hello.html 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066
  1. <html lang="en">
  2. <head>
  3. <meta charset="utf-8" />
  4. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  5. <link rel="icon" href="/favicon.ico" />
  6. <link rel="stylesheet" type="text/css" href="/static/styles/custom.css?v=06" />
  7. <!-- <script
  8. src="https://res.cdn.office.net/teams-js/2.17.0/js/MicrosoftTeams.min.js"
  9. integrity="sha384-xp55t/129OsN192JZYLP0rGhzjCF9aYtjY0LVtXvolkDrBe4Jchylp56NrUYJ4S2"
  10. crossorigin="anonymous"
  11. ></script>
  12. <script src="https://secure.aadcdn.microsoftonline-p.com/lib/1.2.1/js/msal.js"></script>
  13. <script src="/static/scripts/teamsapp.js"></script> -->
  14. <script src="https://code.jquery.com/jquery-latest.min.js"></script>
  15. <title>Microsoft Teams Tab</title>
  16. <style>
  17. </style>
  18. </head>
  19. <body>
  20. <div class="wrap">
  21. <div class="content">
  22. <nav>
  23. <div class="tree">
  24. <li class="">
  25. <input type="checkbox" id="file">
  26. <label for="file">내 OFFICE 365 파일</label>
  27. </li>
  28. </div>
  29. <div class="total">모두</div>
  30. <div class="tree group"></div>
  31. </nav>
  32. <section>
  33. <div class="menu">
  34. <div class="sub-menu">
  35. <img src="/static/images/menu-icon.png" width="30" height="30" alt="메뉴 아이콘">
  36. </div>
  37. <div onclick="menuOpen(event, 'mk-items')">
  38. <div>새로만들기</div>
  39. <div class="mk-items click-menu">
  40. <div onclick="mkdir()"><img src="/static/images/folder.png" width="20" height="20" alt="문서 이미지">&nbsp;폴더</div>
  41. <div onclick="mkWord()"><img src="/static/images/docx.svg" width="20" height="20" alt="문서 이미지">&nbsp;Word 문서</div>
  42. <div onclick="mkExcel()"><img src="/static/images/xlsx.svg" width="20" height="20" alt="문서 이미지">&nbsp;Excel 통합 문서</div>
  43. <div onclick="mkPpt()"><img src="/static/images/pptx.svg" width="20" height="20" alt="문서 이미지">&nbsp;PowerPoint 프레젠테이션</div>
  44. </div>
  45. </div>
  46. <div onclick="menuOpen(event, 'upload-items')">
  47. <div>업로드</div>
  48. <div class="upload-items click-menu">
  49. <div style="width: 160px;" onclick="openFolder(event)">폴더</div>
  50. <div style="width: 160px;" onclick="openFile(event)">파일</div>
  51. </div>
  52. </div>
  53. <div onclick="refreshDrive()">새로고침</div>
  54. <div class="one-drive-button">OneDrive에서 열기</div>
  55. <input type="file" style="display: none;" id="folder-upload" name="folder" onchange="uploadFolders(event)" webkitdirectory multiple >
  56. <input type="file" style="display: none;" id="file-upload" name="file" onchange="uploadFiles(event)" multiple >
  57. <div id="hubState" style="display: none;"></div>
  58. </div>
  59. <div class="panel"></div>
  60. <div class="file-title">
  61. <div><input type="checkbox" id="all-check" onchange="allSelect(event)"><img src="/static/images/file.png" width="20" alt="파일"></div>
  62. <div class="head-name" onclick="sorting('name')">이름</div>
  63. <div class="head-size" onclick="sorting('size')">용량</div>
  64. <div class="head-lastModifiedDateTime" onclick="sorting('lastModifiedDateTime')">수정된 날짜</div>
  65. <div class="head-lastModifiedBy.user.displayName" onclick="sorting('lastModifiedBy.user.displayName')">수정한 사람</div>
  66. <div class="head-label" onclick="sorting('label')">민감도</div>
  67. </div>
  68. <div class="file-content"></div>
  69. </section>
  70. </div>
  71. </div>
  72. </body>
  73. </html>
  74. <script>
  75. let _formData = new FormData($('<form enctype="multipart/form-data"></form>')[0]);
  76. const groupId = '3df73dac-a8bc-4dd0-9159-fdb2c696c067';
  77. const groupMap = new Map();
  78. let _selectedData = [];
  79. let _listData = [];
  80. $(document).ajaxStart(()=>{
  81. $('body').append(`<div id="load">
  82. <img src="/static/images/Settings.gif" alt="loading">
  83. </div>`);
  84. }).ajaxStop(()=>{
  85. $('#load').remove();
  86. });
  87. $(()=>{
  88. // microsoftTeams.appInitialization.notifySuccess();
  89. getGroupList();
  90. window.oncontextmenu = function () {
  91. return false;
  92. };
  93. window.addEventListener('click', function() {
  94. $('.click-menu').css('display', 'none');
  95. })
  96. $('.file-content').on('click', function(event){
  97. if (event.originalEvent.target === $('.file-content')[0]) {
  98. $('.file-content input[type="checkbox"]').prop('checked', false);
  99. $('.file-content > div.on').removeClass('on');
  100. }
  101. });
  102. });
  103. function openFolder(event) {
  104. $('.upload-items').css('display', 'none');
  105. if (!$('.panel-item.on')[0]) return alertMessage('폴더 업로드', '업로드할 그룹을 선택해 주세요.', null, 'red');
  106. $('#folder-upload').click();
  107. }
  108. function openFile(event) {
  109. $('.upload-items').css('display', 'none');
  110. if (!$('.panel-item.on')[0]) return alertMessage('파일 업로드', '업로드할 그룹을 선택해 주세요.', null, 'red');
  111. $('#file-upload').click();
  112. }
  113. function allSelect(event) {
  114. const isChecked = $(event.target).is(':checked');
  115. $('.file-content input[type="checkbox"]').prop('checked', isChecked);
  116. let method = 'addClass';
  117. if (!isChecked) {
  118. method = 'removeClass';
  119. }
  120. $('.file-content > div')[method]('on');
  121. }
  122. function uploadFiles(event) {
  123. const files = event.target.files;
  124. if (files.length === 0) return;
  125. const alertTitle = '파일 업로드';
  126. const formData = new FormData($('<form enctype="multipart/form-data"></form>')[0]);
  127. const driveFileNames = getDriveFileNames();
  128. for (let file of files) {
  129. let fileName = file.name;
  130. if (driveFileNames.length > 0 && driveFileNames.includes(fileName)) {
  131. $(event.target).val("");
  132. return alertMessage(alertTitle, '업로드 경로에 이미 같은 이름의 파일이 있습니다.<br>파일을 업로드 하려면 기존 파일의 명칭을 변경해주세요.<br>파일명 : '+ fileName, null, 'red');
  133. }
  134. formData.append('file', file);
  135. }
  136. upload(formData);
  137. }
  138. function getDriveFileNames() {
  139. const driveFiles = $('section .file-content div .sp-name');
  140. const result = [];
  141. if (driveFiles.length) {
  142. for (let ii = 0; ii < driveFiles.length; ii++) {
  143. const name = driveFiles.eq(ii).text();
  144. if (name && name.trim()) {
  145. result.push(name);
  146. }
  147. }
  148. }
  149. return result;
  150. }
  151. function uploadFolders(event) {
  152. const srcEl = event.srcElement;
  153. const alertTitle = '폴더 업로드';
  154. if (srcEl && srcEl.files) {
  155. const files = srcEl.files;
  156. if (files.length > 100) {
  157. return alertMessage(alertTitle, '업로드 파일 수 : '+ files.length + '<br>업로드 파일은 최대 100개 까지 가능합니다.', null, 'red');
  158. }
  159. let folders = {};
  160. const siteId = getSitesId();
  161. let formData = new FormData($('<form enctype="multipart/form-data"></form>')[0]);
  162. const driveFileNames = getDriveFileNames();
  163. if (files.length) {
  164. const filePath = files[0].webkitRelativePath;
  165. const rootFolder = filePath.substring(0, filePath.indexOf('/'));
  166. console.log(rootFolder);
  167. if (driveFileNames.includes(rootFolder)) {
  168. $(srcEl).val("");
  169. return alertMessage(alertTitle, '폴더명 : '+ rootFolder + '<br>업로드 경로에 이미 같은 이름의 폴더가 있습니다.<br>폴더를 업로드 하려면 기존 폴더의 명칭을 변경해주세요.', null, 'red');
  170. }
  171. }
  172. for (let file of files) {
  173. let path = file.webkitRelativePath;
  174. path = '/'+ path.substring(0, path.lastIndexOf('/'));
  175. formData.append('file', file);
  176. let filePath = path;
  177. formData.append(file.name + '_path', filePath);
  178. if (!folders[path] && path.indexOf('/') >= 0) {
  179. let folderPath = "";
  180. if (path.lastIndexOf('/') > 0) {
  181. folderPath = path.substring(0, path.lastIndexOf('/'));
  182. }
  183. let name = path.substring(path.lastIndexOf('/') + 1, path.length);
  184. formData.append('folder', JSON.stringify({name : name, path : folderPath}));
  185. folders[path] = true;
  186. }
  187. }
  188. upload(formData);
  189. $(srcEl).val("");
  190. }
  191. }
  192. function menuOpen(event, className) {
  193. event.preventDefault();
  194. event.stopPropagation();
  195. if ($('.panel-item').length === 0) {
  196. return;
  197. }
  198. const toggleBox = document.getElementsByClassName('toggle-box');
  199. if (document.getElementsByClassName('toggle-box')){
  200. $(toggleBox).remove();
  201. }
  202. $('.click-menu:not(.'+className+')').css('display', 'none');
  203. $('.' + className).toggle();
  204. }
  205. function drawDriveFiles(jsonData, parentData, name) {
  206. _selectedData = [];
  207. const panel = $('section .panel');
  208. let panelStr = `<span class="panel-item on">${name}</span>`;
  209. const $fileContent = $('.file-content');
  210. const $oneDriveBtn = $('.one-drive-button');
  211. let text = name;
  212. if (name !== 'One Drive') {
  213. text = 'SharePoint'
  214. }
  215. $oneDriveBtn.text(text+'에서 열기');
  216. $oneDriveBtn.off('click');
  217. if (parentData && parentData.webUrl) {
  218. $oneDriveBtn.on('click', ()=>{
  219. window.open(parentData.webUrl);
  220. });
  221. };
  222. if (jsonData && jsonData.value && jsonData.value.length > 0) {
  223. _selectedData = jsonData;
  224. const selectedPref = _selectedData.value[0].parentReference;
  225. if (selectedPref && selectedPref.path) {
  226. let path = selectedPref.path;
  227. panelStr = drawPath(path, selectedPref.siteId, name);
  228. }
  229. let str = "";
  230. jsonData.value.forEach((obj, idx)=>{
  231. dragAndDrop();
  232. let modifyName = "";
  233. if (obj.lastModifiedBy && obj.lastModifiedBy.user) {
  234. modifyName = obj.lastModifiedBy.user.displayName;
  235. }
  236. const imageData = getFileImage(obj);
  237. const images = imageData[0];
  238. const imageName = imageData[1];
  239. let amount = '0 Bytes';
  240. if (obj.size) {
  241. amount = getVolume(obj.size);
  242. }
  243. let modifyDate = obj.lastModifiedDateTime;
  244. if (modifyDate) {
  245. modifyDate = modifyDate.replace('T', ' ');
  246. modifyDate = modifyDate.substring(5, 7)+ '월 '+ modifyDate.substring(8, 10)+ '일';
  247. }
  248. // let method = `findOneDriveChildrenItems('${obj.id}')`;(siteId, path, name, value)
  249. let method = `siteDriveChildrenItems('${obj.parentReference.siteId}','${obj.parentReference.path + '/' + obj.name}','${name}', null, event)`;
  250. if (obj.file) {
  251. // method = `downloadItems('${obj['@microsoft.graph.downloadUrl']}', '${obj.name}', event)`;
  252. method = `openWebUrl('${obj.webUrl}', '${obj.name}', event)`;
  253. }
  254. str += `
  255. <div id="row_${idx}">
  256. <div>
  257. <input type="checkbox" name="row_${idx}" value="${obj.id}" onchange="checkState(event)" onclick="event.stopPropagation()">
  258. <img src="${images}" width="32" height="32" alt="${imageName}">
  259. </div>
  260. <div class="file_name"><span class="sp-name" onclick="${method}">${obj.name}</span></div>
  261. <div>${amount}</div>
  262. <div>${modifyDate}</div>
  263. <div>${modifyName}</div>
  264. <div></div>
  265. </div>`
  266. });
  267. $fileContent.html(str);
  268. $('.file-content > div').on('click', function(e){
  269. e.preventDefault();
  270. const checkbox = $('input[name="'+$(this).attr('id') + '"]');
  271. if (checkbox[0]) {
  272. const isChecked = checkbox.prop("checked");
  273. checkbox.prop('checked', !isChecked);
  274. const method = !isChecked ? 'addClass' : 'removeClass';
  275. $(this)[method]('on');
  276. }
  277. });
  278. window.addEventListener('click', ()=>{
  279. if ($('.toggle-box')[0]){
  280. $('.toggle-box').remove();
  281. }
  282. })
  283. $('.file-content > div').on('mousedown', function(e){
  284. if ((e.button == 2) || (e.which == 3)) {
  285. const checkbox = $('input[name="'+$(this).attr('id') + '"]');
  286. if (!$(this).hasClass('on')) {
  287. checkbox.prop('checked', true);
  288. $(this).addClass('on');
  289. }
  290. if ($('.toggle-box')[0]) {
  291. $('.toggle-box').remove();
  292. }
  293. const {clientX, clientY} = e;
  294. const array = $('.file-content input[type="checkbox"]');
  295. let checkCnt = 0;
  296. let isChannel = false;
  297. if (array && array.length > 0) {
  298. for (let ii = 0; ii < array.length; ii++) {
  299. if (array.eq(ii).is(':checked')) {
  300. checkCnt++;
  301. const chanel = document.getElementById(array.eq(ii).val());
  302. if (chanel) {
  303. isChannel = true;
  304. }
  305. }
  306. }
  307. }
  308. const teamId = $('section .panel .panel-item').eq(0).attr('id');
  309. const teamList = document.querySelector('#my-team').nextElementSibling.nextElementSibling;
  310. let isTeam = false;
  311. if (teamList && $(teamList).find('#'+teamId+'_li').length > 0) {
  312. isTeam = true;
  313. }
  314. let str = `<div>편집</div>`;
  315. const selectImage = $('section .file-content div.on').find('img');
  316. if (checkCnt === 1 &&
  317. selectImage.length &&
  318. isTeam === true &&
  319. selectImage.attr('src') !== '/static/images/folder.png') {
  320. str += `<div onclick="addTabs()">탭으로 설정</div>`;
  321. }
  322. str += `<div onclick="download()">다운로드</div>
  323. <div onclick="deleteItem()">삭제</div>`;
  324. if (!isChannel) {
  325. str +=`<div onclick="moveItem('이동')">이동</div>`;
  326. }
  327. str += `<div onclick="moveItem('복사')">복사</div>`;
  328. if (checkCnt === 1) {
  329. str += `<div onclick="nameChange()">이름 바꾸기</div>`;
  330. }
  331. const toggleBox = $(`<div class="toggle-box" style="position:absolute; top:${clientY}; left: ${clientX}">
  332. ${str}
  333. </div>`);
  334. $('body').append(toggleBox);
  335. }
  336. });
  337. }
  338. else {
  339. if (parentData && parentData.folder && parentData.folder.childCount === 0) {
  340. const refData = parentData.parentReference;
  341. let path = '';
  342. if (refData.path) {
  343. path = refData.path +'/' + parentData.name;
  344. }
  345. panelStr = drawPath(path, refData.siteId, name);
  346. $oneDriveBtn.off('click');
  347. if (parentData.webUrl){
  348. $oneDriveBtn.on('click', ()=>{
  349. window.open(parentData.webUrl);
  350. });
  351. }
  352. $fileContent.html(`<div class="empty-box">
  353. <img src="/static/images/empty_folder_v2.svg" alt="이미지">
  354. <div>이 폴더는 비어 있습니다.</div>
  355. </div>`)
  356. }
  357. }
  358. panel.html(panelStr);
  359. }
  360. function openWebUrl(url, name, event) {
  361. window.open(url);
  362. }
  363. function addTabs() {
  364. const fileName = $('section .file-content div.on .file_name').text();
  365. const siteId = $('section .panel .panel-item').eq(0).attr('id');
  366. const path = getDrivePath() + '/' + fileName;
  367. let teamId = null;
  368. const teamData = _listData.joinedTeams.teams;
  369. const teamName = $('section .panel .panel-item').eq(0).text().trim();
  370. const channelName = $('section .panel .panel-item').eq(1).text().trim();
  371. if (teamData && teamData.length > 0) {
  372. let idx = teamData.findIndex(obj=> obj.displayName === teamName);
  373. if (idx >= 0) {
  374. teamId = teamData[idx].id;
  375. }
  376. }
  377. console.log(fileName , siteId , teamId , path, teamName, channelName);
  378. if (fileName && siteId && teamId && path && teamName && channelName) {
  379. //teams/a677e58b-0812-4abb-887f-4c49f5adfa3d/channels
  380. $.ajax({
  381. method : 'post',
  382. url : '/api/add-tab',
  383. data : {
  384. siteId : siteId,
  385. path : path,
  386. name : fileName,
  387. teamId : teamId,
  388. teamName : teamName,
  389. channelName : channelName,
  390. },
  391. success : (res) => {
  392. console.log(res);
  393. },
  394. error : (error) => {
  395. console.log(error);
  396. }
  397. })
  398. // callApi('get', '/sites/' + siteId + path + '/'+ fileName, (jsonData)=>{
  399. // console.log(jsonData);
  400. // });
  401. // const param = {
  402. // displayName: fileName,
  403. // webUrl : "https://graph.microsoft.com/v1.0/appCatalogs/teamsApps/06805b9e-77e3-4b93-ac81-525eb87513b8",
  404. // "configuration": {
  405. // "entityId": "2DCA2E6C7A10415CAF6B8AB6661B3154",
  406. // "contentUrl": "https://www.contoso.com/Orders/2DCA2E6C7A10415CAF6B8AB6661B3154/tabView",
  407. // "websiteUrl": "https://www.contoso.com/Orders/2DCA2E6C7A10415CAF6B8AB6661B3154",
  408. // "removeUrl": "https://www.contoso.com/Orders/2DCA2E6C7A10415CAF6B8AB6661B3154/uninstallTab"
  409. // }
  410. // }
  411. }
  412. else {
  413. alertMessage('탭으로 설정', '탭으로 설정 할 파일 정보를 확인 해주세요.');
  414. }
  415. // const param = {
  416. // "displayName": "My Contoso Tab",
  417. // "teamsApp@odata.bind" : "https://graph.microsoft.com/v1.0/appCatalogs/teamsApps/06805b9e-77e3-4b93-ac81-525eb87513b8",
  418. // "configuration": {
  419. // "entityId": "2DCA2E6C7A10415CAF6B8AB6661B3154",
  420. // "contentUrl": "https://www.contoso.com/Orders/2DCA2E6C7A10415CAF6B8AB6661B3154/tabView",
  421. // "websiteUrl": "https://www.contoso.com/Orders/2DCA2E6C7A10415CAF6B8AB6661B3154",
  422. // "removeUrl": "https://www.contoso.com/Orders/2DCA2E6C7A10415CAF6B8AB6661B3154/uninstallTab"
  423. // }
  424. // }
  425. // $.ajax({
  426. // url : '/api/add-tabs'
  427. // })
  428. }
  429. //파일별 이미지 세팅
  430. function getFileImage(obj) {
  431. let images = "/static/images/";
  432. let imageName = "";
  433. if (obj.folder || obj.driveType) {
  434. images += "folder.png";
  435. imageName = "폴더 이미지";
  436. }
  437. else if (obj.file && obj.name) {
  438. imageName = "파일 이미지";
  439. let ext = obj.name.substring(obj.name.lastIndexOf('.') + 1);
  440. let imageExt = ".svg";
  441. //photo
  442. // if (obj.file.mimeType && obj.file.mimeType.includes('image')){
  443. if (['psd', 'bmp', 'rle', 'dib', 'jpeg', 'jpg', 'gif', 'png', 'tiff', 'raw', 'ico'].includes(ext)){
  444. ext = 'photo';
  445. }
  446. else if (['ai', 'eps', 'svg'].includes(ext)) {
  447. ext = 'vector';
  448. }
  449. else if (['txt', 'properties'].includes(ext)) {
  450. ext = 'txt';
  451. }
  452. else if (['pptx', 'ppt', 'pptm'].includes(ext)) {
  453. ext = 'pptx';
  454. }
  455. else if (['xlsx', 'xlsm', 'xlsb', 'xltx'].includes(ext)) {
  456. ext = 'xlsx';
  457. }
  458. else if (['pdf'].includes(ext)) {
  459. ext = 'pdf';
  460. }
  461. else if (['doc', 'docx'].includes(ext)) {
  462. ext = 'docx';
  463. }
  464. else if (['one', 'onetoc'].includes(ext)) {
  465. ext = 'onetoc';
  466. }
  467. else if (['vsd', 'vdx', 'vdw', 'vstx', 'vstm', 'vst', 'vtx', 'vsdx'].includes(ext)) {
  468. ext = 'vsdx';
  469. }
  470. else if (['zip', 'apk', 'rar', '7z', 'tar'].includes(ext)) {
  471. ext = 'zip';
  472. }
  473. else if (['jsp', 'js', 'css', 'php', 'ini', 'yml', 'json', 'java', 'c', 'cpp', 'h', 'm', 'mm',
  474. 'pl', 'o', 'class', 'as', 'asp', 'cs', 'md', 'ps1', 'ps2'].includes(ext)) {
  475. ext = 'code';
  476. }
  477. else if (['html'].includes(ext)) {
  478. ext = 'html';
  479. }
  480. else if (['exe', 'msi'].includes(ext)) {
  481. ext = 'exe';
  482. }
  483. else if (['jar', 'war', 'cab', 'dll', ].includes(ext)) {
  484. ext = 'sysfile';
  485. }
  486. else if (['mp4', 'mov', 'Webm', 'mp3','wav', 'Ogg'].includes(ext)) {
  487. ext = 'clipchamp';
  488. }
  489. else if (['bdf', 'chr', 'dfont', 'eot','etx', 'fnt', 'gdr', 'gf', 'mcf', 'xft', 'ttf', 'woff2',
  490. 'mf', 'otf', 'pfa', 'pfb', 'pfr', 'sfd', 'suit', 'tfm', 'ttc', 'vlw', 'woff', 'xfn'].includes(ext)) {
  491. ext = 'font';
  492. }
  493. else if (['xml'].includes(ext)) {
  494. ext = 'xml';
  495. }
  496. else {
  497. ext = 'genericfile';
  498. }
  499. images += ext + imageExt;
  500. }
  501. else {
  502. imageName = "파일 이미지";
  503. images += 'genericfile.svg';
  504. }
  505. return [images, imageName];
  506. }
  507. function moveItem(text) {
  508. const alertTxt = '파일 '+ text;
  509. const moveArr = $('.file-content div.on input[type="checkbox"]');
  510. if (moveArr.length === 0) {
  511. return alertMessage(alertTxt, '선택 된 파일 정보가 없습니다.');
  512. }
  513. $.ajax({
  514. method: 'post',
  515. url : "/getGroupList",
  516. success: (res)=> {
  517. // drawList(res);
  518. let oneDriveId = "";
  519. if (res.oneDrive) {
  520. oneDriveId = res.oneDrive.teams.sharePoint.siteId;
  521. }
  522. let str = `<div class="modal move" style="display: flex;">
  523. <div class="modal-move-box">
  524. <div class="left-box">
  525. <h3 style="padding: 10px;">${moveArr.length}개 항목 ${text}</h3>
  526. <div id="move_${oneDriveId}" class="my-file" onclick="setContent('${oneDriveId}', event)"><img src="/static/images/folder-icon.png" alt="폴더 이미지">&nbsp;&nbsp;내 파일</div>
  527. <div class="">
  528. <div></div>
  529. </div>
  530. <div class="access-box">
  531. <div class="access">빠른 엑세스</div>`;
  532. if (res) {
  533. const {joinedTeams, oneDrive, sites} = res;
  534. const groupImageUrl = "/_api/siteiconmanager/getsitelogo?type='1'";
  535. if (joinedTeams.teams.length > 0) {
  536. const jTeam = joinedTeams.teams;
  537. jTeam.forEach((obj, idx)=>{
  538. const share = obj.sharePoint;
  539. str += `<div id="move_${share.siteId}" onclick="setContent('${share.siteId}', event)">
  540. <div>
  541. <img width="25" height="25" src="${share.siteUrl}${groupImageUrl}" alt="아이콘">
  542. <div>${obj.displayName}</div>
  543. </div>
  544. </div>`
  545. });
  546. }
  547. if (sites.teams) {
  548. const sTeam = sites.teams;
  549. const share = sTeam.sharePoint;
  550. str += `<div id="move_${share.siteId}" onclick="setContent('${share.siteId}', event)">
  551. <div>
  552. <img width="25" height="25" src="${share.siteUrl + groupImageUrl}" alt="아이콘">
  553. <div>${sTeam.displayName}</div>
  554. </div>
  555. </div>`
  556. }
  557. }
  558. str +=`<div>
  559. <div style="color: rgb(91, 95, 199); margin-left: 15px;">더 많은 장소...</div>
  560. </div>
  561. </div>
  562. </div>
  563. <div class="right-box">
  564. <div class="panel"></div>
  565. <div class="content">
  566. <div class="header">
  567. <div><img src="/static/images/file.png" width="20" alt="파일"></div>
  568. <div>이름</div>
  569. <div>수정된 날짜</div>
  570. <div>수정한 사람</div>
  571. </div>
  572. <div class="list">
  573. </div>
  574. </div>
  575. <div class="button-box">
  576. <div id="move-btn" onclick="moveUpdate('${text}')">여기로 ${text}</div>
  577. <div onclick="modalClose('move')">취소</div>
  578. </div>
  579. </div>
  580. </div>
  581. </div>`;
  582. $('body').append($(str));
  583. if (res.joinedTeams && res.joinedTeams.teams.length > 0) {
  584. const firstId = "move_" + res.joinedTeams.teams[0].sharePoint.siteId;
  585. $('#'+firstId).click();
  586. }
  587. },
  588. error: (error)=> {
  589. console.log(error);
  590. }
  591. })
  592. }
  593. function moveUpdate(text) {
  594. const alertTitle = '파일 '+ text;
  595. const selectedDrive = $('.modal-move-box .left-box div.on');
  596. const siteId = selectedDrive.attr('id');
  597. const pathArr = $('.modal-move-box .right-box .panel .panel-item');
  598. const fileArr = $('.modal-move-box .list .file-name');
  599. const moveArr = $('section .file-content div.on .sp-name');
  600. if (moveArr && moveArr.length && fileArr && fileArr.length) {
  601. for (let ii = 0; ii < moveArr.length; ii++) {
  602. for (let jj = 0; jj < fileArr.length; jj++) {
  603. if (moveArr.eq(ii).text() === fileArr.eq(jj).text()) {
  604. return alertMessage(alertTitle, '파일명 : ' + moveArr.eq(ii).text() +'<br>대상 경로에 이미 같은 이름의 파일이 있습니다.<br>파일을 '+text+' 하려면 해당 파일의 명칭을 변경해주세요.');
  605. }
  606. }
  607. }
  608. }
  609. if (selectedDrive[0] && siteId) {
  610. let path = getDrivePath(true);
  611. const currentId = $('section .panel-item').eq(0).attr('id');
  612. const selectId = siteId.replace('move_', '');
  613. if (selectId === currentId && path === getDrivePath()) {
  614. return alertMessage(alertTitle, '대상 경로는 원본 개체와 같을 수 없습니다.');
  615. }
  616. callApi('get', '/sites/'+ currentId + getDrivePath(), (itemData)=>{
  617. if (itemData && itemData.id){
  618. const itemId = itemData.id;
  619. callApi('get', '/sites/'+ selectId + path, async (jsonData)=>{
  620. const $selectedItems = $('.file-content div.on');
  621. const name = [];
  622. let str = `<div class="loading-box"><div>파일 생성중입니다...</div>`;
  623. for (let ii = 0; ii < $selectedItems.length; ii++) {
  624. const selectCheck = $selectedItems.eq(ii).find('input[type="checkbox"]');
  625. const selectName = $selectedItems.eq(ii).find('.sp-name');
  626. const isFolder = ($selectedItems.eq(ii).find('img').attr('src') === '/static/images/folder.png');
  627. const idArr = [];
  628. if ($selectedItems.eq(ii) && selectCheck.length && selectName.length) {
  629. name.push({
  630. id : selectCheck.val(),
  631. name : selectName.text(),
  632. isFolder : isFolder,
  633. });
  634. str += `<div>
  635. <div>
  636. <div>${selectName.text()}</div>
  637. <div class="loading_image_${ii}_box">
  638. <img class="loading_image_${ii}" src="/static/images/refresh.png" alt="로딩 이미지" width="25" height="25">
  639. </div>
  640. </div>
  641. <div class="loading-gauge-box">
  642. <div>
  643. <div class="loading-background"></div>
  644. <div class="loading-gauge gauge_${ii}"></div>
  645. </div>
  646. <div><span class="gauge_${ii}_value">0</span> %</div>
  647. </div>
  648. </div>`
  649. }
  650. }
  651. if (jsonData && jsonData.id) {
  652. let uri = '/api/copy-item';
  653. if (selectId === currentId) {
  654. uri = '/api/move-item';
  655. }
  656. else {
  657. $('.modal-move-box .content').append(str);
  658. }
  659. let param = {
  660. siteId : currentId,
  661. itemId : itemId,
  662. id : jsonData.id,
  663. name : JSON.stringify(name),
  664. driveId : jsonData.parentReference.driveId,
  665. text : text,
  666. }
  667. $.ajax({
  668. method : 'post',
  669. url : uri,
  670. data : param,
  671. global: false,
  672. success : (res) => {
  673. if (res){
  674. let message = res.message;
  675. let failIndexes = [];
  676. if (res.failItems && res.failItems.length) {
  677. res.failItems.forEach((failItem)=>{
  678. let idx = name.findIndex(obj=> obj.name === failItem.name);
  679. failIndexes.push(idx);
  680. $('.loading_image_' + idx).remove();
  681. $('.loading_image_' + idx +'_box').html('실패');
  682. });
  683. }
  684. if (res.locations && res.locations.length > 0) {
  685. // function getLoadingState(arr, totalCount){
  686. // Promise.all(res.locations.map((val, idx) => {
  687. // if (failIndexes.includes(idx)) {
  688. // return null;
  689. // }
  690. // if (name[idx].isFolder) {
  691. // return $.ajax({ url: '/api/folder-count', global : false, method: 'post',
  692. // data: { id: jsonData.id, siteId: selectId, name: name[idx].name,
  693. // originSiteId: currentId, originId: name[idx].id, totalCount: totalCount }
  694. // });
  695. // }
  696. // return $.ajax({url: '/api/loading', global: false, method:'post', data: {url: val}});
  697. // }))
  698. // .then((values)=>{
  699. // console.log(values);
  700. // if (values) {
  701. // const array = [];
  702. // for (let idx in values) {
  703. // const value = values[idx];
  704. // if (value && value.percentageComplete) {
  705. // if (value.percentageComplete !== 100) {
  706. // array.push(res.locations[idx]);
  707. // }
  708. // else {
  709. // $('.loading_image_' + idx).remove();
  710. // $('.loading_image_' + idx +'_box').html('완료됨');
  711. // }
  712. // const percent = value.percentageComplete;
  713. // $('.gauge_'+ idx).css('width', percent+'%');
  714. // $('.gauge_'+ idx + '_value').html(percent);
  715. // }
  716. // else if(value && value.totalCount){
  717. // console.log(value);
  718. // }
  719. // }
  720. // if (array.length) {
  721. // setTimeout(()=>{
  722. // getLoadingState(array);
  723. // }, 2000)
  724. // }
  725. // else {
  726. // if (text === '이동') {
  727. // const checkedArr = [];
  728. // name.forEach((obj)=>{
  729. // checkedArr.push(obj.id);
  730. // });
  731. // $.ajax({
  732. // url: '/api/delete',
  733. // global: false,
  734. // method:'post',
  735. // data: {
  736. // siteId : currentId,
  737. // itemIds : JSON.stringify(checkedArr),
  738. // },
  739. // success: (res)=>{
  740. // console.log();
  741. // if (res && res.success === 'S') {
  742. // alertMessage(alertTitle, message);
  743. // const selected = $('section .panel-item.on');
  744. // selected.removeClass('on');
  745. // selected.click();
  746. // modalClose('move');
  747. // }
  748. // },
  749. // error : (error)=>{
  750. // console.log(error);
  751. // }
  752. // });
  753. // }
  754. // else {
  755. // alertMessage(alertTitle, message);
  756. // const selected = $('section .panel-item.on');
  757. // selected.removeClass('on');
  758. // selected.click();
  759. // modalClose('move');
  760. // }
  761. // }
  762. // }
  763. // })
  764. // .catch((error)=>{
  765. // console.log(error);
  766. // })
  767. // }
  768. // getLoadingState(res.locations);
  769. // jsonData.id, siteId: selectId, name: name[idx].name,
  770. // originSiteId: currentId, originId: name[idx].id, totalCount: totalCount
  771. for (let idx in res.locations) {
  772. if (!failIndexes.includes(idx)) {
  773. getFileState(jsonData.id, selectId, name[idx].name, currentId, name[idx].id, 0,
  774. res.locations[idx], name[idx].isFolder, idx, alertTitle, message);
  775. }
  776. }
  777. }
  778. else {
  779. alertMessage(alertTitle, message);
  780. const selected = $('section .panel-item.on');
  781. selected.removeClass('on');
  782. selected.click();
  783. modalClose('move');
  784. }
  785. }
  786. },
  787. error : (error) => {
  788. console.log(error);
  789. }
  790. })
  791. }
  792. else {
  793. alertMessage(alertTitle, '선택된 그룹 정보를 찾을 수 없습니다.');
  794. }
  795. });
  796. }
  797. else {
  798. alertMessage(alertTitle, '선택된 그룹 정보를 찾을 수 없습니다.');
  799. }
  800. });
  801. }
  802. else {
  803. alertMessage(alertTitle, '선택된 그룹 정보를 찾을 수 없습니다.');
  804. }
  805. }
  806. function getFileState(id, siteId, name, originSiteId, originId, totalCount, value, isFolder, idx, alertTitle, message) {
  807. const wss = new WebSocket('wss://localhost:53000/');
  808. wss.onopen = (event)=>{
  809. console.log('WebSocket Connection');
  810. wss.send(JSON.stringify({id: id, siteId : siteId, name: name, originSiteId : originSiteId,
  811. originId : originId, totalCount: totalCount, value : value, isFolder : isFolder}));
  812. };
  813. wss.onclose = (event)=>{
  814. console.log('WebSocket Close')
  815. };
  816. wss.onmessage = async (event)=>{
  817. if (event.data) {
  818. const percent = event.data;
  819. $('.gauge_'+ idx).css('width', percent+'%');
  820. $('.gauge_'+ idx + '_value').html(percent);
  821. if (percent === '100') {
  822. $('.loading_image_' + idx).remove();
  823. $('.loading_image_' + idx +'_box').html('완료됨');
  824. try {
  825. const deleteData = await $.ajax({
  826. url: '/api/delete',
  827. global: false,
  828. method:'post',
  829. data: {
  830. siteId : originSiteId,
  831. itemIds : JSON.stringify([originId]),
  832. },});
  833. console.log(deleteData);
  834. }
  835. catch(error) {
  836. console.log(error);
  837. }
  838. if ($('.modal.move').length && $('img[src="/static/images/refresh.png"]').length === 0) {
  839. alertMessage(alertTitle, message);
  840. const selected = $('section .panel-item.on');
  841. selected.removeClass('on');
  842. selected.click();
  843. modalClose('move');
  844. }
  845. wss.close();
  846. }
  847. }
  848. };
  849. wss.onerror = (event)=>{
  850. console.log('에러 :',event.data)
  851. };
  852. }
  853. function setContent(siteId, event) {
  854. const $selectEl = $('#move_' + siteId);
  855. const $selectedEl = $('.modal-move-box .left-box div.on');
  856. const selectTitle = $('.modal-move-box .panel-item.on').text().trim();
  857. if ($selectEl.text().trim() === selectTitle) {
  858. return;
  859. }
  860. $selectedEl.removeClass('on');
  861. $selectEl.addClass('on');
  862. drawMoveItems(siteId, '/drive/root');
  863. }
  864. function drawMoveItems(siteId, path) {
  865. const $panel = $('.modal .modal-move-box .right-box .panel');
  866. const imgSrc = $('#move_' + siteId+ ' img').attr('src');
  867. const text = $('#move_' + siteId).text().trim();
  868. let onOff = 'on';
  869. if (path && path.includes('/drive/root:')) {
  870. onOff = '';
  871. }
  872. let str = "";
  873. if (path && path.includes('/drive/root:')) {
  874. str = `<div class="panel-item" onclick="drawMoveItems('${siteId}', '/drive/root')">`
  875. if (text !== '내 파일') {
  876. str +=`<img width="24" height="24" src="${imgSrc}" alt="아이콘">&nbsp;&nbsp;`
  877. }
  878. str +=`${text}</div>`;
  879. let itemPath = path.replace('/drive/root:/', '');
  880. let pathArr = itemPath.split('/');
  881. if (pathArr && pathArr.length > 0) {
  882. let directoryRoot = '';
  883. let id = "";
  884. pathArr.forEach((directory, idx)=>{
  885. if (directory) {
  886. onOff = '';
  887. directoryRoot += `/${directory}`;
  888. let method = `drawMoveItems('${siteId}', '/drive/root:${directoryRoot}')`;
  889. if (idx === pathArr.length - 1) {
  890. onOff = 'on'
  891. method = '';
  892. }
  893. str += `<div> > </div><div class="panel-item ${onOff}" onclick="${method}">${directory}</div>`
  894. }
  895. })
  896. }
  897. }
  898. else {
  899. str = `<div class="panel-item on">`
  900. if (text !== '내 파일') {
  901. str +=`<img width="24" height="24" src="${imgSrc}" alt="아이콘">&nbsp;&nbsp;`
  902. }
  903. str +=`${text}</div>`;
  904. }
  905. $panel.html(str);
  906. const menuWidth = $('.modal .modal-move-box .right-box').width() - 40;
  907. const menuArr = $panel.children();
  908. let totalWidth = 0;
  909. for (let ii = 0; ii < menuArr.length; ii++) {
  910. const menu = menuArr.eq(ii);
  911. let gap = 10;
  912. if ( menuArr.length-1 === ii) {
  913. gap = 0;
  914. }
  915. totalWidth += menu.width() + gap;
  916. }
  917. if (menuWidth < totalWidth) {
  918. let div = '<div class="toggle-button">';
  919. for (let ii = 0; ii < menuArr.length; ii++) {
  920. const menu = menuArr.eq(ii);
  921. totalWidth -= menu.width() + 10;
  922. if (menu.attr('class') && menu.attr('class').trim() === 'panel-item') {
  923. div += `<div onclick="${menu.attr('onclick')}">${menu.text().trim()}</div>`;
  924. }
  925. menu.css('display', 'none');
  926. if (menuWidth - 30 >= totalWidth && !menu.attr('class')) {
  927. div += '</div>';
  928. break;
  929. }
  930. }
  931. console.log(div);
  932. $panel.prepend($(`<div class="menu-button"><img src="/static/images/dote.png" width="20" height="20"></div>
  933. ${div}
  934. `));
  935. $('.menu-button').off('click');
  936. $('.menu-button').on('click', ()=>{
  937. $('.toggle-button').toggle();
  938. })
  939. }
  940. callApi('get', '/sites/' + siteId + path, (parentData)=>{
  941. const $list = $('.modal-move-box .right-box .content .list');
  942. if (parentData && parentData.folder && parentData.folder.childCount) {
  943. callApi('get', '/sites/' +siteId +'/drive/items/' + parentData.id + '/children', (childrenData)=>{
  944. const items = childrenData.value;
  945. if (items && items.length > 0) {
  946. let listStr = "";
  947. for (let idx in items) {
  948. const item = items[idx];
  949. let itemPath = '/drive/root';
  950. if (item.parentReference && item.parentReference.path) {
  951. itemPath = item.parentReference.path + '/' + item.name;
  952. }
  953. listStr += getListStr(item, idx, siteId, itemPath);
  954. }
  955. $list.html(listStr);
  956. }
  957. else {
  958. listStr = getListStr(null, null, siteId);
  959. $list.html(listStr);
  960. }
  961. })
  962. }
  963. else {
  964. $list.html(getEmptyBox());
  965. }
  966. })
  967. }
  968. function getListStr(obj, idx, siteId, itemPath) {
  969. if (obj && !isNaN(Number(idx)) && siteId){
  970. let isFolder = obj.folder;
  971. let className = '';
  972. let date = '-';
  973. let name = '-';
  974. let modifyName = '-';
  975. let path = '/drive/root';
  976. let method = `drawMoveItems('${siteId}', '${itemPath}')`;
  977. if (!isFolder) {
  978. className = 'off';
  979. method = '';
  980. }
  981. if (obj.name) {
  982. name = obj.name;
  983. }
  984. if (obj.lastModifiedBy && obj.lastModifiedBy.user && obj.lastModifiedBy.user.displayName) {
  985. modifyName = obj.lastModifiedBy.user.displayName;
  986. }
  987. if (obj.lastModifiedDateTime) {
  988. date = obj.lastModifiedDateTime.substring(0, obj.lastModifiedDateTime.indexOf('T'));
  989. }
  990. const imgData = getFileImage(obj);
  991. return `<div class="move_row row_${idx} ${className}">
  992. <div><img src="${imgData[0]}" alt="${imgData[1]}" width="25" height="25"></div>
  993. <div><span onclick="${method}" class="file-name">${name}</span></div>
  994. <div>${date}</div>
  995. <div>${modifyName}</div>
  996. </div>`;
  997. }
  998. else {
  999. return getEmptyBox();
  1000. }
  1001. }
  1002. function getEmptyBox() {
  1003. return `<div class="empty-box">
  1004. <img src="/static/images/empty_folder_v2.svg" alt="이미지">
  1005. <div>이 폴더는 비어 있습니다.</div>
  1006. </div>`
  1007. }
  1008. //새로고침 이벤트
  1009. function refreshDrive() {
  1010. const selectedDrive = $('.panel-item.on');
  1011. if (selectedDrive[0]) {
  1012. selectedDrive.removeClass('on');
  1013. selectedDrive.click();
  1014. }
  1015. }
  1016. //체크에 따른 css 적용
  1017. function checkState(event){
  1018. const $target = $(event.target);
  1019. const $row = $('#'+$target.attr('name'));
  1020. let method = 'removeClass';
  1021. if ($target.is(':checked')) {
  1022. method = 'addClass';
  1023. }
  1024. $row[method]('on');
  1025. }
  1026. //삭제 이벤트
  1027. function deleteItem() {
  1028. const checkArr = $('.file-content input[type="checkbox"]');
  1029. const checkedArr = [];
  1030. let siteId = getSitesId();
  1031. if (!siteId) {
  1032. return alertMessage('파일 삭제','그룹 정보를 확인 할 수 없습니다.');
  1033. }
  1034. if (checkArr.length > 0) {
  1035. for (let ii = 0; ii < checkArr.length; ii++) {
  1036. if (checkArr.eq(ii).is(':checked')) {
  1037. const title = checkArr.eq(ii).parent().next().text();
  1038. const team = _listData.joinedTeams;
  1039. const idx = team.teams.findIndex(obj => obj.sharePoint.siteId === siteId);
  1040. if (idx >= 0) {
  1041. const sameIndex = team.items[team.teams[idx].id].findIndex(obj => obj.id === checkArr.eq(ii).val());
  1042. if (sameIndex >= 0) {
  1043. return alertMessage('파일 삭제', '채널 정보는 삭제하실수 없습니다.');
  1044. };
  1045. }
  1046. checkedArr.push(checkArr.eq(ii).val());
  1047. }
  1048. }
  1049. if (checkedArr.length === 0) {
  1050. alertMessage('파일 삭제', '선택된 정보가 없습니다. 삭제하실 파일을 먼저 선택해주세요.');
  1051. }
  1052. else {
  1053. confirmMessage('파일 삭제', '선택된 파일을 삭제하시겠습니까?', ()=>{
  1054. $.ajax({
  1055. method:'post',
  1056. url : "/api/delete",
  1057. data: {
  1058. siteId: siteId,
  1059. itemIds : JSON.stringify(checkedArr),
  1060. },
  1061. success: (res)=> {
  1062. if (res.success === 'S') {
  1063. refreshDrives();
  1064. }
  1065. $('.modal').remove();
  1066. alertMessage('파일 삭제', res.message);
  1067. },
  1068. error: (error)=> {
  1069. console.log(error);
  1070. }
  1071. })
  1072. })
  1073. }
  1074. }
  1075. }
  1076. //폴더 경로 가져오기
  1077. function getDrivePath(isMove) {
  1078. let path = '/drive/root';
  1079. let $pathArr = $('section .panel-item');
  1080. if (isMove) {
  1081. $pathArr = $('.modal-move-box .panel-item');
  1082. }
  1083. if ($pathArr.length > 1) {
  1084. path += ':';
  1085. for (let ii = 1; ii < $pathArr.length; ii++) {
  1086. path += '/' + $pathArr.eq(ii).text();
  1087. }
  1088. }
  1089. return path;
  1090. }
  1091. //다운로드 이벤트
  1092. function download(){
  1093. const fileArr = $('.file-content input[type="checkbox"]');
  1094. if (fileArr || fileArr.length) {
  1095. const fileIdArr = [];
  1096. for (let ii = 0; ii < fileArr.length; ii++) {
  1097. const isChecked = fileArr.eq(ii).is(':checked');
  1098. if (isChecked) {
  1099. fileIdArr.push(fileArr.eq(ii).val());
  1100. }
  1101. }
  1102. if (fileIdArr.length === 0) return alertMessage('다운로드', '다운로드 할 파일을 선택해주세요.');
  1103. $.ajax({
  1104. method: 'post',
  1105. url : '/api/download',
  1106. data : {
  1107. siteId : getSitesId(),
  1108. path : getDrivePath(),
  1109. fileIds : JSON.stringify(fileIdArr),
  1110. zipName : $('.panel-item.on').text().trim(),
  1111. },
  1112. success: (res)=>{
  1113. if (res.success === 'S') {
  1114. const dataUrl = window.URL.createObjectURL(new Blob([new Uint8Array(res.data.data).buffer]));
  1115. const link = document.createElement('a');
  1116. link.href = dataUrl;
  1117. link.download = res.name;
  1118. link.style.display = 'none';
  1119. $('body').append(link);
  1120. link.click();
  1121. link.remove();
  1122. }
  1123. else {
  1124. let message = res.message;
  1125. if (res.error) {
  1126. message += '<br>' + res.error;
  1127. }
  1128. alertMessage('다운로드', message);
  1129. }
  1130. },
  1131. error : (error) => {
  1132. console.log(error);
  1133. }
  1134. })
  1135. }
  1136. }
  1137. function drawPath(path, siteId, name) {
  1138. let imgSrc = '';
  1139. let panelStr = '';
  1140. if ($('#'+siteId + '_li').find('img')[0]) {
  1141. imgSrc = $('#'+siteId + '_li').find('img').attr('src');
  1142. }
  1143. if (path) {
  1144. let formatPath = path.substring(path.lastIndexOf('root:') + 5);
  1145. if (formatPath) {
  1146. formatPath = formatPath.substring(1);
  1147. formatPath = formatPath.split('/');
  1148. panelStr = `<span class="panel-item" id="${siteId}" onclick="siteDriveChildrenItems('${siteId}', '/drive/root', '${name}', '${siteId}', event)">`;
  1149. if (imgSrc) {
  1150. panelStr += `<img style="margin-right:5px;" width="24" height="24" src="${imgSrc}" alt="이미지">`
  1151. }
  1152. panelStr += ` ${name}</span>`;
  1153. let itemPath = "/drive/root:";
  1154. if (Array.isArray(formatPath)) {
  1155. for(let ii = 0; ii < formatPath.length; ii++) {
  1156. let pathName = formatPath[ii];
  1157. let className = 'panel-item';
  1158. itemPath += "/" + pathName;
  1159. let method = `siteDriveChildrenItems('${siteId}','${itemPath}', '${name}', null, event)`;
  1160. if (formatPath.length - 1 === ii) {
  1161. className += ' on';
  1162. // method = '';
  1163. }
  1164. panelStr += `<span> > </span><span class="${className}" onclick="${method}">${pathName}</span>`;
  1165. }
  1166. }
  1167. return panelStr;
  1168. }
  1169. }
  1170. panelStr = `<span class="panel-item on" id="${siteId}" onclick="siteDriveChildrenItems('${siteId}', '/drive/root', '${name}', '${siteId}', event)">`;
  1171. if (imgSrc) {
  1172. panelStr += `<img style="margin-right:5px;" width="24" height="24" src="${imgSrc}" alt="이미지">`
  1173. }
  1174. panelStr += ` ${name}</span>`;
  1175. return panelStr;
  1176. }
  1177. function dragAndDrop() {
  1178. const $fileContent = $('.file-content');
  1179. $fileContent.off('dragover');
  1180. $fileContent.off('dragleave');
  1181. $fileContent.off('drop');
  1182. $fileContent.on('dragover', function(e){
  1183. e.preventDefault();
  1184. $(this).css('background-color', '#eee');
  1185. });
  1186. $fileContent.on('dragleave', function(e){
  1187. $(this).css('background-color', '#f5f5f5');
  1188. })
  1189. $fileContent.on("drop", async function(e){
  1190. const transfer = e.originalEvent.dataTransfer;
  1191. e.preventDefault();
  1192. $(this).css('background-color', '#f5f5f5');
  1193. const items = transfer.items;
  1194. _formData = new FormData($('<form enctype="multipart/form-data"></form>')[0]);
  1195. const result = await getFilesDataTransferItems(items);
  1196. upload(_formData);
  1197. });
  1198. }
  1199. async function upload(formData) {
  1200. const folders = formData.getAll('folder');
  1201. const files = formData.getAll('file');
  1202. const alertTitle = '파일 업로드';
  1203. if (folders.length === 0 && files.length === 0) return;
  1204. if (folders && folders.length > 100) {
  1205. return alertMessage(alertTitle, '업로드 폴더는 최대 100개 까지 가능합니다.<br>업로드 폴더 수 : '+ folders.length, null, 'red');
  1206. }
  1207. if (files && files.length > 100) {
  1208. return alertMessage(alertTitle, '업로드 파일은 최대 100개 까지 가능합니다.\n업로드 파일 수 : '+ files.length, null, 'red');
  1209. }
  1210. let siteId = getSitesId();
  1211. if (siteId === null) {
  1212. return alertMessage(alertTitle, '선택된 그룹 정보를 찾을 수 없습니다. 생성할 그룹을 선택해주세요.', null, 'red');
  1213. }
  1214. const groupIndex = _listData.joinedTeams.teams.findIndex(obj => obj.sharePoint.siteId === siteId);
  1215. const pathArr = $('.panel').children();
  1216. if (groupIndex >= 0 && $('.panel').children().length === 1) {
  1217. return alertMessage(alertTitle,'채널에는 업로드 할 수 없습니다. 채널 리스트를 먼저 선택해 주세요.', null, 'red');
  1218. }
  1219. let sitePath = getDrivePath();
  1220. formData.append('siteId', siteId);
  1221. formData.append('path', sitePath);
  1222. $.ajax({
  1223. method: 'post',
  1224. processData : false,
  1225. contentType : false,
  1226. data : formData,
  1227. url : '/api/upload',
  1228. success: (res) => {
  1229. let str = res.message;
  1230. let color = null;
  1231. if (res.success === 'F') {
  1232. // str += '<br>오류 : ' + res.error.message;
  1233. color = 'red';
  1234. }
  1235. alertMessage(alertTitle, str, null, color);
  1236. refreshDrives();
  1237. },
  1238. error: (error) => {
  1239. console.log(error);
  1240. alertMessage(alertTitle, error, null, 'red');
  1241. },
  1242. });
  1243. }
  1244. function alertMessage(title, message, id, color) {
  1245. let method = "modalClose('alert')";
  1246. if (id) {
  1247. method = `modalClose('alert', '${id}')`;
  1248. }
  1249. $('body').append($(`<div class="modal alert" style="display:flex;">
  1250. <div class="modal-box">
  1251. <div class="header">
  1252. <div class="title">${title}</div>
  1253. <div class="x-button">
  1254. <span><img src="/static/images/x-button.png" width="15" height="15" alt="닫기 버튼" onclick="modalClose('alert')"></span>
  1255. </div>
  1256. </div>
  1257. <div class="modal-content">
  1258. ${message}
  1259. </div>
  1260. <div class="button-box">
  1261. <div class="name-btn" onclick="${method}">확인</div>
  1262. </div>
  1263. </div>
  1264. </div>
  1265. </div>`));
  1266. if (color) {
  1267. $('.modal.alert').addClass(color);
  1268. }
  1269. }
  1270. function confirmMessage(title, message, method) {
  1271. $('body').append($(`<div class="modal confirm" style="display:flex;">
  1272. <div class="modal-box">
  1273. <div class="header">
  1274. <div class="title">${title}</div>
  1275. <div class="x-button">
  1276. <span><img src="/static/images/x-button.png" width="15" height="15" alt="닫기 버튼" onclick="modalClose('confirm')"></span>
  1277. </div>
  1278. </div>
  1279. <div class="modal-content">
  1280. ${message}
  1281. </div>
  1282. <div class="button-box">
  1283. <div class="success-button" >확인</div>
  1284. <div class="name-btn" onclick="modalClose('confirm')">취소</div>
  1285. </div>
  1286. </div>
  1287. </div>
  1288. </div>`));
  1289. $('.success-button').on('click', ()=>{
  1290. method();
  1291. })
  1292. }
  1293. function confirmMethod(method) {
  1294. method();
  1295. }
  1296. function getUploadItems(dataTransferItems) {
  1297. for (let item of dataTransferItems) {
  1298. if (item.isFile) {
  1299. item.file(file => {
  1300. _formData.append('file', file);
  1301. _formData.append(file.name + '_path', item.fullPath);
  1302. })
  1303. }
  1304. else if (item.isDirectory) {
  1305. _formData.append('folder', JSON.stringify({name : item.name, path : item.fullPath}));
  1306. // _formData.append('path', item.fullPath);
  1307. let dirReader = item.createReader();
  1308. dirReader.readEntries(entries => {
  1309. for (let entry of entries) {
  1310. getUploadItems(entry);
  1311. }
  1312. })
  1313. }
  1314. }
  1315. }
  1316. // function getFilesDataTransferItems(dataTransferItems) {
  1317. // function traverseFileTreePromise(item, folder) {
  1318. // return new Promise(resolve => {
  1319. // let subfolder = [];
  1320. // let files = [];
  1321. // let fileObj = {};
  1322. // if (item.isFile) {
  1323. // item.file(file => {
  1324. // let fileName = file.name;
  1325. // // if (file.name.indexOf('.') > 0) {
  1326. // // fileName = file.name.substring(0, file.name.lastIndexOf('.'));
  1327. // // }
  1328. // let path = item.fullPath.substring(0, item.fullPath.lastIndexOf('/'));
  1329. // if (!path) {
  1330. // path = '';
  1331. // }
  1332. // _formData.append('file', file);
  1333. // _formData.append(fileName + '_path', path);
  1334. // resolve(fileObj);
  1335. // });
  1336. // } else if (item.isDirectory) {
  1337. // let dirReader = item.createReader();
  1338. // const path = item.fullPath.substring(0, item.fullPath.lastIndexOf('/'));
  1339. // _formData.append('folder', JSON.stringify({name : item.name, path : path}));
  1340. // dirReader.readEntries(entries => {
  1341. // let entriesPromises = [];
  1342. // fileObj = {
  1343. // path : item.fullPath,
  1344. // param : {
  1345. // name: item.name,
  1346. // folder: {},
  1347. // '@microsoft.graph.conflictBehavior': 'rename'
  1348. // },
  1349. // subfolder : subfolder,
  1350. // };
  1351. // folder.push(fileObj);
  1352. // for (let entr of entries) {
  1353. // entriesPromises.push(
  1354. // traverseFileTreePromise(entr, subfolder)
  1355. // );
  1356. // }
  1357. // resolve(Promise.all(entriesPromises));
  1358. // });
  1359. // }
  1360. // });
  1361. // }
  1362. // let files = [];
  1363. // return new Promise((resolve, reject) => {
  1364. // let entriesPromises = [];
  1365. // for (let it of dataTransferItems)
  1366. // entriesPromises.push(
  1367. // traverseFileTreePromise(it.webkitGetAsEntry(), files)
  1368. // );
  1369. // Promise.all(entriesPromises).then(entries => {
  1370. // resolve(files);
  1371. // });
  1372. // });
  1373. // }
  1374. function getFilesDataTransferItems(dataTransferItems) {
  1375. function traverseFileTreePromise(item, folder) {
  1376. return new Promise(resolve => {
  1377. let subfolder = [];
  1378. let files = [];
  1379. let fileObj = {};
  1380. if (item.isFile) {
  1381. item.file(file => {
  1382. let fileName = file.name;
  1383. // if (file.name.indexOf('.') > 0) {
  1384. // fileName = file.name.substring(0, file.name.lastIndexOf('.'));
  1385. // }
  1386. let path = item.fullPath.substring(0, item.fullPath.lastIndexOf('/'));
  1387. if (!path) {
  1388. path = '';
  1389. }
  1390. _formData.append('file', file);
  1391. _formData.append(fileName + '_path', path);
  1392. console.log(path);
  1393. resolve(fileObj);
  1394. });
  1395. } else if (item.isDirectory) {
  1396. let dirReader = item.createReader();
  1397. const path = item.fullPath.substring(0, item.fullPath.lastIndexOf('/'));
  1398. _formData.append('folder', JSON.stringify({name : item.name, path : path}));
  1399. console.log(path);
  1400. dirReader.readEntries(entries => {
  1401. let entriesPromises = [];
  1402. fileObj = {
  1403. path : item.fullPath,
  1404. param : {
  1405. name: item.name,
  1406. folder: {},
  1407. '@microsoft.graph.conflictBehavior': 'rename'
  1408. },
  1409. subfolder : subfolder,
  1410. };
  1411. folder.push(fileObj);
  1412. for (let entr of entries) {
  1413. entriesPromises.push(
  1414. traverseFileTreePromise(entr, subfolder)
  1415. );
  1416. }
  1417. resolve(Promise.all(entriesPromises));
  1418. });
  1419. }
  1420. });
  1421. }
  1422. let files = [];
  1423. return new Promise((resolve, reject) => {
  1424. let entriesPromises = [];
  1425. for (let it of dataTransferItems)
  1426. entriesPromises.push(
  1427. traverseFileTreePromise(it.webkitGetAsEntry(), files)
  1428. );
  1429. Promise.all(entriesPromises).then(entries => {
  1430. resolve(files);
  1431. });
  1432. });
  1433. }
  1434. function encryptFile(file, driveId) {
  1435. const extArr = [
  1436. 'lnk', 'exe', 'com', 'cmd', 'bat', 'dll', 'ini',
  1437. 'pst', 'sca', 'drm', 'sys', 'cpl', 'inf', 'drv',
  1438. 'dat', 'tmp', 'msp', 'msi', 'pdb', 'jar'
  1439. ]
  1440. if (file && file.name) {
  1441. const ext = file.name.substring(file.name.lastIndexOf('.') + 1);
  1442. if (extArr.includes(ext)) {
  1443. const modal = `<div class="modal error" style="display: flex;">
  1444. <div style="display:flex; border:1px solid red; flex-direction: column; padding:20px;justify-content:center;width:400px;height:120px; background-color:white;">
  1445. <div style='width:100%;margin-bottom:10px; height:40px;display:flex;justify-content:space-between; align-items:center; font-weight: bold; font-size: 18px;'>
  1446. <div style="">파일 형식 오류</div>
  1447. <div onclick="modalClose('error')" style="cursor:pointer; user-select:none;">x</div>
  1448. </div>
  1449. <div>
  1450. 암호화 할수 없는 형식의 파일입니다.<br>
  1451. 파일명 : ${file.name}
  1452. </div>
  1453. </div>
  1454. </div>`;
  1455. $('body').append($(modal));
  1456. return;
  1457. }
  1458. }
  1459. }
  1460. function callApi(type, uri, callBackMethod, args, params) {
  1461. $.ajax({
  1462. method: 'post',
  1463. url : "/api-"+type,
  1464. data: {
  1465. api_uri: uri,
  1466. param : JSON.stringify(params),
  1467. },
  1468. success: (res)=> {
  1469. callBackMethod(res, args);
  1470. },
  1471. error: (error)=> {
  1472. console.log(error);
  1473. }
  1474. });
  1475. }
  1476. function siteDriveChildrenItems(siteId, path, name, value, event) {
  1477. event.preventDefault();
  1478. event.stopPropagation();
  1479. const toggleBox = document.getElementsByClassName('toggle-box');
  1480. if (document.getElementsByClassName('toggle-box')){
  1481. $(toggleBox).remove();
  1482. }
  1483. if ($('#all-check').is(':checked')) {
  1484. $('#all-check').prop('checked', false);
  1485. }
  1486. if ($(event.target).hasClass('on')) {
  1487. return;
  1488. }
  1489. if (value) {
  1490. // $('.tree.group input').prop('checked', true);
  1491. $('input[value="'+value+'"]').prop('checked', false);
  1492. if ($('section .panel').children().text() === name) {
  1493. return;
  1494. }
  1495. }
  1496. callApi('get', '/sites/' +siteId + path, (jsonData)=>{
  1497. if (jsonData && jsonData.id) {
  1498. if (jsonData.folder && jsonData.folder.childCount === 0) {
  1499. if (path.indexOf('root:') < 0) {
  1500. path = '';
  1501. }
  1502. const panelStr = drawPath(path, siteId, name);
  1503. const $oneDriveBtn = $('.one-drive-button');
  1504. const $fileContent = $('.file-content');
  1505. const $panel = $('section .panel');
  1506. $oneDriveBtn.off('click');
  1507. let text = name;
  1508. if (name !== 'One Drive') {
  1509. text = 'SharePoint'
  1510. }
  1511. $oneDriveBtn.text(text+'에서 열기');
  1512. if (jsonData.webUrl){
  1513. $oneDriveBtn.on('click', ()=>{
  1514. window.open(jsonData.webUrl);
  1515. });
  1516. }
  1517. $fileContent.html(`<div class="empty-box">
  1518. <img src="/static/images/empty_folder_v2.svg" alt="이미지">
  1519. <div>이 폴더는 비어 있습니다.</div>
  1520. </div>`);
  1521. $panel.html(panelStr);
  1522. dragAndDrop();
  1523. return;
  1524. }
  1525. callApi('get', '/sites/' +siteId +'/drive/items/'+jsonData.id+'/children', (childrenData)=>{
  1526. drawDriveFiles(childrenData, jsonData, name);
  1527. },null);
  1528. }
  1529. })
  1530. }
  1531. function getVolume(amount) {
  1532. const tb = 1099511627776;
  1533. const gb = 1073741824;
  1534. const mb = 1048576;
  1535. const kb = 1024;
  1536. if (!isNaN(Number(amount)) && amount > 0) {
  1537. if (amount >= tb) {
  1538. amount = (amount/tb).toFixed(2) + 'TB';
  1539. }
  1540. else if (amount >= gb){
  1541. amount = (amount/gb).toFixed(2) + 'GB';
  1542. }
  1543. else if (amount >= mb){
  1544. amount = (amount/mb).toFixed(2) + 'MB';
  1545. }
  1546. else if (amount >= kb){
  1547. amount = (amount/kb).toFixed(2) + 'KB';
  1548. }
  1549. else {
  1550. amount += "Byte";
  1551. }
  1552. }
  1553. return amount;
  1554. }
  1555. function getGroupList() {
  1556. $.ajax({
  1557. method: 'post',
  1558. url : "/getGroupList",
  1559. success: (res)=> {
  1560. drawList(res);
  1561. },
  1562. error: (error)=> {
  1563. console.log(error);
  1564. }
  1565. })
  1566. }
  1567. function drawList(jsonData) {
  1568. const group = $('.group');
  1569. group.empty();
  1570. if (jsonData) {
  1571. _listData = jsonData;
  1572. const groupImageUrl = "/_api/siteiconmanager/getsitelogo?type='1'";
  1573. const {oneDrive, joinedTeams, sites} = jsonData;
  1574. let parentId = '';
  1575. let siteId = '';
  1576. let str = "";
  1577. if (joinedTeams && joinedTeams.teams.length > 0) {
  1578. str += `<li>
  1579. <input id="my-team" type="checkbox">
  1580. <label for="my-team">내 Teams 그룹</label>
  1581. <ul class="group-section">
  1582. `
  1583. joinedTeams.teams.forEach((team)=>{
  1584. const items = joinedTeams.items[team.id];
  1585. let siteId = team.sharePoint.siteId;
  1586. str += `<li id="${siteId}_li">
  1587. <input type="checkbox" checked="false" id="${siteId}_check" value="${siteId}">
  1588. <label for="${siteId}_check"><img width="24" height="24" src="${team.sharePoint.siteUrl}${groupImageUrl}" alt="이미지">&nbsp;${team.displayName}</label>
  1589. <ul>`;
  1590. if (items && items.length > 0) {
  1591. items.forEach((item)=>{
  1592. str +=`<li id="${item.id}" onclick="siteDriveChildrenItems('${siteId}', '/drive/root:/${item.name}', '${team.displayName}', null, event)">${item.name}</li>`
  1593. })
  1594. }
  1595. str +=`</ul></li>`;
  1596. })
  1597. str += '</ul></li>';
  1598. }
  1599. if (oneDrive) {
  1600. const {teams, items} = oneDrive;
  1601. const sharePoint = teams.sharePoint;
  1602. siteId = sharePoint.siteId;
  1603. str += `<div id="${siteId}_li" onclick="siteDriveChildrenItems('${siteId}', '/drive/root', 'One Drive', '${siteId}', event)">
  1604. <img width="24" height="24" src="${sharePoint.siteUrl}${groupImageUrl}" alt="그룹 이미지">&nbsp;One Drive
  1605. </div>`;
  1606. }
  1607. if (sites) {
  1608. let {teams, items} = sites;
  1609. if (!Array.isArray(teams)) {
  1610. teams = [teams];
  1611. }
  1612. for (let team of teams) {
  1613. let siteId = team.sharePoint.siteId;
  1614. let path;
  1615. let imageUrl;
  1616. str += `
  1617. <div id="${siteId}_li" onclick="siteDriveChildrenItems('${siteId}', '/drive/root', '${team.displayName}', '${siteId}', event)">
  1618. <img width="24" height="24" src="${team.sharePoint.siteUrl}${groupImageUrl}" alt="그룹 이미지">&nbsp;${team.displayName}
  1619. </div>`;
  1620. }
  1621. }
  1622. group.append($(str));
  1623. }
  1624. }
  1625. function sorting(type) {
  1626. const $sortingColumn = $('.head-'+type);
  1627. const isSelected = $sortingColumn.hasClass('on');
  1628. if ($('.file-title > div.on')[0]) {
  1629. $('.file-title > div.on').removeClass('on');
  1630. }
  1631. if (_selectedData.value.length > 0) {
  1632. let first = 1;
  1633. let end = -1;
  1634. if (!isSelected) {
  1635. $sortingColumn.addClass('on');
  1636. }
  1637. else {
  1638. first = -1;
  1639. end = 1;
  1640. }
  1641. _selectedData.value.sort(function (a, b){
  1642. return a[type] > b[type] ? first : a[type] === b[type] ? 0 : end;
  1643. });
  1644. }
  1645. }
  1646. $('.tree.group input[type="checkbox"]').on('change', function(event){
  1647. console.log($(this));
  1648. })
  1649. function downloadItems(downloadUrl, name, event) {
  1650. event.preventDefault();
  1651. event.stopPropagation();
  1652. const link = document.createElement('a');
  1653. link.download = name;
  1654. link.href = downloadUrl;
  1655. $('body').append(link);
  1656. link.click();
  1657. $(link).remove();
  1658. window.URL.revokeObjectURL(downloadUrl);
  1659. }
  1660. //새로만들기 이벤트
  1661. function makeItems(id, name, url, ext) {
  1662. const $name = $('#'+id);
  1663. let nameVal = $name.val();
  1664. if (!nameVal || !nameVal.trim()) {
  1665. return alertMessage(name, name + "명을 입력해주세요.", id, 'red');
  1666. }
  1667. const pattern = /[<>\:\*\"\/\\\?\|]/gi;
  1668. if (pattern.test(nameVal)) {
  1669. $name.focus();
  1670. return alertMessage(name, name + `명에 해당 특수 문자를 포함 할 수 없습니다.( \\ / : * ? " < > | )`, id, 'red');
  1671. }
  1672. if (ext) {
  1673. nameVal += ext;
  1674. }
  1675. const siteId = getSitesId();
  1676. if (siteId === null) {
  1677. return alertMessage(name, '선택된 그룹 정보를 찾을 수 없습니다. 생성할 그룹을 선택해주세요.', null, 'red');
  1678. }
  1679. const groupIndex = _listData.joinedTeams.teams.findIndex(obj => obj.sharePoint.siteId === siteId);
  1680. const pathArr = $('.panel').children();
  1681. if (groupIndex >= 0 && $('.panel').children().length === 1) {
  1682. return alertMessage(name, '채널 리스트를 먼저 선택해 주세요.', null, 'red');
  1683. }
  1684. const fileArr = $('section .file-content .sp-name');
  1685. for (let ii = 0; ii < fileArr.length; ii++) {
  1686. if (fileArr.eq(ii).text() === nameVal) {
  1687. $name.focus();
  1688. return alertMessage(name, '파일명 : ' + nameVal +'<br>이미 같은 이름의 파일이 있습니다.<br>생성할 파일 명칭을 변경해주세요.', id, 'red');
  1689. }
  1690. }
  1691. const path = getDrivePath();
  1692. $.ajax({
  1693. method: 'post',
  1694. url : url,
  1695. data : {
  1696. siteId : siteId,
  1697. path : path,
  1698. name : nameVal,
  1699. },
  1700. success: (res) => {
  1701. alertMessage(name, res.message);
  1702. if (res.success === 'S') {
  1703. modalClose('make');
  1704. refreshDrives();
  1705. }
  1706. },
  1707. error: (error) => {
  1708. console.log('==============error=============\n');
  1709. console.log(error);
  1710. }
  1711. })
  1712. }
  1713. //새폴더 생성
  1714. function mkdir() {
  1715. const modalContainer = $(
  1716. `<div class="modal make" style="display: flex;">
  1717. <div class="modal-box">
  1718. <div class="header">
  1719. <div class="title">폴더 생성</div>
  1720. <div class="x-button">
  1721. <span><img src="/static/images/x-button.png" width="15" height="15" alt="닫기 버튼" onclick="modalClose('make')"></span>
  1722. </div>
  1723. </div>
  1724. <div class="modal-content">
  1725. <div>폴더명</div>
  1726. <input type="text" name="file_name" autocomplete='off' onkeyup="enterKey(()=>makeItems('folder_name', '폴더', '/api/makeFolder', null), event)" id="folder_name" value="">
  1727. </div>
  1728. <div class="button-box">
  1729. <div class="name-btn" onclick="makeItems('folder_name', '폴더', '/api/makeFolder', null)">만들기</div>
  1730. <div class="name-btn" onclick="modalClose('make')">취소</div>
  1731. </div>
  1732. </div>
  1733. </div>`);
  1734. $('body').append(modalContainer);
  1735. $('#folder_name').focus();
  1736. }
  1737. //새 엑셀 파일 생성
  1738. function mkExcel() {
  1739. const modalContainer = $(
  1740. `<div class="modal make" style="display: flex;">
  1741. <div class="modal-box">
  1742. <div class="header">
  1743. <div class="title">Excel 통합 문서</div>
  1744. <div class="x-button">
  1745. <span><img src="/static/images/x-button.png" width="15" height="15" alt="닫기 버튼" onclick="modalClose('make')"></span>
  1746. </div>
  1747. </div>
  1748. <div class="modal-content">
  1749. <div>이름</div>
  1750. <div style="display:flex; align-items:flex-end; user-select:none;">
  1751. <input type="text" placeholder="새 이름을 입력하세요." style="width:'calc(100% - 35px)';" autocomplete='off' onkeyup="enterKey(()=>makeItems('excel_input', 'Excel 통합 문서', '/api/makeExcel', '.xlsx'), event)" name="change_name" id="excel_input" value="">&nbsp;.xlsx
  1752. </div>
  1753. </div>
  1754. <div class="button-box">
  1755. <div class="name-btn" onclick="makeItems('excel_input', 'Excel 통합 문서', '/api/makeExcel', '.xlsx')">만들기</div>
  1756. <div class="cancel-btn" onclick="modalClose('make')">취소</div>
  1757. </div>
  1758. </div>
  1759. </div>`);
  1760. $('body').append(modalContainer);
  1761. $('#excel_input').focus();
  1762. }
  1763. function mkWord() {
  1764. const modalContainer = $(
  1765. `<div class="modal make" style="display: flex;">
  1766. <div class="modal-box">
  1767. <div class="header">
  1768. <div class="title">Word 문서</div>
  1769. <div class="x-button">
  1770. <span><img src="/static/images/x-button.png" width="15" height="15" alt="닫기 버튼" onclick="modalClose('make')"></span>
  1771. </div>
  1772. </div>
  1773. <div class="modal-content">
  1774. <div>이름</div>
  1775. <div style="display:flex; align-items:flex-end; user-select:none;">
  1776. <input type="text" placeholder="새 이름을 입력하세요." style="width:'calc(100% - 35px)';" autocomplete='off' onkeyup="enterKey(()=>makeItems('word_input', 'Word 문서', '/api/makeWord', '.docx'), event)" name="change_name" id="word_input" value="">&nbsp;.docx
  1777. </div>
  1778. </div>
  1779. <div class="button-box">
  1780. <div class="name-btn" onclick="makeItems('word_input', 'Word 문서', '/api/makeWord', '.docx')">만들기</div>
  1781. <div class="cancel-btn" onclick="modalClose('make')">취소</div>
  1782. </div>
  1783. </div>
  1784. </div>`);
  1785. $('body').append(modalContainer);
  1786. $('#word_input').focus();
  1787. }
  1788. function mkPpt() {
  1789. const modalContainer = $(
  1790. `<div class="modal make" style="display: flex;">
  1791. <div class="modal-box">
  1792. <div class="header">
  1793. <div class="title">PowerPoint 프레젠테이션</div>
  1794. <div class="x-button">
  1795. <span><img src="/static/images/x-button.png" width="15" height="15" alt="닫기 버튼" onclick="modalClose('make')"></span>
  1796. </div>
  1797. </div>
  1798. <div class="modal-content">
  1799. <div>이름</div>
  1800. <div style="display:flex; align-items:flex-end; user-select:none;">
  1801. <input type="text" placeholder="새 이름을 입력하세요." style="width:'calc(100% - 35px)';" autocomplete='off' onkeyup="enterKey(()=>makeItems('ppt_input', 'PowerPoint 프레젠테이션', '/api/makePptx', '.pptx'), event)" name="change_name" id="ppt_input" value="">&nbsp;.docx
  1802. </div>
  1803. </div>
  1804. <div class="button-box">
  1805. <div class="name-btn" onclick="makeItems('ppt_input', 'PowerPoint 프레젠테이션', '/api/makePptx', '.pptx')">만들기</div>
  1806. <div class="cancel-btn" onclick="modalClose('make')">취소</div>
  1807. </div>
  1808. </div>
  1809. </div>`);
  1810. $('body').append(modalContainer);
  1811. $('#ppt_input').focus();
  1812. }
  1813. function enterKey(method, event) {
  1814. if (event.key === 'Enter' && $('.modal.alert').length === 0) {
  1815. method();
  1816. }
  1817. }
  1818. function modalClose(className, id){
  1819. $('.modal.' + className).remove();
  1820. if(id) {
  1821. $('#' + id).focus();
  1822. }
  1823. }
  1824. function getSitesId() {
  1825. let siteId = null;
  1826. if ($('.panel').children().first()[0]) {
  1827. siteId = $('.panel').children().first().attr('id');
  1828. }
  1829. return siteId;
  1830. }
  1831. function nameChange() {
  1832. const $checkbox = $('.file-content > div.on input[type="checkbox"]');
  1833. if ($checkbox.length > 1) return;
  1834. if (!$('.file-content > div.on .file_name')[0]) return;
  1835. const siteId = getSitesId();
  1836. const itemId = $checkbox.val();
  1837. const name = $('.file-content > div.on .file_name').text();
  1838. let ext = "";
  1839. let inputVal = name;
  1840. let width = '100%';
  1841. if(name.includes(".")) {
  1842. inputVal = name.substring(0, name.lastIndexOf("."));
  1843. ext = name.substring(name.lastIndexOf("."));
  1844. width = 'calc(100% - 35px)';
  1845. }
  1846. // callApi('get', "/sites/"+ siteId + "/drive/items/" + itemId, (jsonData)=>{
  1847. // console.log(jsonData);
  1848. // })
  1849. const modalContainer = $(
  1850. `<div class="modal name" style="display: flex;">
  1851. <div class="modal-box">
  1852. <div class="header">
  1853. <div class="title">이름 바꾸기</div>
  1854. <div class="x-button">
  1855. <span><img src="/static/images/x-button.png" width="15" height="15" alt="닫기 버튼" onclick="modalClose('name')"></span>
  1856. </div>
  1857. </div>
  1858. <div class="modal-content">
  1859. <div>이름</div>
  1860. <div style="display:flex; align-items:flex-end;">
  1861. <input type="text" style="width:${width};" name="change_name" id="${itemId}_input" value="${inputVal}">&nbsp;${ext}
  1862. </div>
  1863. </div>
  1864. <div class="button-box">
  1865. <div class="name-btn" onclick="updateDriveItems('${siteId}','${itemId}')">이름 바꾸기</div>
  1866. <div class="cancel-btn" onclick="modalClose('name')">취소</div>
  1867. </div>
  1868. </div>
  1869. </div>`);
  1870. $('body').append(modalContainer);
  1871. }
  1872. function updateDriveItems(siteId, itemId) {
  1873. const input = $('#' + itemId + '_input');
  1874. console.log($('#' + itemId + '_input').val() , $('#' + itemId + '_input').parent().text().trim());
  1875. let name = input.val();
  1876. const ext = input.parent().text().trim();
  1877. if (ext) {
  1878. name += ext;
  1879. }
  1880. $.ajax({
  1881. method: 'post',
  1882. url : '/api/update-name',
  1883. data : {
  1884. siteId : siteId,
  1885. itemId : itemId,
  1886. name : name,
  1887. },
  1888. success : (res)=> {
  1889. if (res.success === 'S') {
  1890. refreshDrives();
  1891. }
  1892. alertMessage('이름 변경',res.message);
  1893. },
  1894. error : (error) => {
  1895. alertMessage('이름 변경','오류가 발생하였습니다.<br>'+ error);
  1896. }
  1897. })
  1898. }
  1899. function refreshDrives() {
  1900. const selectDrive = $('.panel-item.on');
  1901. selectDrive.removeClass('on');
  1902. selectDrive.click();
  1903. }
  1904. </script>