|
|
@ -13,11 +13,20 @@ var TimelineCanvas = require('web_timeline.TimelineCanvas'); |
|
|
|
|
|
|
|
var _t = core._t; |
|
|
|
|
|
|
|
var CalendarRenderer = AbstractRenderer.extend({ |
|
|
|
var TimelineRenderer = AbstractRenderer.extend({ |
|
|
|
template: "TimelineView", |
|
|
|
|
|
|
|
events: _.extend({}, AbstractRenderer.prototype.events, { |
|
|
|
'click .oe_timeline_button_today': '_onTodayClicked', |
|
|
|
'click .oe_timeline_button_scale_day': '_onScaleDayClicked', |
|
|
|
'click .oe_timeline_button_scale_week': '_onScaleWeekClicked', |
|
|
|
'click .oe_timeline_button_scale_month': '_onScaleMonthClicked', |
|
|
|
'click .oe_timeline_button_scale_year': '_onScaleYearClicked', |
|
|
|
}), |
|
|
|
|
|
|
|
/** |
|
|
|
* @constructor |
|
|
|
*/ |
|
|
|
init: function (parent, state, params) { |
|
|
|
this._super.apply(this, arguments); |
|
|
|
this.modelName = params.model; |
|
|
@ -36,6 +45,9 @@ var CalendarRenderer = AbstractRenderer.extend({ |
|
|
|
this.modelClass = this.view.model; |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* @override |
|
|
|
*/ |
|
|
|
start: function () { |
|
|
|
var self = this; |
|
|
|
var attrs = this.arch.attrs; |
|
|
@ -53,6 +65,9 @@ var CalendarRenderer = AbstractRenderer.extend({ |
|
|
|
this._super.apply(this, self); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Triggered when the timeline is attached to the DOM. |
|
|
|
*/ |
|
|
|
on_attach_callback: function() { |
|
|
|
var height = this.$el.parent().height() - this.$el.find('.oe_timeline_buttons').height(); |
|
|
|
if (height > this.min_height) { |
|
|
@ -62,8 +77,10 @@ var CalendarRenderer = AbstractRenderer.extend({ |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* @override |
|
|
|
*/ |
|
|
|
_render: function () { |
|
|
|
this.add_events(); |
|
|
|
var self = this; |
|
|
|
return $.when().then(function () { |
|
|
|
// Prevent Double Rendering on Updates
|
|
|
@ -74,25 +91,11 @@ var CalendarRenderer = AbstractRenderer.extend({ |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
add_events: function() { |
|
|
|
var self = this; |
|
|
|
this.$(".oe_timeline_button_today").click(function() { |
|
|
|
self._onTodayClicked(); |
|
|
|
}); |
|
|
|
this.$(".oe_timeline_button_scale_day").click(function() { |
|
|
|
self._onScaleDayClicked(); |
|
|
|
}); |
|
|
|
this.$(".oe_timeline_button_scale_week").click(function() { |
|
|
|
self._onScaleWeekClicked(); |
|
|
|
}); |
|
|
|
this.$(".oe_timeline_button_scale_month").click(function() { |
|
|
|
self._onScaleMonthClicked(); |
|
|
|
}); |
|
|
|
this.$(".oe_timeline_button_scale_year").click(function() { |
|
|
|
self._onScaleYearClicked(); |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Set the timeline window to today (day). |
|
|
|
* |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
_onTodayClicked: function () { |
|
|
|
this.current_window = { |
|
|
|
start: new moment(), |
|
|
@ -104,22 +107,48 @@ var CalendarRenderer = AbstractRenderer.extend({ |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Scale the timeline window to a day. |
|
|
|
* |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
_onScaleDayClicked: function () { |
|
|
|
this._scaleCurrentWindow(24); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Scale the timeline window to a week. |
|
|
|
* |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
_onScaleWeekClicked: function () { |
|
|
|
this._scaleCurrentWindow(24 * 7); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Scale the timeline window to a month. |
|
|
|
* |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
_onScaleMonthClicked: function () { |
|
|
|
this._scaleCurrentWindow(24 * 30); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Scale the timeline window to a year. |
|
|
|
* |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
_onScaleYearClicked: function () { |
|
|
|
this._scaleCurrentWindow(24 * 365); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Scales the timeline window based on the current window. |
|
|
|
* |
|
|
|
* @param {Integer} factor The timespan (in hours) the window must be scaled to. |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
_scaleCurrentWindow: function (factor) { |
|
|
|
if (this.timeline) { |
|
|
|
this.current_window = this.timeline.getWindow(); |
|
|
@ -128,6 +157,11 @@ var CalendarRenderer = AbstractRenderer.extend({ |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Computes the initial visible window. |
|
|
|
* |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
_computeMode: function () { |
|
|
|
if (this.mode) { |
|
|
|
var start = false, end = false; |
|
|
@ -154,6 +188,11 @@ var CalendarRenderer = AbstractRenderer.extend({ |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Initializes the timeline (http://visjs.org/docs/timeline/).
|
|
|
|
* |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
init_timeline: function () { |
|
|
|
var self = this; |
|
|
|
this._computeMode(); |
|
|
@ -205,6 +244,11 @@ var CalendarRenderer = AbstractRenderer.extend({ |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Clears and draws the canvas items. |
|
|
|
* |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
draw_canvas: function () { |
|
|
|
this.canvas.clear(); |
|
|
|
if (this.dependency_arrow) { |
|
|
@ -212,6 +256,11 @@ var CalendarRenderer = AbstractRenderer.extend({ |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Draw item dependencies on canvas. |
|
|
|
* |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
draw_dependencies: function () { |
|
|
|
var self = this; |
|
|
|
var items = this.timeline.itemSet.items; |
|
|
@ -227,6 +276,16 @@ var CalendarRenderer = AbstractRenderer.extend({ |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Draws a dependency arrow between 2 timeline items. |
|
|
|
* |
|
|
|
* @param {Object} from Start timeline item |
|
|
|
* @param {Object} to Destination timeline item |
|
|
|
* @param {Object} options |
|
|
|
* @param {Object} options.line_color Color of the line |
|
|
|
* @param {Object} options.line_width The width of the line |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
draw_dependency: function (from, to, options) { |
|
|
|
if (!from.displayed || !to.displayed) { |
|
|
|
return; |
|
|
@ -240,6 +299,12 @@ var CalendarRenderer = AbstractRenderer.extend({ |
|
|
|
this.canvas.draw_arrow(from.dom.box, to.dom.box, defaults.line_color, defaults.line_width); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Load display_name of records. |
|
|
|
* |
|
|
|
* @private |
|
|
|
* @returns {jQuery.Deferred} |
|
|
|
*/ |
|
|
|
on_data_loaded: function (events, group_bys, adjust_window) { |
|
|
|
var self = this; |
|
|
|
var ids = _.pluck(events, "id"); |
|
|
@ -262,6 +327,11 @@ var CalendarRenderer = AbstractRenderer.extend({ |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Set groups and events. |
|
|
|
* |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
on_data_loaded_2: function (events, group_bys, adjust_window) { |
|
|
|
var self = this; |
|
|
|
var data = []; |
|
|
@ -282,7 +352,12 @@ var CalendarRenderer = AbstractRenderer.extend({ |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
// get the groups
|
|
|
|
/** |
|
|
|
* Get the groups. |
|
|
|
* |
|
|
|
* @private |
|
|
|
* @returns {Array} |
|
|
|
*/ |
|
|
|
split_groups: function (events, group_bys) { |
|
|
|
if (group_bys.length === 0) { |
|
|
|
return events; |
|
|
@ -310,7 +385,12 @@ var CalendarRenderer = AbstractRenderer.extend({ |
|
|
|
return groups; |
|
|
|
}, |
|
|
|
|
|
|
|
/* Transform Odoo event object to timeline event object */ |
|
|
|
/** |
|
|
|
* Transform Odoo event object to timeline event object. |
|
|
|
* |
|
|
|
* @private |
|
|
|
* @returns {Object} |
|
|
|
*/ |
|
|
|
event_data_transform: function (evt) { |
|
|
|
var self = this; |
|
|
|
var date_start = new moment(); |
|
|
@ -368,6 +448,13 @@ var CalendarRenderer = AbstractRenderer.extend({ |
|
|
|
return r; |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Render timeline item template. |
|
|
|
* |
|
|
|
* @param {Object} evt Record |
|
|
|
* @private |
|
|
|
* @returns {String} Rendered template |
|
|
|
*/ |
|
|
|
render_timeline_item: function (evt) { |
|
|
|
if(this.qweb.has_template('timeline-item')) { |
|
|
|
return this.qweb.render('timeline-item', { |
|
|
@ -381,8 +468,12 @@ var CalendarRenderer = AbstractRenderer.extend({ |
|
|
|
); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Handle a click on a group header. |
|
|
|
* |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
on_group_click: function (e) { |
|
|
|
// handle a click on a group header
|
|
|
|
if (e.what === 'group-label' && e.group !== -1) { |
|
|
|
this._trigger(e, function() { |
|
|
|
// Do nothing
|
|
|
@ -390,22 +481,47 @@ var CalendarRenderer = AbstractRenderer.extend({ |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Trigger onUpdate. |
|
|
|
* |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
on_update: function (item, callback) { |
|
|
|
this._trigger(item, callback, 'onUpdate'); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Trigger onMove. |
|
|
|
* |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
on_move: function (item, callback) { |
|
|
|
this._trigger(item, callback, 'onMove'); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Trigger onRemove. |
|
|
|
* |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
on_remove: function (item, callback) { |
|
|
|
this._trigger(item, callback, 'onRemove'); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Trigger onAdd. |
|
|
|
* |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
on_add: function (item, callback) { |
|
|
|
this._trigger(item, callback, 'onAdd'); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* trigger_up encapsulation adds by default the rights, and the renderer. |
|
|
|
* |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
_trigger: function (item, callback, trigger) { |
|
|
|
this.trigger_up(trigger, { |
|
|
|
'item': item, |
|
|
@ -417,5 +533,5 @@ var CalendarRenderer = AbstractRenderer.extend({ |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
return CalendarRenderer; |
|
|
|
return TimelineRenderer; |
|
|
|
}); |