Mercurial > lada > lada-client
comparison app/view/widgets/LadaForm.js @ 133:819bfedb70de
Do not use the model.save mathod to store items in the databut but trigger a
custom Ajax POST or PUT request.
author | Torsten Irländer <torsten.irlaender@intevation.de> |
---|---|
date | Tue, 25 Jun 2013 17:32:07 +0200 |
parents | ee1d1305dcff |
children | df5dcdff7b69 |
comparison
equal
deleted
inserted
replaced
132:04439f3feba3 | 133:819bfedb70de |
---|---|
19 border: 0, | 19 border: 0, |
20 | 20 |
21 errors: null, | 21 errors: null, |
22 warnings: null, | 22 warnings: null, |
23 message: null, | 23 message: null, |
24 success: null, | |
24 readonly: false, | 25 readonly: false, |
25 | 26 |
26 initComponent: function() { | 27 initComponent: function() { |
27 | 28 |
28 this.callParent(); | 29 this.callParent(); |
62 | 63 |
63 commit: function(callback, scope) { | 64 commit: function(callback, scope) { |
64 if (this.form.isDirty() && this.form.isValid()) { | 65 if (this.form.isDirty() && this.form.isValid()) { |
65 this.form.updateRecord(this.model); | 66 this.form.updateRecord(this.model); |
66 | 67 |
67 this.model.save({ | 68 var data = this.model.getAllData(); |
68 callback: function(records, operation) { | 69 var baseUrl = this.model.getProxy().url; |
69 this.parseResponse(operation); | 70 var url = baseUrl; |
70 if (operation.wasSuccessful()) { | 71 var method = "POST"; |
72 if (this.model.getId()) { | |
73 url += this.model.getEidi(); | |
74 method = "PUT"; | |
75 } | |
76 | |
77 Ext.Ajax.request({ | |
78 url: url, | |
79 jsonData: data, | |
80 method: method, | |
81 callback: function(option, success, response) { | |
82 this.parseResponse(response); | |
83 if (this.success) { | |
71 console.log('Save was successfull'); | 84 console.log('Save was successfull'); |
72 this.fireEvent('savesuccess', this, records, operation); | 85 this.fireEvent('savesuccess', this); |
73 } else { | 86 } else { |
74 console.log('Save was not successfull'); | 87 console.log('Save was not successfull'); |
75 this.form.markInvalid(this.errors); | 88 this.form.markInvalid(this.errors); |
76 this.fireEvent('savefailure', this, records, operation); | 89 this.fireEvent('savefailure', this); |
77 } | |
78 if (callback) { | |
79 callback.call(scope || this, this, operation.wasSuccessful(), this.model); | |
80 } | 90 } |
81 }, | 91 }, |
82 scope: this | 92 scope: this |
83 }); | 93 }); |
94 | |
95 //this.model.save({ | |
96 // callback: function(records, operation) { | |
97 // this.parseResponse(operation); | |
98 // if (operation.wasSuccessful()) { | |
99 // console.log('Save was successfull'); | |
100 // this.fireEvent('savesuccess', this, records, operation); | |
101 // } else { | |
102 // console.log('Save was not successfull'); | |
103 // this.form.markInvalid(this.errors); | |
104 // this.fireEvent('savefailure', this, records, operation); | |
105 // } | |
106 // if (callback) { | |
107 // callback.call(scope || this, this, operation.wasSuccessful(), this.model); | |
108 // } | |
109 // }, | |
110 // scope: this | |
111 //}); | |
84 } | 112 } |
85 }, | 113 }, |
86 | 114 |
87 onModelLoadSuccess: function(record, operation) { | 115 onModelLoadSuccess: function(record, operation) { |
88 this.bindModel(record); | 116 this.bindModel(record); |
106 this.getForm().getFields().each (function (field) { | 134 this.getForm().getFields().each (function (field) { |
107 //field.setDisabled(bReadOnly); | 135 //field.setDisabled(bReadOnly); |
108 field.setReadOnly(bReadOnly); | 136 field.setReadOnly(bReadOnly); |
109 }); | 137 }); |
110 }, | 138 }, |
111 parseResponse: function(operation) { | 139 parseResponse: function(response) { |
112 this.errors = this.translateReturnCodes(operation.request.scope.reader.jsonData["errors"]); | 140 var json = Ext.decode(response.responseText); |
113 this.warnings = this.translateReturnCodes(operation.request.scope.reader.jsonData["warnings"]); | 141 if (json) { |
114 this.message = Lada.getApplication().bundle.getMsg(operation.request.scope.reader.jsonData["message"]); | 142 this.success = json.success; |
143 this.errors = this.translateReturnCodes(json.errors); | |
144 this.warnings = this.translateReturnCodes(json.warnings); | |
145 this.message = Lada.getApplication().bundle.getMsg(json.message); | |
146 } | |
115 //this.setReadOnly(true); | 147 //this.setReadOnly(true); |
116 } | 148 } |
149 // This parse method is used if the model.save() method is used to trigger | |
150 // a request on the server side. In this case the response object is | |
151 // different. | |
152 //parseResponse: function(operation) { | |
153 // this.errors = this.translateReturnCodes(operation.request.scope.reader.jsonData["errors"]); | |
154 // this.warnings = this.translateReturnCodes(operation.request.scope.reader.jsonData["warnings"]); | |
155 // this.message = Lada.getApplication().bundle.getMsg(operation.request.scope.reader.jsonData["message"]); | |
156 // //this.setReadOnly(true); | |
157 //} | |
117 | 158 |
118 }); | 159 }); |