|
@ -1,7 +1,7 @@ |
|
|
/*--------------------------------------------------------- |
|
|
|
|
|
* Odoo web_timeline |
|
|
|
|
|
|
|
|
/* Odoo web_timeline |
|
|
* Copyright 2015 ACSONE SA/NV |
|
|
* Copyright 2015 ACSONE SA/NV |
|
|
*---------------------------------------------------------*/ |
|
|
|
|
|
|
|
|
* Copyright 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com> |
|
|
|
|
|
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
|
|
|
|
|
|
|
|
|
_.str.toBoolElse = function (str, elseValues, trueValues, falseValues) { |
|
|
_.str.toBoolElse = function (str, elseValues, trueValues, falseValues) { |
|
|
var ret = _.str.toBool(str, trueValues, falseValues); |
|
|
var ret = _.str.toBool(str, trueValues, falseValues); |
|
@ -11,21 +11,32 @@ _.str.toBoolElse = function (str, elseValues, trueValues, falseValues) { |
|
|
return ret; |
|
|
return ret; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
openerp.web_timeline = function(instance) { |
|
|
|
|
|
var _t = instance.web._t, |
|
|
|
|
|
_lt = instance.web._lt, |
|
|
|
|
|
QWeb = instance.web.qweb; |
|
|
|
|
|
|
|
|
odoo.define('web_timeline.TimelineView', function (require) { |
|
|
|
|
|
"use strict"; |
|
|
|
|
|
|
|
|
|
|
|
var core = require('web.core'); |
|
|
|
|
|
var form_common = require('web.form_common'); |
|
|
|
|
|
var Model = require('web.DataModel'); |
|
|
|
|
|
var time = require('web.time'); |
|
|
|
|
|
var View = require('web.View'); |
|
|
|
|
|
var widgets = require('web_calendar.widgets'); |
|
|
|
|
|
var _ = require('_'); |
|
|
|
|
|
var $ = require('$'); |
|
|
|
|
|
|
|
|
|
|
|
var _t = core._t; |
|
|
|
|
|
var _lt = core._lt; |
|
|
|
|
|
var QWeb = core.qweb; |
|
|
|
|
|
|
|
|
function isNullOrUndef(value) { |
|
|
function isNullOrUndef(value) { |
|
|
return _.isUndefined(value) || _.isNull(value); |
|
|
return _.isUndefined(value) || _.isNull(value); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
instance.web.views.add('timeline', 'instance.web_timeline.TimelineView'); |
|
|
|
|
|
|
|
|
|
|
|
instance.web_timeline.TimelineView = instance.web.View.extend({ |
|
|
|
|
|
|
|
|
var TimelineView = View.extend({ |
|
|
template: "TimelineView", |
|
|
template: "TimelineView", |
|
|
display_name: _lt('Timeline'), |
|
|
display_name: _lt('Timeline'), |
|
|
quick_create_instance: 'instance.web_timeline.QuickCreate', |
|
|
|
|
|
|
|
|
icon: 'fa-clock-o', |
|
|
|
|
|
quick_create_instance: widgets.QuickCreate, |
|
|
|
|
|
|
|
|
init: function (parent, dataset, view_id, options) { |
|
|
init: function (parent, dataset, view_id, options) { |
|
|
this._super(parent); |
|
|
this._super(parent); |
|
|
this.ready = $.Deferred(); |
|
|
this.ready = $.Deferred(); |
|
@ -48,7 +59,7 @@ openerp.web_timeline = function(instance) { |
|
|
var promise = self.permissions[name]; |
|
|
var promise = self.permissions[name]; |
|
|
if(!promise) { |
|
|
if(!promise) { |
|
|
var defer = $.Deferred(); |
|
|
var defer = $.Deferred(); |
|
|
new instance.web.Model(this.dataset.model) |
|
|
|
|
|
|
|
|
new Model(this.dataset.model) |
|
|
.call("check_access_rights", [name, false]) |
|
|
.call("check_access_rights", [name, false]) |
|
|
.then(function (value) { |
|
|
.then(function (value) { |
|
|
self.permissions[name] = value; |
|
|
self.permissions[name] = value; |
|
@ -84,14 +95,14 @@ openerp.web_timeline = function(instance) { |
|
|
this.fields_view = fv; |
|
|
this.fields_view = fv; |
|
|
this.parse_colors(); |
|
|
this.parse_colors(); |
|
|
this.$timeline = this.$el.find(".oe_timeline_widget"); |
|
|
this.$timeline = this.$el.find(".oe_timeline_widget"); |
|
|
this.$el.find(".oe_timeline_button_today").click(self.on_today_clicked); |
|
|
|
|
|
this.$el.find(".oe_timeline_button_scale_day").click(self.on_scale_day_clicked); |
|
|
|
|
|
this.$el.find(".oe_timeline_button_scale_week").click(self.on_scale_week_clicked); |
|
|
|
|
|
this.$el.find(".oe_timeline_button_scale_month").click(self.on_scale_month_clicked); |
|
|
|
|
|
this.$el.find(".oe_timeline_button_scale_year").click(self.on_scale_year_clicked); |
|
|
|
|
|
|
|
|
this.$el.find(".oe_timeline_button_today").click($.proxy(this.on_today_clicked, this)); |
|
|
|
|
|
this.$el.find(".oe_timeline_button_scale_day").click($.proxy(this.on_scale_day_clicked, this)); |
|
|
|
|
|
this.$el.find(".oe_timeline_button_scale_week").click($.proxy(this.on_scale_week_clicked, this)); |
|
|
|
|
|
this.$el.find(".oe_timeline_button_scale_month").click($.proxy(this.on_scale_month_clicked, this)); |
|
|
|
|
|
this.$el.find(".oe_timeline_button_scale_year").click($.proxy(this.on_scale_year_clicked, this)); |
|
|
this.current_window = { |
|
|
this.current_window = { |
|
|
start: new Date(), |
|
|
|
|
|
end : new Date().addHours(24), |
|
|
|
|
|
|
|
|
start: new moment(), |
|
|
|
|
|
end : new moment().add(24, 'hours'), |
|
|
} |
|
|
} |
|
|
this.info_fields = []; |
|
|
this.info_fields = []; |
|
|
|
|
|
|
|
@ -104,10 +115,8 @@ openerp.web_timeline = function(instance) { |
|
|
this.name = fv.name || attrs.string; |
|
|
this.name = fv.name || attrs.string; |
|
|
this.view_id = fv.view_id; |
|
|
this.view_id = fv.view_id; |
|
|
|
|
|
|
|
|
this.start = py.eval(attrs.start || 'None', instance.web.pyeval.context()); |
|
|
|
|
|
this.mode = attrs.mode; // one of month, week or day
|
|
|
|
|
|
this.date_start = attrs.date_start; // Field name of starting
|
|
|
|
|
|
// date field
|
|
|
|
|
|
|
|
|
this.mode = attrs.mode; |
|
|
|
|
|
this.date_start = attrs.date_start; |
|
|
this.date_stop = attrs.date_stop; |
|
|
this.date_stop = attrs.date_stop; |
|
|
|
|
|
|
|
|
if (!isNullOrUndef(attrs.quick_create_instance)) { |
|
|
if (!isNullOrUndef(attrs.quick_create_instance)) { |
|
@ -128,17 +137,17 @@ openerp.web_timeline = function(instance) { |
|
|
this.info_fields.push(fv.arch.children[fld].attrs.name); |
|
|
this.info_fields.push(fv.arch.children[fld].attrs.name); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var fields_get = new instance.web.Model(this.dataset.model) |
|
|
|
|
|
|
|
|
var fields_get = new Model(this.dataset.model) |
|
|
.call('fields_get') |
|
|
.call('fields_get') |
|
|
.then(function (fields) { |
|
|
.then(function (fields) { |
|
|
self.fields = fields; |
|
|
self.fields = fields; |
|
|
}); |
|
|
}); |
|
|
var unlink_check = new instance.web.Model(this.dataset.model) |
|
|
|
|
|
|
|
|
var unlink_check = new Model(this.dataset.model) |
|
|
.call("check_access_rights", ["unlink", false]) |
|
|
.call("check_access_rights", ["unlink", false]) |
|
|
.then(function (unlink_right) { |
|
|
.then(function (unlink_right) { |
|
|
self.unlink_right = unlink_right; |
|
|
self.unlink_right = unlink_right; |
|
|
}); |
|
|
}); |
|
|
var edit_check = new instance.web.Model(this.dataset.model) |
|
|
|
|
|
|
|
|
var edit_check = new Model(this.dataset.model) |
|
|
.call("check_access_rights", ["write", false]) |
|
|
.call("check_access_rights", ["write", false]) |
|
|
.then(function (write_right) { |
|
|
.then(function (write_right) { |
|
|
self.write_right = write_right; |
|
|
self.write_right = write_right; |
|
@ -152,8 +161,7 @@ openerp.web_timeline = function(instance) { |
|
|
}); |
|
|
}); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
var test = $.when(self.fields_get, self.get_perm('unlink'), self.get_perm('write'), self.get_perm('create')); |
|
|
|
|
|
return $.when(test).then(init); |
|
|
|
|
|
|
|
|
return $.when(self.fields_get, self.get_perm('unlink'), self.get_perm('write'), self.get_perm('create')).then(init); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
init_timeline: function() { |
|
|
init_timeline: function() { |
|
@ -161,10 +169,14 @@ openerp.web_timeline = function(instance) { |
|
|
var options = { |
|
|
var options = { |
|
|
groupOrder: self.group_order, |
|
|
groupOrder: self.group_order, |
|
|
editable: { |
|
|
editable: { |
|
|
add: self.permissions['create'], // add new items by double tapping
|
|
|
|
|
|
updateTime: self.permissions['write'], // drag items horizontally
|
|
|
|
|
|
updateGroup: self.permissions['write'], // drag items from one group to another
|
|
|
|
|
|
remove: self.permissions['unlink'], // delete an item by tapping the delete button top right
|
|
|
|
|
|
|
|
|
// add new items by double tapping
|
|
|
|
|
|
add: self.permissions['create'], |
|
|
|
|
|
// drag items horizontally
|
|
|
|
|
|
updateTime: self.permissions['write'], |
|
|
|
|
|
// drag items from one group to another
|
|
|
|
|
|
updateGroup: self.permissions['write'], |
|
|
|
|
|
// delete an item by tapping the delete button top right
|
|
|
|
|
|
remove: self.permissions['unlink'], |
|
|
}, |
|
|
}, |
|
|
orientation: 'both', |
|
|
orientation: 'both', |
|
|
selectable: true, |
|
|
selectable: true, |
|
@ -174,7 +186,6 @@ openerp.web_timeline = function(instance) { |
|
|
onUpdate: self.on_update, |
|
|
onUpdate: self.on_update, |
|
|
onRemove: self.on_remove, |
|
|
onRemove: self.on_remove, |
|
|
orientation: 'both', |
|
|
orientation: 'both', |
|
|
start: self.start, |
|
|
|
|
|
}; |
|
|
}; |
|
|
self.timeline = new vis.Timeline(self.$timeline.empty().get(0)); |
|
|
self.timeline = new vis.Timeline(self.$timeline.empty().get(0)); |
|
|
self.timeline.setOptions(options); |
|
|
self.timeline.setOptions(options); |
|
@ -198,11 +209,11 @@ openerp.web_timeline = function(instance) { |
|
|
|
|
|
|
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Transform OpenERP event object to timeline event object |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
/* Transform Odoo event object to timeline event object */ |
|
|
event_data_transform: function(evt) { |
|
|
event_data_transform: function(evt) { |
|
|
var self = this; |
|
|
var self = this; |
|
|
|
|
|
var date_start = new moment(); |
|
|
|
|
|
var date_stop = new moment(); |
|
|
|
|
|
|
|
|
var date_delay = evt[this.date_delay] || 1.0, |
|
|
var date_delay = evt[this.date_delay] || 1.0, |
|
|
all_day = this.all_day ? evt[this.all_day] : false, |
|
|
all_day = this.all_day ? evt[this.all_day] : false, |
|
@ -211,19 +222,19 @@ openerp.web_timeline = function(instance) { |
|
|
attendees = []; |
|
|
attendees = []; |
|
|
|
|
|
|
|
|
if (!all_day) { |
|
|
if (!all_day) { |
|
|
date_start = instance.web.auto_str_to_date(evt[this.date_start]); |
|
|
|
|
|
date_stop = this.date_stop ? instance.web.auto_str_to_date(evt[this.date_stop]) : null; |
|
|
|
|
|
|
|
|
date_start = time.auto_str_to_date(evt[this.date_start]); |
|
|
|
|
|
date_stop = this.date_stop ? time.auto_str_to_date(evt[this.date_stop]) : null; |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
date_start = instance.web.auto_str_to_date(evt[this.date_start].split(' ')[0],'start'); |
|
|
|
|
|
date_stop = this.date_stop ? instance.web.auto_str_to_date(evt[this.date_stop].split(' ')[0],'stop') : null; |
|
|
|
|
|
|
|
|
date_start = time.auto_str_to_date(evt[this.date_start].split(' ')[0],'start'); |
|
|
|
|
|
date_stop = this.date_stop ? time.auto_str_to_date(evt[this.date_stop].split(' ')[0],'stop') : null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!date_start){ |
|
|
if (!date_start){ |
|
|
date_start = new Date(); |
|
|
|
|
|
|
|
|
date_start = new moment(); |
|
|
} |
|
|
} |
|
|
if(!date_stop) { |
|
|
if(!date_stop) { |
|
|
date_stop = date_start.clone().addHours(date_delay); |
|
|
|
|
|
|
|
|
date_stop = moment(date_start).add(date_delay, 'hours').toDate(); |
|
|
} |
|
|
} |
|
|
var group = evt[self.last_group_bys[0]]; |
|
|
var group = evt[self.last_group_bys[0]]; |
|
|
if (group){ |
|
|
if (group){ |
|
@ -238,7 +249,7 @@ openerp.web_timeline = function(instance) { |
|
|
var r = { |
|
|
var r = { |
|
|
'start': date_start, |
|
|
'start': date_start, |
|
|
'end': date_stop, |
|
|
'end': date_stop, |
|
|
'content': evt.__name, |
|
|
|
|
|
|
|
|
'content': evt.__name != undefined ? evt.__name : evt.display_name, |
|
|
'id': evt.id, |
|
|
'id': evt.id, |
|
|
'group': group, |
|
|
'group': group, |
|
|
'evt': evt, |
|
|
'evt': evt, |
|
@ -249,7 +260,6 @@ openerp.web_timeline = function(instance) { |
|
|
return r; |
|
|
return r; |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
do_search: function (domains, contexts, group_bys) { |
|
|
do_search: function (domains, contexts, group_bys) { |
|
|
var self = this; |
|
|
var self = this; |
|
|
self.last_domains = domains; |
|
|
self.last_domains = domains; |
|
@ -279,7 +289,6 @@ openerp.web_timeline = function(instance) { |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reload: function() { |
|
|
reload: function() { |
|
|
var self = this; |
|
|
var self = this; |
|
|
if (this.last_domains !== undefined){ |
|
|
if (this.last_domains !== undefined){ |
|
@ -288,34 +297,34 @@ openerp.web_timeline = function(instance) { |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
on_data_loaded: function(tasks, group_bys) { |
|
|
|
|
|
|
|
|
on_data_loaded: function(events, group_bys) { |
|
|
var self = this; |
|
|
var self = this; |
|
|
var ids = _.pluck(tasks, "id"); |
|
|
|
|
|
|
|
|
var ids = _.pluck(events, "id"); |
|
|
return this.dataset.name_get(ids).then(function(names) { |
|
|
return this.dataset.name_get(ids).then(function(names) { |
|
|
var ntasks = _.map(tasks, function(task) { |
|
|
|
|
|
return _.extend({__name: _.detect(names, function(name) { return name[0] == task.id; })[1]}, task); |
|
|
|
|
|
|
|
|
var nevents = _.map(events, function(event) { |
|
|
|
|
|
return _.extend({__name: _.detect(names, function(name) { return name[0] == event.id; })[1]}, event); |
|
|
}); |
|
|
}); |
|
|
return self.on_data_loaded_2(ntasks, group_bys); |
|
|
|
|
|
|
|
|
return self.on_data_loaded_2(nevents, group_bys); |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
on_data_loaded_2: function(tasks, group_bys) { |
|
|
|
|
|
|
|
|
on_data_loaded_2: function(events, group_bys) { |
|
|
var self = this; |
|
|
var self = this; |
|
|
var data = []; |
|
|
var data = []; |
|
|
var groups = []; |
|
|
var groups = []; |
|
|
_.each(tasks, function(event) { |
|
|
|
|
|
|
|
|
_.each(events, function(event) { |
|
|
if (event[self.date_start]){ |
|
|
if (event[self.date_start]){ |
|
|
data.push(self.event_data_transform(event)); |
|
|
data.push(self.event_data_transform(event)); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
// get the groups
|
|
|
// get the groups
|
|
|
var split_groups = function(tasks, group_bys) { |
|
|
|
|
|
|
|
|
var split_groups = function(events, group_bys) { |
|
|
if (group_bys.length === 0) |
|
|
if (group_bys.length === 0) |
|
|
return tasks; |
|
|
|
|
|
|
|
|
return events; |
|
|
var groups = []; |
|
|
var groups = []; |
|
|
groups.push({id:-1, content: _t('-')}) |
|
|
groups.push({id:-1, content: _t('-')}) |
|
|
_.each(tasks, function(task) { |
|
|
|
|
|
var group_name = task[_.first(group_bys)]; |
|
|
|
|
|
|
|
|
_.each(events, function(event) { |
|
|
|
|
|
var group_name = event[_.first(group_bys)]; |
|
|
if (group_name) { |
|
|
if (group_name) { |
|
|
var group = _.find(groups, function(group) { return _.isEqual(group.id, group_name[0]); }); |
|
|
var group = _.find(groups, function(group) { return _.isEqual(group.id, group_name[0]); }); |
|
|
if (group === undefined) { |
|
|
if (group === undefined) { |
|
@ -326,10 +335,10 @@ openerp.web_timeline = function(instance) { |
|
|
}); |
|
|
}); |
|
|
return groups; |
|
|
return groups; |
|
|
} |
|
|
} |
|
|
var groups = split_groups(tasks, group_bys); |
|
|
|
|
|
|
|
|
var groups = split_groups(events, group_bys); |
|
|
this.timeline.setGroups(groups); |
|
|
this.timeline.setGroups(groups); |
|
|
this.timeline.setItems(data); |
|
|
this.timeline.setItems(data); |
|
|
this.timeline.setWindow(this.current_window); |
|
|
|
|
|
|
|
|
this.timeline.fit(); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
do_show: function() { |
|
|
do_show: function() { |
|
@ -343,55 +352,46 @@ openerp.web_timeline = function(instance) { |
|
|
} |
|
|
} |
|
|
return this._super(action); |
|
|
return this._super(action); |
|
|
}, |
|
|
}, |
|
|
/** |
|
|
|
|
|
* Handles a newly created record |
|
|
|
|
|
* |
|
|
|
|
|
* @param {id} id of the newly created record |
|
|
|
|
|
*/ |
|
|
|
|
|
quick_created: function (id) { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Note: it's of the most utter importance NOT to use inplace |
|
|
|
|
|
* modification on this.dataset.ids as reference to this data is |
|
|
|
|
|
* spread out everywhere in the various widget. Some of these |
|
|
|
|
|
* reference includes values that should trigger action upon |
|
|
|
|
|
* modification. |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
create_completed: function(id) { |
|
|
|
|
|
var self = this; |
|
|
this.dataset.ids = this.dataset.ids.concat([id]); |
|
|
this.dataset.ids = this.dataset.ids.concat([id]); |
|
|
this.dataset.trigger("dataset_changed", id); |
|
|
this.dataset.trigger("dataset_changed", id); |
|
|
this.refresh_event(id); |
|
|
|
|
|
|
|
|
this.dataset.read_ids([id], this.fields).done(function(records) { |
|
|
|
|
|
var new_event = self.event_data_transform(records[0]); |
|
|
|
|
|
var items = self.timeline.itemsData; |
|
|
|
|
|
items.add(new_event); |
|
|
|
|
|
self.timeline.setItems(items); |
|
|
|
|
|
}); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
on_add: function(item, callback) { |
|
|
on_add: function(item, callback) { |
|
|
var self = this, |
|
|
|
|
|
pop = new instance.web.form.SelectCreatePopup(this), |
|
|
|
|
|
context = this.get_popup_context(item); |
|
|
|
|
|
pop.on("elements_selected", self, function(element_ids) { |
|
|
|
|
|
self.reload().then(function() { |
|
|
|
|
|
self.timeline.focus(element_ids); |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
pop.select_element( |
|
|
|
|
|
self.dataset.model, |
|
|
|
|
|
{ |
|
|
|
|
|
title: _t("Create"), |
|
|
|
|
|
initial_view: "form", |
|
|
|
|
|
}, |
|
|
|
|
|
null, |
|
|
|
|
|
context |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
var self = this; |
|
|
|
|
|
var context = this.dataset.get_context(); |
|
|
|
|
|
// Initialize default values for creation
|
|
|
|
|
|
var default_context = {} |
|
|
|
|
|
default_context['default_'.concat(this.date_start)] = item.start; |
|
|
|
|
|
default_context['default_'.concat(this.date_stop)] = moment(item.start).add(1, 'hours').toDate(); |
|
|
|
|
|
if (item.group > 0) { |
|
|
|
|
|
default_context['default_'.concat(this.last_group_bys[0])] = item.group; |
|
|
|
|
|
} |
|
|
|
|
|
context.add(default_context); |
|
|
|
|
|
// Show popup
|
|
|
|
|
|
var dialog = new form_common.FormViewDialog(this, { |
|
|
|
|
|
res_model: this.dataset.model, |
|
|
|
|
|
res_id: null, |
|
|
|
|
|
context: context, |
|
|
|
|
|
view_id: +this.open_popup_action, |
|
|
|
|
|
}).open(); |
|
|
|
|
|
dialog.on('create_completed', this, this.create_completed); |
|
|
|
|
|
return false; |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
get_popup_context: function(item) { |
|
|
|
|
|
var context = {}; |
|
|
|
|
|
context['default_'.concat(this.date_start)] = item.start; |
|
|
|
|
|
context['default_'.concat(this.date_stop)] = item.start.clone() |
|
|
|
|
|
.addHours(this.date_delay || 1); |
|
|
|
|
|
if(item.group != -1) |
|
|
|
|
|
{ |
|
|
|
|
|
context['default_'.concat(this.last_group_bys[0])] = item.group; |
|
|
|
|
|
} |
|
|
|
|
|
return context; |
|
|
|
|
|
|
|
|
write_completed: function(id) { |
|
|
|
|
|
this.dataset.trigger("dataset_changed", id); |
|
|
|
|
|
this.current_window = this.timeline.getWindow(); |
|
|
|
|
|
this.reload(); |
|
|
|
|
|
this.timeline.setWindow(this.current_window); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
on_update: function(item, callback) { |
|
|
on_update: function(item, callback) { |
|
@ -408,47 +408,14 @@ openerp.web_timeline = function(instance) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
var id_cast = parseInt(id).toString() == id ? parseInt(id) : id; |
|
|
|
|
|
var pop = new instance.web.form.FormOpenPopup(self); |
|
|
|
|
|
pop.on('write_completed', self, self.reload); |
|
|
|
|
|
pop.show_element( |
|
|
|
|
|
self.dataset.model, |
|
|
|
|
|
id_cast, |
|
|
|
|
|
null, |
|
|
|
|
|
{readonly: true, title: title} |
|
|
|
|
|
); |
|
|
|
|
|
var form_controller = pop.view_form; |
|
|
|
|
|
form_controller.on("load_record", self, function() { |
|
|
|
|
|
var footer = pop.$el.closest(".modal").find(".modal-footer"); |
|
|
|
|
|
footer.find('.oe_form_button_edit,.oe_form_button_save').remove(); |
|
|
|
|
|
footer.find(".oe_form_button_cancel").prev().remove(); |
|
|
|
|
|
footer.find('.oe_form_button_cancel').before("<span> or </span>"); |
|
|
|
|
|
button_edit = _.str.sprintf("<button class='oe_button oe_form_button_edit oe_bold oe_highlight'><span> %s </span></button>",_t("Edit")); |
|
|
|
|
|
button_save = _.str.sprintf("<button class='oe_button oe_form_button_save oe_bold oe_highlight'><span> %s </span></button>",_t("Save")); |
|
|
|
|
|
footer.prepend(button_edit + button_save); |
|
|
|
|
|
footer.find('.oe_form_button_save').hide(); |
|
|
|
|
|
footer.find('.oe_form_button_edit').on('click', function() { |
|
|
|
|
|
form_controller.to_edit_mode(); |
|
|
|
|
|
footer.find('.oe_form_button_edit,.oe_form_button_save').toggle(); |
|
|
|
|
|
}); |
|
|
|
|
|
footer.find('.oe_form_button_save').on('click', function() { |
|
|
|
|
|
form_controller.save(); |
|
|
|
|
|
form_controller.to_view_mode(); |
|
|
|
|
|
footer.find('.oe_form_button_edit,.oe_form_button_save').toggle(); |
|
|
|
|
|
}); |
|
|
|
|
|
var chatter = pop.$el.closest(".modal").find(".oe_chatter"); |
|
|
|
|
|
if(chatter.length){ |
|
|
|
|
|
var chatter_toggler = $($.parseHTML(_.str.sprintf('<div class="oe_chatter_toggle fa fa-plus-circle"><span> %s </span><div class="oe_chatter_content"></div></div>', _t("Messages")))); |
|
|
|
|
|
chatter.before(chatter_toggler) |
|
|
|
|
|
var chatter_content = chatter_toggler.find(".oe_chatter_content"); |
|
|
|
|
|
chatter_content.prepend(chatter); |
|
|
|
|
|
chatter_content.toggle(); |
|
|
|
|
|
chatter_toggler.click(function(){ |
|
|
|
|
|
chatter_content.toggle(); |
|
|
|
|
|
chatter_toggler.toggleClass('fa-plus-circle fa-minus-circle'); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
var dialog = new form_common.FormViewDialog(this, { |
|
|
|
|
|
res_model: this.dataset.model, |
|
|
|
|
|
res_id: parseInt(id).toString() == id ? parseInt(id) : id, |
|
|
|
|
|
context: this.dataset.get_context(), |
|
|
|
|
|
title: title, |
|
|
|
|
|
view_id: +this.open_popup_action, |
|
|
|
|
|
}).open(); |
|
|
|
|
|
dialog.on('write_completed', this, this.write_completed); |
|
|
} |
|
|
} |
|
|
return false; |
|
|
return false; |
|
|
}, |
|
|
}, |
|
@ -463,14 +430,12 @@ openerp.web_timeline = function(instance) { |
|
|
} |
|
|
} |
|
|
var data = {}; |
|
|
var data = {}; |
|
|
data[self.fields_view.arch.attrs.date_start] = |
|
|
data[self.fields_view.arch.attrs.date_start] = |
|
|
instance.web.auto_date_to_str(start, self.fields[self.fields_view.arch.attrs.date_start].type); |
|
|
|
|
|
|
|
|
time.auto_date_to_str(start, self.fields[self.fields_view.arch.attrs.date_start].type); |
|
|
data[self.fields_view.arch.attrs.date_stop] = |
|
|
data[self.fields_view.arch.attrs.date_stop] = |
|
|
instance.web.auto_date_to_str(end, self.fields[self.fields_view.arch.attrs.date_stop].type); |
|
|
|
|
|
|
|
|
time.auto_date_to_str(end, self.fields[self.fields_view.arch.attrs.date_stop].type); |
|
|
data[self.fields_view.arch.attrs.default_group_by] = group; |
|
|
data[self.fields_view.arch.attrs.default_group_by] = group; |
|
|
var id = item.evt.id; |
|
|
var id = item.evt.id; |
|
|
this.dataset.write(id, data).then(function() { |
|
|
|
|
|
self.reload(); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
this.dataset.write(id, data); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
on_remove: function(item, callback) { |
|
|
on_remove: function(item, callback) { |
|
@ -510,37 +475,21 @@ openerp.web_timeline = function(instance) { |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
on_today_clicked: function(){ |
|
|
|
|
|
this.current_window = { |
|
|
|
|
|
start: new Date(), |
|
|
|
|
|
end : new Date().addHours(24), |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scale_current_window: function(factor){ |
|
|
if (this.timeline){ |
|
|
if (this.timeline){ |
|
|
|
|
|
this.current_window = this.timeline.getWindow(); |
|
|
|
|
|
this.current_window.end = moment(this.current_window.start).add(factor, 'hours'); |
|
|
this.timeline.setWindow(this.current_window); |
|
|
this.timeline.setWindow(this.current_window); |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
get_middel_date: function(start, end){ |
|
|
|
|
|
//Get 1 hour in milliseconds
|
|
|
|
|
|
var one_hour=1000*60*60; |
|
|
|
|
|
|
|
|
|
|
|
// Convert both dates to milliseconds
|
|
|
|
|
|
var date1_ms = start.getTime(); |
|
|
|
|
|
var date2_ms = end.getTime(); |
|
|
|
|
|
|
|
|
|
|
|
// Calculate the difference in milliseconds
|
|
|
|
|
|
var difference_ms = date2_ms - date1_ms; |
|
|
|
|
|
|
|
|
|
|
|
// Convert back to days and return
|
|
|
|
|
|
nb_hours = Math.round(difference_ms/one_hour); |
|
|
|
|
|
return start.clone().addHours(nb_hours/2) |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
on_today_clicked: function(){ |
|
|
|
|
|
this.current_window = { |
|
|
|
|
|
start: new moment(), |
|
|
|
|
|
end : new moment().add(24, 'hours'), |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
scale_current_window: function(factor){ |
|
|
|
|
|
if (this.timeline) { |
|
|
if (this.timeline) { |
|
|
this.current_window = this.timeline.getWindow(); |
|
|
|
|
|
this.current_window.end = this.current_window.start.clone().addHours(factor); |
|
|
|
|
|
this.timeline.setWindow(this.current_window); |
|
|
this.timeline.setWindow(this.current_window); |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
@ -556,9 +505,12 @@ openerp.web_timeline = function(instance) { |
|
|
on_scale_month_clicked: function(){ |
|
|
on_scale_month_clicked: function(){ |
|
|
this.scale_current_window(24 * 30); |
|
|
this.scale_current_window(24 * 30); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
on_scale_year_clicked: function(){ |
|
|
on_scale_year_clicked: function(){ |
|
|
this.scale_current_window(24 * 365); |
|
|
this.scale_current_window(24 * 365); |
|
|
}, |
|
|
}, |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
core.view_registry.add('timeline', TimelineView); |
|
|
|
|
|
return TimelineView; |
|
|
}); |
|
|
}); |
|
|
}; |
|
|
|