<%
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 FloatLeft">
								<a href="javaScript:void(0);" onclick="<%=uicomponent.event("AddEntry")%>" class="Newsletter">
									<%=_ctx.appRes("UICategories.title.NewsLetter")%>
								</a>
							</div>
							<div class="Line FloatLeft">
								<a href="javaScript:void(0);" onclick="<%=uicomponent.event("AddSubcription")%>" class="NewsSubcript">
									<%=_ctx.appRes("UICategories.title.NewsSubscription")%>
								</a>
							</div>
							<div class="Line FloatLeft">
								<a href="javaScript:void(0);" onclick="<%=uicomponent.event("AddCategory")%>" class="NewsCategory">
									<%=_ctx.appRes("UICategories.title.NewsCategory")%>
								</a>
							</div>
							<div class="Line FloatLeft">
								<a href="javaScript:void(0);" onclick="<%=uicomponent.event("ManagerUsers")%>" class="NewsAdmin">
									<%=_ctx.appRes("UISubscription.title.ManageUsers")%>
								</a>
							</div>
							<!-- action of this category -->
							<!-- WE COMMENT THIS PART UNTIL WCM 1.3 with NEWSLETTER V2 IMPROVMENTS
							<div class="Line FloatLeft" style="background: none;" onclick="eXo.webui.UIPopupSelectCategory.show(this, event);">
								<a href="#" class="NewsAdmin"><%=_ctx.appRes("UICategories.title.Administration")%></a>
								<div style="position:relative;">
									<div class="UIPopupCategory" style="display:none; left:2px; top:-2px; ">
										<div class="UIRightClickPopupMenu UINewLetterPopup" style="display:block;">
											<div class="UIContextMenuContainer BorderOutline">											
												<div class="TopLeftRightClickPopupMenu">
													<div class="TopRightRightClickPopupMenu ">
														<div class="TopCenterRightClickPopupMenu"><span></span></div>
													</div>
												</div>
												<div class="MiddleLeftRightClickPopupMenu">
													<div class="MiddleRightRightClickPopupMenu">
														<div class="UIRightPopupMenuContainer" style="background: none;margin: 0px; padding-left: 8px; padding-right: 8px;">
															<!-- Detail action -- >
															<div class="MenuItem" onclick="javaScript:void(0)">
																<div class="ItemIcon BlueActionWheel" style="padding-left:30px;">
																	<a href="javaScript:void(0);"><%=_ctx.appRes("NewsletterPortlet.title.Preferences")%></a>
																</div>
															</div>
															<div><hr></div>
															<div class="MenuItem" onclick="javaScript:void(0)">
																<div class="ItemIcon Pencil" style="padding-left:30px;">
																	<a href="javaScript:void(0);"><%=_ctx.appRes("UISubscription.title.Edit")%></a>
																</div>
															</div>
															<div class="MenuItem" onclick="javaScript:void(0)">
																<div class="ItemIcon Remove16x16Icon" style="padding-left:30px;">
																	<a href="javaScript:void(0);"><%=_ctx.appRes("UISubscription.title.Delete")%></a>
																</div>
															</div>
															<div class="MenuItem" onclick="javaScript:void(0)">
																<div class="ItemIcon SmallGroup16x16Icon" style="padding-left:30px;">
																	<a href="<%=uicomponent.event("ManagerUsers")%>"><%=_ctx.appRes("UISubscription.title.ManageUsers")%></a>
																</div>
															</div>
															<!-- Finish detail action -- >
														</div>
													</div>
												</div>
												<div class="BottomLeftRightClickPopupMenu PopupRightBg">
													<div class="BottomRightRightClickPopupMenu ">
														<div class="BottomCenterRightClickPopupMenu"><span></span></div>
													</div>
												</div>
											</div>
										</div>
									</div>
								</div>
							</div>
							-->
							<!-- end action of this category -->
						</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">
							<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 class="ClearLeft"><span></span></div>
						</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>
