| | |
| | | 'app' |
| | | ], |
| | | function (app) { |
| | | app.controller('companyFieldAddController', ['$scope', '$rootScope', '$log', '$resourceProvider', 'SweetAlert', '$uibModal', '$uibModalInstance', '$state', 'CompanyField', '$filter', |
| | | function ($scope, $rootScope, $log, $resourceProvider, SweetAlert, $uibModal, $uibModalInstance, $state, CompanyField, $filter) { |
| | | app.controller('companyFieldAddController', ['$scope', '$rootScope', '$log', '$resourceProvider', 'SweetAlert', '$uibModal', '$uibModalInstance', '$state', 'CompanyField', 'CompanyFieldCategory', '$filter', '$injector','$controller', |
| | | function ($scope, $rootScope, $log, $resourceProvider, SweetAlert, $uibModal, $uibModalInstance, $state, CompanyField, CompanyFieldCategory, $filter, $injector, $controller) { |
| | | |
| | | $scope.fn = { |
| | | cancel : cancel, // 팝업 창 닫기 |
| | | formSubmit : formSubmit, // 폼 전송 |
| | | formCheck : formCheck, // 폼 체크 |
| | | getIssueIspFieldListCallBack : getIssueIspFieldListCallBack, |
| | | getIssueHostingFieldListCallBack : getIssueHostingFieldListCallBack, |
| | | getCompanyTypeListCallBack : getCompanyTypeListCallBack, |
| | | getParentSectorListCallBack : getParentSectorListCallBack, |
| | | getChildSectorListCallBack : getChildSectorListCallBack, |
| | | getRegionListCallBack : getRegionListCallBack, |
| | | getStatusListCallBack : getStatusListCallBack, |
| | | addTel : addTel, |
| | | addMail : addMail, |
| | | addIpRange : addIpRange, |
| | | removeTelInput : removeTelInput, |
| | | removeMailInput : removeMailInput, |
| | | removeIpRangeInput : removeIpRangeInput |
| | | }; |
| | | |
| | | $scope.vm = { |
| | | form : { |
| | | name : "", //업체명 |
| | | companyType : "", //업체분류 |
| | | profitYN : "", //영리/비영리 |
| | | industry : "", //산업분류 |
| | | domain : "", //도메인 |
| | | email : "", //이메일 |
| | | ispId : "", |
| | | ispName : "", |
| | | hostingName : "", |
| | | hostingId : "", |
| | | manager : "", //담당자 |
| | | tel : "", //전화번호 |
| | | desc : "" //메모(비고) |
| | | email : "", //이메일 |
| | | url : "", // url |
| | | ipStart : "", //ip시작주소 |
| | | ipEnd : "", //ip종료주소 |
| | | memo : "", //비고 |
| | | companyTypeId : "", |
| | | companyType : "", //기업구분 |
| | | parentSectorId : "", |
| | | parentSector : "", //업종(대분류) |
| | | childSectorId : "", |
| | | childSector : "", //업종(중분류) |
| | | regionId : "", |
| | | region : "", //지역 |
| | | statusId : "", |
| | | status : "", //상태 |
| | | inputTels : [0], //연락처 |
| | | tels : [], |
| | | inputMails : [0], //이메일 |
| | | emails : [], |
| | | inputIpStarts : [0], //ip 시작점 |
| | | ipStarts : [], |
| | | inputIpEnds : [0], //ip 종료점 |
| | | ipEnds : [] |
| | | }, |
| | | typeCategory : { |
| | | companyType : "COMPANYTYPE", |
| | | parentSector : "PARENTSECTOR", |
| | | childSector : "CHILDSECTOR", |
| | | region : "REGION", |
| | | status : "STATUS" |
| | | }, |
| | | autoCompletePage : { |
| | | ispField : { |
| | | page : 0, |
| | | totalPage : 0 |
| | | }, |
| | | hostingField : { |
| | | page : 0, |
| | | totalPage : 0 |
| | | }, |
| | | companyType : { |
| | | page : 0, |
| | | totalPage : 0 |
| | | }, |
| | | parentSector : { |
| | | page : 0, |
| | | totalPage : 0 |
| | | }, |
| | | childSector : { |
| | | page : 0, |
| | | totalPage : 0 |
| | | }, |
| | | region : { |
| | | page : 0, |
| | | totalPage : 0 |
| | | }, |
| | | status : { |
| | | page : 0, |
| | | totalPage : 0 |
| | | } |
| | | } |
| | | }; |
| | | |
| | | angular.extend(this, $controller('autoCompleteController', {$scope : $scope, $injector : $injector})); |
| | | |
| | | |
| | | // ISP정보 autocomplete page 업데이트 |
| | | function getIssueIspFieldListCallBack(result) { |
| | | $scope.vm.autoCompletePage.ispField.totalPage = result.data.page.totalPage; |
| | | } |
| | | |
| | | // 호스팅정보 autocomplete page 업데이트 |
| | | function getIssueHostingFieldListCallBack(result) { |
| | | $scope.vm.autoCompletePage.hostingField.totalPage = result.data.page.totalPage; |
| | | } |
| | | |
| | | // 기업구분 autocomplete page 업데이트 |
| | | function getCompanyTypeListCallBack(result) { |
| | | $scope.vm.autoCompletePage.companyType.totalPage = result.data.page.totalPage; |
| | | } |
| | | |
| | | // 업종(대분류) autocomplete page 업데이트 |
| | | function getParentSectorListCallBack(result, value) { |
| | | if (value === "") { |
| | | $scope.vm.form.parentSectorId = ""; |
| | | if ($rootScope.isDefined($scope.vm.form.parentSectors) && $rootScope.isDefined($scope.vm.form.parentSectors[0])) { |
| | | $scope.vm.form.parentSectors[0].id = ""; |
| | | } |
| | | $scope.vm.form.childSectorId = ""; |
| | | $scope.vm.form.childSector = ""; |
| | | $scope.vm.form.childSectors = []; |
| | | } |
| | | $scope.vm.autoCompletePage.parentSector.totalPage = result.data.page.totalPage; |
| | | } |
| | | |
| | | // 업종(중분류) 카테고리 autocomplete page 업데이트 |
| | | function getChildSectorListCallBack(result) { |
| | | $scope.vm.autoCompletePage.childSector.totalPage = result.data.page.totalPage; |
| | | } |
| | | |
| | | // 지역 카테고리 autocomplete page 업데이트 |
| | | function getRegionListCallBack(result) { |
| | | $scope.vm.autoCompletePage.region.totalPage = result.data.page.totalPage; |
| | | } |
| | | |
| | | // 상태 카테고리 autocomplete page 업데이트 |
| | | function getStatusListCallBack(result) { |
| | | $scope.vm.autoCompletePage.status.totalPage = result.data.page.totalPage; |
| | | } |
| | | |
| | | // 폼 체크 |
| | | function formCheck(formInvalid) { |
| | |
| | | return false; |
| | | } |
| | | |
| | | $scope.$on("ispFieldEvent", function (event, result) { |
| | | if ($rootScope.isDefined(result) && $rootScope.isDefined(result[0])) { |
| | | $scope.vm.form.ispId = result[0].id; |
| | | } |
| | | }); |
| | | |
| | | $scope.$on("hostingFieldEvent", function (event, result) { |
| | | if ($rootScope.isDefined(result) && $rootScope.isDefined(result[0])) { |
| | | $scope.vm.form.hostingId = result[0].id; |
| | | } |
| | | }); |
| | | |
| | | $scope.$on("companyTypeEvent", function (event, result) { |
| | | if ($rootScope.isDefined(result) && $rootScope.isDefined(result[0])) { |
| | | $scope.vm.form.companyTypeId = result[0].id; |
| | | } |
| | | }); |
| | | $scope.$on("parentSectorEvent", function (event, result) { |
| | | if ($rootScope.isDefined(result) && $rootScope.isDefined(result[0])) { |
| | | $scope.vm.form.parentSectorId = result[0].id; |
| | | } else { |
| | | $scope.vm.form.parentSectorId = ""; |
| | | if ($rootScope.isDefined($scope.vm.form.parentSectors) && $rootScope.isDefined($scope.vm.form.parentSectors[0])) { |
| | | $scope.vm.form.parentSectors[0].id = ""; |
| | | } |
| | | } |
| | | $scope.vm.form.childSectorId = ""; |
| | | $scope.vm.form.childSector = ""; |
| | | $scope.vm.form.childSectors = []; |
| | | }); |
| | | $scope.$on("childSectorEvent", function (event, result) { |
| | | if ($rootScope.isDefined(result) && $rootScope.isDefined(result[0])) { |
| | | $scope.vm.form.childSectorId = result[0].id; |
| | | } |
| | | }); |
| | | $scope.$on("regionEvent", function (event, result) { |
| | | if ($rootScope.isDefined(result) && $rootScope.isDefined(result[0])) { |
| | | $scope.vm.form.regionId = result[0].id; |
| | | } |
| | | }); |
| | | $scope.$on("statusEvent", function (event, result) { |
| | | if ($rootScope.isDefined(result) && $rootScope.isDefined(result[0])) { |
| | | $scope.vm.form.statusId = result[0].id; |
| | | } |
| | | }); |
| | | |
| | | // 폼 전송 |
| | | function formSubmit(condition) { |
| | | $rootScope.spinner = true; |
| | | |
| | | var content = { |
| | | name : $rootScope.preventXss($scope.vm.form.name), // 업체명 |
| | | companyType : $scope.vm.form.companyType, //업체분류 |
| | | profitYN : $scope.vm.form.profitYN, //영리/비영리 |
| | | industry : $scope.vm.form.industry, //산업분류 |
| | | domain : $scope.vm.form.domain, //도메인 |
| | | email : $scope.vm.form.email, //이메일 |
| | | tel : $scope.vm.form.tel, //전화번호 |
| | | desc : $scope.vm.form.desc //메모(비고) |
| | | ispId : (function () { // ISP 아이디 |
| | | var ispId = null; |
| | | if ($scope.vm.form.issueIspFields != null) { |
| | | ispId = $scope.vm.form.ispId; |
| | | } |
| | | return ispId; |
| | | })(), |
| | | hostingId : (function () { // Hosting 아이디 |
| | | var hostingId = null; |
| | | if ($scope.vm.form.issueHostingFields != null) { |
| | | hostingId = $scope.vm.form.hostingId; |
| | | } |
| | | return hostingId; |
| | | })(), |
| | | manager : $scope.vm.form.manager, //담당자 |
| | | 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 : (function () { |
| | | // 모든 공백 제거 |
| | | var regex = / /gi; |
| | | let url = $scope.vm.form.url; |
| | | if ($rootScope.isDefined(url) && url.indexOf(" ") !== -1) { |
| | | url = url.replace(regex, ""); |
| | | } |
| | | return url; |
| | | })(), |
| | | ipStarts : (function () { |
| | | var ipStarts = []; |
| | | if ($scope.vm.form.ipStarts != null) { |
| | | angular.forEach($scope.vm.form.ipStarts, function (ipS) { |
| | | ipStarts.push(ipS); |
| | | }); |
| | | ipStarts = ipStarts.filter(function(item) { //쓰레기 데이터 필터링 |
| | | return item !== null && item !== undefined && item !== ''; |
| | | }); |
| | | } |
| | | return ipStarts; |
| | | })(), |
| | | ipEnds : (function () { |
| | | var ipEnds = []; |
| | | if ($scope.vm.form.ipEnds != null) { |
| | | angular.forEach($scope.vm.form.ipEnds, function (ipE) { |
| | | ipEnds.push(ipE); |
| | | }); |
| | | ipEnds = ipEnds.filter(function(item) { //쓰레기 데이터 필터링 |
| | | return item !== null && item !== undefined && item !== ''; |
| | | }); |
| | | } |
| | | return ipEnds; |
| | | })(), |
| | | memo : $scope.vm.form.memo, //비고 |
| | | companyTypeId : (function () { |
| | | var companyTypeId = null; |
| | | if ($scope.vm.form.companyTypes != null && $scope.vm.form.companyTypes.length > 0) { |
| | | companyTypeId = $scope.vm.form.companyTypes[0].id; |
| | | } |
| | | return companyTypeId; |
| | | })(), |
| | | parentSectorId : (function () { |
| | | var parentSectorId = null; |
| | | if ($scope.vm.form.parentSectors != null && $scope.vm.form.parentSectors.length > 0) { |
| | | parentSectorId = $scope.vm.form.parentSectors[0].id; |
| | | } |
| | | return parentSectorId; |
| | | })(), |
| | | childSectorId : (function () { |
| | | var childSectorId = null; |
| | | if ($scope.vm.form.childSectors != null && $scope.vm.form.childSectors.length > 0) { |
| | | childSectorId = $scope.vm.form.childSectors[0].id; |
| | | } |
| | | return childSectorId; |
| | | })(), |
| | | regionId : (function () { |
| | | var regionId = null; |
| | | if ($scope.vm.form.regions != null && $scope.vm.form.regions.length > 0) { |
| | | regionId = $scope.vm.form.regions[0].id; |
| | | } |
| | | return regionId; |
| | | })(), |
| | | statusId : (function () { |
| | | var statusId = null; |
| | | if ($scope.vm.form.statuses != null && $scope.vm.form.statuses.length > 0) { |
| | | statusId = $scope.vm.form.statuses[0].id; |
| | | } else if ($scope.vm.form.status !== ""){ |
| | | statusId = 120; //직접입력 일 경우 |
| | | } |
| | | return statusId; |
| | | })(), |
| | | statusName : $scope.vm.form.status |
| | | }; |
| | | |
| | | // ip 대역대 유효성 체크 |
| | | let result = ipRangeChk(content.ipStarts, content.ipEnds); |
| | | if (!result) { |
| | | $rootScope.spinner = false; |
| | | return; |
| | | } |
| | | |
| | | CompanyField.add($resourceProvider.getContent(content, |
| | | $resourceProvider.getPageContent(0, 10))).then(function (result) { |
| | | |
| | | if (result.data.message.status === "success") { |
| | | $scope.fn.cancel(); |
| | | // 목록 화면 갱신 |
| | | $rootScope.$broadcast("getDepartmentList", {}); |
| | | $rootScope.$broadcast("getPageList", {}); |
| | | } |
| | | else { |
| | | SweetAlert.error($filter("translate")("managementWorkspace.failedLevelRegistration"), result.data.message.message); |
| | | SweetAlert.warning($filter("translate")("companyField.failedCompanyFieldRegistration"), result.data.message.message); |
| | | } |
| | | |
| | | $rootScope.spinner = false; |
| | | }); |
| | | } |
| | | |
| | | // ip 대역대 유효성 검사 |
| | | function ipRangeChk(ipStarts, ipEnds) { |
| | | let result = true; |
| | | |
| | | if ($rootScope.isDefined(ipStarts) && $rootScope.isDefined(ipEnds)) { |
| | | if (ipStarts.length !== ipEnds.length) { |
| | | SweetAlert.warning($filter("translate")("companyField.ipRangeError"), $filter("translate")("companyField.ipRangeNotEnter")); |
| | | result = false; |
| | | return; |
| | | } |
| | | |
| | | let ipStartArr = []; |
| | | let ipEndArr = []; |
| | | |
| | | for (let i=0; i<ipStarts.length; i++) { |
| | | let ipStart = ipToLong(ipStarts[i]); |
| | | let ipEnd = ipToLong(ipEnds[i]); |
| | | if (ipEnd < ipStart) { |
| | | SweetAlert.warning($filter("translate")("companyField.ipRangeError"), $filter("translate")("companyField.ipStartNotLargerThanEnd")); |
| | | result = false; |
| | | return; |
| | | } |
| | | ipStartArr.push(ipStart); |
| | | ipEndArr.push(ipEnd); |
| | | } |
| | | |
| | | for (let i=0; i<ipStartArr.length; i++) { |
| | | if ($rootScope.isDefined(ipStartArr[i+1])) { |
| | | if((ipStartArr[i] >= ipStartArr[i+1] && ipStartArr[i] <= ipEndArr[i+1]) |
| | | || (ipEndArr[i] >= ipStartArr[i+1] && ipEndArr[i] <= ipEndArr[i+1])) { |
| | | SweetAlert.warning($filter("translate")("companyField.ipRangeError"), $filter("translate")("companyField.ipRangeNotOverlap")); |
| | | result = false; |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | // ip 주소 숫자로 변환 |
| | | function ipToLong(ip) { |
| | | let result = 0; |
| | | let ipArr = ip.split("."); |
| | | |
| | | for (let i=0; i<ipArr.length; i++) { |
| | | result += parseInt(ipArr[i]) * Math.pow(256, 3-i); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | // 연락처 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")); // 추가버튼 경고 |
| | | } |
| | | } |
| | | |
| | | // IPRange input 창 추가 버튼 |
| | | function addIpRange() { |
| | | var arrayFull = true; // 배열이 가득 차 있는지 여부 |
| | | var startIdx = 0; |
| | | var endIdx = 0; |
| | | $scope.vm.form.inputIpStarts.forEach(function (start) { |
| | | if (!$rootScope.isDefined($scope.vm.form.ipStarts[startIdx])) { |
| | | arrayFull = false; |
| | | } |
| | | startIdx++; |
| | | }); |
| | | |
| | | $scope.vm.form.inputIpEnds.forEach(function (start) { |
| | | if (!$rootScope.isDefined($scope.vm.form.ipEnds[endIdx])) { |
| | | arrayFull = false; |
| | | } |
| | | endIdx++; |
| | | }); |
| | | |
| | | if (arrayFull) { |
| | | $scope.vm.form.inputIpStarts.push(startIdx); |
| | | $scope.vm.form.ipStarts[startIdx] = ""; |
| | | $scope.vm.form.inputIpEnds.push(endIdx); |
| | | $scope.vm.form.ipEnds[endIdx] = ""; |
| | | } else { |
| | | SweetAlert.warning($filter("translate")("companyField.writeCompanyIpRange"), $filter("translate")("companyField.writeIpRange")); // 추가버튼 경고 |
| | | } |
| | | } |
| | | |
| | | // 연락처 input 삭제 |
| | | function removeTelInput(index) { |
| | | $scope.vm.form.inputTels.splice(index, 1); |
| | | $scope.vm.form.tels.splice(index, 1); |
| | | } |
| | | |
| | | // 이메일 주소 input 삭제 |
| | | function removeMailInput(index) { |
| | | $scope.vm.form.inputMails.splice(index, 1); |
| | | $scope.vm.form.emails.splice(index, 1); |
| | | } |
| | | |
| | | // ipRange input 삭제 |
| | | function removeIpRangeInput(index) { |
| | | $scope.vm.form.inputIpStarts.splice(index, 1); |
| | | $scope.vm.form.ipStarts.splice(index, 1); |
| | | $scope.vm.form.inputIpEnds.splice(index, 1); |
| | | $scope.vm.form.ipEnds.splice(index, 1); |
| | | } |
| | | |
| | | // 팝업 창 닫기 |
| | |
| | | $uibModalInstance.dismiss('cancel'); |
| | | $(document).unbind("keydown"); // 단축키 이벤트 제거 |
| | | } |
| | | |
| | | } |
| | | |
| | | ]); |
| | | } |
| | | ); |