comparison app/controller/grid/Datensatzerzeuger.js @ 1007:23bfcbdb4527

merged.
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 20 Jan 2016 17:33:33 +0100
parents 15d8c64049d1
children 77e22ad5cc84
comparison
equal deleted inserted replaced
1002:54179b6043b6 1007:23bfcbdb4527
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 Datensatzerzeuger Stammdaten
11 */
12 Ext.define('Lada.controller.grid.Datensatzerzeuger', {
13 extend: 'Ext.app.Controller',
14
15 /**
16 * Inhitialize the controller
17 * It has 3 listeners
18 */
19 init: function() {
20 this.control({
21 'datensatzerzeugergrid': {
22 edit: this.gridSave,
23 canceledit: this.cancelEdit,
24 select: this.activateButtons,
25 deselect: this.deactivateButtons
26 },
27 'datensatzerzeugergrid button[action=add]': {
28 click: this.add
29 },
30 'datensatzerzeugergrid 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 var i18n = Lada.getApplication().bundle;
44 context.record.save({
45 success: function(record, response) {
46 //Do Nothing
47 },
48 failure: function(record, response) {
49 var json = response.request.scope.reader.jsonData;
50 if (json) {
51 if (json.message){
52 Ext.Msg.alert(i18n.getMsg('err.msg.save.title')
53 +' #'+json.message,
54 i18n.getMsg(json.message));
55 } else {
56 Ext.Msg.alert(i18n.getMsg('err.msg.save.title'),
57 i18n.getMsg('err.msg.generic.body'));
58 }
59 }
60 }
61 });
62 },
63
64 /**
65 * When the edit was canceled,
66 * the empty row might have been created by the roweditor is removed
67 */
68 cancelEdit: function(editor, context) {
69 if (!context.record.get('id') ||
70 context.record.get('id') === '') {
71 editor.getCmp().store.remove(context.record);
72 }
73 context.grid.getSelectionModel().deselect(context.record);
74 },
75
76 /**
77 * This function adds a new row to add a Datensatzerzeuger
78 */
79 add: function(button) {
80 var record = Ext.create('Lada.model.DatensatzErzeuger');
81 button.up('datensatzerzeugergrid').store.insert(0, record);
82 button.up('datensatzerzeugergrid').rowEditing.startEdit(0, 1);
83 },
84
85 /**
86 * A record can be removed from the grid with the remove
87 * function. It asks the user for confirmation
88 * If the removal was confirmed, it reloads the parent window on success,
89 * on failure, an error message is shown.
90 */
91 remove: function(button) {
92 var grid = button.up('grid');
93 var selection = grid.getView().getSelectionModel().getSelection()[0];
94 var i18n = Lada.getApplication().bundle;
95 //TODO: i18n
96 Ext.MessageBox.confirm(i18n.getMsg('delete'),
97 i18n.getMsg('confirmation.question'),
98 function(btn) {
99 if (btn === 'yes') {
100 selection.destroy({
101 success: function() {
102 //DO NOTHING
103 },
104 failure: function(request, response) {
105 var json = response.request.scope.reader.jsonData;
106 if (json) {
107 if (json.message){
108 Ext.Msg.alert(i18n.getMsg('err.msg.delete.title')
109 +' #'+json.message,
110 i18n.getMsg(json.message));
111 } else {
112 Ext.Msg.alert(i18n.getMsg('err.msg.delete.title'),
113 i18n.getMsg('err.msg.generic.body'));
114 }
115 } else {
116 Ext.Msg.alert(i18n.getMsg('err.msg.delete.title'),
117 i18n.getMsg('err.msg.response.body'));
118 }
119 }
120 });
121 }
122 });
123 grid.down('button[action=delete]').disable();
124 },
125 /**
126 * Toggles the buttons in the toolbar
127 **/
128 activateButtons: function(rowModel, record) {
129 var grid = rowModel.view.up('grid');
130 this.buttonToggle(true, grid);
131 },
132
133 /**
134 * Toggles the buttons in the toolbar
135 **/
136 deactivateButtons: function(rowModel, record) {
137 var grid = rowModel.view.up('grid');
138 // Only disable buttons when nothing is selected
139 if (rowModel.selected.items == 0) {
140 this.buttonToggle(false, grid);
141 }
142 },
143
144 /**
145 * Enables/Disables a set of buttons
146 **/
147 buttonToggle: function(enabled, grid) {
148 if (!enabled) {
149 grid.down('button[action=delete]').disable();
150 }
151 else {
152 if (!grid.getPlugin('rowedit').editing) {
153 //only enable buttons, when grid is not beeing edited
154 grid.down('button[action=delete]').enable();
155 }
156 //else turn them off again!
157 else {
158 this.buttonToggle(false, grid);
159 }
160 }
161 }
162 });
163

http://lada.wald.intevation.org