Mercurial > lada > lada-client
comparison app/controller/grid/Probenehmer.js @ 984:b21421ba6917 stammdatengrids
added buttons for datensatzerzeuger, pobenehmer, added controllers
author | Dustin Demuth <dustin@intevation.de> |
---|---|
date | Thu, 10 Dec 2015 08:30:14 +0100 |
parents | |
children | 15d8c64049d1 |
comparison
equal
deleted
inserted
replaced
983:0a5fe163f1c8 | 984:b21421ba6917 |
---|---|
1 /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz | |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU GPL (v>=3) | |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out | |
6 * the documentation coming with IMIS-Labordaten-Application for details. | |
7 */ | |
8 | |
9 /** | |
10 * This is a controller for a grid of Probenehmer Stammdaten | |
11 */ | |
12 Ext.define('Lada.controller.grid.Probenehmer', { | |
13 extend: 'Ext.app.Controller', | |
14 | |
15 /** | |
16 * Inhitialize the controller | |
17 * It has 3 listeners | |
18 */ | |
19 init: function() { | |
20 this.control({ | |
21 'probenehmergrid': { | |
22 edit: this.gridSave, | |
23 canceledit: this.cancelEdit, | |
24 select: this.activateButtons, | |
25 deselect: this.deactivateButtons | |
26 }, | |
27 'probenehmergrid button[action=add]': { | |
28 click: this.add | |
29 }, | |
30 'probenehmergrid button[action=delete]': { | |
31 click: this.remove | |
32 } | |
33 }); | |
34 }, | |
35 | |
36 /** | |
37 * This function is called when the grids roweditor saves | |
38 * the record. | |
39 * On success it refreshes the windows which contains the grid | |
40 * On failure it displays a message | |
41 */ | |
42 gridSave: function(editor, context) { | |
43 context.record.save({ | |
44 success: function(record, response) { | |
45 //Do Nothing | |
46 }, | |
47 failure: function(record, response) { | |
48 var json = response.request.scope.reader.jsonData; | |
49 if (json) { | |
50 if (json.message){ | |
51 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title') | |
52 +' #'+json.message, | |
53 Lada.getApplication().bundle.getMsg(json.message)); | |
54 } else { | |
55 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'), | |
56 Lada.getApplication().bundle.getMsg('err.msg.generic.body')); | |
57 } | |
58 } | |
59 } | |
60 }); | |
61 }, | |
62 | |
63 /** | |
64 * When the edit was canceled, | |
65 * the empty row might have been created by the roweditor is removed | |
66 */ | |
67 cancelEdit: function(editor, context) { | |
68 if (!context.record.get('id') || | |
69 context.record.get('id') === '') { | |
70 editor.getCmp().store.remove(context.record); | |
71 } | |
72 context.grid.getSelectionModel().deselect(context.record); | |
73 }, | |
74 | |
75 /** | |
76 * This function adds a new row to add a probenehmer | |
77 */ | |
78 add: function(button) { | |
79 var record = Ext.create('Lada.model.Probenehmer'); | |
80 button.up('probenehmergrid').store.insert(0, record); | |
81 button.up('probenehmergrid').rowEditing.startEdit(0, 1); | |
82 }, | |
83 | |
84 /** | |
85 * A record can be removed from the grid with the remove | |
86 * function. It asks the user for confirmation | |
87 * If the removal was confirmed, it reloads the parent window on success, | |
88 * on failure, an error message is shown. | |
89 */ | |
90 remove: function(button) { | |
91 var grid = button.up('grid'); | |
92 var selection = grid.getView().getSelectionModel().getSelection()[0]; | |
93 //TODO: i18n | |
94 Ext.MessageBox.confirm('Löschen', 'Sind Sie sicher?', function(btn) { | |
95 if (btn === 'yes') { | |
96 selection.destroy({ | |
97 success: function() { | |
98 //DO NOTHING | |
99 }, | |
100 failure: function(request, response) { | |
101 var json = response.request.scope.reader.jsonData; | |
102 if (json) { | |
103 if (json.message){ | |
104 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.delete.title') | |
105 +' #'+json.message, | |
106 Lada.getApplication().bundle.getMsg(json.message)); | |
107 } else { | |
108 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.delete.title'), | |
109 Lada.getApplication().bundle.getMsg('err.msg.generic.body')); | |
110 } | |
111 } else { | |
112 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.delete.title'), | |
113 Lada.getApplication().bundle.getMsg('err.msg.response.body')); | |
114 } | |
115 } | |
116 }); | |
117 } | |
118 }); | |
119 grid.down('button[action=delete]').disable(); | |
120 }, | |
121 /** | |
122 * Toggles the buttons in the toolbar | |
123 **/ | |
124 activateButtons: function(rowModel, record) { | |
125 var grid = rowModel.view.up('grid'); | |
126 this.buttonToggle(true, grid); | |
127 }, | |
128 | |
129 /** | |
130 * Toggles the buttons in the toolbar | |
131 **/ | |
132 deactivateButtons: function(rowModel, record) { | |
133 var grid = rowModel.view.up('grid'); | |
134 // Only disable buttons when nothing is selected | |
135 if (rowModel.selected.items == 0) { | |
136 this.buttonToggle(false, grid); | |
137 } | |
138 }, | |
139 | |
140 /** | |
141 * Enables/Disables a set of buttons | |
142 **/ | |
143 buttonToggle: function(enabled, grid) { | |
144 if (!enabled) { | |
145 grid.down('button[action=delete]').disable(); | |
146 } | |
147 else { | |
148 if (!grid.getPlugin('rowedit').editing) { | |
149 //only enable buttons, when grid is not beeing edited | |
150 grid.down('button[action=delete]').enable(); | |
151 } | |
152 //else turn them off again! | |
153 else { | |
154 this.buttonToggle(false, grid); | |
155 } | |
156 } | |
157 }, | |
158 }); | |
159 |