/*

@license
dhtmlxScheduler.Net v.4.0.3 Professional Evaluation

This software is covered by DHTMLX Evaluation License. Contact sales@dhtmlx.com to get Commercial or Enterprise license. Usage without proper license is prohibited.

(c) XB Software Ltd.

*/
Scheduler.plugin(function(e){e.attachEvent("onTimelineCreated",function(t){"tree"==t.render&&(t.y_unit_original=t.y_unit,t.y_unit=e._getArrayToDisplay(t.y_unit_original),e.attachEvent("onOptionsLoadStart",function(){t.y_unit=e._getArrayToDisplay(t.y_unit_original)}),e.form_blocks[t.name]={render:function(e){return"<div class='dhx_section_timeline' style='overflow: hidden; height: "+e.height+"px'></div>"},set_value:function(t,a,n,i){
var r=e._getArrayForSelect(e.matrix[i.type].y_unit_original,i.type);t.innerHTML="";var o=document.createElement("select");t.appendChild(o);var l=t.getElementsByTagName("select")[0];!l._dhx_onchange&&i.onchange&&(l.onchange=i.onchange,l._dhx_onchange=!0);for(var d=0;d<r.length;d++){var _=document.createElement("option");_.value=r[d].key,_.value==n[e.matrix[i.type].y_property]&&(_.selected=!0),_.innerHTML=r[d].label,l.appendChild(_)}},get_value:function(e,t,a){return e.firstChild.value},
focus:function(e){}})}),e.attachEvent("onBeforeSectionRender",function(t,a,n){var i={};if("tree"==t){var r,o,l,d,_,s;d="dhx_matrix_scell",a.children?(r=n.folder_dy||n.dy,n.folder_dy&&!n.section_autoheight&&(l="height:"+n.folder_dy+"px;"),o="dhx_row_folder",d+=" folder",a.open?d+=" opened":d+=" closed",_="<div class='dhx_scell_expand'>"+(a.open?"-":"+")+"</div>",s=n.folder_events_available?"dhx_data_table folder_events":"dhx_data_table folder"):(r=n.dy,o="dhx_row_item",d+=" item",_="",
s="dhx_data_table"),d+=e.templates[n.name+"_scaley_class"](a.key,a.label,a)?" "+e.templates[n.name+"_scaley_class"](a.key,a.label,a):"";i={height:r,style_height:l,tr_className:o,td_className:d,td_content:"<div class='dhx_scell_level"+a.level+"'>"+_+"<div class='dhx_scell_name'>"+(e.templates[n.name+"_scale_label"](a.key,a.label,a)||a.label)+"</div></div>",table_className:s}}return i});var t;e.attachEvent("onBeforeEventChanged",function(a,n,i){
if(e._isRender("tree"))for(var r=e._get_event_sections?e._get_event_sections(a):[a[e.matrix[e._mode].y_property]],o=0;o<r.length;o++){var l=e.getSection(r[o]);if(l&&l.children&&!e.matrix[e._mode].folder_events_available)return i||(a[e.matrix[e._mode].y_property]=t),!1}return!0}),e.attachEvent("onBeforeDrag",function(a,n,i){if(e._isRender("tree")){var r,o=e._locate_cell_timeline(i);if(o&&(r=e.matrix[e._mode].y_unit[o.y].key,
e.matrix[e._mode].y_unit[o.y].children&&!e.matrix[e._mode].folder_events_available))return!1;var l=e.getEvent(a),d=e.matrix[e._mode].y_property;t=l&&l[d]?l[d]:r}return!0}),e._getArrayToDisplay=function(t){var a=[],n=function(t,i,r,o){for(var l=i||0,d=0;d<t.length;d++){var _=t[d];_.level=l,_.$parent=r||null,_.children&&void 0===_.key&&(_.key=e.uid()),o||a.push(_),_.children&&n(_.children,l+1,_.key,o||!_.open)}};return n(t),a},e._getArrayForSelect=function(t,a){var n=[],i=function(t){
for(var r=0;r<t.length;r++)e.matrix[a].folder_events_available?n.push(t[r]):t[r].children||n.push(t[r]),t[r].children&&i(t[r].children,a)};return i(t),n},e._toggleFolderDisplay=function(t,a,n){var i,r=function(e,t,a,n){for(var o=0;o<t.length&&(t[o].key!=e&&!n||!t[o].children||(t[o].open=void 0!==a?a:!t[o].open,i=!0,n||!i));o++)t[o].children&&r(e,t[o].children,a,n)},o=e.getSection(t);void 0!==a||n||(a=!o.open),
e.callEvent("onBeforeFolderToggle",[o,a,n])&&(r(t,e.matrix[e._mode].y_unit_original,a,n),e.matrix[e._mode].y_unit=e._getArrayToDisplay(e.matrix[e._mode].y_unit_original),e.callEvent("onOptionsLoad",[]),e.callEvent("onAfterFolderToggle",[o,a,n]))},e.attachEvent("onCellClick",function(t,a,n,i,r){e._isRender("tree")&&(e.matrix[e._mode].folder_events_available||void 0!==e.matrix[e._mode].y_unit[a]&&e.matrix[e._mode].y_unit[a].children&&e._toggleFolderDisplay(e.matrix[e._mode].y_unit[a].key))}),
e.attachEvent("onYScaleClick",function(t,a,n){e._isRender("tree")&&a.children&&e._toggleFolderDisplay(a.key)}),e.getSection=function(t){if(e._isRender("tree")){var a,n=function(e,t){for(var i=0;i<t.length;i++)t[i].key==e&&(a=t[i]),t[i].children&&n(e,t[i].children)};return n(t,e.matrix[e._mode].y_unit_original),a||null}},e.deleteSection=function(t){if(e._isRender("tree")){var a=!1,n=function(e,t){for(var i=0;i<t.length&&(t[i].key==e&&(t.splice(i,1),a=!0),!a);i++)t[i].children&&n(e,t[i].children)}
;return n(t,e.matrix[e._mode].y_unit_original),e.matrix[e._mode].y_unit=e._getArrayToDisplay(e.matrix[e._mode].y_unit_original),e.callEvent("onOptionsLoad",[]),a}},e.deleteAllSections=function(){e._isRender("tree")&&(e.matrix[e._mode].y_unit_original=[],e.matrix[e._mode].y_unit=e._getArrayToDisplay(e.matrix[e._mode].y_unit_original),e.callEvent("onOptionsLoad",[]))},e.addSection=function(t,a){if(e._isRender("tree")){var n=!1,i=function(e,t,r){
if(a)for(var o=0;o<r.length&&(r[o].key==t&&r[o].children&&(r[o].children.push(e),n=!0),!n);o++)r[o].children&&i(e,t,r[o].children);else r.push(e),n=!0};return i(t,a,e.matrix[e._mode].y_unit_original),e.matrix[e._mode].y_unit=e._getArrayToDisplay(e.matrix[e._mode].y_unit_original),e.callEvent("onOptionsLoad",[]),n}},e.openAllSections=function(){e._isRender("tree")&&e._toggleFolderDisplay(1,!0,!0)},e.closeAllSections=function(){e._isRender("tree")&&e._toggleFolderDisplay(1,!1,!0)},
e.openSection=function(t){e._isRender("tree")&&e._toggleFolderDisplay(t,!0)},e.closeSection=function(t){e._isRender("tree")&&e._toggleFolderDisplay(t,!1)}});