comparison app/controller/grid/MessprogrammKategorie.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 MessprogrammKategorie Stammdaten
11 */
12 Ext.define('Lada.controller.grid.MessprogrammKategorie', {
13 extend: 'Ext.app.Controller',
14
15 /**
16 * Inhitialize the controller
17 * It has 3 listeners
18 */
19 init: function() {
20 this.control({
21 'messprogrammkategoriegrid': {
22 edit: this.gridSave,
23 canceledit: this.cancelEdit,
24 select: this.activateButtons,
25 deselect: this.deactivateButtons
26 },
27 'messprogrammkategoriegrid button[action=add]': {
28 click: this.add
29 },
30 'messprogrammkategoriegrid 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 probenehmer
78 */
79 add: function(button) {
80 var record = Ext.create('Lada.model.MessprogrammKategorie');
81 button.up('messprogrammkategoriegrid').store.insert(0, record);
82 button.up('messprogrammkategoriegrid').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 Ext.MessageBox.confirm(i18n.getMsg('delete'),
96 i18n.getMsg('confirmation.question'),
97 function(btn) {
98 if (btn === 'yes') {
99 selection.destroy({
100 success: function() {
101 //DO NOTHING
102 },
103 failure: function(request, response) {
104 var json = response.request.scope.reader.jsonData;
105 if (json) {
106 if (json.message){
107 Ext.Msg.alert(i18n.getMsg('err.msg.delete.title')
108 +' #'+json.message,
109 i18n.getMsg(json.message));
110 } else {
111 Ext.Msg.alert(i18n.getMsg('err.msg.delete.title'),
112 i18n.getMsg('err.msg.generic.body'));
113 }
114 } else {
115 Ext.Msg.alert(i18n.getMsg('err.msg.delete.title'),
116 i18n.getMsg('err.msg.response.body'));
117 }
118 }
119 });
120 }
121 });
122 grid.down('button[action=delete]').disable();
123 },
124 /**
125 * Toggles the buttons in the toolbar
126 **/
127 activateButtons: function(rowModel, record) {
128 var grid = rowModel.view.up('grid');
129 this.buttonToggle(true, grid);
130 },
131
132 /**
133 * Toggles the buttons in the toolbar
134 **/
135 deactivateButtons: function(rowModel, record) {
136 var grid = rowModel.view.up('grid');
137 // Only disable buttons when nothing is selected
138 if (rowModel.selected.items == 0) {
139 this.buttonToggle(false, grid);
140 }
141 },
142
143 /**
144 * Enables/Disables a set of buttons
145 **/
146 buttonToggle: function(enabled, grid) {
147 if (!enabled) {
148 grid.down('button[action=delete]').disable();
149 }
150 else {
151 if (!grid.getPlugin('rowedit').editing) {
152 //only enable buttons, when grid is not beeing edited
153 grid.down('button[action=delete]').enable();
154 }
155 //else turn them off again!
156 else {
157 this.buttonToggle(false, grid);
158 }
159 }
160 },
161 });
162
163

http://lada.wald.intevation.org