<%
  /**
   * Created by The eXo Platform SARL
   * Author : Dang Van Minh
   *          minhdv@exoplatform.com
   * July 25, 2006
   * 8:16:23 AM
   */
%>
<%
  import org.exoplatform.ecm.webui.utils.Utils;
  import org.exoplatform.web.application.Parameter;
  import org.exoplatform.webui.core.UIRightClickPopupMenu;
  import org.exoplatform.services.jcr.util.Text;
  import org.exoplatform.ecm.webui.component.explorer.UIWorkingArea;
  import org.exoplatform.ecm.jcr.model.Preference;
  import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer;
  import org.exoplatform.services.jcr.RepositoryService;
  import org.apache.commons.lang.StringEscapeUtils;
  
  def uiWorkingArea = uicomponent.getAncestorOfType(UIWorkingArea.class);
  def uiExplorer = uicomponent.getAncestorOfType(UIJCRExplorer.class);
  def pref = uiExplorer.getPreference();
  def enableDragAndDrop = pref.isEnableDragAndDrop();
  
  UIRightClickPopupMenu contextMenu = uicomponent.getContextMenu();
  String componentId = uicomponent.getId();
  java.text.DateFormat dateFormat = uicomponent.getSimpleDateFormat();
  
  def viewComponentId  = new Date().getTime();
  def rcontext = _ctx.getRequestContext();
  rcontext.getJavascriptManager().importJavascript('eXo.ecm.UIListView','/ecmexplorer/javascript/');
  rcontext.getJavascriptManager().importJavascript('eXo.ecm.DMSBrowser','/ecm-wcm-extension/javascript/');
  rcontext.getJavascriptManager().addJavascript("eXo.ecm.UIListView.initAllEvent('${componentId}-$viewComponentId', '$enableDragAndDrop');");
