comparison app/controller/form/Ort.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 2d454bfef426
children 24b5684d74d7
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 an Ort Form
11 */
9 Ext.define('Lada.controller.form.Ort', { 12 Ext.define('Lada.controller.form.Ort', {
10 extend: 'Ext.app.Controller', 13 extend: 'Ext.app.Controller',
11 14
15 /**
16 * Initialize the Controller with 4 listeners
17 */
12 init: function() { 18 init: function() {
13 this.control({ 19 this.control({
14 'ortform button[action=save]': { 20 'ortform button[action=save]': {
15 click: this.save 21 click: this.save
16 }, 22 },
24 select: this.updateDetails 30 select: this.updateDetails
25 } 31 }
26 }); 32 });
27 }, 33 },
28 34
29 save: function(button) { 35 /**
36 * The save function saves the content of the Location form.
37 * On success it will reload the Store,
38 * on failure, it will display an Errormessage
39 */
40 save: function(button) {
30 var formPanel = button.up('ortform'); 41 var formPanel = button.up('ortform');
31 var data = formPanel.getForm().getFieldValues(true); 42 var data = formPanel.getForm().getFieldValues(true);
32 for (var key in data) { 43 for (var key in data) {
33 formPanel.getForm().getRecord().set(key, data[key]); 44 formPanel.getForm().getRecord().set(key, data[key]);
34 } 45 }
70 } 81 }
71 } 82 }
72 }); 83 });
73 }, 84 },
74 85
75 discard: function(button) { 86 /**
87 * The discard function resets the Location form
88 * to its original state.
89 */
90 discard: function(button) {
76 var formPanel = button.up('form'); 91 var formPanel = button.up('form');
77 formPanel.getForm().loadRecord(formPanel.getForm().getRecord()); 92 formPanel.getForm().loadRecord(formPanel.getForm().getRecord());
78 var win = button.up('window'); 93 var win = button.up('window');
79 var id = formPanel.getForm().getRecord().get('ort'); 94 var id = formPanel.getForm().getRecord().get('ort');
80 var toLoad = Ext.data.StoreManager.get('locations').getById(id); 95 var toLoad = Ext.data.StoreManager.get('locations').getById(id);
81 win.down('locationform').setRecord(toLoad); 96 win.down('locationform').setRecord(toLoad);
82 win.down('map').selectFeature(id); 97 win.down('map').selectFeature(id);
83 }, 98 },
84 99
100 /**
101 * The dirtyForm function enables or disables the save and discard
102 * button which are present in the toolbar of the form.
103 * The Buttons are only active if the content of the form was altered
104 * (the form is dirty).
105 */
85 dirtyForm: function(form, dirty) { 106 dirtyForm: function(form, dirty) {
86 if (dirty) { 107 if (dirty) {
87 form.owner.down('button[action=save]').setDisabled(false); 108 form.owner.down('button[action=save]').setDisabled(false);
88 form.owner.down('button[action=discard]').setDisabled(false); 109 form.owner.down('button[action=discard]').setDisabled(false);
89 } 110 }
91 form.owner.down('button[action=save]').setDisabled(true); 112 form.owner.down('button[action=save]').setDisabled(true);
92 form.owner.down('button[action=discard]').setDisabled(true); 113 form.owner.down('button[action=discard]').setDisabled(true);
93 } 114 }
94 }, 115 },
95 116
117 /**
118 * updateDetails is used when a value is selected within the ort combobox
119 * When this function is called, the map element within the window
120 * which is embedding this form is updated.
121 */
96 updateDetails: function(combobox, record) { 122 updateDetails: function(combobox, record) {
97 var win = combobox.up('window'); 123 var win = combobox.up('window');
98 var details = win.down('locationform'); 124 var details = win.down('locationform');
99 var id = record[0].get('id'); 125 var id = record[0].get('id');
100 if (details) { 126 if (details) {

http://lada.wald.intevation.org