<%	
	import org.exoplatform.wcm.webui.toolbar.UIAdminToolbarPortlet;
	import org.exoplatform.web.application.JavascriptManager;
	import org.exoplatform.portal.mop.user.UserNavigation;
	import org.exoplatform.portal.webui.util.Util;
	import org.exoplatform.portal.webui.workspace.UIPortalApplication;
	import org.exoplatform.portal.webui.page.UIPage;
	import org.exoplatform.services.organization.User;
	import org.exoplatform.services.security.ConversationState;
	import org.exoplatform.web.CacheUserProfileFilter;

		
	def rcontext = _ctx.getRequestContext();
	
	JavascriptManager jsmanager = rcontext.getJavascriptManager();
	jsmanager.importJavascript('eXo.portal.UIPortalNavigation');
	jsmanager.importJavascript('eXo.portal.UIAdminToolbar');
	jsmanager.addCustomizedOnLoadScript('eXo.portal.UIAdminToolbar.onLoad("' + uicomponent.id + '");');
	
	String addPageLabel = _ctx.appRes("UIAdminToolbarPortlet.action.AddPage");	
	String editPageLabel = _ctx.appRes("UIAdminToolbarPortlet.action.EditPage");
	String editPortalLabel = _ctx.appRes("UIAdminToolbarPortlet.action.EditPortal");
	String editPageAndNaviLabel = _ctx.appRes("UIAdminToolbarPortlet.action.EditPageAndNavigation");
	String editSiteLayout = _ctx.appRes("UIAdminToolbarPortlet.action.EditSiteLayout");
	String editorLabel = _ctx.appRes("UIAdminToolbarPortlet.action.Editor");
	
	boolean userCouldEditNavigation = uicomponent.hasEditPermissionOnNavigation();
	boolean userCouldEditPage = uicomponent.hasEditPermissionOnPage();
	boolean userCouldEditPortal = uicomponent.hasEditPermissionOnPortal();
	
	UserNavigation selectedNav = uicomponent.getSelectedNavigation();
	if (selectedNav != null) {
		editorLabel = _ctx.appRes("UIAdminToolbarPortlet.action." + selectedNav.getKey().getTypeName() + ".Editor");
	}
	String accountSetting = "javascript:if(document.getElementById('UIMaskWorkspace')) ajaxGet(eXo.env.server.createPortalURL('UIPortal', 'AccountSettings', true));"
%>
<ul class="UIAdminToolbarPortlet UIHorizontalTabs" id="$uicomponent.id" >
	<li class="UITab NormalToolbarTab">
		<a class="EditorIcon TBIcon" href="#">$editorLabel</a>
		<ul class="MenuItemContainer" style="display:none;">
			<% if(userCouldEditNavigation){ %>
				<li class="MenuItem">	
					<a href="javascript:ajaxGet(eXo.env.server.createPortalURL('UIWorkingWorkspace', 'PageCreationWizard', true))" title="$addPageLabel" class="ItemIcon AddPageIcon">$addPageLabel</a>
				</li>
			<% } %>
			
			<% if(userCouldEditPage){ 
        UIPortalApplication portalApp = Util.getUIPortalApplication();
        UIPage uiPage = portalApp.findFirstComponentOfType(UIPage.class);//TODO: Find a better solution than this traversing
        String editPageRequest = "javascript:ajaxGet(eXo.env.server.createPortalURL('" + uiPage.getId() + "', 'EditCurrentPage', true))";
			  %>
				<li class="MenuItem">
					<a href="$editPageRequest" title="$editPageLabel" class="ItemIcon EditPageIcon">$editPageLabel</a>
				</li>
			<% } %>
			
			<% if(userCouldEditPortal){ %>
				<li class="MenuItem">	
					<a href="javascript:ajaxGet(eXo.env.server.createPortalURL('UIWorkingWorkspace', 'EditInline', true))" title="$editSiteLayout" class="ItemIcon EditSiteIcon">$editSiteLayout</a>
				</li>
			<% } %>
		</ul>
	</li>
</ul>