%>
<div id="$componentId">
  <div id="${componentId}-$viewComponentId" class="UIListView" style="">  
    <div class="UIListGrid">
        <div class="TitleTable ClearFix">
          
          <%
            String typeSort = uicomponent.getTypeSort();
            String sortOrder = uicomponent.getSortOrder();
            String typeActionLink = "";
            if (sortOrder.equals("BlueDownArrow")) {
              typeActionLink = "Descending;";
            } else {
              typeActionLink = "Ascending;";
            }
          %>
          <% String actionURL = uicomponent.event("Sort", typeActionLink + "Type"); %>
          
          <div class="LeftColumn" onclick="$actionURL" style="float: left; width: 30px; height: 19px; cursor:pointer;">
            <%
              if (typeSort.equals("Type")) {
            %>
              <div class="SortButton ${sortOrder}16x16Icon" style="width: auto; padding-left: 20px; background-position: center center;">
                <span></span>
              </div>
            <%}%>
          </div>
          <div class="LineLeft"><span></span></div>
          <div class="RightColumn" style="border: none; width:80px;">
            <a href="<%=uicomponent.event("Sort", typeActionLink + "Auditing")%>">
              <%
                if (typeSort.equals("Auditing")) {
              %>
                <div class="SortButton ${sortOrder}16x16Icon" style="width: auto; padding-left: 20px;">
                  <%=_ctx.appRes("ListView.view.label.auditing")%>
                </div>
              <%} else { %>
                <%=_ctx.appRes("ListView.view.label.auditing")%>
              <%} %>
            </a>
          </div>
          <div class="LineLeft" style="float: right"><span></span></div>
          <div class="RightColumn" style="width:80px;">
            <a href="<%=uicomponent.event("Sort", typeActionLink + "Versionable")%>">
              <%
                if (typeSort.equals("Versionable")) {
              %>
                <div class="SortButton ${sortOrder}16x16Icon" style="width: auto; padding-left: 20px;">
                  <%=_ctx.appRes("ListView.view.label.versionable")%>
                </div>
              <%} else { %>
                <%=_ctx.appRes("ListView.view.label.versionable")%>
              <%} %>
            </a>
          </div>
          <div class="LineLeft" style="float: right"><span></span></div>
          <div class="RightColumn" style="width: 90px;">
            <a href="<%=uicomponent.event("Sort", typeActionLink + "Owner")%>">
              <%
                if (typeSort.equals("Owner")) {
              %>
                <div class="SortButton ${sortOrder}16x16Icon" style="width: auto; padding-left: 20px;">
                  <%=_ctx.appRes("ListView.view.label.exo_owner")%>
                </div>
              <%} else { %>
                <%=_ctx.appRes("ListView.view.label.exo_owner")%>
              <%} %>
            </a>
          </div>
          <div class="LineLeft" style="float: right"><span></span></div>
          <div class="RightColumn" style="width: 125px;">
            <a href="<%=uicomponent.event("Sort", typeActionLink + "ModifiedDate")%>">
              <%
                if (typeSort.equals("ModifiedDate")) {
              %>
                <div class="SortButton ${sortOrder}16x16Icon" style="width: auto; padding-left: 20px;">
                  <%=_ctx.appRes("ListView.view.label.exo_dateModified")%>
                </div>
              <%} else { %>
                <%=_ctx.appRes("ListView.view.label.exo_dateModified")%>
              <%} %>
            </a>
          </div>
          <div class="LineLeft" style="float: right"><span></span></div>
          <div class="RightColumn" style="width: 105px;">
            <a href="<%=uicomponent.event("Sort", typeActionLink + "CreatedDate")%>">
              <%
                if (typeSort.equals("CreatedDate")) {
              %>
                <div class="SortButton ${sortOrder}16x16Icon" style="width: auto; padding-left: 20px;">
                  <%=_ctx.appRes("ListView.view.label.exo_dateCreated")%>
                </div>
              <%} else { %>
                  <%=_ctx.appRes("ListView.view.label.exo_dateCreated")%>
              <%} %>
            </a>
          </div>
          <div class="LineLeft" style="float: right"><span></span></div>
          <div class="ResizeColumn" style="margin-right: 530px">
            <a href="<%=uicomponent.event("Sort", typeActionLink + "Alphabetic")%>">
              <%
                if (typeSort.equals("Alphabetic")) {
              %>
                <div class="SortButton ${sortOrder}16x16Icon" style="padding-left: 20px;">
                  <%=_ctx.appRes("ListView.view.label.name")%>
                </div>
              <%} else { %>
                <%=_ctx.appRes("ListView.view.label.name")%>
              <%} %>
            </a>
          </div>
          
        </div>
        <%          
          String portalName = uicomponent.getPortalName();
          RepositoryService rService = uicomponent.getApplicationComponent(RepositoryService.class);
          String repository = rService.getCurrentRepository().getConfiguration().getName();
          for(data in uicomponent.getChildrenList()) {
            def isPreferenceNode = uicomponent.isPreferenceNode(data);
            def preferenceWS = data.getSession().getWorkspace().getName();
            String nodePath = data.getPath();
            String name = nodePath.substring(nodePath.lastIndexOf("/") + 1, nodePath.length());   
            String title = uiWorkingArea.getTitle(data);            
            String subName;
             String hiddenStyle = (data.isNodeType("exo:hiddenable"))?"color: #A0A0A0;":"";
            //nodePath = nodePath + "&workspaceName=" + preferenceWS;
            String actionLink = uicomponent.event("ChangeNode",Utils.formatNodeName(data.path), new Parameter("workspaceName", preferenceWS));
        %>
        <div class="RowView Normal ClearFix" ondblclick="$actionLink">
          <div class="LeftColumn" style="float: left; width: 30px; height: 19px; padding: 2px 0px;  border-right: none;">
            <div title="$name" class="Icon16x16 default16x16Icon <%=Utils.getNodeTypeIcon(data, "16x16Icon")%>">              
            <%if(uicomponent.isSymLink(data)) {%>
                <div class="LinkSmall"></div>
              <%}%>
            </div>

          </div>
          <%
              if (title.length() < 50) subName = title;
              else subName = title.substring(0,50) + "...";
            %>
          <div class="RightColumn" style="border: none;width:84px;"><!--added CPop Bull SA -->
             <%= Utils.isAuditable(data)%>
             <% if (Utils.isAuditable(data)&& uicomponent.hasAuditHistory(data)) 
                  println "("+ uicomponent.getNumAuditHistory(data)+")";
                else
                  println ""; 
              %>
          </div>
          <div class="RightColumn" style="width:88px;">
              <%=Utils.isVersionable(data)%>
              <%
                if(Utils.isVersionable(data) && !uicomponent.getVersionName(data).equals("jcr:rootVersion")) {
                  println "(" + uicomponent.getVersionName(data) + ")";
                }
              %>
          </div>
          <div class="RightColumn" style="width: 97px">
            <%=uicomponent.getNodeOwner(data)%>
          </div>
          <div class="RightColumn" style="width: 131px">
            <%=dateFormat.format(uicomponent.getDateModified(data))%>
          </div>
         
          <div class="RightColumn" style="width: 112px;">
            <%=dateFormat.format(uicomponent.getDateCreated(data))%>
          </div>
          <div class="ResizeColumn" style="float:left; width: 113px; padding-left: 6px;$hiddenStyle;">
              <div class="NodeLabel">
                <div style="cursor: pointer; -moz-outline: none; -moz-user-select: none; white-space: nowrap; width:113px; overflow:hidden;" title="<%=title%>"><%=subName%></div>
              </div>
          </div>
          
        </div>
        <%}%>
    </div>
  </div>
  <% int availablePage = uicomponent.getContentPageIterator().getAvailablePage();
     if (availablePage > 1) { %>  
      <div class="PageAvailable" pageAvailable='$availablePage'>
        <%_ctx.renderUIComponent(uicomponent.getContentPageIterator())%>
      </div>
  <% } %>
</div>  