changeset 856:e44070aa45d2

Implemented a 'Delete Button' in the ResultGrid. Proben can be deleted when they are not ReadOnly and the Users is the Owner of the Probe
author Dustin Demuth <dustin@intevation.de>
date Fri, 10 Jul 2015 17:14:19 +0200
parents dff2798390f8
children 01cddda65fea 03f39ddae596
files app/model/ProbeList.js app/view/grid/FilterResult.js app/view/window/DeleteProbe.js resources/i18n/Lada_de-DE.properties resources/img/edit-delete.png
diffstat 5 files changed, 228 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/app/model/ProbeList.js	Fri Jul 10 14:21:59 2015 +0200
+++ b/app/model/ProbeList.js	Fri Jul 10 17:14:19 2015 +0200
@@ -15,6 +15,8 @@
 
     fields: [{
         name: 'readonly'
+    }, {
+        name: 'owner'
     }],
 
     idProperty: 'id',
--- a/app/view/grid/FilterResult.js	Fri Jul 10 14:21:59 2015 +0200
+++ b/app/view/grid/FilterResult.js	Fri Jul 10 17:14:19 2015 +0200
@@ -13,6 +13,8 @@
     extend: 'Ext.grid.Panel',
     alias: 'widget.filterresultgrid',
 
+    requires: 'Lada.view.window.DeleteProbe',
+
     store: null, //'ProbenList',
 
     multiSelect: true,
@@ -120,21 +122,26 @@
         var resultColumns = [];
         var fields = [];
 
+        fields.push(new Ext.data.Field({
+            name: 'owner'
+        }));
+        fields.push(new Ext.data.Field({
+            name: 'readonly'
+        }));
+
         resultColumns.push({
             header: 'RW',
             dataIndex: 'readonly',
             sortable: false,
             width: 30,
-            renderer: function(value) {
-                if (value) {
-                    return '<img src="resources/img/view-time-schedule-baselined.png"/>';
+            renderer: function(value, meta, record) {
+                if ( !value && record.get('owner')) {
+                    return '<img src="resources/img/view-time-schedule-edit.png"/>';
                 }
-                return '<img src="resources/img/view-time-schedule-edit.png"/>';
+                return '<img src="resources/img/view-time-schedule-baselined.png"/>';
             }
         });
-        fields.push(new Ext.data.Field({
-            name: 'readonly'
-        }));
+
         for (var i = cols.length - 1; i >= 0; i--) {
             if (cols[i] === 'id') {
                 continue;
@@ -144,6 +151,38 @@
                 name: cols[i].dataIndex
             }));
         }
