[Lada-commits] [PATCH 3 of 5] Added controller for PKommentarGrid and implemented update/add/delete

Wald Commits scm-commit at wald.intevation.org
Tue Mar 10 14:32:13 CET 2015


# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1425994267 -3600
# Node ID 2c8aa09402a21cce413a9ae15c0e9b28134cc947
# Parent  1dedce48e3e1feee90ae63d1c0833767a68e0b61
Added controller for PKommentarGrid and implemented update/add/delete.

diff -r 1dedce48e3e1 -r 2c8aa09402a2 app/controller/PKommentarGrid.js
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/controller/PKommentarGrid.js	Tue Mar 10 14:31:07 2015 +0100
@@ -0,0 +1,61 @@
+/* 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.
+ */
+
+Ext.define('Lada.controller.PKommentarGrid', {
+    extend: 'Ext.app.Controller',
+
+    init: function() {
+        this.control({
+            'pkommentargrid': {
+                edit: this.edit
+            },
+            'pkommentargrid button[action=add]': {
+                click: this.add
+            },
+            'pkommentargrid button[action=delete]': {
+                click: this.remove
+            }
+        });
+    },
+
+    edit: function(editor, context) {
+        context.record.save({
+            success: function() {
+                context.grid.store.reload();
+                context.grid.up('window').initData();
+            },
+            failure: function() {
+                // TODO
+            }
+        });
+    },
+
+    add: function(button) {
+        var record = Ext.create('Lada.model.PKommentar');
+        record.set('probeId', button.up('pkommentargrid').recordId);
+        button.up('pkommentargrid').store.insert(0, record);
+        button.up('pkommentargrid').rowEditing.startEdit(0, 1);
+    },
+
+    remove: function(button) {
+        var grid = button.up('grid');
+        var selection = grid.getView().getSelectionModel().getSelection()[0];
+        Ext.MessageBox.confirm('Löschen', 'Sind Sie sicher?', function(btn) {
+            if (btn === 'yes') {
+                selection.destroy({
+                    success: function() {
+                        button.up('window').initData();
+                    },
+                    failure: function() {
+                        // TODO
+                    }
+                });
+            }
+        });
+    }
+});
diff -r 1dedce48e3e1 -r 2c8aa09402a2 app/view/grid/PKommentar.js
--- a/app/view/grid/PKommentar.js	Tue Mar 10 12:11:50 2015 +0100
+++ b/app/view/grid/PKommentar.js	Tue Mar 10 14:31:07 2015 +0100
@@ -14,12 +14,13 @@
     alias: 'widget.pkommentargrid',
 
     requires: [
-        'Ext.toolbar.Toolbar'
+        'Ext.toolbar.Toolbar',
+        'Lada.store.PKommentare'
     ],
 
     maxHeight: 350,
     emptyText: 'Keine Kommentaregefunden.',
-    minHeight: 65,
+    minHeight: 110,
     viewConfig: {
         deferEmptyText: false
     },
@@ -27,11 +28,11 @@
     recordId: null,
 
     initComponent: function() {
-        var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
+        this.rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
             clicksToMoveEditor: 1,
             autoCancel: false
         });
-        this.plugins = [rowEditing];
+        this.plugins = [this.rowEditing];
         this.dockedItems = [{
             xtype: 'toolbar',
             dock: 'bottom',
@@ -49,7 +50,20 @@
         this.columns = [{
             header: 'Erzeuger',
             dataIndex: 'erzeuger',
+            width: 140,
+            renderer: function(value) {
+                if (!value || value === '') {
+                    return '';
+                }
+                var store = Ext.data.StoreManager.get('messstellen');
+                var record = store.getById(value);
+                return record.get('messStelle');
+            },
             editor: {
+                xtype: 'combobox',
+                store: Ext.data.StoreManager.get('messstellen'),
+                displayField: 'messStelle',
+                valueField: 'id',
                 allowBlank: false
             }
         }, {
@@ -65,10 +79,25 @@
             header: 'Text',
             dataIndex: 'text',
             flex: 1,
+            renderer: function(value) {
+                return '<div style="white-space: normal !important;">' +
+                    value + '</div>';
+            },
             editor: {
+                xtype: 'textarea',
                 allowBlank: false
             }
         }];
+        this.initData();
         this.callParent(arguments);
+    },
+
+    initData: function() {
+        this.store = Ext.create('Lada.store.PKommentare');
+        this.store.load({
+            params: {
+                probeId: this.recordId
+            }
+        });
     }
 });


More information about the Lada-commits mailing list