comparison app/view/widgets/LadaForm.js @ 491:850ccfe5f3c4

Code style.
author Raimund Renkert <raimund.renkert@intevation.de>
date Fri, 31 Oct 2014 23:23:32 +0100
parents 446e99cfd425
children 7c0653e8d9f7
comparison
equal deleted inserted replaced
490:446e99cfd425 491:850ccfe5f3c4
49 * be set after calling the {setReadOnly} function. 49 * be set after calling the {setReadOnly} function.
50 */ 50 */
51 readonly: false, 51 readonly: false,
52 52
53 initComponent: function() { 53 initComponent: function() {
54 54 this.callParent(arguments);
55 this.callParent();
56 55
57 this.getForm().trackResetOnLoad = true; //Workaround 56 this.getForm().trackResetOnLoad = true; //Workaround
58 57
59 if (Ext.isString(this.model)) { 58 if (Ext.isString(this.model)) {
60
61 //Load a model to be updated 59 //Load a model to be updated
62 if (this.modelId) { 60 if (this.modelId) {
63
64 Ext.ClassManager.get(this.model).load(this.modelId, { 61 Ext.ClassManager.get(this.model).load(this.modelId, {
65 failure: this.onModelLoadFailure, 62 failure: this.onModelLoadFailure,
66 success: this.onModelLoadSuccess, 63 success: this.onModelLoadSuccess,
67 scope: this 64 scope: this
68 }); 65 });
69
70 //Load an empty record to be inserted 66 //Load an empty record to be inserted
71 } else { 67 }
68 else {
72 this.bindModel(Ext.create(this.model, {})); 69 this.bindModel(Ext.create(this.model, {}));
73 } 70 }
74 71 }
75 } else { 72 else {
76 73
77 //Bind the provided model to be updated 74 //Bind the provided model to be updated
78 this.bindModel(this.model); 75 this.bindModel(this.model);
79 76
80 } 77 }
81 78 this.addEvents(
82 this.addEvents('loadsuccess', 'loadfailure', 'savesuccess', 'savefailure'); 79 'loadsuccess',
80 'loadfailure',
81 'savesuccess',
82 'savefailure');
83 }, 83 },
84 84
85 bindModel: function(model) { 85 bindModel: function(model) {
86 this.model = model; 86 this.model = model;
87 this.loadRecord(model); 87 this.loadRecord(model);
112 callback: function(option, success, response) { 112 callback: function(option, success, response) {
113 this.parseResponse(response); 113 this.parseResponse(response);
114 if (this.success) { 114 if (this.success) {
115 console.log('Save was successfull'); 115 console.log('Save was successfull');
116 this.fireEvent('savesuccess', this, this.model, response); 116 this.fireEvent('savesuccess', this, this.model, response);
117 } else { 117 }
118 else {
118 console.log('Save was not successfull'); 119 console.log('Save was not successfull');
119 this.form.markInvalid(this.errors); 120 this.form.markInvalid(this.errors);
120 this.fireEvent('savefailure', this, this.model, response); 121 this.fireEvent('savefailure', this, this.model, response);
121 } 122 }
122 }, 123 },
156 /* Iterate over all fields and set them readonly */ 157 /* Iterate over all fields and set them readonly */
157 if (bReadOnly) { 158 if (bReadOnly) {
158 this.getForm().getFields().each (function (field) { 159 this.getForm().getFields().each (function (field) {
159 // Check if the field name is in the list of fields to ignore 160 // Check if the field name is in the list of fields to ignore
160 var ignore = false; 161 var ignore = false;
161 for (var i = ignoreFields.length - 1; i >= 0; i--){ 162 for (var i = ignoreFields.length - 1; i >= 0; i--) {
162 console.log(ignoreFields[i] + "===" + field.getName()); 163 console.log(ignoreFields[i] + "===" + field.getName());
163 if (ignoreFields[i] === field.getName(true)) { 164 if (ignoreFields[i] === field.getName(true)) {
164 ignore = true; 165 ignore = true;
165 }; 166 };
166 }; 167 };
169 field.setReadOnly(true); 170 field.setReadOnly(true);
170 } 171 }
171 }); 172 });
172 /* Iterate over all toolbars of lists and hide them */ 173 /* Iterate over all toolbars of lists and hide them */
173 var childs = this.query('toolbar'); 174 var childs = this.query('toolbar');
174 for (var i = childs.length - 1; i >= 0; i--){ 175 for (var i = childs.length - 1; i >= 0; i--) {
175 childs[i].setVisible(false); 176 childs[i].setVisible(false);
176 } 177 }
177 /* 178 /*
178 * Find Save-Button and hide it. Only hide it if there are not 179 * Find Save-Button and hide it. Only hide it if there are not
179 * fields left in the form which are editable 180 * fields left in the form which are editable
180 * */ 181 * */
181 if (ignoreFields.length == 0) { 182 if (ignoreFields.length == 0) {
182 var win = this.up('window'); 183 var win = this.up('window');
183 var buttons = win.query('.button'); 184 var buttons = win.query('.button');
184 for (var j = buttons.length - 1; j >= 0; j--){ 185 for (var j = buttons.length - 1; j >= 0; j--) {
185 if (buttons[j].text === 'Speichern') { 186 if (buttons[j].text === 'Speichern') {
186 buttons[j].setVisible(false); 187 buttons[j].setVisible(false);
187 }; 188 };
188 }; 189 };
189 } 190 }
190 } 191 }
191 }, 192 },
193
192 parseResponse: function(response) { 194 parseResponse: function(response) {
193 var json = Ext.decode(response.responseText); 195 var json = Ext.decode(response.responseText);
194 if (json) { 196 if (json) {
195 this.success = json.success; 197 this.success = json.success;
196 this.errors = this.translateReturnCodes(json.errors); 198 this.errors = this.translateReturnCodes(json.errors);
199 var e = Ext.Object.isEmpty(this.warnings); 201 var e = Ext.Object.isEmpty(this.warnings);
200 if (!Ext.Object.isEmpty(this.warnings) || 202 if (!Ext.Object.isEmpty(this.warnings) ||
201 !Ext.Object.isEmpty(this.errors)) { 203 !Ext.Object.isEmpty(this.errors)) {
202 this.createMessages(); 204 this.createMessages();
203 } 205 }
204 } else { 206 }
207 else {
205 this.setReadOnly(this.model.get('readonly')); 208 this.setReadOnly(this.model.get('readonly'));
206 } 209 }
207 }, 210 },
211
208 createMessages: function() { 212 createMessages: function() {
209 var messages = Ext.create('Ext.form.Panel', { 213 var messages = Ext.create('Ext.form.Panel', {
210 bodyPadding: '5 5 5 5' 214 bodyPadding: '5 5 5 5'
211 }); 215 });
212 for (var key in this.warnings) { 216 for (var key in this.warnings) {

http://lada.wald.intevation.org