comparison app/controller/grid/Datensatzerzeuger.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 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 context.record.set('datum', new Date());
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(Lada.getApplication().bundle.getMsg('err.msg.save.title')
53 +' #'+json.message,
54 Lada.getApplication().bundle.getMsg(json.message));
55 } else {
56 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'),
57 Lada.getApplication().bundle.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 //TODO: i18n
95 Ext.MessageBox.confirm('Löschen', 'Sind Sie sicher?', function(btn) {
96 if (btn === 'yes') {
97 selection.destroy({
98 success: function() {
99 //DO NOTHING
100 },
101 failure: function(request, response) {
102 var json = response.request.scope.reader.jsonData;
103 if (json) {
104 if (json.message){
105 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.delete.title')
106 +' #'+json.message,
107 Lada.getApplication().bundle.getMsg(json.message));
108 } else {
109 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.delete.title'),
110 Lada.getApplication().bundle.getMsg('err.msg.generic.body'));
111 }
112 } else {
113 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.delete.title'),
114 Lada.getApplication().bundle.getMsg('err.msg.response.body'));
115 }
116 }
117 });
118 }
119 });
120 grid.down('button[action=delete]').disable();
121 },
122 /**
123 * Toggles the buttons in the toolbar
124 **/
125 activateButtons: function(rowModel, record) {
126 var grid = rowModel.view.up('grid');
127 this.buttonToggle(true, grid);
128 },
129
130 /**
131 * Toggles the buttons in the toolbar
132 **/
133 deactivateButtons: function(rowModel, record) {
134 var grid = rowModel.view.up('grid');
135 // Only disable buttons when nothing is selected
136 if (rowModel.selected.items == 0) {
137 this.buttonToggle(false, grid);
138 }
139 },
140
141 /**
142 * Enables/Disables a set of buttons
143 **/
144 buttonToggle: function(enabled, grid) {
145 if (!enabled) {
146 grid.down('button[action=delete]').disable();
147 }
148 else {
149 if (!grid.getPlugin('rowedit').editing) {
150 //only enable buttons, when grid is not beeing edited
151 grid.down('button[action=delete]').enable();
152 }
153 //else turn them off again!
154 else {
155 this.buttonToggle(false, grid);
156 }
157 }
158 }
159 });
160

http://lada.wald.intevation.org