changeset 287:12e7f0ef90b6

Move more methods into the BaseController.
author Torsten Irländer <torsten.irlaender@intevation.de>
date Fri, 09 Aug 2013 14:58:13 +0200
parents c509e9f6d4db
children ea60be45fd4d
files app/controller/Base.js
diffstat 1 files changed, 52 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/app/controller/Base.js	Fri Aug 09 14:21:08 2013 +0200
+++ b/app/controller/Base.js	Fri Aug 09 14:58:13 2013 +0200
@@ -37,7 +37,11 @@
      * Method to save the kommentar in the database. The method is called when
      * the user clicks on the "Save" button
      */
-    saveItem: function(button) {},
+    saveItem: function(button) {
+        console.log('Saving ...');
+        var form = button.up('window').down('form');
+        form.commit();
+    },
     /**
      * Method to open a window to enter the values for a new kommentar.
      * The method is called when the user clicks on the "Add" button in the
@@ -57,15 +61,58 @@
      * The method is called when the user selects the item in the grid and
      * selects the delete button in the grid toolbar.
      */
-    deleteItem: function(button) {},
+    deleteItem: 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'){
+                var store = grid.getStore();
+                var deleteUrl = selection.getProxy().url + selection.getEidi();
+                Ext.Ajax.request({
+                    url: deleteUrl,
+                    method: 'DELETE',
+                    success: function(response, opts) {
+                        store.reload();
+                    }
+                });
+                console.log('Deleting ' + selection);
+            } else {
+                console.log('Cancel Deleting ' + selection);
+            }
+        });
+    },
     /**
-     * Method to trigger the action after successfull save (create or edit).
+     * Method to trigger the action after successfull save (create).
      * In this case the related store is refreshed and the window is closed.
      */
     createSuccess: function(form, record, operation) {},
     /**
-     * Method to trigger the action after save (create or edit) fails.
+     * Method to trigger the action after save (create) fails.
      * In this case a Message Boss with a general error is shown.
      */
-    createFailure: function(form, record, operation) {}
+    createFailure: function(form, record, operation) {
+        Ext.MessageBox.show({
+            title: 'Fehler beim Speichern',
+            msg: form.message,
+            icon: Ext.MessageBox.ERROR,
+            buttons: Ext.Msg.OK
+        });
+    },
+    /**
+     * Method to trigger the action after successfull save (edit).
+     * In this case the related store is refreshed and the window is closed.
+     */
+    editSuccess: function(form, record, operation) {},
+    /**
+     * Method to trigger the action after save ( edit) fails.
+     * In this case a Message Boss with a general error is shown.
+     */
+    editFailure: function(form, record, operation) {
+        Ext.MessageBox.show({
+            title: 'Fehler beim Speichern',
+            msg: form.message,
+            icon: Ext.MessageBox.ERROR,
+            buttons: Ext.Msg.OK
+        });
+    },
 });

http://lada.wald.intevation.org