Mercurial > lada > lada-client
annotate app/controller/grid/MKommentar.js @ 1142:255d550e74f4
Use the correct record to compare treemodified field.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Thu, 26 May 2016 14:56:41 +0200 |
parents | f4eb53ba63fc |
children |
rev | line source |
---|---|
596
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
1 /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
2 * Software engineering by Intevation GmbH |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
3 * |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
4 * This file is Free Software under the GNU GPL (v>=3) |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
6 * the documentation coming with IMIS-Labordaten-Application for details. |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
7 */ |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
8 |
742
6e28ebbe1a73
added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents:
701
diff
changeset
|
9 /** |
6e28ebbe1a73
added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents:
701
diff
changeset
|
10 * This is a controller for a grid of MKommentar |
6e28ebbe1a73
added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents:
701
diff
changeset
|
11 * MKommentar are comments which are associated to a |
6e28ebbe1a73
added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents:
701
diff
changeset
|
12 * Measurement |
6e28ebbe1a73
added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents:
701
diff
changeset
|
13 */ |
596
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
14 Ext.define('Lada.controller.grid.MKommentar', { |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
15 extend: 'Ext.app.Controller', |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
16 |
742
6e28ebbe1a73
added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents:
701
diff
changeset
|
17 /** |
6e28ebbe1a73
added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents:
701
diff
changeset
|
18 * Inhitialize the controller |
6e28ebbe1a73
added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents:
701
diff
changeset
|
19 * It has 3 listeners |
6e28ebbe1a73
added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents:
701
diff
changeset
|
20 */ |
596
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
21 init: function() { |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
22 this.control({ |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
23 'mkommentargrid': { |
700
1e76aec72815
Renamed function edit to gridSave
Dustin Demuth <dustin@intevation.de>
parents:
697
diff
changeset
|
24 edit: this.gridSave, |
637
8acb3123b46c
Remove a new record on cancel in grids with rowediting plugin.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
596
diff
changeset
|
25 canceledit: this.cancelEdit |
596
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
26 }, |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
27 'mkommentargrid button[action=add]': { |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
28 click: this.add |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
29 }, |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
30 'mkommentargrid button[action=delete]': { |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
31 click: this.remove |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
32 } |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
33 }); |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
34 }, |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
35 |
742
6e28ebbe1a73
added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents:
701
diff
changeset
|
36 /** |
6e28ebbe1a73
added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents:
701
diff
changeset
|
37 * This function is called when the grids roweditor saves |
6e28ebbe1a73
added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents:
701
diff
changeset
|
38 * the record. |
6e28ebbe1a73
added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents:
701
diff
changeset
|
39 * On success it refreshes the windows which contains the grid |
6e28ebbe1a73
added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents:
701
diff
changeset
|
40 * On failure it displays a message |
6e28ebbe1a73
added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents:
701
diff
changeset
|
41 */ |
700
1e76aec72815
Renamed function edit to gridSave
Dustin Demuth <dustin@intevation.de>
parents:
697
diff
changeset
|
42 gridSave: function(editor, context) { |
944 | 43 context.record.set('datum', new Date()); |
44 context.record.save({ | |
697
5b2cbc6bc39a
Display Error Message on Failure
Dustin Demuth <dustin@intevation.de>
parents:
637
diff
changeset
|
45 success: function(record, response) { |
596
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
46 context.grid.initData(); |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
47 context.grid.up('window').initData(); |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
48 }, |
697
5b2cbc6bc39a
Display Error Message on Failure
Dustin Demuth <dustin@intevation.de>
parents:
637
diff
changeset
|
49 failure: function(record, response) { |
5b2cbc6bc39a
Display Error Message on Failure
Dustin Demuth <dustin@intevation.de>
parents:
637
diff
changeset
|
50 var json = response.request.scope.reader.jsonData; |
5b2cbc6bc39a
Display Error Message on Failure
Dustin Demuth <dustin@intevation.de>
parents:
637
diff
changeset
|
51 if (json) { |
5b2cbc6bc39a
Display Error Message on Failure
Dustin Demuth <dustin@intevation.de>
parents:
637
diff
changeset
|
52 if (json.message){ |
701
f0bc5387abcc
Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents:
700
diff
changeset
|
53 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title') |
f0bc5387abcc
Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents:
700
diff
changeset
|
54 +' #'+json.message, |
697
5b2cbc6bc39a
Display Error Message on Failure
Dustin Demuth <dustin@intevation.de>
parents:
637
diff
changeset
|
55 Lada.getApplication().bundle.getMsg(json.message)); |
701
f0bc5387abcc
Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents:
700
diff
changeset
|
56 } else { |
f0bc5387abcc
Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents:
700
diff
changeset
|
57 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'), |
f0bc5387abcc
Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents:
700
diff
changeset
|
58 Lada.getApplication().bundle.getMsg('err.msg.generic.body')); |
f0bc5387abcc
Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents:
700
diff
changeset
|
59 } |
f0bc5387abcc
Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents:
700
diff
changeset
|
60 } |
596
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
61 } |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
62 }); |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
63 }, |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
64 |
742
6e28ebbe1a73
added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents:
701
diff
changeset
|
65 /** |
6e28ebbe1a73
added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents:
701
diff
changeset
|
66 * When the edit was canceled, |
6e28ebbe1a73
added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents:
701
diff
changeset
|
67 * the empty row might have been created by the roweditor is removed |
6e28ebbe1a73
added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents:
701
diff
changeset
|
68 */ |
637
8acb3123b46c
Remove a new record on cancel in grids with rowediting plugin.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
596
diff
changeset
|
69 cancelEdit: function(editor, context) { |
8acb3123b46c
Remove a new record on cancel in grids with rowediting plugin.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
596
diff
changeset
|
70 if (!context.record.get('id') || |
8acb3123b46c
Remove a new record on cancel in grids with rowediting plugin.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
596
diff
changeset
|
71 context.record.get('id') === '') { |
8acb3123b46c
Remove a new record on cancel in grids with rowediting plugin.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
596
diff
changeset
|
72 editor.getCmp().store.remove(context.record); |
8acb3123b46c
Remove a new record on cancel in grids with rowediting plugin.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
596
diff
changeset
|
73 } |
8acb3123b46c
Remove a new record on cancel in grids with rowediting plugin.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
596
diff
changeset
|
74 }, |
8acb3123b46c
Remove a new record on cancel in grids with rowediting plugin.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
596
diff
changeset
|
75 |
742
6e28ebbe1a73
added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents:
701
diff
changeset
|
76 /** |
6e28ebbe1a73
added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents:
701
diff
changeset
|
77 * This function adds a new row to add a MKommentar |
6e28ebbe1a73
added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents:
701
diff
changeset
|
78 */ |
596
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
79 add: function(button) { |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
80 var record = Ext.create('Lada.model.MKommentar'); |
970
f4eb53ba63fc
Setting Timestamps the correct way. Before this commit the times of the instatiation of the model were used as default values, which led to wrong dates.
Dustin Demuth <dustin@intevation.de>
parents:
944
diff
changeset
|
81 record.data.datum = new Date(); |
596
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
82 record.set('messungsId', button.up('mkommentargrid').recordId); |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
83 button.up('mkommentargrid').store.insert(0, record); |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
84 button.up('mkommentargrid').rowEditing.startEdit(0, 1); |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
85 }, |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
86 |
742
6e28ebbe1a73
added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents:
701
diff
changeset
|
87 /** |
6e28ebbe1a73
added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents:
701
diff
changeset
|
88 * A Mkommentar-row can be removed from the grid with the remove |
6e28ebbe1a73
added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents:
701
diff
changeset
|
89 * function. It asks the user for confirmation |
6e28ebbe1a73
added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents:
701
diff
changeset
|
90 * If the removal was confirmed, it reloads the parent window on success, |
6e28ebbe1a73
added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents:
701
diff
changeset
|
91 * on failure, an error message is shown. |
6e28ebbe1a73
added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents:
701
diff
changeset
|
92 */ |
596
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
93 remove: function(button) { |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
94 var grid = button.up('grid'); |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
95 var selection = grid.getView().getSelectionModel().getSelection()[0]; |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
96 Ext.MessageBox.confirm('Löschen', 'Sind Sie sicher?', function(btn) { |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
97 if (btn === 'yes') { |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
98 selection.destroy({ |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
99 success: function() { |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
100 button.up('window').initData(); |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
101 }, |
701
f0bc5387abcc
Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents:
700
diff
changeset
|
102 failure: function(request, response) { |
f0bc5387abcc
Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents:
700
diff
changeset
|
103 var json = response.request.scope.reader.jsonData; |
f0bc5387abcc
Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents:
700
diff
changeset
|
104 if (json) { |
f0bc5387abcc
Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents:
700
diff
changeset
|
105 if (json.message){ |
f0bc5387abcc
Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents:
700
diff
changeset
|
106 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.delete.title') |
f0bc5387abcc
Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents:
700
diff
changeset
|
107 +' #'+json.message, |
f0bc5387abcc
Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents:
700
diff
changeset
|
108 Lada.getApplication().bundle.getMsg(json.message)); |
f0bc5387abcc
Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents:
700
diff
changeset
|
109 } else { |
f0bc5387abcc
Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents:
700
diff
changeset
|
110 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.delete.title'), |
f0bc5387abcc
Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents:
700
diff
changeset
|
111 Lada.getApplication().bundle.getMsg('err.msg.generic.body')); |
f0bc5387abcc
Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents:
700
diff
changeset
|
112 } |
f0bc5387abcc
Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents:
700
diff
changeset
|
113 } else { |
f0bc5387abcc
Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents:
700
diff
changeset
|
114 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.delete.title'), |
f0bc5387abcc
Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents:
700
diff
changeset
|
115 Lada.getApplication().bundle.getMsg('err.msg.response.body')); |
f0bc5387abcc
Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents:
700
diff
changeset
|
116 } |
596
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
117 } |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
118 }); |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
119 } |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
120 }); |
826
2362f8ab1e9f
disable remove button after a item is deleted from grid
Dustin Demuth <dustin@intevation.de>
parents:
742
diff
changeset
|
121 grid.down('button[action=delete]').disable(); |
596
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
122 } |
b0a3580a41e9
Added messung kommentar grid and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
123 }); |