[MERGE] callback2deferred dataset.create

bzr revid: al@openerp.com-20120930144528-dbtbt8xad3tsqndi
This commit is contained in:
Antony Lesuisse 2012-09-30 16:45:28 +02:00
commit 04c263f284
3 changed files with 9 additions and 14 deletions

View File

@ -635,11 +635,10 @@ instance.web.DataSet = instance.web.CallbackEnabled.extend({
* @param {Function} error_callback function called in case of creation error
* @returns {$.Deferred}
*/
create: function(data, callback, error_callback) {
create: function(data) {
return this._model.call('create',
[data], {context: this._model.context()})
.pipe(function (r) { return {result: r}; })
.then(callback, error_callback);
.pipe(function (r) { return {result: r}; });
},
/**
* Saves the provided data in an existing db record
@ -919,14 +918,12 @@ instance.web.BufferedDataSet = instance.web.DataSetStatic.extend({
on_default_get: function(res) {
this.last_default_get = res;
},
create: function(data, callback, error_callback) {
create: function(data) {
var cached = {id:_.uniqueId(this.virtual_id_prefix), values: data,
defaults: this.last_default_get};
this.to_create.push(_.extend(_.clone(cached), {values: _.clone(cached.values)}));
this.cache.push(cached);
var prom = $.Deferred().then(callback);
prom.resolve({result: cached.id});
return prom.promise();
return $.Deferred().resolve({result: cached.id}).promise();
},
write: function (id, data, options, callback) {
var self = this;
@ -1095,9 +1092,9 @@ instance.web.ProxyDataSet = instance.web.DataSetSearch.extend({
return this._super.apply(this, arguments);
}
},
create: function(data, callback, error_callback) {
create: function(data) {
if (this.create_function) {
return this.create_function(data, this._super).then(callback, error_callback);
return this.create_function(data, this._super);
} else {
return this._super.apply(this, arguments);
}

View File

@ -305,7 +305,7 @@ instance.web_calendar.CalendarView = instance.web.View.extend({
do_create_event: function(event_id, event_obj) {
var self = this,
data = this.get_event_data(event_obj);
this.dataset.create(data, function(r) {
this.dataset.create(data).then(function(r) {
var id = r.result;
self.dataset.ids.push(id);
scheduler.changeEventId(event_id, id);

View File

@ -148,9 +148,7 @@ instance.web_view_editor.ViewEditor = instance.web.Widget.extend({
if (records) {view_string = records[0].name;}
var arch = _.str.sprintf("<?xml version='1.0'?>\n<%s string='%s'>\n\t<field name='%s'/>\n</%s>", values.view_type, view_string, field_name, values.view_type);
var vals = {'model': self.model, 'name': values.view_name, 'priority': values.priority, 'type': values.view_type, 'arch': arch};
self.dataset.create(vals, function(suc) {
def.resolve();
});
def = self.dataset.create(vals);
});
}
});
@ -458,7 +456,7 @@ instance.web_view_editor.ViewEditor = instance.web.Widget.extend({
var priority = _.detect(self.one_object['arch'], function(val) {return val.view_id == view_id;});
var arch = _.str.sprintf("<?xml version='1.0'?>\n\t <field name='%s' position='after'> </field>", val[1]);
var vals = {'model': self.model, 'name': view_name, 'priority': priority.priority + 1, 'type': "form", 'arch': arch,'inherit_id':self.main_view_id};
this.dataset.create(vals, function(suc) {
this.dataset.create(vals).then(function(suc) {
var arch_to_obj = self.parse_xml(arch,suc.result);
obj.child_id.push(arch_to_obj[0]);
self.one_object['parent_child_id'] = self.parent_child_list(self.one_object['main_object'],[]);