notification.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. 'require view';
  3. 'require fs';
  4. 'require ui';
  5. var isReadonlyView = !L.hasViewPermission() || null;
  6. return view.extend({
  7. load: function() {
  8. return L.resolveDefault(fs.read('/etc/keepalived.user'), '');
  9. },
  10. handleSave: function(ev) {
  11. var value = (document.querySelector('textarea').value || '').trim().replace(/\r\n/g, '\n') + '\n';
  12. return fs.write('/etc/keepalived.user', value).then(function(rc) {
  13. document.querySelector('textarea').value = value;
  14. ui.addNotification(null, E('p', _('Contents have been saved.')), 'info');
  15. return fs.exec('/etc/init.d/keepalived', [ 'reload' ]);
  16. }).catch(function(e) {
  17. ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
  18. });
  19. },
  20. render: function(keepalived) {
  21. return E([
  22. E('h2', _('Keepalived.user')),
  23. E('p', { 'class': 'cbi-section-descr' }, _('This is the /etc/keepalived.user file in which custom commands can be defined.')),
  24. E('p', {}, E('textarea', { 'style': 'width:100%', 'rows': 25, 'disabled': isReadonlyView }, [ keepalived != null ? keepalived : '' ]))
  25. ]);
  26. },
  27. handleSaveApply: null,
  28. handleReset: null
  29. });