mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
@@ -41,6 +41,7 @@ odoo.define("web_timeline.TimelineRenderer", function (require) {
|
||||
this.fields = params.fields;
|
||||
|
||||
this.timeline = false;
|
||||
this.initial_data_loaded = false;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -48,11 +49,6 @@ odoo.define("web_timeline.TimelineRenderer", function (require) {
|
||||
*/
|
||||
start: function () {
|
||||
const attrs = this.arch.attrs;
|
||||
this.current_window = {
|
||||
start: new moment(),
|
||||
end: new moment().add(24, "hours"),
|
||||
};
|
||||
|
||||
this.$el.addClass(attrs.class);
|
||||
this.$timeline = this.$(".oe_timeline_widget");
|
||||
|
||||
@@ -85,7 +81,6 @@ odoo.define("web_timeline.TimelineRenderer", function (require) {
|
||||
// Prevent Double Rendering on Updates
|
||||
if (!this.timeline) {
|
||||
this.init_timeline();
|
||||
$(window).trigger("resize");
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -96,13 +91,11 @@ odoo.define("web_timeline.TimelineRenderer", function (require) {
|
||||
* @private
|
||||
*/
|
||||
_onTodayClicked: function () {
|
||||
this.current_window = {
|
||||
start: new moment(),
|
||||
end: new moment().add(24, "hours"),
|
||||
};
|
||||
|
||||
if (this.timeline) {
|
||||
this.timeline.setWindow(this.current_window);
|
||||
this.timeline.setWindow({
|
||||
start: new moment(),
|
||||
end: new moment().add(24, "hours"),
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
@@ -112,7 +105,7 @@ odoo.define("web_timeline.TimelineRenderer", function (require) {
|
||||
* @private
|
||||
*/
|
||||
_onScaleDayClicked: function () {
|
||||
this._scaleCurrentWindow(24);
|
||||
this._scaleCurrentWindow(() => 24);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -121,7 +114,7 @@ odoo.define("web_timeline.TimelineRenderer", function (require) {
|
||||
* @private
|
||||
*/
|
||||
_onScaleWeekClicked: function () {
|
||||
this._scaleCurrentWindow(24 * 7);
|
||||
this._scaleCurrentWindow(() => 24 * 7);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -130,9 +123,7 @@ odoo.define("web_timeline.TimelineRenderer", function (require) {
|
||||
* @private
|
||||
*/
|
||||
_onScaleMonthClicked: function () {
|
||||
this._scaleCurrentWindow(
|
||||
24 * moment(this.current_window.start).daysInMonth()
|
||||
);
|
||||
this._scaleCurrentWindow((start) => 24 * moment(start).daysInMonth());
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -142,24 +133,22 @@ odoo.define("web_timeline.TimelineRenderer", function (require) {
|
||||
*/
|
||||
_onScaleYearClicked: function () {
|
||||
this._scaleCurrentWindow(
|
||||
24 * (moment(this.current_window.start).isLeapYear() ? 366 : 365)
|
||||
(start) => 24 * (moment(start).isLeapYear() ? 366 : 365)
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Scales the timeline window based on the current window.
|
||||
*
|
||||
* @param {Integer} factor The timespan (in hours) the window must be scaled to.
|
||||
* @param {function} getHoursFromStart Function which returns the timespan
|
||||
* (in hours) the window must be scaled to, starting from the "start" moment.
|
||||
* @private
|
||||
*/
|
||||
_scaleCurrentWindow: function (factor) {
|
||||
_scaleCurrentWindow: function (getHoursFromStart) {
|
||||
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);
|
||||
const start = this.timeline.getWindow().start;
|
||||
const end = moment(start).add(getHoursFromStart(start), "hours");
|
||||
this.timeline.setWindow(start, end);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -219,6 +208,7 @@ odoo.define("web_timeline.TimelineRenderer", function (require) {
|
||||
onUpdate: this.on_update,
|
||||
onRemove: this.on_remove,
|
||||
});
|
||||
this.options.xss = {disabled: true};
|
||||
this.qweb = new QWeb(session.debug, {_s: session.origin}, false);
|
||||
if (this.arch.children.length) {
|
||||
const tmpl = utils.json_node_to_xml(
|
||||
@@ -227,25 +217,17 @@ odoo.define("web_timeline.TimelineRenderer", function (require) {
|
||||
this.qweb.add_template(tmpl);
|
||||
}
|
||||
|
||||
this.timeline = new vis.Timeline(
|
||||
this.$timeline.get(0),
|
||||
{},
|
||||
{xss: {disabled: true}}
|
||||
);
|
||||
this.timeline.setOptions(this.options);
|
||||
if (this.mode && this["on_scale_" + this.mode + "_clicked"]) {
|
||||
this["on_scale_" + this.mode + "_clicked"]();
|
||||
}
|
||||
this.timeline = new vis.Timeline(this.$timeline.get(0), {}, this.options);
|
||||
this.timeline.on("click", this.on_group_click);
|
||||
const group_bys = this.arch.attrs.default_group_by.split(",");
|
||||
this.last_group_bys = group_bys;
|
||||
this.last_domains = this.modelClass.data.domain;
|
||||
this.on_data_loaded(this.modelClass.data.data, group_bys);
|
||||
this.$centerContainer = $(this.timeline.dom.centerContainer);
|
||||
this.canvas = new TimelineCanvas(this);
|
||||
this.canvas.appendTo(this.$centerContainer);
|
||||
this.timeline.on("changed", () => {
|
||||
this.draw_canvas();
|
||||
this.load_initial_data();
|
||||
});
|
||||
},
|
||||
|
||||
@@ -313,6 +295,16 @@ odoo.define("web_timeline.TimelineRenderer", function (require) {
|
||||
);
|
||||
},
|
||||
|
||||
/* Load initial data. This is called once after each redraw; we only handle the first one.
|
||||
* Deferring this initial load here avoids rendering issues. */
|
||||
load_initial_data: function () {
|
||||
if (!this.initial_data_loaded) {
|
||||
this.on_data_loaded(this.modelClass.data.data, this.last_group_bys);
|
||||
this.initial_data_loaded = true;
|
||||
this.timeline.redraw();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Load display_name of records.
|
||||
*
|
||||
|
||||
@@ -86,10 +86,6 @@ odoo.define("web_timeline.TimelineView", function (require) {
|
||||
const mode = attrs.mode || attrs.default_window || "fit";
|
||||
const min_height = attrs.min_height || 300;
|
||||
|
||||
const current_window = {
|
||||
start: new moment(),
|
||||
end: new moment().add(24, "hours"),
|
||||
};
|
||||
if (!isNullOrUndef(attrs.quick_create_instance)) {
|
||||
this.quick_create_instance = "instance." + attrs.quick_create_instance;
|
||||
}
|
||||
@@ -104,7 +100,6 @@ odoo.define("web_timeline.TimelineView", function (require) {
|
||||
this.rendererParams.model = this.modelName;
|
||||
this.rendererParams.view = this;
|
||||
this.rendererParams.options = this._preapre_vis_timeline_options(attrs);
|
||||
this.rendererParams.current_window = current_window;
|
||||
this.rendererParams.date_start = date_start;
|
||||
this.rendererParams.date_stop = date_stop;
|
||||
this.rendererParams.date_delay = date_delay;
|
||||
|
||||
Reference in New Issue
Block a user