file_operation.html 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. <html>
  2. <head>
  3. <title locale="title">File Operation</title>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">
  6. <link rel="stylesheet" href="../../script/semantic/semantic.min.css">
  7. <script type="text/javascript" src="../../script/jquery.min.js"></script>
  8. <script type="text/javascript" src="../../script/semantic/semantic.min.js"></script>
  9. <script type="text/javascript" src="../../script/ao_module.js"></script>
  10. <script type="text/javascript" src="../../script/applocale.js"></script>
  11. <style>
  12. .banner{
  13. background-color:#4287f5;
  14. height:50px;
  15. padding:12px;
  16. padding-left:20px;
  17. padding-top:16px;
  18. }
  19. #opricon{
  20. position:absolute;
  21. top:0px;
  22. right:0px;
  23. width:80px;
  24. height:80px;
  25. }
  26. .title{
  27. color:white;
  28. font-size:130%;
  29. }
  30. .content{
  31. padding:12px;
  32. }
  33. .info{
  34. margin-top:3px;
  35. white-space: nowrap;
  36. overflow: hidden;
  37. text-overflow: ellipsis;
  38. }
  39. </style>
  40. </head>
  41. <body>
  42. <div class="banner">
  43. <div class="title" locale="banner/title">Calculating Operation</div>
  44. <img id="opricon" src="img/loading.png" class="ui image"></img>
  45. </div>
  46. <div class="content">
  47. <div class="info"><span locale="info/from">From:</span> <span id="src"></span></div>
  48. <div class="info"><span locale="info/to">To:</span> <span id="dest"></span></div>
  49. <div class="info"><span locale="info/progress">Progress:</span> <span id="progress"> <i class="loading spinner icon"></i> <span>Calculating</span></div>
  50. <div class="ui active small progress" style="margin-top:18px;">
  51. <div id="progressbar" class="bar" style="width:100%; background-color:#4287f5;"></div>
  52. </div>
  53. </div>
  54. <div class="ui modal" id="duplicateAction">
  55. <div class="content">
  56. <div class="description" style="padding: 0px !important;">
  57. <p><i class="big exclamation triangle icon"></i> <span>At least one file has the same filename with another existsing file. <b>Which action should be taken?</b></span></p><br>
  58. </div>
  59. </div>
  60. <div class="actions">
  61. <div class="ui labeled button" onclick="continueProcess('overwrite');">
  62. Overwrite
  63. </div>
  64. <div class="ui labeled button" onclick="continueProcess('skip');">
  65. Skip
  66. </div>
  67. <div class="ui labeled button" style="color: #2fb55c;" onclick="continueProcess('keep');">
  68. Rename & Keep
  69. </div>
  70. </div>
  71. </div>
  72. <script>
  73. /*
  74. ArOZ Online File Operation Listener
  75. Usage: Pass in the following JSON object as hash with encodeURIComponent after JSON stringify
  76. {
  77. opr: {move / copy / zip / unzip / download / zipAndDown / unzipAndOpen},
  78. src: {filelist, allow multiple files},
  79. dest: {filepath},
  80. //Optional paramters
  81. overwriteMode: {skip / overwrite / keep},
  82. callbackWindowID: {floatWindow ID},
  83. callbackFunction: {target Window Function Name as String}
  84. }
  85. **For download opr, it will first buffer into the browser memory.
  86. It is not recommended for files > 2GB (Firefox Limit)
  87. Example callbackFunction: "refreshList()" (string)
  88. */
  89. var operationConfig = null;
  90. var opr = "";
  91. var maxPathDisplayLength = 40;
  92. var legacyMode = !('WebSocket' in window || 'MozWebSocket' in window); //Use AJAX instead of WebSocket if legacy mode is activated
  93. var enterErrorMode = false;
  94. //Initalized floatWindow events
  95. ao_module_setFixedWindowSize();
  96. ao_module_setWindowSize(400,220);
  97. if (applocale){
  98. //Applocale found. Do localization
  99. applocale.init("../locale/file_operation.json", function(){
  100. applocale.translate();
  101. init();
  102. });
  103. }else{
  104. //Applocale not found. Is this a trim down version of ArozOS?
  105. applocale = {
  106. getString: function(key, original){
  107. return original;
  108. }
  109. }
  110. init();
  111. }
  112. function init(){
  113. console.log("Checking launch parameters...");
  114. if (window.location.hash.length > 0){
  115. //OK to proceed
  116. //try{
  117. operationConfig = JSON.parse(decodeURIComponent(window.location.hash.substring(1)));
  118. //Check if there are any missing paratmers
  119. configValid = true;
  120. if (typeof operationConfig.opr == "undefined"){ configValid = false; }
  121. if (typeof operationConfig.src == "undefined"){ configValid = false; }
  122. if (typeof operationConfig.dest == "undefined"){ configValid = false; }
  123. if (!configValid){
  124. console.log("Invalid file operation config. Please see the file_operation.html source code for the correct config json object.")
  125. ao_module_close();
  126. return;
  127. }
  128. //Parse the missing argument if there are any
  129. if (typeof operationConfig.overwriteMode == "undefined"){
  130. operationConfig.overwriteMode = "skip";
  131. }
  132. //Update 17-12-2020, ask the user for overwrite mode if file duplicate exists
  133. if (operationConfig.overwriteMode == "ask"){
  134. //Check if any file duplication before proceeding
  135. console.log(operationConfig.src);
  136. $.ajax({
  137. url: "../../system/file_system/listDir",
  138. data: {dir: operationConfig.dest},
  139. success: function(filelist){
  140. //Check for duplication
  141. var duplicateFound = filelist.some(function(file){
  142. return operationConfig.src.includes(file);
  143. });
  144. if (duplicateFound){
  145. //Duplication found.
  146. $("#duplicateAction").modal({
  147. closable: false
  148. }).modal("show");
  149. }else{
  150. //Duplication not found. Start the operation with default mode
  151. operationConfig.overwriteMode = "skip";
  152. processOperations(operationConfig);
  153. }
  154. }
  155. })
  156. }else{
  157. //All information are defined. Process it now.
  158. processOperations(operationConfig)
  159. }
  160. /*
  161. }catch(ex){
  162. //Failed
  163. console.log("Argument parse error", ex);
  164. }
  165. */
  166. }else{
  167. alert("Invalid use of File Operation Listener.")
  168. ao_module_close();
  169. }
  170. }
  171. function continueProcess(duplicateMode){
  172. operationConfig.overwriteMode = duplicateMode;
  173. $("#duplicateAction").modal("hide");
  174. processOperations(operationConfig)
  175. }
  176. function processOperations(operationConfig){
  177. //Update the display information
  178. $("#src").text(operationConfig.src);
  179. $("#dest").text(operationConfig.dest);
  180. opr = operationConfig.opr;
  181. updateTitle(operationConfig.src.length, operationConfig.opr);
  182. //Check which type of the oprs is about. And assign the related functions to start
  183. if (operationConfig.opr == "move"){
  184. $("#opricon").attr("src","img/move.gif");
  185. cut(operationConfig.src, operationConfig.dest, operationConfig.overwriteMode);
  186. }else if (operationConfig.opr == "copy"){
  187. $("#opricon").attr("src","img/copy.gif");
  188. copy(operationConfig.src, operationConfig.dest, operationConfig.overwriteMode);
  189. }else if (operationConfig.opr == "zip"){
  190. $("#opricon").attr("src","img/zip.gif");
  191. zip(operationConfig.src, operationConfig.dest, operationConfig.overwriteMode);
  192. }else if (operationConfig.opr == "unzip"){
  193. $("#opricon").attr("src","img/unzip.gif");
  194. unzip(operationConfig.src, operationConfig.dest, operationConfig.overwriteMode);
  195. }else if (operationConfig.opr == "unzipAndOpen"){
  196. $("#opricon").attr("src","img/unzip.gif");
  197. unzip(operationConfig.src, operationConfig.dest, operationConfig.overwriteMode, function(){
  198. //Open the target directory
  199. });
  200. }
  201. }
  202. //Unzip zip
  203. function unzip(srcList, dest, overwriteMode, callback=undefined){
  204. if (legacyMode){
  205. //Run in legacy mode
  206. requestCSRFToken(function(token){
  207. $.ajax({
  208. type: 'POST',
  209. url: `../../system/file_system/fileOpr`,
  210. data: {opr: "unzip" ,src: JSON.stringify(srcList), dest: dest, csrft: token},
  211. success: function(data){
  212. handleFinish(data);
  213. }
  214. });
  215. });
  216. }else{
  217. //Filter all + sign in the list
  218. var filteredSrcList = [];
  219. srcList.forEach(src => {
  220. filteredSrcList.push(src.split("+").join("{{plug_sign}}"));
  221. });
  222. //Open WebSocket
  223. var endpoint = getWSEndpoint() + `?opr=unzip&src=${encodeURIComponent(JSON.stringify(filteredSrcList))}&dest=${encodeURIComponent(dest)}&existsresp=${overwriteMode}`
  224. console.log(endpoint);
  225. var ws = new WebSocket(endpoint);
  226. ws.onopen = function(){
  227. //Do nothing. Just listen to the progress update
  228. };
  229. ws.onmessage = function (evt) {
  230. var data = evt.data;
  231. var progress = JSON.parse(data);
  232. console.log(progress);
  233. if (progress.Error != ""){
  234. //Something went wrong
  235. $("#progressbar").css("background-color", "#eb3f28");
  236. $("#opricon").attr("src", "img/error.png");
  237. enterErrorMode = true;
  238. alert(progress.Error);
  239. }else{
  240. //Update the progress display
  241. $("#progressbar").css("width", progress.Progress + "%");
  242. var currentSrc = truncate(progress.LatestFile, maxPathDisplayLength);
  243. var filteredDest = operationConfig.dest.trim();
  244. if (filteredDest.substr(filteredDest.length -1, 1) != "/"){
  245. filteredDest += "/"
  246. }
  247. var currentDest = truncate(filteredDest + progress.LatestFile, maxPathDisplayLength);
  248. $("#src").text(currentSrc);
  249. $("#dest").text(currentDest);
  250. $("#progress").text(progress.Progress + "%")
  251. if (progress.Progress == 100){
  252. //Set progress bar to green
  253. $("#progressbar").css("background-color", "#2bba35");
  254. }
  255. }
  256. };
  257. ws.onclose = function() {
  258. if (!enterErrorMode){
  259. $("#progressbar").css("background-color", "#2bba35");
  260. $("#progressbar").css("width", "100%");
  261. $("#progress").text("100%");
  262. $("#opricon").attr("src", "img/done.png")
  263. setTimeout(function(){
  264. if (operationConfig.opr == "unzipAndOpen"){
  265. //If open after unzip is required
  266. ao_module_openPath(operationConfig.dest);
  267. }
  268. ao_module_close();
  269. }, 100);
  270. }
  271. };
  272. ws.onerror = function(event){
  273. console.error("WebSocket error observed:", event);
  274. legacyMode = true;
  275. console.log("Falling back to Legacy Mode");
  276. unzip(srcList, dest, overwriteMode, callback);
  277. }
  278. }
  279. }
  280. //Create zip
  281. function zip(srcList, dest, overwriteMode){
  282. if (legacyMode){
  283. //Run in legacy mode
  284. requestCSRFToken(function(token){
  285. $.ajax({
  286. type: 'POST',
  287. url: `../../system/file_system/fileOpr`,
  288. data: {opr: "zip" ,src: JSON.stringify(srcList), dest: dest, csrft: token},
  289. success: function(data){
  290. handleFinish(data);
  291. }
  292. });
  293. });
  294. }else{
  295. //Replace all + sign with tag
  296. var filteredSrcList = [];
  297. srcList.forEach(src => {
  298. filteredSrcList.push(src.split("+").join("{{plug_sign}}"));
  299. })
  300. //Start WebSocket connection
  301. var endpoint = getWSEndpoint() + `?opr=zip&src=${encodeURIComponent(JSON.stringify(filteredSrcList))}&dest=${encodeURIComponent(dest)}&existsresp=${overwriteMode}`
  302. console.log(endpoint);
  303. var ws = new WebSocket(endpoint);
  304. var srcZipRoot = "";
  305. ws.onopen = function() {
  306. console.log("File Operation WebSocket opened")
  307. //Emulate the src folder
  308. var srcDir = srcList[0].split("/");
  309. srcDir.pop();
  310. srcDir = srcDir.join("/");
  311. srcZipRoot = srcDir;
  312. var currentSrc = truncate(srcDir, maxPathDisplayLength);
  313. $("#src").text(currentSrc);
  314. //Emulate the dest folder
  315. var destFolderName = dest.substr(0, dest.length - 1).split('/').pop();
  316. destFolderName += ".zip";
  317. var currentDest = truncate(dest + destFolderName, maxPathDisplayLength);
  318. $("#dest").text(currentDest);
  319. };
  320. ws.onmessage = function (evt) {
  321. var data = evt.data;
  322. var progress = JSON.parse(data);
  323. if (progress.Error != ""){
  324. //Something went wrong
  325. $("#progressbar").css("background-color", "#eb3f28");
  326. enterErrorMode = true;
  327. alert(progress.Error);
  328. }else{
  329. //Update the progress display
  330. $("#progressbar").css("width", progress.Progress + "%");
  331. var currentSrc = truncate(srcZipRoot + "/" + progress.LatestFile, maxPathDisplayLength);
  332. var filteredDest = operationConfig.dest.trim();
  333. if (filteredDest.substr(filteredDest.length -1, 1) != "/"){
  334. filteredDest += "/"
  335. }
  336. var currentDest = truncate(filteredDest + progress.LatestFile, maxPathDisplayLength);
  337. $("#src").text(currentSrc);
  338. $("#dest").text(currentDest);
  339. $("#progress").text(progress.Progress + "%")
  340. if (progress.Progress == 100){
  341. //Set progress bar to green
  342. $("#progressbar").css("background-color", "#2bba35");
  343. }
  344. }
  345. };
  346. ws.onclose = function() {
  347. //Transfer finished! Set OK and close in 1 second
  348. if (!enterErrorMode){
  349. $("#progressbar").css("background-color", "#2bba35");
  350. $("#progressbar").css("width", "100%");
  351. $("#progress").text("100%")
  352. handleFinish({});
  353. }
  354. };
  355. ws.onerror = function(event){
  356. console.error("WebSocket error observed:", event);
  357. legacyMode = true;
  358. console.log("Falling back to Legacy Mode");
  359. zip(srcList, dest, overwriteMode);
  360. }
  361. }
  362. }
  363. function cut(srcList, dest, overwriteMode){
  364. if (legacyMode){
  365. console.log("WebSocket not found, Running in legacy mode");
  366. requestCSRFToken(function(token){
  367. $.ajax({
  368. type: 'POST',
  369. url: `../../system/file_system/fileOpr`,
  370. data: {opr: "move" ,src: JSON.stringify(srcList), dest: dest,existsresp: overwriteMode, csrft: token},
  371. success: function(data){
  372. handleFinish(data);
  373. }
  374. });
  375. });
  376. }else{
  377. //Replace all + sign in srclist with {{plus_sign}}
  378. var filteredSrcList = [];
  379. srcList.forEach(src => {
  380. filteredSrcList.push(src.split("+").join("{{plug_sign}}"));
  381. })
  382. //Use Websocket for operation updates
  383. var endpoint = getWSEndpoint() + `?opr=move&src=${encodeURIComponent(JSON.stringify(filteredSrcList))}&dest=${encodeURIComponent(dest)}&existsresp=${overwriteMode}`
  384. console.log(endpoint);
  385. var ws = new WebSocket(endpoint);
  386. ws.onopen = function() {
  387. console.log("File Operation WebSocket opened")
  388. };
  389. ws.onmessage = function (evt) {
  390. var data = evt.data;
  391. var progress = JSON.parse(data);
  392. if (progress.Error != ""){
  393. $("#progressbar").css("background-color", "#eb3f28");
  394. enterErrorMode = true;
  395. alert(progress.Error);
  396. }else{
  397. $("#progressbar").css("width", progress.Progress + "%");
  398. var currentSrc = truncate(operationConfig.src + "/" + progress.LatestFile, maxPathDisplayLength);
  399. var filteredDest = operationConfig.dest.trim();
  400. if (filteredDest.substr(filteredDest.length -1, 1) != "/"){
  401. filteredDest += "/"
  402. }
  403. var currentDest = truncate(filteredDest + progress.LatestFile, maxPathDisplayLength);
  404. $("#src").text(currentSrc);
  405. $("#dest").text(currentDest);
  406. $("#progress").text(progress.Progress + "%")
  407. if (progress.Progress == 100){
  408. //Set progress bar to green
  409. $("#progressbar").css("background-color", "#2bba35");
  410. }
  411. }
  412. };
  413. ws.onclose = function() {
  414. //Transfer finished! Set OK and close in 1 second
  415. if (!enterErrorMode){
  416. $("#progressbar").css("background-color", "#2bba35");
  417. $("#progressbar").css("width", "100%");
  418. $("#progress").text("100%")
  419. handleFinish({});
  420. }
  421. };
  422. ws.onerror = function(event){
  423. console.error("WebSocket error observed:", event);
  424. console.log("Falling back to Legacy Mode")
  425. legacyMode = true;
  426. cut(srcList, dest, overwriteMode)
  427. }
  428. }
  429. }
  430. function copy(srcList, dest, overwriteMode){
  431. if (legacyMode){
  432. //Open operation in legacy mode
  433. console.log("WebSocket not found, Running in legacy mode");
  434. requestCSRFToken(function(token){
  435. $.ajax({
  436. type: 'POST',
  437. url: `../../system/file_system/fileOpr`,
  438. data: {opr: "copy" ,src: JSON.stringify(srcList), dest: dest,existsresp: overwriteMode , csrft: token},
  439. success: function(data){
  440. handleFinish(data);
  441. }
  442. });
  443. });
  444. }else{
  445. var filteredSrcList = [];
  446. srcList.forEach(src => {
  447. filteredSrcList.push(src.split("+").join("{{plug_sign}}"));
  448. })
  449. //Use Websocket for operation updates
  450. var endpoint = getWSEndpoint() + `?opr=copy&src=${JSON.stringify(filteredSrcList)}&dest=${encodeURIComponent(dest)}&existsresp=${overwriteMode}`
  451. var ws = new WebSocket(endpoint);
  452. ws.onopen = function() {
  453. console.log("File Operation WebSocket opened")
  454. };
  455. ws.onmessage = function (evt) {
  456. var data = evt.data;
  457. var progress = JSON.parse(data);
  458. if (progress.Error != ""){
  459. $("#progressbar").css("background-color", "#eb3f28");
  460. enterErrorMode = true;
  461. alert(progress.Error);
  462. }else{
  463. $("#progressbar").css("width", progress.Progress + "%");
  464. var currentSrc = truncate(operationConfig.src + "/" + progress.LatestFile, maxPathDisplayLength);
  465. var filteredDest = operationConfig.dest.trim();
  466. if (filteredDest.substr(filteredDest.length -1, 1) != "/"){
  467. filteredDest += "/"
  468. }
  469. var currentDest = truncate(filteredDest + progress.LatestFile, maxPathDisplayLength);
  470. $("#src").text(currentSrc);
  471. $("#dest").text(currentDest);
  472. $("#progress").text(progress.Progress + "%")
  473. if (progress.Progress == 100){
  474. //Set progress bar to green
  475. $("#progressbar").css("background-color", "#2bba35");
  476. }
  477. }
  478. };
  479. ws.onclose = function() {
  480. //Transfer finished! Set OK and close in 1 second
  481. if (!enterErrorMode){
  482. $("#progressbar").css("background-color", "#2bba35");
  483. $("#progressbar").css("width", "100%");
  484. $("#progress").text("100%");
  485. handleFinish({});
  486. }
  487. };
  488. ws.onerror = function(event){
  489. console.error("WebSocket error observed:", event);
  490. console.log("Falling back to Legacy Mode")
  491. legacyMode = true;
  492. copy(srcList, dest, overwriteMode)
  493. }
  494. }
  495. }
  496. var truncate = function (fullStr, strLen, separator) {
  497. if (fullStr.length <= strLen) return fullStr;
  498. separator = separator || '...';
  499. var sepLen = separator.length,
  500. charsToShow = strLen - sepLen,
  501. frontChars = Math.ceil(charsToShow/2),
  502. backChars = Math.floor(charsToShow/2);
  503. return fullStr.substr(0, frontChars) +
  504. separator +
  505. fullStr.substr(fullStr.length - backChars);
  506. };
  507. function getWSEndpoint(){
  508. //Open opeartion in websocket
  509. let protocol = "wss://";
  510. if (location.protocol !== 'https:') {
  511. protocol = "ws://";
  512. }
  513. var port = window.location.port;
  514. if (window.location.port == ""){
  515. if (location.protocol !== 'https:') {
  516. port = "80";
  517. }else{
  518. port = "443";
  519. }
  520. }
  521. wsControlEndpoint = (protocol + window.location.hostname + ":" + port + "/system/file_system/ws/fileOpr");
  522. return wsControlEndpoint;
  523. }
  524. function updateTitle(fileNumber, opr){
  525. var title = "";
  526. if (opr == "move"){
  527. title = applocale.getString("title/moving","Moving ");
  528. }else if (opr == "copy"){
  529. title = applocale.getString("title/copying","Copying ");
  530. }else if (opr == "zip" || opr == "zipAndDownload"){
  531. title = applocale.getString("title/zipping","Zipping ");
  532. }else if (opr == "download"){
  533. title = applocale.getString("title/downloading","Downloading ");
  534. }else if (opr == "unzip" || opr == "unzipAndOpen"){
  535. title = applocale.getString("title/unzipping","Unzipping ");
  536. }
  537. title += fileNumber + " ";
  538. if (fileNumber == 1){
  539. title += applocale.getString("title/file"," File");
  540. }else{
  541. title += applocale.getString("title/files"," Files");
  542. }
  543. $(".title").text(title);
  544. }
  545. function handleFinish(data){
  546. if (data.error !== undefined){
  547. $("#progressbar").css("background-color","#db2828");
  548. $("#progressbar").parent().removeClass('active');
  549. $(".title").html(`<i class="remove icon"></i>` + applocale.getString("error/" + data.error,data.error));
  550. enterErrorMode = true;
  551. return
  552. }else{
  553. $("#progressbar").css("background-color","#21ba45");
  554. $("#progressbar").parent().removeClass('active');
  555. if (opr == "move" || opr == "copy" || opr == "zip" || opr == "unzip"){
  556. //Action completed. close window.
  557. setTimeout(function(){
  558. //Do callback if exists
  559. if (operationConfig.callbackWindowID == "desktop"){
  560. //Special call from desktop
  561. parent.eval(operationConfig.callbackFunction);
  562. }else if (operationConfig.callbackWindowID !== undefined && operationConfig.callbackFunction !== undefined){
  563. var callbackWindowObject = parent.getFloatWindowByID(operationConfig.callbackWindowID)
  564. var windowObject = $(callbackWindowObject).find("iframe")[0];
  565. if (windowObject == undefined || windowObject == null){
  566. //Caller no longer exists.
  567. }else{
  568. //Caller still exists. Do callback events
  569. //console.log(windowObject.contentWindow, operationConfig.callbackFunction);
  570. windowObject.contentWindow.eval(operationConfig.callbackFunction);
  571. }
  572. }
  573. //If the target or src is desktop, refresh desktop as well
  574. if(pathIsOnDesktop(operationConfig.dest) || pathIsOnDesktop(operationConfig.src[0])){
  575. parent.refresh(undefined, true);
  576. }
  577. if (!enterErrorMode){
  578. ao_module_close();
  579. }
  580. }, 1000);
  581. }else if (opr == "download"){
  582. //Create download from buffer
  583. }else if (opr == "zipAndDown"){
  584. //Download
  585. }else if (opr == "unzipAndOpen"){
  586. //Unzip and open the target directory
  587. setTimeout(function(){
  588. //Open the target directory
  589. ao_module_openPath(operationConfig.dest);
  590. //Close the window
  591. ao_module_close();
  592. }, 1000);
  593. }
  594. }
  595. console.log(data);
  596. }
  597. function pathIsOnDesktop(path){
  598. var filteredDest = path;
  599. if (filteredDest.substr(filteredDest.length - 1) == "/"){
  600. filteredDest = filteredDest.substr(0, filteredDest.length - 1);
  601. }
  602. var dirChunk = filteredDest.split("/");
  603. console.log(dirChunk);
  604. if (dirChunk.length == 2 || dirChunk.length == 3){
  605. if (dirChunk[0].toLowerCase() == "user:" && dirChunk[1].toLowerCase() == "desktop"){
  606. //This is a direct access desktop file
  607. return true;
  608. }
  609. }
  610. return false;
  611. }
  612. function requestCSRFToken(callback){
  613. $.ajax({
  614. url: "../../system/csrf/new",
  615. success: function(token){
  616. callback(token);
  617. }
  618. })
  619. }
  620. </script>
  621. </body>
  622. </html>