/**
|
* Created by wisestone on 2017-12-15.
|
*/
|
'use strict';
|
|
define([
|
'app',
|
'angular'
|
],
|
function (app, angular) {
|
app.controller('userInviteController', ['$scope', '$rootScope', '$log', '$resourceProvider', 'UserInvite', '$uibModalInstance', 'SweetAlert', '$timeout', '$q', '$filter', '$controller', '$injector', 'User',
|
function ($scope, $rootScope, $log, $resourceProvider, UserInvite, $uibModalInstance, SweetAlert, $timeout, $q, $filter, $controller, $injector, User) {
|
|
$scope.fn = {
|
cancel : cancel, // 팝업창 닫기
|
formSubmit : formSubmit, // 폼 전송
|
formCheck : formCheck, // 폼 체크
|
addEmail : addEmail, // 이메일 추가
|
removeUser : removeUser, // 사용자 삭제
|
removeEmail : removeEmail, // 이메일 삭제
|
getAllUserList : getAllUserList, // 전체 시스템에 가입된 사용자를 조회한다.
|
getProjectListCallBack : getProjectListCallBack, // 프로젝트 auto complete 페이징 업데이트
|
getUserListCallBack : getUserListCallBack // 사용자 auto complete 페이징 업데이트
|
};
|
|
$scope.vm = {
|
form : {
|
users : [], // 시스템에 가입된 사용자 초대
|
projects : [], // 참여시킬 프로젝트
|
emails : [], // 메일 주소
|
email : "", // 이메일
|
},
|
userName : "",
|
projectName : "",
|
autoCompletePage : {
|
project : {
|
page : 0,
|
totalPage : 0
|
},
|
user : {
|
page : 0,
|
totalPage : 0
|
}
|
}
|
};
|
|
angular.extend(this, $controller('autoCompleteController', {$scope : $scope, $injector : $injector}));
|
|
// 전체 업무 공간의 사용자를 조회한다.
|
function getAllUserList(query, excludeList, page, callBack) {
|
var conditions = {
|
name : query,
|
statuses : ["01"],
|
excludeIds : (function () {
|
var excludeIds = [];
|
|
angular.forEach(excludeList, function (exclude) {
|
excludeIds.push(exclude.id);
|
});
|
|
return excludeIds;
|
})()
|
};
|
|
var deferred = $q.defer();
|
|
User.findByAllWorkspace($resourceProvider.getContent( // 페이징 업데이트가 필요한 컴포넌트 일경우, page 업데이트가 있을 경우 기본 10개씩 가져오고 아닐경우 25개씩 가져온다.
|
conditions, $resourceProvider.getPageContent($rootScope.isDefined(page) ? page : 0, $rootScope.isDefined(page) ? 10 : 25))).then(function (result) {
|
if (result.data.message.status === "success") {
|
|
if ($rootScope.isDefined(callBack)) {
|
callBack(result);
|
}
|
|
deferred.resolve(result.data.data);
|
}
|
else {
|
SweetAlert.swal($filter("translate")("common.failedToUserListLookUp"), result.data.message.message, "error"); // "사용자 목록 조회 실패"
|
}
|
});
|
|
return deferred.promise;
|
}
|
|
|
// 폼 체크
|
function formCheck(formInvalid) {
|
if (formInvalid) {
|
return true;
|
}
|
|
if ($scope.vm.form.projects.length < 1) {
|
return true;
|
}
|
|
if ($scope.vm.form.emails.length < 1 && $scope.vm.form.users.length < 1) {
|
return true;
|
}
|
|
return false;
|
}
|
|
// 이메일 추가
|
function addEmail() {
|
if ($rootScope.isDefined($scope.vm.form.email)) {
|
var regex = new RegExp("^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$");
|
|
if (regex.test($scope.vm.form.email)) {
|
var duplicateCheck = false;
|
|
for (var count in $scope.vm.form.emails) {
|
var email = $scope.vm.form.emails[count];
|
|
if (email === $scope.vm.form.email) {
|
duplicateCheck = true;
|
break;
|
}
|
}
|
|
if (duplicateCheck) {
|
SweetAlert.warning($filter("translate")("users.duplicateEmail"), $filter("translate")("users.duplicateEmailEntered")); // 이메일이 잘못 입력되었습니다.
|
}
|
else {
|
$scope.vm.form.emails.push($scope.vm.form.email);
|
$scope.vm.form.email = "";
|
|
$timeout(function () {
|
$("#userInviteForm1").trigger("focus")
|
}, 200);
|
}
|
}
|
else {
|
SweetAlert.warning($filter("translate")("users.confirmEmailInput"), $filter("translate")("users.emailEnteredIncorrectly")); // 이메일이 잘못 입력되었습니다.
|
}
|
}
|
else {
|
SweetAlert.warning($filter("translate")("users.confirmEmailInput"), $filter("translate")("users.noEmailEntered")); // 이메일이 입력되지 않았습니다.
|
}
|
}
|
|
// 사용자 삭제
|
function removeUser(index) {
|
$scope.vm.form.users.splice(index, 1);
|
}
|
|
// 이메일 삭제
|
function removeEmail(index) {
|
$scope.vm.form.emails.splice(index, 1);
|
}
|
|
// 폼 전송
|
function formSubmit() {
|
$rootScope.spinner = true;
|
|
var content = {
|
emails : (function () {
|
var tmpEmails = []; // 초대하는 사용자 저장
|
var inviteEmails = [];// 초대하는 사용자 이메일 암호화
|
|
angular.forEach($scope.vm.form.users, function (user) {
|
var duplicateCheck = false;
|
|
for (var count in $scope.vm.form.emails) {
|
var email = $scope.vm.form.emails[count];
|
|
if (email === user.account) {
|
duplicateCheck = true;
|
break;
|
}
|
}
|
|
if (!duplicateCheck) {
|
tmpEmails.push(user.account);
|
}
|
});
|
|
tmpEmails = tmpEmails.concat($scope.vm.form.emails);
|
|
angular.forEach(tmpEmails, function(email) {
|
inviteEmails.push($rootScope.encryption(email));
|
});
|
|
return inviteEmails;
|
})(),
|
projectIds : (function () {
|
var projectIds = [];
|
angular.forEach($scope.vm.form.projects, function (project) {
|
projectIds.push(project.id);
|
});
|
|
return projectIds;
|
})()
|
};
|
|
UserInvite.invite($resourceProvider.getContent(
|
content,
|
$resourceProvider.getPageContent(0, 10))).then(function (result) {
|
|
if (result.data.message.status === "success") {
|
// 나의 업무 공간 관리의 참여 가능 목록 화면 갱신
|
$rootScope.$broadcast("getUserWorkspaceList", {});
|
// 업무 공간 정보도 갱신
|
$rootScope.$broadcast("findMyWorkspace", {});
|
|
$scope.fn.cancel();
|
|
SweetAlert.success($filter("translate")("users.successInviteMail"), result.data.message.message);
|
}
|
else {
|
SweetAlert.error($filter("translate")("users.failedInviteMail"), result.data.message.message); // "초대 메일 발송 실패"
|
}
|
|
$rootScope.spinner = false;
|
});
|
}
|
|
function cancel() {
|
$rootScope.$broadcast("closeLayer"); // 팝업이 열리고 나서 js-multi, js-single 등에서 body 이벤트가 날아가는 현상 수정
|
$uibModalInstance.dismiss('cancel');
|
$(document).unbind("keydown"); // 단축키 이벤트 제거
|
}
|
|
// 프로젝트 autocomplete 페이지 정보 업데이트
|
function getProjectListCallBack(result) {
|
$scope.vm.autoCompletePage.project.totalPage = result.data.page.totalPage;
|
}
|
|
// 사용자 autocomplete 페이지 정보 업데이트
|
function getUserListCallBack(result) {
|
$scope.vm.autoCompletePage.user.totalPage = result.data.page.totalPage;
|
}
|
|
}]);
|
});
|