From 15d236ad3b9886f127838c41c564c8f6fc1b8b4b Mon Sep 17 00:00:00 2001
From: Renaud Le Gac <legac@cppm.in2p3.fr>
Date: Thu, 25 Sep 2014 21:09:27 +0200
Subject: [PATCH] Simplify the logic for the context menu. It pops up
 everywhere in the grid panel.

---
 static/plugin_dbui/src/grid/plugin/Export.js | 94 +++++++-------------
 views/reports/report_4.html                  |  4 +-
 2 files changed, 33 insertions(+), 65 deletions(-)

diff --git a/static/plugin_dbui/src/grid/plugin/Export.js b/static/plugin_dbui/src/grid/plugin/Export.js
index 60aaae81..21ffedf2 100644
--- a/static/plugin_dbui/src/grid/plugin/Export.js
+++ b/static/plugin_dbui/src/grid/plugin/Export.js
@@ -86,13 +86,20 @@ Ext.define('App.grid.plugin.Export', {
             }]
         });
 
-        grid.on({
-            'containercontextmenu': this.onContainerContextMenu,
-            'headercontextmenu': this.onHeaderContextMenu,
-            'itemcontextmenu': this.onItemContextMenu,
-            scope: this
-        });
+        // the menu pops up everywhere in the the grid, no context menu outside.
+        // Move from the Ext.component to the Ext.dom.element space.
+        grid.on('render', function(cmp){
+
+            cmp.body.on("contextmenu", function(event){
+                event.stopEvent();
+                this.menu.showAt(event.getXY());
+            }, this);
+
+            cmp.body.up(".x-panel-body").on("contextmenu", function(event){
+                event.stopEvent();
+            }, this);
 
+        }, this, {single: true});
     },
 
     /**
@@ -112,11 +119,22 @@ Ext.define('App.grid.plugin.Export', {
         return value;
     },
 
+    /**
+     * Destroy the plugin
+     *
+     */
+    destroy: function () {
+
+        "use strict";
+        Ext.destroy(this.memu);
+    },
+
     /**
      * Get the label and the alignment of the visible columns.
      *
      * @return {Object}
      * @return {String[]} return.alignments
+     * @return {Boolean}  return.hidden
      * @return {String[]} return.labels empty for hidden headers
      *
      */
@@ -146,27 +164,11 @@ Ext.define('App.grid.plugin.Export', {
             }
         }
 
-        if (container[0].hiddenHeaders) {
-            labels = [];
-        }
-
-        return {alignments: alignments, labels: labels};
-    },
-
-    /**
-     * Show the context menu when right clicking in an empty grid.
-     *
-     * @param {App.grid.Panel} grid
-     * @param {Ext.EventObject} event
-     * @param {Object} eOpts
-     *
-     */
-    onContainerContextMenu: function (grid, event, eOpts) {
-
-        "use strict";
-
-        event.stopEvent();
-        this.menu.showAt(event.getXY());
+        return {
+            alignments: alignments,
+            hidden: container[0].hiddenHeaders,
+            labels: labels
+        };
     },
 
     /**
@@ -186,7 +188,7 @@ Ext.define('App.grid.plugin.Export', {
             total;
 
         // convert the header
-        if (header.labels.length) {
+        if (! header.hidden) {
             for (i = 0; i < header.labels.length; i += 1) {
                 header.labels[i] = this.delimit(header.labels[i]);
             }
@@ -236,40 +238,6 @@ Ext.define('App.grid.plugin.Export', {
         this.save("text/csv", "utf-8", lines);
     },
 
-    /**
-     * Inhibit the context menu when right clicking in the grid header.
-     *
-     * @param {Ext.grid.header.Container} gridheader
-     * @param {Ext.grid.column.Column} column
-     * @param {Ext.EventObject} event
-     * @param {HTMLElement} html
-     * @param {Object} eOpts
-     *
-     */
-    onHeaderContextMenu: function (gridheader, colum, event, html, eOpts) {
-
-        "use strict";
-        event.stopEvent();
-    },
-
-    /**
-     * Show the context menu when right clicking in the non-empty grid.
-     *
-     * @param {Ext.view.View} view
-     * @param {Ext.data.Model} record
-     * @param {HTMLElement} item
-     * @param {Ext.EventObject} event
-     * @param {Object} eOpts
-     *
-     */
-    onItemContextMenu: function (view, record, item, index, event, eOpts) {
-
-        "use strict";
-
-        event.stopEvent();
-        this.menu.showAt(event.getXY());
-    },
-
     /**
      * Export the content of the grid as a LaTex file.
      *
@@ -384,7 +352,7 @@ Ext.define('App.grid.plugin.Export', {
         lines.push(cmd);
 
         // table header
-        if (header.labels.length) {
+        if (! header.hidden) {
             lines.push(header.labels.join(' & ') + ' \\\\');
         }
 
diff --git a/views/reports/report_4.html b/views/reports/report_4.html
index d48af783..247eca35 100644
--- a/views/reports/report_4.html
+++ b/views/reports/report_4.html
@@ -43,8 +43,8 @@
                 summaryType: 'sum'
             }
         ],
-        features: [{ftype:'grouping'}],
-        //features: [{ftype:'groupingsummary'}, {ftype:'summary'}],
+        //features: [{ftype:'grouping'}],
+        features: [{ftype:'groupingsummary'}, {ftype:'summary'}],
         forceFit: true,
         //hideHeaders: true,
         padding: "10 40 20 60",
-- 
GitLab