How to refactor Ext.Ajax.request to Ext.Model.save
Hi,
I have the following code:
Code:
assignModel: function(model, date, callback) {
var credentials = Ext.getStore('credentialsStore').first();
Ext.Ajax.request({
url: MyApp.Save,
params: {
username: credentials.get('username'),
password: "",
token: credentials.get('token'),
ApiKey: MyApp.apiKey,
date: Ext.Date.format(date, 'Y-m-d'),
modelId: model.get('id')
},
success: function () {
Ext.callback(callback.success);
},
failure: function () {
Ext.callback(callback.failure, null, ["Failed to assign model"]);
}
});
}
And I want to refactor this by using model.save, here's the model:
Code:
Ext.define('MyApp.Model', { extend: 'Ext.data.Model',
config: {
idProperty: 'id',
fields: [
{
name: 'id',
mapping: 'Id',
type: 'string'
},
{
name: 'name',
mapping: 'Name',
type: 'string'
}
],
proxy: {
type: 'rest',
url : MyApp.Save,
actionMethods: {
create : 'POST',
update : 'POST',
}
}
}
});
When I do the first method, I get a clean POST-request with all the params.
When I do the model.save() method, I get an OPTION and a POST-request with the JSON-object somewhere in it.
How can I alter the save method from the model, so it sends the (username, password, token,...) parameters too? Why are there 2 requests being sent?