관리 메뉴

거니의 velog

(9) script.js 본문

대덕인재개발원_2nd project

(9) script.js

Unlimited00 2023. 10. 20. 11:25

- 직접 짠 js 코드입니다.

// 공통 함수
$.passToEmail = function(){
	$.ajax({
		url : contextPath + "/findPassSendEmail.do",
		type : "post",
		data : { "emailEmpNo" : emailEmpNo },
		success : function(res){
			$("#alertModal .modal-body").empty();
    		$("#alertModal .modal-body").html(emailEmpNo + " 사번에 등록된 이메일로 비밀번호가 전송되었습니다. <br /> 확인해 주세요.");
    		
    		$("#modalBtn").trigger("click");
    		
    		setTimeout(function(){
    			$("#modalCloseBtn").trigger("click");
    		}, 2000);
		},
		error : function(xhr){
			alert("상태 : " + xhr.status);
		}
	});
}

$.inputNum = function(thisIs){
	var regex = /^[0-9]+$/;
    var testResult = regex.test(thisIs.val());
    if (!testResult) { // 숫자가 아님
        // alert("사원번호는 숫자만 입력 가능합니다.");
        thisIs.val("");
    }
}

$.ratioBoxH = function(sel1, sel2){
	var boxSel = sel1;
    var boxW = boxSel.width();
    //console.log("boxW : " + boxW);
    var boxH = boxSel.height();
    //console.log("boxH : " + boxH);
    var boxRatio = boxH / boxW;
    //console.log("boxRatio : " + boxRatio);
    
    var imgSel = sel2;
    var imgW = imgSel.width();
    //console.log("imgW : " + imgW);
    var imgH = imgSel.height();
    //console.log("imgH : " + imgH);
    var imgRatio = imgH / imgW;
    //console.log("imgRatio : " + imgRatio);
    
    if(boxRatio < imgRatio){ // 박스보다 이미지의 세로가 더 길다.
        imgSel.width(boxW).height("auto");
    }else{ // 이미지보다 박스의 세로가 더 길다.
        imgSel.height(boxH).width("auto");
    }
}

$.ratioBoxW = function(sel1, sel2){
	var boxSel = sel1;
    var boxW = boxSel.width();
    //console.log("boxW : " + boxW);
    var boxH = boxSel.height();
    //console.log("boxH : " + boxH);
    var boxRatio = boxW / boxH;
    //console.log("boxRatio : " + boxRatio);
    
    var imgSel = sel2;
    var imgW = imgSel.width();
    //console.log("imgW : " + imgW);
    var imgH = imgSel.height();
    //console.log("imgH : " + imgH);
    var imgRatio = imgW / imgH;
    //console.log("imgRatio : " + imgRatio);
    
    if(boxRatio < imgRatio){ // 박스보다 이미지의 가로가 더 길다.
        imgSel.height(boxH).width("auto");
    }else{ // 이미지보다 박스의 가로가 더 길다.
        imgSel.width(boxW).height("auto");
    }
}

/*$.idChkShowImg = function(empNum){
	$.ajax({
		url : contextPath + "/selectEmpNo.do",
		type : "post",
		data : { "empNum" : empNum },
		success : function(res){
			
			var empId = res;
			var imgSrc = contextPath + "/images/default_profile.png";
	        if (empNum == empId) { // 사원번호가 일치하는 경우
	            imgSrc = contextPath + "/images/" + empNum + "/emp_" + empNum + ".jpg";
	            $("#profileImg").attr("src", imgSrc);
	            $(".loginBgColor").css({
	            	"backgroundColor" : "black",
	            	"opacity" : "0.2"
	            });
				idFlag = true;
	        } else { // 사원번호가 일치하지 않는 경우
	            imgSrc = contextPath + "/images/default_profile.png";
	            $("#profileImg").attr("src", imgSrc);
	            $(".loginBgColor").css({
	            	"backgroundColor" : "#343434",
	            	"opacity" : "0.7"
	            });
				idFlag = false;
	        }

			// 이미지가 변경될 때 실행
		    $(empLogimg).on("load", function() {
		        // 이미지가 로드될 때마다 함수 실행
		        $.ratioBoxH(empLogBox, empLogimg);
		    });
	        
		},
		error : function(xhr){
			alert("상태 : " + xhr.status);
		},
		dataType : "json"
	});
}*/

