Mercurial > lada > lada-client
comparison app/controller/Ort.js @ 1051:981339d774b8
merged stammdatengrids to default.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Tue, 01 Mar 2016 14:12:39 +0100 |
parents | e0b5e64928c9 |
children | e4952906634d |
comparison
equal
deleted
inserted
replaced
1048:eacf25f071c0 | 1051:981339d774b8 |
---|---|
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]')) { | |
108 panel.down('button[action=delete]').disable(); | |
109 } | |
110 else { | |
111 if (panel.down('ortstammdatengrid').getPlugin('rowedit') && | |
112 !panel.down('ortstammdatengrid').getPlugin('rowedit').editing && | |
113 panel.down('button[action=delete]')) { | |
114 //only enable buttons, when grid is not beeing edited | |
115 panel.down('button[action=delete]').enable(); | |
116 } | |
117 //else turn them off again! | |
118 else if (panel.down('button[action=delete]')) { | |
119 panel.down('button[action=delete]').disable(); | |
120 } | |
121 } | |
122 } | |
123 }); |