이호영 이호영 2024-08-23
문자전송 > 미리보기 기능 완료
@69af137b060116394719fd298a672ae506da8eb6
src/main/webapp/WEB-INF/jsp/web/msgdata/MsgDataSMLView.jsp
--- src/main/webapp/WEB-INF/jsp/web/msgdata/MsgDataSMLView.jsp
+++ src/main/webapp/WEB-INF/jsp/web/msgdata/MsgDataSMLView.jsp
@@ -15,80 +15,220 @@
 
 
 $(document).ready(function(){
-    var currentIndex = 0;
-    var dataLength = tableL.getData().length;
+	
+	
+
+	
+	//받는사람 연락처 내용 처리
+	//Tabulator AJAX Data Loading
+	tableL = new Tabulator(".callList_box", {
+		height:"255px",
+	    layout:"fitColumns",
+	    headerHozAlign:"center",
+	    validationMode:"highlight",
+	    placeholder:"복사(Ctrl+C)한 내용을 여기에 붙여넣기(Ctrl+V) 해주세요.", //fit columns to width of table (optional)
+	    resizableColumns:false,
+	 	columns:[ //Define Table Columns
+	 		{formatter:"rowSelection", headerHozAlign:"center", titleFormatter:"rowSelection",clipboard:false, hozAlign:"center", width:5, headerSort:false, cellClick:function(e, cell){
+	 	        cell.getRow().toggleSelect();
+		 	}}, 
+// 			{formatter:"rownum", align:"center", title:"No", hozAlign:"center", headerHozAlign:"center", field:"No", width:30},
+			{formatter:"rownum", align:"center" ,title:"No", hozAlign:"center", headerHozAlign:"center", width:40},
+		 	{title:"이름", hozAlign:"center", headerHozAlign:"center", field:"name", editor:"input", validator:["maxLength:12"], cellEdited:function(cell){
+		 	    fnReplCell();
+		    }},
+		 	{title:"휴대폰", hozAlign:"center", headerHozAlign:"center", field:"phone", editor:"input", width:100, validator:["required","minLength:10", "maxLength:12"], cellEdited:function(cell){
+		 	    fnDuplPhone();
+		    }},
+		 	{title:"[*1*]", hozAlign:"center", headerHozAlign:"center", field:"rep1", editor:"input", minWidth:60, validator:["maxLength:40"], cellEdited:function(cell){
+		 	    fnReplCell();
+		    }},
+		 	{title:"[*2*]", hozAlign:"center", headerHozAlign:"center", field:"rep2", editor:"input", minWidth:60, validator:["maxLength:40"], cellEdited:function(cell){
+		 		fnReplCell();
+		    }},
+		 	{title:"[*3*]", hozAlign:"center", headerHozAlign:"center", field:"rep3", editor:"input", minWidth:60, validator:["maxLength:40"], cellEdited:function(cell){
+		 		fnReplCell();
+		    }},
+		 	{title:"[*4*]", hozAlign:"center", headerHozAlign:"center", field:"rep4", editor:"input", minWidth:60, validator:["maxLength:40"], cellEdited:function(cell){
+		 		fnReplCell();
+		    }},
+		 	
+	 	],
+	 	validationFailed:function(cell, value, parameters){ // 유효성 체크 함수 - 아직 잘 모르겠음 
+	        //take action on validation fail
+	 		var valid = cell.isValid();
+	 		var fieldNm = cell.getField();
+	 		var cellVal = cell.getValue();
+	 		var returnVal = "";
+	 		if(!valid){
+	 			
+	 			if(fieldNm == "name"){
+	 				alert("받는사람 이름은 최대 12글자까지만 입력 가능합니다.");
+	 				cell.setValue(strMaxLengthSubstring(cellVal, 11)); //스크립트 함수가 0부터 시작이므로 원하는 글자수 -1을 해줘야한다.
+	 				cell.clearValidation();
+	 			}else if(fieldNm == "phone"){
+	 				alert("휴대폰번호는 하이픈(-)을 제외한 숫자만 정확히 입력해 주세요.");
+	 			}else{
+		 			alert("치환문자를 정확히 입력해 주세요. 40글자 이내로 입력 가능합니다.");
+		 			cell.setValue(strMaxLengthSubstring(cellVal, 39));
+		 			cell.clearValidation();
+	 			}
+	 			
+	 			//해당 셀 데이터 삭제
+	 			//cell.setValue("");
+	 			
+	 		}
+	 		return value % parameters.phone;
+	    },
+
+	});
+	
+	
+	//주소록 불러오기 팝업 내용
+	//Tabulator AJAX Data Loading
+	tableAddr = new Tabulator(".callAddr_box", {
+		height:"255px",
+	    layout:"fitColumns",
+	    headerHozAlign:"center",
+	    validationMode:"highlight",
+	    placeholder:"주소록 그룹을 선택해 주세요.", //fit columns to width of table (optional)
+	    resizableColumns:false,
+	 	columns:[ //Define Table Columns
+	 		{formatter:"rowSelection", titleFormatter:"rowSelection",clipboard:false, hozAlign:"center", headerSort:false, cellClick:function(e, cell){
+	 	        cell.getRow().toggleSelect();
+		 		}
+		 	}, 
+		 	{title:"그룹명", hozAlign:"center", field:"addrGroupNm", editor:"input", width:100, validator:["required","minLength:2", "maxLength:40"]},
+		 	{title:"이름", hozAlign:"center", field:"addrName", editor:"input",  width:100, validator:["maxLength:12"]},
+		 	{title:"휴대폰번호", hozAlign:"center", field:"addrPhone", editor:"input", width:100, validator:["required","minLength:10", "maxLength:11"]},
+		 	{title:"[*1*]", hozAlign:"center", field:"addrRep1", editor:"input", width:84, validator:["maxLength:40"]},
+		 	{title:"[*2*]", hozAlign:"center", field:"addrRep2", editor:"input", width:84, validator:["maxLength:40"]},
+		 	{title:"[*3*]", hozAlign:"center", field:"addrRep3", editor:"input", width:84, validator:["maxLength:40"]},
+		 	{title:"[*4*]", hozAlign:"center", field:"addrRep4", editor:"input", width:84, validator:["maxLength:40"]},
+		 	
+	 	],
+	 	validationFailed:function(cell, value, parameters){ // 유효성 체크 함수 - 아직 잘 모르겠음 
+	 		var valid = cell.isValid();
+	 		var fieldNm = cell.getField();
+	 		if(!valid){
+	 			if(fieldNm == "addrName"){
+	 				alert("받는사람 이름은 최대 12글자까지만 입력 가능합니다.");
+	 			}else if(fieldNm == "addrPhone"){
+	 				alert("휴대폰번호는 하이픈(-)을 제외한 숫자만 정확히 입력해 주세요.");
+	 			}else if(fieldNm == "addrGroupNm"){
+	 				alert("그룹명을 정확히 입력해 주세요. 2 ~ 40글자 이내로 입력 가능합니다.");
+	 			}else{
+		 			alert("치환문자를 정확히 입력해 주세요. 100글자 이내로 입력 가능합니다.");
+	 			}
+	 			
+	 			//해당 셀 데이터 삭제
+	 			cell.setValue("");
+	 		}
+	 		return value % parameters.addrPhone;
+	    },
+
+	});
+	
+	
+	
+	/*  
+	* 20240823
+	* 미리보기 스크립트
+	*/
+	// 현재 위치
+	var currentIndex = 0;
+
+	// 제일 이전
+	$('#btnFirst').on('click', function(){
+		currentIndex = 0;
+		
+		updateButtons(currentIndex );
+		fn_previewText(currentIndex);
+	});
+
+	// 이전
+	$('#btnPrev').on('click', function(){
+    	
+		if (currentIndex > 0) {
+			currentIndex--;
+			updateButtons(currentIndex );
+			fn_previewText(currentIndex);
+		}
+    });
     
 
-    $('#btnFirst').on('click', function(){
-        currentIndex = 0;
-        updateButtons();
-        fn_previewText(currentIndex);
-    });
-    
-    $('#btnPrev').on('click', function(){
-        if (currentIndex > 0) {
-            currentIndex--;
-            updateButtons();
-            fn_previewText(currentIndex);
-        }
-    });
-    
-    $('#btnNext').on('click', function(){
-    	console.log('currentIndex : ', currentIndex);
-    	console.log('dataLength : ', dataLength);
-        if (currentIndex < dataLength - 1) {
-            currentIndex++;
-            updateButtons();
-            fn_previewText(currentIndex);
-        }
-    });
-    
-    $('#btnLast').on('click', function(){
-        currentIndex = dataLength - 1;
-        updateButtons();
-        fn_previewText(currentIndex);
+	// 다음
+	$('#btnNext').on('click', function(){
+		var dataLength = tableL.getData().length;
+		if (currentIndex < dataLength - 1) {
+			currentIndex++;
+			updateButtons(currentIndex );
+			fn_previewText(currentIndex);
+		}
     });
 
-    // Initialize buttons on page load
-    updateButtons();
+	// 제일 다음
+	$('#btnLast').on('click', function(){
+		var dataLength = tableL.getData().length;
+		currentIndex = dataLength - 1;
+		updateButtons(currentIndex );
+		fn_previewText(currentIndex);
+	});
+
+	updateButtons(currentIndex);
 	
 });
 
-function updateButtons() {
-    $('#btnPrev').data('index', currentIndex - 1);
-    $('#btnNext').data('index', currentIndex + 1);
-    
-    if (currentIndex <= 0) {
-        $('#btnPrev').attr('disabled', true);
-    } else {
-        $('#btnPrev').attr('disabled', false);
-    }
-    
-    if (currentIndex >= dataLength - 1) {
-        $('#btnNext').attr('disabled', true);
-    } else {
-        $('#btnNext').attr('disabled', false);
-    }
-}
+/*
+ * 버튼 disabled 스크립트
+ */
+function updateButtons(currentIndex ) {
+	
+	
+	var dataLength = tableL.getData().length;
+	console.log('dataLength ', dataLength);
+	console.log('currentIndex ', currentIndex);
+	
+	
+	if (currentIndex <= 0) {
+		$('#btnPrev').attr('disabled', true);
+		$('#btnFirst').attr('disabled', true);
+	} else {
+		$('#btnPrev').attr('disabled', false);
+		$('#btnFirst').attr('disabled', false);
+	}
+	
+	if (currentIndex >= dataLength - 1) {
+		$('#btnNext').attr('disabled', true);
+		$('#btnLast').attr('disabled', true);
+	} else {
+		$('#btnNext').attr('disabled', false);
+		$('#btnLast').attr('disabled', false);
+	}
+} 
 
+/*
+ * 미리보기 데이터 치환
+ */
 function fn_previewText(rowIndex){
-
+	
 	var smsText = $('#smsTxtArea').val()
 	// 데이터 가져오기
 	var data = tableL.getData();
-
+	
 	// 특정 인덱스(예: 1)로 행을 선택하여 치환
 	var row = data[rowIndex]; // 인덱스 1의 행을 선택
-
+	
+	
 	// 이름 치환
-	smsText = smsText.replace(/\[\*이름\*\]/g, row.name);
-
+	smsText = smsText.replace(/\[\*이름\*\]/g, row.name !== undefined && row.name !== null ? row.name : '[*이름*]');
+	
 	// rep1, rep2, rep3, rep4 치환
-	smsText = smsText.replace(/\[\*1\*\]/g, row.rep1 || '');
-	smsText = smsText.replace(/\[\*2\*\]/g, row.rep2 || '');
-	smsText = smsText.replace(/\[\*3\*\]/g, row.rep3 || '');
-	smsText = smsText.replace(/\[\*4\*\]/g, row.rep4 || '');
-
+	smsText = smsText.replace(/\[\*1\*\]/g, row.rep1 !== undefined && row.rep1 !== null ? row.rep1 : '[*1*]');
+	smsText = smsText.replace(/\[\*2\*\]/g, row.rep2 !== undefined && row.rep2 !== null ? row.rep2 : '[*2*]');
+	smsText = smsText.replace(/\[\*3\*\]/g, row.rep3 !== undefined && row.rep3 !== null ? row.rep3 : '[*3*]');
+	smsText = smsText.replace(/\[\*4\*\]/g, row.rep4 !== undefined && row.rep4 !== null ? row.rep4 : '[*4*]');
+	
 	// 결과 출력 또는 다른 곳에 사용
 	console.log(smsText);
 	$('.realtime').text(smsText);
@@ -719,116 +859,6 @@
 	 ]; */
 	
 	//var selectRow;
-	
-	//받는사람 연락처 내용 처리
-	//Tabulator AJAX Data Loading
-	tableL = new Tabulator(".callList_box", {
-		height:"255px",
-	    layout:"fitColumns",
-	    headerHozAlign:"center",
-	    validationMode:"highlight",
-	    placeholder:"복사(Ctrl+C)한 내용을 여기에 붙여넣기(Ctrl+V) 해주세요.", //fit columns to width of table (optional)
-	    resizableColumns:false,
-	 	columns:[ //Define Table Columns
-	 		{formatter:"rowSelection", headerHozAlign:"center", titleFormatter:"rowSelection",clipboard:false, hozAlign:"center", width:5, headerSort:false, cellClick:function(e, cell){
-	 	        cell.getRow().toggleSelect();
-		 	}}, 
-// 			{formatter:"rownum", align:"center", title:"No", hozAlign:"center", headerHozAlign:"center", field:"No", width:30},
-			{formatter:"rownum", align:"center" ,title:"No", hozAlign:"center", headerHozAlign:"center", width:40},
-		 	{title:"이름", hozAlign:"center", headerHozAlign:"center", field:"name", editor:"input", validator:["maxLength:12"], cellEdited:function(cell){
-		 	    fnReplCell();
-		    }},
-		 	{title:"휴대폰", hozAlign:"center", headerHozAlign:"center", field:"phone", editor:"input", width:100, validator:["required","minLength:10", "maxLength:12"], cellEdited:function(cell){
-		 	    fnDuplPhone();
-		    }},
-		 	{title:"[*1*]", hozAlign:"center", headerHozAlign:"center", field:"rep1", editor:"input", minWidth:60, validator:["maxLength:40"], cellEdited:function(cell){
-		 	    fnReplCell();
-		    }},
-		 	{title:"[*2*]", hozAlign:"center", headerHozAlign:"center", field:"rep2", editor:"input", minWidth:60, validator:["maxLength:40"], cellEdited:function(cell){
-		 		fnReplCell();
-		    }},
-		 	{title:"[*3*]", hozAlign:"center", headerHozAlign:"center", field:"rep3", editor:"input", minWidth:60, validator:["maxLength:40"], cellEdited:function(cell){
-		 		fnReplCell();
-		    }},
-		 	{title:"[*4*]", hozAlign:"center", headerHozAlign:"center", field:"rep4", editor:"input", minWidth:60, validator:["maxLength:40"], cellEdited:function(cell){
-		 		fnReplCell();
-		    }},
-		 	
-	 	],
-	 	validationFailed:function(cell, value, parameters){ // 유효성 체크 함수 - 아직 잘 모르겠음 
-	        //take action on validation fail
-	 		var valid = cell.isValid();
-	 		var fieldNm = cell.getField();
-	 		var cellVal = cell.getValue();
-	 		var returnVal = "";
-	 		if(!valid){
-	 			
-	 			if(fieldNm == "name"){
-	 				alert("받는사람 이름은 최대 12글자까지만 입력 가능합니다.");
-	 				cell.setValue(strMaxLengthSubstring(cellVal, 11)); //스크립트 함수가 0부터 시작이므로 원하는 글자수 -1을 해줘야한다.
-	 				cell.clearValidation();
-	 			}else if(fieldNm == "phone"){
-	 				alert("휴대폰번호는 하이픈(-)을 제외한 숫자만 정확히 입력해 주세요.");
-	 			}else{
-		 			alert("치환문자를 정확히 입력해 주세요. 40글자 이내로 입력 가능합니다.");
-		 			cell.setValue(strMaxLengthSubstring(cellVal, 39));
-		 			cell.clearValidation();
-	 			}
-	 			
-	 			//해당 셀 데이터 삭제
-	 			//cell.setValue("");
-	 			
-	 		}
-	 		return value % parameters.phone;
-	    },
-
-	});
-	
-	
-	//주소록 불러오기 팝업 내용
-	//Tabulator AJAX Data Loading
-	tableAddr = new Tabulator(".callAddr_box", {
-		height:"255px",
-	    layout:"fitColumns",
-	    headerHozAlign:"center",
-	    validationMode:"highlight",
-	    placeholder:"주소록 그룹을 선택해 주세요.", //fit columns to width of table (optional)
-	    resizableColumns:false,
-	 	columns:[ //Define Table Columns
-	 		{formatter:"rowSelection", titleFormatter:"rowSelection",clipboard:false, hozAlign:"center", headerSort:false, cellClick:function(e, cell){
-	 	        cell.getRow().toggleSelect();
-		 		}
-		 	}, 
-		 	{title:"그룹명", hozAlign:"center", field:"addrGroupNm", editor:"input", width:100, validator:["required","minLength:2", "maxLength:40"]},
-		 	{title:"이름", hozAlign:"center", field:"addrName", editor:"input",  width:100, validator:["maxLength:12"]},
-		 	{title:"휴대폰번호", hozAlign:"center", field:"addrPhone", editor:"input", width:100, validator:["required","minLength:10", "maxLength:11"]},
-		 	{title:"[*1*]", hozAlign:"center", field:"addrRep1", editor:"input", width:84, validator:["maxLength:40"]},
-		 	{title:"[*2*]", hozAlign:"center", field:"addrRep2", editor:"input", width:84, validator:["maxLength:40"]},
-		 	{title:"[*3*]", hozAlign:"center", field:"addrRep3", editor:"input", width:84, validator:["maxLength:40"]},
-		 	{title:"[*4*]", hozAlign:"center", field:"addrRep4", editor:"input", width:84, validator:["maxLength:40"]},
-		 	
-	 	],
-	 	validationFailed:function(cell, value, parameters){ // 유효성 체크 함수 - 아직 잘 모르겠음 
-	 		var valid = cell.isValid();
-	 		var fieldNm = cell.getField();
-	 		if(!valid){
-	 			if(fieldNm == "addrName"){
-	 				alert("받는사람 이름은 최대 12글자까지만 입력 가능합니다.");
-	 			}else if(fieldNm == "addrPhone"){
-	 				alert("휴대폰번호는 하이픈(-)을 제외한 숫자만 정확히 입력해 주세요.");
-	 			}else if(fieldNm == "addrGroupNm"){
-	 				alert("그룹명을 정확히 입력해 주세요. 2 ~ 40글자 이내로 입력 가능합니다.");
-	 			}else{
-		 			alert("치환문자를 정확히 입력해 주세요. 100글자 이내로 입력 가능합니다.");
-	 			}
-	 			
-	 			//해당 셀 데이터 삭제
-	 			cell.setValue("");
-	 		}
-	 		return value % parameters.addrPhone;
-	    },
-
-	});
 	
 	//핸드폰 번호 Tabulator에서 수정시 중복 체크
 	function fnDuplPhone(){
src/main/webapp/WEB-INF/jsp/web/msgdata/include/msgDataIncludeExcel.jsp
--- src/main/webapp/WEB-INF/jsp/web/msgdata/include/msgDataIncludeExcel.jsp
+++ src/main/webapp/WEB-INF/jsp/web/msgdata/include/msgDataIncludeExcel.jsp
@@ -257,6 +257,8 @@
 		// 합쳐진 데이터를 tableL에 설정합니다.
 		tableL.setData(combinedData);
 		
+		// 미리보기 버튼 활성화
+		updateButtons(0);
 		
 		var totRows = tableL.getRows().length; 
 		updateTotCnt(totRows); //전체 데이터 갯수 구하기
Add a comment
List