Browse Source

[FIX] linting

pull/908/head
Tom Blauwendraat 6 years ago
parent
commit
041e518416
  1. 25
      web_timeline/__openerp__.py
  2. 434
      web_timeline/static/src/js/web_timeline.js

25
web_timeline/__openerp__.py

@ -3,21 +3,22 @@
# 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).
{ {
'name': "Web timeline",
'summary': "Interactive visualization chart to show events in time",
"version": "9.0.1.0.0",
'author': 'ACSONE SA/NV,'
'Tecnativa,'
'Odoo Community Association (OCA)',
"name": "Web timeline",
"summary": "Interactive visualization chart to show events in time",
"version": "8.0.1.0.0",
"author": "ACSONE SA/NV,"
"Tecnativa,"
"Odoo Community Association (OCA)",
"category": "web", "category": "web",
"website": "http://acsone.eu", "website": "http://acsone.eu",
'depends': [
'web',
"license": "AGPL-3",
"depends": [
"web",
], ],
'qweb': [
'static/src/xml/web_timeline.xml',
"qweb": [
"static/src/xml/web_timeline.xml",
], ],
'data': [
'views/web_timeline.xml',
"data": [
"views/web_timeline.xml",
], ],
} }

434
web_timeline/static/src/js/web_timeline.js

