odoo/addons/hr_timesheet_sheet/static/src/js/timesheet.js

44 lines
1.6 KiB
JavaScript
Raw Normal View History

openerp.hr_timesheet_sheet = function(instance) {
var QWeb = instance.web.qweb;
var _t = instance.web._t;
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');
};