  <%--
  - FileName   : NotiDetail.jsp
  - Author     : gyeongmo an
  - Date       : 2014.07.14
  - Copyright  : Copyright (c) 2014 www.udapsoft.co.kr, Inc.
  - All rights reserved.
  - Description: 공지사항 상세
--%>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="com.udapsoft.waf.system.HandlerStorage" %>
<%@ page import="com.udapsoft.waf.common.ui.*" %>
<%@ page import="kr.co.hsnc.common.util.*"%>
<%@ page import="kr.co.hsnc.common.sql.*" %>
<%@ page import="com.udapsoft.waf.common.util.DateUtil" %>
<%@ include file="/jsp/work/taglib.jsp" %>
<jsp:useBean id="ctx" class="com.udapsoft.waf.system.context.SessionContext" scope="session" />
<%
    ctx.init(request, response);
	String fevent = ctx.get("fevent");

    HandlerStorage storage = ctx.getHandlerStorage();
    ValueObject params = storage.getParams();
    ValueObject user = storage.getUser();
    ValueObject vo = storage.getValueObject("notiDetailRowSet");
%>

<SCRIPT language="JavaScript">
	function _onReady(){
		var f = document.form1;
		
		jQuery("#btnSave").click(function() {
			var isModify = <%= (vo.get("seq")=="")?"true":"false"%>;
			
			if( isEmpty(f.noti_title) ) {
				alert("제목을 입력하세요.");
		        return;
			} else if ( stringByteSize4UTF($("#noti_title").val()) > 256 ) {
		    	alert("제목은 256자까지 입력하실 수 있습니다.");
		    	return;
		    }
			
			if( stringByteSize4UTF($("#write_nm").val()) > 50 ) {
				alert("작성자는 50자까지 입력하실 수 있습니다.");
		    	return;
			}
			
			if( isEmpty(f.content) ) {
				alert("내용을 입력하세요.");
		        return;
			}else if ( stringByteSize4UTF($("#content").val()) > 4000 ) {
		    	alert("내용은 4000자까지 입력하실 수 있습니다.");
		    	return;
		    }
			
			 if($('input[name="supp_open_yn"]').is(":checked") == true){
				 f.supp_open_yn_value.value = "Y";
			 } else {
				 f.supp_open_yn_value.value = "N";
			 }
		    
		    if(confirm("저장하시겠습니까?")) {
		    	if(isModify == true){	   
					//저장
			    	submitXmlRequest("/center/center/NotiDetail_form.screen", "SAVE_NOTI_DETAIL", f, "VALUEOBJECT");
				}else{
					//수정
					submitXmlRequest("/center/center/NotiDetail_form.screen", "UPDATE_NOTI_DETAIL", f);
				}
			}
		});
		
		jQuery("#btnDelete").click(function() {
		    if(confirm("삭제하시겠습니까?")) {
				submitXmlRequest("/center/center/NotiDetail_form.screen", "DELETE_NOTI_DETAIL", f);
			}
		});
	
		jQuery("#btnList").click(function() {
			var f = document.form1;
		    
			f.fevent.value ="";
		    f.action = "/center/center/NotiList.screen";
		    f.target = "_self";
		    f.submit();
		});
	}
	
	function doResult(resultObj) {
		try {
			document.form1.isSubmit = false;
			if( resultObj.getRequestEvent() == "SAVE_NOTI_DETAIL") {
				if( resultObj.getSuccess() ) {
					alert("저장했습니다.");
					var vo = resultObj.getValueObject();
					jQuery("#seq").val(vo.get("SEQ"));
					jQuery("#fevent").val("GET_NOTI_DETAIL");
					jQuery("#form1").attr("action", "/center/center/NotiDetail.screen");
					jQuery("#form1").attr("target", "_self");
					jQuery("#form1").attr("method", "post");
					jQuery("#form1").submit();
				}
				else {
					alert("저장을 실패하였습니다.");
					//dlgErrorMsg(resultObj);
				}
			} else if ( resultObj.getRequestEvent() == "UPDATE_NOTI_DETAIL" ) {
				if( resultObj.getSuccess() ) {
					alert("저장했습니다.");
					jQuery("#seq").val(document.form1.seq.value);
					jQuery("#fevent").val("GET_NOTI_DETAIL");
					jQuery("#form1").attr("action", "/center/center/NotiDetail.screen");
					jQuery("#form1").attr("target", "_self");
					jQuery("#form1").attr("method", "post");
					jQuery("#form1").submit();
				}
				else {
					alert("저장을 실패하였습니다.");
					//dlgErrorMsg(resultObj);
				}
				
			} else if ( resultObj.getRequestEvent() == "DELETE_NOTI_DETAIL" ) {
				if( resultObj.getSuccess() ) {
					alert("삭제했습니다.");
					jQuery("#btnList").click();
				}
				else {
					alert("삭제 실패하였습니다.");
					//dlgErrorMsg(resultObj);
				}
			}
		}
		catch(errorObject) {
			showErrorDlg("doResult()", errorObject);
		}
	}
	
	//첨부파일   
	function doAttachFile(obj) {
		 if(obj.value==''){
			alert("저장을 한 후 파일을 첨부할 수 있습니다.");
		}
		else if(obj.value != ''){ 
			viewFileListNew('NOTI_DETAIL', obj.value, document.form1.p_AttachFile, "Y", "");
		} 
	}
	
