<%
  import org.exoplatform.ecm.webui.utils.Utils;
  import org.exoplatform.services.jcr.RepositoryService;
  
  def personalDrives = uicomponent.personalDrives();
  def groupDrives = uicomponent.groupDrives();
  def mainDrives = uicomponent.mainDrives();
  RepositoryService rService = uicomponent.getApplicationComponent(RepositoryService.class) ;
  String repository = rService.getCurrentRepository().getConfiguration().getName() ;    
%>
<div id="$uicomponent.id" class="UIDrivesArea">
	<div class="UIDriversAreaContainer">
    <% if (uicomponent.isFirstVisit()) {
        uicomponent.setFirstVisit(false); 
     %>
        <div class="Info" style="padding-left: 25px;font-size:12px;margin-bottom:12px">
          <%= _ctx.appRes("UIDrivesArea.DrivesArea.allDrives") %>
          &nbsp;<img alt="<%= _ctx.appRes("UIDrivesArea.DrivesArea.allDrives") %>" src="/ecmexplorer/skin/webui/component/explorer/sidebar/DefaultSkin/icons/DriversButton.png" />
        </div>
    <% } %>
	  <%if(mainDrives.size() > 0) {%>
			<div class="RowDrives ClearFix">
				<div class="IconArrowDrives TextTitleDriver"><%=_ctx.appRes("UIDrivesBrowser.title.GeneralDrives" )%></div>
				<%
				  for(drive in mainDrives) {
    				println("<div class=\"Drive\">");
    				if(drive.getIcon() != null && drive.getIcon().length() > 0) {
  	          String[] mainIconPath = drive.getIcon().split(":/") ;
  	    %>
  	          <div class="DriveIcon" onclick="<%=uicomponent.event("SelectDrive","${drive.name}")%>" title="${drive.name}">
    	          <img alt="${drive.name}" src="/${uicomponent.getPortalName()}/${uicomponent.getRestName()}/jcr/${repository}/${mainIconPath[0]}/${mainIconPath[1]}" width="27" height="27" onclick="<%=uicomponent.event("SelectDrive","${drive.name}")%>"/>
    	        </div>
		          <a class="DriveLabel" href="<%=uicomponent.event("SelectDrive", Utils.formatNodeName(drive.getName()))%>"><%=uicomponent.getLabel(drive.getName())%></a>
				<%
				    } else {
				%>
				      <div class="IconDrivesDefault IconDrives${drive.workspace} DriveIcon" onclick="<%=uicomponent.event("SelectDrive","${drive.name}")%>" title="<%=uicomponent.getLabel(drive.getName())%>">
				        <span></span>
			        </div>
 				      <a class="DriveLabel" href="<%=uicomponent.event("SelectDrive", Utils.formatNodeName(drive.getName()))%>"  title="<%=uicomponent.getLabel(drive.getName())%>">
 				        <%=uicomponent.getLabel(drive.getName())%>
			        </a>
				<%      
				    }
				    println("</div>");
				  }
				%>
			</div>
		<%}%>
		<%if(groupDrives.size() > 0) {%>
			<div class="RowDrives RowDrivesGroups ClearFix">
				<div class="IconArrowDrives TextTitleDriver"><%=_ctx.appRes("UIDrivesBrowser.title.GroupDrives" )%></div>
	        <%
	          for(groupDrive in groupDrives) {
	            println("<div class=\"Drive\">");
	            def groupLabel = uicomponent.getGroupLabel(groupDrive);
	  	        if(groupDrive.getIcon() != null && groupDrive.getIcon().length() > 0) {
		  		      String[] groupIconPath = groupDrive.getIcon().split(":/") ;
		      %>
			        <div class="Icon" onclick="<%=uicomponent.event("SelectDrive","${groupDrive.name}")%>" title="${groupDrive.name}">
			        	<img alt="${groupDrive.name}" src="/${uicomponent.getPortalName()}/rest/jcr/${repository}/${groupIconPath[0]}/${groupIconPath[1]}" width="48" height="41" />			                				                  
			        </div>
	        <%  } else {  %>
				        <div class="IconDrivesUse DriveIcon" onclick="<%=uicomponent.event("SelectDrive","${groupDrive.name}")%>" title="${groupLabel}"><span></span></div>
	  			      <a class="DriveLabel" href="<%=uicomponent.event("SelectDrive","${groupDrive.name}")%>" title="${groupLabel}">
	  			        ${groupLabel}
  			        </a>
		      <%
		          }
		          println("</div>");
		        }
		      %>
	      
			</div>
		<%}%>	
		<%if(personalDrives.size() > 0) {%>
			<div class="RowNormal ClearFix">
				<div class="IconArrowDrives TextTitleDriver"><%=_ctx.appRes("UIDrivesBrowser.title.PersonalDrives" )%></div>
        <%
          for(drive in personalDrives) {
	          println("<div class=\"Drive\">");
	          if(drive.getIcon() != null && drive.getIcon().length() > 0) {
	            String[] personalIconPath = drive.getIcon().split(":/") ;
	      %>
			        <div class="DriveIcon" onclick="<%=uicomponent.event("SelectDrive","${drive.name}")%>" title="${drive.name}">
			        	<img alt="${drive.name}" src="/${uicomponent.getPortalName()}/rest/jcr/${repository}/${personalIconPath[0]}/${personalIconPath[1]}" alt="" width="48" height="41" />			                				                			                  
			        </div>
	      <%  } else { %>
	            <div class="IconDrives${drive.name} DriveIcon" onclick="<%=uicomponent.event("SelectDrive","${drive.name}")%>" title="<%=uicomponent.getLabel(drive.getName())%>">
	              <span></span>
              </div>
  	          <a class="DriveLabel" href="<%=uicomponent.event("SelectDrive","${drive.name}")%>" title="<%=uicomponent.getLabel(drive.getName())%>">
  	            <%=uicomponent.getLabel(drive.getName())%>
	            </a>
        <%
            }
            println("</div>");
          }
        %>
	     
			</div>  
		<%}%>
	</div>
</div>