[MERGE] trunk-deferred-write, change r.result into r

bzr revid: al@openerp.com-20121001220248-e40r7wypgzxa3i0a
This commit is contained in:
Antony Lesuisse 2012-10-02 00:02:48 +02:00
commit f025e07860
6 changed files with 23 additions and 31 deletions

View File

@ -636,8 +636,7 @@ instance.web.DataSet = instance.web.CallbackEnabled.extend({
* @returns {$.Deferred} * @returns {$.Deferred}
*/ */
create: function(data) { create: function(data) {
return this._model.call('create', [data], {context: this._model.context()}) return this._model.call('create', [data], {context: this._model.context()});
.pipe(function (r) { return {result: r}; });
}, },
/** /**
* Saves the provided data in an existing db record * Saves the provided data in an existing db record
@ -648,12 +647,9 @@ instance.web.DataSet = instance.web.CallbackEnabled.extend({
* @param {Function} error_callback function called in case of write error * @param {Function} error_callback function called in case of write error
* @returns {$.Deferred} * @returns {$.Deferred}
*/ */
write: function (id, data, options, callback, error_callback) { write: function (id, data, options) {
options = options || {}; options = options || {};
return this._model.call('write', return this._model.call('write', [[id], data], {context: this._model.context(options.context)});
[[id], data], {context: this._model.context(options.context)})
.pipe(function (r) { return {result: r}})
.then(callback, error_callback);
}, },
/** /**
* Deletes an existing record from the database * Deletes an existing record from the database
@ -916,9 +912,9 @@ instance.web.BufferedDataSet = instance.web.DataSetStatic.extend({
defaults: this.last_default_get}; defaults: this.last_default_get};
this.to_create.push(_.extend(_.clone(cached), {values: _.clone(cached.values)})); this.to_create.push(_.extend(_.clone(cached), {values: _.clone(cached.values)}));
this.cache.push(cached); this.cache.push(cached);
return $.Deferred().resolve({result: cached.id}).promise(); return $.Deferred().resolve(cached.id).promise();
}, },
write: function (id, data, options, callback) { write: function (id, data, options) {
var self = this; var self = this;
var record = _.detect(this.to_create, function(x) {return x.id === id;}); var record = _.detect(this.to_create, function(x) {return x.id === id;});
record = record || _.detect(this.to_write, function(x) {return x.id === id;}); record = record || _.detect(this.to_write, function(x) {return x.id === id;});
@ -944,9 +940,7 @@ instance.web.BufferedDataSet = instance.web.DataSetStatic.extend({
$.extend(cached.values, record.values); $.extend(cached.values, record.values);
if (dirty) if (dirty)
this.on_change(); this.on_change();
var to_return = $.Deferred().then(callback); return $.Deferred().resolve(true).promise();
to_return.resolve({result: true});
return to_return.promise();
}, },
unlink: function(ids, callback, error_callback) { unlink: function(ids, callback, error_callback) {
var self = this; var self = this;
@ -1092,9 +1086,9 @@ instance.web.ProxyDataSet = instance.web.DataSetSearch.extend({
return this._super.apply(this, arguments); return this._super.apply(this, arguments);
} }
}, },
write: function (id, data, options, callback, error_callback) { write: function (id, data, options) {
if (this.write_function) { if (this.write_function) {
return this.write_function(id, data, options, this._super).then(callback, error_callback); return this.write_function(id, data, options, this._super);
} else { } else {
return this._super.apply(this, arguments); return this._super.apply(this, arguments);
} }

View File

@ -881,7 +881,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
* @param {Object} r result of the write function. * @param {Object} r result of the write function.
*/ */
on_saved: function(r) { on_saved: function(r) {
if (!r.result) { if (!r) {
// should not happen in the server, but may happen for internal purpose // should not happen in the server, but may happen for internal purpose
return $.Deferred().reject(); return $.Deferred().reject();
} else { } else {
@ -904,11 +904,11 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
* at the beginning of the dataset instead of the end * at the beginning of the dataset instead of the end
*/ */
on_created: function(r, prepend_on_create) { on_created: function(r, prepend_on_create) {
if (!r.result) { if (!r) {
// should not happen in the server, but may happen for internal purpose // should not happen in the server, but may happen for internal purpose
return $.Deferred().reject(); return $.Deferred().reject();
} else { } else {
this.datarecord.id = r.result; this.datarecord.id = r;
if (!prepend_on_create) { if (!prepend_on_create) {
this.dataset.alter_ids(this.dataset.ids.concat([this.datarecord.id])); this.dataset.alter_ids(this.dataset.ids.concat([this.datarecord.id]));
this.dataset.index = this.dataset.ids.length - 1; this.dataset.index = this.dataset.ids.length - 1;
@ -3484,7 +3484,7 @@ instance.web.form.One2ManyViewManager = instance.web.ViewManager.extend({
title: _t("Open: ") + self.o2m.string, title: _t("Open: ") + self.o2m.string,
create_function: function(data) { create_function: function(data) {
return self.o2m.dataset.create(data).then(function(r) { return self.o2m.dataset.create(data).then(function(r) {
self.o2m.dataset.set_ids(self.o2m.dataset.ids.concat([r.result])); self.o2m.dataset.set_ids(self.o2m.dataset.ids.concat([r]));
self.o2m.dataset.on_change(); self.o2m.dataset.on_change();
}); });
}, },
@ -3574,7 +3574,7 @@ instance.web.form.One2ManyListView = instance.web.ListView.extend({
alternative_form_view: self.o2m.field.views ? self.o2m.field.views["form"] : undefined, alternative_form_view: self.o2m.field.views ? self.o2m.field.views["form"] : undefined,
create_function: function(data, callback, error_callback) { create_function: function(data, callback, error_callback) {
return self.o2m.dataset.create(data).then(function(r) { return self.o2m.dataset.create(data).then(function(r) {
self.o2m.dataset.set_ids(self.o2m.dataset.ids.concat([r.result])); self.o2m.dataset.set_ids(self.o2m.dataset.ids.concat([r]));
self.o2m.dataset.on_change(); self.o2m.dataset.on_change();
}).then(callback, error_callback); }).then(callback, error_callback);
}, },
@ -3599,7 +3599,7 @@ instance.web.form.One2ManyListView = instance.web.ListView.extend({
pop.show_element(self.o2m.field.relation, id, self.o2m.build_context(), { pop.show_element(self.o2m.field.relation, id, self.o2m.build_context(), {
title: _t("Open: ") + self.o2m.string, title: _t("Open: ") + self.o2m.string,
write_function: function(id, data) { write_function: function(id, data) {
return self.o2m.dataset.write(id, data, {}, function(r) { return self.o2m.dataset.write(id, data, {}).then(function() {
self.o2m.reload_current_view(); self.o2m.reload_current_view();
}); });
}, },

View File

@ -306,7 +306,7 @@ instance.web_calendar.CalendarView = instance.web.View.extend({
var self = this, var self = this,
data = this.get_event_data(event_obj); data = this.get_event_data(event_obj);
this.dataset.create(data).then(function(r) { this.dataset.create(data).then(function(r) {
var id = r.result; var id = r;
self.dataset.ids.push(id); self.dataset.ids.push(id);
scheduler.changeEventId(event_id, id); scheduler.changeEventId(event_id, id);
self.refresh_minical(); self.refresh_minical();
@ -348,7 +348,7 @@ instance.web_calendar.CalendarView = instance.web.View.extend({
index = this.dataset.get_id_index(event_id); index = this.dataset.get_id_index(event_id);
if (index != null) { if (index != null) {
event_id = this.dataset.ids[index]; event_id = this.dataset.ids[index];
this.dataset.write(event_id, data, {}, function() { this.dataset.write(event_id, data, {}).then(function() {
self.refresh_minical(); self.refresh_minical();
}); });
} }

View File

@ -206,9 +206,7 @@ instance.web_gantt.GanttView = instance.web.View.extend({
} else { // we assume date_duration is defined } else { // we assume date_duration is defined
data[self.fields_view.arch.attrs.date_delay] = duration; data[self.fields_view.arch.attrs.date_delay] = duration;
} }
this.dataset.write(itask.id, data).then(function() { this.dataset.write(itask.id, data);
console.log("task edited");
});
}, },
on_task_display: function(task) { on_task_display: function(task) {
var self = this; var self = this;

View File

@ -379,7 +379,7 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
record.group = new_group; record.group = new_group;
var data = {}; var data = {};
data[this.group_by] = new_group.value; data[this.group_by] = new_group.value;
this.dataset.write(record.id, data, {}, function() { this.dataset.write(record.id, data, {}).then(function() {
record.do_reload(); record.do_reload();
new_group.do_save_sequences(); new_group.do_save_sequences();
}).fail(function(error, evt) { }).fail(function(error, evt) {
@ -877,7 +877,7 @@ instance.web_kanban.KanbanRecord = instance.web.Widget.extend({
var color_field = $(this).parents('.oe_kanban_colorpicker').first().data('field') || 'color'; var color_field = $(this).parents('.oe_kanban_colorpicker').first().data('field') || 'color';
var data = {}; var data = {};
data[color_field] = $(this).data('color'); data[color_field] = $(this).data('color');
self.view.dataset.write(self.id, data, {}, function() { self.view.dataset.write(self.id, data, {}).then(function() {
self.record[color_field] = $(this).data('color'); self.record[color_field] = $(this).data('color');
self.do_reload(); self.do_reload();
}); });

View File

@ -456,11 +456,11 @@ 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 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 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}; 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).then(function(suc) { this.dataset.create(vals).then(function(id) {
var arch_to_obj = self.parse_xml(arch,suc.result); var arch_to_obj = self.parse_xml(arch,id);
obj.child_id.push(arch_to_obj[0]); obj.child_id.push(arch_to_obj[0]);
self.one_object['parent_child_id'] = self.parent_child_list(self.one_object['main_object'],[]); self.one_object['parent_child_id'] = self.parent_child_list(self.one_object['main_object'],[]);
self.one_object['arch'].push({'view_id':suc.result,"arch":arch,'priority': priority.priority + 1}); self.one_object['arch'].push({'view_id':id,"arch":arch,'priority': priority.priority + 1});
self.increase_level(arch_to_obj[0],obj.level+1); self.increase_level(arch_to_obj[0],obj.level+1);
self.render_inherited_view(selected_row,arch_to_obj[0]); self.render_inherited_view(selected_row,arch_to_obj[0]);
}); });
@ -775,7 +775,7 @@ instance.web_view_editor.ViewEditor = instance.web.Widget.extend({
convert_to_utf = convert_to_utf.replace('xmlns="http://www.w3.org/1999/xhtml"', ""); convert_to_utf = convert_to_utf.replace('xmlns="http://www.w3.org/1999/xhtml"', "");
convert_to_utf = '<?xml version="1.0"?>' + convert_to_utf; convert_to_utf = '<?xml version="1.0"?>' + convert_to_utf;
arch.arch = convert_to_utf; arch.arch = convert_to_utf;
this.dataset.write(this.one_object.clicked_tr_view[0] ,{"arch":convert_to_utf}, function(r) {}); this.dataset.write(this.one_object.clicked_tr_view[0] ,{"arch":convert_to_utf});
} else { } else {
this.dataset.unlink([this.one_object.clicked_tr_view[0]]); this.dataset.unlink([this.one_object.clicked_tr_view[0]]);
} }