hello.html 80 KB

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