@ -3,7 +3,13 @@
* Copyright 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com> * Copyright 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
/* global moment,vis,py */
/* eslint require-jsdoc:0 */
/* eslint no-alert:0 */
/* eslint no-eval:0 */
_.str.toBoolElse = function (str, elseValues, trueValues, falseValues) { _.str.toBoolElse = function (str, elseValues, trueValues, falseValues) {
'use strict';
var ret = _.str.toBool(str, trueValues, falseValues); var ret = _.str.toBool(str, trueValues, falseValues);
if (_.isUndefined(ret)) { if (_.isUndefined(ret)) {
return elseValues; return elseValues;
@ -11,21 +17,15 @@ _.str.toBoolElse = function (str, elseValues, trueValues, falseValues) {
return ret; return ret;
}; };
var moment = vis.moment;
openerp.web_timeline = function(instance) {
var core = instance.web.core;
var form_common = instance.web.form_common;
openerp.web_timeline = function (instance) {
'use strict';
var Model = instance.web.Model; var Model = instance.web.Model;
var str_to_datetime = instance.str_to_datetime; var str_to_datetime = instance.str_to_datetime;
var View = instance.web.View;
var widgets = instance.web_calendar;
var _t = instance.web._t, var _t = instance.web._t,
_lt = instance.web._lt,
QWeb = instance.web.qweb;
_lt = instance.web._lt;
var moment = vis.moment;
function isNullOrUndef(value) {
function isNullOrUndef (value) {
return _.isUndefined(value) || _.isNull(value); return _.isUndefined(value) || _.isNull(value);
} }
@ -54,10 +54,10 @@ openerp.web_timeline = function(instance) {
this.current_window = null; this.current_window = null;
}, },
get_perm: function(name){
get_perm: function (name) {
var self = this; var self = this;
var promise = self.permissions[name]; var promise = self.permissions[name];
if(!promise) {
if (!promise) {
var defer = $.Deferred(); var defer = $.Deferred();
new Model(this.dataset.model) new Model(this.dataset.model)
.call("check_access_rights", [name, false]) .call("check_access_rights", [name, false])
@ -66,51 +66,73 @@ openerp.web_timeline = function(instance) {
defer.resolve(); defer.resolve();
}); });
return defer; return defer;
} else {
return promise;
} }
return promise;
}, },
set_default_options: function(options) {
set_default_options: function (options) {
this._super(options); this._super(options);
_.defaults(this.options, { _.defaults(this.options, {
confirm_on_delete: true
confirm_on_delete: true,
}); });
}, },
parse_colors: function(){
if(this.fields_view.arch.attrs.colors) {
this.colors = _(this.fields_view.arch.attrs.colors.split(';')).chain().compact().map(function(color_pair) {
var pair = color_pair.split(':'), color = pair[0], expr = pair[1];
var temp = py.parse(py.tokenize(expr));
return {'color': color, 'field': temp.expressions[0].value, 'opt': temp.operators[0], 'value': temp.expressions[1].value};
parse_colors: function () {
if (this.fields_view.arch.attrs.colors) {
this.colors = _(
this.fields_view.arch.attrs.colors.split(';')
).chain().compact().map(function (color_pair) {
var pair = color_pair.split(':'),
color = pair[0],
expr = pair[1],
temp = py.parse(py.tokenize(expr));
return {
'color': color,
'field': temp.expressions[0].value,
'opt': temp.operators[0],
'value': temp.expressions[1].value,
};
}).value(); }).value();
} }
}, },
view_loading: function (fv) { view_loading: function (fv) {
/* xml view timeline options */
/* Xml view timeline options */
var attrs = fv.arch.attrs; var attrs = fv.arch.attrs;
var self = this; var self = this;
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($.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.$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 moment(), start: new moment(),
end : new moment().add(24, 'hours'), end : new moment().add(24, 'hours'),
}
};
this.info_fields = []; this.info_fields = [];
if (!attrs.date_start) { if (!attrs.date_start) {
throw new Error(_t("Timeline view has not defined 'date_start' attribute."));
throw new Error(_t(
"Timeline view has not defined 'date_start' attribute."
));
} }
this.$el.addClass(attrs['class']);
this.$el.addClass(attrs.class);
this.name = fv.name || attrs.string; this.name = fv.name || attrs.string;
this.view_id = fv.view_id; this.view_id = fv.view_id;
@ -120,12 +142,19 @@ openerp.web_timeline = function(instance) {
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;
} else { } else {
this.open_popup_action = attrs.event_open_popup; this.open_popup_action = attrs.event_open_popup;
@ -137,46 +166,49 @@ 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 Model(this.dataset.model)
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 Model(this.dataset.model)
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 Model(this.dataset.model)
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;
}); });
var init = function () { var init = function () {
self.init_timeline().then(function() {
self.init_timeline().then(function () {
$(window).trigger('resize'); $(window).trigger('resize');
self.trigger('timeline_view_loaded', fv); self.trigger('timeline_view_loaded', fv);
self.ready.resolve(); self.ready.resolve();
}); });
}; };
return $.when(self.fields_get, self.get_perm('unlink'), self.get_perm('write'), self.get_perm('create')).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 () {
var self = this; var self = this;
var options = { var options = {
groupOrder: self.group_order, groupOrder: self.group_order,
editable: { editable: {
// 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'],
// 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,
@ -189,20 +221,19 @@ openerp.web_timeline = function(instance) {
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);
if(self.mode && self['on_scale_' + self.mode + '_clicked'])
{
if (self.mode && self['on_scale_' + self.mode + '_clicked']) {
self['on_scale_' + self.mode + '_clicked'](); self['on_scale_' + self.mode + '_clicked']();
} }
self.timeline.on('click', self.on_click); self.timeline.on('click', self.on_click);
return $.when(); return $.when();
}, },
group_order: function(grp1, grp2) {
// display non grouped elements first
if (grp1.id === -1){
group_order: function (grp1, grp2) {
// Display non grouped elements first
if (grp1.id === -1) {
return -1; return -1;
} }
if (grp2.id === -1){
if (grp2.id === -1) {
return +1; return +1;
} }
return grp1.content - grp2.content; return grp1.content - grp2.content;
@ -210,47 +241,58 @@ openerp.web_timeline = function(instance) {
}, },
/* Transform Odoo 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_start = new moment();
var date_stop = 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,
res_computed_text = '',
the_title = '',
attendees = [];
all_day = this.all_day ? evt[this.all_day] : false;
if (!all_day) {
if (all_day) {
date_start = str_to_datetime(
evt[this.date_start].split(' ')[0], 'start'
);
date_stop = this.date_stop
? str_to_datetime(
evt[this.date_stop].split(' ')[0], 'stop'
) : null;
} else {
date_start = str_to_datetime(evt[this.date_start]); date_start = str_to_datetime(evt[this.date_start]);
date_stop = this.date_stop ? str_to_datetime(evt[this.date_stop]) : null;
}
else {
date_start = str_to_datetime(evt[this.date_start].split(' ')[0],'start');
date_stop = this.date_stop ? str_to_datetime(evt[this.date_stop].split(' ')[0],'stop') : null;
date_stop = this.date_stop ? str_to_datetime(
evt[this.date_stop]
) : null;
} }
if (!date_start){
if (!date_start) {
date_start = new moment(); date_start = new moment();
} }
if(!date_stop) {
date_stop = moment(date_start).add(date_delay, 'hours').toDate();
if (!date_stop) {
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) {
group = _.first(group); group = _.first(group);
} else { } else {
group = -1; group = -1;
} }
_.each(self.colors, function(color){
if(eval("'" + evt[color.field] + "' " + color.opt + " '" + color.value + "'"))
_.each(self.colors, function (color) {
if (eval(
"'" + evt[color.field] + "' " + color.opt + " '" +
color.value + "'")
) {
self.color = color.color; self.color = color.color;
}
}); });
var r = { var r = {
'start': date_start, 'start': date_start,
'end': date_stop, 'end': date_stop,
'content': evt.__name != undefined ? evt.__name : evt.display_name,
'content':
evt.__name === undefined
? evt.display_name : evt.__name,
'id': evt.id, 'id': evt.id,
'group': group, 'group': group,
'evt': evt, 'evt': evt,
@ -265,105 +307,115 @@ openerp.web_timeline = function(instance) {
var self = this; var self = this;
self.last_domains = domains; self.last_domains = domains;
self.last_contexts = contexts; self.last_contexts = contexts;
// select the group by
// Select the group by
var n_group_bys = []; var n_group_bys = [];
if (this.fields_view.arch.attrs.default_group_by) { if (this.fields_view.arch.attrs.default_group_by) {
n_group_bys = this.fields_view.arch.attrs.default_group_by.split(',');
n_group_bys =
this.fields_view.arch.attrs.default_group_by.split(',');
} }
if (group_bys.length) { if (group_bys.length) {
n_group_bys = group_bys; n_group_bys = group_bys;
} }
self.last_group_bys = n_group_bys; self.last_group_bys = n_group_bys;
// gather the fields to get
var fields = _.compact(_.map(["date_start", "date_delay", "date_stop", "progress"], function(key) {
// Gather the fields to get
var fields = _.compact(_.map(
["date_start", "date_delay", "date_stop", "progress"],
function (key) {
return self.fields_view.arch.attrs[key] || ''; return self.fields_view.arch.attrs[key] || '';
}));
}
));
fields.push(this.fields_view.arch.attrs.name); fields.push(this.fields_view.arch.attrs.name);
fields = _.uniq(fields.concat(
_.pluck(this.colors, "field").concat(n_group_bys)
));
fields = _.uniq(fields.concat(_.pluck(this.colors, "field").concat(n_group_bys)));
return $.when(this.has_been_loaded).then(function() {
return $.when(this.has_been_loaded).then(function () {
return self.dataset.read_slice(fields, { return self.dataset.read_slice(fields, {
domain: domains, domain: domains,
context: contexts
}).then(function(data) {
context: contexts,
}).then(function (data) {
return self.on_data_loaded(data, n_group_bys); return self.on_data_loaded(data, n_group_bys);
}); });
}); });
}, },
reload: function() {
reload: function () {
var self = this; var self = this;
if (this.last_domains !== undefined){
if (this.last_domains !== undefined) {
self.current_window = self.timeline.getWindow(); self.current_window = self.timeline.getWindow();
return this.do_search(this.last_domains, this.last_contexts, this.last_group_bys);
return this.do_search(
this.last_domains, this.last_contexts, this.last_group_bys
);
} }
}, },
on_data_loaded: function(events, group_bys) {
on_data_loaded: function (events, group_bys) {
var self = this; var self = this;
var ids = _.pluck(events, "id"); var ids = _.pluck(events, "id");
return this.dataset.name_get(ids).then(function(names) {
var nevents = _.map(events, function(event) {
return _.extend({__name: _.detect(names, function(name) {
return name[0] == event.id;
return this.dataset.name_get(ids).then(function (names) {
var nevents = _.map(events, function (event) {
return _.extend({__name: _.detect(names, function (name) {
return name[0] === event.id;
})[1]}, event); })[1]}, event);
}); });
return self.on_data_loaded_2(nevents, group_bys); return self.on_data_loaded_2(nevents, group_bys);
}); });
}, },
on_data_loaded_2: function(events, group_bys) {
on_data_loaded_2: function (events, group_bys) {
var self = this; var self = this;
var data = []; var data = [];
var groups = [];
_.each(events, function(event) {
if (event[self.date_start]){
_.each(events, function (event) {
if (event[self.date_start]) {
var item = self.event_data_transform(event); var item = self.event_data_transform(event);
item.content = event.timeline_name; item.content = event.timeline_name;
data.push(item); data.push(item);
} }
}); });
// get the groups
var split_groups = function(events, group_bys) {
if (group_bys.length === 0)
return events;
var groups = [];
groups.push({id:-1, content: _t('-')})
_.each(events, function(event) {
var group_name = event[_.first(group_bys)];
// Get the groups
var split_groups = function (_events, _group_bys) {
if (_group_bys.length === 0) {
return _events;
}
var _groups = [];
_groups.push({id:-1, content: _t('-')});
_.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) {
group = {id: group_name[0], content: group_name[1]}; group = {id: group_name[0], content: group_name[1]};
groups.push(group);
_groups.push(group);
} }
} }
}); });
return groups;
}
return _groups;
};
var groups = split_groups(events, 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.fit(); this.timeline.fit();
}, },
do_show: function() {
do_show: function () {
this.do_push_state({}); this.do_push_state({});
return this._super(); return this._super();
}, },
is_action_enabled: function(action) {
is_action_enabled: function (action) {
if (action === 'create' && !this.options.creatable) { if (action === 'create' && !this.options.creatable) {
return false; return false;
} }
return this._super(action); return this._super(action);
}, },
create_completed: function(id) {
create_completed: function (id) {
var self = this; 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.dataset.read_ids([id], this.fields).done(function(records) {
this.dataset.read_ids([id], this.fields).done(function (records) {
var new_event = self.event_data_transform(records[0]); var new_event = self.event_data_transform(records[0]);
var items = self.timeline.itemsData; var items = self.timeline.itemsData;
items.add(new_event); items.add(new_event);
@ -371,12 +423,12 @@ openerp.web_timeline = function(instance) {
}); });
}, },
on_add: function(item, callback) {
on_add: function (item) {
var self = this, var self = this,
pop = new instance.web.form.SelectCreatePopup(this), pop = new instance.web.form.SelectCreatePopup(this),
context = this.get_popup_context(item); context = this.get_popup_context(item);
pop.on("elements_selected", self, function(element_ids) {
self.reload().then(function() {
pop.on("elements_selected", self, function (element_ids) {
self.reload().then(function () {
self.timeline.focus(element_ids); self.timeline.focus(element_ids);
}); });
}); });
@ -391,34 +443,26 @@ openerp.web_timeline = function(instance) {
); );
}, },
get_popup_context: function(item) {
get_popup_context: function (item) {
var context = {}; var context = {};
context['default_'.concat(this.date_start)] = item.start; context['default_'.concat(this.date_start)] = item.start;
context['default_'.concat(this.date_stop)] = item.start.clone() context['default_'.concat(this.date_stop)] = item.start.clone()
.addHours(this.date_delay || 1); .addHours(this.date_delay || 1);
if (item.group != -1) {
if (item.group !== -1) {
context['default_'.concat(this.last_group_bys[0])] = item.group; context['default_'.concat(this.last_group_bys[0])] = item.group;
} }
return context
return context;
}, },
on_update: function(item, callback) {
on_update: function (item) {
var self = this; var self = this;
var id = item.evt.id; var id = item.evt.id;
var title = item.evt.__name; var title = item.evt.__name;
if (! this.open_popup_action) {
var index = this.dataset.get_id_index(id);
this.dataset.index = index;
if (this.write_right) {
this.do_switch_view('form', null, { mode: "edit" });
} else {
this.do_switch_view('form', null, { mode: "view" });
}
}
else {
var id_cast = parseInt(id).toString() == id ? parseInt(id) : id;
if (this.open_popup_action) {
var id_cast =
parseInt(id, 10).toString() === id
? parseInt(id, 10) : id;
var pop = new instance.web.form.FormOpenPopup(self); var pop = new instance.web.form.FormOpenPopup(self);
pop.on('write_completed', self, self.reload); pop.on('write_completed', self, self.reload);
pop.show_element( pop.show_element(
@ -428,47 +472,90 @@ openerp.web_timeline = function(instance) {
{readonly: true, title: title} {readonly: true, title: title}
); );
var form_controller = pop.view_form; 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();
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").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.find('.oe_form_button_cancel').before(
"<span> or </span>"
);
var button_edit = _.str.sprintf(
"<button class='oe_button oe_form_button_edit " +
"oe_bold oe_highlight'><span> %s </span></button>",
_t("Edit")
);
var 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.prepend(button_edit + button_save);
footer.find('.oe_form_button_save').hide(); footer.find('.oe_form_button_save').hide();
footer.find('.oe_form_button_edit').on('click', function() {
footer.find('.oe_form_button_edit').on(
'click',
function () {
form_controller.to_edit_mode(); 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() {
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.save();
form_controller.to_view_mode(); 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");
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.prepend(chatter);
chatter_content.toggle(); chatter_content.toggle();
chatter_toggler.click(function(){
chatter_toggler.click(function () {
chatter_content.toggle(); chatter_content.toggle();
chatter_toggler.toggleClass('fa-plus-circle fa-minus-circle');
chatter_toggler.toggleClass(
'fa-plus-circle fa-minus-circle'
);
}); });
} }
}); });
} else {
var index = this.dataset.get_id_index(id);
this.dataset.index = index;
if (this.write_right) {
this.do_switch_view('form', null, {mode: "edit"});
} else {
this.do_switch_view('form', null, {mode: "view"});
}
} }
return false; return false;
}, },
on_move: function(item, callback) {
on_move: function (item) {
var self = this; var self = this;
var start = new moment(item.start); var start = new moment(item.start);
var end = new moment(item.end); var end = new moment(item.end);
var group = false; var group = false;
if (item.group != -1) {
if (item.group !== -1) {
group = item.group; group = item.group;
} }
var data = {}; var data = {};
@ -486,31 +573,34 @@ openerp.web_timeline = function(instance) {
this.dataset.write(id, data); this.dataset.write(id, data);
}, },
on_remove: function(item, callback) {
on_remove: function (item, callback) {
var self = this; var self = this;
function do_it() {
return $.when(self.dataset.unlink([item.evt.id])).then(function() {
function do_it () {
return $.when(self.dataset.unlink([item.evt.id])).then(
function () {
callback(item); callback(item);
});
}
);
} }
if (this.options.confirm_on_delete) { if (this.options.confirm_on_delete) {
if (confirm(_t("Are you sure you want to delete this record ?"))) {
if (confirm(_t(
"Are you sure you want to delete this record ?"
))) {
return do_it(); return do_it();
} }
} else
} else {
return do_it(); return do_it();
}
}, },
on_click: function(e) {
// handle a click on a group header
if(e.what == 'group-label')
{
on_click: function (e) {
// Handle a click on a group header
if (e.what === 'group-label') {
return this.on_group_click(e); return this.on_group_click(e);
} }
}, },
on_group_click: function(e) {
if (e.group == -1)
{
on_group_click: function (e) {
if (e.group === -1) {
return; return;
} }
return this.do_action({ return this.do_action({
@ -522,38 +612,40 @@ openerp.web_timeline = function(instance) {
}); });
}, },
scale_current_window: function(factor){
if (this.timeline){
scale_current_window: function (factor) {
if (this.timeline) {
this.current_window = this.timeline.getWindow(); this.current_window = this.timeline.getWindow();
this.current_window.end = moment(this.current_window.start).add(factor, 'hours');
this.current_window.end = moment(
this.current_window.start
).add(factor, 'hours');
this.timeline.setWindow(this.current_window); this.timeline.setWindow(this.current_window);
} }
}, },
on_today_clicked: function(){
on_today_clicked: function () {
this.current_window = { this.current_window = {
start: new moment(), start: new moment(),
end : new moment().add(24, 'hours'), end : new moment().add(24, 'hours'),
}
};
if (this.timeline) { if (this.timeline) {
this.timeline.setWindow(this.current_window); this.timeline.setWindow(this.current_window);
} }
}, },
on_scale_day_clicked: function(){
on_scale_day_clicked: function () {
this.scale_current_window(24); this.scale_current_window(24);
}, },
on_scale_week_clicked: function(){
on_scale_week_clicked: function () {
this.scale_current_window(24 * 7); this.scale_current_window(24 * 7);
}, },
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);
}, },
}); });

Loading…
Cancel
Save