$.idChkShowImg2 = function(empNum){
	$.ajax({
		url : contextPath + "/selectEmpInfo.do",
		type : "post",
		data : { "empNum" : empNum },
		success : function(res){
			
			//console.log(res);
			
			var imgSrc = contextPath + "/images/default_profile.png";
			
			if(!res) {
				//console.log("DB에 사번이 없다.");
				imgSrc = contextPath + "/images/default_profile.png";
	            $("#profileImg").attr("src", imgSrc);
	            $(".loginBgColor").css({
	            	"backgroundColor" : "#343434",
	            	"opacity" : "0.7"
	            });
				idFlag = false;
				$.ratioBoxH(empLogBox, empLogimg);
			}else {
				//console.log("DB에 사번이 있다.");
				var empId = res.empno;
				var empPhoto = res.empphoto;
				if (empNum == empId) { // 사원번호가 일치하는 경우
					imgSrc = contextPath + "/images/imgView.do?fileno=" + empPhoto;
		            $("#profileImg").attr("src", imgSrc);
		            $(".loginBgColor").css({
		            	"backgroundColor" : "black",
		            	"opacity" : "0.2"
		            });
					idFlag = true;
					$.ratioBoxH(empLogBox, empLogimg);
				}
			}
			
			// 이미지가 변경될 때 실행
		    $(empLogimg).on("load", function() {
		        // 이미지가 로드될 때마다 함수 실행
		        $.ratioBoxH(empLogBox, empLogimg);
		    });
	        
		},
		error : function(xhr){
			alert("상태 : " + xhr.status);
		},
		dataType : "json"
	});
}

$.empNoDupChk = function(empNum){
	$.ajax({
		url : contextPath + "/dupChkEmpNo.do",
		type : "post",
		data : { "empNum" : empNum },
		success : function(res){
			//console.log(res);
			var empId = res;
			
			if(!res) { // 아이디가 중복되지 않는 경우
				//alert("아이디가 중복되지 않사옵나이다...");
				var newEmpNo = isEmpNo + "01";
				console.log("newEmpNo : " + newEmpNo);
				$("#empno").val(newEmpNo);
				$(".empPreAuto").eq(0).find("span").eq(1).text("");
        		$(".empPreAuto").eq(0).find("span").eq(1).text(newEmpNo + " [사원번호 자동 완성됨]");
			}else { // 아이디가 중복되는 경우
				//alert("아이디가 중복되옵나이다...");
				isEmpNo = parseInt(empId) + 1;
				console.log("isEmpNo : " + isEmpNo);
				$("#empno").val(isEmpNo);
				$(".empPreAuto").eq(0).find("span").eq(1).text("");
        		$(".empPreAuto").eq(0).find("span").eq(1).text(isEmpNo + " [사원번호 자동 완성됨]");
			}
		},
		error : function(xhr){
			alert("상태 : " + xhr.status);
		},
		dataType : "json"
	});
}

$.empNoDupChk2 = function(empNum){
	$.ajax({
		url : contextPath + "/dupChkEmpNo.do",
		type : "post",
		data : { "empNum" : empNum },
		success : function(res){
			//console.log(res);
			var empId = res;
			
			if(!res) { // 아이디가 중복되지 않는 경우
				//alert("아이디가 중복되지 않사옵나이다...");
				var newEmpNo = isEmpNo + "01";
				console.log("newEmpNo : " + newEmpNo);
				$("#empno").val(newEmpNo);
				$("#changeempno").val(newEmpNo);
				$(".empPreAuto").eq(0).find("span").eq(1).text("");
        		$(".empPreAuto").eq(0).find("span").eq(1).text(newEmpNo + " [사원번호 자동 완성됨]");
			}else { // 아이디가 중복되는 경우
				//alert("아이디가 중복되옵나이다...");
				isEmpNo = parseInt(empId) + 1;
				console.log("isEmpNo : " + isEmpNo);
				$("#empno").val(isEmpNo);
				$("#changeempno").val(isEmpNo);
				$(".empPreAuto").eq(0).find("span").eq(1).text("");
        		$(".empPreAuto").eq(0).find("span").eq(1).text(isEmpNo + " [사원번호 자동 완성됨]");
			}
		},
		error : function(xhr){
			alert("상태 : " + xhr.status);
		},
		dataType : "json"
	});
}

