comparison app/controller/Orte.js @ 292:73a2c114db64

Inherit from Base controller
author Torsten Irländer <torsten.irlaender@intevation.de>
date Fri, 09 Aug 2013 15:00:06 +0200
parents 4db982514a5f
children 6a7a9267e00f
comparison
equal deleted inserted replaced
291:e95662994c50 292:73a2c114db64
1 /**
2 * Controller for Orte
3 */
1 Ext.define('Lada.controller.Orte', { 4 Ext.define('Lada.controller.Orte', {
2 extend: 'Ext.app.Controller', 5 extend: 'Lada.controller.Base',
3 views: [ 6 views: [
4 'orte.List', 7 'orte.List',
5 'orte.Create' 8 'orte.Create'
6 ], 9 ],
7 stores: [ 10 stores: [
13 models: [ 16 models: [
14 'Ort' 17 'Ort'
15 ], 18 ],
16 init: function() { 19 init: function() {
17 console.log('Initialising the Orte controller'); 20 console.log('Initialising the Orte controller');
21 this.callParent();
22 },
23 addListeners: function() {
18 this.control({ 24 this.control({
19 // CSS like selector to select element in the viewport. See
20 // ComponentQuery documentation for more details.
21 'ortelist': { 25 'ortelist': {
22 itemdblclick: this.editOrt 26 itemdblclick: this.editItem
23 }, 27 },
24 'ortelist toolbar button[action=add]': { 28 'ortelist toolbar button[action=add]': {
25 click: this.addOrt 29 click: this.addItem
26 }, 30 },
27 'ortelist toolbar button[action=delete]': { 31 'ortelist toolbar button[action=delete]': {
28 click: this.deleteOrt 32 click: this.deleteItem
29 }, 33 },
30 'ortecreate button[action=save]': { 34 'ortecreate button[action=save]': {
31 click: this.saveOrt 35 click: this.saveItem
32 }, 36 },
33 'ortecreate form': { 37 'ortecreate form': {
34 savesuccess: this.createSuccess, 38 savesuccess: this.createSuccess,
35 savefailure: this.createFailure 39 savefailure: this.createFailure
36 }, 40 },
38 savesuccess: this.editSuccess, 42 savesuccess: this.editSuccess,
39 savefailure: this.editFailure 43 savefailure: this.editFailure
40 } 44 }
41 }); 45 });
42 }, 46 },
43 saveOrt: function(button) { 47 saveItem: function(button) {
44 console.log('Saving Ort'); 48 console.log('Saving Ort');
45 var form = button.up('window').down('form'); 49 var form = button.up('window').down('form');
46 var fform = form.getForm(); 50 var fform = form.getForm();
47 51
48 var ortdetail = null; 52 var ortdetail = null;
82 console.log('Error on saving Ortdetails'); 86 console.log('Error on saving Ortdetails');
83 } 87 }
84 }); 88 });
85 89
86 }, 90 },
87 addOrt: function(button) { 91 addItem: function(button) {
88 console.log('Adding new Ort for Probe ' + button.probeId); 92 console.log('Adding new Ort for Probe ' + button.probeId);
89 var ort = Ext.create('Lada.model.Ort'); 93 var ort = Ext.create('Lada.model.Ort');
90 ort.set('probeId', button.probeId); 94 ort.set('probeId', button.probeId);
91 var view = Ext.widget('ortecreate', {model: ort}); 95 var view = Ext.widget('ortecreate', {model: ort});
92 }, 96 },
93 editOrt: function(grid, record) { 97 editItem: function(grid, record) {
94 console.log('Editing Ort'); 98 console.log('Editing Ort');
95 var view = Ext.widget('ortecreate', {model: record}); 99 var view = Ext.widget('ortecreate', {model: record});
96 console.log("Loaded Ort with ID " + record.getId()); //outputs ID 100 console.log("Loaded Ort with ID " + record.getId()); //outputs ID
97 },
98 deleteOrt: function(button) {
99 // Get selected item in grid
100 var grid = button.up('grid');
101 var selection = grid.getView().getSelectionModel().getSelection()[0];
102 Ext.MessageBox.confirm('Löschen', 'Sind Sie sicher?', function(btn){
103 if(btn === 'yes'){
104 var store = grid.getStore();
105 var deleteUrl = selection.getProxy().url + selection.getEidi();
106 Ext.Ajax.request({
107 url: deleteUrl,
108 method: 'DELETE',
109 success: function(response, opts) {
110 store.reload();
111 }
112 });
113 console.log('Deleting Ort');
114 } else {
115 console.log('Cancel Deleting Ort');
116 }
117 });
118 }, 101 },
119 createSuccess: function(form, record, operation) { 102 createSuccess: function(form, record, operation) {
120 // Reload store 103 // Reload store
121 var store = this.getOrteStore(); 104 var store = this.getOrteStore();
122 store.reload(); 105 store.reload();
123 var win = form.up('window'); 106 var win = form.up('window');
124 win.close(); 107 win.close();
125 }, 108 },
126 createFailure: function(form, record, operation) {
127 Ext.MessageBox.show({
128 title: 'Fehler beim Speichern',
129 msg: form.message,
130 icon: Ext.MessageBox.ERROR,
131 buttons: Ext.Msg.OK
132 });
133 },
134 editSuccess: function(form, record, operation) { 109 editSuccess: function(form, record, operation) {
135 // Reload store 110 // Reload store
136 var store = this.getOrteStore(); 111 var store = this.getOrteStore();
137 store.reload(); 112 store.reload();
138 var win = form.up('window'); 113 var win = form.up('window');
139 win.close(); 114 win.close();
140 },
141 editFailure: function(form, record, operation) {
142 Ext.MessageBox.show({
143 title: 'Fehler beim Speichern',
144 msg: form.message,
145 icon: Ext.MessageBox.ERROR,
146 buttons: Ext.Msg.OK
147 });
148 } 115 }
149 }); 116 });

http://lada.wald.intevation.org