OWL ITS + 탐지시스템(인터넷 진흥원)
이민희
2022-01-12 3b019e5599dfb5d368f4e8fd50fb557f4679a645
src/main/webapp/scripts/app/ispField/ispFieldAdd.controller.js
@@ -14,7 +14,10 @@
                    cancel : cancel,    //  팝업 창 닫기
                    formSubmit : formSubmit,    //  폼 전송
                    formCheck : formCheck,   //  폼 체크
                    autoHyphenPhone : autoHyphenPhone // 연락처 입력시 하이픈 자동 입력
                    addTel : addTel,
                    addMail : addMail,
                    removeTelInput : removeTelInput,
                    removeMailInput : removeMailInput
                };
                $scope.vm = {
@@ -25,7 +28,11 @@
                        tel : "",  //전화번호
                        email : "",  //이메일
                        url : "", // url
                        memo : ""  //비고
                        memo : "",  //비고
                        inputTels : [0], //연락처
                        tels : {},
                        inputMails : [0], //이메일
                        emails : {}
                    }
                };
@@ -37,67 +44,48 @@
                    return false;
                }
                //  연락처 입력시 하이픈 자동 입력
                function autoHyphenPhone() {
                    let phone = $scope.vm.form.tel
                    let seoul = $scope.vm.form.tel
                    // 핸드폰 및 지방 지역번호 조건
                    phone.replace(/^[0-9]/g, '');
                    // 서울 지역번호 조건
                    seoul.replace(/^[0-9]/g, '');
                    var tmp = '';
                    if (phone.length < 4) {
                        return phone;
                    } else if (phone.length < 7) {
                        tmp += phone.substr(0, 3);
                        tmp += '-';
                        tmp += phone.substr(3);
                        $scope.vm.form.tel = tmp;
                    } else if (seoul.substring(0, 2) === "02" && seoul.length === 9) {    // 서울 지역번호 조건
                        tmp += seoul.substring(0, 2);
                        tmp += '-';
                        tmp += seoul.substring(2, 5);
                        tmp += '-';
                        tmp += seoul.substr(5);
                        $scope.vm.form.tel = tmp;
                    } else if (seoul.substring(0, 2) === "02" && seoul.length === 10) {   // 서울 지역번호 조건
                        tmp += seoul.substring(0, 2);
                        tmp += '-';
                        tmp += seoul.substring(2, 6);
                        tmp += '-';
                        tmp += seoul.substr(6);
                        $scope.vm.form.tel = tmp;
                    } else if (phone.length < 11) {     // 핸드폰 및 지방 지역번호 조건
                        tmp += phone.substr(0, 3);
                        tmp += '-';
                        tmp += phone.substr(3, 3);
                        tmp += '-';
                        tmp += phone.substr(6);
                        $scope.vm.form.tel = tmp;
                    } else {                           // 핸드폰 및 지방 지역번호 조건
                        tmp += phone.substr(0, 3);
                        tmp += '-';
                        tmp += phone.substr(3, 4);
                        tmp += '-';
                        tmp += phone.substr(7);
                        $scope.vm.form.tel = tmp;
                    }
                    return phone;
                }
                //  폼 전송
                function formSubmit(condition) {
                    $rootScope.spinner = true;
                    $scope.vm.form.tel = $scope.vm.form.tel.replace(/\-/g,'');  // 전화번호를 보낼땐 하이픈을 제거해서 DB에 저장
                    var content = {
                        code : $rootScope.preventXss($scope.vm.form.code),  //코드
                        name : $rootScope.preventXss($scope.vm.form.name),    //  ISP명
                        manager : $scope.vm.form.manager,   //담당자
                        tel : $scope.vm.form.tel,  //전화번호
                        email : $scope.vm.form.email,  //이메일
                        tels : (function () {
                            var telList = [];
                            if ($scope.vm.form.tels != null) {
                                angular.forEach($scope.vm.form.tels, function (tel) {
                                    telList.push(tel);
                                });
                                telList  = telList.filter(function(item) { //쓰레기 데이터 필터링
                                    return item !== null && item !== undefined && item !== '';
                                });
                                telList  = telList.filter(function(item, idx){
                                    return telList.findIndex(function(item2, idx2){
                                        return item === item2
                                    }) == idx;
                                });
                            }
                            return telList;
                        })(),
                        emails : (function () {
                            var emailList = [];
                            if ($scope.vm.form.emails != null) {
                                angular.forEach($scope.vm.form.emails, function (email) {
                                    emailList.push(email);
                                });
                                emailList  = emailList.filter(function(item) { //쓰레기 데이터 필터링
                                    return item !== null && item !== undefined && item !== '';
                                });
                                emailList  = emailList.filter(function(item, idx){
                                    return emailList.findIndex(function(item2, idx2){
                                        return item === item2
                                    }) == idx;
                                });
                            }
                            return emailList;
                        })(),
                        url : $scope.vm.form.url, // url
                        memo : $scope.vm.form.memo  //비고
                    };
@@ -119,6 +107,54 @@
                }
                // 연락처 input 창 추가 버튼
                function addTel() {
                    var arrayFull = true;      // 배열이 가득 차 있는지 여부
                    var index = 0;
                    $scope.vm.form.inputTels.forEach(function (tel) {
                        if (!$rootScope.isDefined($scope.vm.form.tels[index])) {
                            arrayFull = false;
                        }
                        index++;
                    });
                    if (arrayFull) {
                        $scope.vm.form.inputTels.push(index);
                        $scope.vm.form.tels[index] = "";
                    } else {
                        SweetAlert.warning($filter("translate")("companyField.writeCompanyTel"), $filter("translate")("companyField.writeTel")); // 추가버튼 경고
                    }
                }
                // 메일 주소 input 창 추가 버튼
                function addMail() {
                    var arrayFull = true;      // 배열이 가득 차 있는지 여부
                    var index = 0;
                    $scope.vm.form.inputMails.forEach(function (email) {
                        if (!$rootScope.isDefined($scope.vm.form.emails[index])) {
                            arrayFull = false;
                        }
                        index++;
                    });
                    if (arrayFull) {
                        $scope.vm.form.inputMails.push(index);
                        $scope.vm.form.emails[index] = "";
                    } else {
                        SweetAlert.warning($filter("translate")("issue.writeIssueMail"), $filter("translate")("issue.writeMail")); // 추가버튼 경고
                    }
                }
                // 연락처 input 삭제
                function removeTelInput(index) {
                    $scope.vm.form.inputTels.splice(index, 1);
                }
                // 이메일 주소 input 삭제
                function removeMailInput(index) {
                    $scope.vm.form.inputMails.splice(index, 1);
                }
                //  팝업 창 닫기
                function cancel() {
                    $rootScope.$broadcast("closeLayer");    //  팝업이 열리고 나서 js-multi, js-single 등에서 body 이벤트가 날아가는 현상 수정