changeset 1039:77e22ad5cc84

Use user 'funktionen' attribute to set read/write status for stammdaten.
author Raimund Renkert <raimund.renkert@intevation.de>
date Fri, 19 Feb 2016 13:59:24 +0100
parents 1251094e7500
children 6a176e9ca890 16c0c6946ae9
files app.js app/controller/grid/Datensatzerzeuger.js app/controller/grid/MessprogrammKategorie.js app/controller/grid/Probenehmer.js app/view/grid/DatensatzErzeuger.js app/view/grid/MessprogrammKategorie.js app/view/grid/Probenehmer.js
diffstat 7 files changed, 116 insertions(+), 115 deletions(-) [+]
line wrap: on
line diff
--- a/app.js	Fri Feb 19 13:58:43 2016 +0100
+++ b/app.js	Fri Feb 19 13:59:24 2016 +0100
@@ -113,6 +113,7 @@
         Lada.userroles = json.data.roles;
         Lada.logintime = json.data.servertime;
         Lada.mst = json.data.mst; //Store Messstellen this user may select
+        Lada.funktionen = json.data.funktionen;
         //Lada.serverVersion
         this.getServerVersion();
 
--- a/app/controller/grid/Datensatzerzeuger.js	Fri Feb 19 13:58:43 2016 +0100
+++ b/app/controller/grid/Datensatzerzeuger.js	Fri Feb 19 13:59:24 2016 +0100
@@ -21,8 +21,9 @@
             'datensatzerzeugergrid': {
                 edit: this.gridSave,
                 canceledit: this.cancelEdit,
-                select: this.activateButtons,
-                deselect: this.deactivateButtons
+                select: this.buttonToggle,
+                deselect: this.buttonToggle,
+                itemdblclick: this.edit
             },
             'datensatzerzeugergrid button[action=add]': {
                 click: this.add
@@ -33,6 +34,11 @@
         });
     },
 
+    edit: function() {
+        var grid = Ext.ComponentQuery.query('datensatzerzeugergrid')[0];
+        grid.down('button[action=delete]').disable();
+    },
+
     /**
      * This function is called when the grids roweditor saves
      * the record.
@@ -69,8 +75,11 @@
         if (!context.record.get('id') ||
             context.record.get('id') === '') {
             editor.getCmp().store.remove(context.record);
+            this.buttonToggle();
         }
-        context.grid.getSelectionModel().deselect(context.record);
+        else {
+            this.buttonToggle(context.grid.getSelectionModel(), context.record);
+        }
     },
 
     /**
@@ -122,42 +131,30 @@
         });
         grid.down('button[action=delete]').disable();
     },
-    /**
-     * Toggles the buttons in the toolbar
-     **/
-    activateButtons: function(rowModel, record) {
-        var grid = rowModel.view.up('grid');
-        this.buttonToggle(true, grid);
-    },
-
-    /**
-     * Toggles the buttons in the toolbar
-     **/
-    deactivateButtons: function(rowModel, record) {
-        var grid = rowModel.view.up('grid');
-        // Only disable buttons when nothing is selected
-        if (rowModel.selected.items == 0) {
-            this.buttonToggle(false, grid);
-        }
-    },
 
     /**
      * Enables/Disables a set of buttons
      **/
-    buttonToggle: function(enabled, grid) {
-        if (!enabled) {
+    buttonToggle: function(rowModel, record) {
+        if (!Ext.Array.contains(Lada.funktionen, 4)) {
+            return;
+        }
+        var grid = Ext.ComponentQuery.query('datensatzerzeugergrid')[0];
+        if (!record) {
+            grid.down('button[action=delete]').disable();
+        }
+        if (record.get('readonly') ||
+            rowModel.selected.items.length === 0) {
             grid.down('button[action=delete]').disable();
         }
         else {
-            if (!grid.getPlugin('rowedit').editing) {
+            if (grid.getPlugin('rowedit').editing) {
             //only enable buttons, when grid is not beeing edited
+                grid.down('button[action=delete]').disable();
+            }
+            else {
                 grid.down('button[action=delete]').enable();
             }
-            //else turn them off again!
-            else {
-                this.buttonToggle(false, grid);
-            }
         }
     }
 });
-
--- a/app/controller/grid/MessprogrammKategorie.js	Fri Feb 19 13:58:43 2016 +0100
+++ b/app/controller/grid/MessprogrammKategorie.js	Fri Feb 19 13:59:24 2016 +0100
@@ -21,8 +21,9 @@
             'messprogrammkategoriegrid': {
                 edit: this.gridSave,
                 canceledit: this.cancelEdit,
-                select: this.activateButtons,
-                deselect: this.deactivateButtons
+                select: this.buttonToggle,
+                deselect: this.buttonToggle,
+                itemdblclick: this.edit
             },
             'messprogrammkategoriegrid button[action=add]': {
                 click: this.add
@@ -33,6 +34,11 @@
         });
     },
 
