Mercurial > lada > lada-client
comparison app/controller/grid/Messwert.js @ 742:6e28ebbe1a73
added documentation for Form and Grid controllers
author | Dustin Demuth <dustin@intevation.de> |
---|---|
date | Thu, 23 Apr 2015 16:28:04 +0200 |
parents | 2e8da590ea0c |
children | 2362f8ab1e9f |
comparison
equal
deleted
inserted
replaced
740:2e8da590ea0c | 742:6e28ebbe1a73 |
---|---|
4 * This file is Free Software under the GNU GPL (v>=3) | 4 * This file is Free Software under the GNU GPL (v>=3) |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out | 5 * and comes with ABSOLUTELY NO WARRANTY! Check out |
6 * the documentation coming with IMIS-Labordaten-Application for details. | 6 * the documentation coming with IMIS-Labordaten-Application for details. |
7 */ | 7 */ |
8 | 8 |
9 /** | |
10 * This is a Controller for a Messwert Grid | |
11 */ | |
9 Ext.define('Lada.controller.grid.Messwert', { | 12 Ext.define('Lada.controller.grid.Messwert', { |
10 extend: 'Ext.app.Controller', | 13 extend: 'Ext.app.Controller', |
11 | 14 |
12 init: function() { | 15 /** |
16 * Inhitialize the controller | |
17 * It has 3 listeners | |
18 */ | |
19 init: function() { | |
13 this.control({ | 20 this.control({ |
14 'messwertgrid': { | 21 'messwertgrid': { |
15 edit: this.gridSave, | 22 edit: this.gridSave, |
16 canceledit: this.cancelEdit | 23 canceledit: this.cancelEdit |
17 }, | 24 }, |
22 click: this.remove | 29 click: this.remove |
23 } | 30 } |
24 }); | 31 }); |
25 }, | 32 }, |
26 | 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 */ | |
27 gridSave: function(editor, context) { | 40 gridSave: function(editor, context) { |
28 context.record.save({ | 41 context.record.save({ |
29 success: function(request, response) { | 42 success: function(request, response) { |
30 if (Ext.data.StoreManager.get('messeinheiten')) { | 43 if (Ext.data.StoreManager.get('messeinheiten')) { |
31 Ext.data.StoreManager.get('messeinheiten').clearFilter(); | 44 Ext.data.StoreManager.get('messeinheiten').clearFilter(); |
57 } | 70 } |
58 } | 71 } |
59 }); | 72 }); |
60 }, | 73 }, |
61 | 74 |
75 /** | |
76 * When the edit was canceled, | |
77 * the empty row might have been created by the roweditor is removed | |
78 */ | |
62 cancelEdit: function(editor, context) { | 79 cancelEdit: function(editor, context) { |
63 if (!context.record.get('id') || | 80 if (!context.record.get('id') || |
64 context.record.get('id') === '') { | 81 context.record.get('id') === '') { |
65 editor.getCmp().store.remove(context.record); | 82 editor.getCmp().store.remove(context.record); |
66 } | 83 } |
67 }, | 84 }, |
68 | 85 |
86 /** | |
87 * This function adds a new row to add a Messwert | |
88 */ | |
69 add: function(button) { | 89 add: function(button) { |
70 var record = Ext.create('Lada.model.Messwert', { | 90 var record = Ext.create('Lada.model.Messwert', { |
71 messungsId: button.up('messwertgrid').recordId | 91 messungsId: button.up('messwertgrid').recordId |
72 }); | 92 }); |
73 button.up('messwertgrid').store.insert(0, record); | 93 button.up('messwertgrid').store.insert(0, record); |
74 button.up('messwertgrid').rowEditing.startEdit(0, 1); | 94 button.up('messwertgrid').rowEditing.startEdit(0, 1); |
75 }, | 95 }, |
76 | 96 |
77 remove: function(button) { | 97 /** |
98 * A Messwert-row can be removed from the grid with the remove | |
99 * function. It asks the user for confirmation | |
100 * If the removal was confirmed, it reloads the parent window on success, | |
101 * on failure, an error message is shown. | |
102 */ | |
103 remove: function(button) { | |
78 var grid = button.up('grid'); | 104 var grid = button.up('grid'); |
79 var selection = grid.getView().getSelectionModel().getSelection()[0]; | 105 var selection = grid.getView().getSelectionModel().getSelection()[0]; |
80 Ext.MessageBox.confirm('Messwert löschen', 'Sind Sie sicher?', function(btn) { | 106 Ext.MessageBox.confirm('Messwert löschen', 'Sind Sie sicher?', function(btn) { |
81 if (btn === 'yes') { | 107 if (btn === 'yes') { |
82 selection.destroy({ | 108 selection.destroy({ |