comparison app/view/widgets/LadaForm.js @ 83:8525e3525538

Move parsing the response in a seperate function.
author Torsten Irländer <torsten.irlaender@intevation.de>
date Tue, 11 Jun 2013 11:17:33 +0200
parents 4a82e28dfcc4
children 5ad82cff1a21
comparison
equal deleted inserted replaced
82:679dedddb688 83:8525e3525538
63 if (this.form.isDirty()) { 63 if (this.form.isDirty()) {
64 this.form.updateRecord(this.model); 64 this.form.updateRecord(this.model);
65 65
66 this.model.save({ 66 this.model.save({
67 callback: function(records, operation) { 67 callback: function(records, operation) {
68 this.parseResponse(operation);
68 if (operation.wasSuccessful()) { 69 if (operation.wasSuccessful()) {
69 console.log('Save was successfull'); 70 console.log('Save was successfull');
70 this.fireEvent('savesuccess', this, records, operation); 71 this.fireEvent('savesuccess', this, records, operation);
71 } else { 72 } else {
72 console.log('Save was not successfull'); 73 console.log('Save was not successfull');
73 this.errors = this.translateReturnCodes(operation.request.scope.reader.jsonData["errors"]);
74 this.warnings = this.translateReturnCodes(operation.request.scope.reader.jsonData["warnings"]);
75 this.message = Lada.getApplication().bundle.getMsg(operation.request.scope.reader.jsonData["message"]);
76 this.form.markInvalid(this.errors); 74 this.form.markInvalid(this.errors);
77 this.fireEvent('savefailure', this, records, operation); 75 this.fireEvent('savefailure', this, records, operation);
78 } 76 }
79 if (callback) { 77 if (callback) {
80 callback.call(scope || this, this, operation.wasSuccessful(), this.model); 78 callback.call(scope || this, this, operation.wasSuccessful(), this.model);
85 } 83 }
86 }, 84 },
87 85
88 onModelLoadSuccess: function(record, operation) { 86 onModelLoadSuccess: function(record, operation) {
89 this.bindModel(record); 87 this.bindModel(record);
88 this.parseResponse(operation);
90 this.fireEvent('loadsuccess', this, record, operation); 89 this.fireEvent('loadsuccess', this, record, operation);
91 }, 90 },
92 91
93 onModelLoadFailure: function(record, operation) { 92 onModelLoadFailure: function(record, operation) {
93 this.parseResponse(operation);
94 this.fireEvent('loadfailure', this, record, operation); 94 this.fireEvent('loadfailure', this, record, operation);
95 }, 95 },
96 96
97 translateReturnCodes: function(codes) { 97 translateReturnCodes: function(codes) {
98 var translated = {}; 98 var translated = {};
99 for (var k in codes) { 99 for (var k in codes) {
100 translated[k] = Lada.getApplication().bundle.getMsg(codes[k]); 100 translated[k] = Lada.getApplication().bundle.getMsg(codes[k]);
101 } 101 }
102 return translated; 102 return translated;
103 },
104 parseResponse: function(operation) {
105 this.errors = this.translateReturnCodes(operation.request.scope.reader.jsonData["errors"]);
106 this.warnings = this.translateReturnCodes(operation.request.scope.reader.jsonData["warnings"]);
107 this.message = Lada.getApplication().bundle.getMsg(operation.request.scope.reader.jsonData["message"]);
103 } 108 }
104 109
105 }); 110 });

http://lada.wald.intevation.org