annotate 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
rev   line source
758
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
1 /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
2 * Software engineering by Intevation GmbH
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
3 *
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
4 * This file is Free Software under the GNU GPL (v>=3)
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
6 * the documentation coming with IMIS-Labordaten-Application for details.
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
7 */
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
8
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
9 /**
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
10 * This is a controller for a grid of Messmethode
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
11 */
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
12 Ext.define('Lada.controller.grid.Messmethode', {
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
13 extend: 'Ext.app.Controller',
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
14
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
15 /**
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
16 * Inhitialize the controller
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
17 * It has 3 listeners
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
18 */
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
19 init: function() {
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
20 this.control({
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
21 'messmethodengrid': {
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
22 edit: this.gridSave,
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
23 canceledit: this.cancelEdit
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
24 },
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
25 'messmethodengrid button[action=add]': {
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
26 click: this.add
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
27 },
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
28 'messmethodengrid button[action=delete]': {
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
29 click: this.remove
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
30 }
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
31 });
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
32 },
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
33
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
34 /**
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
35 * This function is called when the grids roweditor saves
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
36 * the record.
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
37 * On success it refreshes the windows which contains the grid
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
38 * On failure it displays a message
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
39 */
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
40 gridSave: function(editor, context) {
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
41 console.log(context);
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
42 context.record.save({
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
43 success: function() {
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
44 context.grid.initData();
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
45 context.grid.up('window').initData();
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
46 },
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
47 failure: function(request, response) {
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
48 var json = response.request.scope.reader.jsonData;
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
49 if (json) {
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
50 if (json.message){
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
51 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title')
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
52 +' #'+json.message,
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
53 Lada.getApplication().bundle.getMsg(json.message));
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
54 } else {
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
55 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'),
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
56 Lada.getApplication().bundle.getMsg('err.msg.generic.body'));
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
57 }
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
58 } else {
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
59 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'),
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
60 Lada.getApplication().bundle.getMsg('err.msg.response.body'));
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
61 }
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
62 }
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
63 });
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
64 },
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
65
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
66 /**
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
67 * When the edit was canceled,
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
68 * the empty row might have been created by the roweditor is removed
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
69 */
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
70 cancelEdit: function(editor, context) {
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
71 if (!context.record.get('id') ||
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
72 context.record.get('id') === '') {
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
73 editor.getCmp().store.remove(context.record);
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
74 }
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
75 },
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
76
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
77 /**
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
78 * This function adds a new row
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
79 */
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
80 add: function(button) {
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
81 var record = Ext.create('Lada.model.MmtMessprogramm');
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
82 record.set('messprogrammId', button.up('messmethodengrid').recordId);
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
83 button.up('messmethodengrid').store.insert(0, record);
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
84 button.up('messmethodengrid').rowEditing.startEdit(0, 0);
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
85 },
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
86
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
87 /**
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
88 * A row can be removed from the grid with the remove
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
89 * function. It asks the user for confirmation
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
90 * If the removal was confirmed, it reloads the parent window on success,
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
91 * on failure, an error message is shown.
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
92 */
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
93 remove: function(button) {
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
94 var grid = button.up('grid');
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
95 //TODO i18n
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
96 var selection = grid.getView().getSelectionModel().getSelection()[0];
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
97 Ext.MessageBox.confirm('Löschen', 'Sind Sie sicher?', function(btn) {
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
98 if (btn === 'yes') {
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
99 selection.destroy({
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
100 success: function() {
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
101 button.up('window').initData();
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
102 },
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
103 failure: function(request, response) {
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
104 var json = response.request.scope.reader.jsonData;
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
105 if (json) {
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
106 if (json.message){
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
107 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.delete.title')
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
108 +' #'+json.message,
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
109 Lada.getApplication().bundle.getMsg(json.message));
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
110 } else {
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
111 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.delete.title'),
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
112 Lada.getApplication().bundle.getMsg('err.msg.generic.body'));
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
113 }
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
114 } else {
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
115 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.delete.title'),
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
116 Lada.getApplication().bundle.getMsg('err.msg.response.body'));
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
117 }
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
118 }
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
119 });
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
120 }
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
121 });
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
122 }
b2fcbdc4969d Filled MessmethodenGrid with life.
Dustin Demuth <dustin@intevation.de>
parents:
diff changeset
123 });

http://lada.wald.intevation.org