comparison app/controller/Ort.js @ 1130:e4952906634d

Implemented insert, edit and delete for stammdaten.ort.
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 25 May 2016 14:04:51 +0200
parents 981339d774b8
children c213c3dc51d2
comparison
equal deleted inserted replaced
1126:f1d234a7adc7 1130:e4952906634d
10 */ 10 */
11 init: function() { 11 init: function() {
12 var me = this; 12 var me = this;
13 this.control({ 13 this.control({
14 'ortpanel button[action=addMap]': { 14 'ortpanel button[action=addMap]': {
15 click: me.addFeature 15 click: me.activateDraw
16 }, 16 },
17 'ortpanel button[action=add]': { 17 'ortpanel button[action=add]': {
18 click: me.addRecord 18 click: me.addRecord
19 }, 19 },
20 'ortpanel button[action=delete]': { 20 'ortpanel button[action=delete]': {
21 click: me.deleteItem 21 click: me.deleteItem
22 }, 22 },
23 'ortpanel ortstammdatengrid': { 23 'ortpanel ortstammdatengrid': {
24 edit: me.gridSave, 24 edit: me.gridSave,
25 canceledit: me.cancelEdit, 25 canceledit: me.cancelEdit,
26 select: me.activateButtons, 26 select: me.select
27 deselect: me.deactivateButtons 27 },
28 'ortpanel map': {
29 featureadded: me.featureadded
28 } 30 }
29 }); 31 });
30 }, 32 },
31 33
32 addFeature: function(button) { 34 featureadded: function(record) {
33 console.log('add feature'); 35 var grid = Ext.ComponentQuery.query('ortpanel ortstammdatengrid')[0];
36 if (!record.get('letzteAenderung')) {
37 record.data.letzteAenderung = new Date();
38 }
39 grid.store.insert(0, record);
40 grid.rowEditing.startEdit(0, 1);
41 },
42
43 activateDraw: function(button) {
44 var map = button.up('ortpanel').down('map');
45 var record = Ext.create('Lada.model.Ort');
46 map.activateDraw(record);
34 }, 47 },
35 48
36 addRecord: function(button) { 49 addRecord: function(button) {
37 console.log('add record'); 50 console.log('add record');
51 var record = Ext.create('Lada.model.Ort');
52 var grid = button.up('ortpanel').down('ortstammdatengrid');
53 if (!record.get('letzteAenderung')) {
54 record.data.letzteAenderung = new Date();
55 }
56 grid.store.insert(0, record);
57 grid.rowEditing.startEdit(0, 1);
38 }, 58 },
39 59
40 deleteItem: function(button) { 60 deleteItem: function(button) {
41 console.log('delete item'); 61 var grid = button.up('ortpanel').down('ortstammdatengrid');
62 var selection = grid.getView().getSelectionModel().getSelection()[0];
63 var i18n = Lada.getApplication().bundle;
64 Ext.MessageBox.confirm(i18n.getMsg('delete'),
65 i18n.getMsg('confirmation.question'),
66 function(btn) {
67 if (btn === 'yes') {
68 selection.destroy({
69 success: function() {
70 //DO NOTHING
71 },
72 failure: function(request, response) {
73 var json = response.request.scope.reader.jsonData;
74 if (json) {
75 if (json.message){
76 Ext.Msg.alert(i18n.getMsg('err.msg.delete.title')
77 +' #'+json.message,
78 i18n.getMsg(json.message));
79 } else {
80 Ext.Msg.alert(i18n.getMsg('err.msg.delete.title'),
81 i18n.getMsg('err.msg.generic.body'));
82 }
83 } else {
84 Ext.Msg.alert(i18n.getMsg('err.msg.delete.title'),
85 i18n.getMsg('err.msg.response.body'));
86 }
87 }
88 });
89 }
90 });
91 grid.up('ortpanel').down('button[action=delete]').disable();
92 },
93
94 select: function(rowModel, record) {
95 this.checkEdit(rowModel, record);
96 this.buttonToggle(rowModel, record);
97 },
98
99 checkEdit: function(rowModel, record) {
100 if (!Ext.Array.contains(Lada.netzbetreiber,
101 record.get('netzbetreiberId')) &&
102 record.get('netzbetreiberId') !== '') {
103 var grid = Ext.ComponentQuery.query('ortpanel ortstammdatengrid')[0];
104 grid.rowEditing.cancelEdit();
105 return;
106 }
42 }, 107 },
43 108
44 /** 109 /**
45 * This function is called when the grids roweditor saves 110 * This function is called when the grids roweditor saves
46 * the record. 111 * the record.
49 */ 114 */
50 gridSave: function(editor, context) { 115 gridSave: function(editor, context) {
51 var i18n = Lada.getApplication().bundle; 116 var i18n = Lada.getApplication().bundle;
52 context.record.save({ 117 context.record.save({
53 success: function(record, response) { 118 success: function(record, response) {
54 //Do Nothing 119 var grid = Ext.ComponentQuery.query('ortstammdatengrid')[0];
120 grid.store.reload();
55 }, 121 },
56 failure: function(record, response) { 122 failure: function(record, response) {
57 var json = response.request.scope.reader.jsonData; 123 var json = response.request.scope.reader.jsonData;
58 if (json) { 124 if (json) {
59 if (json.message){ 125 if (json.message){
78 context.record.get('id') === '') { 144 context.record.get('id') === '') {
79 editor.getCmp().store.remove(context.record); 145 editor.getCmp().store.remove(context.record);
80 } 146 }
81 context.grid.getSelectionModel().deselect(context.record); 147 context.grid.getSelectionModel().deselect(context.record);
82 }, 148 },
83 /**
84 * Toggles the buttons in the toolbar
85 **/
86 activateButtons: function(rowModel, record) {
87 var panel = rowModel.view.up('ortpanel');
88 this.buttonToggle(true, panel);
89 },
90
91 /**
92 * Toggles the buttons in the toolbar
93 **/
94 deactivateButtons: function(rowModel, record) {
95 var panel = rowModel.view.up('ortpanel');
96 // Only disable buttons when nothing is selected
97 if (rowModel.selected.items == 0) {
98 this.buttonToggle(false, panel);
99 }
100 },
101 149
102 /** 150 /**
103 * Enables/Disables a set of buttons 151 * Enables/Disables a set of buttons
104 **/ 152 **/
105 buttonToggle: function(enabled, panel) { 153 buttonToggle: function(rowModel, record) {
154 if (!Ext.Array.contains(Lada.funktionen, 4)) {
155 return;
156 }
157 var grid = Ext.ComponentQuery.query('ortstammdatengrid')[0];
158 if (!record ||
159 !Ext.Array.contains(Lada.netzbetreiber,
160 record.get('netzbetreiberId'))) {
161 grid.up('ortpanel').down('button[action=delete]').disable();
162 return;
163 }
164 if (record.get('readonly') ||
165 rowModel.selected.items.length === 0) {
166 grid.up('ortpanel').down('button[action=delete]').disable();
167 }
168 else {
169 if (grid.getPlugin('rowedit').editing) {
170 //only enable buttons, when grid is not beeing edited
171 grid.up('ortpanel').down('button[action=delete]').disable();
172 }
173 else {
174 grid.up('ortpanel').down('button[action=delete]').enable();
175 }
176 }
177 /*
106 if (!enabled && 178 if (!enabled &&
107 panel.down('button[action=delete]')) { 179 panel.down('button[action=delete]')) {
108 panel.down('button[action=delete]').disable(); 180 panel.down('button[action=delete]').disable();
109 } 181 }
110 else { 182 else {
117 //else turn them off again! 189 //else turn them off again!
118 else if (panel.down('button[action=delete]')) { 190 else if (panel.down('button[action=delete]')) {
119 panel.down('button[action=delete]').disable(); 191 panel.down('button[action=delete]').disable();
120 } 192 }
121 } 193 }
194 */
122 } 195 }
123 }); 196 });

http://lada.wald.intevation.org