Synchronize with the o2m

bzr revid: nicolas.vanhoren@openerp.com-20120928143403-feje9sa10bqeo56r
This commit is contained in:
niv-openerp 2012-09-28 16:34:03 +02:00
parent 35277fd0b1
commit 27ce5af186
1 changed files with 30 additions and 0 deletions

View File

@ -5,7 +5,37 @@ openerp.hr_timesheet_sheet = function(instance) {
instance.hr_timesheet_sheet.WeeklyTimesheet = instance.web.form.FormWidget.extend({
template: "hr_timesheet_sheet.WeeklyTimesheet",
init: function() {
this._super.apply(this, arguments);
this.set({sheets: []});
this.field_manager.on("field_changed:timesheet_ids", this, this.query_sheets);
this.on("change:sheets", this, this.update_sheets);
this.res_o2m_drop = new instance.web.DropMisordered();
},
query_sheets: function() {
var self = this;
if (self.updating)
return;
var commands = this.field_manager.get_field_value("timesheet_ids");
this.res_o2m_drop.add(new instance.web.Model(this.view.model).call("resolve_2many_commands", ["timesheet_ids", commands, []]))
.then(function(result) {
self.querying = true;
self.set({sheets: result});
self.querying = false;
});
},
update_sheets: function() {
var self = this;
if (self.querying)
return;
self.updating = true;
self.field_manager.set_values({timesheet_ids: self.get("sheets")}).then(function() {
self.updating = false;
});
},
start: function() {
},
});
instance.web.form.custom_widgets.add('weekly_timesheet', 'instance.hr_timesheet_sheet.WeeklyTimesheet');