comparison app/controller/Ort.js @ 1049:1bd4c0709bd6 stammdatengrids

Working version of selectable 'ort' in map and grid.
author Raimund Renkert <raimund.renkert@intevation.de>
date Tue, 01 Mar 2016 11:50:39 +0100
parents
children e0b5e64928c9
comparison
equal deleted inserted replaced
1028:2e7adc19b4fe 1049:1bd4c0709bd6
1 /**
2 *
3 */
4 Ext.define('Lada.controller.Ort', {
5 extend: 'Ext.app.Controller',
6
7 /**
8 * @private
9 * Initialize the controller.
10 */
11 init: function() {
12 var me = this;
13 this.control({
14 'ortpanel button[action=addMap]': {
15 click: me.addFeature
16 },
17 'ortpanel button[action=add]': {
18 click: me.addRecord
19 },
20 'ortpanel button[action=delete]': {
21 click: me.deleteItem
22 },
23 'ortpanel ortstammdatengrid': {
24 edit: me.gridSave,
25 canceledit: me.cancelEdit,
26 select: me.activateButtons,
27 deselect: me.deactivateButtons
28 }
29 });
30 },
31
32 addFeature: function(button) {
33 console.log('add feature');
34 },
35
36 addRecord: function(button) {
37 console.log('add record');
38 },
39
40 deleteItem: function(button) {
41 console.log('delete item');
42 },
43
44 /**
45 * This function is called when the grids roweditor saves
46 * the record.
47 * On success it refreshes the windows which contains the grid
48 * On failure it displays a message
49 */
50 gridSave: function(editor, context) {
51 var i18n = Lada.getApplication().bundle;
52 context.record.save({
53 success: function(record, response) {
54 //Do Nothing
55 },
56 failure: function(record, response) {
57 var json = response.request.scope.reader.jsonData;
58 if (json) {
59 if (json.message){
60 Ext.Msg.alert(i18n.getMsg('err.msg.save.title')
61 +' #'+json.message,
62 i18n.getMsg(json.message));
63 } else {
64 Ext.Msg.alert(i18n.getMsg('err.msg.save.title'),
65 i18n.getMsg('err.msg.generic.body'));
66 }
67 }
68 }
69 });
70 },
71
72 /**
73 * When the edit was canceled,
74 * the empty row might have been created by the roweditor is removed
75 */
76 cancelEdit: function(editor, context) {
77 if (!context.record.get('id') ||
78 context.record.get('id') === '') {
79 editor.getCmp().store.remove(context.record);
80 }
81 context.grid.getSelectionModel().deselect(context.record);
82 },
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
102 /**
103 * Enables/Disables a set of buttons
104 **/
105 buttonToggle: function(enabled, panel) {
106 if (!enabled) {
107 panel.down('button[action=delete]').disable();
108 }
109 else {
110 if (!panel.down('ortstammdatengrid').getPlugin('rowedit').editing) {
111 //only enable buttons, when grid is not beeing edited
112 panel.down('button[action=delete]').enable();
113 }
114 //else turn them off again!
115 else {
116 this.buttonToggle(false, panel);
117 }
118 }
119 }
120 });

http://lada.wald.intevation.org