(function(){"use strict";var n=nspace("kd.components.navtree");n.NavigationTreeModel=Backbone.Model.extend({})})(jQuery),function(n){"use strict";var t=nspace("kd.components.navtree"),i=nspace("kd.events").EventNames.route.hydrate.name;t.NavigationTreeView=Backbone.View.extend({initialize:function(t){var r,f,e,s,u,o;if(_.bindAll(this,"expandAll","collapseAll","updateExpandCollapse"),r=t.keys,r)for(this.keys=r,f=0;f<r.length;f++)e=r[f],s=n("dt[data-entity="+e+"].show",n(this.el)).map(function(){return n(this).attr("data-id")}).toArray(),this.model.set(e,s);if(u=t.helper,!!u){this.helper=u;n("body").on("click",u+" .expand",this.expandAll);n("body").on("click",u+" .collapse",this.collapseAll)}o=t.prefix,!o||(this.prefix=o),this.updateExpandCollapse(),this.model.bind(i,this.hydrateView,this),this.initialRenderPromise.resolve()},initialRenderPromise:n.Deferred(),getInitialRenderPromise:function(){return this.initialRenderPromise.promise()},keys:[],hydrateView:function(){for(var f=n(this.el),e=this.keys,i,r,u,o,s,t=0;t<e.length;t++)for(i=e[t],r=this.model.get(i),r.length>0&&n("dt[data-entity="+i+"]:has(.title)",f).removeClass("show"),u=0;u<r.length;u++)o=r[u],s=n("dt[data-entity="+i+"][data-id="+o+"]",f),s.addClass("show");this.updateExpandCollapse()},events:{"click .title":"toggleBranch"},toggleBranch:function(t){var l=n(t.currentTarget),r=l.parent("dt"),u=r.attr("data-entity"),h=r.data("id"),i,o,e,f,c,s;if(this.prefix&&(u=this.prefix+u),i={},i[u]=(this.model.get(u)||[]).slice(0),r.hasClass("show"))for(i[u].splice(i[u].indexOf(h),1),o=r.find("~ dd:first").find("dt:has(.title)").removeClass("show").map(function(){return{entity:this.prefix?this.prefix+n(this).attr("data-entity"):n(this).attr("data-entity"),id:n(this).data("id")}}).toArray(),e=0;e<o.length;e++)f=o[e].entity,c=o[e].id,typeof i[f]=="undefined"&&(i[f]=(this.model.get(f)||[]).slice(0)),i[f].splice(i[f].indexOf(c),1);else i[u].push(h);this.model.set(i),r.toggleClass("show"),this.updateExpandCollapse(),s=navigator.userAgent.match(/(msie)\/?\s*(\.?\d+(\.\d+)*)/i),s&&s[1]&&parseFloat(s[2])<=8&&(r.hide(),r.show())},collapseAll:function(t){var i,c,r,u,f,e,o,v,s,a,h;if(t.preventDefault(),i=n(this.el),window.location.href.indexOf("/region")>1){for(c=this.keys,r=0;r<c.length;r++)for(u=c[r],f=this.model.get(u),f.length>0&&n("dt[data-entity="+u+"]:has(.title)",i).removeClass("show"),e=0;e<f.length;e++)o=f[e],(o==5||o==1)&&(v=n("dt[data-entity="+u+"][data-id="+o+"]",i),v.addClass("show"));this.updateExpandCollapse();return}var y=this,l={},p=n("dt:has(.title)",i).removeClass("show").map(function(){return y.prefix?y.prefix+n(this).attr("data-entity"):n(this).attr("data-entity")}).toArray();for(s=0;s<p.length;s++)a=p[s],typeof l[a]=="undefined"&&(l[a]=[]);this.updateExpandCollapse(),this.model.set(l),h=navigator.userAgent.match(/(msie)\/?\s*(\.?\d+(\.\d+)*)/i),h&&h[1]&&parseFloat(h[2])<=8&&setTimeout(function(){document.body.className=document.body.className},200)},expandAll:function(t){var u,i,f;t.preventDefault();var s=n(this.el),e=this,r={},o=n("dt:has(.title)",s).addClass("show").map(function(){return{entity:e.prefix?e.prefix+n(this).attr("data-entity"):n(this).attr("data-entity"),id:n(this).data("id")}}).toArray();for(u=0;u<o.length;u++)i=o[u],typeof r[i.entity]=="undefined"&&(r[i.entity]=[]),r[i.entity].push(i.id);this.model.set(r),this.updateExpandCollapse(),f=navigator.userAgent.match(/(msie)\/?\s*(\.?\d+(\.\d+)*)/i),f&&f[1]&&parseFloat(f[2])<=8&&setTimeout(function(){document.body.className=document.body.className},400)},updateExpandCollapse:function(){var i=n(this.el),r=n("dt:has(.title).show",i).length,u=n("dt:has(.title):not(.show)",i).length,f=u>0,e=r>0,t=n(this.helper);t.removeClass("expandable collapsible"),f&&t.addClass("expandable"),e&&t.addClass("collapsible")}})}(jQuery),function(){var n=nspace("kd.components.navtree"),t=nspace("kd.events").EventNames.route.hydrate.name;n.NavigationTreeRouter=Backbone.Router.extend({initialize:function(n){var t,i;if(!n.treeEl)throw"treeEl is required";else this.treeEl=$(n.treeEl);if(t=n.keys,!t)throw"keys are required";else this.keys=typeof t=="string"?t.split(","):t;i=n.helper,!i||(this.helper=i),_.bindAll(this)},routes:{"(:expandedNodes)":"initializeViews"},initializeViews:function(i){var r=this,u;r.model=new n.NavigationTreeModel,r.views={navTreeView:new n.NavigationTreeView({model:this.model,el:this.treeEl,keys:this.keys,helper:this.helper})},u=_(r.views).filter(function(n){return!!n.getInitialRenderPromise}).map(function(n){return n.getInitialRenderPromise()}).value(),$.when.apply(this,u).done(function(){for(var e=velir.collections.NameValueCollection.parseQueryString(i),s=e.getKeys(),u,h,o,f,c,n=0;n<s.length;n++)(u=s[n],h=e.getValue(u),h)&&r.model.set(u,e.getValue(u).split(","));for(o=r.keys,f=0;f<o.length;f++)c=o[f],r.model.bind("change:"+c,r.updateRoute);r.model.trigger(t)})},updateRoute:function(){for(var r=this.keys,u=new velir.collections.NameValueCollection,i,t,n=0;n<r.length;n++)i=r[n],t=this.model.get(i),!!t&&t.length>0&&u.add(i,t.join(","));this.navigate(u.toQueryString(),{replace:!0})}})}()