2011-08-03 14:09:14 +00:00
/ *
This software is allowed to use under GPL or you need to obtain Commercial or Enterise License
2012-10-24 13:48:59 +00:00
to use it in non - GPL project . Please contact sales @ dhtmlx . com for details
2011-08-03 14:09:14 +00:00
* /
2011-04-07 16:41:06 +00:00
scheduler . config . year _x = 4 ;
scheduler . config . year _y = 3 ;
scheduler . config . year _mode _name = "year" ;
scheduler . xy . year _top = 0 ;
2011-08-03 14:09:14 +00:00
scheduler . templates . year _date = function ( date ) {
return scheduler . date . date _to _str ( scheduler . locale . labels . year _tab + " %Y" ) ( date ) ;
2011-04-07 16:41:06 +00:00
} ;
2011-08-03 14:09:14 +00:00
scheduler . templates . year _month = scheduler . date . date _to _str ( "%F" ) ;
2011-04-07 16:41:06 +00:00
scheduler . templates . year _scale _date = scheduler . date . date _to _str ( "%D" ) ;
2011-08-03 14:09:14 +00:00
scheduler . templates . year _tooltip = function ( s , e , ev ) {
return ev . text
2011-04-07 16:41:06 +00:00
} ;
2011-08-03 14:09:14 +00:00
( function ( ) {
var is _year _mode = function ( ) {
return scheduler . _mode == scheduler . config . year _mode _name ;
} ;
2011-04-07 16:41:06 +00:00
2011-08-03 14:09:14 +00:00
scheduler . dblclick _dhx _month _head = function ( e ) {
if ( is _year _mode ( ) ) {
var t = ( e . target || e . srcElement ) ;
if ( t . parentNode . className . indexOf ( "dhx_before" ) != - 1 || t . parentNode . className . indexOf ( "dhx_after" ) != - 1 ) return false ;
var start = this . templates . xml _date ( t . parentNode . parentNode . parentNode . parentNode . parentNode . parentNode . getAttribute ( "date" ) ) ;
start . setDate ( parseInt ( t . innerHTML , 10 ) ) ;
var end = this . date . add ( start , 1 , "day" )
if ( ! this . config . readonly && this . config . dblclick _create )
this . addEventNow ( start . valueOf ( ) , end . valueOf ( ) , e ) ;
}
} ;
var chid = scheduler . changeEventId ;
scheduler . changeEventId = function ( ) {
chid . apply ( this , arguments ) ;
if ( is _year _mode ( ) )
this . year _view ( true ) ;
} ;
var old = scheduler . render _data ;
var to _attr = scheduler . date . date _to _str ( "%Y/%m/%d" ) ;
var from _attr = scheduler . date . str _to _date ( "%Y/%m/%d" ) ;
scheduler . render _data = function ( evs ) {
if ( ! is _year _mode ( ) ) return old . apply ( this , arguments ) ;
for ( var i = 0 ; i < evs . length ; i ++ )
this . _year _render _event ( evs [ i ] ) ;
} ;
var clear = scheduler . clear _view ;
scheduler . clear _view = function ( ) {
if ( ! is _year _mode ( ) ) return clear . apply ( this , arguments ) ;
2012-10-24 13:48:59 +00:00
for ( var date in marked ) {
if ( marked . hasOwnProperty ( date ) ) {
var div = marked [ date ] ;
div . className = "dhx_month_head" ;
div . setAttribute ( "date" , "" )
}
2011-08-03 14:09:14 +00:00
}
2012-10-24 13:48:59 +00:00
marked = { } ;
2011-08-03 14:09:14 +00:00
} ;
scheduler . hideToolTip = function ( ) {
if ( this . _tooltip ) {
this . _tooltip . style . display = "none" ;
this . _tooltip . date = new Date ( 9999 , 1 , 1 ) ;
}
} ;
scheduler . showToolTip = function ( date , pos , e , src ) {
if ( this . _tooltip ) {
if ( this . _tooltip . date . valueOf ( ) == date . valueOf ( ) ) return ;
this . _tooltip . innerHTML = "" ;
} else {
var t = this . _tooltip = document . createElement ( "DIV" ) ;
t . className = "dhx_tooltip" ;
document . body . appendChild ( t ) ;
t . onclick = scheduler . _click . dhx _cal _data ;
}
var evs = this . getEvents ( date , this . date . add ( date , 1 , "day" ) ) ;
var html = "" ;
for ( var i = 0 ; i < evs . length ; i ++ ) {
var ev = evs [ i ] ;
2012-10-24 13:48:59 +00:00
var bg _color = ( ev . color ? ( "background:" + ev . color + ";" ) : "" ) ;
2011-08-03 14:09:14 +00:00
var color = ( ev . textColor ? ( "color:" + ev . textColor + ";" ) : "" ) ;
html += "<div class='dhx_tooltip_line' style='" + bg _color + "" + color + "' event_id='" + evs [ i ] . id + "'>" ;
html += "<div class='dhx_tooltip_date' style='" + bg _color + "" + color + "'>" + ( evs [ i ] . _timed ? this . templates . event _date ( evs [ i ] . start _date ) : "" ) + "</div>" ;
html += "<div class='dhx_event_icon icon_details'> </div>" ;
html += this . templates . year _tooltip ( evs [ i ] . start _date , evs [ i ] . end _date , evs [ i ] ) + "</div>" ;
}
this . _tooltip . style . display = "" ;
this . _tooltip . style . top = "0px" ;
if ( document . body . offsetWidth - pos . left - this . _tooltip . offsetWidth < 0 )
this . _tooltip . style . left = pos . left - this . _tooltip . offsetWidth + "px" ;
else
this . _tooltip . style . left = pos . left + src . offsetWidth + "px" ;
this . _tooltip . date = date ;
this . _tooltip . innerHTML = html ;
if ( document . body . offsetHeight - pos . top - this . _tooltip . offsetHeight < 0 )
this . _tooltip . style . top = pos . top - this . _tooltip . offsetHeight + src . offsetHeight + "px" ;
else
this . _tooltip . style . top = pos . top + "px" ;
} ;
scheduler . _init _year _tooltip = function ( ) {
dhtmlxEvent ( scheduler . _els [ "dhx_cal_data" ] [ 0 ] , "mouseover" , function ( e ) {
if ( ! is _year _mode ( ) ) return ;
var e = e || event ;
var src = e . target || e . srcElement ;
if ( src . tagName . toLowerCase ( ) == 'a' ) // fix for active links extension (it adds links to the date in the cell)
src = src . parentNode ;
if ( ( src . className || "" ) . indexOf ( "dhx_year_event" ) != - 1 )
scheduler . showToolTip ( from _attr ( src . getAttribute ( "date" ) ) , getOffset ( src ) , e , src ) ;
else
scheduler . hideToolTip ( ) ;
} ) ;
this . _init _year _tooltip = function ( ) {
} ;
} ;
scheduler . attachEvent ( "onSchedulerResize" , function ( ) {
if ( is _year _mode ( ) ) {
this . year _view ( true ) ;
return false ;
}
return true ;
} ) ;
scheduler . _get _year _cell = function ( d ) {
//there can be more than 1 year in view
//year can start not from January
var m = d . getMonth ( ) + 12 * ( d . getFullYear ( ) - this . _min _date . getFullYear ( ) ) - this . week _starts . _month ;
var t = this . _els [ "dhx_cal_data" ] [ 0 ] . childNodes [ m ] ;
var d = this . week _starts [ m ] + d . getDate ( ) - 1 ;
return t . childNodes [ 2 ] . firstChild . rows [ Math . floor ( d / 7 ) ] . cells [ d % 7 ] . firstChild ;
} ;
2012-10-24 13:48:59 +00:00
var marked = { } ;
2011-08-03 14:09:14 +00:00
scheduler . _mark _year _date = function ( d , ev ) {
2012-10-24 13:48:59 +00:00
var date = to _attr ( d ) ;
2011-08-03 14:09:14 +00:00
var c = this . _get _year _cell ( d ) ;
2012-10-24 13:48:59 +00:00
var ev _class = this . templates . event _class ( ev . start _date , ev . end _date , ev ) ;
if ( ! marked [ date ] ) {
c . className = "dhx_month_head dhx_year_event" ;
c . setAttribute ( "date" , date ) ;
marked [ date ] = c ;
}
c . className += ( ev _class ) ? ( " " + ev _class ) : "" ;
2011-08-03 14:09:14 +00:00
} ;
scheduler . _unmark _year _date = function ( d ) {
this . _get _year _cell ( d ) . className = "dhx_month_head" ;
} ;
scheduler . _year _render _event = function ( ev ) {
var d = ev . start _date ;
if ( d . valueOf ( ) < this . _min _date . valueOf ( ) )
d = this . _min _date ;
else d = this . date . date _part ( new Date ( d ) ) ;
while ( d < ev . end _date ) {
this . _mark _year _date ( d , ev ) ;
d = this . date . add ( d , 1 , "day" ) ;
if ( d . valueOf ( ) >= this . _max _date . valueOf ( ) )
return ;
}
} ;
scheduler . year _view = function ( mode ) {
if ( mode ) {
var temp = scheduler . xy . scale _height ;
scheduler . xy . scale _height = - 1 ;
}
scheduler . _els [ "dhx_cal_header" ] [ 0 ] . style . display = mode ? "none" : "" ;
scheduler . set _sizes ( ) ;
if ( mode )
scheduler . xy . scale _height = temp ;
scheduler . _table _view = mode ;
if ( this . _load _mode && this . _load ( ) ) return ;
if ( mode ) {
scheduler . _init _year _tooltip ( ) ;
scheduler . _reset _year _scale ( ) ;
2012-10-24 13:48:59 +00:00
if ( scheduler . _load _mode && scheduler . _load ( ) ) return scheduler . _render _wait = true ;
2011-08-03 14:09:14 +00:00
scheduler . render _view _data ( ) ;
} else {
scheduler . hideToolTip ( ) ;
}
} ;
scheduler . _reset _year _scale = function ( ) {
this . _cols = [ ] ;
this . _colsS = { } ;
var week _starts = [ ] ; //start day of first week in each month
var b = this . _els [ "dhx_cal_data" ] [ 0 ] ;
var c = this . config ;
b . scrollTop = 0 ; //fix flickering in FF
b . innerHTML = "" ;
var dx = Math . floor ( parseInt ( b . style . width ) / c . year _x ) ;
var dy = Math . floor ( ( parseInt ( b . style . height ) - scheduler . xy . year _top ) / c . year _y ) ;
if ( dy < 190 ) {
dy = 190 ;
dx = Math . floor ( ( parseInt ( b . style . width ) - scheduler . xy . scroll _width ) / c . year _x ) ;
}
var summ = dx - 11 ;
var left = 0 ;
var week _template = document . createElement ( "div" ) ;
var dummy _date = this . date . week _start ( new Date ( ) ) ;
for ( var i = 0 ; i < 7 ; i ++ ) {
this . _cols [ i ] = Math . floor ( summ / ( 7 - i ) ) ;
this . _render _x _header ( i , left , dummy _date , week _template ) ;
dummy _date = this . date . add ( dummy _date , 1 , "day" ) ;
summ -= this . _cols [ i ] ;
left += this . _cols [ i ] ;
}
week _template . lastChild . className += " dhx_scale_bar_last" ;
var sd = this . date [ this . _mode + "_start" ] ( this . date . copy ( this . _date ) ) ;
var ssd = sd ;
for ( var i = 0 ; i < c . year _y ; i ++ )
for ( var j = 0 ; j < c . year _x ; j ++ ) {
var d = document . createElement ( "DIV" ) ;
d . style . cssText = "position:absolute;" ;
d . setAttribute ( "date" , this . templates . xml _format ( sd ) ) ;
d . innerHTML = "<div class='dhx_year_month'></div><div class='dhx_year_week'>" + week _template . innerHTML + "</div><div class='dhx_year_body'></div>" ;
d . childNodes [ 0 ] . innerHTML = this . templates . year _month ( sd ) ;
var dd = this . date . week _start ( sd ) ;
var ed = this . _reset _month _scale ( d . childNodes [ 2 ] , sd , dd ) ;
var r = d . childNodes [ 2 ] . firstChild . rows ;
for ( var k = r . length ; k < 6 ; k ++ ) {
r [ 0 ] . parentNode . appendChild ( r [ 0 ] . cloneNode ( true ) ) ;
for ( var ri = 0 ; ri < r [ k ] . childNodes . length ; ri ++ ) {
r [ k ] . childNodes [ ri ] . className = "dhx_after" ;
r [ k ] . childNodes [ ri ] . firstChild . innerHTML = scheduler . templates . month _day ( ed ) ;
ed = scheduler . date . add ( ed , 1 , "day" ) ;
}
}
b . appendChild ( d ) ;
d . childNodes [ 1 ] . style . height = d . childNodes [ 1 ] . childNodes [ 0 ] . offsetHeight + "px" ; // dhx_year_week should have height property so that day dates would get correct position. dhx_year_week height = height of it's child (with the day name)
var dt = Math . round ( ( dy - 190 ) / 2 ) ;
d . style . marginTop = dt + "px" ;
this . set _xy ( d , dx - 10 , dy - dt - 10 , dx * j + 5 , dy * i + 5 + scheduler . xy . year _top ) ;
week _starts [ i * c . year _x + j ] = ( sd . getDay ( ) - ( this . config . start _on _monday ? 1 : 0 ) + 7 ) % 7 ;
sd = this . date . add ( sd , 1 , "month" ) ;
}
this . _els [ "dhx_cal_date" ] [ 0 ] . innerHTML = this . templates [ this . _mode + "_date" ] ( ssd , sd , this . _mode ) ;
this . week _starts = week _starts ;
week _starts . _month = ssd . getMonth ( ) ;
this . _min _date = ssd ;
this . _max _date = sd ;
}
2011-04-07 16:41:06 +00:00
} ) ( ) ;