$.empNoDupChk3 = function(empNum){
	$.ajax({
		url : contextPath + "/dupChkEmpNo.do",
		type : "post",
		data : { "empNum" : empNum },
		success : function(res){
			//console.log(res);
			var empId = res;
			
			if(!res) { // 아이디가 중복되지 않는 경우
				//alert("아이디가 중복되지 않사옵나이다...");
				var newEmpNo = isEmpNo + "01";
				console.log("newEmpNo : " + newEmpNo);
				$("#empno").val(newEmpNo);
				$("#changeempno").val(newEmpNo);
				$("#changeId").val(newEmpNo);
				$(".empPreAuto").eq(0).find("span").eq(1).text("");
        		$(".empPreAuto").eq(0).find("span").eq(1).text(newEmpNo + " [사원번호 자동 완성됨]");
			}else { // 아이디가 중복되는 경우
				//alert("아이디가 중복되옵나이다...");
				isEmpNo = parseInt(empId) + 1;
				console.log("isEmpNo : " + isEmpNo);
				$("#empno").val(isEmpNo);
				$("#changeempno").val(isEmpNo);
				$("#changeId").val(isEmpNo);
				$(".empPreAuto").eq(0).find("span").eq(1).text("");
        		$(".empPreAuto").eq(0).find("span").eq(1).text(isEmpNo + " [사원번호 자동 완성됨]");
			}
		},
		error : function(xhr){
			alert("상태 : " + xhr.status);
		},
		dataType : "json"
	});
}

$.signJobSearch = function(signJob){
	$.ajax({
		url : contextPath + "/signJobSearch.do",
		type : "post",
		data : { "signJob" : signJob },
		success : function(res){
			
			var htmlCode = "";
			$.each(res, function(i, v){
				console.log(v);
				htmlCode += `<option value="${v.empjob}" data="${v.empno}" data2="${v.emppos}">${v.empname}</option>`;
			});
			$("#firstSignEmp").empty();
			$("#firstSignEmp").append(htmlCode);
			
			$(document).on("change", "#firstSignEmp", function(){
	        	var thisIs = $(this);
	        	var empnodata = $("#firstSignEmp option:selected").attr("data");
	        	thisIs.attr("data", empnodata);
				var empposdata = $("#firstSignEmp option:selected").attr("data2");
	        	thisIs.attr("data2", empposdata);
				var firstname = $("#firstSignEmp option:selected").text();
				var firstno = thisIs.attr("data");
				var firstjob = thisIs.parent().prev().val();
				var firstpos = thisIs.attr("data2");
	        	
	        	var inputHidden = `<div class="removeHidden1">`;
				inputHidden += `<input id="firstname" name="firstname" type="hidden" value="${firstname}" />`;
				inputHidden += `<input id="firstno" name="firstno" type="hidden" value="${firstno}" />`;
				inputHidden += `<input id="firstjob" name="firstjob" type="hidden" value="${firstjob}" />`;
				inputHidden += `<input id="firstpos" name="firstpos" type="hidden" value="${firstpos}" />`;
				inputHidden += `</div>`;
				$(".removeHidden1").remove();
				$("#signLineForm").prepend(inputHidden);
	        });
	        
	        $("#firstSignEmp").trigger("change");
			
		},
		error : function(xhr){
			alert("상태 : " + xhr.status);
		},
		dataType : "json"
	});
}

$.signJobSearch2 = function(signJob){
	$.ajax({
		url : contextPath + "/signJobSearch.do",
		type : "post",
		data : { "signJob" : signJob },
		success : function(res){
			
			var empjob = "";
			$.each(res, function(i, v){
				console.log("v.empjob : " + v.empjob);
				empjob = v.empjob;
			});
			console.log("empjob : " + empjob);
			
			var htmlCode = `<hr class='removeHr2' />
							<div class='removeSecond' style='margin-top: 12px;'>
							<label for="signlinejob">
                                   	부서 선택
                            </label>
							<select id="signlinejob2" name="signlinejob2" class="form-control">`;
								if(empjob == "10"){
                                	htmlCode += `<option value="10" selected>인사팀</option>`;
								}else {
									htmlCode += `<option value="10">인사팀</option>`;
								}
								if(empjob == "20"){
                                	htmlCode += `<option value="20" selected>개발팀</option>`;
								}else {
									htmlCode += `<option value="20">개발팀</option>`;
								}
								if(empjob == "30"){
                                	htmlCode += `<option value="30" selected>사업관리팀</option>`;
								}else {
									htmlCode += `<option value="30">사업관리팀</option>`;
								}
            htmlCode += `</select>
							<label for="secondSignEmp" style='margin-top: 12px;'>
								중간승인자
								<button id="nextSignAdd2" class="btn btn-info btn-sm" type="button" style="margin-left: 94px;">결재자 추가</button>
								<select id="secondSignEmp" name="secondSignEmp" class="form-control">`;
			
			$.each(res, function(i, v){
				//console.log(v);
				htmlCode += `<option value="${v.empjob}">${v.empname}</option>`;
			});
			
			htmlCode += `</select>
					</label>
				</div>`;
			
			$(".removeHr2").remove();
			$(".removeSecond").remove();
			$("#firstSignEmp").after(htmlCode);
			
			$("#signLine>div").css("height", "420px");
			
			$("#signlinejob2").trigger("change");
			
			/*var dupEmpNo1 = $("#firstno").val().trim();
			console.log("dupEmpNo1 : " + dupEmpNo1);
			var newCode = ``;
			$.each(res, function(i, v){
				//console.log(v);
				console.log("v.empno : " + v.empno);
				if(dupEmpNo1 != v.empno){
					console.log(i + " 번째 반복");
					newCode += `<option value="${v.empjob}">${v.empname}</option>`;
				}
			});
			
			$("#secondSignEmp").empty();
			$("#secondSignEmp").html(newCode);*/
			
		},
		error : function(xhr){
			alert("상태 : " + xhr.status);
		},
		dataType : "json"
	});
}

