'use strict';
|
|
define([
|
'app'
|
],
|
function (app) {
|
app.controller('issueCommonSendMailController', ['$scope', '$rootScope', '$state', '$log', '$resourceProvider', '$uibModalInstance', '$controller', '$injector', '$q','SweetAlert', '$filter', 'Issue', 'parameter',
|
function ($scope, $rootScope, $state, $log, $resourceProvider, $uibModalInstance, $controller, $injector, $q, SweetAlert, $filter, Issue, parameter) {
|
|
$scope.fn = {
|
cancel : cancel, // 팝업 창 닫기
|
formSubmit : formSubmit, // 폼 전송
|
formCheck : formCheck, // 폼 체크
|
addInput : addInput,
|
removeInput : removeInput,
|
onFileSelect : onFileSelect, // 파일 첨부
|
removeUploadFile : removeUploadFile, // 업로드하려는 특정 파일을 삭제
|
imageUpload : imageUpload, // 섬머노트 이미지 업로드
|
|
};
|
|
$scope.vm = {
|
form : {
|
issueId : parameter.issueId,
|
title : "",
|
description: "",
|
inputs : [0],
|
emails : {}, // 입력된 사용자 이메일
|
files : [], // 업로드 파일
|
attachedFiles : [], // 섬머노트로 파일 업로드를 할 경우 서버에서 pk를 따고 issue id와 연동 작업이 필요하다.
|
},
|
userName : "",
|
autoCompletePage : {
|
user : {
|
page : 0,
|
totalPage : 0
|
}
|
}
|
};
|
|
// 폼 체크
|
function formCheck(formInvalid) {
|
if (formInvalid) {
|
return true;
|
}
|
return false;
|
}
|
|
// 섬머노트 이미지 업로드
|
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
|
}
|
},
|
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 removeUploadFile(index) {
|
$scope.vm.form.files.splice(index, 1);
|
|
angular.forEach($scope.vm.form.files, function (file, index) {
|
file.index = index;
|
});
|
}
|
|
// 메일 주소 input 창 추가 버튼
|
function addInput() {
|
var arrayFull = true; // 배열이 가득 차 있는지 여부
|
var index = 0;
|
$scope.vm.form.inputs.forEach(function (email) {
|
if (!$rootScope.isDefined($scope.vm.form.emails[index])) {
|
arrayFull = false;
|
}
|
index++;
|
});
|
|
if (arrayFull) {
|
$scope.vm.form.inputs.push(index);
|
$scope.vm.form.emails[index] = ""
|
} else {
|
SweetAlert.warning($filter("translate")("issue.writeIssueMail"), $filter("translate")("issue.writeMail")); // 추가버튼 경고
|
}
|
}
|
|
// 폼 전송
|
function formSubmit() {
|
$rootScope.spinner = true;
|
|
var content = {
|
issueId : $scope.vm.form.issueId,
|
title : $scope.vm.form.title,
|
description : $scope.vm.form.description,
|
sendEmails : (function () {
|
var sendEmails = [];
|
var index = 0
|
$scope.vm.form.inputs.forEach(function (email) {
|
if ($rootScope.isDefined($scope.vm.form.emails[index])) {
|
sendEmails.push($rootScope.encryption($scope.vm.form.emails[index])); // 이메일주소 암호화
|
}
|
index++;
|
});
|
|
return sendEmails;
|
})(),
|
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;
|
})(),
|
};
|
|
Issue.sendCommonEmail({
|
method : "POST",
|
file : $scope.vm.form.files,
|
// data 속성으로 별도의 데이터 전송
|
fields : {
|
content : content
|
},
|
fileFormDataName : "file"
|
}).then(function (result) {
|
if (result.data.message.status === "success") {
|
SweetAlert.success($filter("translate")("issue.succeededIssueMail"), $filter("translate")("issue.sentToTheSelectedUser")); // "이슈 메일 발송 완료"
|
$scope.fn.cancel();
|
}
|
else {
|
SweetAlert.error($filter("translate")("issue.failedIssueMail"), result.data.message.message); // "이슈 메일 발송 실패"
|
}
|
|
$rootScope.spinner = false;
|
});
|
}
|
|
// 이메일 주소 input 삭제
|
function removeInput(index) {
|
$scope.vm.form.inputs.splice(index, 1);
|
}
|
|
function cancel() {
|
$rootScope.$broadcast("closeLayer"); // 팝업이 열리고 나서 js-multi, js-single 등에서 body 이벤트가 날아가는 현상 수정
|
$uibModalInstance.dismiss('cancel');
|
$(document).unbind("keydown"); // 단축키 이벤트 제거
|
}
|
}]);
|
});
|