if (!window.App) {
	App = {};
}
if(!App.board) {
	App.board = {};
}

/*
모듈 초기화
*/
$(function() {
	var boardApp = new App.board.newsletter();
	boardApp.init();
})

App.board.newsletter = function() {
	var self;
	
	return {
		init() {
			self = this;
			self.attachFileInputChangeEvent();
			self.deleteAttachButton();
		},
		attachFileInputChangeEvent() {
			$('.attachFileInput').change(function() {
				var attachOrder = $(this).data('attach-order');
				document.getElementById('fileView'+attachOrder).innerText = this.value;
				
				// 등록된 파일이 있는 경우 delete checkbox 체크하기
				var $fileDeleteButton = $('#fileDeleteButton'+attachOrder);
				var attachNo = $fileDeleteButton.data('attach-no');
				var $deleteAttachInput = $('#attachFile'+attachNo);
				if($deleteAttachInput) {
					$deleteAttachInput.prop('checked', true);
				}
				
				// 파일 삭제 버튼 숨김
				$fileDeleteButton.removeClass('hide');
			});
		},
		deleteAttachButton() {
			$('.fileDeleteButton').click(function() {
				var attachNo = $(this).data('attach-no');
				var $deleteAttachInput = $('#attachFile'+attachNo);
				
				if($deleteAttachInput) {
					$deleteAttachInput.prop('checked', true);
				}
				
				$(this).siblings('span').text($m('파일없음'));
				$(this).addClass('hide');
			});
		}
	}
}