<%
import org.exoplatform.services.wcm.newsletter.NewsletterCategoryConfig;
import org.exoplatform.services.wcm.newsletter.NewsletterSubscriptionConfig;

if(uicomponent.userCode != null){
	uicomponent.setActionAgain();
}
%>
<div class="UINewsletterPortlet $uicomponent.id">
	<%uiform.begin()%>
		<div class="NewsletterBoxContent">
		<div class="ClearFix">
			<div class="UserName ClearFix" style="height:32px;width:auto;line-height:32px;width:auto;margin-bottom:7px;">
				<div class="LeftUserName" style="float:left; margin-left:18px;">
					<label for="inputEmail"><%=_ctx.appRes("UINewsletterViewerForm.title.userEmail")%></label>
				</div>
				<div class="RightUserName ClearFix" style="float:left;">
					<div class="Input" style="float:left;padding:0px 5px 0px 10px;">
						<%uicomponent.renderChild("inputEmail");%> 
						<a href="#" style="color:#0101FF;text-decoration:underline;font-weight:bold;"><%=uicomponent.userMail%></a>
					</div>
					<div class="buttonForget" style="float:left; margin-left:50px;">
						<%if (uicomponent.isUpdated == true) {%>
								<div class="UIAction"> 
				          <%String forgetAction = uicomponent.event("ForgetEmail") ;%>
				          <div class="ActionContainer">
			                  <a href="javascript:void(0);" onclick="$forgetAction" class="ActionButton LightBlueStyle">
			                  	<%=_ctx.appRes("UINewsletterViewerForm.action.ForgetEmail")%>
			                  </a>
				          </div>
				  		</div>
			  			<%}%>
					</div>
					
				</div>
				
			</div>
			</div>
		<%for(NewsletterCategoryConfig category in uicomponent.getListCategories()){%>
			<div class="UICategories" style="width:auto;">
				<div style="width:auto;">
					<!-- Category infor -->
					<div class="CategoryTitle ClearFix">
						<div class="LeftTitle">
							<div class="RightTitle">
								<div class="CenterTitle">
									<a class="IconCategory" href="javaScript:void(0);"><%=category.getTitle()%></a>
								</div>
							</div>
						</div>
						<%
							def categoryDescription = category.getDescription();
							if (categoryDescription == null) categoryDescription = "";
						%>
						<div style="float:left;line-height:26px;padding-left:10px">$categoryDescription</div>
					
					</div>
					<!-- All subscriptions -->
					<div class="Subscriptions">
						<table cellpadding="5" cellspacing="0" border="0">
							<tr>
								<th class="Title">
									<%=_ctx.appRes("UINewsletterViewerForm.title.subscription")%>
								</th>
								<th class="Title" style="border-right:none;width:100px; white-space:nowrap; padding-left:5px; padding-right:5px;">
									<%=_ctx.appRes("UINewsletterViewerForm.title.yourStatus")%>
								</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>
												<div class="SubscriptionTitle"><%=subScription.getTitle()%></div>
												<div class="SubscriptionDescription">
												<%
													def subscriptionDescription = subScription.getDescription();
													if (subscriptionDescription == null) subscriptionDescription = "";
												%>
												$subscriptionDescription
												</div>
											</td>
											<td style="border:none;text-align:center;">
												<%
													uicomponent.renderChild(category.getName() + "#" + subScription.getName());
												%>
											</td>
										</tr>
							<%	}
								}else{%>
									<tr class="OddRow">
										<td colspan="2"><span></span></td>
									</tr>
							<%}%>
						</table>
					</div>
				</div>
			</div>
		<%}%>
		</div>
		
		<div class="UIAction"> 
          <%
          for(action in uicomponent.getActions()) { 
      			if ("ForgetEmail".equals(action)) continue;
          	String actionLabel = _ctx.appRes(uicomponent.getName() + ".action." + action); 
	    			String link = uicomponent.event(action) ;
          %>
          <a href="javascript:void(0);" onclick="$link" class="ActionButton LightBlueStyle">$actionLabel</a>
      		<%}%>
	  </div>
	  <%uicomponent.userCode = null;%>
	<%uiform.end()%>
</div>
