From 9709ddf7896ad4d02859d755fb8ef1a28599b587 Mon Sep 17 00:00:00 2001 From: 이민희 <mhlee@maprex.co.kr> Date: 화, 25 1월 2022 18:50:00 +0900 Subject: [PATCH] 일반 이메일 전송시 첨부 파일 추가 --- src/main/webapp/scripts/app/issue/issueCommonSendMail.controller.js | 161 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 155 insertions(+), 6 deletions(-) diff --git a/src/main/webapp/scripts/app/issue/issueCommonSendMail.controller.js b/src/main/webapp/scripts/app/issue/issueCommonSendMail.controller.js index 6440824..086643f 100644 --- a/src/main/webapp/scripts/app/issue/issueCommonSendMail.controller.js +++ b/src/main/webapp/scripts/app/issue/issueCommonSendMail.controller.js @@ -12,7 +12,11 @@ formSubmit : formSubmit, // �뤌 �쟾�넚 formCheck : formCheck, // �뤌 泥댄겕 addInput : addInput, - removeInput : removeInput + removeInput : removeInput, + onFileSelect : onFileSelect, // �뙆�씪 泥⑤� + removeUploadFile : removeUploadFile, // �뾽濡쒕뱶�븯�젮�뒗 �듅�젙 �뙆�씪�쓣 �궘�젣 + imageUpload : imageUpload, // �꽟癒몃끂�듃 �씠誘몄� �뾽濡쒕뱶 + }; $scope.vm = { @@ -22,6 +26,8 @@ description: "", inputs : [0], emails : {}, // �엯�젰�맂 �궗�슜�옄 �씠硫붿씪 + files : [], // �뾽濡쒕뱶 �뙆�씪 + attachedFiles : [], // �꽟癒몃끂�듃濡� �뙆�씪 �뾽濡쒕뱶瑜� �븷 寃쎌슦 �꽌踰꾩뿉�꽌 pk瑜� �뵲怨� issue id�� �뿰�룞 �옉�뾽�씠 �븘�슂�븯�떎. }, userName : "", autoCompletePage : { @@ -38,6 +44,133 @@ 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 李� 異붽� 踰꾪듉 @@ -78,13 +211,29 @@ }); 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($resourceProvider.getContent( - content, - $resourceProvider.getPageContent(0, 10))).then(function (result) { - + 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(); -- Gitblit v1.8.0