$.fn.WSTGridTree=function(k){var j=(new Date().getTime()+Math.round(Math.random()*700));var f={id:"wst_"+j,tbodyId:"wst_tbody_"+j,width:"100%",headerRowHeight:28,rowHeight:28,nodeNum:0,params:{},level:0};var a=$.extend(f,k);var i=$(this);var d;var c=function(){var o=[],l,p,m;o.push('<table class="mmg-head wst-grid-tree" cellspacing="0" cellpadding="0" width="'+a.width+'"><thead id="'+a.tbodyId+'" class="mmg-headWrapper"><tr height="'+a.headerRowHeight+'" class="mmg-head wst-grid-tree-hd">');if(a.rownumbers){o.push('<td class="wst-grid-tree-hd-cell first" style="width:26px;">#</td>')}for(var n=0;n<a.columns.length;n++){l=a.columns[n];m=l.width?('width="'+l.width+'"'):"";if(l.id){d=l.id;o.push('<td class="wst-grid-tree-hd-cell" style="text-align:left;padding-left:5px;" '+m+">"+l.display+"</td>")}else{p=(l.align?(' style="text-align:'+l.align+'" '):"");o.push('<td class="wst-grid-tree-hd-cell" '+p+" "+m+">"+l.display+"</td>")}}o.push("</tr></thead></table>");$(i).html(o.join(""))};var h=function(){var l=$.extend(a,{pid:a.tbodyId,params:{},level:0});b(l)};var b=function(l){$("tr[id^='"+a.pid+"_']").remove();$.getJSON(l.url,l.params,function(v,o){if(v.Rows){var x,r,m,p,y,q,n,w;v=v.Rows;var z=a.pid;for(var u=0;u<v.length;u++){m=v[u];n=l.pid+"_"+a.nodeNum;a.nodeNum++;x=[];x.push('<tr id="'+n+'" height="'+a.rowHeight+'" class="mmg mmg-body wst-grid-tree-row j-'+m[d]+'" dataid="'+m[d]+'" pdataid="'+n+'" lv="'+l.level+'">');if(a.rownumbers){x.push('<td class="wst-grid-tree-row-cell first"><label class="mmg-index" style="margin-right:0px">'+(u+1)+"</label></td>")}for(var t=0;t<a.columns.length;t++){r=a.columns[t];if(r.render){p=r.render(m)}else{p=m[r.name]}q=r.width?('width="'+r.width+'"'):"";if(r.id){w="";for(var s=0;s<l.level;s++){w+='<div class="wst-grid-tree-space"></div>'}w+='<div class="l-grid-tree-link fa fa-folder wst-tree-img" dataid="'+m[d]+'" pdataid="'+n+'" lv="'+l.level+'"></div>';x.push('<td class="wst-grid-tree-row-cell" style="text-align:left" '+q+">"+w+p+"</td>")}else{y=(r.align?(' style="text-align:'+r.align+'" '):"");x.push('<td class="wst-grid-tree-row-cell" '+y+" "+q+">"+p+"</td>")}}x.push("</tr>");$(x.join("")).insertAfter($("#"+z));z=n;$("#"+n+" .wst-tree-img").click(function(){if($(this).hasClass("fa-folder")){$(this).removeClass("fa-folder").addClass("fa-folder-open");if($("tr[id^='"+$(this).attr("pdataid")+"_']").size()==0){l.pid=$(this).attr("pdataid");l.params[d]=$(this).attr("dataid");l.level=parseInt($(this).attr("lv"),10)+1;b(l)}else{$("tr[id^='"+$(this).attr("pdataid")+"_']").each(function(){$(this).show()})}}else{$(this).removeClass("fa-folder-open").addClass("fa-folder");$("tr[id^='"+$(this).attr("pdataid")+"_']").each(function(){$(this).hide()})}g();e()})}g();e()}if(a.callback){a.callback()}})};var g=function(){var l=false;$(".wst-grid-tree-row").each(function(){$(this).removeClass("bg-color");if($(this).is(":visible")){if(l){$(this).addClass("bg-color")}l=!l;$(this).click(function(){$(this).addClass("row-selected").siblings().removeClass("row-selected");$(this).addClass("row-selected").siblings().each(function(){if($(this).hasClass("bg-color2")&&!$(this).hasClass("row-selected")){$(this).removeClass("bg-color2").addClass("bg-color")}})})}})};var e=function(){var l=1;$(".wst-grid-tree-row").each(function(){if($(this).is(":visible")){$(this).find(".l-grid-row-cell-rownumbers").html(l++)}})};c();h();return{reload:function(o){if(o&&o>0){var l=$(".j-"+o);var n={params:{}};n["pid"]=l.attr("id");n["params"][d]=o;n["level"]=parseInt(l.attr("lv"),10)+1;var m=$.extend(a,n);b(m)}else{h()}}}};