Skip to content

Commit 5f037df

Browse files
hbrunnAdrien Peiffer (ACSONE)
authored andcommitted
[ADD] a few features
1 parent 313156b commit 5f037df

File tree

2 files changed

+50
-8
lines changed

2 files changed

+50
-8
lines changed

web_timeline/static/src/css/web_timeline.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,8 @@
3535

3636
.oe_chatter_toggle {
3737
padding: 15px;
38-
}
38+
}
39+
40+
.oe_timeline_view .vlabel .inner:hover{
41+
cursor: pointer;
42+
}

web_timeline/static/src/js/web_timeline.js

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ openerp.web_timeline = function(instance) {
104104
this.name = fv.name || attrs.string;
105105
this.view_id = fv.view_id;
106106

107+
this.start = py.eval(attrs.start || 'None', instance.web.pyeval.context());
107108
this.mode = attrs.mode; // one of month, week or day
108109
this.date_start = attrs.date_start; // Field name of starting
109110
// date field
@@ -173,9 +174,15 @@ openerp.web_timeline = function(instance) {
173174
onUpdate: self.on_update,
174175
onRemove: self.on_remove,
175176
orientation: 'both',
177+
start: self.start,
176178
};
177-
self.timeline = new vis.Timeline(self.$timeline.get(0));
179+
self.timeline = new vis.Timeline(self.$timeline.empty().get(0));
178180
self.timeline.setOptions(options);
181+
if(self.mode && self['on_scale_' + self.mode + '_clicked'])
182+
{
183+
self['on_scale_' + self.mode + '_clicked']();
184+
}
185+
self.timeline.on('click', self.on_click);
179186
return $.when();
180187
},
181188

@@ -356,17 +363,14 @@ openerp.web_timeline = function(instance) {
356363
},
357364

358365
on_add: function(item, callback) {
359-
var self = this;
360-
var pop = new instance.web.form.SelectCreatePopup(this);
366+
var self = this,
367+
pop = new instance.web.form.SelectCreatePopup(this),
368+
context = this.get_popup_context(item);
361369
pop.on("elements_selected", self, function(element_ids) {
362370
self.reload().then(function() {
363371
self.timeline.focus(element_ids);
364372
});
365373
});
366-
context = {};
367-
context['default_'.concat(self.date_start)] = item.start;
368-
context['default_'.concat(self.last_group_bys[0])] = item.group;
369-
context['default_'.concat(self.date_stop)] = item.start.clone().addHours(this.date_delay || 1);
370374
pop.select_element(
371375
self.dataset.model,
372376
{
@@ -378,6 +382,18 @@ openerp.web_timeline = function(instance) {
378382
);
379383
},
380384

385+
get_popup_context: function(item) {
386+
var context = {};
387+
context['default_'.concat(this.date_start)] = item.start;
388+
context['default_'.concat(this.date_stop)] = item.start.clone()
389+
.addHours(this.date_delay || 1);
390+
if(item.group != -1)
391+
{
392+
context['default_'.concat(this.last_group_bys[0])] = item.group;
393+
}
394+
return context;
395+
},
396+
381397
on_update: function(item, callback) {
382398
var self = this;
383399
var id = item.evt.id;
@@ -472,6 +488,28 @@ openerp.web_timeline = function(instance) {
472488
return do_it();
473489
},
474490

491+
on_click: function(e) {
492+
// handle a click on a group header
493+
if(e.what == 'group-label')
494+
{
495+
return this.on_group_click(e);
496+
}
497+
},
498+
499+
on_group_click: function(e) {
500+
if(e.group == -1)
501+
{
502+
return;
503+
}
504+
return this.do_action({
505+
type: 'ir.actions.act_window',
506+
res_model: this.fields[this.last_group_bys[0]].relation,
507+
res_id: e.group,
508+
target: 'new',
509+
views: [[false, 'form']],
510+
});
511+
},
512+
475513
on_today_clicked: function(){
476514
this.current_window = {
477515
start: new Date(),

0 commit comments

Comments
 (0)