file_selector.html 32 KB

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