file_selector.html 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  1. <html>
  2. <head>
  3. <title locale="title">File Selector</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. <link rel="stylesheet" href="../../script/ao.css">
  8. <script type="text/javascript" src="../../script/jquery.min.js"></script>
  9. <script type="text/javascript" src="../../script/semantic/semantic.min.js"></script>
  10. <script type="text/javascript" src="../../script/ao_module.js"></script>
  11. <script type="text/javascript" src="../../script/applocale.js"></script>
  12. <style>
  13. body{
  14. background-color:#f5f5f5 !important;
  15. }
  16. .navi{
  17. padding:8px;
  18. background-color:#fcfcfc;
  19. border-bottom:2px solid #34b7eb;
  20. left:0px;
  21. top:0px;
  22. margin-top: -0.6em;
  23. width:100%;
  24. z-index:99;
  25. position: fixed;
  26. }
  27. .fileSelectorContainer{
  28. width: 100%;
  29. vertical-align:top;
  30. }
  31. #sidebar{
  32. padding-top: 1em;
  33. background-color:#f5f5f5 !important;
  34. display: inline-block;
  35. z-index:90 !important;
  36. width:200px;
  37. top: 0;
  38. }
  39. #fileListWrapper{
  40. display: inline-block;
  41. width: calc(100% - 220px);
  42. min-height:300px;
  43. vertical-align:top;
  44. padding: 1em;
  45. background-color: white;
  46. border-radius: 12px;
  47. margin-bottom: 20px;
  48. margin-top: 1em;
  49. }
  50. .navi .button{
  51. box-shadow: 0 1px 1px 0px rgb(190, 190, 190) !important;
  52. }
  53. .list .item{
  54. cursor:pointer;
  55. }
  56. .list .item:hover{
  57. color:#c7c7c7 !important;
  58. }
  59. .extrapadding{
  60. padding-left:6px !important;
  61. padding-right:6px !important;
  62. color:#676768 !important;
  63. }
  64. .fileObject{
  65. overflow-wrap: break-word !important;
  66. display: block !important;
  67. padding:12px !important;
  68. font-size:98%;
  69. }
  70. .fileObject .fileInfo{
  71. display:inline-block !important;
  72. word-break: break-all;
  73. text-overflow: ellipsis !important;
  74. overflow: hidden;
  75. color:black;
  76. user-select: none;
  77. }
  78. .fileObject.selected{
  79. background-color:#d2f2f7 !important;
  80. }
  81. .fileObject.item:hover{
  82. background-color:#f2f2f2;
  83. }
  84. .bordered{
  85. border: 1px solid #dedede;
  86. }
  87. #fileListWrapper{
  88. width: calc(100% - 220px);
  89. min-height: 90vh;
  90. }
  91. @media only screen and (max-width: 560px) {
  92. #sidebar{
  93. padding-top: 2em;
  94. background-color:#f5f5f5 !important;
  95. position: fixed;
  96. width:200px;
  97. height: 100%;
  98. top: 0;
  99. left: 0;
  100. -webkit-box-shadow: 9px 0px 23px -14px rgba(135,135,135,0.4);
  101. -moz-box-shadow: 9px 0px 23px -14px rgba(135,135,135,0.4);
  102. box-shadow: 9px 0px 23px -14px rgba(135,135,135,0.4);
  103. }
  104. .navi{
  105. margin-top: -1em;
  106. }
  107. #fileListWrapper{
  108. width: 100%;
  109. }
  110. }
  111. .flexContainer{
  112. display: flex;
  113. flex-wrap:wrap;
  114. align-items:flex-start;
  115. margin-top:5px;
  116. }
  117. .flexleft {
  118. padding-right: 1em;
  119. min-width: 200px;
  120. }
  121. .flexright{
  122. flex-grow:1;
  123. margin-bottom: 0.4em;
  124. min-width: 300px;
  125. }
  126. </style>
  127. </head>
  128. <body>
  129. <div class="navi">
  130. <div class="flexContainer">
  131. <div class="flexleft">
  132. <button id="sidebarToggleBtn" class="ui icon small button" onclick="$('#sidebar').toggle();"><i class="content icon"></i></button>
  133. <button title="Back" class="ui icon small button" onclick="backDir();"><i class="arrow left icon"></i></button>
  134. <button title="Parent" class="ui icon small button" onclick="parentDir();"><i class="arrow up icon"></i></button>
  135. <button title="Refresh" class="ui icon small button" onclick="refresh();"><i class="refresh icon"></i></button>
  136. <button title="New Folder" class="ui icon small button" onclick="newFolder();"><i class="folder icon"></i></button>
  137. </div>
  138. <div class="flexright">
  139. <div class="ui action fluid tiny input" style="height: 34px; margin-top: 0.4em;">
  140. <input id="addressbar" type="text" placeholder="" onchange="updatePath();">
  141. <button class="ui positive icon button" onclick="confirmSelection();"><i class="checkmark icon"></i></button>
  142. </div>
  143. <div id="newfilenameInput" style="height: 34px; margin-top: 0.4em;">
  144. <div class="ui fluid tiny input">
  145. <input id="filename" type="text" placeholder="New Filename">
  146. </div>
  147. </div>
  148. <div id="newFolderInput" style="height: 34px; margin-top: 0.6em; display:none;">
  149. <div class="ui fluid action tiny input">
  150. <input id="foldername" type="text" placeholder="New Folder" value="">
  151. <button class="ui icon button" onclick="createFolder()" title="Create Folder"><i class="add icon"></i></button>
  152. </div>
  153. </div>
  154. </div>
  155. </div>
  156. </div>
  157. <div class="fileSelectorContainer">
  158. <!-- Sidebar -->
  159. <div id="sidebar" style="padding-left: 0.6em;">
  160. <div class="contents">
  161. <div class="ui accordion">
  162. <div class="title active">
  163. <i class="dropdown icon"></i>
  164. <span locale="roots/user">User</span>
  165. </div>
  166. <div class="active content" style="padding-left: 1em; padding-bottom: 0.5em;">
  167. <div class="ui list" id="userlist"></div>
  168. </div>
  169. </div >
  170. <div class="ui accordion">
  171. <div class="title active">
  172. <i class="dropdown icon"></i>
  173. <span locale="roots/storage">Storage</span>
  174. </div>
  175. <div class="active content">
  176. <div id="storagelist" class="ui list" style="padding-left: 1em; padding-bottom: 0.5em;" >
  177. </div>
  178. </div>
  179. </div>
  180. </div>
  181. </div>
  182. <!-- Folder List -->
  183. <div id="fileListWrapper" class="fileListWrapper">
  184. <div id="folderList" class="ui relaxed divided fluid list bordered whiteTheme">
  185. <div class="fileObject">
  186. <span class="fileInfo"><i class="loading spinner icon" style="margin-right:12px;"></i> <span locale="message/loading">Loading</span></span>
  187. </div>
  188. </div>
  189. <div id="fileList" class="ui relaxed divided list bordered whiteTheme">
  190. </div>
  191. <div id="nofilesCheckmark" style="width: 100%; margin-top: calc(150px - 2em); text-align:center; opacity: 0.6; display:none; pointer-events: none; user-select: none;">
  192. <p><i class="grey folder open icon"></i> <span locale="message/nofile">No file</span></p>
  193. </div>
  194. </div>
  195. </div>
  196. <div id="waitloader" class="ui active dimmer" style="display:none; z-index:999;">
  197. <div id="waitloadertext" class="ui indeterminate text loader" locale="message/waitingResp">Waiting Response</div>
  198. </div>
  199. <script>
  200. var multiSelect = false;
  201. var type = "file";
  202. var currentDir = "user:/";
  203. var currentFileList = [];
  204. var pathHistory = [];
  205. var ctrlDown = false;
  206. var shiftDown = false;
  207. var lastClickedItemID = 0;
  208. var listenerUUID = "";
  209. var fileOptions = {};
  210. //$('.ui.accordion').accordion();
  211. if (applocale){
  212. //Applocale found. Do localization
  213. applocale.init("../locale/file_selector.json", function(){
  214. applocale.translate();
  215. initRoots();
  216. });
  217. }else{
  218. //Applocale not found. Is this a trim down version of ArozOS?
  219. applocale = {
  220. getString: function(key, original){
  221. return original;
  222. }
  223. }
  224. initRoots();
  225. }
  226. initSelectorObject();
  227. updateWindowResize();
  228. function initSelectorObject(){
  229. var initInfo = loadSelectorInfoFromHash();
  230. //Load the initiation directory
  231. listDir(initInfo.root);
  232. //init global var
  233. type = initInfo.type;
  234. multiSelect = initInfo.allowMultiple;
  235. listenerUUID = initInfo.listenerUUID;
  236. if (initInfo.options != undefined){
  237. fileOptions = JSON.parse(JSON.stringify(initInfo.options));
  238. }
  239. //Load options and parse the UI
  240. if (type == "new"){
  241. //Resize the top bar
  242. updateUIElements();
  243. if (typeof(fileOptions.defaultName) != "undefined"){
  244. $("#filename").val(fileOptions.defaultName);
  245. }else{
  246. $("#filename").val("newfile.txt");
  247. }
  248. }else{
  249. $("#newfilenameInput").hide();
  250. }
  251. }
  252. function cancelSelection(){
  253. localStorage.setItem(listenerUUID, JSON.stringify("&&selection_canceled&&"));
  254. }
  255. function confirmSelection(){
  256. var files = [];
  257. $(".selected.fileObject").each(function(){
  258. var filename = decodeURIComponent($(this).attr('filename'));
  259. var filepath = decodeURIComponent($(this).attr('filepath'));
  260. files.push({
  261. filename: filename,
  262. filepath: filepath
  263. });
  264. });
  265. //Check if currentdir end with "/". If not, append it
  266. if(currentDir.substr(currentDir.length - 1, 1) != "/"){
  267. currentDir = currentDir + "/";
  268. }
  269. //Check for special cases
  270. if (files.length == 0 && type == "folder"){
  271. //Select the current path as target instead
  272. var currentPathname = currentDir.split("/");
  273. currentPathname.pop();
  274. currentPathname = currentPathname.pop();
  275. if (currentPathname == ""){
  276. currentPathname = currentDir;
  277. }
  278. files.push({
  279. filename: currentPathname,
  280. filepath: currentDir
  281. });
  282. }else if (files.length == 0 && type == "new"){
  283. //Push this new file into the return structure
  284. var newFilename = $("#filename").val();
  285. files.push({
  286. filename: newFilename,
  287. filepath: currentDir + newFilename
  288. });
  289. }
  290. if (ao_module_virtualDesktop){
  291. if (!ao_module_parentCallback(files)){
  292. //Parent callback not exists
  293. alert("Selection Failed. Is parent window alive?")
  294. }else{
  295. parent.closeFwProcess(ao_module_windowID);
  296. }
  297. }else{
  298. if (listenerUUID == ""){
  299. alert("Invalid listener UUID. Please re-open your file selector.")
  300. return;
  301. }
  302. var selectedFilesInJSON = JSON.stringify(files);
  303. localStorage.setItem(listenerUUID, selectedFilesInJSON);
  304. $("#waitloader").show();
  305. setTimeout(function(){
  306. $("#waitloadertext").html("<i class='remove icon'></i> System is not responding. <br>Please close this window and retry.");
  307. },10000)
  308. }
  309. }
  310. //Handle on window close function, cancel current selection
  311. window.onbeforeunload = function(){
  312. cancelSelection();
  313. }
  314. //Overwrite the ao_module close function
  315. function ao_module_close(){
  316. if (!ao_module_virtualDesktop){
  317. return;
  318. }
  319. if (!ao_module_parentCallback(files)){
  320. alert("Selection Failed. Is parent window alive?")
  321. }else{
  322. parent.closeFwProcess(ao_module_windowID);
  323. }
  324. }
  325. function updatePath(){
  326. var newDir = $("#addressbar").val();
  327. listDir(newDir);
  328. }
  329. function refresh(){
  330. $("#fileList").html("");
  331. $("#folderList").html("");
  332. listDir(currentDir);
  333. }
  334. function newFolder(){
  335. var newFileOffset = 0;
  336. if ($("#newfilenameInput").is(":visible")){
  337. newFileOffset += 40;
  338. }
  339. $("#newFolderInput").toggle();
  340. updateUIElements();
  341. }
  342. function updateUIElements(){
  343. $("#sidebar").css("padding-top", $(".navi").height() + 8);
  344. $("#fileListWrapper").css("padding-top", $(".navi").height() + 8)
  345. }
  346. function hideFolderNameInput(){
  347. $("#newFolderInput").hide();
  348. updateUIElements();
  349. }
  350. function createFolder(){
  351. var folderName = $("#foldername").val();
  352. if (folderName == ""){
  353. folderName = "New Folder"
  354. $("#foldername").val("New Folder");
  355. }
  356. folderName = folderName.replace(/[<>:"/\\|?*]/g, "_");
  357. //Check if folder exists
  358. var nameAlreadyExists = false;
  359. currentFileList.forEach(fileObject => {
  360. if (fileObject.IsDir && fileObject.Filename == folderName){
  361. nameAlreadyExists = true;
  362. }
  363. });
  364. if (nameAlreadyExists){
  365. alert("Folder already exists")
  366. return
  367. }
  368. //Create the new folder request
  369. requestCSRFToken(function(token){
  370. $.ajax({
  371. url: "../../system/file_system/newItem",
  372. data: {type: "folder", src: currentDir, filename: folderName, csrft: token},
  373. success: function(data){
  374. if (data.error !== undefined){
  375. alert(data.error);
  376. }else{
  377. refresh()
  378. }
  379. hideFolderNameInput();
  380. }
  381. });
  382. });
  383. }
  384. function loadSelectorInfoFromHash(){
  385. if (window.location.hash.length == 0){
  386. return {
  387. root: "user:/",
  388. type: "file",
  389. allowMultiple: false
  390. }
  391. }else{
  392. try{
  393. var selectInfo = JSON.parse(decodeURIComponent(window.location.hash.substring(1)));
  394. return selectInfo;
  395. }catch{
  396. //Error parsing the input. Use default settings
  397. return {
  398. root: "user:/",
  399. type: "file",
  400. allowMultiple: false
  401. }
  402. }
  403. }
  404. }
  405. function listDir(dir){
  406. currentDir = dir;
  407. pathHistory.push(currentDir);
  408. $("#addressbar").val(currentDir);
  409. $("#nofilesCheckmark").hide();
  410. $("#folderList").html(`<div class="ui fluid" style="text-align: center; padding: 1.2em;"><i class="ui loading spinner icon"></i></div>`);
  411. $("#folderList").show();
  412. $("#fileList").hide();
  413. ao_module_setWindowTitle(`Open`);
  414. $.get("../../system/file_system/listDir?dir=" + encodeURIComponent(dir),function(data){
  415. $("#folderList").html("");
  416. $("#fileList").html("");
  417. if (data === null){
  418. $("#folderList").hide();
  419. $("#fileList").hide();
  420. $("#nofilesCheckmark").show();
  421. return;
  422. }else{
  423. $("#folderList").show();
  424. $("#fileList").show();
  425. }
  426. if (data.error !== undefined){
  427. //Load the index instead
  428. listDir("user:/");
  429. }else{
  430. currentFileList = data;
  431. var folders = [];
  432. var files = [];
  433. for (var i =0; i < data.length; i++){
  434. if (data[i].IsDir == true){
  435. folders.push(data[i]);
  436. }else{
  437. if (fileOptions.filter != undefined){
  438. var fileExt = data[i].Filename.split(".").pop();
  439. for (var j = 0; j < fileOptions.filter.length; j++){
  440. if (fileOptions.filter[j] == fileExt){
  441. files.push(data[i]);
  442. break;
  443. }
  444. }
  445. }else{
  446. files.push(data[i]);
  447. }
  448. }
  449. }
  450. //Append folder first then files
  451. var count = 0;
  452. for (var i =0; i < folders.length; i++){
  453. var filename = folders[i].Filename;
  454. var filepath = folders[i].Filepath;
  455. var ext = filename.split(".").pop();
  456. var icon = ao_module_utils.getIconFromExt(ext);
  457. var isDir = folders[i].IsDir;
  458. if (isDir == true){
  459. icon = "yellow folder";
  460. }
  461. var fileSize = folders[i].Displaysize;
  462. $("#folderList").append(`<div class="fileObject item" fid="${count}" ondblclick="openFolder(event,this);" onclick="selectThis(this,event);" filepath="${encodeURIComponent(filepath)}" filename="${encodeURIComponent(filename)}" isDir="${isDir}">
  463. <span class="fileInfo"><i class="${icon} icon" style="margin-right:4px;"></i> ${filename}</span>
  464. </div>`);
  465. count++;
  466. }
  467. if (folders.length == 0){
  468. $("#folderList").hide();
  469. }
  470. for (var i =0; i < files.length; i++){
  471. var filename = files[i].Filename;
  472. var filepath = files[i].Filepath;
  473. var ext = filename.split(".").pop();
  474. var icon = ao_module_utils.getIconFromExt(ext);
  475. var isDir = files[i].IsDir;
  476. if (isDir == true){
  477. icon = "folder";
  478. }
  479. var fileSize = files[i].Displaysize;
  480. $("#fileList").append(`<div class="fileObject item" fid="${count}" ondblclick="chooseThisFile(this);" onclick="selectThis(this,event);" filepath="${encodeURIComponent(filepath)}" filename="${encodeURIComponent(filename)}" isDir="${isDir}">
  481. <span class="fileInfo"><i class="${icon} icon" style="margin-right:4px;margin-top: 2px;"></i> ${filename}</span>
  482. </div>`);
  483. count++;
  484. }
  485. if (files.length == 0){
  486. $("#fileList").hide();
  487. }
  488. if (folders.length == 0 && files.length == 0){
  489. //There is nothing in this dir
  490. $("#nofilesCheckmark").show();
  491. }else{
  492. $("#nofilesCheckmark").hide();
  493. }
  494. }
  495. });
  496. }
  497. function requestCSRFToken(callback){
  498. $.ajax({
  499. url: "../../system/csrf/new",
  500. success: function(token){
  501. callback(token);
  502. }
  503. })
  504. }
  505. //Open folder
  506. function openFolder(event, object){
  507. event.preventDefault();
  508. var filepath = $(object).attr("filepath");
  509. filepath = decodeURIComponent(filepath);
  510. listDir(filepath);
  511. }
  512. function selectThis(object,event){
  513. //event.preventDefault();
  514. //event.stopImmediatePropagation();
  515. //Check if this object is in suitable selection type
  516. if ($(object).attr("IsDir") == "true" && type == "file"){
  517. return;
  518. }else if ($(object).attr("IsDir") == "false" && type == "folder"){
  519. return;
  520. }else if (type == "new" && $(object).attr("IsDir") == "false"){
  521. //Use this filename as the newfile name (aka overwrite mode)
  522. var newNewFilename = $(object).attr("filename");
  523. newNewFilename = decodeURIComponent(newNewFilename);
  524. $("#filename").val(newNewFilename);
  525. return;
  526. }else if (type == "new" && $(object).attr("IsDir") == "true"){
  527. //Selected a folder in new mode. Ignore it
  528. return
  529. }
  530. if (multiSelect){
  531. if (ctrlDown){
  532. //Add this into selection list
  533. $(object).addClass("selected");
  534. }else if (shiftDown){
  535. var start = lastClickedItemID;
  536. var end = $(object).attr("fid");
  537. if (start > end){
  538. start = end;
  539. end = lastClickedItemID;
  540. }
  541. var fileObjects = $(".fileObject");
  542. for (var k = start; k <= end; k++){
  543. $(fileObjects[k]).addClass("selected");
  544. }
  545. }else{
  546. //Reset and add this into selection list
  547. $(".selected").removeClass("selected");
  548. $(object).addClass("selected");
  549. }
  550. }else{
  551. $(".selected").removeClass("selected");
  552. $(object).addClass("selected");
  553. }
  554. //Update last selected id
  555. lastClickedItemID = $(object).attr('fid');
  556. //Update title
  557. var objectCount = $(".selected").length;
  558. var typeName = "object"
  559. if (type == "file"){
  560. typeName = "file";
  561. }else if (type == "folder"){
  562. typeName = "folder";
  563. }
  564. var desc = `${typeName} selected`;
  565. if (objectCount > 1){
  566. desc = `${typeName + "s"} selected`;
  567. }
  568. ao_module_setWindowTitle(`Open (${objectCount} ${desc})`);
  569. }
  570. $(window).on("keydown",function(event){
  571. if (event.which == 17){
  572. ctrlDown = true;
  573. }else if (event.which == 16){
  574. shiftDown = true;
  575. }
  576. });
  577. $(window).on("keyup",function(event){
  578. if (event.which == 17){
  579. ctrlDown = false;
  580. }else if (event.which == 16){
  581. shiftDown = false;
  582. }
  583. });
  584. $(window).on("resize",function(){
  585. updateWindowResize();
  586. });
  587. function updateWindowResize(){
  588. if (window.innerWidth < 560){
  589. //Mobile mode
  590. $("#sidebarToggleBtn").show();
  591. $("#sidebar").hide();
  592. $("#addressbar").parent().css({
  593. "width": "100%",
  594. "margin-top": "4px"
  595. });
  596. $("#newfilenameInput").find(".input").css({
  597. "width": "100%",
  598. "margin-top": "4px"
  599. });
  600. $("#newFolderInput").find(".input").css({
  601. "width": "100%",
  602. "margin-top": "4px"
  603. });
  604. }else{
  605. $("#sidebarToggleBtn").hide();
  606. $("#sidebar").show();
  607. $("#sidebar").css("margin-top", "0px");
  608. }
  609. updateUIElements();
  610. }
  611. function initAddressBarWidth(){
  612. $("#addressbar").css("width",window.innerWidth - 220 + "px");
  613. }
  614. function chooseThisFile(object){
  615. $(".selected").removeClass('selected');
  616. $(object).addClass('selected');
  617. confirmSelection();
  618. }
  619. function parentDir(){
  620. if (currentDir.substring(currentDir.length - 1) == "/"){
  621. currentDir = currentDir.substring(0, currentDir.length - 1);
  622. }
  623. var tmp = currentDir.split("/");
  624. tmp.pop();
  625. var parentPath = tmp.join("/");
  626. if (parentPath.length == 0){
  627. //Do nothing. Already at root dir
  628. }else{
  629. listDir(parentPath);
  630. }
  631. }
  632. function backDir(){
  633. if (pathHistory.length > 1){
  634. pathHistory.pop();
  635. var targetPath = pathHistory.pop();
  636. listDir(targetPath);
  637. }
  638. }
  639. //Initialize user shortcuts
  640. function initRoots(){
  641. $.get("../../system/file_system/listRoots",function(data){
  642. $("#storagelist").html("");
  643. for (var i =0; i < data.length; i++){
  644. $('#storagelist').append(`<div class="item extrapadding" filepath="${data[i]["RootPath"]}" onclick="openShortcut(this);"><i class="disk outline icon" style="margin-right:8px;"></i> ${data[i]["RootName"]} (${data[i]["RootPath"]})</div>`);
  645. }
  646. });
  647. $.get("../../system/file_system/listRoots?user=true",function(data){
  648. $("#userlist").html("");
  649. for (var i =0; i < data.length; i++){
  650. if (data[i].IsDir == true){
  651. if (data[i]["Filename"].substring(0,1) == "."){
  652. //Do not show hidden files
  653. continue;
  654. }
  655. //Get the icon and the localization of this user root
  656. var iconAndFolderName = getUserRootIcons(data[i]["Filename"]);
  657. console.log(iconAndFolderName);
  658. $('#userlist').append(`<div class="item extrapadding" filepath="${data[i]["Filepath"]}" onclick="openShortcut(this);"><i class="${iconAndFolderName[0]} icon" style="margin-right:8px;"></i> ${iconAndFolderName[1]}</div>`);
  659. }
  660. }
  661. });
  662. }
  663. function getUserRootIcons(foldername){
  664. var icon = "folder open";
  665. var name = foldername;
  666. foldername = foldername.toLowerCase();
  667. if (foldername == "desktop"){
  668. icon = "computer";
  669. name = applocale.getString("sidebar/vroot/desktop", name);
  670. }else if (foldername == "document"){
  671. icon = "file text outline";
  672. name = applocale.getString("sidebar/vroot/document", name);
  673. }else if (foldername == "music" || foldername == "audio"){
  674. icon = "music";
  675. name = applocale.getString("sidebar/vroot/music", name);
  676. }else if (foldername == "photo" || foldername == "picture"){
  677. icon = "image";
  678. name = applocale.getString("sidebar/vroot/photo", name);
  679. }else if (foldername == "video" || foldername == "film"){
  680. icon = "video";
  681. name = applocale.getString("sidebar/vroot/video", name);
  682. }else if (foldername == "trash" || foldername == "bin" || foldername == "rubbish"){
  683. icon = "trash"
  684. name = applocale.getString("sidebar/vroot/trash", name);
  685. }else if (foldername == "download"){
  686. icon = "download"
  687. name = applocale.getString("sidebar/vroot/download", name);
  688. }else if (foldername == "www" || foldername == "web" || foldername == "mysite"){
  689. icon = "globe"
  690. name = applocale.getString("sidebar/vroot/web", name);
  691. }else if (foldername == "model"){
  692. icon = "cube"
  693. name = applocale.getString("sidebar/vroot/model", name);
  694. }else if (foldername == "appdata"){
  695. icon = "code"
  696. name = applocale.getString("sidebar/vroot/appdata", name);
  697. }
  698. return [icon, name];
  699. }
  700. function openShortcut(object){
  701. var targetdir = $(object).attr("filepath");
  702. targetdir = decodeURIComponent(targetdir);
  703. listDir(targetdir);
  704. if (window.innerWidth < 560){
  705. $("#sidebar").hide();
  706. }
  707. }
  708. </script>
  709. </body>
  710. </html>