!function(a,b,c){"use strict";function d(a,e){var f=this;return e=e||{},e=b.extend({treeID:!1,minimumExpandLevel:2,selectNodeByKey:[],enableDragAndDrop:!0,onSelect:!1,onClick:!1,readOnly:!1,removeNodesByID:[],chooseNodeInForm:!1},e),f.options=e,f.$element=a,f._menuTemplate=c.template(d.getMenu()),f.setupTree(),f.setupTreeEvents(),f.$element}d.prototype={dragRequest:function(a,c,d){var e=c.parent.data.key;"over"==d&&(e=c.data.key),jQuery.fn.dialog.showLoader();var f=[{name:"sourceTreeNodeID",value:a.data.key},{name:"treeNodeParentID",value:e}],g=c.parent.getChildren();if(g)for(var h=0;h<g.length;h++){var i=g[h];f.push({name:"treeNodeID[]",value:i.data.key})}b.ajax({dataType:"json",type:"POST",data:f,url:CCM_TOOLS_PATH+"/tree/node/drag_request",success:function(a){ccm_parseJSON(a,function(){}),jQuery.fn.dialog.hideLoader()}})},setupTree:function(){var a=this,c=a.options,d={},e=!1,f={};if(f.treeID=c.treeID,c.chooseNodeInForm){switch(e=!0,c.chooseNodeInForm){case"single":d={checkbox:"dynatree-radio"};break;case"multiple":d={checkbox:"dynatree-checkbox"}}c.selectNodesByKey.length&&(f.treeNodeSelectedIDs=c.selectNodesByKey)}b(a.$element).dynatree({autoFocus:!1,cookieId:"ConcreteGroups",cookie:{path:CCM_REL+"/"},initAjax:{url:CCM_TOOLS_PATH+"/tree/load",type:"post",data:f},onLazyRead:function(b){a.reloadNode(b)},onSelect:c.onSelect,selectMode:"multiple"===c.chooseNodeInForm?3:1,checkbox:e,classNames:d,minExpandLevel:c.minimumExpandLevel,clickFolderMode:1,onPostInit:function(){var d=a.$element;if(c.removeNodesByID.length)for(var e=0;e<c.removeNodesByID.length;e++){var f=c.removeNodesByID[e],g=this.getNodeByKey(f);g&&g.remove()}if(c.readOnly&&d.dynatree("disable"),c.chooseNodeInForm){var h=d.dynatree("getTree");if(h=h.getSelectedNodes(),h[0]){var g=h[0];c.onSelect(!0,g)}}if(h){b.map(h,function(a){a.makeVisible()})}},onClick:function(d,e){if("expander"==d.getEventTargetType(e))return!0;if(c.chooseNodeInForm){var f=d.getEventTargetType(e);return"checkbox"==f||"title"==f?("title"==f&&d.select(!0),!0):!1}if(!d.getEventTargetType(e))return!1;if(!c.chooseNodeInForm&&"title"==d.getEventTargetType(e))if(c.onClick){if(!d.data.gID)return!1;c.onClick(d)}else{var g=a._menuTemplate({options:a.options,data:d.data});if(g){var h=new ConcreteMenu(b(d.span),{menu:g,handle:"none"});h.show(e)}}return!0},fx:{height:"toggle",duration:200},dnd:{onDragStart:function(a){return c.enableDragAndDrop?!0:!1},onDragStop:function(a){},autoExpandMS:1e3,preventVoidMoves:!0,onDragEnter:function(a,b){return!0},onDragOver:function(a,b,c){return a.parent.data.treeNodeID||"1"===a.data.treeNodeID?"over"!=c&&1==a.data.treeNodeID?!1:b.data.treeNodeID==a.data.treeNodeID?!1:a.data.treeNodeID||"after"!=c?a.isDescendantOf(b)?!1:!0:!1:!1},onDrop:function(b,c,d,e,f){c.move(b,d),a.dragRequest(c,b,d)}}})},setupTreeEvents:function(){},reloadNode:function(a,b){var c=this,d=(c.options,{url:CCM_TOOLS_PATH+"/tree/node/load",data:{treeNodeParentID:a.data.key},success:function(){b&&b()}});a.appendAjax(d)}},d.getMenu=function(){return'<div class="ccm-popover-page-menu popover fade" data-search-page-menu="<%=data.cID%>" data-search-menu="<%=data.cID%>"><div class="arrow"></div><div class="popover-inner"><ul class="dropdown-menu"><% if (data.canEditTreeNode && data.treeNodeTypeHandle == \'group\' && data.gID) { %><li><a href="'+CCM_DISPATCHER_FILENAME+'/dashboard/users/groups/-/edit/<%=data.gID%>">'+ccmi18n_groups.editGroup+'</a></li><% } %><% if (data.canEditTreeNodePermissions) { %><li><a class="dialog-launch" dialog-width="480" dialog-height="380" dialog-modal="true" dialog-title="Edit Permissions" href="'+CCM_TOOLS_PATH+'/tree/node/permissions?treeNodeID=<%=data.key%>">'+ccmi18n_groups.editPermissions+"</a></li><% } %></ul></div></div>"},b.fn.concreteGroupsTree=function(a){return b.each(b(this),function(c,e){new d(b(this),a)})},a.ConcreteGroupsTree=d}(this,$,_);