@@ -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