comparison app/view/widgets/LadaForm.js @ 515:66f3c5d258e2

Added save and discard buttons to proben header fields and listen to changes to enable or disable buttons.
author Raimund Renkert <raimund.renkert@intevation.de>
date Tue, 16 Dec 2014 13:21:54 +0100
parents 2b5aa0e6e641
children d2e90f117c20
comparison
equal deleted inserted replaced
514:61c76c12bd28 515:66f3c5d258e2
92 if (model.get('readonly') === true) { 92 if (model.get('readonly') === true) {
93 this.setReadOnly(true); 93 this.setReadOnly(true);
94 } 94 }
95 }, 95 },
96 96
97 reset: function() {
98 this.loadRecord(this.model);
99 this.updateOnChange();
100 },
101
97 commit: function() { 102 commit: function() {
98 if (this.form.isDirty() && this.form.isValid()) { 103 if (this.form.isDirty() && this.form.isValid()) {
99 this.form.updateRecord(this.model);
100 104
101 var data = this.model.getAllData(); 105 var data = this.model.getAllData();
102 var baseUrl = this.model.getProxy().url; 106 var baseUrl = this.model.getProxy().url;
103 var url = baseUrl; 107 var url = baseUrl;
104 var method = 'POST'; 108 var method = 'POST';
112 jsonData: data, 116 jsonData: data,
113 method: method, 117 method: method,
114 callback: function(option, success, response) { 118 callback: function(option, success, response) {
115 this.parseResponse(response); 119 this.parseResponse(response);
116 if (this.success) { 120 if (this.success) {
121 this.form.updateRecord(this.model);
117 this.fireEvent( 122 this.fireEvent(
118 'savesuccess', 123 'savesuccess',
119 this, 124 this,
120 this.model, 125 this.model,
121 response); 126 response);
127 this.updateOnChange();
122 } 128 }
123 else { 129 else {
124 this.form.markInvalid(this.errors); 130 this.form.markInvalid(this.errors);
125 this.fireEvent( 131 this.fireEvent(
126 'savefailure', 132 'savefailure',
255 }] 261 }]
256 }); 262 });
257 messages.insert(0, label); 263 messages.insert(0, label);
258 } 264 }
259 this.insert(0, messages); 265 this.insert(0, messages);
266 },
267
268 updateOnChange: function() {
269 console.log(this.isDirty());
270 var childs = this.query('toolbar');
271 for (var i = childs.length - 1; i >= 0; i--) {
272 if (childs[i].ownerCt.xtype === 'panel') {
273 if (this.isDirty()) {
274 childs[i].down('button[action=discard]').enable();
275 childs[i].down('button[action=save]').enable();
276 }
277 else {
278 childs[i].down('button[action=discard]').disable();
279 childs[i].down('button[action=save]').disable();
280 }
281 }
282 else {
283 var btn = childs[i].down('button[action=add]');
284 if (this.isDirty()) {
285 btn.disable();
286 }
287 else {
288 btn.enable();
289 }
290 }
291 }
260 } 292 }
261 }); 293 });

http://lada.wald.intevation.org