Mercurial > lada > lada-client
comparison app/controller/grid/Messmethode.js @ 758:b2fcbdc4969d
Filled MessmethodenGrid with life.
author | Dustin Demuth <dustin@intevation.de> |
---|---|
date | Wed, 06 May 2015 16:24:23 +0200 |
parents | |
children | ba8c0e754979 |
comparison
equal
deleted
inserted
replaced
757:b8502964f5c3 | 758:b2fcbdc4969d |
---|---|
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 Messmethode | |
11 */ | |
12 Ext.define('Lada.controller.grid.Messmethode', { | |
13 extend: 'Ext.app.Controller', | |
14 | |
15 /** | |
16 * Inhitialize the controller | |
17 * It has 3 listeners | |
18 */ | |
19 init: function() { | |
20 this.control({ | |
21 'messmethodengrid': { | |
22 edit: this.gridSave, | |
23 canceledit: this.cancelEdit | |
24 }, | |
25 'messmethodengrid button[action=add]': { | |
26 click: this.add | |
27 }, | |
28 'messmethodengrid button[action=delete]': { | |
29 click: this.remove | |
30 } | |
31 }); | |
32 }, | |
33 | |
34 /** | |
35 * This function is called when the grids roweditor saves | |
36 * the record. | |
37 * On success it refreshes the windows which contains the grid | |
38 * On failure it displays a message | |
39 */ | |
40 gridSave: function(editor, context) { | |
41 console.log(context); | |
42 context.record.save({ | |
43 success: function() { | |
44 context.grid.initData(); | |
45 context.grid.up('window').initData(); | |
46 }, | |
47 failure: function(request, 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 } else { | |
59 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'), | |
60 Lada.getApplication().bundle.getMsg('err.msg.response.body')); | |
61 } | |
62 } | |
63 }); | |
64 }, | |
65 | |
66 /** | |
67 * When the edit was canceled, | |
68 * the empty row might have been created by the roweditor is removed | |
69 */ | |
70 cancelEdit: function(editor, context) { | |
71 if (!context.record.get('id') || | |
72 context.record.get('id') === '') { | |
73 editor.getCmp().store.remove(context.record); | |
74 } | |
75 }, | |
76 | |
77 /** | |
78 * This function adds a new row | |
79 */ | |
80 add: function(button) { | |
81 var record = Ext.create('Lada.model.MmtMessprogramm'); | |
82 record.set('messprogrammId', button.up('messmethodengrid').recordId); | |
83 button.up('messmethodengrid').store.insert(0, record); | |
84 button.up('messmethodengrid').rowEditing.startEdit(0, 0); | |
85 }, | |
86 | |
87 /** | |
88 * A row can be removed from the grid with the remove | |
89 * function. It asks the user for confirmation | |
90 * If the removal was confirmed, it reloads the parent window on success, | |
91 * on failure, an error message is shown. | |
92 */ | |
93 remove: function(button) { | |
94 var grid = button.up('grid'); | |
95 //TODO i18n | |
96 var selection = grid.getView().getSelectionModel().getSelection()[0]; | |
97 Ext.MessageBox.confirm('Löschen', 'Sind Sie sicher?', function(btn) { | |
98 if (btn === 'yes') { | |
99 selection.destroy({ | |
100 success: function() { | |
101 button.up('window').initData(); | |
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(Lada.getApplication().bundle.getMsg('err.msg.delete.title') | |
108 +' #'+json.message, | |
109 Lada.getApplication().bundle.getMsg(json.message)); | |
110 } else { | |
111 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.delete.title'), | |
112 Lada.getApplication().bundle.getMsg('err.msg.generic.body')); | |
113 } | |
114 } else { | |
115 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.delete.title'), | |
116 Lada.getApplication().bundle.getMsg('err.msg.response.body')); | |
117 } | |
118 } | |
119 }); | |
120 } | |
121 }); | |
122 } | |
123 }); |