[Lada-commits] [PATCH 02 of 56] Added BaseController and inherit Kommentar controller from it

Wald Commits scm-commit at wald.intevation.org
Tue Aug 13 09:53:28 CEST 2013


# HG changeset patch
# User Torsten Irländer <torsten.irlaender at intevation.de>
# Date 1376050868 -7200
# Node ID c509e9f6d4db089f5ceab1921e61dd7f3e43b609
# Parent  6c030e5739a71e284d9efae20c4ffcfca2db31eb
Added BaseController and inherit Kommentar controller from it.

diff -r 6c030e5739a7 -r c509e9f6d4db app/controller/Base.js
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/controller/Base.js	Fri Aug 09 14:21:08 2013 +0200
@@ -0,0 +1,71 @@
+/**
+ * Base Controller
+ *
+ * The controller defines the main logic of the application. It provides
+ * various methods which are bound to listeners and called when the defined
+ * events in the various UI elements occour (e.g User clicks on a button)
+ */
+Ext.define('Lada.controller.Base', {
+    extend: 'Ext.app.Controller',
+    /**
+     * Define required views for this controller
+     */
+    views: [],
+    /**
+     * Define required stores for this controller
+     */
+    stores: [],
+    /**
+     * Define required models for this controller
+     */
+    models: [],
+    init: function() {
+        console.log('Initialising the Kommentare controller');
+        this.addListeners();
+    },
+    /**
+     * Function to add listeners for various events in UI items. The UI Items are selected
+     * with a CSS like selector.See ComponentQuery documentation for more
+     * details. The function is called while initializing the controller.
+     *
+     * The function should be overwritten by a specfic implementation.
+     */
+    addListeners: function() {
+        this.control({});
+    },
+    /**
+     * Method to save the kommentar in the database. The method is called when
+     * the user clicks on the "Save" button
+     */
+    saveItem: function(button) {},
+    /**
+     * 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
+     * grid toolbar.
+     */
+    addItem: function(button) {},
+    /**
+     * Method to open a window to edit the values for an existing kommentar.
+     * The method is called when the user doubleclicks on the item in the
+     * grid.
+     */
+    editItem: function(grid, record) {},
+    /**
+     * Method to delete a kommentar. This will trigger the display of a
+     * Confirmation dialog. After the deletion the related store will be
+     * refreshed.
+     * 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) {},
+    /**
+     * Method to trigger the action after successfull save (create or edit).
+     * 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.
+     * In this case a Message Boss with a general error is shown.
+     */
+    createFailure: function(form, record, operation) {}
+});
diff -r 6c030e5739a7 -r c509e9f6d4db app/controller/Kommentare.js
--- a/app/controller/Kommentare.js	Fri Aug 09 12:56:32 2013 +0200
+++ b/app/controller/Kommentare.js	Fri Aug 09 14:21:08 2013 +0200
@@ -1,12 +1,8 @@
 /**
  * Controller for Kommentare
- *
- * The controller defines the main logic of the application. It provides
- * various methods which are bound to listeners and called when the defined
- * events in the various UI elements occour (e.g User clicks on a button)
  */
 Ext.define('Lada.controller.Kommentare', {
-    extend: 'Ext.app.Controller',
+    extend: 'Lada.controller.Base',
     views: [
         'kommentare.Create'
     ],
@@ -16,22 +12,19 @@
     models: [
         'Kommentar'
     ],
-    init: function() {
-        console.log('Initialising the Kommentare controller');
+    addListeners: function() {
         this.control({
-            // CSS like selector to select element in the viewport. See
-            // ComponentQuery documentation for more details.
             'kommentarelist': {
-                itemdblclick: this.editKommentar
+                itemdblclick: this.editItem
             },
             'kommentarelist toolbar button[action=add]': {
-                click: this.addKommentar
+                click: this.addItem
             },
             'kommentarelist toolbar button[action=delete]': {
-                click: this.deleteKommentar
+                click: this.deleteItem
             },
             'kommentarecreate button[action=save]': {
-                click: this.saveKommentar
+                click: this.saveItem
             },
             'kommentarecreate form': {
                 savesuccess: this.createSuccess,
@@ -39,45 +32,23 @@
             }
         });
     },
-    /**
-     * Method to save the kommentar in the database. The method is called when
-     * the user clicks on the "Save" button
-     */
-    saveKommentar: function(button) {
+    saveItem: function(button) {
         console.log('Saving Kommentar');
         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
-     * grid toolbar.
-     */
-    addKommentar: function(button) {
+    addItem: function(button) {
         console.log('Adding new Kommentar for Probe ' + button.probeId);
         var kommentar = Ext.create('Lada.model.Kommentar');
         kommentar.set('probeId', button.probeId);
         var view = Ext.widget('kommentarecreate', {model: kommentar});
     },
-    /**
-     * Method to open a window to edit the values for an existing kommentar.
-     * The method is called when the user doubleclicks on the item in the
-     * grid.
-     */
-    editKommentar: function(grid, record) {
+    editItem: function(grid, record) {
         console.log('Editing Kommentar');
         var view = Ext.widget('kommentarecreate', {model: record});
         console.log("Loaded Kommentar with ID " + record.getId()); //outputs ID
     },
-    /**
-     * Method to delete a kommentar. This will trigger the display of a
-     * Confirmation dialog. After the deletion the related store will be
-     * refreshed.
-     * The method is called when the user selects the item in the grid and
-     * selects the delete button in the grid toolbar.
-     */
-    deleteKommentar: function(button) {
-        // Get selected item in grid
+    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){
@@ -97,21 +68,12 @@
             }
         });
     },
-    /**
-     * Method to trigger the action after successfull save (create or edit).
-     * In this case the related store is refreshed and the window is closed.
-     */
     createSuccess: function(form, record, operation) {
-        // Reload store
         var store = this.getKommentareStore();
         store.reload();
         var win = form.up('window');
         win.close();
     },
-    /**
-     * Method to trigger the action after save (create or edit) fails.
-     * In this case a Message Boss with a general error is shown.
-     */
     createFailure: function(form, record, operation) {
         Ext.MessageBox.show({
             title: 'Fehler beim Speichern',


More information about the Lada-commits mailing list