</script>

<form id="form1" name="form1" method="post">
<INPUT type="hidden" name="fevent" value="<%= params.get("fevent") %>">
<INPUT type="hidden" name="write_id" value="<%=user.get("acct_id")%>">
<INPUT type="hidden" name="seq" value="<%=vo.get("seq")%>">
<INPUT type="hidden" name="supp_open_yn_value">


<!-- 제목 및 버튼 -->
   	<table width="100%">
		<colgroup>
			<col width="500" />
			<col width="*" />
		</colgroup>
	<tr>
	   	<th>
		   <div align="left" id="title">
		    <ul>
		     <li>공지사항</li>
		    </ul>
		   </div>
	   </th>
	   <td align="right">
			<span class="btnSearch center"><a href="javascript:void(0);" id="btnSave">저장</a></span>
			<span class="btnSearch center"><a href="javascript:void(0);" id="btnDelete">삭제</a></span>
			<span class="btnSearch center"><a href="javascript:void(0);" id="btnList">목록</a></span>
	   </td>
   	</tr>
   	</table>
   	
<TABLE class="form-table">
	<col width="15%">
	<col width="50%">
	<col width="15%">
	<col width="20%">
	<tr> 
		<th style="text-align: left;">
			제목
		</th>
		<td>
			<%= InputText.get("noti_title", vo.get("title"), 95, 30, "class=input, persize") %>
		</td>
		<th style="text-align: left;">
	     	공지일자
	 	</th>
		<td>
			<%	if(fevent.equals("NEW_NOTI_DETAIL") ) { %>
				<%= InputText.get("noti_dy", DateUtil.formatDateTime(DateUtil.getToday(), "yyyyMMdd", "yyyy-MM-dd"), 65, 50, "READONLY, persize") %>
			<% 	} else { %>
	 			<%= InputText.get("noti_dy", DateUtil.formatDateTime(vo.get("noti_dy"), "yyyyMMdd", "yyyy-MM-dd"), 65, 50, "READONLY, persize") %>
			<% 	} %>
			<IMG name="noti_dy_img" src="/img/buyer/button/bt_calender.gif" border="0" align="absmiddle" onClick="JavaScript:dlgCalendar('noti_dy');">
		</td>
	</tr>
	<tr> 
		<th style="text-align: left;">
	    	작성자
	 	</th>
		<td>
			<%	if(fevent.equals("NEW_NOTI_DETAIL") ) { %>
				<%= InputText.get("write_nm", user.get("user_name"), 45, 30, "class=input_blank, readOnly=white, string, left, tabIndex=-1", "string") %>
			<% 	} else { %>
				<%= InputText.get("write_nm", vo.get("write_nm"), 45, 30, "class=input_blank, readOnly=white, string, left, tabIndex=-1", "string") %>
			<% 	} %>
		</td>
		<th style="text-align: left;">
	    	업체공지여부
	 	</td>
		<td>
			<input type="checkbox" name="supp_open_yn" value="<%=vo.get("supp_open_yn")%>" style="width: 10%;" <%=vo.get("supp_open_yn").equals("Y") ? "checked=\"checked\"" : "" %>>업체공개시 체크
		</td>
	</tr>
	<tr> 
		<th style="text-align: left;">
			내용
	 	</th>
		<td colspan="3" >
			<TEXTAREA name="content" style="width:97%" rows="10" class="input"><%=vo.get("content") %></TEXTAREA>
		</td>
	</tr>
	<tr> 
		<th style="text-align: left;">
			첨부파일
	 	</th>
		<td width="30%" style="padding-top: 3px;" COLSPAN='3'> 
			<TEXTAREA name="p_AttachFile" style="width:93%" rows="1" class="input" readOnly><%=vo.get("NOTI_DETAIL_FILE") %></TEXTAREA>
			<IMG src="/img/buyer/icon/icon_plus.gif" alt="adjust size" border="0" align="top" onClick="JavaScript:toggleTextarea(this, document.form1.p_AttachFile, 1, 5);" style="cursor:hand;">
	        <IMG id='search_spot_button' onClick="doAttachFile(document.form1.seq);" src='/img/buyer/button/bt_change.gif' border='0'  align="top" align='absmiddle' alt='[Attach File]' style='cursor:hand;'>  		 	
	    </td>
 	</tr>
</table>
</form>