annotate app/controller/form/Ort.js @ 1020:00da72171de3

No default value for statuswerte, this time it should work
author Dustin Demuth <dustin@intevation.de>
date Thu, 04 Feb 2016 16:17:26 +0100
parents 24b5684d74d7
children
rev   line source
603
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
1 /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
2 * Software engineering by Intevation GmbH
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
3 *
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
4 * This file is Free Software under the GNU GPL (v>=3)
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
6 * the documentation coming with IMIS-Labordaten-Application for details.
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
7 */
9d0113bc2f70 Added ort form 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: 704
diff changeset
9 /*
6e28ebbe1a73 added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents: 704
diff changeset
10 * This is a controller for an Ort Form
6e28ebbe1a73 added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents: 704
diff changeset
11 */
603
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
12 Ext.define('Lada.controller.form.Ort', {
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
13 extend: 'Ext.app.Controller',
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
14
742
6e28ebbe1a73 added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents: 704
diff changeset
15 /**
6e28ebbe1a73 added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents: 704
diff changeset
16 * Initialize the Controller with 4 listeners
6e28ebbe1a73 added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents: 704
diff changeset
17 */
603
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
18 init: function() {
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
19 this.control({
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
20 'ortform button[action=save]': {
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
21 click: this.save
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
22 },
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
23 'ortform button[action=discard]': {
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
24 click: this.discard
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
25 },
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
26 'ortform': {
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
27 dirtychange: this.dirtyForm
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
28 },
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
29 'ortform combobox[name=ort]': {
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
30 select: this.updateDetails
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
31 }
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
32 });
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
33 },
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
34
742
6e28ebbe1a73 added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents: 704
diff changeset
35 /**
972
24b5684d74d7 Set letzteAenderung in a Bunch of controllers.
Dustin Demuth <dustin@intevation.de>
parents: 742
diff changeset
36 * The save function saves the content of the Ort form.
742
6e28ebbe1a73 added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents: 704
diff changeset
37 * On success it will reload the Store,
6e28ebbe1a73 added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents: 704
diff changeset
38 * on failure, it will display an Errormessage
6e28ebbe1a73 added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents: 704
diff changeset
39 */
6e28ebbe1a73 added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents: 704
diff changeset
40 save: function(button) {
641
5b5bba1d8e6a Load and update the correct orte form.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 615
diff changeset
41 var formPanel = button.up('ortform');
603
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
42 var data = formPanel.getForm().getFieldValues(true);
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
43 for (var key in data) {
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
44 formPanel.getForm().getRecord().set(key, data[key]);
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
45 }
972
24b5684d74d7 Set letzteAenderung in a Bunch of controllers.
Dustin Demuth <dustin@intevation.de>
parents: 742
diff changeset
46 if (!formPanel.getForm().getRecord().get('letzteAenderung')) {
24b5684d74d7 Set letzteAenderung in a Bunch of controllers.
Dustin Demuth <dustin@intevation.de>
parents: 742
diff changeset
47 formPanel.getForm().getRecord().data.letzteAenderung = new Date();
24b5684d74d7 Set letzteAenderung in a Bunch of controllers.
Dustin Demuth <dustin@intevation.de>
parents: 742
diff changeset
48 }
603
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
49 formPanel.getForm().getRecord().save({
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
50 success: function(record, response) {
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
51 var json = Ext.decode(response.response.responseText);
641
5b5bba1d8e6a Load and update the correct orte form.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 615
diff changeset
52 if (json) {
603
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
53 button.setDisabled(true);
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
54 button.up('toolbar').down('button[action=discard]')
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
55 .setDisabled(true);
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
56 formPanel.clearMessages();
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
57 formPanel.setRecord(record);
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
58 formPanel.setMessages(json.errors, json.warnings);
644
71e8b84d7829 Reload grids on messung or ort changed/added.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 641
diff changeset
59 formPanel.up('window').grid.store.reload();
603
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
60 }
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
61 },
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
62 failure: function(record, response) {
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
63 button.setDisabled(true);
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
64 button.up('toolbar').down('button[action=discard]')
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
65 .setDisabled(true);
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
66 formPanel.getForm().loadRecord(formPanel.getForm().getRecord());
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
67 var json = response.request.scope.reader.jsonData;
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
68 if (json) {
695
d6ef146e1a9f Added simple handling for Failure-Messages
Dustin Demuth <dustin@intevation.de>
parents: 644
diff changeset
69 if(json.errors.totalCount > 0 || json.warnings.totalCount > 0){
d6ef146e1a9f Added simple handling for Failure-Messages
Dustin Demuth <dustin@intevation.de>
parents: 644
diff changeset
70 formPanel.setMessages(json.errors, json.warnings);
d6ef146e1a9f Added simple handling for Failure-Messages
Dustin Demuth <dustin@intevation.de>
parents: 644
diff changeset
71 }
d6ef146e1a9f Added simple handling for Failure-Messages
Dustin Demuth <dustin@intevation.de>
parents: 644
diff changeset
72
d6ef146e1a9f Added simple handling for Failure-Messages
Dustin Demuth <dustin@intevation.de>
parents: 644
diff changeset
73 if(json.message){
704
2d454bfef426 Further Failure Messages
Dustin Demuth <dustin@intevation.de>
parents: 701
diff changeset
74 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title')
701
f0bc5387abcc Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents: 695
diff changeset
75 +' #'+json.message,
695
d6ef146e1a9f Added simple handling for Failure-Messages
Dustin Demuth <dustin@intevation.de>
parents: 644
diff changeset
76 Lada.getApplication().bundle.getMsg(json.message));
701
f0bc5387abcc Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents: 695
diff changeset
77 } else {
f0bc5387abcc Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents: 695
diff changeset
78 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'),
f0bc5387abcc Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents: 695
diff changeset
79 Lada.getApplication().bundle.getMsg('err.msg.generic.body'));
695
d6ef146e1a9f Added simple handling for Failure-Messages
Dustin Demuth <dustin@intevation.de>
parents: 644
diff changeset
80 }
701
f0bc5387abcc Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents: 695
diff changeset
81 } else {
f0bc5387abcc Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents: 695
diff changeset
82 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'),
f0bc5387abcc Added failure - Messages
Dustin Demuth <dustin@intevation.de>
parents: 695
diff changeset
83 Lada.getApplication().bundle.getMsg('err.msg.response.body'));
603
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
84 }
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
85 }
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
86 });
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
87 },
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
88
742
6e28ebbe1a73 added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents: 704
diff changeset
89 /**
6e28ebbe1a73 added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents: 704
diff changeset
90 * The discard function resets the Location form
6e28ebbe1a73 added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents: 704
diff changeset
91 * to its original state.
6e28ebbe1a73 added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents: 704
diff changeset
92 */
6e28ebbe1a73 added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents: 704
diff changeset
93 discard: function(button) {
603
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
94 var formPanel = button.up('form');
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
95 formPanel.getForm().loadRecord(formPanel.getForm().getRecord());
615
3d33c65319f3 Update feature selection on 'ort' selection change.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 603
diff changeset
96 var win = button.up('window');
3d33c65319f3 Update feature selection on 'ort' selection change.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 603
diff changeset
97 var id = formPanel.getForm().getRecord().get('ort');
3d33c65319f3 Update feature selection on 'ort' selection change.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 603
diff changeset
98 var toLoad = Ext.data.StoreManager.get('locations').getById(id);
3d33c65319f3 Update feature selection on 'ort' selection change.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 603
diff changeset
99 win.down('locationform').setRecord(toLoad);
3d33c65319f3 Update feature selection on 'ort' selection change.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 603
diff changeset
100 win.down('map').selectFeature(id);
603
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
101 },
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
102
742
6e28ebbe1a73 added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents: 704
diff changeset
103 /**
6e28ebbe1a73 added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents: 704
diff changeset
104 * The dirtyForm function enables or disables the save and discard
6e28ebbe1a73 added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents: 704
diff changeset
105 * button which are present in the toolbar of the form.
6e28ebbe1a73 added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents: 704
diff changeset
106 * The Buttons are only active if the content of the form was altered
6e28ebbe1a73 added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents: 704
diff changeset
107 * (the form is dirty).
6e28ebbe1a73 added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents: 704
diff changeset
108 */
603
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
109 dirtyForm: function(form, dirty) {
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
110 if (dirty) {
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
111 form.owner.down('button[action=save]').setDisabled(false);
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
112 form.owner.down('button[action=discard]').setDisabled(false);
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
113 }
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
114 else {
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
115 form.owner.down('button[action=save]').setDisabled(true);
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
116 form.owner.down('button[action=discard]').setDisabled(true);
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
117 }
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
118 },
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
119
742
6e28ebbe1a73 added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents: 704
diff changeset
120 /**
6e28ebbe1a73 added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents: 704
diff changeset
121 * updateDetails is used when a value is selected within the ort combobox
6e28ebbe1a73 added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents: 704
diff changeset
122 * When this function is called, the map element within the window
6e28ebbe1a73 added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents: 704
diff changeset
123 * which is embedding this form is updated.
6e28ebbe1a73 added documentation for Form and Grid controllers
Dustin Demuth <dustin@intevation.de>
parents: 704
diff changeset
124 */
603
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
125 updateDetails: function(combobox, record) {
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
126 var win = combobox.up('window');
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
127 var details = win.down('locationform');
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
128 var id = record[0].get('id');
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
129 if (details) {
615
3d33c65319f3 Update feature selection on 'ort' selection change.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 603
diff changeset
130 var toLoad = Ext.data.StoreManager.get('locations').getById(id);
3d33c65319f3 Update feature selection on 'ort' selection change.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 603
diff changeset
131 win.down('locationform').setRecord(toLoad);
3d33c65319f3 Update feature selection on 'ort' selection change.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 603
diff changeset
132 win.down('map').selectFeature(id);
603
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
133 }
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
134 }
9d0113bc2f70 Added ort form and controller.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
135 });

http://lada.wald.intevation.org