+    edit: function() {
+        var grid = Ext.ComponentQuery.query('messprogrammkategoriegrid')[0];
+        grid.down('button[action=delete]').disable();
+    },
+
     /**
      * This function is called when the grids roweditor saves
      * the record.
@@ -121,43 +127,32 @@
         });
         grid.down('button[action=delete]').disable();
     },
-    /**
-     * Toggles the buttons in the toolbar
-     **/
-    activateButtons: function(rowModel, record) {
-        var grid = rowModel.view.up('grid');
-        this.buttonToggle(true, grid);
-    },
-
-    /**
-     * Toggles the buttons in the toolbar
-     **/
-    deactivateButtons: function(rowModel, record) {
-        var grid = rowModel.view.up('grid');
-        // Only disable buttons when nothing is selected
-        if (rowModel.selected.items == 0) {
-            this.buttonToggle(false, grid);
-        }
-    },
 
     /**
      * Enables/Disables a set of buttons
      **/
-    buttonToggle: function(enabled, grid) {
-        if (!enabled) {
+    buttonToggle: function(rowModel, record) {
+        if (!Ext.Array.contains(Lada.funktionen, 4)) {
+            return;
+        }
+        var grid = Ext.ComponentQuery.query('messprogrammkategoriegrid')[0];
+        if (!record) {
+            grid.down('button[action=delete]').disable();
+        }
+        if (record.get('readonly') ||
+            rowModel.selected.items.length === 0) {
             grid.down('button[action=delete]').disable();
         }
         else {
-            if (!grid.getPlugin('rowedit').editing) {
+            if (grid.getPlugin('rowedit').editing) {
             //only enable buttons, when grid is not beeing edited
+                grid.down('button[action=delete]').disable();
+            }
+            else {
                 grid.down('button[action=delete]').enable();
             }
-            //else turn them off again!
-            else {
-                this.buttonToggle(false, grid);
-            }
         }
-    },
+    }
 });
 
 
--- a/app/controller/grid/Probenehmer.js	Fri Feb 19 13:58:43 2016 +0100
+++ b/app/controller/grid/Probenehmer.js	Fri Feb 19 13:59:24 2016 +0100
@@ -21,8 +21,9 @@
             'probenehmergrid': {
                 edit: this.gridSave,
                 canceledit: this.cancelEdit,
-                select: this.activateButtons,
-                deselect: this.deactivateButtons
+                select: this.buttonToggle,
+                deselect: this.buttonToggle,
+                itemdblclick: this.edit
             },
             'probenehmergrid button[action=add]': {
                 click: this.add
@@ -33,6 +34,11 @@
         });
     },
 
+    edit: function() {
+        var grid = Ext.ComponentQuery.query('probenehmergrid')[0];
+        grid.down('button[action=delete]').disable();
+    },
+
     /**
      * This function is called when the grids roweditor saves
      * the record.
@@ -69,8 +75,11 @@
         if (!context.record.get('id') ||
             context.record.get('id') === '') {
             editor.getCmp().store.remove(context.record);
+            this.buttonToggle();
         }
-        context.grid.getSelectionModel().deselect(context.record);
+        else {
+            this.buttonToggle(context.grid.getSelectionModel(), context.record);
+        }
     },
 
     /**
@@ -121,42 +130,30 @@
         });
         grid.down('button[action=delete]').disable();
     },
-    /**
-     * Toggles the buttons in the toolbar
-     **/
-    activateButtons: function(rowModel, record) {
-        var grid = rowModel.view.up('grid');
-        this.buttonToggle(true, grid);
-    },
-
-    /**
-     * Toggles the buttons in the toolbar
-     **/
-    deactivateButtons: function(rowModel, record) {
-        var grid = rowModel.view.up('grid');
-        // Only disable buttons when nothing is selected
-        if (rowModel.selected.items == 0) {
-            this.buttonToggle(false, grid);
-        }
-    },
 
     /**
      * Enables/Disables a set of buttons
      **/
-    buttonToggle: function(enabled, grid) {
-        if (!enabled) {
+    buttonToggle: function(rowModel, record) {
+        if (!Ext.Array.contains(Lada.funktionen, 4)) {
+            return;
+        }
+        var grid = Ext.ComponentQuery.query('probenehmergrid')[0];
+        if (!record) {
+            grid.down('button[action=delete]').disable();
+        }
+        if (record.get('readonly') ||
+            rowModel.selected.items.length === 0) {
             grid.down('button[action=delete]').disable();
         }
         else {
-            if (!grid.getPlugin('rowedit').editing) {
+            if (grid.getPlugin('rowedit').editing) {
             //only enable buttons, when grid is not beeing edited
+                grid.down('button[action=delete]').disable();
+            }
+            else {
                 grid.down('button[action=delete]').enable();
             }
-            //else turn them off again!
-            else {
-                this.buttonToggle(false, grid);
-            }
         }
-    },
+    }
 });
