<%
import org.exoplatform.services.wcm.newsletter.NewsletterCategoryConfig;
import org.exoplatform.services.wcm.newsletter.NewsletterSubscriptionConfig;
import java.util.ArrayList;
import java.util.List;
//import org.exoplatform.web.application.JavascriptManager;
//def rcontext = _ctx.getRequestContext();
//JavascriptManager jsmanager = rcontext.getJavascriptManager();
//jsmanager.importJavascript('eXo.newsletterManager.UINewsletterManagerPortlet','/newsletter/javascript/');
%>

<div class="UINewsletterPortlet" id="$uicomponent.id">
	<div class="NewsletterBoxContent">
		<div class="BreadCumbs">
			<a href="#" class="Selected"><%=_ctx.appRes("NewsletterPortlet.title.newsletter")%></a>
		</div>
		<%
		if(uicomponent.isAdministrator()){
		%>
			<div class="LeftActionBar">
				<div class="RightActionBar">
					<div class="CenterActionBar">
						<div class="NewsletterActionBar">			
							<div class="Line FL">
								<a href="javaScript:void(0);" onclick="<%=uicomponent.event("AddEntry")%>" class="Newsletter">
									<%=_ctx.appRes("UICategories.title.NewsLetter")%>
								</a>
							</div>
							<div class="Line FL">
								<a href="javaScript:void(0);" onclick="<%=uicomponent.event("AddSubcription")%>" class="NewsSubcript">
									<%=_ctx.appRes("UICategories.title.NewsSubscription")%>
								</a>
							</div>
							<div class="Line FL">
								<a href="javaScript:void(0);" onclick="<%=uicomponent.event("AddCategory")%>" class="NewsCategory">
									<%=_ctx.appRes("UICategories.title.NewsCategory")%>
								</a>
							</div>
							<div class="Line FL">
								<a href="javaScript:void(0);" onclick="<%=uicomponent.event("ManagerUsers")%>" class="NewsAdmin">
									<%=_ctx.appRes("UISubscription.title.ManageUsers")%>
								</a>
							</div>
						</div>
					</div>
				</div>
			</div>
		<%
		}else{%>
			<div style="margin-top: 20px;"><span></span></div>
	<%}%>
	
	<%List listCategories = uicomponent.getListCategories();
		if(listCategories != null && !listCategories.isEmpty()){
			for(NewsletterCategoryConfig category in listCategories){%>
				<div class="UICategories">
					<div style="width:100%;">
						<!-- Category infor -->
						<div class="CategoryTitle ClearFix">
							<div class="LeftTitle">
								<div class="RightTitle">
									<div class="CenterTitle" style="max-width:350px; overflow:hidden;">
										<a title="<%=category.getTitle()%>" class="IconCategory" href="<%=uicomponent.event("OpenCategory", category.getName())%>"><%=category.getTitle()%></a>
									</div>
								</div>
							</div>
							<%
								def categoryDescription = category.getDescription();
								if (categoryDescription == null) categoryDescription = "";
								if (categoryDescription.length() > 30) categoryDescription = categoryDescription.substring(0, 30) + " ...";
							%>
							<span title="<%=category.getDescription()%>" style="line-height:26px;padding-left:10px">$categoryDescription</span>
							
						</div>
						<!-- All subscriptions -->
						<div class="Subscriptions">
							<table cellpadding="5" cellspacing="0" border="0">
								<tr>
									<th class="Title" style="width:auto; overflow: hidden; max-width: 350px;" title="<%=_ctx.appRes("UICategories.title.SubScription")%>">
										<%=_ctx.appRes("UICategories.title.SubScription")%>
									</th>
									<th class="thContent Title">
										<%=_ctx.appRes("UICategories.title.NumberOfUser")%>
									</th>
									<th class="thContent Title" style="border-right:none">
										<%=_ctx.appRes("UICategories.title.AWaitingLetter")%>
									</th>
								</tr>
								<%List<NewsletterSubscriptionConfig> listSubscriptions = uicomponent.getListSubscription(category.getName());
									if(listSubscriptions.size() > 0){
										int i = 0;
										String classTr = "";
										for(NewsletterSubscriptionConfig subScription in listSubscriptions){
											if(i % 2 == 0) classTr = "OddRow";
											else classTr = "EvenRow";
											i ++;
										%>
											<tr class="$classTr">
												<td style="width:auto; overflow: hidden; max-width: 350px;"><a title="<%=subScription.getTitle()%>" href="<%=uicomponent.event("SelectSubscription", category.getName() + "/" + subScription.getName())%>"><%=subScription.getTitle()%></a></td>
												<td class="tdContent">
													<%=uicomponent.getNumberOfUser(category.getName(), subScription.getName())%>
												</td>
												<td class="tdContent" style="border:none;">
													<%=uicomponent.getNumberOfWaitingNewsletter(category.getName(), subScription.getName())%>
												</td>
											</tr>
								<%	}
									}else{%>
										<tr class="OddRow">
											<td colspan="3"><span></span></td>
										</tr>
								<%}%>
							</table>
						</div>
					</div>
				</div>
	<%	}
		} else {%>
			<div><span></span></div>
	<%}%>
	
	</div>	
</div>
