comparison app/controller/Kommentare.js @ 286:c509e9f6d4db

Added BaseController and inherit Kommentar controller from it.
author Torsten Irländer <torsten.irlaender@intevation.de>
date Fri, 09 Aug 2013 14:21:08 +0200
parents 6c030e5739a7
children ea60be45fd4d
comparison
equal deleted inserted replaced
285:6c030e5739a7 286:c509e9f6d4db
1 /** 1 /**
2 * Controller for Kommentare 2 * Controller for Kommentare
3 *
4 * The controller defines the main logic of the application. It provides
5 * various methods which are bound to listeners and called when the defined
6 * events in the various UI elements occour (e.g User clicks on a button)
7 */ 3 */
8 Ext.define('Lada.controller.Kommentare', { 4 Ext.define('Lada.controller.Kommentare', {
9 extend: 'Ext.app.Controller', 5 extend: 'Lada.controller.Base',
10 views: [ 6 views: [
11 'kommentare.Create' 7 'kommentare.Create'
12 ], 8 ],
13 stores: [ 9 stores: [
14 'Kommentare' 10 'Kommentare'
15 ], 11 ],
16 models: [ 12 models: [
17 'Kommentar' 13 'Kommentar'
18 ], 14 ],
19 init: function() { 15 addListeners: function() {
20 console.log('Initialising the Kommentare controller');
21 this.control({ 16 this.control({
22 // CSS like selector to select element in the viewport. See
23 // ComponentQuery documentation for more details.
24 'kommentarelist': { 17 'kommentarelist': {
25 itemdblclick: this.editKommentar 18 itemdblclick: this.editItem
26 }, 19 },
27 'kommentarelist toolbar button[action=add]': { 20 'kommentarelist toolbar button[action=add]': {
28 click: this.addKommentar 21 click: this.addItem
29 }, 22 },
30 'kommentarelist toolbar button[action=delete]': { 23 'kommentarelist toolbar button[action=delete]': {
31 click: this.deleteKommentar 24 click: this.deleteItem
32 }, 25 },
33 'kommentarecreate button[action=save]': { 26 'kommentarecreate button[action=save]': {
34 click: this.saveKommentar 27 click: this.saveItem
35 }, 28 },
36 'kommentarecreate form': { 29 'kommentarecreate form': {
37 savesuccess: this.createSuccess, 30 savesuccess: this.createSuccess,
38 savefailure: this.createFailure 31 savefailure: this.createFailure
39 } 32 }
40 }); 33 });
41 }, 34 },
42 /** 35 saveItem: function(button) {
43 * Method to save the kommentar in the database. The method is called when
44 * the user clicks on the "Save" button
45 */
46 saveKommentar: function(button) {
47 console.log('Saving Kommentar'); 36 console.log('Saving Kommentar');
48 var form = button.up('window').down('form'); 37 var form = button.up('window').down('form');
49 form.commit(); 38 form.commit();
50 }, 39 },
51 /** 40 addItem: function(button) {
52 * Method to open a window to enter the values for a new kommentar.
53 * The method is called when the user clicks on the "Add" button in the
54 * grid toolbar.
55 */
56 addKommentar: function(button) {
57 console.log('Adding new Kommentar for Probe ' + button.probeId); 41 console.log('Adding new Kommentar for Probe ' + button.probeId);
58 var kommentar = Ext.create('Lada.model.Kommentar'); 42 var kommentar = Ext.create('Lada.model.Kommentar');
59 kommentar.set('probeId', button.probeId); 43 kommentar.set('probeId', button.probeId);
60 var view = Ext.widget('kommentarecreate', {model: kommentar}); 44 var view = Ext.widget('kommentarecreate', {model: kommentar});
61 }, 45 },
62 /** 46 editItem: function(grid, record) {
63 * Method to open a window to edit the values for an existing kommentar.
64 * The method is called when the user doubleclicks on the item in the
65 * grid.
66 */
67 editKommentar: function(grid, record) {
68 console.log('Editing Kommentar'); 47 console.log('Editing Kommentar');
69 var view = Ext.widget('kommentarecreate', {model: record}); 48 var view = Ext.widget('kommentarecreate', {model: record});
70 console.log("Loaded Kommentar with ID " + record.getId()); //outputs ID 49 console.log("Loaded Kommentar with ID " + record.getId()); //outputs ID
71 }, 50 },
72 /** 51 deleteItem: function(button) {
73 * Method to delete a kommentar. This will trigger the display of a
74 * Confirmation dialog. After the deletion the related store will be
75 * refreshed.
76 * The method is called when the user selects the item in the grid and
77 * selects the delete button in the grid toolbar.
78 */
79 deleteKommentar: function(button) {
80 // Get selected item in grid
81 var grid = button.up('grid'); 52 var grid = button.up('grid');
82 var selection = grid.getView().getSelectionModel().getSelection()[0]; 53 var selection = grid.getView().getSelectionModel().getSelection()[0];
83 Ext.MessageBox.confirm('Löschen', 'Sind Sie sicher?', function(btn){ 54 Ext.MessageBox.confirm('Löschen', 'Sind Sie sicher?', function(btn){
84 if(btn === 'yes'){ 55 if(btn === 'yes'){
85 var store = grid.getStore(); 56 var store = grid.getStore();
95 } else { 66 } else {
96 console.log('Cancel Deleting Kommentar'); 67 console.log('Cancel Deleting Kommentar');
97 } 68 }
98 }); 69 });
99 }, 70 },
100 /**
101 * Method to trigger the action after successfull save (create or edit).
102 * In this case the related store is refreshed and the window is closed.
103 */
104 createSuccess: function(form, record, operation) { 71 createSuccess: function(form, record, operation) {
105 // Reload store
106 var store = this.getKommentareStore(); 72 var store = this.getKommentareStore();
107 store.reload(); 73 store.reload();
108 var win = form.up('window'); 74 var win = form.up('window');
109 win.close(); 75 win.close();
110 }, 76 },
111 /**
112 * Method to trigger the action after save (create or edit) fails.
113 * In this case a Message Boss with a general error is shown.
114 */
115 createFailure: function(form, record, operation) { 77 createFailure: function(form, record, operation) {
116 Ext.MessageBox.show({ 78 Ext.MessageBox.show({
117 title: 'Fehler beim Speichern', 79 title: 'Fehler beim Speichern',
118 msg: form.message, 80 msg: form.message,
119 icon: Ext.MessageBox.ERROR, 81 icon: Ext.MessageBox.ERROR,

http://lada.wald.intevation.org