comparison app/controller/grid/Messmethode.js @ 766:31eaed998531

enabled removal and creation of messgroessen for a messmethode
author Dustin Demuth <dustin@intevation.de>
date Tue, 12 May 2015 14:24:41 +0200
parents 62721a75d31d
children 5ee59111b188
comparison
equal deleted inserted replaced
765:62721a75d31d 766:31eaed998531
9 /** 9 /**
10 * This is a controller for a grid of Messmethode 10 * This is a controller for a grid of Messmethode
11 */ 11 */
12 Ext.define('Lada.controller.grid.Messmethode', { 12 Ext.define('Lada.controller.grid.Messmethode', {
13 extend: 'Ext.app.Controller', 13 extend: 'Ext.app.Controller',
14 record: null,
14 15
15 /** 16 /**
16 * Inhitialize the controller 17 * Inhitialize the controller
17 * It has 3 listeners 18 * It has 3 listeners
18 */ 19 */
26 'messmethodengrid button[action=add]': { 27 'messmethodengrid button[action=add]': {
27 click: this.add 28 click: this.add
28 }, 29 },
29 'messmethodengrid button[action=delete]': { 30 'messmethodengrid button[action=delete]': {
30 click: this.remove 31 click: this.remove
32 },
33 //Nuklidegrid
34 'nuklidegrid': {
35 edit: this.gridSaveNuklid,
36 canceledit: this.cancelEdit
37 },
38 'nuklidegrid button[action=add]': {
39 click: this.addNuklid
40 },
41 'nuklidegrid button[action=remove]': {
42 click: this.removeNuklid
31 } 43 }
32 }); 44 });
33 }, 45 },
34 46
35 /** 47 /**
37 * the record. 49 * the record.
38 * On success it refreshes the windows which contains the grid 50 * On success it refreshes the windows which contains the grid
39 * On failure it displays a message 51 * On failure it displays a message
40 */ 52 */
41 gridSave: function(editor, context) { 53 gridSave: function(editor, context) {
42 console.log(context);
43 context.record.save({ 54 context.record.save({
44 success: function() { 55 success: function() {
45 context.grid.initData(); 56 context.grid.initData();
46 context.grid.up('window').initData(); 57 context.grid.up('window').initData();
47 }, 58 },
63 } 74 }
64 }); 75 });
65 }, 76 },
66 77
67 /** 78 /**
79 * This function is called when the Nuklide-grids roweditor saves
80 * the record.
81 * It adds the nuklid to the messgroessen-array of the messmethode
82 * record.
83 * On success it refreshes the windows which contains the grid
84 * On failure it displays a message
85 */
86 gridSaveNuklid: function(editor, context) {
87 console.log(context);
88 this.syncArray(context.store);
89 },
90
91 /**
68 * When the edit was canceled, 92 * When the edit was canceled,
69 * the empty row might have been created by the roweditor is removed 93 * the empty row might have been created by the roweditor is removed
70 */ 94 */
71 cancelEdit: function(editor, context) { 95 cancelEdit: function(editor, context) {
72 if (!context.record.get('id') || 96 if (!context.record.get('id') ||
73 context.record.get('id') === '') { 97 context.record.get('id') === '') {
74 editor.getCmp().store.remove(context.record); 98 editor.getCmp().store.remove(context.record);
75 } 99 }
76 }, 100 },
80 * the nuklid-grid will be updated 104 * the nuklid-grid will be updated
81 * to display the nuklide which are possible for this 105 * to display the nuklide which are possible for this
82 * Messmethod 106 * Messmethod
83 */ 107 */
84 selectRow: function(row, record, index) { 108 selectRow: function(row, record, index) {
109 //save the record to this object. which makes it accessible
110 //for nuklideGrid releated functions.
111 this.record = record;
112 var nuklide = record.get('messgroessen');
113
85 var ngrid = row.view.up('window').down('nuklidegrid'); 114 var ngrid = row.view.up('window').down('nuklidegrid');
86 var nuklide = record.get('messgroessen'); 115
116 var mmtmessgroessenstore = this.buildNuklideStore(nuklide);
117 //Set Store
118 ngrid.setData(mmtmessgroessenstore);
119
120 //Enable Editing
121 ngrid.setReadOnly(false);
122 },
123
124 /**
125 * This function syncs the Messmethoden-Messgroessen Array
126 * With the Nuklide Store.
127 * It simply overwrites the Array
128 */
129 syncArray: function(store) {
130 var mg = new Array();
131 console.log('syncarray');
132 console.log(store);
133 var item;
134 for (item in store.data.items){
135 mg.push(store.data.items[item].get('id'));
136 }
137
138 // Ext.Array.contains(mg, id[i])
139 this.record.set('messgroessen', mg);
140 var me = this;
141 this.record.save({
142 success: function() {
143 console.log('Success');
144 console.log(me.record.get('messgroessen'));
145 console.log(mg);
146 },
147 failure: function(request, response) {
148 var json = response.request.scope.reader.jsonData;
149 if (json) {
150 if (json.message){
151 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title')
152 +' #'+json.message,
153 Lada.getApplication().bundle.getMsg(json.message));
154 } else {
155 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'),
156 Lada.getApplication().bundle.getMsg('err.msg.generic.body'));
157 }
158 } else {
159 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'),
160 Lada.getApplication().bundle.getMsg('err.msg.response.body'));
161 }
162 }
163 });
164
165 },
166
167 /**
168 * Return a MessgroessenStore created from nuklide array
169 */
170 buildNuklideStore: function(nuklide) {
171 // Create a fully populated Messgroessen Store
87 var store = Ext.data.StoreManager.get('messgroessen'); 172 var store = Ext.data.StoreManager.get('messgroessen');
88 if (!store) { 173 if (!store) {
89 store = Ext.create('Lada.store.Messgroessen'); 174 store = Ext.create('Lada.store.Messgroessen');
90 } 175 }
91 //get selection model 176
92 var selectedRecords = []; 177 //Create an empty Messgroessen Store which will be populated with the
93 //iterate store and slecet all records which are in nuklide array 178 //Messgroessen defined in the Messmethoden record.
94 store.each(function(record){ 179 var mmtmessgroessenstore = Ext.create('Ext.data.Store', {
95 //TODO if(record.get('id') in nuklide){ 180 model: 'Lada.model.Messgroesse',
96 selectedRecords.push(record); 181 });
97 //TODO} 182
98 }); 183 // Copy every Record from Messgroessenstore to the empty Store
99 ngrid.setData(store); 184 // which was defined in the messmethode record
100 185 for (n in nuklide) {
101 var selModel = ngrid.getSelectionModel(); 186 mmtmessgroessenstore.add(store.getById(nuklide[n]));
102 console.log(selModel); 187 }
103 selModel.select(selectedRecords, false, false); 188 return mmtmessgroessenstore;
189 },
190
191 /**
192 * This function adds a new row in the NuklidGrid
193 */
194 addNuklid: function(button) {
195 var record = Ext.create('Lada.model.Messgroesse');
196 button.up('nuklidegrid').store.insert(0, record);
197 button.up('nuklidegrid').rowEditing.startEdit(0, 0);
198 },
199
200 /**
201 * A row can be removed from the Nuklidgrid with the remove
202 * function. It asks the user for confirmation
203 * If the removal was confirmed, it reloads the parent window on success,
204 * on failure, an error message is shown.
205 */
206 removeNuklid: function(button) {
207 var grid = button.up('grid');
208 var selection = grid.getView().getSelectionModel().getSelection()[0];
209 grid.getStore().remove(selection);
210 var store = grid.getStore();
211 this.syncArray(store);
104 }, 212 },
105 213
106 /** 214 /**
107 * This function adds a new row 215 * This function adds a new row
108 */ 216 */

http://lada.wald.intevation.org