<%
	/**
	 * Created by The eXo Platform SARL
	 * Author : Tran The Trong
	 *          trongtt@gmail.com
	 * August 02, 2006
	 * version: $Id$
	 */
%>
<%
  import java.util.List;
  import java.util.ArrayList;
  import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorerPortlet;
  import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer;
  
  def uiPortlet = uicomponent.getAncestorOfType(UIJCRExplorerPortlet.class);
  def uiExplorer = uicomponent.getAncestorOfType(UIJCRExplorer.class);
  def uniqueId  = new Date().getTime();
  def rcontext = _ctx.getRequestContext() ;
	rcontext.getJavascriptManager().addOnLoadJavascript('eXo.ecm.ECMUtils.checkAvailableSpace');
  rcontext.getJavascriptManager().addOnLoadJavascript('eXo.ecm.ECMUtils.checkTabSize');
  def tabs = uicomponent.getTabList() ;
  def actionBarStyle = "";
  def displayTabContainer = "";
	List<String> tabAvailableList = new ArrayList<String>();
	for(tab in tabs) {
	  if(uicomponent.isActionAvailable(tab)) {
	    tabAvailableList.add(tab);       
	  }
	}
	if(tabAvailableList.size() < 2) {
    actionBarStyle = "UIActionBarAlone";
    displayTabContainer = "display: none;";
  }
%>

<%if (uiPortlet.isShowActionBar() && !uiExplorer.isAddingDocument()) {%>
<% uiform.begin() %>
<div class="UIActionBar $actionBarStyle" id="$uicomponent.id">
	<div class="UIHorizontalTabs">
		<div class="TabsContainer">
		  <div style="overflow: hidden; $displayTabContainer">
				<%
			    def isSelected = false;
					def selectedTab = uicomponent.getSelectedTab();
				  if(!tabAvailableList.contains(selectedTab) && tabAvailableList.size() > 0) {
						selectedTab = tabAvailableList.get(0);
						uicomponent.setSelectedTab(selectedTab);
					}
					for(tab in tabAvailableList) {
				    def tabStyle = "NormalActionBarTab";
				    if(selectedTab.equals(tab)) {
				      isSelected = true;
				      tabStyle = "SelectedActionBarTab";
				    }
				    String fullTabName = (String)_ctx.appRes(uicomponent.getId() + ".obtion." + tab);
				    String displayTabName = fullTabName;
				    if (fullTabName.length() > 13)
				    {
				      displayTabName = fullTabName.substring(0, 10) + "..."
				    } 
				%>
					    <div class="UITab" style="display: block;">
						    <div class="$tabStyle">
								  <div class="TabL">
								    <div class="TabR">
										  <div class="TabM" style="width: 125px;">
										    <a href="<%=uicomponent.event("ChangeTab", tab)%>" title="$fullTabName" class="TabLabel">$displayTabName</a>
										  </div>
								    </div>
								  </div>  
						    </div>
						  </div>
				<%
				  }
				%>
				<div class="CleanRTL"><span></span></div>
		  </div>
		 <%if(isSelected) {%>
		   <div id="DMSMenuItemContainer" class="DMSMenuItemContainer MenuItemContainer">
		   <%
		     for(button in uicomponent.getActionInTab(uicomponent.getSelectedTab())) {
		       def action = uicomponent.getUIAction(button);
				   if (action != null) {
				     def title = _ctx.appRes(uicomponent.getId() + ".tooltip." + button);
			 %>
						 <div class="NormalSubItem SubTabItem" style="width: auto;">
							 <div class="NormalSubTabItemL">
								 <div class="NormalSubTabItemR">
									 <div class="NormalSubTabItemM">
									 	<div class="Split">
										 	<a href="<%=action.event(button)%>" title="$title" class="SubTabIcon DefaultActionIcon ${button}Icon">$title</a>
										 </div>
									 </div>
								 </div>
							 </div>
						 </div>
				<%
					 }
				 }
				%>
				</div>
		 <%}%>
		</div>
  		<div class="UIViewBarContainer" id="UIViewBarContainer">
  		  <%
  		  if (uicomponent.hasBackButton()) {%>
  		  <a class ="URLBackToButton" href="<%=uicomponent.event("BackTo")%>"></a>
  		  <%}
 			  if(uicomponent.isShowSaveSession()) {%>
  	      <a class="SaveSessionButton" href="<%=uicomponent.event("SaveSession")%>" title="<%=_ctx.appRes("UIViewBar.label.saveSession")%>"></a>
  	    <%}%>  	      
  	    <a class="SetupPreferencesButton" href="<%=uicomponent.event("Preferences")%>" title="<%=_ctx.appRes("UIViewBar.label.setUpBrowser")%>"></a>
  	    
  			<div class="ClearRight"><span></span></div>
  		</div>
  		<div id="IconListHideElement" style="float:right; padding-top: 2px;" onclick="eXo.ecm.ECMUtils.showListHideElements(this,event);">
  			<a class="ListHideElementIcon"></a>
  			<div class="ListHideContainer" id="ListHideContainer" style="display:none">								
  			</div>
  		</div>
	</div>
</div>
<% uiform.end() %>
<% } else if (uicomponent.hasBackButton()) {%>
  <% uiform.begin() %>
    <div class="UIActionBar $actionBarStyle" id="$uicomponent.id">
      <div class="UIViewBarContainer" id="UIViewBarContainer">
        <a class ="URLBackToButton" style = "padding-top:28px!important" href="<%=uicomponent.event("BackTo")%>"></a>
      </div>
    </div>
  <% uiform.end() %>
<%}%>

		  