$.signJobSearch3 = function(signJob){
	$.ajax({
		url : contextPath + "/signJobSearch.do",
		type : "post",
		data : { "signJob" : signJob },
		success : function(res){
			
			/*var htmlCode = "";
			$.each(res, function(i, v){
				console.log(v);
				htmlCode += `<option value="${v.empjob}" data="${v.empno}" data2="${v.emppos}">${v.empname}</option>`;
			});
			$("#secondSignEmp").empty();
			$("#secondSignEmp").append(htmlCode);*/
			
			var dupEmpNo1 = $("#firstno").val().trim();
			console.log("dupEmpNo1 : " + dupEmpNo1);
			var newCode = ``;
			$.each(res, function(i, v){
				//console.log(v);
				console.log("v.empno : " + v.empno);
				if(dupEmpNo1 != v.empno){
					console.log(i + " 번째 반복");
					newCode += `<option value="${v.empjob}" data="${v.empno}" data2="${v.emppos}">${v.empname}</option>`;
				}
			});
			
			$("#secondSignEmp").empty();
			$("#secondSignEmp").html(newCode);
			
			$(document).on("change", "#secondSignEmp", function(){
	        	var thisIs = $(this);
	        	var empnodata = $("#secondSignEmp option:selected").attr("data");
				//console.log("empnodata : " + empnodata);
	        	thisIs.attr("data", empnodata);
				var empposdata = $("#secondSignEmp option:selected").attr("data2");
				//console.log("empposdata : " + empposdata);
	        	thisIs.attr("data2", empposdata);
				
				var secondname = $("#secondSignEmp option:selected").text();
				console.log("secondname : " + secondname);
				var secondno = thisIs.attr("data");
				console.log("secondno : " + secondno); // no
				var secondjob = thisIs.parent().prev().val();
				console.log("secondjob : " + secondjob);
				var secondpos = thisIs.attr("data2");
				console.log("secondpos : " + secondpos); // no
	        	
	        	var inputHidden = `<div class="removeHidden2">`;
				inputHidden += `<input id="secondname" name="secondname" type="hidden" value="${secondname}" />`;
				inputHidden += `<input id="secondno" name="secondno" type="hidden" value="${secondno}" />`;
				inputHidden += `<input id="secondjob" name="secondjob" type="hidden" value="${secondjob}" />`;
				inputHidden += `<input id="secondpos" name="secondpos" type="hidden" value="${secondpos}" />`;
				inputHidden += `</div>`;
				$(".removeHidden2").remove();
				$("#signLineForm").prepend(inputHidden);
	        });
	        
	        $("#secondSignEmp").trigger("change");
			
		},
		error : function(xhr){
			alert("상태 : " + xhr.status);
		},
		dataType : "json"
	});
}

