<% 
	import org.exoplatform.web.application.JavascriptManager;
	import org.exoplatform.faq.service.Question;
	import org.exoplatform.faq.webui.ValidatorDataInput;
	import org.exoplatform.faq.service.FileAttachment;
	import org.exoplatform.faq.webui.FAQUtils;
	import org.exoplatform.faq.service.Answer;
	import org.exoplatform.faq.service.Comment;
	def rcontext = _ctx.getRequestContext() ;
  JavascriptManager jsmanager = rcontext.getJavascriptManager();
	jsmanager.addOnResizeJavascript('eXo.faq.UIAnswersPortlet.reSizeImagesView');
	jsmanager.addJavascript("eXo.faq.UIAnswersPortlet.reSizeImagesView();");
 %>
<div class="UIPopupViewQuestion">
	<% uiform.begin() %>
	<%uicomponent.renderChildren() ;%>
	<div class= "ViewQuestion">
		<table class="UIFormGridTableForm">
			<tbody>
				<tr>
					<td>
				<% 
 						Question question = uicomponent.getViewQuestion() ; 
						String qId = question.getId();
						String content = question.getQuestion() ;
						String responseBy = "" ;
						String date = "" ;
						String response = "<center><b>" + _ctx.appRes("UIPopupViewQuestion.title.not-answer")+ "</center></b>" ;
				%>
				<div class="ResponseContent">
					<div style="width:97%;"><b><%=_ctx.appRes("UIPopupViewQuestion.label.QuestionContent")%> : </b></div>
					<div class="Response" style="width:97%;">$content</div>
					<% 
					if(question.getAnswers() != null && question.getAnswers().length > 0) {
							for(Answer answer in question.getAnswers()) {
								responseBy = answer.getResponseBy();
							 	date = FAQUtils.getShortDateFormat(answer.getDateResponse());
								response = uicomponent.renderAnswer(answer);
								%> 
								<div style="width:97%;"><b><%=_ctx.appRes("UIPopupViewQuestion.label.QuestionResponsedContent")%> : </b></div>
								<div class="Response" id="SetWidthImageContent" style="width:97%;">$response</div>
								<div class=" ResponsActions">
									<div style="margin-left:10px; color:gray;"><%= _ctx.appRes("UIPopupViewQuestion.label.response-by"); %>
										<span>$responseBy , $date</span>
									</div>
								</div>
								<%
							}
						}
					 %>
					<%
					if(!question.getAttachMent().isEmpty()) {
					%>
					<div style="width:97%;"><b><%=_ctx.appRes("UIPopupViewQuestion.label.file-attached"); %></b></div>
					<div class="AttachmentContent">
						<div style="margin-top:5px; margin-bottom:5px;">
							<%
								for(FileAttachment fileAttachment : question.getAttachMent()){
							    String fileName = fileAttachment.getName() ;
							    long fileSize = fileAttachment.getSize() ;
							    if(fileSize > 0){
							    	String size = uicomponent.convertSize(fileSize);
								    String dataPath = "" ;
								    String fileStream = "" ;
								    try{
								      dataPath = fileAttachment.getDataPath() ;
								      fileStream = fileAttachment.getInputStream() ;
								    } catch(Exception e) {
								    	dataPath = "null" ;
								      fileStream = "null" ;
								    }
								    String fileType = fileAttachment.getMimeType() ;
								    String fileWorkSpace = fileAttachment.getWorkspace() ;
								    ValidatorDataInput validate = new ValidatorDataInput() ;
							    	String linkImage = FAQUtils.getFileSource(fileAttachment) ;
							    	String typeFileIcon = fileAttachment.getMimeType().substring((fileAttachment.getMimeType().indexOf("/")+1));
								    if(validate.isImage(fileName)) {
								      String attLink = uicomponent.getImageUrl(fileAttachment.getPath());
							    %>
							    	<div  style="float:left; margin-left:5px;" id="divId${fileName}">
								    	<div class="Image">
								    		<div onclick="eXo.faq.UIAnswersPortlet.showPicture('$attLink');" style="cursor:pointer">
													<img id="imgView${fileName}" src="$attLink" width="100" height="100" class="AttachmentFile" alt=""/>
												</div>
								    	</div>
					 						<div style="clear:left;"><span></span></div>
					 						<div class="LabelBox">
						 						<div style="line-height:20px;">
							 						<div class="Size AttachmentLabel" style="color:#1052b5;">
							 							<%
							 								downloadAtt = uicomponent.event("DownloadAttach");
							 							%>
 																<a onclick="if(eXo.core.Browser.browserType === 'ie') {<%=uicomponent.event("DownloadAttach");%>; } ajaxRedirect('$linkImage'); return false;" href="javaScript:void(0);">
							 								$fileName
							 							</a>
							 						</div>
							 						&nbsp;- <span style="color:gray;font-size:11px;">$size</span>
							 					</div>
						 						<div style="clear:left;"><span></span></div>
						 					</div>
					 					</div>
						    <%} else {
						    %>
						    		<div class="LabelBox">
											<div class="AttachmentIcon FileAttachmentIcon" style="width:auto; height:auto;">
												<a class="AttachmentLabel" onclick="if(eXo.core.Browser.browserType === 'ie') {<%=uicomponent.event("DownloadAttach");%>; } ajaxRedirect('$linkImage'); return false;" href="javaScript:void(0);">
													$fileName
												</a>
											</div>
											<div style="clear:left;"><span></span></div>
											<div class="Size"><%= _ctx.appRes("UIPopupViewQuestion.label.size"); %> $size</div>
										</div>
						    <%}
						    } else {
						    	%>
						    		<div class="LabelBox" style="margin:10px 10px 0px 5px;">
							    		<div class="FalseIcon" style="padding-left:15px;">
							    			<a style="color:red;" href="javaScript: void(0)">
							    				<%=_ctx.appRes("UIPopupViewQuestion.label.lostFile")%>
							    			</a>
							    		</div>
							    		<div style="clear:left;"><span></span></div>
						    		</div>
						    	<%
						    	}
						  	} %>
						  	</div>
				  	<div style="clear:left;"><span></span></div>
					</div>
			  	<%
			  	}%>
					<%
					if(question.getRelations() != null && question.getRelations().length > 0){
					%>
						<div class="RelatedQuestionsView"><b><%= _ctx.appRes("UIPopupViewQuestion.label.related-question"); %></b><br/>
							<%String questionRelationById = "" ;
								String cateRelaId = "" ;
								String quesRelaId = "" ;
								String quesRelaCont = "" ;
								String linkRelaQues = "" ;
								for(String relationId : question.getRelations()) { 
									quesRelaCont = "" ;
									questionRelationById = uicomponent.getQuestionRelationById(relationId) ;
									if(questionRelationById!= null && questionRelationById.trim().length() > 0) {
										cateRelaId = questionRelationById.split("/")[0] ;
										quesRelaId = questionRelationById.split("/")[1] ;
										quesRelaCont = (questionRelationById.replaceAll(cateRelaId + "/", "").replaceAll(quesRelaId + "/", "")).replaceAll("<p>", "").replaceAll("</p>", "") ;
									}
									if(quesRelaCont != null && quesRelaCont.trim().length() > 0) {
									String title = quesRelaCont ;
										if (quesRelaCont.length() > 50) {
											title = FAQUtils.getTitle(title) ;
											quesRelaCont = FAQUtils.getSubString(quesRelaCont, 50); 
										}
							%>
										&nbsp; <div title="$title">- $quesRelaCont<br/></div>
							<% 	}
								}%>
						</div>
					<%
					}%>
						</div>
					</td>
				</tr>
			</tbody>
		</table>
	</div>
		<div class="UIAction">
      <a href="javascript:void(0);" onclick="<%=uicomponent.event("Close");%>" class="ActionButton LightBlueStyle"><%=_ctx.appRes("UIAnswersPortlet.action.Close");%></a>
    </div>
	<%uiform.end()%>
</div>