+        if (this.store.$className == 'Lada.store.ProbenList') {
+            // Add a Delete-Button
+            // TODO: Might need to be extended to Messprogramme
+            resultColumns.push({
+                xtype: 'actioncolumn',
+                header: 'Aktionen',
+                sortable: false,
+                width: 30,
+                items: [{
+                    icon: '/resources/img/edit-delete.png',
+                    tooltip: 'Löschen',
+                    isDisabled: function(grid, rowIndex, colIndex) {
+                        var rec = grid.getStore().getAt(rowIndex);
+                        if ( rec.get('readonly') || !rec.get('owner')) {
+                            return true;
+                        }
+                        return false;
+                    },
+                    handler: function(grid, rowIndex, colIndex){
+                        var rec = grid.getStore().getAt(rowIndex);
+
+                        var winname = 'Lada.view.window.DeleteProbe';
+                        var win = Ext.create(winname, {
+                            record: rec,
+                            parentWindow: this
+                        });
+                        win.show();
+                        win.initData();
+                    }
+                }]
+            });
+        }
         this.store.model.setFields(fields);
         this.reconfigure(this.store, resultColumns);
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/view/window/DeleteProbe.js	Fri Jul 10 17:14:19 2015 +0200
@@ -0,0 +1,175 @@
+/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU GPL (v>=3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out
+ * the documentation coming with IMIS-Labordaten-Application for details.
+ */
+
+/*
+ * Window to show a confirmation dialog to delete a Probe
+ */
+Ext.define('Lada.view.window.DeleteProbe', {
+    extend: 'Ext.window.Window',
+    alias: 'widget.deleteProbe',
+
+    collapsible: true,
+    maximizable: true,
+    autoShow: true,
+    autoScroll: true,
+    layout: 'fit',
+    constrain: true,
+
+    record: null,
+    parentWindow: null,
+
+    initComponent: function() {
+        var i18n = Lada.getApplication().bundle;
+
+        // add listeners to change the window appearence when it becomes inactive
+        this.on({
+            activate: function(){
+                this.getEl().removeCls('window-inactive');
+            },
+            deactivate: function(){
+                this.getEl().addCls('window-inactive');
+            }
+        });
+
+        this.title = i18n.getMsg('delete.probe.window.title');
+        var me = this;
+        this.buttons = [{
+            text: i18n.getMsg('cancel'),
+            scope: this,
+            handler: this.close
+        }, {
+            text: i18n.getMsg('delete'),
+            handler: function() {
+
+                Ext.Ajax.request({
+                    //TODO Use correct URLs
+                    url: 'lada-server/probe/'+me.record.get('id'),
+                    method: 'DELETE',
+                    headers: {
+                        'X-OPENID-PARAMS': Lada.openIDParams
+                    },
+                    success: function(response) {
+                        var json = Ext.JSON.decode(response.responseText);
+                        Ext.Msg.show({
+                            title: i18n.getMsg('success'),
+                            autoScroll: true,
+                            msg: me.evalResponse(json),
+                            buttons: Ext.Msg.OK,
+                        });
+                    },
+                    failure: function(response) {
+                        var json = null;
+                        try {
+                            json = Ext.JSON.decode(response.responseText);
+                        }
+                        catch(err){
+                            Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title'),
+                                Lada.getApplication().bundle.getMsg('err.msg.response.body'));
+                        }
+                        if (json) {
+                            if(json.errors.totalCount > 0 || json.warnings.totalCount > 0){
+                                formPanel.setMessages(json.errors, json.warnings);
+                            }
+                            // TODO Move this handling of 699 and 698 to a more central place!
+                            // TODO i18n
+                            if (json.message === "699" || json.message === "698") {
+                                /* This is the unauthorized message with the authentication
+                                    * redirect in the data */
+
+                                /* We decided to handle this with a redirect to the identity
+                                    * provider. In which case we have no other option then to
+                                    * handle it here with relaunch. */
+                                Ext.MessageBox.confirm('Erneutes Login erforderlich',
+                                    'Der Server konnte die Anfrage nicht authentifizieren.<br/>'+
+                                    'Für ein erneutes Login muss die Anwendung neu geladen werden.<br/>' +
+                                    'Alle ungesicherten Daten gehen dabei verloren.<br/>' +
+                                    'Soll die Anwendung jetzt neu geladen werden?', me.reload);
+                            }
+                            else if(json.message){
+                                Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title')
+                                    +' #'+json.message,
+                                    Lada.getApplication().bundle.getMsg(json.message));
+                            } else {
+                                Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title'),
+                                    Lada.getApplication().bundle.getMsg('err.msg.generic.body'));
+                            }
+                        } else {
+                            Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title'),
+                                Lada.getApplication().bundle.getMsg('err.msg.response.body'));
+                        }
+                    }
+                });
+            }
+        }];
+        this.width = 350;
+        this.height = 250;
+
+        // add listeners to change the window appearence when it becomes inactive
+        this.on({
+            activate: function(){
+                this.getEl().removeCls('window-inactive');
+            },
+            deactivate: function(){
+                this.getEl().addCls('window-inactive');
+            },
+            close: function () {
+                this.parentWindow.probenWindow = null;
+            }
+        });
+
+        // InitialConfig is the config object passed to the constructor on
+        // creation of this window. We need to pass it throuh to the form as
+        // we need the "Id" param to load the correct item.
+        this.items = [{
+            border: 0,
+            autoScroll: true,
+            items: [{
+                xtype: 'panel',
+                border: 0,
+                margin: 5,
+                layout: 'fit',
+                html: '<p>'
+                    + i18n.getMsg('delete.probe')
+                    + '<br/>'
+                    + '<br/>'
+                    + this.record.get('probeId')
+                    + '<br/>'
+                    + '<br/>'
+                    + i18n.getMsg('delete.probe.warning')
+                    + '</p>'
+            }]
+        }];
+        this.callParent(arguments);
+    },
+
+    /**
+     * Init
+     */
+    initData: function() {
+        var i18n = Lada.getApplication().bundle;
+        me = this;
+    },
+
+    /**
+     * Parse ServerResponse when Proben have been generated
+     */
+    evalResponse: function(response) {
+        var i18n = Lada.getApplication().bundle;
+        var r = '';
+            r += response.data.length;
+            r += ' ' + i18n.getMsg('probedeleted');
+        return r;
+    },
+
+    reload: function(btn) {
+        if (btn === 'yes') {
+            location.reload();
+        }
+    }
+});
+
--- a/resources/i18n/Lada_de-DE.properties	Fri Jul 10 14:21:59 2015 +0200
+++ b/resources/i18n/Lada_de-DE.properties	Fri Jul 10 17:14:19 2015 +0200
@@ -116,6 +116,11 @@
 select:Auswählen
 apply:Übernehmen
 
+delete.probe.window.title:Probe und ihre Messungen Löschen?
+delete.probe:Wollen Sie die Probe und alle damit verbundenen Messungen wirklich LÖSCHEN?
+delete.probe.warning:ACHTUNG: Diese Aktion kann nicht rückgängig gemacht werden.
+
+
 ##
 # Msg:
 ##
Binary file resources/img/edit-delete.png has changed

http://lada.wald.intevation.org