]> git.proxmox.com Git - pve-manager-legacy.git/commitdiff
BackupEdit, cleanup: remove insideUpdate construct
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 5 Oct 2016 09:34:17 +0000 (11:34 +0200)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Thu, 10 Nov 2016 08:56:05 +0000 (09:56 +0100)
insideUpdate protects for a endless loop which gets caused if the sm
selection change callback updates vmidField which then triggers the
vmidField change callback which updates the selection model again,
and the circle starts again.

As this construct is rather confusing when looking first at the code
replace it with a temporary suspend of the change event during the
vmidField update.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
www/manager6/dc/Backup.js

index 54eca4be2d1077c9a9d24fff122fb05679a43b68..e37b62847bd0bc1dd2e7a14aa7b1a30dbab422f6 100644 (file)
@@ -35,22 +35,20 @@ Ext.define('PVE.dc.BackupEdit', {
            value: ''
        });
 
-       var insideUpdate = false;
-       
        var sm = Ext.create('Ext.selection.CheckboxModel', {
            mode: 'SIMPLE',
            listeners: {
                selectionchange: function(model, selected) {
-                   if (!insideUpdate) { // avoid endless loop
-                       var sel = [];
-                       Ext.Array.each(selected, function(record) {
-                           sel.push(record.data.vmid);
-                       });
+                   var sel = [];
+                   Ext.Array.each(selected, function(record) {
+                       sel.push(record.data.vmid);
+                   });
 
-                       insideUpdate = true;
-                       vmidField.setValue(sel);
-                       insideUpdate = false;
-                   }
+                   // to avoid endless recursion suspend the vmidField change
+                   // event temporary as it calls us again
+                   vmidField.suspendEvent('change');
+                   vmidField.setValue(sel);
+                   vmidField.resumeEvent('change');
                }
            }
        });
@@ -219,10 +217,6 @@ Ext.define('PVE.dc.BackupEdit', {
        });
 
        var update_vmid_selection = function(list, mode) {
-           if (insideUpdate) {
-               return; // should not happen - just to be sure
-           }
-           insideUpdate = true;
            if (mode !== 'all') {
                sm.deselectAll(true);
                if (list) {
@@ -234,7 +228,6 @@ Ext.define('PVE.dc.BackupEdit', {
                    });
                }
            }
-           insideUpdate = false;
        };
 
        vmidField.on('change', function(f, value) {