/** * Created by wisestone on 2017-12-15. */ 'use strict'; define([ 'app', 'angular' ], function (app, angular) { app.controller('issueModifyController', ['$scope', '$rootScope', '$log', '$resourceProvider', '$uibModalInstance', '$injector', '$controller', '$tableProvider', 'SweetAlert', '$timeout', '$stateParams', '$q', 'parameter', 'Issue', 'User', 'AttachedFile', 'IssueType', 'Priority', 'Severity', 'HostingField', 'IssueTypeCustomField', '$filter', function ($scope, $rootScope, $log, $resourceProvider, $uibModalInstance, $injector, $controller, $tableProvider, SweetAlert, $timeout, $stateParams, $q, parameter, Issue, User, AttachedFile, IssueType, Priority, Severity, HostingField, IssueTypeCustomField, $filter) { $scope.fn = { cancel : cancel, // 팝업 창 닫기 formSubmit : formSubmit, // 폼 전송 formCheck : formCheck, // 폼 체크 getUserListCallBack : getUserListCallBack, // 담당자 autocomplete 페이징 getProjectListCallBack : getProjectListCallBack, // 프로젝트 autocomplete 페이징 getIssueCompanyFieldListCallBack : getIssueCompanyFieldListCallBack, // 업체정보 autocomplete 페이징 getIssueDepartmentListCallBack : getIssueDepartmentListCallBack, // 담당자 -> 담당부서 autocomplete 페이징 getIssueIspFieldListCallBack : getIssueIspFieldListCallBack, // ISP정보 autocomplete 페이징 getIssueHostingFieldListCallBack : getIssueHostingFieldListCallBack, // 호스팅정보 autocomplete 페이징 getOptionColor : getOptionColor, // 우선순위, 중요도 색상으로 Select 태그 적용 onFileSelect : onFileSelect, // 파일 첨부 imageUpload : imageUpload, // 섬머노트 이미지 업로드 getIssueTypes : getIssueTypes, // 이슈 타입 목록 가져오기 getPriorities : getPriorities, // 우선순위 목록 가져오기 getSeverities : getSeverities, // 중요도 목록 가져오기 getIssueTypeCustomFields : getIssueTypeCustomFields, // 이슈 유형에 연결된 사용자 정의 필드 목록 가져오기 setFormByIssueTypeCustomFields : setFormByIssueTypeCustomFields, // 이슈 유형에 연결된 사용자 정의 필드 정보를 입력 폼에서 사용할 수 있게 가공한다. setUseValueByIssueTypeCustomFields : setUseValueByIssueTypeCustomFields, // 이슈에서 사용자가 선택한 사용자 정의 필드 값을 입력 폼에 셋팅한다. detail : detail, // 이슈 정보 조회 removeManager : removeManager, // 담당자 삭제 removeDepartment : removeDepartment, // 담당부서 삭제 removeUploadFile : removeUploadFile, // 특정 파일을 삭제 setIssueTypeTemplate : setIssueTypeTemplate, // 이슈 유형 템플릿 적용하기 startExecute : startExecute, // 최초 실행 containsPartner : containsPartner, getPartners : getPartners, getCompanyTypeListCallBack : getCompanyTypeListCallBack, getParentSectorListCallBack : getParentSectorListCallBack, getChildSectorListCallBack : getChildSectorListCallBack, getRegionListCallBack : getRegionListCallBack, getStatusListCallBack : getStatusListCallBack, }; $scope.vm = { partnerVos : "", search : { id : parameter.id, deep : "02" // 프로젝트 연관된 모든 정보를 어느정도까지 가져올지 결정, 01 - 사용자, 관리자 정보 }, form : { title : "", // 제목 description : "", // 내용 projects : [], // 프로젝트 issueCompanyFields : [], // 업체정보 issueIspFields : [], // ISP 정보 issueHostingFields : [], // 호스팅정보 issueTypeId : parameter.issueTypeId, // 이슈 유형 아이디 priorityId : "", // 우선순위 아이디 severityId : "", // 중요도 아이디 issueStatusId : "", // 이슈 상태 아이디 // users : [], // 담당자 departments : [], // 담당부서 files : [], // 업로드 파일 attachedFiles : [], // 섬머노트로 파일 업로드를 할 경우 서버에서 pk를 따고 issue id와 연동 작업이 필요하다. startCompleteDateRange : "", // 시작일 ~ 종료일 issueCustomFields : [], // 이슈에서 사용되는 사용자 정의 필드 removeFiles : [], // 삭제한 파일 정보 companyTypeId : "", companyType : "", //기업구분 parentSectorId : "", parentSector : "", //업종(대분류) childSectorId : "", childSector : "", //업종(중분류) regionId : "", region : "", //지역 statusId : "", status : "", //상태 }, typeCategory : { companyType : "COMPANYTYPE", parentSector : "PARENTSECTOR", childSector : "CHILDSECTOR", region : "REGION", status : "STATUS" }, projectName : "", // 프로젝트 명 검색 userName : "", // 사용자 검색 departmentName : "", // 부서명 검색 companyId : -1, companyName : "", // 업체명 검색 companyManager : "", // 업체 담당자 companyTel : "", // 업체 전화번호 companyEmail : "", // 업체 이메일 companyUrl : "", // 업체 url ipStart : "", //ip시작주소 ipEnd : "", //ip종료주소 companyMemo : "", // 업체 비고 ispId : -1, ispName : "", // ISP 명 ispCode : "", // ISP 코드 ispManager : "", // ISP 담당자 ispTel : "", // ISP 전화번호 ispEmail : "", // ISP 이메일 ispUrl : "", // url ispMemo : "", // ISP 비고 hostingId : -1, hostingName : "", // 호스팅명 검색 hostingManager : "", // 호스팅 담당자 hostingCode : "", // 호스팅 코드 hostingTel : "", // 호스팅 전화번호 hostingEmail : "", // 호스팅 이메일 hostingUrl : "", // url hostingMemo : "", // 호스팅 비고 autoCompletePage : { // user : { // page : 0, // totalPage : 0 // }, project : { page : 0, totalPage : 0 }, issueCompanyField : { page : 0, totalPage : 0 }, department : { page : 0, totalPage : 0 }, 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 } }, summerNote : { editable : null, editor : null }, issueTypes : [], // 이슈 유형 전체 목록 priorities : [], // 우선순위 정보 severities : [], // 중요도 정보 fileTableConfigs : [], // 파일 업로드 정보 테이블 inheritPartners : parameter.inheritPartners, downTotalCount : parameter.downTotalCount, usePartner : parameter.usePartner, }; // 연관 일감 관련 $scope.vm.relationIssueTypes = [ { id: 0, name: $filter("translate")("issue.relationIssueType1") }, { id: 1, name: $filter("translate")("issue.relationIssueType2") }, { id: 2, name: $filter("translate")("issue.relationIssueType3") }, { id: 3, name: $filter("translate")("issue.relationIssueType4") }, { id: 4, name: $filter("translate")("issue.relationIssueType5") }, { id: 5, name: $filter("translate")("issue.relationIssueType6") } ]; $scope.vm.relationIssueType = $scope.vm.relationIssueTypes[0]; angular.extend(this, $controller('autoCompleteController', {$scope : $scope, $injector : $injector})); // 프로젝트가 변경되면 담당부서 초기화 $scope.$watch("vm.form.projects", function (newValue, oldValue) { if (angular.isDefined(newValue)) { if (newValue.length < 1) { $scope.vm.form.departments = []; $scope.vm.form.issueCustomFields = []; } else { if ($rootScope.isDefined($scope.vm.form.issueTypeId)) { $scope.fn.getIssueTypeCustomFields(); } } } }); $scope.$watch("vm.form.issueTypeId", function (newValue, oldValue) { $scope.vm.partnerVos = $scope.fn.getPartners(); }); // 업로드 파일 삭제 function removeUploadFile(index) { var temp = []; for (var count in $scope.vm.form.files) { var file = $scope.vm.form.files[count]; if (String(index) === count) { if ($rootScope.isDefined(file.id)) { $scope.vm.form.removeFiles.push(file.id); } } else { temp.push(file); } } $scope.vm.form.files = temp; } // 담당자 삭제 function removeManager(index) { $scope.vm.form.users.splice(index, 1); } // 담당부서 삭제 function removeDepartment(index) { $scope.vm.form.departments.splice(index, 1); } // 섬머노트 이미지 업로드 function imageUpload($files) { var listFiles = []; var uploadFileSize = 0; for (var count in $files) { var $file = $files[count]; if (typeof ($file) == "object") { uploadFileSize += $file.size; // 파일당 용량 제한 10MB if ($file.size > $rootScope.fileByte.image) { SweetAlert.error($filter("translate")("issue.capacityExceededImageFile"), $filter("translate")("issue.attachedOnlyImageFiles10mb")); // "이미지 파일 용량 초과", "10MB 이하의 이미지 파일만 첨부가 가능합니다." listFiles = []; break; } // 여러건의 파일을 한번에 업로드할 경우 제한 300MB if (uploadFileSize > $rootScope.fileByte.file) { SweetAlert.error($filter("translate")("issue.capacityExceededImageFile"), $filter("translate")("issue.attachedMultipleImageFiles100mb")); // "이미지 파일 용량 초과", "여러 건의 이미지를 한번에 첨부할 경우 100MB 이하까지만 첨부가 가능합니다." listFiles = []; break; } if (!$rootScope.checkImageType($file)) { SweetAlert.error($filter("translate")("issue.limitImageFile"), $filter("translate")("issue.canBeUploadedOnlyImageFiles")); // "이미지 파일 제한", "이미지 파일만 업로드 가능합니다. - bmp, jpg, jpeg, png, tif" listFiles = []; break; } if (!angular.isDefined($file.name)) { var fileType = $file.type.split("/"); var imageType = ""; if (fileType[0] === "image") { imageType = "." + fileType[1]; } $file.name = new Date().getTime() + imageType; } else { if ($file.name.indexOf(';') !== -1) { SweetAlert.error($filter("translate")("issue.nameErrorImageFile"), $filter("translate")("issue.cannotUploadFileNameSpecialCharacters")); // "이미지 파일명 오류", "파일명에 특수문자(;)가 들어가면 업로드 할 수 없습니다." listFiles = []; break; } } listFiles.push($file); } } // 파일 업로드 검증을 거친 파일이 1개이상 존재할 경우에만 실행 if (listFiles.length > 0) { AttachedFile.add({ method : "POST", file : listFiles, // data 속성으로 별도의 데이터 전송 fields : { content : { workspaceId : $rootScope.user.lastWorkspaceId, issueId : parameter.id } }, fileFormDataName : "file" }) .then(function (result) { if (result.data.message.status === "success") { angular.forEach(result.data.attachedFiles, function (fileInfo) { $scope.vm.summerNote.editor.summernote("editor.insertImage", fileInfo.path); $scope.vm.form.attachedFiles.push(fileInfo); }); } else { SweetAlert.error($filter("translate")("issue.errorFileUpload"), result.data.message.message); // 파일 업로드 오류 } }); } } // 파일 업로드에 사용 function onFileSelect($files) { var uploadFileSize = 0; // 이전에 첨부한 파일이 있을 경우 전체 업로드 용량에 포함 angular.forEach($scope.vm.form.files, function ($file) { uploadFileSize += $file.size; }); for (var count in $files) { var $file = $files[count]; if (typeof ($file) == "object") { uploadFileSize += $file.size; // 파일당 용량 제한 300MB if (($file.size > $rootScope.fileByte.file) || (uploadFileSize > $rootScope.fileByte.file)) { SweetAlert.error($filter("translate")("issue.attachmentCapacityExceeded"), $filter("translate")("issue.canAttachFileUpTo100mb")); // "첨부 파일 용량 초과", "100MB 이하까지만 파일 첨부가 가능합니다." break; } // 파일을 업로드할 때 파일 유형을 확인해주는 기능 - 허용되지 않은 확장자일 때는 첨부 금지 if (!$rootScope.checkFileType($file)) { SweetAlert.error($filter("translate")("issue.limitAttachmentExtensions"), $filter("translate")("issue.notAllowedAttachment")); // "첨부 파일 확장자 제한", "첨부가 허용되지 않는 파일입니다." break; } if ($file.name.indexOf(';') !== -1) { SweetAlert.error($filter("translate")("issue.nameErrorAttachment"), $filter("translate")("issue.cannotUploadFileNameSpecialCharacters")); // "첨부 파일명 오류", "파일명에 특수문자(;)가 들어가면 업로드 할 수 없습니다." break; } $file.index = count; $scope.vm.form.files.push($file); } } } // 셀렉트 박스에서 중요도, 우선순위 색상 표시 function getOptionColor(list, key) { var color = "#353535"; // 기본색은 검은색. for (var count in list) { if (String(list[count].id) === key) { color = list[count].color; break; } } return color; } // 담당자 autocomplete page 업데이트트 function getUserListCallBack(result) { $scope.vm.autoCompletePage.user.totalPage = result.data.page.totalPage; } // 프로젝트 autocomplete page 업데이트 function getProjectListCallBack(result) { $scope.vm.autoCompletePage.project.totalPage = result.data.page.totalPage; } // 업체정보 autocomplete page 업데이트 function getIssueCompanyFieldListCallBack(result) { $scope.vm.autoCompletePage.issueCompanyField.totalPage = result.data.page.totalPage; } // 부서정보 autocomplete page 업데이트 function getIssueDepartmentListCallBack(result) { $scope.vm.autoCompletePage.department.totalPage = result.data.page.totalPage; } // 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) { if (formInvalid) { return true; } if ($scope.vm.form.projects.length < 1) { return true; } return false; } $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; } }); // 업체정보 결과 값 Event 처리(set) $scope.$on("companyFieldEvent", function (event, result) { if ($rootScope.isDefined(result) && $rootScope.isDefined(result[0])) { var ispFieldVo = result[0].ispFieldVo; var hostingFieldVo = result[0].hostingFieldVo; $scope.vm.companyId = result[0].id; $scope.vm.companyName = result[0].name; $scope.vm.companyManager = result[0].manager; $scope.vm.companyTel = result[0].tel; $scope.vm.companyEmail = result[0].email; $scope.vm.companyUrl = result[0].url; $scope.vm.ipStart = result[0].ipStart; $scope.vm.ipEnd = result[0].ipEnd; $scope.vm.companyMemo = result[0].memo; $scope.vm.form.companyTypeId = result[0].companyTypeId; $scope.vm.form.parentSectorId = result[0].parentSectorId; $scope.vm.form.childSectorId = result[0].childSectorId; $scope.vm.form.regionId = result[0].regionId; $scope.vm.form.statusId = result[0].statusId; $scope.vm.form.companyType = result[0].companyTypeName; $scope.vm.form.parentSector = result[0].parentSectorName; $scope.vm.form.childSector = result[0].childSectorName; $scope.vm.form.region = result[0].regionName; $scope.vm.form.status = result[0].statusName; $scope.vm.ispId = ""; $scope.vm.ispName = ""; $scope.vm.ispCode = ""; $scope.vm.ispManager = ""; $scope.vm.ispTel = ""; $scope.vm.ispEmail = ""; $scope.vm.ispUrl = ""; $scope.vm.ispMemo = ""; $scope.vm.hostingId = ""; $scope.vm.hostingName = ""; $scope.vm.hostingCode = ""; $scope.vm.hostingManager = ""; $scope.vm.hostingTel = ""; $scope.vm.hostingEmail = ""; $scope.vm.hostingUrl = ""; $scope.vm.hostingMemo = ""; if (ispFieldVo != null) { $scope.vm.form.issueIspFields[0] = angular.copy(ispFieldVo); $scope.vm.ispId = ispFieldVo.id; $scope.vm.ispName = ispFieldVo.name; $scope.vm.ispCode = ispFieldVo.code; $scope.vm.ispManager = ispFieldVo.manager; $scope.vm.ispTel = ispFieldVo.tel; $scope.vm.ispEmail = ispFieldVo.email; $scope.vm.ispUrl = ispFieldVo.url; $scope.vm.ispMemo = ispFieldVo.memo; } if (hostingFieldVo != null) { $scope.vm.form.issueHostingFields[0] = angular.copy(hostingFieldVo); $scope.vm.hostingId = hostingFieldVo.id; $scope.vm.hostingName = hostingFieldVo.name; $scope.vm.hostingCode = hostingFieldVo.code; $scope.vm.hostingManager = hostingFieldVo.manager; $scope.vm.hostingTel = hostingFieldVo.tel; $scope.vm.hostingEmail = hostingFieldVo.email; $scope.vm.hostingUrl = hostingFieldVo.url; $scope.vm.hostingMemo = hostingFieldVo.memo; } } }); // ISP정보 결과 값 Event 처리(set) $scope.$on("ispFieldEvent", function (event, result) { if ($rootScope.isDefined(result) && $rootScope.isDefined(result[0])) { $scope.vm.ispId = result[0].id; $scope.vm.ispName = result[0].name; $scope.vm.ispCode = result[0].code; $scope.vm.ispManager = result[0].manager; $scope.vm.ispTel = result[0].tel; $scope.vm.ispEmail = result[0].email; $scope.vm.ispUrl = result[0].url; $scope.vm.ispMemo = result[0].memo; } }); // 호스팅정보 결과 값 Event 처리(set) $scope.$on("hostingFieldEvent", function (event, result) { if ($rootScope.isDefined(result) && $rootScope.isDefined(result[0])) { $scope.vm.hostingId = result[0].id; $scope.vm.hostingName = result[0].name; $scope.vm.hostingCode = result[0].code; $scope.vm.hostingManager = result[0].manager; $scope.vm.hostingTel = result[0].tel; $scope.vm.hostingEmail = result[0].email; $scope.vm.hostingUrl = result[0].url; $scope.vm.hostingMemo = result[0].memo; } }); function formSubmit() { $rootScope.spinner = true; let inheritYn = false; var content = { id : parameter.id, title : $rootScope.preventXss($scope.vm.form.title), // 제목 description : $rootScope.preventXss($scope.vm.form.description), // 내용 inheritYn : inheritYn, companyName : $scope.vm.companyName, companyManager : $scope.vm.companyManager, companyTel : $scope.vm.companyTel, companyEmail :$scope.vm.companyEmail, companyUrl : $scope.vm.companyUrl, ipStart :$scope.vm.ipStart, ipEnd :$scope.vm.ipEnd, companyMemo : $scope.vm.companyMemo, companyTypeId : (function () { var companyTypeId = null; if ($scope.vm.form.companyTypes != null && $scope.vm.form.companyTypes.length > 0) { companyTypeId = $scope.vm.form.companyTypes[0].id; } else { companyTypeId = $scope.vm.form.companyTypeId; } 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; } else { parentSectorId = $scope.vm.form.parentSectorId; } 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; } else { childSectorId = $scope.vm.form.childSectorId; } 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; } else { regionId = $scope.vm.form.regionId; } 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 { statusId = $scope.vm.form.statusId; } return statusId; })(), statusName : $scope.vm.form.status, ispName : $scope.vm.ispName, ispCode : $scope.vm.ispCode, ispManager : $scope.vm.ispManager, ispTel : $scope.vm.ispTel, ispEmail : $scope.vm.ispEmail, ispUrl : $scope.vm.ispUrl, ispMemo : $scope.vm.ispMemo, hostingName : $scope.vm.hostingName, hostingCode : $scope.vm.hostingCode, hostingManager : $scope.vm.hostingManager, hostingTel : $scope.vm.hostingTel, hostingEmail : $scope.vm.hostingEmail, hostingUrl : $scope.vm.hostingUrl, hostingMemo : $scope.vm.hostingMemo, projectId : (function () { // 프로젝트 아이디 var projectId = ""; if ($scope.vm.form.projects.length > 0) { projectId = $scope.vm.form.projects[0].id; } return projectId; })(), issueTypeId : $scope.vm.form.issueTypeId, // 이슈 유형 아이디 priorityId : $scope.vm.form.priorityId, // 우선순위 아이디 severityId : $scope.vm.form.severityId, // 중요도 아이디 issueStatusId : $scope.vm.form.issueStatusId, // 이슈 상태 아이디 companyId : (function () { var companyId = null; if ($scope.vm.form.issueCompanyFields != null && $scope.vm.form.issueCompanyFields.length > 0) { companyId = $scope.vm.form.issueCompanyFields[0].id; } return companyId; }), ispId : (function () { var ispId = null; if ($scope.vm.form.issueIspFields != null && $scope.vm.form.issueIspFields.length > 0) { ispId = $scope.vm.form.issueIspFields[0].id; } return ispId; }), hostingId : (function () { var hostingId = null; if ($scope.vm.form.issueHostingFields != null && $scope.vm.form.issueHostingFields.length > 0) { hostingId = $scope.vm.form.issueHostingFields[0].id; } return hostingId; }), userIds : (function () { var userIds = []; angular.forEach($scope.vm.form.users, function (user) { userIds.push(user.id); }); return userIds; })(), departmentIds : (function () { var departmentIds = []; angular.forEach($scope.vm.form.departments, function (department) { departmentIds.push(department.id); }); return departmentIds; })(), attachedFileIds : (function () { var attachedFileIds = []; angular.forEach($scope.vm.form.attachedFiles, function (attachedFile) { if ($scope.vm.form.description.indexOf(attachedFile.path) !== -1) { attachedFileIds.push(attachedFile.id); } }); return attachedFileIds; })(), issueCompanyFields : (function () { var issueCompanyFields = []; if ($scope.vm.form.issueCompanyFields != null && $scope.vm.form.issueCompanyFields.length > 0 ){ var companyField = $scope.vm.form.issueCompanyFields[0]; //사용자가 직접 업체 추가 할 경우 if ($rootScope.isDefined(companyField) && companyField.name !== $scope.vm.companyName) { return issueCompanyFields; } issueCompanyFields.push({ id : companyField.id, companyId : $scope.vm.companyId, name : $scope.vm.companyName, manager : $scope.vm.companyManager, tel : $scope.vm.companyTel, email :$scope.vm.companyEmail, url :$scope.vm.companyUrl, ipStart :$scope.vm.ipStart, ipEnd :$scope.vm.ipEnd, memo : $scope.vm.companyMemo, companyTypeId : $scope.vm.form.companyTypeId, parentSectorId : $scope.vm.form.parentSectorId, childSectorId : $scope.vm.form.childSectorId, regionId : $scope.vm.form.regionId, statusId : $scope.vm.form.statusId, statusName : $scope.vm.form.status }); } return issueCompanyFields; })(), issueIspFields : (function () { var issueIspFields = []; if ($scope.vm.form.issueCompanyFields != null && $scope.vm.form.issueCompanyFields.length > 0 && $scope.vm.form.issueCompanyFields[0].ispFieldVo != null || $scope.vm.form.issueIspFields != null && $scope.vm.form.issueIspFields.length > 0 ){ var ispField = $scope.vm.form.issueIspFields[0]; //사용자가 직접 ISP 추가 할 경우 if ($rootScope.isDefined(ispField) && ispField.name !== $scope.vm.ispName) { return issueIspFields; } issueIspFields.push({ ispId : $scope.vm.ispId, code : $scope.vm.ispCode, name : $scope.vm.ispName, manager : $scope.vm.ispManager, tel : $scope.vm.ispTel, email :$scope.vm.ispEmail, url :$scope.vm.ispUrl, memo : $scope.vm.ispMemo }); } return issueIspFields; })(), issueHostingFields : (function () { var issueHostingFields = []; if ($scope.vm.form.issueCompanyFields != null && $scope.vm.form.issueCompanyFields.length > 0 && $scope.vm.form.issueCompanyFields[0].hostingFieldVo != null || $scope.vm.form.issueHostingFields != null && $scope.vm.form.issueHostingFields.length > 0 ){ var hostingField = $scope.vm.form.issueHostingFields[0]; //사용자가 직접 호스팅 추가 할 경우 if ($rootScope.isDefined(hostingField) && hostingField.name !== $scope.vm.hostingName) { return issueHostingFields; } issueHostingFields.push({ hostingId : $scope.vm.hostingId, name : $scope.vm.hostingName, code : $scope.vm.hostingCode, manager : $scope.vm.hostingManager, tel : $scope.vm.hostingTel, email :$scope.vm.hostingEmail, url :$scope.vm.hostingUrl, memo : $scope.vm.hostingMemo }); } return issueHostingFields; })(), removeFiles : $scope.vm.form.removeFiles, startCompleteDateRange : $scope.vm.form.startCompleteDateRange, issueCustomFields : (function () { // 이슈에서 사용되는 사용자 정의 필드 var issueCustomFields = []; angular.forEach($scope.vm.form.issueCustomFields, function (issueCustomField) { var useValues = []; if (angular.isArray(issueCustomField.useValues)) { angular.forEach(issueCustomField.useValues, function (useValue) { useValues.push(useValue.value); }); } else { useValues.push(issueCustomField.useValues); } // useValues 를 배열로 변환한다. var temp = angular.copy(issueCustomField); temp.useValues = useValues; issueCustomFields.push(temp); }); return issueCustomFields; })() }; if ($rootScope.isDefined($scope.vm.usePartner) && $scope.vm.usePartner.length > 0 && $rootScope.isDefined($scope.vm.inheritPartners) && $scope.vm.inheritPartners && $rootScope.isDefined($scope.vm.downTotalCount) && $scope.vm.downTotalCount > 0) { SweetAlert.swal({ title : $filter("translate")("issue.modifyIssues"), // 이슈 변경 text : $filter("translate")("issue.wantToInheritPartnersOfIssue"), // 현재 이슈의 파트너 정보(업체/ISP/호스팅)를 모든 하위이슈에 일괄 적용시키겠습니까? type : "warning", showCancelButton : true, confirmButtonColor : "#DD6B55", confirmButtonText : $filter("translate")("common.ok"), // 네 cancelButtonText : $filter("translate")("common.no"), // 아니오 closeOnConfirm : false, closeOnCancel : false }, function (isConfirm) { if (isConfirm) { inheritYn = true; content.inheritYn = true; } Issue.modify({ method : "POST", file : (function () { var files = []; angular.forEach($scope.vm.form.files, function (file) { if (angular.isUndefined(file.id)) { files.push(file); } }); return files; })(), // data 속성으로 별도의 데이터 전송 fields : { content : content }, fileFormDataName : "file" }).then(function (result) { if (result.data.message.status === "success") { $scope.fn.cancel(); // 이슈 상세 화면 요청 $rootScope.$broadcast("getIssueDetail", { id : parameter.id }); $rootScope.$broadcast("getIssueList"); } else { SweetAlert.error($filter("translate")("issue.failedIssueModify"), result.data.message.message); // 이슈 수정 실패 } $rootScope.spinner = false; }); }); } else { Issue.modify({ method : "POST", file : (function () { var files = []; angular.forEach($scope.vm.form.files, function (file) { if (angular.isUndefined(file.id)) { files.push(file); } }); return files; })(), // data 속성으로 별도의 데이터 전송 fields : { content : content }, fileFormDataName : "file" }).then(function (result) { if (result.data.message.status === "success") { $scope.fn.cancel(); // 이슈 상세 화면 요청 $rootScope.$broadcast("getIssueDetail", { id : parameter.id }); $rootScope.$broadcast("getIssueList"); } else { SweetAlert.error($filter("translate")("issue.failedIssueModify"), result.data.message.message); // 이슈 수정 실패 } $rootScope.spinner = false; }); } } function cancel() { SweetAlert.close(); $rootScope.$broadcast("closeLayer"); // 팝업이 열리고 나서 js-multi, js-single 등에서 body 이벤트가 날아가는 현상 수정 $uibModalInstance.dismiss('cancel'); $(document).unbind("keydown"); // 단축키 이벤트 제거 } // 이슈 유형 목록 function getIssueTypes() { var deferred = $q.defer(); IssueType.find($resourceProvider.getContent({}, $resourceProvider.getPageContent(0, 1000))).then(function (result) { if (result.data.message.status === "success") { $scope.vm.issueTypes = result.data.data; } else { SweetAlert.error($filter("translate")("issue.failedToIssueTypeListLookup"), result.data.message.message); // 이슈 타입 목록 조회 실패 } deferred.resolve(result.data.data); }); return deferred.promise; } // 우선순위 목록 function getPriorities() { var deferred = $q.defer(); Priority.find($resourceProvider.getContent({}, $resourceProvider.getPageContent(0, 1000))).then(function (result) { if (result.data.message.status === "success") { $scope.vm.priorities = result.data.data; } else { SweetAlert.error($filter("translate")("issue.failedToPriorityListLookup"), result.data.message.message); // 우선순위 목록 조회 실패 } deferred.resolve(result.data.data); }); return deferred.promise; } // 업체/ISP/호스팅 이름이 포함 여부 확인 function containsPartner(name) { var result = false; if ($scope.vm.partnerVos != null) { $scope.vm.partnerVos.forEach(function (partnerVo) { if (name === partnerVo.name) { result = true; } }); } return result; } // 중요도 목록 function getSeverities() { var deferred = $q.defer(); Severity.find($resourceProvider.getContent({}, $resourceProvider.getPageContent(0, 1000))).then(function (result) { if (result.data.message.status === "success") { $scope.vm.severities = result.data.data; } else { SweetAlert.error($filter("translate")("issue.failedToCriticalListLookup"), result.data.message.message); // 중요도 목록 조회 실패 } deferred.resolve(result.data.data); }); return deferred.promise; } // 이슈 유형에 연결된 사용자 정의 필드 function getIssueTypeCustomFields() { $scope.vm.form.issueCustomFields = []; // 이슈 타입 아이디나 프로젝트 아이디가 없으면 통신을 하지 않는다. if (!$rootScope.isDefined($scope.vm.form.issueTypeId) || $scope.vm.form.projects.length < 1) { return; } // 이슈 유형 템플릿 적용하기 $scope.fn.setIssueTypeTemplate(); var deferred = $q.defer(); IssueTypeCustomField.find($resourceProvider.getContent({projectId : $scope.vm.form.projects[0].id, issueTypeId : $scope.vm.form.issueTypeId}, $resourceProvider.getPageContent(0, 1000))).then(function (result) { if (result.data.message.status === "success") { // 이슈 유형에 연결된 사용자 정의 필드 정보를 입력 폼에서 사용할 수 있게 가공한다. $scope.fn.setFormByIssueTypeCustomFields(result.data.data); } else { SweetAlert.error($filter("translate")("issue.failedToUserDefinedFieldListAssociatedLookup"), result.data.message.message); // 이슈 유형에 연결된 사용자 정의 필드 목록 조회 실패 } deferred.resolve(result.data.data); }); return deferred.promise; } // 이슈 유형에 연결된 사용자 정의 필드 정보를 입력 폼에서 사용할 수 있게 가공한다. // 이슈 수정에서는 useValues 값이 issue_custom_field_value 의 값으로 셋팅해야하므로 여기서는 초기화만 해준다. function setFormByIssueTypeCustomFields(issueTypeCustomFields) { $scope.vm.form.issueCustomFields = []; angular.forEach(issueTypeCustomFields, function (issueTypeCustomField) { switch (issueTypeCustomField.customFieldVo.customFieldType) { case "INPUT" : case "SINGLE_SELECT" : case "NUMBER" : case "DATETIME" : case "IP_ADDRESS" : case "EMAIL" : case "SITE" : case "TEL" : issueTypeCustomField.useValues = ""; break; case "MULTI_SELECT" : issueTypeCustomField.useValues = []; break; } $scope.vm.form.issueCustomFields.push(issueTypeCustomField); }); } // 이슈에서 사용자가 선택한 사용자 정의 필드 값을 입력 폼에 셋팅한다. function setUseValueByIssueTypeCustomFields(issueCustomFieldValues) { angular.forEach(issueCustomFieldValues, function (issueCustomFieldValue) { for (var count in $scope.vm.form.issueCustomFields) { var issueCustomField = $scope.vm.form.issueCustomFields[count]; if (issueCustomField.customFieldVo.id === issueCustomFieldValue.customFieldVo.id) { // 멀티셀렉트 일때 if (angular.isArray(issueCustomField.useValues)) { issueCustomField.useValues.push({ value : issueCustomFieldValue.useValue }); } else { issueCustomField.useValues = issueCustomFieldValue.useValue; } break; } } }); } // 이슈 상세 정보 function detail() { $rootScope.spinner = true; var deferred = $q.defer(); Issue.detail($resourceProvider.getContent( $scope.vm.search, $resourceProvider.getPageContent(0, 1))).then(function (result) { if (result.data.message.status === "success") { if (angular.isDefined(result.data.data)) { $scope.vm.form.title = result.data.data.title; $scope.vm.form.description = result.data.data.description; $scope.vm.form.projects.push(result.data.data.projectVo); $scope.vm.projectName = result.data.data.projectVo.name; $scope.vm.form.issueTypeId = String(result.data.data.issueTypeVo.id); $scope.vm.form.priorityId = String(result.data.data.priorityVo.id); $scope.vm.form.severityId = String(result.data.data.severityVo.id); $scope.vm.form.issueStatusId = String(result.data.data.issueStatusVo.id); $scope.vm.form.users = result.data.data.userVos; $scope.vm.form.departments = result.data.data.departmentVos; $scope.vm.form.files = result.data.data.attachedFileVos; if (result.data.data.issueCompanyVos != null && result.data.data.issueCompanyVos.length > 0) { $scope.vm.form.issueCompanyFields = result.data.data.issueCompanyVos; var issueCompanyFieldValue = result.data.data.issueCompanyVos[0]; $scope.vm.companyId = issueCompanyFieldValue.companyId; $scope.vm.companyName = issueCompanyFieldValue.name; $scope.vm.companyManager = issueCompanyFieldValue.manager; $scope.vm.companyTel = issueCompanyFieldValue.tel; $scope.vm.companyEmail = issueCompanyFieldValue.email; $scope.vm.companyUrl = issueCompanyFieldValue.url; $scope.vm.ipStart = issueCompanyFieldValue.ipStart; $scope.vm.ipEnd = issueCompanyFieldValue.ipEnd; $scope.vm.companyMemo = issueCompanyFieldValue.memo; $scope.vm.form.companyTypeId = issueCompanyFieldValue.companyTypeId; $scope.vm.form.companyType = issueCompanyFieldValue.companyTypeName; $scope.vm.form.parentSectorId = issueCompanyFieldValue.parentSectorId; $scope.vm.form.parentSector = issueCompanyFieldValue.parentSectorName; $scope.vm.form.childSectorId = issueCompanyFieldValue.childSectorId; $scope.vm.form.childSector = issueCompanyFieldValue.childSectorName; $scope.vm.form.regionId = issueCompanyFieldValue.regionId; $scope.vm.form.region = issueCompanyFieldValue.regionName; $scope.vm.form.statusId = issueCompanyFieldValue.statusId; $scope.vm.form.status = issueCompanyFieldValue.statusName; } if (result.data.data.issueIspVos != null && result.data.data.issueIspVos.length > 0) { $scope.vm.form.issueIspFields = result.data.data.issueIspVos; var issueIspFieldValue = result.data.data.issueIspVos[0]; $scope.vm.ispId = issueIspFieldValue.ispId; $scope.vm.ispName = issueIspFieldValue.name; $scope.vm.ispCode = issueIspFieldValue.code; $scope.vm.ispManager = issueIspFieldValue.manager; $scope.vm.ispTel = issueIspFieldValue.tel; $scope.vm.ispEmail = issueIspFieldValue.email; $scope.vm.ispUrl = issueIspFieldValue.url; $scope.vm.ispMemo = issueIspFieldValue.memo; } if (result.data.data.issueHostingVos != null && result.data.data.issueHostingVos.length > 0) { $scope.vm.form.issueHostingFields = result.data.data.issueHostingVos; var issueHostingFieldValue = result.data.data.issueHostingVos[0]; $scope.vm.hostingId = issueHostingFieldValue.hostingId; $scope.vm.hostingName = issueHostingFieldValue.name; $scope.vm.hostingCode = issueHostingFieldValue.code; $scope.vm.hostingManager = issueHostingFieldValue.manager; $scope.vm.hostingTel = issueHostingFieldValue.tel; $scope.vm.hostingEmail = issueHostingFieldValue.email; $scope.vm.hostingUrl = issueHostingFieldValue.url; $scope.vm.hostingMemo = issueHostingFieldValue.memo; } if ($rootScope.isDefined(result.data.data.startDate)) { $scope.vm.form.startCompleteDateRange = result.data.data.startDate + " ~ " + result.data.data.completeDate; } else { $scope.vm.form.startCompleteDateRange = ""; } // 이슈 유형에 연결된 사용자 정의 필드 정보를 입력 폼에서 사용할 수 있게 가공한다. $scope.fn.setFormByIssueTypeCustomFields(result.data.data.issueTypeCustomFieldVos); // 이슈에서 사용자가 선택한 사용자 정의 필드 값을 입력 폼에 셋팅한다. $scope.fn.setUseValueByIssueTypeCustomFields(result.data.data.issueCustomFieldValueVos); } } else { SweetAlert.error($filter("translate")("issue.failedToProjectDetails"), result.data.message.message); // 프로젝트 상세 정보 조회 실패 } $rootScope.spinner = false; deferred.resolve(result.data.data); }); return deferred.promise; } // 이슈 타입에 있는 템플릿을 적용한다. function setIssueTypeTemplate() { for (var count in $scope.vm.issueTypes) { var issueType = $scope.vm.issueTypes[count]; if ($scope.vm.form.issueTypeId === String(issueType.id)) { // 템플릿이 작성되어 있는지 확인 if ($rootScope.isDefined(issueType.description)) { // 이슈 내용이 작성되어 있지 않으면 바로 템플릿 적용 if (!$rootScope.isDefined($scope.vm.form.description)) { $scope.vm.form.description = issueType.description; } else { // 이미 내용이 작성되어 있으면 확인 후 적용 SweetAlert.swal({ title : $filter("translate")("issue.applyTemplate"), // 템플릿 적용하기 text : $filter("translate")("issue.issueContentIsWrittenApplyTheTemplate"), // 이슈 내용이 작성되어 있습니다. 템플릿을 적용하겠습니까? 템플릿이 적용되면 이미 작성된 내용이 사라집니다. type : "warning", showCancelButton : true, confirmButtonColor : "#DD6B55", confirmButtonText : $filter("translate")("issue.applyTemplate"), // 템플릿 적용하기 cancelButtonText : $filter("translate")("common.cancel"), // 취소 closeOnConfirm : false, closeOnCancel : true }, function (isConfirm) { SweetAlert.close(); if (isConfirm) { $scope.vm.form.description = issueType.description; } }); } } break; } } } function getPartners() { if($scope.vm.form.issueTypeId === ""){ if ($rootScope.issueTypeMenu != null) { $scope.vm.form.issueTypeId = $rootScope.issueTypeMenu.id } } var content = { issueTypeId : $scope.vm.form.issueTypeId, }; Issue.findPartners($resourceProvider.getContent( content, $resourceProvider.getPageContent(0, 1))).then(function (result) { if (result.data.message.status === "success") { $scope.vm.partnerVos = result.data.data; } }); } // 최초 실행 function startExecute() { var promises = { detail : $scope.fn.detail(), getIssueTypes : $scope.fn.getIssueTypes(), getPriorities : $scope.fn.getPriorities(), getSeverities : $scope.fn.getSeverities(), getPartners : $scope.fn.getPartners() }; $q.all(promises).then(function (results) { $log.debug("promises 결과 ", results); }); } $scope.fn.startExecute(); }]); });