$.signJobSearch4 = function(signJob){
	$.ajax({
		url : contextPath + "/signJobSearch.do",
		type : "post",
		data : { "signJob" : signJob },
		success : function(res){
			
			var empjob = "";
			$.each(res, function(i, v){
				console.log("v.empjob : " + v.empjob);
				empjob = v.empjob;
			});
			console.log("empjob : " + empjob);
			
			var htmlCode = `<hr class='removeHr3' />
							<div class='removeThird' style='margin-top: 12px;'>
							<label for="signlinejob">
                                   	부서 선택
                            </label>
							<select id="signlinejob3" name="signlinejob2" class="form-control">`;
								if(empjob == "10"){
                                	htmlCode += `<option value="10" selected>인사팀</option>`;
								}else {
									htmlCode += `<option value="10">인사팀</option>`;
								}
								if(empjob == "20"){
                                	htmlCode += `<option value="20" selected>개발팀</option>`;
								}else {
									htmlCode += `<option value="20">개발팀</option>`;
								}
								if(empjob == "30"){
                                	htmlCode += `<option value="30" selected>사업관리팀</option>`;
								}else {
									htmlCode += `<option value="30">사업관리팀</option>`;
								}
            htmlCode += `</select>
							<label for="thirdSignEmp" style='margin-top: 12px;'>
								최종승인자
								<select id="thirdSignEmp" name="thirdSignEmp" class="form-control">`;
			
			$.each(res, function(i, v){
				//console.log(v);
				htmlCode += `<option value="${v.empjob}">${v.empname}</option>`;
			});
			
			htmlCode += `</select>
					</label>
				</div>`;
			
			$(".removeHr3").remove();
			$(".removeThird").remove();
			$("#secondSignEmp").after(htmlCode);
			
			$("#signLine>div").css("height", "595px");
			
			$("#signlinejob3").trigger("change");
			
			/*var dupEmpNo1 = $("#firstno").val().trim();
			console.log("dupEmpNo1 : " + dupEmpNo1);
			var dupEmpNo2 = $("#secondno").val();
			console.log("dupEmpNo2 : " + dupEmpNo2);
			$.each(res, function(i, v){
				//console.log(v);
				console.log("v.empno : " + v.empno);
				if((dupEmpNo2 != v.empno) && (dupEmpNo1 != v.empno)){
					console.log(i + " 번째 반복");
					htmlCode += `<option value="${v.empjob}">${v.empname}</option>`;
				}
			});
			
			$("#thirdSignEmp").empty();
			$("#thirdSignEmp").html(newCode);*/
			
		},
		error : function(xhr){
			alert("상태 : " + xhr.status);
		},
		dataType : "json"
	});
}

$.signJobSearch5 = function(signJob){
	$.ajax({
		url : contextPath + "/signJobSearch.do",
		type : "post",
		data : { "signJob" : signJob },
		success : function(res){
			
			/*var htmlCode = "";
			$.each(res, function(i, v){
				console.log(v);
				htmlCode += `<option value="${v.empjob}" data="${v.empno}" data2="${v.emppos}">${v.empname}</option>`;
			});
			$("#thirdSignEmp").empty();
			$("#thirdSignEmp").append(htmlCode);*/
			
			var dupEmpNo1 = $("#firstno").val().trim();
			console.log("dupEmpNo1 : " + dupEmpNo1);
			var dupEmpNo2 = $("#secondno").val();
			console.log("dupEmpNo2 : " + dupEmpNo2);
			var newCode = ``;
			$.each(res, function(i, v){
				//console.log(v);
				console.log("v.empno : " + v.empno);
				if((dupEmpNo2 != v.empno) && (dupEmpNo1 != v.empno)){
					console.log(i + " 번째 반복");
					newCode += `<option value="${v.empjob}" data="${v.empno}" data2="${v.emppos}">${v.empname}</option>`;
				}
			});
			
			$("#thirdSignEmp").empty();
			$("#thirdSignEmp").html(newCode);
			
			$(document).on("change", "#thirdSignEmp", function(){
	        	var thisIs = $(this);
	        	var empnodata = $("#thirdSignEmp option:selected").attr("data");
	        	thisIs.attr("data", empnodata);
				var empposdata = $("#thirdSignEmp option:selected").attr("data2");
	        	thisIs.attr("data2", empposdata);
				var thirdname = $("#thirdSignEmp option:selected").text();
				var thirdno = thisIs.attr("data");
				var thirdjob = thisIs.parent().prev().val();
				var thirdpos = thisIs.attr("data2");
	        	
	        	var inputHidden = `<div class="removeHidden3">`;
				inputHidden += `<input id="thirdname" name="thirdname" type="hidden" value="${thirdname}" />`;
				inputHidden += `<input id="thirdno" name="thirdno" type="hidden" value="${thirdno}" />`;
				inputHidden += `<input id="thirdjob" name="thirdjob" type="hidden" value="${thirdjob}" />`;
				inputHidden += `<input id="thirdpos" name="thirdpos" type="hidden" value="${thirdpos}" />`;
				inputHidden += `</div>`;
				$(".removeHidden3").remove();
				$("#signLineForm").prepend(inputHidden);
	        });
	        
	        $("#thirdSignEmp").trigger("change");
			
		},
		error : function(xhr){
			alert("상태 : " + xhr.status);
		},
		dataType : "json"
	});
}

'대덕인재개발원_2nd project' 카테고리의 다른 글

(11) SQL 모음  (0) 2023.10.26
(10) 배경 자료 수집  (0) 2023.10.26
(8) CommonDAO, CommonService 세팅  (0) 2023.10.20
(7) MyBatis 세팅  (0) 2023.10.20
(6) common.css  (0) 2023.10.20