-
--- a/app/view/grid/DatensatzErzeuger.js	Fri Feb 19 13:58:43 2016 +0100
+++ b/app/view/grid/DatensatzErzeuger.js	Fri Feb 19 13:59:24 2016 +0100
@@ -29,15 +29,15 @@
     initComponent: function() {
         var i18n = Lada.getApplication().bundle;
         this.emptyText = i18n.getMsg('de.emptyGrid');
-
-        this.rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
-            clicksToMoveEditor: 1,
-            autoCancel: false,
-            disabled: false,
-            pluginId: 'rowedit'
-        });
-        this.plugins = [this.rowEditing];
-
+        if (Ext.Array.contains(Lada.funktionen, 4)) {
+            this.rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
+                clicksToMoveEditor: 1,
+                autoCancel: false,
+                disabled: false,
+                pluginId: 'rowedit'
+            });
+            this.plugins = [this.rowEditing];
+        }
         // TODO: Which docked Items are required?
         this.dockedItems = [{
             xtype: 'toolbar',
@@ -138,13 +138,15 @@
     /**
      * This sets the Store of this Grid
      */
-    setStore: function(store){
+    setStore: function(store) {
         var i18n = Lada.getApplication().bundle;
+        if (Ext.Array.contains(Lada.funktionen, 4)) {
+            this.down('button[action=add]').enable();
+        }
 
         if (store) {
             this.removeDocked(Ext.getCmp('ptbar'), true);
             this.reconfigure(store);
-            this.down('button[action=add]').enable();
             this.addDocked([{
                 xtype: 'pagingtoolbar',
                 id: 'ptbar',
--- a/app/view/grid/MessprogrammKategorie.js	Fri Feb 19 13:58:43 2016 +0100
+++ b/app/view/grid/MessprogrammKategorie.js	Fri Feb 19 13:59:24 2016 +0100
@@ -30,13 +30,15 @@
         var i18n = Lada.getApplication().bundle;
         this.emptyText = i18n.getMsg('mk.emptyGrid');
 
-        this.rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
-            clicksToMoveEditor: 1,
-            autoCancel: false,
-            disabled: false,
-            pluginId: 'rowedit'
-        });
-        this.plugins = [this.rowEditing];
+        if (Ext.Array.contains(Lada.funktionen, 4)) {
+            this.rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
+                clicksToMoveEditor: 1,
+                autoCancel: false,
+                disabled: false,
+                pluginId: 'rowedit'
+            });
+            this.plugins = [this.rowEditing];
+        }
 
         // TODO: Which docked Items are required?
         this.dockedItems = [{
@@ -115,8 +117,11 @@
     /**
      * This sets the Store of this Grid
      */
-    setStore: function(store){
+    setStore: function(store) {
         var i18n = Lada.getApplication().bundle;
+        if (Ext.Array.contains(Lada.funktionen, 4)) {
+            this.down('button[action=add]').enable();
+        }
 
         this.removeDocked(Ext.getCmp('ptbar'), true);
         this.reconfigure(store);
--- a/app/view/grid/Probenehmer.js	Fri Feb 19 13:58:43 2016 +0100
+++ b/app/view/grid/Probenehmer.js	Fri Feb 19 13:59:24 2016 +0100
@@ -30,13 +30,15 @@
         var i18n = Lada.getApplication().bundle;
         this.emptyText = i18n.getMsg('pn.emptyGrid');
 
-        this.rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
-            clicksToMoveEditor: 1,
-            autoCancel: false,
-            disabled: false,
-            pluginId: 'rowedit'
-        });
-        this.plugins = [this.rowEditing];
+        if (Ext.Array.contains(Lada.funktionen, 4)) {
+            this.rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
+                clicksToMoveEditor: 1,
+                autoCancel: false,
+                disabled: false,
+                pluginId: 'rowedit'
+            });
+            this.plugins = [this.rowEditing];
+        }
 
         // TODO: Which docked Items are required?
         this.dockedItems = [{
@@ -167,13 +169,15 @@
     /**
      * This sets the Store of this Grid
      */
-    setStore: function(store){
+    setStore: function(store) {
         var i18n = Lada.getApplication().bundle;
+        if (Ext.Array.contains(Lada.funktionen, 4)) {
+            this.down('button[action=add]').enable();
+        }
 
         if (store) {
             this.removeDocked(Ext.getCmp('ptbar'), true);
             this.reconfigure(store);
-            this.down('button[action=add]').enable();
             this.addDocked([{
                 xtype: 'pagingtoolbar',
                 id: 'ptbar',

http://lada.wald.intevation.org