comparison app/controller/form/Ortszuordnung.js @ 1289:bfdc00c24baf

Ortszuordnung for messprogramm and probe using same form
author Maximilian Krambach <mkrambach@intevation.de>
date Wed, 01 Feb 2017 14:52:51 +0100
parents 08085b7d1d0b
children e9f812528324
comparison
equal deleted inserted replaced
1288:08085b7d1d0b 1289:bfdc00c24baf
46 try { 46 try {
47 formPanel.down('button[action=setOrt]').toggle(false); 47 formPanel.down('button[action=setOrt]').toggle(false);
48 } 48 }
49 catch (e) { 49 catch (e) {
50 } 50 }
51 51 var data = formPanel.getForm().getFieldValues(false);
52 var data = formPanel.getForm().getFieldValues(true);
53 var i18n = Lada.getApplication().bundle; 52 var i18n = Lada.getApplication().bundle;
54 for (var key in data) { 53 //TODO: the forms seem not to submit anything into record.
55 formPanel.getForm().getRecord().set(key, data[key]); 54 var recordData = formPanel.getForm().getRecord().data;
56 } 55 if (recordData['probeId'] !== undefined) {
57 if (!formPanel.getForm().getRecord().get('letzteAenderung')) { 56 // TODO: as model.ort.ortId and model.ortszuordnung.ortId coexist,
58 formPanel.getForm().getRecord().data.letzteAenderung = new Date(); 57 // but mean different things, data.ortId is an array here, of
58 // which we need the first entry
59 recordData.ortId = data.ortId[0];
60 recordData.ortszuordnungTyp = data.ortszuordnungTyp;
61 } else { //messprogramm
62 recordData.ortsTyp = data.ortsTyp;
63 recordData.ort = data.ort;
64 }
65 recordData.ortszusatztext = data.ortszusatztext;
66 if (!data.letzteAenderung) {
67 recordData.letzteAenderung = new Date();
68 } else {
69 recordData.letzteAenderung = data.letzteAenderung;
59 } 70 }
60 formPanel.getForm().getRecord().save({ 71 formPanel.getForm().getRecord().save({
61 success: function(record, response) { 72 success: function(record, response) {
62 var json = Ext.decode(response.response.responseText); 73 var json = Ext.decode(response.response.responseText);
63 if (json) { 74 if (json) {
114 discard: function(button) { 125 discard: function(button) {
115 var formPanel = button.up('form'); 126 var formPanel = button.up('form');
116 var record = formPanel.getForm().getRecord(); 127 var record = formPanel.getForm().getRecord();
117 formPanel.getForm().loadRecord(record); 128 formPanel.getForm().loadRecord(record);
118 try { 129 try {
119 formPanel.refreshOrt(record.get('ortId')); 130 if (record.get('ortId') !== undefined) {
131 formPanel.setOrt(record.get('ortId'));
132 } else {
133 formPanel.setOrt(record.get('ort'));
134 }
120 formPanel.down('button[action=setOrt]').toggle(false); 135 formPanel.down('button[action=setOrt]').toggle(false);
121 } 136 }
122 catch (e) { 137 catch (e) {
123 } 138 }
124 }, 139 },
125 140
126 /** 141 /**
127 * When the button is Active, a Record can be selected. 142 * When the button is Active, a Record can be selected.
128 * If the Record was selected from a grid this function 143 * If the Record was selected from a grid this function
129 * sets the ortzuordnung. 144 * sets the ortzuordnung.
130 * TODO: Check if the selected Record is a ORT
131 */ 145 */
132 chooseLocation: function(button, pressed, opts) { 146 chooseLocation: function(button, pressed, opts) {
133 var i18n = Lada.getApplication().bundle; 147 var i18n = Lada.getApplication().bundle;
134 var win = button.up('window'); 148 var win = button.up('window');
135 var gridPanel = win.down('panel[name=ortgrid]'); 149 var gridPanel = win.down('panel[name=ortgrid]');
136 var osg = win.down('ortstammdatengrid'); 150 var osg = win.down('ortstammdatengrid');
137 var oForm = button.up('form'); 151 var oForm = button.up('form');
152 osg.addListener('select',oForm.setOrt, oForm);
138 if (pressed) { 153 if (pressed) {
139 win.setHeight(Ext.getBody().getViewSize().height - 50); 154 win.setHeight(Ext.getBody().getViewSize().height - 50);
140 button.setText(i18n.getMsg('ortszuordnung.form.setOrt.pressed')); 155 button.setText(i18n.getMsg('ortszuordnung.form.setOrt.pressed'));
141 win.setY(25); 156 win.setY(25);
142 gridPanel.show(); 157 gridPanel.show();
158 * button which are present in the toolbar of the form. 173 * button which are present in the toolbar of the form.
159 */ 174 */
160 validityChange: function(form, valid) { 175 validityChange: function(form, valid) {
161 if (form.isDirty()) { 176 if (form.isDirty()) {
162 form.owner.down('button[action=discard]').setDisabled(false); 177 form.owner.down('button[action=discard]').setDisabled(false);
163 if ( valid && form.getValues().ortId !== '' 178 if (valid) {
164 && /[UEZA]/.test(form.getValues().ortszuordnungTyp) 179 if (form.getValues().ortId !== ''
165 ) { 180 && /[UEZA]/.test(form.getValues().ortszuordnungTyp)) {
166 form.owner.down('button[action=save]').setDisabled(false); 181 // valid ortzuordnung(Probe)
182 form.owner.down('button[action=save]').setDisabled(false);
183 } else if (form.getValues().ort !== ''
184 && /[UEZA]/.test(form.getValues().ortsTyp)) {
185 // valid ortzuordnung(messprogramm)
186 form.owner.down('button[action=save]').setDisabled(false);
187 } else {
188 form.owner.down('button[action=save]').setDisabled(true);
189 }
167 } else { 190 } else {
191 //invalid
168 form.owner.down('button[action=save]').setDisabled(true); 192 form.owner.down('button[action=save]').setDisabled(true);
169 } 193 }
170 } else { 194 } else {
195 //not dirty
196 form.owner.down('button[action=save]').setDisabled(true);
171 form.owner.down('button[action=discard]').setDisabled(true); 197 form.owner.down('button[action=discard]').setDisabled(true);
172 } 198 }
173 } 199 }
174 }); 200 });

http://lada.wald.intevation.org