Browse Source

Port web_timeline to v10

pull/521/head
Leonardo Donelli 8 years ago
committed by Pedro M. Baeza
parent
commit
7d7d1852de
  1. 1
      web_timeline/README.rst
  2. 3
      web_timeline/__manifest__.py
  3. 4
      web_timeline/static/src/css/web_timeline.css
  4. 133
      web_timeline/static/src/js/web_timeline.js

1
web_timeline/README.rst

@ -124,6 +124,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> * Pedro M. Baeza <pedro.baeza@tecnativa.com>
* Leonardo Donelli <donelli@webmonks.it>
Maintainer Maintainer
---------- ----------

3
web_timeline/__openerp__.py → web_timeline/__manifest__.py

@ -5,9 +5,10 @@
{ {
'name': "Web timeline", 'name': "Web timeline",
'summary': "Interactive visualization chart to show events in time", 'summary': "Interactive visualization chart to show events in time",
"version": "9.0.1.0.0",
"version": "10.0.1.0.0",
'author': 'ACSONE SA/NV, ' 'author': 'ACSONE SA/NV, '
'Tecnativa, ' 'Tecnativa, '
'Monk Software, ',
'Odoo Community Association (OCA)', 'Odoo Community Association (OCA)',
"category": "web", "category": "web",
"website": "http://acsone.eu", "website": "http://acsone.eu",

4
web_timeline/static/src/css/web_timeline.css

@ -3,10 +3,10 @@
content: "N"; content: "N";
} }
/* gray background in weekends, white text color */
/* very light gray background in weekends */
.vis.timeline .timeaxis .grid.saturday, .vis.timeline .timeaxis .grid.saturday,
.vis.timeline .timeaxis .grid.sunday { .vis.timeline .timeaxis .grid.sunday {
background: gray;
background: #DCDCDC;
} }
.vis.timeline .item.range .content { .vis.timeline .item.range .content {

133
web_timeline/static/src/js/web_timeline.js

@ -20,12 +20,9 @@ odoo.define('web_timeline.TimelineView', function (require) {
var time = require('web.time'); var time = require('web.time');
var View = require('web.View'); var View = require('web.View');
var widgets = require('web_calendar.widgets'); var widgets = require('web_calendar.widgets');
var _ = require('_');
var $ = require('$');
var _t = core._t; var _t = core._t;
var _lt = core._lt; var _lt = core._lt;
var QWeb = core.qweb;
function isNullOrUndef(value) { function isNullOrUndef(value) {
return _.isUndefined(value) || _.isNull(value); return _.isUndefined(value) || _.isNull(value);
@ -38,45 +35,31 @@ odoo.define('web_timeline.TimelineView', function (require) {
quick_create_instance: widgets.QuickCreate, quick_create_instance: widgets.QuickCreate,
init: function (parent, dataset, view_id, options) { init: function (parent, dataset, view_id, options) {
this._super(parent);
this.ready = $.Deferred();
this.permissions = {}; this.permissions = {};
this.set_default_options(options);
this.dataset = dataset;
this.model = dataset.model;
this.fields_view = {};
this.view_id = view_id;
this.view_type = 'timeline';
this.color_map = {};
this.range_start = null;
this.range_stop = null;
this.selected_filters = [];
this.current_window = null;
return this._super.apply(this, arguments);
}, },
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) {
var defer = $.Deferred();
new Model(this.dataset.model)
if (self.permissions[name]) {
return $.when(self.permissions[name]);
} else {
return 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;
defer.resolve();
return value;
}); });
return defer;
} else {
return promise;
} }
}, },
set_default_options: function(options) {
this._super(options);
_.defaults(this.options, {
confirm_on_delete: true
});
},
// set_default_options: function(options) {
// this._super(options);
// _.defaults(this.options, {
// confirm_on_delete: true
// });
// },
parse_colors: function(){ parse_colors: function(){
if(this.fields_view.arch.attrs.colors) { if(this.fields_view.arch.attrs.colors) {
@ -88,34 +71,35 @@ odoo.define('web_timeline.TimelineView', function (require) {
} }
}, },
view_loading: function (fv) {
/* xml view timeline options */
var attrs = fv.arch.attrs;
start: function () {
var self = this; var self = this;
this.fields_view = fv;
var attrs = this.fields_view.arch.attrs;
var fv = this.fields_view;
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.$(".oe_timeline_button_today").click(
this.proxy(this.on_today_clicked));
this.$(".oe_timeline_button_scale_day").click(
this.proxy(this.on_scale_day_clicked));
this.$(".oe_timeline_button_scale_week").click(
this.proxy(this.on_scale_week_clicked));
this.$(".oe_timeline_button_scale_month").click(
this.proxy(this.on_scale_month_clicked));
this.$(".oe_timeline_button_scale_year").click(
this.proxy(this.on_scale_year_clicked));
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.$el.addClass(attrs['class']);
this.info_fields = []; this.info_fields = [];
this.mode = attrs.mode;
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.name = fv.name || attrs.string;
this.view_id = fv.view_id;
this.mode = attrs.mode;
this.date_start = attrs.date_start; this.date_start = attrs.date_start;
this.date_stop = attrs.date_stop; this.date_stop = attrs.date_stop;
@ -142,26 +126,17 @@ odoo.define('web_timeline.TimelineView', function (require) {
.then(function (fields) { .then(function (fields) {
self.fields = fields; self.fields = fields;
}); });
var unlink_check = new Model(this.dataset.model)
.call("check_access_rights", ["unlink", false])
.then(function (unlink_right) {
self.unlink_right = unlink_right;
});
var edit_check = new Model(this.dataset.model)
.call("check_access_rights", ["write", false])
.then(function (write_right) {
self.write_right = write_right;
});
var init = function () {
self.init_timeline().then(function() {
this._super.apply(this, self);
return $.when(
self.fields_get,
self.get_perm('unlink'),
self.get_perm('write'),
self.get_perm('create')
).then(function() {
self.init_timeline();
$(window).trigger('resize'); $(window).trigger('resize');
self.trigger('timeline_view_loaded', fv); self.trigger('timeline_view_loaded', fv);
self.ready.resolve();
}); });
};
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() {
@ -176,7 +151,7 @@ odoo.define('web_timeline.TimelineView', function (require) {
// drag items from one group to another // drag items from one group to another
updateGroup: self.permissions['write'], updateGroup: self.permissions['write'],
// delete an item by tapping the delete button top right // delete an item by tapping the delete button top right
remove: self.permissions['unlink'],
remove: self.permissions['unlink']
}, },
orientation: 'both', orientation: 'both',
selectable: true, selectable: true,
@ -185,16 +160,13 @@ odoo.define('web_timeline.TimelineView', function (require) {
onMove: self.on_move, onMove: self.on_move,
onUpdate: self.on_update, onUpdate: self.on_update,
onRemove: self.on_remove, onRemove: self.on_remove,
orientation: 'both',
}; };
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();
}, },
group_order: function(grp1, grp2) { group_order: function(grp1, grp2) {
@ -253,8 +225,7 @@ odoo.define('web_timeline.TimelineView', function (require) {
'id': evt.id, 'id': evt.id,
'group': group, 'group': group,
'evt': evt, 'evt': evt,
'style': 'background-color: ' + self.color + ';',
'style': 'background-color: ' + self.color + ';'
}; };
self.color = undefined; self.color = undefined;
return r; return r;
@ -369,7 +340,7 @@ odoo.define('web_timeline.TimelineView', function (require) {
var self = this; var self = this;
var context = this.dataset.get_context(); var context = this.dataset.get_context();
// Initialize default values for creation // Initialize default values for creation
var default_context = {}
var default_context = {};
default_context['default_'.concat(this.date_start)] = item.start; default_context['default_'.concat(this.date_start)] = item.start;
default_context['default_'.concat(this.date_stop)] = moment(item.start).add(1, 'hours').toDate(); default_context['default_'.concat(this.date_stop)] = moment(item.start).add(1, 'hours').toDate();
if (item.group > 0) { if (item.group > 0) {
@ -381,7 +352,7 @@ odoo.define('web_timeline.TimelineView', function (require) {
res_model: this.dataset.model, res_model: this.dataset.model,
res_id: null, res_id: null,
context: context, context: context,
view_id: +this.open_popup_action,
view_id: +this.open_popup_action
}).open(); }).open();
dialog.on('create_completed', this, this.create_completed); dialog.on('create_completed', this, this.create_completed);
return false; return false;
@ -413,7 +384,7 @@ odoo.define('web_timeline.TimelineView', function (require) {
res_id: parseInt(id).toString() == id ? parseInt(id) : id, res_id: parseInt(id).toString() == id ? parseInt(id) : id,
context: this.dataset.get_context(), context: this.dataset.get_context(),
title: title, title: title,
view_id: +this.open_popup_action,
view_id: +this.open_popup_action
}).open(); }).open();
dialog.on('write_completed', this, this.write_completed); dialog.on('write_completed', this, this.write_completed);
} }
@ -455,15 +426,13 @@ odoo.define('web_timeline.TimelineView', function (require) {
on_click: function(e) { on_click: function(e) {
// handle a click on a group header // handle a click on a group header
if(e.what == 'group-label')
{
if (e.what == 'group-label') {
return this.on_group_click(e); return this.on_group_click(e);
} }
}, },
on_group_click: function(e) { on_group_click: function(e) {
if (e.group == -1)
{
if (e.group == -1) {
return; return;
} }
return this.do_action({ return this.do_action({
@ -471,7 +440,7 @@ odoo.define('web_timeline.TimelineView', function (require) {
res_model: this.fields[this.last_group_bys[0]].relation, res_model: this.fields[this.last_group_bys[0]].relation,
res_id: e.group, res_id: e.group,
target: 'new', target: 'new',
views: [[false, 'form']],
views: [[false, 'form']]
}); });
}, },
@ -486,8 +455,8 @@ odoo.define('web_timeline.TimelineView', function (require) {
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);
@ -508,7 +477,7 @@ odoo.define('web_timeline.TimelineView', function (require) {
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); core.view_registry.add('timeline', TimelineView);

Loading…
Cancel
Save