/** * Created by jeong on 2018-01-28. */ 'use strict'; define([ 'app' ], function (app) { app.controller('userDetailController', ['$scope', '$rootScope', '$log', '$resourceProvider', '$tableProvider', 'IssueHistory', '$uibModal', 'SweetAlert', '$filter', 'User', function ($scope, $rootScope, $log, $resourceProvider, $tableProvider, IssueHistory, $uibModal, SweetAlert, $filter, User) { // 함수 $scope.fn = { getMyInfo : getMyInfo, //나의 정보 조회(등급, 담당부서) getIssueHistoryList : getIssueHistoryList, // 이슈 기록 정보 조회 modify : modify, // 사용자 수정 changeSearchPeriod : changeSearchPeriod, // 이력 조회 검색 조건 변경 modifyPassword : modifyPassword // 비밀번호 변경 }; $scope.vm = { viewer : {}, search : { searchPeriod : "LAST_SEVEN_DAYS", startEndDateRange : "" // 이슈 기록 조회 날짜 }, issueHistoryVos : [], // 이슈 기록 정보 issueHistoryDates : [], // 이슈 기록 정보 날짜 myLevel : "", myDepartments : [], phone : "" }; // 직접 입력에서 날짜 선택시 이슈 기록 정보 조회 $scope.$watch("vm.search.startEndDateRange", function (newValue) { if ($rootScope.isDefined(newValue)) { $scope.fn.getIssueHistoryList(); } }); // 사용자 수정 function modify(id) { $uibModal.open({ templateUrl : 'views/user/userModify.html', size : "md", controller : "userModifyController", backdrop : 'static', resolve : { parameter : function () { return { id : id }; } } }); } // 사용자 비밀번호 변경 function modifyPassword(id) { $uibModal.open({ templateUrl : 'views/user/userModifyPassword.html', size : "md", controller : "userModifyPasswordController", backdrop : 'static', resolve : { parameter : function () { return { id : id }; } } }); } // 나의 정보 조회(등급, 담당부서) function getMyInfo() { User.findMyLevelAndDepartment($resourceProvider.getContent( $resourceProvider.getPageContent(0, 0))).then(function (result) { if (result.data.message.status === "success") { $scope.vm.myLevel = result.data.data.levelName; $scope.vm.myDepartments = result.data.data.departmentName; // 전화번호 하이픈 추가하여 조회 $scope.vm.phone = $rootScope.user.phone; let hyphen = $scope.vm.phone.trim(); let phone = hyphen.replace(/(^02.{0}|^01.{1}|[0-9]{3})([0-9]+)([0-9]{4})/,"$1-$2-$3"); $rootScope.user.phone = phone; } else { SweetAlert.swal($filter("translate")("users.failedToRetrieveIssueHistory"), result.data.message.message, "error"); // "이슈 기록 정보 조회 실패" } }); } // 이슈 기록 정보 조회 function getIssueHistoryList() { var content = { searchPeriod : $scope.vm.search.searchPeriod, searchStartDate : "", searchEndDate : "" }; if ($rootScope.isDefined($scope.vm.search.startEndDateRange)) { var startEndDateRange = $scope.vm.search.startEndDateRange.split("~"); content.searchStartDate = startEndDateRange[0].trim(); content.searchEndDate = startEndDateRange[1].trim(); } IssueHistory.find($resourceProvider.getContent(content, $resourceProvider.getPageContent(0, 0))).then(function (result) { if (result.data.message.status === "success") { $scope.vm.issueHistoryDates = Object.keys(result.data.data.issueHistoryGroups); // 기록 날짜 수집 $scope.vm.issueHistoryDates.sort(function (a, b) { var c = new Date(a); var d = new Date(b); return d - c; }); $scope.vm.issueHistoryVos = result.data.data.issueHistoryGroups; // 이슈 기록 정보 } else { SweetAlert.swal($filter("translate")("users.failedToRetrieveIssueHistory"), result.data.message.message, "error"); // "이슈 기록 정보 조회 실패" } }); } // 이력 조회 검색 조건 변경 function changeSearchPeriod() { switch ($scope.vm.search.searchPeriod) { case "CUSTOM_INPUT" : $scope.vm.search.startEndDateRange = ""; break; default : $scope.vm.search.startEndDateRange = ""; $scope.fn.getIssueHistoryList(); } } // 이슈 기록 정보 조회 $scope.fn.getIssueHistoryList(); $scope.fn.getMyInfo(); } ]); } );