From: Jaroslav Kysela Date: Tue, 1 Dec 2015 08:24:25 +0000 (+0100) Subject: WEBUI: handle the form dirty state properly for apply buttons, fixes #3359 X-Git-Tag: v4.2.1~1426 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b4ce047a32c1ae17cd348c0087b17f02ebd7cbbc;p=thirdparty%2Ftvheadend.git WEBUI: handle the form dirty state properly for apply buttons, fixes #3359 --- diff --git a/src/webui/static/app/idnode.js b/src/webui/static/app/idnode.js index 4b4a15ee5..d71c33501 100644 --- a/src/webui/static/app/idnode.js +++ b/src/webui/static/app/idnode.js @@ -934,27 +934,7 @@ tvheadend.idnode_editor = function(item, conf) text: _('Save'), iconCls: 'save', handler: function() { - var node = panel.getForm().getFieldValues(); - node.uuid = conf.uuids ? conf.uuids : item.uuid; - tvheadend.Ajax({ - url: 'api/idnode/save', - params: { - node: Ext.encode(node) - }, - success: function(d) { - if (conf.win) - conf.win.close(); - } - }); - } - }); - buttons.push(saveBtn); - - if (!conf.noApply) { - var applyBtn = new Ext.Button({ - text: _('Apply'), - iconCls: 'apply', - handler: function() { + if (panel.getForm().isDirty()) { var node = panel.getForm().getFieldValues(); node.uuid = conf.uuids ? conf.uuids : item.uuid; tvheadend.Ajax({ @@ -963,8 +943,36 @@ tvheadend.idnode_editor = function(item, conf) node: Ext.encode(node) }, success: function(d) { + if (conf.win) + conf.win.close(); } }); + } else { + if (conf.win) + conf.win.close(); + } + } + }); + buttons.push(saveBtn); + + if (!conf.noApply) { + var applyBtn = new Ext.Button({ + text: _('Apply'), + iconCls: 'apply', + handler: function() { + if (panel.getForm().isDirty()) { + var node = panel.getForm().getFieldValues(); + node.uuid = conf.uuids ? conf.uuids : item.uuid; + tvheadend.Ajax({ + url: 'api/idnode/save', + params: { + node: Ext.encode(node) + }, + success: function(d) { + panel.getForm().reset(); + } + }); + } } }); buttons.push(applyBtn); @@ -1023,19 +1031,23 @@ tvheadend.idnode_create = function(conf, onlyDefault) iconCls: 'add', hidden: true, handler: function() { - var params = conf.create.params || {}; - if (puuid) - params['uuid'] = puuid; - if (pclass) - params['class'] = pclass; - params['conf'] = Ext.encode(panel.getForm().getFieldValues()); - tvheadend.Ajax({ - url: conf.create.url || conf.url + '/create', - params: params, - success: function(d) { - win.close(); - } - }); + if (panel.getForm().isDirty()) { + var params = conf.create.params || {}; + if (puuid) + params['uuid'] = puuid; + if (pclass) + params['class'] = pclass; + params['conf'] = Ext.encode(panel.getForm().getFieldValues()); + tvheadend.Ajax({ + url: conf.create.url || conf.url + '/create', + params: params, + success: function(d) { + win.close(); + } + }); + } else { + win.close(); + } } }); var applyBtn = new Ext.Button({ @@ -1044,18 +1056,21 @@ tvheadend.idnode_create = function(conf, onlyDefault) iconCls: 'apply', hidden: true, handler: function() { - var params = conf.create.params || {}; - if (puuid) - params['uuid'] = puuid; - if (pclass) - params['class'] = pclass; - params['conf'] = Ext.encode(panel.getForm().getFieldValues()); - tvheadend.Ajax({ - url: conf.create.url || conf.url + '/create', - params: params, - success: function(d) { - } - }); + if (panel.getForm().isDirty()) { + var params = conf.create.params || {}; + if (puuid) + params['uuid'] = puuid; + if (pclass) + params['class'] = pclass; + params['conf'] = Ext.encode(panel.getForm().getFieldValues()); + tvheadend.Ajax({ + url: conf.create.url || conf.url + '/create', + params: params, + success: function(d) { + panel.getForm().reset(); + } + }); + } } }); var cancelBtn = new Ext.Button({