comparison app/controller/form/Ortszuordnung.js @ 1288:08085b7d1d0b

Ortszuordnung: Search, new orte, display and validity check
author Maximilian Krambach <mkrambach@intevation.de>
date Fri, 27 Jan 2017 13:25:14 +0100
parents a792eecf1614
children bfdc00c24baf
comparison
equal deleted inserted replaced
1287:e317ba349204 1288:08085b7d1d0b
25 }, 25 },
26 'ortszuordnungform button[action=discard]': { 26 'ortszuordnungform button[action=discard]': {
27 click: this.discard 27 click: this.discard
28 }, 28 },
29 'ortszuordnungform': { 29 'ortszuordnungform': {
30 dirtychange: this.dirtyForm 30 validitychange: this.validityChange,
31 dirtychange: this.validityChange
31 } 32 }
32 }); 33 });
33 }, 34 },
34 35
35 /** 36 /**
82 button.up('toolbar').down('button[action=discard]') 83 button.up('toolbar').down('button[action=discard]')
83 .setDisabled(true); 84 .setDisabled(true);
84 formPanel.getForm().loadRecord(formPanel.getForm().getRecord()); 85 formPanel.getForm().loadRecord(formPanel.getForm().getRecord());
85 var json = response.request.scope.reader.jsonData; 86 var json = response.request.scope.reader.jsonData;
86 if (json) { 87 if (json) {
87 if(json.errors.totalCount > 0 || json.warnings.totalCount > 0){ 88 if(Object.keys(json.errors).length > 0 ||
89 Object.keys(json.warnings).length > 0) {
90
88 formPanel.setMessages(json.errors, json.warnings); 91 formPanel.setMessages(json.errors, json.warnings);
89 } 92 }
90 93
91 if(json.message){ 94 if(json.message){
92 Ext.Msg.alert(i18n.getMsg('err.msg.save.title') 95 Ext.Msg.alert(i18n.getMsg('err.msg.save.title')
116 formPanel.refreshOrt(record.get('ortId')); 119 formPanel.refreshOrt(record.get('ortId'));
117 formPanel.down('button[action=setOrt]').toggle(false); 120 formPanel.down('button[action=setOrt]').toggle(false);
118 } 121 }
119 catch (e) { 122 catch (e) {
120 } 123 }
121 //set undirty.
122 formPanel.fireEvent('dirtychange', formPanel.getForm(), false);
123 }, 124 },
124 125
125 /** 126 /**
126 * When the button is Active, a Record can be selected. 127 * When the button is Active, a Record can be selected.
127 * If the Record was selected from a grid this function 128 * If the Record was selected from a grid this function
128 * sets the ortzuordnung. 129 * sets the ortzuordnung.
129 * TODO: Check if the selected Record is a ORT 130 * TODO: Check if the selected Record is a ORT
130 * TODO: Enable picking from Maps
131 */ 131 */
132 pickOrt: function(button, pressed, opts) { 132 chooseLocation: function(button, pressed, opts) {
133 var i18n = Lada.getApplication().bundle; 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 chooseLocation: function(button, pressed, opts) {
147 var win = button.up('window'); 134 var win = button.up('window');
148 var gridPanel = win.down('panel[name=ortgrid]'); 135 var gridPanel = win.down('panel[name=ortgrid]');
136 var osg = win.down('ortstammdatengrid');
137 var oForm = button.up('form');
149 if (pressed) { 138 if (pressed) {
150 win.setHeight(Ext.getBody().getViewSize().height - 50); 139 win.setHeight(Ext.getBody().getViewSize().height - 50);
140 button.setText(i18n.getMsg('ortszuordnung.form.setOrt.pressed'));
151 win.setY(25); 141 win.setY(25);
152 gridPanel.show(); 142 gridPanel.show();
143 osg.addListener('select',oForm.setOrt, oForm);
144
153 } 145 }
154 else { 146 else {
155 var y = (Ext.getBody().getViewSize().height - 465) / 2 147 var y = (Ext.getBody().getViewSize().height - 465) / 2
156 win.setHeight(465); 148 win.setHeight(465);
157 win.setY(y); 149 win.setY(y);
150 button.setText(i18n.getMsg('ortszuordnung.form.setOrt'));
158 gridPanel.hide(); 151 gridPanel.hide();
152 osg.removeListener('select',oForm.setOrt, oForm);
159 } 153 }
160 }, 154 },
161 155
162
163 /** 156 /**
164 * The dirtyForm function enables or disables the save and discard 157 * The validitychange function enables or disables the save and discard
165 * button which are present in the toolbar of the form. 158 * button which are present in the toolbar of the form.
166 * The Buttons are only active if the content of the form was altered
167 * (the form is dirty).
168 */ 159 */
169 dirtyForm: function(form, dirty) { 160 validityChange: function(form, valid) {
170 if (dirty) { 161 if (form.isDirty()) {
171 if (form.getValues().ortId !== '' 162 form.owner.down('button[action=discard]').setDisabled(false);
163 if ( valid && form.getValues().ortId !== ''
172 && /[UEZA]/.test(form.getValues().ortszuordnungTyp) 164 && /[UEZA]/.test(form.getValues().ortszuordnungTyp)
173 ) { 165 ) {
174 form.owner.down('button[action=save]').setDisabled(false); 166 form.owner.down('button[action=save]').setDisabled(false);
167 } else {
168 form.owner.down('button[action=save]').setDisabled(true);
175 } 169 }
176 form.owner.down('button[action=discard]').setDisabled(false); 170 } else {
177 }
178 else {
179 form.owner.down('button[action=save]').setDisabled(true);
180 form.owner.down('button[action=discard]').setDisabled(true); 171 form.owner.down('button[action=discard]').setDisabled(true);
181 } 172 }
182 } 173 }
183 }); 174 });

http://lada.wald.intevation.org