/*
Copyright Dinamenta, UAB. http://www.dhtmlx.com
To use this component please contact sales@dhtmlx.com to obtain license
*/
Scheduler.plugin(function(a){a.attachEvent("onTimelineCreated",function(b){if(b.render=="tree")b.y_unit_original=b.y_unit,b.y_unit=a._getArrayToDisplay(b.y_unit_original),a.attachEvent("onOptionsLoadStart",function(){b.y_unit=a._getArrayToDisplay(b.y_unit_original)}),a.form_blocks[b.name]={render:function(a){var c="<div class='dhx_section_timeline' style='overflow: hidden; height: "+a.height+"px'></div>";return c},set_value:function(d,c,g,h){var e=a._getArrayForSelect(a.matrix[h.type].y_unit_original,
h.type);d.innerHTML="";var b=document.createElement("select");d.appendChild(b);var i=d.getElementsByTagName("select")[0];if(!i._dhx_onchange&&h.onchange)i.onchange=h.onchange,i._dhx_onchange=!0;for(var k=0;k<e.length;k++){var j=document.createElement("option");j.value=e[k].key;if(j.value==g[a.matrix[h.type].y_property])j.selected=!0;j.innerHTML=e[k].label;i.appendChild(j)}},get_value:function(a){return a.firstChild.value},focus:function(){}}});a.attachEvent("onBeforeSectionRender",function(b,d,c){var g=
{};if(b=="tree"){var h,e,f,i,k,j;d.children?(h=c.folder_dy||c.dy,c.folder_dy&&!c.section_autoheight&&(f="height:"+c.folder_dy+"px;"),e="dhx_row_folder",i="dhx_matrix_scell folder",k="<div class='dhx_scell_expand'>"+(d.open?"-":"+")+"</div>",j=c.folder_events_available?"dhx_data_table folder_events":"dhx_data_table folder"):(h=c.dy,e="dhx_row_item",i="dhx_matrix_scell item",k="",j="dhx_data_table");var m="<div class='dhx_scell_level"+d.level+"'>"+k+"<div class='dhx_scell_name'>"+(a.templates[c.name+
"_scale_label"](d.key,d.label,d)||d.label)+"</div></div>",g={height:h,style_height:f,tr_className:e,td_className:i,td_content:m,table_className:j}}return g});var l;a.attachEvent("onBeforeEventChanged",function(b,d,c){if(a._isRender("tree")){var g=a.getSection(b[a.matrix[a._mode].y_property]);if(g&&typeof g.children!="undefined"&&!a.matrix[a._mode].folder_events_available)return c||(b[a.matrix[a._mode].y_property]=l),!1}return!0});a.attachEvent("onBeforeDrag",function(b,d,c){if(a._isRender("tree")){var g=
a._locate_cell_timeline(c);if(g){var h=a.matrix[a._mode].y_unit[g.y].key;if(typeof a.matrix[a._mode].y_unit[g.y].children!="undefined"&&!a.matrix[a._mode].folder_events_available)return!1}var e=a.getEvent(b);l=h||e[a.matrix[a._mode].y_property]}return!0});a._getArrayToDisplay=function(b){var d=[],c=function(b,h){for(var e=h||0,f=0;f<b.length;f++){b[f].level=e;if(typeof b[f].children!="undefined"&&typeof b[f].key=="undefined")b[f].key=a.uid();d.push(b[f]);b[f].open&&b[f].children&&c(b[f].children,
e+1)}};c(b);return d};a._getArrayForSelect=function(b,d){var c=[],g=function(b){for(var e=0;e<b.length;e++)a.matrix[d].folder_events_available?c.push(b[e]):typeof b[e].children=="undefined"&&c.push(b[e]),b[e].children&&g(b[e].children,d)};g(b);return c};a._toggleFolderDisplay=function(b,d,c){var g,h=function(a,b,e,d){for(var c=0;c<b.length;c++){if((b[c].key==a||d)&&b[c].children)if(b[c].open=typeof e!="undefined"?e:!b[c].open,g=!0,!d&&g)break;b[c].children&&h(a,b[c].children,e,d)}},e=a.getSection(b);
if(a.callEvent("onBeforeFolderToggle",[e,d,c]))h(b,a.matrix[a._mode].y_unit_original,d,c),a.matrix[a._mode].y_unit=a._getArrayToDisplay(a.matrix[a._mode].y_unit_original),a.callEvent("onOptionsLoad",[]),a.callEvent("onAfterFolderToggle",[e,d,c])};a.attachEvent("onCellClick",function(b,d){a._isRender("tree")&&(a.matrix[a._mode].folder_events_available||typeof a.matrix[a._mode].y_unit[d].children!="undefined"&&a._toggleFolderDisplay(a.matrix[a._mode].y_unit[d].key))});a.attachEvent("onYScaleClick",
function(b,d){a._isRender("tree")&&typeof d.children!="undefined"&&a._toggleFolderDisplay(d.key)});a.getSection=function(b){if(a._isRender("tree")){var d,c=function(a,b){for(var e=0;e<b.length;e++)b[e].key==a&&(d=b[e]),b[e].children&&c(a,b[e].children)};c(b,a.matrix[a._mode].y_unit_original);return d||null}};a.deleteSection=function(b){if(a._isRender("tree")){var d=!1,c=function(a,b){for(var e=0;e<b.length;e++){b[e].key==a&&(b.splice(e,1),d=!0);if(d)break;b[e].children&&c(a,b[e].children)}};c(b,a.matrix[a._mode].y_unit_original);
a.matrix[a._mode].y_unit=a._getArrayToDisplay(a.matrix[a._mode].y_unit_original);a.callEvent("onOptionsLoad",[]);return d}};a.deleteAllSections=function(){if(a._isRender("tree"))a.matrix[a._mode].y_unit_original=[],a.matrix[a._mode].y_unit=a._getArrayToDisplay(a.matrix[a._mode].y_unit_original),a.callEvent("onOptionsLoad",[])};a.addSection=function(b,d){if(a._isRender("tree")){var c=!1,g=function(a,b,f){if(d)for(var i=0;i<f.length;i++){f[i].key==b&&typeof f[i].children!="undefined"&&(f[i].children.push(a),
c=!0);if(c)break;f[i].children&&g(a,b,f[i].children)}else f.push(a),c=!0};g(b,d,a.matrix[a._mode].y_unit_original);a.matrix[a._mode].y_unit=a._getArrayToDisplay(a.matrix[a._mode].y_unit_original);a.callEvent("onOptionsLoad",[]);return c}};a.openAllSections=function(){a._isRender("tree")&&a._toggleFolderDisplay(1,!0,!0)};a.closeAllSections=function(){a._isRender("tree")&&a._toggleFolderDisplay(1,!1,!0)};a.openSection=function(b){a._isRender("tree")&&a._toggleFolderDisplay(b,!0)};a.closeSection=function(b){a._isRender("tree")&&
a._toggleFolderDisplay(b,!1)}});
