Mercurial > lada > lada-client
comparison app/controller/form/Ortszuordnung.js @ 1051:981339d774b8
merged stammdatengrids to default.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Tue, 01 Mar 2016 14:12:39 +0100 |
parents | 2e7adc19b4fe |
children | f1d21e6a7449 |
comparison
equal
deleted
inserted
replaced
1048:eacf25f071c0 | 1051:981339d774b8 |
---|---|
1 /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz | |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU GPL (v>=3) | |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out | |
6 * the documentation coming with IMIS-Labordaten-Application for details. | |
7 */ | |
8 | |
9 /* | |
10 * This is a controller for an Ortszuordnung Form | |
11 */ | |
12 Ext.define('Lada.controller.form.Ortszuordnung', { | |
13 extend: 'Ext.app.Controller', | |
14 | |
15 /** | |
16 * Initialize the Controller with 4 listeners | |
17 */ | |
18 init: function() { | |
19 this.control({ | |
20 'ortszuordnungform button[action=setOrt]': { | |
21 toggle: this.pickOrt | |
22 }, | |
23 'ortszuordnungform button[action=save]': { | |
24 click: this.save | |
25 }, | |
26 'ortszuordnungform button[action=discard]': { | |
27 click: this.discard | |
28 }, | |
29 'ortszuordnungform': { | |
30 dirtychange: this.dirtyForm | |
31 } | |
32 }); | |
33 }, | |
34 | |
35 /** | |
36 * The save function saves the content of the Ort form. | |
37 * On success it will reload the Store, | |
38 * on failure, it will display an Errormessage | |
39 */ | |
40 save: function(button) { | |
41 | |
42 var formPanel = button.up('ortszuordnungform'); | |
43 | |
44 //try to disable ortPickerButton: | |
45 try { | |
46 formPanel.down('button[action=setOrt]').toggle(false); | |
47 } | |
48 catch (e) { | |
49 } | |
50 | |
51 var data = formPanel.getForm().getFieldValues(true); | |
52 var i18n = Lada.getApplication().bundle; | |
53 for (var key in data) { | |
54 formPanel.getForm().getRecord().set(key, data[key]); | |
55 } | |
56 if (!formPanel.getForm().getRecord().get('letzteAenderung')) { | |
57 formPanel.getForm().getRecord().data.letzteAenderung = new Date(); | |
58 } | |
59 formPanel.getForm().getRecord().save({ | |
60 success: function(record, response) { | |
61 var json = Ext.decode(response.response.responseText); | |
62 if (json) { | |
63 button.setDisabled(true); | |
64 button.up('toolbar').down('button[action=discard]') | |
65 .setDisabled(true); | |
66 formPanel.clearMessages(); | |
67 formPanel.setRecord(record); | |
68 formPanel.setMessages(json.errors, json.warnings); | |
69 formPanel.up('window').grid.store.reload(); | |
70 } | |
71 //try to refresh the Grid of the Probe | |
72 try { | |
73 formPanel.up('window').parentWindow | |
74 .down('ortszuordnunggrid').store.reload(); | |
75 } | |
76 catch (e) { | |
77 | |
78 } | |
79 }, | |
80 failure: function(record, response) { | |
81 button.setDisabled(true); | |
82 button.up('toolbar').down('button[action=discard]') | |
83 .setDisabled(true); | |
84 formPanel.getForm().loadRecord(formPanel.getForm().getRecord()); | |
85 var json = response.request.scope.reader.jsonData; | |
86 if (json) { | |
87 if(json.errors.totalCount > 0 || json.warnings.totalCount > 0){ | |
88 formPanel.setMessages(json.errors, json.warnings); | |
89 } | |
90 | |
91 if(json.message){ | |
92 Ext.Msg.alert(i18n.getMsg('err.msg.save.title') | |
93 +' #'+json.message, | |
94 i18n.getMsg(json.message)); | |
95 } else { | |
96 Ext.Msg.alert(i18n.getMsg('err.msg.save.title'), | |
97 i18n.getMsg('err.msg.generic.body')); | |
98 } | |
99 } else { | |
100 Ext.Msg.alert(i18n.getMsg('err.msg.save.title'), | |
101 i18n.getMsg('err.msg.response.body')); | |
102 } | |
103 } | |
104 }); | |
105 }, | |
106 | |
107 /** | |
108 * The discard function resets the Location form | |
109 * to its original state. | |
110 */ | |
111 discard: function(button) { | |
112 var formPanel = button.up('form'); | |
113 var record = formPanel.getForm().getRecord(); | |
114 formPanel.getForm().loadRecord(record); | |
115 try { | |
116 formPanel.refreshOrt(record.get('ortId')); | |
117 formPanel.down('button[action=setOrt]').toggle(false); | |
118 } | |
119 catch (e) { | |
120 } | |
121 //set undirty. | |
122 formPanel.fireEvent('dirtychange', formPanel.getForm(), false); | |
123 }, | |
124 | |
125 /** | |
126 * When the button is Active, a Record can be selected. | |
127 * If the Record was selected from a grid this function | |
128 * sets the ortzuordnung. | |
129 * TODO: Check if the selected Record is a ORT | |
130 * TODO: Enable picking from Maps | |
131 */ | |
132 pickOrt: function(button, pressed, opts) { | |
133 var i18n = Lada.getApplication().bundle; | |
134 var oForm = button.up('form'); | |
135 var osg = button.up('window').down('ortstammdatengrid'); | |
136 if (button.pressed) { | |
137 button.setText(i18n.getMsg('ortszuordnung.form.setOrt.pressed')); | |
138 osg.addListener('select',oForm.setOrt, oForm); | |
139 } | |
140 else { | |
141 button.setText(i18n.getMsg('ortszuordnung.form.setOrt')); | |
142 osg.removeListener('select',oForm.setOrt, oForm); | |
143 } | |
144 }, | |
145 | |
146 | |
147 /** | |
148 * The dirtyForm function enables or disables the save and discard | |
149 * button which are present in the toolbar of the form. | |
150 * The Buttons are only active if the content of the form was altered | |
151 * (the form is dirty). | |
152 */ | |
153 dirtyForm: function(form, dirty) { | |
154 if (dirty) { | |
155 form.owner.down('button[action=save]').setDisabled(false); | |
156 form.owner.down('button[action=discard]').setDisabled(false); | |
157 } | |
158 else { | |
159 form.owner.down('button[action=save]').setDisabled(true); | |
160 form.owner.down('button[action=discard]').setDisabled(true); | |
161 } | |
162 } | |
163 }); |