mirror of https://github.com/OCA/web.git
[MIG] web_timeline: Migration to 9.0
parent
f2fd0f8d6b
commit
7f05878fe4
|
@ -2,48 +2,106 @@
|
||||||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
||||||
:alt: License: AGPL-3
|
:alt: License: AGPL-3
|
||||||
|
|
||||||
===============
|
=============
|
||||||
Timeline Widget
|
Timeline view
|
||||||
===============
|
=============
|
||||||
|
|
||||||
Define a new widget displaying events in an interactive visualization chart.
|
Define a new view displaying events in an interactive visualization chart.
|
||||||
|
|
||||||
The widget is based on the external library
|
The widget is based on the external library
|
||||||
http://visjs.org/timeline_examples.html
|
http://visjs.org/timeline_examples.html
|
||||||
|
|
||||||
|
Configuration
|
||||||
|
=============
|
||||||
|
|
||||||
|
You need to define a view with the tag <timeline> as base element. These are
|
||||||
|
the possible attributes for the tag:
|
||||||
|
|
||||||
|
* date_start (required): it defines the name of the field of type date that
|
||||||
|
contains the start of the event.
|
||||||
|
* date_end (optional): it defines the name of the field of type date that
|
||||||
|
contains the end of the event.
|
||||||
|
* date_delay (optional): it defines the name of the field of type date that
|
||||||
|
contains the end of the event.
|
||||||
|
* default_group_by (required): it defines the name of the field that will be
|
||||||
|
taken as default group by when accessing the view or when no other group by
|
||||||
|
is selected.
|
||||||
|
* event_open_popup (optional): when set to true, it allows to edit the events
|
||||||
|
in a popup. If not (default value), the record is edited changing to form
|
||||||
|
view.
|
||||||
|
* colors (optional): it allows to set certain specific colors if the expressed
|
||||||
|
condition (JS syntax) is met.
|
||||||
|
|
||||||
|
You also need to declare the view in an action window of the involved model.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
.. code-block:: xml
|
||||||
|
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
<record id="view_task_timeline" model="ir.ui.view">
|
||||||
|
<field name="model">project.task</field>
|
||||||
|
<field name="type">timeline</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<timeline date_start="date_start"
|
||||||
|
date_stop="date_end"
|
||||||
|
string="Tasks"
|
||||||
|
default_group_by="user_id"
|
||||||
|
event_open_popup="true"
|
||||||
|
colors="#ec7063:user_id == false;#2ecb71:kanban_state=='done';">
|
||||||
|
</timeline>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="project.action_view_task" model="ir.actions.act_window">
|
||||||
|
<field name="view_mode">kanban,tree,form,calendar,gantt,timeline,graph</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
=====
|
=====
|
||||||
|
|
||||||
Example:
|
For accessing the timeline view, you have to click on the button with the clock
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
icon in the view switcher. The first time you access to it, the timeline window
|
||||||
<openerp>
|
is zoomed to fit all the current elements, the same as when you perform a
|
||||||
<data>
|
search, filter or group by operation.
|
||||||
|
|
||||||
<record id="view_task_timeline" model="ir.ui.view">
|
You can use the mouse scroll to zoom in or out in the timeline, and click on
|
||||||
<field name="name">project.task.timeline</field>
|
any free area and drag for panning the view in that direction.
|
||||||
<field name="model">project.task</field>
|
|
||||||
<field name="type">timeline</field>
|
The records of your model will be shown as rectangles whose widths are the
|
||||||
<field eval="2" name="priority"/>
|
duration of the event according our definition. You can select them clicking
|
||||||
<field name="arch" type="xml">
|
on this rectangle. You can also use Ctrl or Shift keys for adding discrete
|
||||||
<timeline date_start="date_start"
|
or range selections. Selected records are hightlighted with a different color
|
||||||
date_stop="date_end"
|
(but the difference will be more noticeable depending on the background color).
|
||||||
date_delay='1'
|
Once selected, you can drag and move the selected records across the timeline.
|
||||||
string="Tasks"
|
|
||||||
default_group_by="user_id" event_open_popup="true" colors="#ec7063:user_id == false;#2ecb71:kanban_state=='done';">
|
When a record is selected, a red cross button appears on the upper left corner
|
||||||
</timeline>
|
that allows to remove that record. This doesn't work for multiple records
|
||||||
</field>
|
although they were selected.
|
||||||
</record>
|
|
||||||
|
Records are grouped in different blocks depending on the group by criteria
|
||||||
|
selected (if none is specified, then the default group by is applied).
|
||||||
|
Dragging a record from one block to another change the corresponding field to
|
||||||
|
the value that represents the block. You can also click on the group name to
|
||||||
|
edit the involved record directly.
|
||||||
|
|
||||||
|
Double-click on the record to edit it. Double-click in open area to create a
|
||||||
|
new record with the group and start date linked to the area you clicked in.
|
||||||
|
|
||||||
<record id="project.action_view_task" model="ir.actions.act_window">
|
|
||||||
<field name="view_mode">kanban,tree,form,calendar,gantt,timeline,graph</field>
|
|
||||||
</record>
|
|
||||||
</data>
|
|
||||||
</openerp>
|
|
||||||
|
|
||||||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
||||||
:alt: Try me on Runbot
|
:alt: Try me on Runbot
|
||||||
:target: https://runbot.odoo-community.org/runbot/162/8.0
|
:target: https://runbot.odoo-community.org/runbot/162/8.0
|
||||||
|
|
||||||
|
Known issues / Roadmap
|
||||||
|
======================
|
||||||
|
|
||||||
|
* Implement support for vis.js timeline range item addition (with Ctrl key
|
||||||
|
pressed).
|
||||||
|
* Implement a more efficient way of refreshing timeline after a record update.
|
||||||
|
|
||||||
Bug Tracker
|
Bug Tracker
|
||||||
===========
|
===========
|
||||||
|
|
||||||
|
@ -65,6 +123,7 @@ Contributors
|
||||||
|
|
||||||
* Laurent Mignon <laurent.mignon@acsone.eu>
|
* Laurent Mignon <laurent.mignon@acsone.eu>
|
||||||
* Adrien Peiffer <adrien.peiffer@acsone.eu>
|
* Adrien Peiffer <adrien.peiffer@acsone.eu>
|
||||||
|
* Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||||
|
|
||||||
Maintainer
|
Maintainer
|
||||||
----------
|
----------
|
||||||
|
|
|
@ -4,16 +4,15 @@
|
||||||
|
|
||||||
{
|
{
|
||||||
'name': "Web timeline",
|
'name': "Web timeline",
|
||||||
'summary': """
|
'summary': "Interactive visualization chart to show events in time",
|
||||||
Interactive visualization chart to visualize events in time
|
"version": "9.0.1.0.0",
|
||||||
""",
|
|
||||||
"version": "8.0.1.0.0",
|
|
||||||
'author': 'ACSONE SA/NV,'
|
'author': 'ACSONE SA/NV,'
|
||||||
|
'Tecnativa,'
|
||||||
'Odoo Community Association (OCA)',
|
'Odoo Community Association (OCA)',
|
||||||
"category": "Tools",
|
"category": "web",
|
||||||
"website": "http://acsone.eu",
|
"website": "http://acsone.eu",
|
||||||
'depends': [
|
'depends': [
|
||||||
'web'
|
'web',
|
||||||
],
|
],
|
||||||
'qweb': [
|
'qweb': [
|
||||||
'static/src/xml/web_timeline.xml',
|
'static/src/xml/web_timeline.xml',
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
|
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
from openerp import models
|
from openerp import fields, models
|
||||||
from openerp import api
|
|
||||||
|
|
||||||
|
|
||||||
TIMELINE_VIEW = ('timeline', 'Timeline')
|
TIMELINE_VIEW = ('timeline', 'Timeline')
|
||||||
|
@ -12,14 +11,4 @@ TIMELINE_VIEW = ('timeline', 'Timeline')
|
||||||
class IrUIView(models.Model):
|
class IrUIView(models.Model):
|
||||||
_inherit = 'ir.ui.view'
|
_inherit = 'ir.ui.view'
|
||||||
|
|
||||||
@api.model
|
type = fields.Selection(selection_add=[TIMELINE_VIEW])
|
||||||
def _setup_fields(self):
|
|
||||||
"""Hack due since the field 'type' is not defined with the new api.
|
|
||||||
"""
|
|
||||||
cls = type(self)
|
|
||||||
type_selection = cls._fields['type'].selection
|
|
||||||
if TIMELINE_VIEW not in type_selection:
|
|
||||||
tmp = list(type_selection)
|
|
||||||
tmp.append(TIMELINE_VIEW)
|
|
||||||
cls._fields['type'].selection = tuple(set(tmp))
|
|
||||||
super(IrUIView, self)._setup_fields()
|
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
|
@ -2,32 +2,12 @@
|
||||||
.openerp .oe_view_manager .oe_view_manager_switch .oe_vm_switch_timeline:after {
|
.openerp .oe_view_manager .oe_view_manager_switch .oe_vm_switch_timeline:after {
|
||||||
content: "N";
|
content: "N";
|
||||||
}
|
}
|
||||||
.timeline-navigation-zoom-in .ui-icon{
|
|
||||||
background: none !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.timeline-navigation-zoom-out .ui-icon{
|
|
||||||
background: none !important;
|
|
||||||
}
|
|
||||||
.timeline-navigation-move-left .ui-icon{
|
|
||||||
background: none !important;
|
|
||||||
}
|
|
||||||
.timeline-navigation-move-right .ui-icon{
|
|
||||||
background: none !important;
|
|
||||||
}
|
|
||||||
/*.vis.timeline .timeaxis .grid.odd {
|
|
||||||
background: #f5f5f5;
|
|
||||||
} */
|
|
||||||
|
|
||||||
/* gray background in weekends, white text color */
|
/* gray background in weekends, white text color */
|
||||||
.vis.timeline .timeaxis .grid.saturday,
|
.vis.timeline .timeaxis .grid.saturday,
|
||||||
.vis.timeline .timeaxis .grid.sunday {
|
.vis.timeline .timeaxis .grid.sunday {
|
||||||
background: gray;
|
background: gray;
|
||||||
}
|
}
|
||||||
/* .vis.timeline .timeaxis .text.saturday,
|
|
||||||
.vis.timeline .timeaxis .text.sunday {
|
|
||||||
color: white;
|
|
||||||
} */
|
|
||||||
|
|
||||||
.vis.timeline .item.range .content {
|
.vis.timeline .item.range .content {
|
||||||
overflow: visible;
|
overflow: visible;
|
||||||
|
|
|
@ -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) {
|
odoo.define('web_timeline.TimelineView', function (require) {
|
||||||
var _t = instance.web._t,
|
"use strict";
|
||||||
_lt = instance.web._lt,
|
|
||||||
QWeb = instance.web.qweb;
|
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');
|
var TimelineView = View.extend({
|
||||||
|
|
||||||
instance.web_timeline.TimelineView = instance.web.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_today").click($.proxy(this.on_today_clicked, this));
|
||||||
this.$el.find(".oe_timeline_button_scale_day").click(self.on_scale_day_clicked);
|
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(self.on_scale_week_clicked);
|
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(self.on_scale_month_clicked);
|
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(self.on_scale_year_clicked);
|
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(),
|
start: new moment(),
|
||||||
end : new Date().addHours(24),
|
end : new moment().add(24, 'hours'),
|
||||||
}
|
}
|
||||||
this.info_fields = [];
|
this.info_fields = [];
|
||||||
|
|
||||||
|
@ -104,17 +115,15 @@ 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;
|
||||||
this.mode = attrs.mode; // one of month, week or day
|
this.date_start = attrs.date_start;
|
||||||
this.date_start = attrs.date_start; // Field name of starting
|
|
||||||
// date field
|
|
||||||
this.date_stop = attrs.date_stop;
|
this.date_stop = attrs.date_stop;
|
||||||
|
|
||||||
if (!isNullOrUndef(attrs.quick_create_instance)) {
|
if (!isNullOrUndef(attrs.quick_create_instance)) {
|
||||||
self.quick_create_instance = 'instance.' + attrs.quick_create_instance;
|
self.quick_create_instance = 'instance.' + attrs.quick_create_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this field is set ot true, we don't open the event in form
|
// If this field is set ot true, we don't open the event in form
|
||||||
// view, but in a popup with the view_id passed by this parameter
|
// view, but in a popup with the view_id passed by this parameter
|
||||||
if (isNullOrUndef(attrs.event_open_popup) || !_.str.toBoolElse(attrs.event_open_popup, true)) {
|
if (isNullOrUndef(attrs.event_open_popup) || !_.str.toBoolElse(attrs.event_open_popup, true)) {
|
||||||
this.open_popup_action = false;
|
this.open_popup_action = false;
|
||||||
|
@ -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(self.fields_get, self.get_perm('unlink'), self.get_perm('write'), self.get_perm('create')).then(init);
|
||||||
return $.when(test).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
|
// add new items by double tapping
|
||||||
updateTime: self.permissions['write'], // drag items horizontally
|
add: self.permissions['create'],
|
||||||
updateGroup: self.permissions['write'], // drag items from one group to another
|
// drag items horizontally
|
||||||
remove: self.permissions['unlink'], // delete an item by tapping the delete button top right
|
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 Odoo event object to timeline event object */
|
||||||
* Transform OpenERP 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_start = time.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_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_start = time.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_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) {
|
var nevents = _.map(events, function(event) {
|
||||||
return _.extend({__name: _.detect(names, function(name) { return name[0] == task.id; })[1]}, task);
|
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) {
|
_.each(events, function(event) {
|
||||||
var group_name = task[_.first(group_bys)];
|
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) {
|
|
||||||
|
|
||||||
/**
|
create_completed: function(id) {
|
||||||
* Note: it's of the most utter importance NOT to use inplace
|
var self = this;
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
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,
|
var self = this;
|
||||||
pop = new instance.web.form.SelectCreatePopup(this),
|
var context = this.dataset.get_context();
|
||||||
context = this.get_popup_context(item);
|
// Initialize default values for creation
|
||||||
pop.on("elements_selected", self, function(element_ids) {
|
var default_context = {}
|
||||||
self.reload().then(function() {
|
default_context['default_'.concat(this.date_start)] = item.start;
|
||||||
self.timeline.focus(element_ids);
|
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;
|
||||||
pop.select_element(
|
}
|
||||||
self.dataset.model,
|
context.add(default_context);
|
||||||
{
|
// Show popup
|
||||||
title: _t("Create"),
|
var dialog = new form_common.FormViewDialog(this, {
|
||||||
initial_view: "form",
|
res_model: this.dataset.model,
|
||||||
},
|
res_id: null,
|
||||||
null,
|
context: context,
|
||||||
context
|
view_id: +this.open_popup_action,
|
||||||
);
|
}).open();
|
||||||
|
dialog.on('create_completed', this, this.create_completed);
|
||||||
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
get_popup_context: function(item) {
|
write_completed: function(id) {
|
||||||
var context = {};
|
this.dataset.trigger("dataset_changed", id);
|
||||||
context['default_'.concat(this.date_start)] = item.start;
|
this.current_window = this.timeline.getWindow();
|
||||||
context['default_'.concat(this.date_stop)] = item.start.clone()
|
this.reload();
|
||||||
.addHours(this.date_delay || 1);
|
this.timeline.setWindow(this.current_window);
|
||||||
if(item.group != -1)
|
|
||||||
{
|
|
||||||
context['default_'.concat(this.last_group_bys[0])] = item.group;
|
|
||||||
}
|
|
||||||
return context;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
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 dialog = new form_common.FormViewDialog(this, {
|
||||||
var pop = new instance.web.form.FormOpenPopup(self);
|
res_model: this.dataset.model,
|
||||||
pop.on('write_completed', self, self.reload);
|
res_id: parseInt(id).toString() == id ? parseInt(id) : id,
|
||||||
pop.show_element(
|
context: this.dataset.get_context(),
|
||||||
self.dataset.model,
|
title: title,
|
||||||
id_cast,
|
view_id: +this.open_popup_action,
|
||||||
null,
|
}).open();
|
||||||
{readonly: true, title: title}
|
dialog.on('write_completed', this, this.write_completed);
|
||||||
);
|
|
||||||
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');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
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() {
|
this.dataset.write(id, data);
|
||||||
self.reload();
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
on_remove: function(item, callback) {
|
on_remove: function(item, callback) {
|
||||||
|
@ -497,7 +462,7 @@ openerp.web_timeline = function(instance) {
|
||||||
},
|
},
|
||||||
|
|
||||||
on_group_click: function(e) {
|
on_group_click: function(e) {
|
||||||
if(e.group == -1)
|
if (e.group == -1)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -510,55 +475,42 @@ openerp.web_timeline = function(instance) {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
on_today_clicked: function(){
|
scale_current_window: function(factor){
|
||||||
this.current_window = {
|
if (this.timeline){
|
||||||
start: new Date(),
|
this.current_window = this.timeline.getWindow();
|
||||||
end : new Date().addHours(24),
|
this.current_window.end = moment(this.current_window.start).add(factor, 'hours');
|
||||||
}
|
this.timeline.setWindow(this.current_window);
|
||||||
|
}
|
||||||
if (this.timeline){
|
|
||||||
this.timeline.setWindow(this.current_window);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
get_middel_date: function(start, end){
|
on_today_clicked: function(){
|
||||||
//Get 1 hour in milliseconds
|
this.current_window = {
|
||||||
var one_hour=1000*60*60;
|
start: new moment(),
|
||||||
|
end : new moment().add(24, 'hours'),
|
||||||
|
}
|
||||||
|
|
||||||
// Convert both dates to milliseconds
|
if (this.timeline) {
|
||||||
var date1_ms = start.getTime();
|
this.timeline.setWindow(this.current_window);
|
||||||
var date2_ms = end.getTime();
|
}
|
||||||
|
},
|
||||||
|
|
||||||
// Calculate the difference in milliseconds
|
on_scale_day_clicked: function(){
|
||||||
var difference_ms = date2_ms - date1_ms;
|
this.scale_current_window(24);
|
||||||
|
},
|
||||||
|
|
||||||
// Convert back to days and return
|
on_scale_week_clicked: function(){
|
||||||
nb_hours = Math.round(difference_ms/one_hour);
|
this.scale_current_window(24 * 7);
|
||||||
return start.clone().addHours(nb_hours/2)
|
},
|
||||||
},
|
|
||||||
|
|
||||||
scale_current_window: function(factor){
|
on_scale_month_clicked: function(){
|
||||||
if (this.timeline){
|
this.scale_current_window(24 * 30);
|
||||||
this.current_window = this.timeline.getWindow();
|
},
|
||||||
this.current_window.end = this.current_window.start.clone().addHours(factor);
|
|
||||||
this.timeline.setWindow(this.current_window);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
on_scale_day_clicked: function(){
|
|
||||||
this.scale_current_window(24);
|
|
||||||
},
|
|
||||||
|
|
||||||
on_scale_week_clicked: function(){
|
|
||||||
this.scale_current_window(24 * 7);
|
|
||||||
},
|
|
||||||
|
|
||||||
on_scale_month_clicked: function(){
|
|
||||||
this.scale_current_window(24 * 30);
|
|
||||||
},
|
|
||||||
on_scale_year_clicked: function(){
|
|
||||||
this.scale_current_window(24 * 365);
|
|
||||||
},
|
|
||||||
|
|
||||||
|
on_scale_year_clicked: function(){
|
||||||
|
this.scale_current_window(24 * 365);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
core.view_registry.add('timeline', TimelineView);
|
||||||
|
return TimelineView;
|
||||||
|
});
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!-- vim:fdn=3:
|
<odoo>
|
||||||
-->
|
|
||||||
<openerp>
|
|
||||||
<data>
|
|
||||||
<template id="assets_backend" name="web_calendar assets" inherit_id="web.assets_backend">
|
|
||||||
<xpath expr="." position="inside">
|
|
||||||
<link rel="stylesheet" href="/web_timeline/static/lib/vis/vis.css"/>
|
|
||||||
<link rel="stylesheet" href="/web_timeline/static/src/css/web_timeline.css"/>
|
|
||||||
|
|
||||||
<script type="text/javascript" src="/web_timeline/static/lib/vis/vis.js"></script>
|
<template id="assets_backend" name="web_timeline assets" inherit_id="web.assets_backend">
|
||||||
<script type="text/javascript" src="/web_timeline/static/src/js/web_timeline.js"></script>
|
<xpath expr="." position="inside">
|
||||||
</xpath>
|
<link rel="stylesheet" href="/web_timeline/static/lib/vis/vis.css"/>
|
||||||
</template>
|
<link rel="stylesheet" href="/web_timeline/static/src/css/web_timeline.css"/>
|
||||||
</data>
|
|
||||||
</openerp>
|
<script type="text/javascript" src="/web_timeline/static/lib/vis/vis.js"/>
|
||||||
|
<script type="text/javascript" src="/web_timeline/static/src/js/web_timeline.js"/>
|
||||||
|
</xpath>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
</odoo>
|
||||||
|
|
Loading…
Reference in New Issue