<%
  def rcontext = _ctx.getRequestContext() ;
	def jsManager = rcontext.getJavascriptManager(); 
	jsManager.importJavascript('eXo.wcm.backoffice.private.Newsletter','/eXoWCMResources/javascript/');
%>
<%
import org.exoplatform.services.wcm.newsletter.NewsletterSubscriptionConfig;
import org.exoplatform.webui.core.UIComponent;
%>
<%
if(uicomponent.categoryConfig != null){
def categoryTitle = uicomponent.categoryConfig.getTitle();
if(categoryTitle != null && categoryTitle.length() > 30)
  categoryTitle = categoryTitle.substring(0,30);
%>
<%uiform.begin()%>
<div class="UINewsletterPortlet" id="$uicomponent.id">
	<div class="NewsletterBoxContent">
		<div class="BreadCumbs">
			<a class="Selected" href="javaScript:void(0);" onclick="<%=uicomponent.event("BackToCategories")%>">
				<%=_ctx.appRes("NewsletterPortlet.title.newsletter")%>
			</a>
			>
			<a title="<%=uicomponent.categoryConfig.getTitle()%>" class="UnSelected"><%=categoryTitle%></a>
		</div>
		
		<%
		if(uicomponent.isAdministrator() || uicomponent.isModerator()){%>
			<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>
					</div>
				</div>
			</div>
		<%
		}else{%>
			<div style="margin-top: 20px;"><span></span></div>
	<%}%>
		
		
		<div class="UICategories">
			<div style="width:100%;">
				<!-- Category infor -->
				<div class="CategoryTitle ClearFix">
					<div class="LeftTitle">
						<div class="RightTitle">
							<div class="CenterTitle">
								<div class="IconCategory" style="max-width:350px; overflow:hidden;" title="<%=uicomponent.categoryConfig.getTitle()%>"><%=uicomponent.categoryConfig.getTitle()%></div>
							</div>
						</div>
					</div>
					<%
						def categoryDescription = uicomponent.categoryConfig.getDescription();
						if (categoryDescription == null) categoryDescription = "";
						if (categoryDescription.length() > 30) categoryDescription = categoryDescription.substring(0, 30) + " ...";
					%>
					<div title="<%=uicomponent.categoryConfig.getDescription()%>" style="float:left;line-height:26px;padding-left:10px">$categoryDescription</div>
						<!-- ----------------------------------- Button -------------------------------------------------- -->
						<div class="UIAction" style="float:right; padding:0px 10px; width: 120px;"> 
					          	  	
							<div class="ContentAction ActionTitle" style="float:right;" onclick="eXo.ecm.NewsletterManager.show(this, event);">
								<!-- action of this category -->
								<div class="Line" style="background: none;" onclick="eXo.ecm.NewsletterManager.show(this, event);">
									<a href="#" onclick="javaScript:void(0);" class="NewsAdmin ActionButton LightBlueStyle"><%=_ctx.appRes("UICategories.title.Administration")%></a>
									<div style="position:absolute;">
										<div class="UIPopupCategory" style="display:none; text-align:left; top: -2px;">
											<div class="UIRightClickPopupMenu UINewLetterPopup" style="display:block;min-width:130px;">
												<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">
																<!-- Detail action -->
																<%
																if(uicomponent.isAdministrator() || uicomponent.isModerator()){%>
																	<div class="MenuItem" onclick="<%=uicomponent.event("EditCategory")%>">
																		<div class="ItemIcon Pencil" style="padding-left:30px;">
																			<a href="javaScript:void(0)"><%=_ctx.appRes("UISubscription.title.EditCategory")%></a>
																		</div>
																	</div>
																	<% 
																	if(uicomponent.isAdministrator()){
																	%>
																		<div class="MenuItem" onclick="javaScript:if (confirm('<%=_ctx.appRes("UISubscription.msg.confirmDeleteCategory")%>')) <%=uicomponent.event("DeleteCategory")%>">
																			<div class="ItemIcon Remove16x16Icon" style="padding-left:30px;">
																				<a href="javaScript:void(0)">
																					<%=_ctx.appRes("UISubscription.title.DeleteCategory")%>
																				</a>
																			</div>
																		</div>
																	<%
																	}%>
																	<div><hr></div>
																<%}%>
																<div class="MenuItem" onclick="<%=uicomponent.event("OpenSubscription")%>">
																	<div class="ItemIcon openFolder" style="padding-left:30px;">
																		<a href="javaScript:void(0)">
																			<%=_ctx.appRes("UISubscription.title.Open")%>
																		</a>
																	</div>
																</div>
																<div class="MenuItem" onclick="<%=uicomponent.event("EditSubscription")%>">
																	<div class="ItemIcon Pencil" style="padding-left:30px;">
																		<a href="javaScript:void(0)">
																			<%=_ctx.appRes("UISubscription.title.Edit")%>
																		</a>
																	</div>
																</div>
																<%
																if(uicomponent.isAdministrator() || uicomponent.isModerator()){%>
																	<div class="MenuItem" onclick="javaScript:if(eXo.ecm.NewsletterManager.checkBeforeDelete('UISubscriptions', '<%=_ctx.appRes("UISubscription.msg.checkOnlyOneSubScriptionToDelete")%>', '<%=_ctx.appRes("UISubscription.msg.confirmDeleteSubscription")%>')) <%=uicomponent.event("DeleteSubscription")%>">
																		<div class="ItemIcon Remove16x16Icon" style="padding-left:30px;">
																			<a href="javaScript:void(0)">
																				<%=_ctx.appRes("UISubscription.title.Delete")%>
																			</a>
																		</div>
																	</div>
																	<div><hr></div>
																	<div class="MenuItem" onclick="<%=uicomponent.event("ManagerUsers")%>">
																		<div class="ItemIcon SmallGroup16x16Icon" style="padding-left:30px;">
																			<a href="javaScript:void(0)">
																				<%=_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>
						<!-- end action of this category -->
					
				</div>
				<!-- All subscriptions -->
				<%List<NewsletterSubscriptionConfig> listSubscriptions = uicomponent.getListSubscription(); %>
				<div class="Subscriptions">
					<table cellpadding="5" cellspacing="0" border="0">
						<tr>
							<th class="Title" style="width:auto; overflow: hidden; max-width: 500px;" 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">
								<%=_ctx.appRes("UICategories.title.AWaitingLetter")%>
							</th>
							<th class="thContent Title" style="border-right:none;">
								<%
								UIComponent child = uicomponent.getChildById("UISubscriptionsCheckAll");
								if (child != null) {
								    uicomponent.renderChild("UISubscriptionsCheckAll")
								}
								%>
							</th>
						</tr>					
						<%
							if(listSubscriptions != null && 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: 500px;">
											<a href="<%=uicomponent.event("SelectSubscription", subScription.getName())%>" title="<%=subScription.getTitle()%>">
												<%=subScription.getTitle()%>
											</a>
										</td>
										<td class="tdContent">
											<%=uicomponent.getNumberOfUser(subScription.getName())%>
										</td>
										<td class="tdContent">
											<%=uicomponent.getNumberOfWaitingNewsletter(subScription.getName())%>
										</td>
										<td class="tdContent" style="border: none;">
											<%uicomponent.renderChild(subScription.getName())%>
										</td>
									</tr>
						<%	}
							}else{%>
								<tr class="OddRow">
									<td colspan="3"><span></span></td>
								</tr>
						<%}%>
					</table>
				</div>
			</div>
		</div>
	
	</div>
</div>
<%uiform.end()%>	
<%
}%>
