[icinga-checkins] icinga.org: icinga-web/next: Fix selection being corrupted after grid reload

git at icinga.org git at icinga.org
Wed Jul 24 15:03:16 CEST 2013


Module: icinga-web
Branch: next
Commit: 620472abcb4d7b0a634fabfc13371b200d0cfad1
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=620472abcb4d7b0a634fabfc13371b200d0cfad1

Author: Jannis Mosshammer <jannis.mosshammer at netways.de>
Date:   Wed Jul 24 15:00:41 2013 +0200

Fix selection being corrupted after grid reload

This commit fixes a bug where a grid reload can lead to invalid selections,
as the same rows are selected, even if there's a different ordering of objects
in the new dataset. Now the object_id columns are remembered and used
to determine if a page contains previously selected objects after a reload,
this is implemented in ObjectSelectionModel

refs #4452

---

 app/modules/Cronks/config/javascript.xml           |    1 +
 .../Cronks/lib/js/Cronk/grid/MetaGridPanel.js      |   10 ++-
 .../lib/js/Cronk/grid/ObjectSelectionModel.js      |   75 ++++++++++++++++++++
 3 files changed, 84 insertions(+), 2 deletions(-)

diff --git a/app/modules/Cronks/config/javascript.xml b/app/modules/Cronks/config/javascript.xml
index efd464b..00c0a54 100644
--- a/app/modules/Cronks/config/javascript.xml
+++ b/app/modules/Cronks/config/javascript.xml
@@ -124,6 +124,7 @@
             <ae:parameter>%core.module_dir%/Cronks/lib/js/Cronk/grid/CommandHandler.js</ae:parameter>
             <ae:parameter>%core.module_dir%/Cronks/lib/js/Icinga/Cronks/System/TemplateGrid.js</ae:parameter>
             <ae:parameter>%core.module_dir%/Cronks/lib/js/Cronk/grid/MetaGridPanel.js</ae:parameter>
+            <ae:parameter>%core.module_dir%/Cronks/lib/js/Cronk/grid/ObjectSelectionModel.js</ae:parameter>
         </javascript>
     </ae:configuration>
 </ae:configurations>
diff --git a/app/modules/Cronks/lib/js/Cronk/grid/MetaGridPanel.js b/app/modules/Cronks/lib/js/Cronk/grid/MetaGridPanel.js
index 351027a..b4c5f83 100644
--- a/app/modules/Cronks/lib/js/Cronk/grid/MetaGridPanel.js
+++ b/app/modules/Cronks/lib/js/Cronk/grid/MetaGridPanel.js
@@ -503,7 +503,13 @@ Ext.ns("Cronk.grid");
                     store: this.getStore(),
                     displayInfo: true,
                     displayMsg: _('Displaying topics {0} - {1} of {2}'),
-                    emptyMsg: _('No topics to display')
+                    emptyMsg: _('No topics to display'),
+                    listeners: {
+                        change: function() {
+                            this.getSelectionModel().syncWithPage();
+                        },
+                        scope: this
+                    }
                 };
 
                 if (Ext.isEmpty(datasource.countmode) || datasource.countmode === "none") {
@@ -630,7 +636,7 @@ Ext.ns("Cronk.grid");
             var options = this.getOption("template.option", {});
             if (!Ext.isEmpty(options.selection_model)) {
                 if (options.selection_model === "checkbox") {
-                    var sm = new Ext.grid.CheckboxSelectionModel({
+                    var sm = new Cronk.grid.ObjectSelectionModel({
                         dataIndex: "id"
                     });
 
diff --git a/app/modules/Cronks/lib/js/Cronk/grid/ObjectSelectionModel.js b/app/modules/Cronks/lib/js/Cronk/grid/ObjectSelectionModel.js
new file mode 100644
index 0000000..bf085fd
--- /dev/null
+++ b/app/modules/Cronks/lib/js/Cronk/grid/ObjectSelectionModel.js
@@ -0,0 +1,75 @@
+// {{{ICINGA_LICENSE_CODE}}}
+// -----------------------------------------------------------------------------
+// This file is part of icinga-web.
+// 
+// Copyright (c) 2009-2013 Icinga Developer Team.
+// All rights reserved.
+// 
+// icinga-web is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+// 
+// icinga-web is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with icinga-web.  If not, see <http://www.gnu.org/licenses/>.
+// -----------------------------------------------------------------------------
+// {{{ICINGA_LICENSE_CODE}}}
+/*global Ext: false, Icinga: false, AppKit: false, _: false, Cronk: false */
+
+Ext.ns("Cronk.grid");
+
+(function () {
+
+    "use strict";
+    
+    /**
+    *   Checkbox selectionmodel that remembers object ids and offers better
+    *   pagination
+    *
+    **/
+    Cronk.grid.ObjectSelectionModel = Ext.extend(Ext.grid.CheckboxSelectionModel, {
+        selectedMonitoringObjects: new Ext.util.MixedCollection(),
+        
+        constructor: function() {
+            Ext.grid.CheckboxSelectionModel.prototype.constructor.apply(this, arguments);
+            this.addListener("selectionchange", this.persistSelectedObjectIds, this);
+        },
+       
+        syncWithPage: function() {
+            var records = [];
+            this.grid.getStore().each(function(displayedObject) {
+                this.selectedMonitoringObjects.each(function(monitoringObject) {
+                    for (var attribute in monitoringObject) {
+                        if (displayedObject.data[attribute] == monitoringObject[attribute]) {
+                            continue;
+                        }
+                        return true;
+                    }
+                    records.push(displayedObject);
+                    return false;
+                }, this);
+            }, this);
+            this.clearSelections();
+            this.selectRecords(records);
+        },
+     
+        persistSelectedObjectIds: function() {
+            var isObjectId = /_object_id$/i;
+            this.selectedMonitoringObjects.clear();
+            this.selections.each(function(monitoringObject) {
+                var selectedObject = {};
+                for (var attribute in monitoringObject.data) {
+                    if (isObjectId.test(attribute)) {
+                        selectedObject[attribute] = monitoringObject.data[attribute];
+                    }
+                }
+                this.selectedMonitoringObjects.add(selectedObject);
+            }, this);
+        }
+    });
+})();





More information about the icinga-checkins mailing list