file_explorer.html 209 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669
  1. <html>
  2. <head>
  3. <title>File Manager</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/tocas/tocas.css">
  7. <link rel="icon" type="image/png" href="./img/small_icon.png">
  8. <link rel="manifest" crossorigin="use-credentials" href="manifest.json">
  9. <script type="text/javascript" src="../../script/tocas/tocas.js"></script>
  10. <script type="text/javascript" src="../../script/jquery.min.js"></script>
  11. <script type="text/javascript" src="../../script/ao_module.js"></script>
  12. <script type="text/javascript" src="../../script/forge-sha256.min.js"></script>
  13. <script type="text/javascript" src="../../script/qrcode.min.js"></script>
  14. <script>
  15. window.mobilecheck = function() {
  16. var check = false;
  17. (function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))) check = true;})(navigator.userAgent||navigator.vendor||window.opera);
  18. return check;
  19. };
  20. </script>
  21. <style>
  22. body{
  23. color:black;
  24. height:100%;
  25. }
  26. @font-face {
  27. font-family: 'TaipeiSansTCBeta-Regular';
  28. src: url('../../script/font/TaipeiSansTCBeta-Regular.ttf');
  29. }
  30. h1, h2, h3, p, span, div,span { font-family: 'TaipeiSansTCBeta-Regular',"Lucida Console", "Courier New", monospace;}
  31. html{
  32. height:100%;
  33. overflow:hidden;
  34. }
  35. body.whiteTheme{
  36. background-color:rgb(250, 250, 250);
  37. }
  38. .darkTheme{
  39. background-color:#242330 !important;
  40. color:white;
  41. }
  42. .whiteTheme{
  43. color:#0d0d0d
  44. }
  45. .navibar{
  46. position:fixed;
  47. width:100%;
  48. padding-left:12px;
  49. padding-right:12px;
  50. padding-top:6px;
  51. padding-bottom:3px;
  52. z-index: 99;
  53. }
  54. .navibar.darkTheme{
  55. background-color:#17161f !important;
  56. border-bottom:2px solid #34b7eb;
  57. }
  58. .navibar.whiteTheme{
  59. /*box-shadow: 0 2px 4px 2px rgb(224, 224, 224);*/
  60. background-color:#fcfcfc;
  61. border-bottom:2px solid #34b7eb;
  62. }
  63. .whiteTheme .button.standard{
  64. box-shadow: 0 1px 1px 0px rgb(190, 190, 190);
  65. border: 0px;
  66. }
  67. .whiteTheme .button.standard:hover{
  68. background-color:#82c2f0 !important;
  69. color:white !important;
  70. }
  71. .ts.button{
  72. margin-bottom:2px;
  73. }
  74. .ts.button.darkTheme{
  75. background-color:#17161f !important;
  76. border: 1px solid #262533;
  77. color:white;
  78. }
  79. .ts.button.active.darkTheme{
  80. background-color:#312f42 !important;
  81. border: 1px solid #262533;
  82. color:white;
  83. }
  84. .ts.button.darkTheme:hover{
  85. background-color:#312f42 !important;
  86. color:white !important;
  87. }
  88. .rightPad{
  89. margin-right:40px;
  90. }
  91. .addressBar{
  92. width:100%;
  93. padding:3px;
  94. min-height: 35px;
  95. padding-top:6px;
  96. }
  97. .breadcrumb.darkTheme{
  98. background-color:transparent;
  99. }
  100. .section.darkTheme{
  101. color:white !important;
  102. background-color:transparent;
  103. }
  104. .selectable{
  105. cursor:pointer;
  106. }
  107. .rightAlign{
  108. position:absolute;
  109. right:0px;
  110. top:3px;
  111. }
  112. .addressText{
  113. padding:5px;
  114. border-radius: 3px;
  115. }
  116. .addressText.darkTheme{
  117. border: 1px solid #262533;
  118. }
  119. .addressText.whiteTheme{
  120. border: 1px solid #cfcfcf;
  121. }
  122. .divider.whiteTheme{
  123. color:#262533 !important;
  124. background-color:transparent;
  125. }
  126. .divider.darkTheme{
  127. background-color:transparent;
  128. color: white !important;
  129. }
  130. #directorySidebar{
  131. padding:12px;
  132. overflow-y:auto;
  133. padding-bottom:20px;
  134. }
  135. #directorySidebar.darkTheme{
  136. border-right:2px solid rgb(25, 24, 31);
  137. color:white;
  138. position:absolute;
  139. }
  140. #directorySidebar.whiteTheme{
  141. border-right:2px solid rgba(219, 226, 241, 0.7);
  142. background-color:#f5f5f5;
  143. color:rgb(44, 44, 44);
  144. position:absolute;
  145. }
  146. #folderView{
  147. position:absolute;
  148. padding-left:2em;
  149. padding-right:2em;
  150. padding-top:2em;
  151. overflow-y:auto;
  152. }
  153. #folderView.whiteTheme{
  154. background-color:white;
  155. }
  156. .item.darkTheme{
  157. color:white;
  158. }
  159. .rightmargin.icon{
  160. margin-right:8px !important;
  161. }
  162. .dir{
  163. cursor:pointer;
  164. }
  165. .dir:hover{
  166. color:#d1d1d1 !important;
  167. }
  168. .dir.item.whiteTheme{
  169. color:rgb(78, 78, 78);
  170. }
  171. .device{
  172. cursor:pointer;
  173. }
  174. .device:hover{
  175. color:#d1d1d1;
  176. }
  177. .accordion.darkTheme{
  178. color:white !important;
  179. }
  180. .accordion.whiteTheme{
  181. background-color:transparent !important;
  182. }
  183. .fileObject{
  184. display:block !important;
  185. cursor:pointer;
  186. overflow-wrap: break-word !important;
  187. -webkit-touch-callout: none;
  188. -webkit-user-select: none;
  189. -khtml-user-select: none;
  190. -moz-user-select: none;
  191. -ms-user-select: none;
  192. user-select: none;
  193. }
  194. .fileObject.darkTheme{
  195. border:1px solid rgb(72, 69, 88) !important;
  196. }
  197. .segmented.list.darkTheme{
  198. border:1px solid rgb(8, 8, 10) !important;
  199. box-shadow: 0 0 0 0;
  200. border-radius: 0px;
  201. }
  202. .fileObject.darkTheme:hover{
  203. background-color:#17161f !important;
  204. }
  205. .fileObject.darkTheme:hover span{
  206. background-color:#17161f !important;
  207. }
  208. .fileObject.whiteTheme:hover{
  209. background-color:#f2f2f2 !important;
  210. }
  211. .fileObject.darkTheme.selected{
  212. background-color:#100f16 !important;
  213. }
  214. .fileObject.darkTheme.selected span{
  215. background-color:#100f16 !important;
  216. }
  217. .fileObject.whiteTheme.selected{
  218. background-color:#d2f2f7 !important;
  219. color:black !important;
  220. }
  221. .mobilePathDisplayWrapper{
  222. width:100%;
  223. margin-bottom:5px;
  224. }
  225. .ts.card.darkTheme{
  226. border:1px solid rgb(72, 69, 88) !important;
  227. box-shadow: 0 0 0 0 transparent;
  228. }
  229. .darkTheme.header{
  230. color:white !important;
  231. background-color:transparent !important;
  232. }
  233. .darkTheme.meta{
  234. color:rgba(255, 255, 255, 0.836) !important;
  235. background-color:transparent !important;
  236. }
  237. .darkTheme.description{
  238. color:white !important;
  239. background-color:transparent !important;
  240. }
  241. .whiteTheme.header{
  242. background-color:transparent;
  243. }
  244. .whiteTheme.meta{
  245. background-color:transparent;
  246. }
  247. .whiteTheme.description{
  248. background-color:transparent;
  249. }
  250. #folderList{
  251. margin-bottom:16px;
  252. }
  253. .msgbox{
  254. padding:3px;
  255. }
  256. .closeMsgButton{
  257. position:absolute;
  258. top:8px;
  259. right:12px;
  260. }
  261. .closeMsgButton{
  262. cursor:pointer;
  263. }
  264. .popup{
  265. position:fixed;
  266. top:30px;
  267. z-index:110;
  268. left:34%;
  269. right:34%;
  270. bottom:30px;
  271. padding-bottom:24px;
  272. border: 0px solid transparent !important;
  273. }
  274. .popup.wide{
  275. left:24%;
  276. right:24%;
  277. }
  278. .popup.darkTheme{
  279. -webkit-box-shadow: 3px 4px 5px 0px rgb(35, 33, 46) ;
  280. -moz-box-shadow: 3px 4px 5px 0px rgb(35, 33, 46);
  281. box-shadow: 3px 4px 5px 0px rgb(35, 33, 46) ;
  282. border: 1px solid rgb(22, 21, 29);
  283. }
  284. .popup.whiteTheme{
  285. -webkit-box-shadow: 3px 4px 5px 0px rgba(138,138,138,1);
  286. -moz-box-shadow: 3px 4px 5px 0px rgba(138,138,138,1);
  287. box-shadow: 3px 4px 5px 0px rgba(138,138,138,1);
  288. border: 1px solid rgb(226, 226, 226);
  289. background-color:white;
  290. }
  291. @media only screen and (max-width: 1920px) {
  292. .popup{
  293. left:35em;
  294. right:35em;
  295. }
  296. .popup.wide{
  297. left:20em;
  298. right:20em;
  299. }
  300. }
  301. @media only screen and (max-width: 1500px) {
  302. .popup{
  303. left:20em;
  304. right:20em;
  305. }
  306. .popup.wide{
  307. left:14em;
  308. right:14em;
  309. }
  310. }
  311. @media only screen and (max-width: 1200px) {
  312. .popup{
  313. left:14em;
  314. right:14em;
  315. }
  316. .popup.wide{
  317. left:5em;
  318. right:5em;
  319. }
  320. }
  321. @media only screen and (max-width: 800px) {
  322. .popup{
  323. left:5em;
  324. right:5em;
  325. }
  326. .popup.wide{
  327. left:2em;
  328. right:2em;
  329. }
  330. }
  331. @media only screen and (max-width: 600px) {
  332. .popup{
  333. position:fixed;
  334. top:5%;
  335. z-index:100;
  336. left:1em;
  337. right:1em;
  338. }
  339. }
  340. .popupheader{
  341. width:100%;
  342. padding:3px;
  343. padding-left:12px;
  344. border-bottom:2px solid #34b7eb;
  345. background-color: #171719;
  346. color: white;
  347. height:29px;
  348. }
  349. .popupcontent{
  350. height: calc(100% - 29px);
  351. overflow:auto;
  352. }
  353. /*
  354. .popupheader.whiteTheme{
  355. background-color:#eee;
  356. color: #232322;
  357. }
  358. .popupheader.darkTheme{
  359. background-color:#111017 !important;
  360. color: white;
  361. }
  362. */
  363. .popupcloser{
  364. position:absolute;
  365. top:5px;
  366. right:0px;
  367. font-size: 120%;
  368. cursor:pointer;
  369. }
  370. .popupbuttons{
  371. cursor:pointer;
  372. padding:5px;
  373. padding-left:12px;
  374. margin-bottom:4px;
  375. border: 1px solid #dedede;
  376. border-radius: 4px;
  377. }
  378. .popupbuttons.primary.whiteTheme{
  379. background-color:#51aded;
  380. box-shadow: 0 2px 1px 0px #34a2ee !important;
  381. border: 1px solid transparent;
  382. color:white;
  383. }
  384. .popupbuttons.negative{
  385. background-color:#ed5151;
  386. box-shadow: 0 2px 1px 0px #ee3434 !important;
  387. border: 1px solid transparent;
  388. color:white;
  389. }
  390. .popupbuttons.primary.darkTheme{
  391. background-color:#413f57 !important;
  392. box-shadow: 0 2px 1px 0px #3c3b50 !important;
  393. border: 1px solid transparent;
  394. color:white;
  395. }
  396. .popupbuttons.negative.darkTheme{
  397. background-color:#ed5151 !important;
  398. }
  399. .popupbuttons.disabled{
  400. opacity: 0.4;
  401. pointer-events: none;
  402. }
  403. .popupbuttons.primary.disabled{
  404. opacity: 0.4;
  405. pointer-events: none;
  406. }
  407. .whiteTheme.allowHover:hover{
  408. background-color:rgba(238, 238, 238, 0.932);
  409. }
  410. .whiteTheme.allowHover.primary:hover{
  411. background-color:#76c0f5;
  412. }
  413. .allowHover.negative:hover{
  414. background-color:#f57676;
  415. }
  416. .allowHover.negative.darkTheme:hover{
  417. background-color:#f57676 !important;
  418. }
  419. .darkTheme.allowHover:hover{
  420. background-color:#111017 !important;
  421. }
  422. .ts.list.darkTheme{
  423. background-color:#464457 !important;
  424. }
  425. input.darkTheme{
  426. color:white !important;
  427. }
  428. .ts.segmented.list.darkTheme .item{
  429. color:white !important;
  430. }
  431. .newFileFormat{
  432. cursor:pointer;
  433. }
  434. .popupWrapper{
  435. position:fixed;
  436. top:0px;
  437. left:0px;
  438. width:100%;
  439. height:100%;
  440. z-index:99;
  441. background-color:rgba(27,27,27,0.5);
  442. display:none;
  443. }
  444. @supports (backdrop-filter: none) {
  445. .popupWrapper {
  446. backdrop-filter: blur(5px);
  447. }
  448. }
  449. .breadcrumb.whiteTheme{
  450. background-color:white;
  451. }
  452. #openWithModuleList{
  453. height:250px;
  454. overflow-y:auto;
  455. }
  456. #openWith .segment.darkTheme{
  457. color:white !important;
  458. }
  459. #openWithModuleList .item{
  460. padding:8px;
  461. padding-left:22px;
  462. border-radius: 2px;
  463. display: flex;
  464. flex-wrap: wrap;
  465. }
  466. #openWithModuleList.darkTheme .item.selected{
  467. background-color:#100f16 !important;
  468. }
  469. #openWithModuleList.whiteTheme .item.selected{
  470. background-color:#51aded !important;
  471. color:white;
  472. }
  473. #openWithModuleList.darkTheme .item.selectable:hover{
  474. background-color:rgba(250,250,250,0.05);
  475. }
  476. #openWithModuleList.whiteTheme .item.selectable:hover{
  477. background-color:rgba(35,35,35,0.14);
  478. }
  479. .contextmenu.darkTheme .item{
  480. color:white !important;
  481. }
  482. .contextmenu .item{
  483. font-size:90% !important;
  484. }
  485. #uploadTab{
  486. position:fixed;
  487. right:0px;
  488. bottom: 0px;
  489. width:300px;
  490. margin-bottom:0px !important;
  491. padding:0px !important;
  492. }
  493. #uploadTab.darkTheme{
  494. color:white;
  495. background-color:rgba(35,35,35,0.14);
  496. border: 1px solid #17161f !important;
  497. box-shadow: 0px 0px 0px 0px rgba(0,0,0,0.75);
  498. }
  499. .statusBar{
  500. height:32px;
  501. background-color:#f5f5f5;
  502. padding:8px;
  503. }
  504. .statusBar.whiteTheme{
  505. color:rgb(78, 78, 78);
  506. }
  507. .statusBar.darkTheme{
  508. background-color:#181720 !important;
  509. }
  510. .hideUploadButton{
  511. float: right;
  512. cursor:pointer;
  513. }
  514. .uploadList{
  515. margin:8px;
  516. padding-bottom:3px;
  517. margin-bottom:0px;
  518. max-height: 250px;
  519. overflow-y:auto;
  520. }
  521. .uploadTask{
  522. margin-top:6px;
  523. }
  524. .uploadTaskRemoveIcon{
  525. position:absolute;
  526. top:0px;
  527. right:0px;
  528. cursor:pointer;
  529. }
  530. .clearallButton{
  531. padding:8px;
  532. cursor:pointer;
  533. }
  534. .normal.object.whiteTheme{
  535. color:#303030;
  536. }
  537. .normal.object.darkTheme{
  538. color:white;
  539. }
  540. .sub.header.darkTheme{
  541. color:rgb(190, 190, 190) !important;
  542. }
  543. .hex.foldername{
  544. color:#2b9447 !important;
  545. }
  546. .um.filename{
  547. color: #69aaff !important;
  548. }
  549. .dropdown.inverted{
  550. background-color: #17161f !important;
  551. }
  552. .sharebtn{
  553. cursor: pointer;
  554. }
  555. .sharebtn.darkTheme {
  556. color: white !important;
  557. background-color: transparent !important;
  558. }
  559. .sharebtn.whiteTheme:hover{
  560. opacity: 0.5;
  561. }
  562. .sharebtn.darkTheme:hover{
  563. opacity: 0.5;
  564. }
  565. </style>
  566. </head>
  567. <body class="whiteTheme">
  568. <div id="navibar" class="navibar whiteTheme">
  569. <!-- Directoy navigations -->
  570. <button id="backbtn" class="ts icon tiny button standard whiteTheme" onclick="previosPath();" title="Back"><i class="left arrow icon"></i></button>
  571. <button id="ppbtn" class="ts icon tiny button standard whiteTheme rightPad" onclick="parentDir();" title="Parent Folder"><i class="up arrow icon"></i></button>
  572. <!-- File Read Operations -->
  573. <button class="ts icon tiny button standard whiteTheme" title="Open" onclick="openViaButton();"><i class="folder open icon"></i></button>
  574. <button class="ts icon tiny button standard whiteTheme" title="Open with" onclick="openWith();"><i class="external icon"></i></button>
  575. <button class="ts icon tiny button standard whiteTheme singleObjectOnly" title="Share File" onclick="shareFile();"><i class="share alternate icon"></i></button>
  576. <button class="ts labeled icon tiny button standard whiteTheme" style="width:154px;" title="Download" onclick="downloadFile();">
  577. <i class="download icon"></i>
  578. Download
  579. </button>
  580. <!-- File Edit Operations -->
  581. <button class="ts icon tiny button standard whiteTheme" title="Copy" onclick="copy();"><i class="copy icon"></i></button>
  582. <button class="ts icon tiny button standard whiteTheme" title="Paste" onclick="paste();"><i class="paste icon"></i></button>
  583. <button class="ts icon tiny button standard whiteTheme" title="Cut" onclick="cut();"><i class="cut icon"></i></button>
  584. <button class="ts icon tiny button standard whiteTheme" title="New File" onclick="newfile();"><i class="file outline icon"></i></button>
  585. <button class="ts icon tiny button standard whiteTheme" title="New Folder" onclick="newFolder();"><i class="folder outline icon"></i></button>
  586. <button class="ts icon tiny button standard whiteTheme" title="Upload" onclick="upload();"><i class="upload icon"></i></button>
  587. <button class="ts icon tiny button standard whiteTheme" title="Create Zip" onclick="zipFile();"><i class="zip file icon"></i></button>
  588. <button class="ts icon tiny button standard whiteTheme" title="Rename" onclick="rename();"><i class="i cursor icon"></i></button>
  589. <button class="ts icon tiny negative button" title="Delete" onclick="deleteFile();"><i class="trash outline icon"></i></button>
  590. <button class="ts icon tiny button standard whiteTheme" title="Refresh" onclick="refreshList();"><i class="refresh icon"></i></button>
  591. <button class="ts icon tiny button standard whiteTheme" title="File Info" onclick="showFileProperties();"><i class="notice icon"></i></button>
  592. <button class="ts icon tiny button standard whiteTheme" title="Help"><i class="help icon"></i></button>
  593. <div class="addressBar">
  594. <button class="ts icon tiny button standard whiteTheme" onclick="toggleSidebar();" title="Toggle Folder List"><i class="content icon"></i></button>
  595. <button class="ts icon tiny button inverted" title="Dark Theme" onclick="toggleDarkTheme();"><i class="moon icon" id="darkthemebtn"></i></button>
  596. <div class="ts breadcrumb whiteTheme addressText pathDisplay desktopOnly">
  597. <div class="section whiteTheme selectable"><i class="folder icon"></i> user</div>
  598. <div class="divider whiteTheme">:/</div>
  599. <div class="section whiteTheme selectable">Desktop</div>
  600. </div>
  601. <div class="rightAlign">
  602. <select id="sortingMethodSelector" title="Sorting Method" class="ts basic borderless mini dropdown" onchange="updateSortingMethods();" autocomplete="off">
  603. <option value="default">Ascending</option>
  604. <option value="reverse">Descending</option>
  605. <option value="smallToLarge">Smallest</option>
  606. <option value="largeToSmall"> Largest</option>
  607. <option value="mostRecent">Most Recent</option>
  608. <option value="leastRecent">Least Recent</option>
  609. </select>
  610. <button id="searhbtn" class="ts icon tiny button standard whiteTheme" title="Search" onclick="toggleSearch();"><i class="search icon"></i></button>
  611. <button class="ts icon tiny button standard whiteTheme videmode" mode="grid" title="Block View" onclick="changeViewMode(this);"><i class="block layout icon"></i></button>
  612. <button class="ts icon tiny button standard whiteTheme videmode" mode="list" title="List View" onclick="changeViewMode(this);"><i class="align justify icon"></i></button>
  613. </div>
  614. </div>
  615. <div class="mobilePathDisplayWrapper">
  616. <div style="width:100%;" class="ts pathDisplay breadcrumb whiteTheme addressText mobileOnly">
  617. <div class="section whiteTheme selectable"><i class="folder icon"></i> user</div>
  618. <div class="divider whiteTheme">:/</div>
  619. <div class="section whiteTheme selectable">Desktop</div>
  620. </div>
  621. </div>
  622. <div class="searchbar" style="z-index:999; display:none;">
  623. <div style="width: 80%; display:inline-block; margin-top:-4px;">
  624. <div class="ts mini fluid input">
  625. <input autocomplete="off" id="searchInput" type="text" class="whiteTheme" placeholder="File Search (Start wildcard search with / , e.g. /*.mp3)" onkeypress="handleSearchBarPress(event);">
  626. </div>
  627. </div>
  628. <button class="ts icon tiny button standard whiteTheme" title="Case Sensitive" onclick="toggleCaseSensitive(this);">Aa</button>
  629. <button class="ts icon tiny button standard whiteTheme" title="Search" onclick="handleSearch();"><i class="search icon"></i></button>
  630. <button class="ts icon tiny button standard whiteTheme" title="Clear Search" onclick="hideSearchBar();"><i class="remove icon"></i></button>
  631. </div>
  632. <div class="msgbox" style="z-index:999; display:none;">
  633. <i class="checkmark icon"></i> <span>No Message</span>
  634. <div class="closeMsgButton" onclick="$(this).parent().slideUp('fast');"><i class="remove icon"></i></div>
  635. </div>
  636. </div>
  637. <div id="mainWindow">
  638. <div id="directorySidebar" class="whiteTheme">
  639. <div class="ts list">
  640. <details class="ts accordion fluid whiteTheme" open>
  641. <summary>
  642. <i class="dropdown icon"></i> User
  643. </summary>
  644. <div id="userroot" class="ts list" style="padding-top:0px !important;">
  645. <div class="dir item whiteTheme"><i class="loading circle notched rightmargin icon"></i> Initiating</div>
  646. </div>
  647. </details>
  648. <details class="ts accordion fluid whiteTheme" open>
  649. <summary>
  650. <i class="dropdown icon"></i> Storage
  651. </summary>
  652. <div id="storageroot" class="ts list" style="padding-top:0px !important;">
  653. <div class="dir item whiteTheme"><i class="loading circle notched rightmargin icon"></i> Initiating</div>
  654. </div>
  655. </details>
  656. <!--
  657. <details class="ts accordion fluid whiteTheme" open>
  658. <summary>
  659. <i class="caret down icon"></i>Disks
  660. </summary>
  661. <div id="deviceList" class="ts list" style="padding-top:0px !important;">
  662. <div class="dir item whiteTheme"><i class="loading circle notched rightmargin icon"></i> Initiating</div>
  663. </div>
  664. </details>
  665. -->
  666. <!-- >
  667. <div class="item fluid whiteTheme">
  668. <i class="world icon"></i>Network
  669. </div>
  670. -->
  671. <br>
  672. </div>
  673. </div>
  674. <div id="folderView" class="whiteTheme" ondrop="drop(event)" ondragover="allowDrop(event)">
  675. <div id="folderList">
  676. </div>
  677. <div id="fileList">
  678. </div>
  679. <br>
  680. </div>
  681. </div>
  682. <!-- Other popup windows -->
  683. <div class="popupWrapper"></div>
  684. <!-- Overwrite Selection Box-->
  685. <div id="overwriteModeSelection" class="popup whiteTheme" style="display:none;">
  686. <div class="popupheader whiteTheme">
  687. <i class="paste icon"></i> Replace, Keep or Skip Files
  688. <div class="popupcloser" onclick="hideAllPopupWindows();">
  689. <i class="remove icon"></i>
  690. </div>
  691. </div>
  692. <div class="popupcontent" style="padding:12px;">
  693. <small style="font-size:80%;">Copying <span class="owm-fc"></span> files from <span class="owm-srcdir"></span> to <span class="owm-destdir"></span>.</small>
  694. <p>The destination has <span class="owm-fc"></span> files with the same names.</p>
  695. <div class="popupbuttons whiteTheme allowHover primary" onclick="changeOverwriteRule(0,true);">
  696. <i class="checkmark icon"></i> Replace the files in the destination
  697. </div>
  698. <div class="popupbuttons whiteTheme allowHover" onclick="changeOverwriteRule(1,true);">
  699. <i class="reply icon"></i> Skip these files
  700. </div>
  701. <div class="popupbuttons whiteTheme allowHover" onclick="changeOverwriteRule(2,true);">
  702. <i class="undo icon"></i> Rename and keep the files
  703. </div>
  704. </div>
  705. </div>
  706. <!-- Force delete confirmation box -->
  707. <div id="forceDeleteConfirmBox" class="popup whiteTheme" style="display:none;">
  708. <div class="popupheader whiteTheme">
  709. <i class="trash icon"></i> Permanently Remove Files
  710. <div class="popupcloser" onclick="hideAllPopupWindows();">
  711. <i class="remove icon"></i>
  712. </div>
  713. </div>
  714. <div class="popupcontent" style="padding:12px;">
  715. <p>Are you sure you want to remove these files <u>permanently?</u><br>This action is <u>irreversible</u>.</p>
  716. <div class="ts list whiteTheme deleteFilelist" style="max-height:350px;overflow-y:auto; ">
  717. </div>
  718. <div class="popupbuttons whiteTheme allowHover" style="background-color: #eb4034 !important;" onclick="forceDelete(true);";>
  719. <i class="trash icon"></i> Confirm
  720. </div>
  721. <div class="popupbuttons whiteTheme allowHover" onclick="cancelForceDelete();hideAllPopupWindows();">
  722. <i class="remove icon"></i> Cancel
  723. </div>
  724. </div>
  725. </div>
  726. <!-- Delete confirm box -->
  727. <div id="deleteConfirmBox" class="popup whiteTheme" style="display:none;">
  728. <div class="popupheader whiteTheme">
  729. <i class="recycle icon"></i> Move files to Trash Bin
  730. <div class="popupcloser" onclick="hideAllPopupWindows();">
  731. <i class="remove icon"></i>
  732. </div>
  733. </div>
  734. <div class="popupcontent" style="padding:12px;">
  735. <p>Are you sure you want to move these files to trash bin?</p>
  736. <div class="ts list whiteTheme deleteFilelist" style="max-height:350px;overflow-y:auto; ">
  737. </div>
  738. <div class="popupbuttons whiteTheme allowHover" style="color: #2bbbdf !important;" onclick="deleteFile(true);";>
  739. <i class="recycle icon"></i> Move to Trash
  740. </div>
  741. <div class="popupbuttons whiteTheme allowHover" onclick="cancelDelete();hideAllPopupWindows();">
  742. <i class="remove icon"></i> Cancel
  743. </div>
  744. </div>
  745. </div>
  746. <!-- Rename tool box -->
  747. <div id="renameBox" class="popup whiteTheme" style="display:none;">
  748. <div class="popupheader whiteTheme">
  749. <i class="text cursor icon"></i> Rename Files
  750. <div class="popupcloser" onclick="hideAllPopupWindows();">
  751. <i class="remove icon"></i>
  752. </div>
  753. </div>
  754. <div class="popupcontent" style="padding:12px;">
  755. <p>Enter the new filename for renaming. </p>
  756. <p class="multifileWarning"><i class="notice icon"></i> Other files will be named as file(#)</p>
  757. <div class="ts left icon small fluid input" style="margin-bottom:12px;">
  758. <input type="text" class="whiteTheme orgfn" placeholder="Original Filename" readonly="true">
  759. <i class="minus square icon" style="color:rgb(122, 176, 247)"></i>
  760. </div>
  761. <div class="ts left icon small fluid input" style="margin-bottom:12px;">
  762. <input type="text" class="whiteTheme newfn" placeholder="New Filename" onkeydown="handleEnterKeyDown(event, function(){confirmRename(true);})">
  763. <i class="add square icon" style="color:rgb(122, 176, 247)"></i>
  764. </div>
  765. <div class="popupbuttons whiteTheme allowHover primary" onclick="confirmRename(true);";>
  766. <i class="checkmark icon"></i> OK
  767. </div>
  768. <div class="popupbuttons whiteTheme allowHover" onclick="hideAllPopupWindows();">
  769. <i class="remove icon"></i> Cancel
  770. </div>
  771. </div>
  772. </div>
  773. <!-- New File Dialog-->
  774. <div id="newFile" class="popup whiteTheme" style="display:none;">
  775. <div class="popupheader whiteTheme">
  776. <i class="add icon"></i> New File
  777. <div class="popupcloser" onclick="hideAllPopupWindows();">
  778. <i class="remove icon"></i>
  779. </div>
  780. </div>
  781. <div class="popupcontent" style="padding:12px;">
  782. <p>Please select a type of file to be created.</p>
  783. <div class="ts segmented list whiteTheme newfilelist" style="max-height:18em; overflow-y:scroll">
  784. <div class="item newFileFormat" ext="php">No Item</div>
  785. </div>
  786. <p>Or create an empty file with given filename:</p>
  787. <div class="ts left icon small fluid input" style="margin-bottom:12px;">
  788. <input id="createNewFileName" type="text" class="whiteTheme" placeholder="New Filename" onkeydown="handleEnterKeyDown(event, confirmNewFile);">
  789. <i class="add square icon" style="color:rgb(122, 176, 247)"></i>
  790. </div>
  791. <p class="duplicateWarning" style="color:#CE5F58; display:none;"><i class="caution sign icon"></i> The given filename already exist.</p>
  792. <div class="popupbuttons whiteTheme allowHover primary" onclick="confirmNewFile();";>
  793. <i class="add icon"></i> Create
  794. </div>
  795. <div class="popupbuttons whiteTheme allowHover" onclick="hideAllPopupWindows();">
  796. <i class="remove icon"></i> Cancel
  797. </div>
  798. </div>
  799. </div>
  800. <!-- New Folder Dialog-->
  801. <div id="newFolder" class="popup whiteTheme" style="display:none;">
  802. <div class="popupheader whiteTheme">
  803. <i class="folder icon"></i> New Folder
  804. <div class="popupcloser" onclick="hideAllPopupWindows();">
  805. <i class="remove icon"></i>
  806. </div>
  807. </div>
  808. <div class="popupcontent" style="padding:12px;">
  809. <p>Please enter the new folder name to be created.</p>
  810. <div class="ts left icon small fluid input" style="margin-bottom:12px;">
  811. <input id="createNewFolder" type="text" class="whiteTheme" placeholder="New Folder Name" onkeydown="handleEnterKeyDown(event, function(){newFolder(true);});">
  812. <i class="add square icon" style="color:rgb(122, 176, 247)"></i>
  813. </div>
  814. <p class="duplicateWarning" style="color:#CE5F58; display:none;"><i class="caution sign icon"></i> The given folder already exist.</p>
  815. <div class="popupbuttons whiteTheme allowHover primary" onclick="newFolder(true);";>
  816. <i class="add icon"></i> Create
  817. </div>
  818. <div class="popupbuttons whiteTheme allowHover" onclick="hideAllPopupWindows();">
  819. <i class="remove icon"></i> Cancel
  820. </div>
  821. </div>
  822. </div>
  823. <!-- Share File Dialog-->
  824. <div id="shareFile" class="popup wide whiteTheme" style="display:none;">
  825. <div class="popupheader whiteTheme">
  826. <i class="external icon"></i> Share File
  827. <div class="popupcloser" onclick="hideAllPopupWindows();">
  828. <i class="remove icon"></i>
  829. </div>
  830. </div>
  831. <div class="popupcontent" style="padding:12px;">
  832. <div class="ts stackable grid">
  833. <div class="eight wide column">
  834. <div class="width: 100%; ">
  835. <div style="display: block; margin-left: auto; margin-right: auto;" align="center">
  836. <div id="qrcode" style="border: 10px solid white; background-color: white;"></div>
  837. </div>
  838. <a id="sharelink" href="" target="_blank" style="margin-top:8px; font-size: 120%; padding-left: 20px; padding-right: 20px; word-break: break-all;">Scan this QR Code to copy the share link</a>
  839. </div>
  840. </div>
  841. <div class="eight wide column" style="padding-left: 12px;">
  842. <div class="ts header whiteTheme">
  843. Share Settings
  844. <div class="sub header whiteTheme">Change who can see this file</div>
  845. </div>
  846. <div id="shareSettingForm" class="ts form">
  847. <div class="field">
  848. <label><p class="whiteTheme">Visable options:</p></label>
  849. <div class="ts checkboxes">
  850. <div class="ts radio checkbox">
  851. <input id="anyone" type="radio" class="shareoption" name="shareopt" value="anyone" checked="true">
  852. <label for="anyone">
  853. <div class="ts header">
  854. <div class="content whiteTheme">
  855. <i class="globe icon"></i> Anyone with the link
  856. <div class="sub header whiteTheme">Anyone who has the link can access this file</div>
  857. </div>
  858. </div>
  859. </label>
  860. </div>
  861. <div class="ts radio disabled checkbox">
  862. <input id="signedin" type="radio" class="shareoption" value="signedin" name="shareopt">
  863. <label for="signedin">
  864. <div class="ts header">
  865. <div class="content whiteTheme">
  866. <i class="user circle outline icon"></i> Anyone signed in
  867. <div class="sub header whiteTheme">Anyone who has signed in can access this file</div>
  868. </div>
  869. </div>
  870. </label>
  871. </div>
  872. <div class="ts radio disabled checkbox">
  873. <input id="samegroup" type="radio" class="shareoption" value="samegroup" name="shareopt">
  874. <label for="samegroup">
  875. <div class="ts header">
  876. <div class="content whiteTheme">
  877. <i class="users icon"></i> Users in the same group
  878. <div class="sub header whiteTheme">Anyone who is in the same group as you do</div>
  879. </div>
  880. </div>
  881. </label>
  882. </div>
  883. <br>
  884. <button class="ts small button" onclick="updateShareSettings(this)" style="border: 0px solid transparent;">Update</button>
  885. </div>
  886. </div>
  887. </div>
  888. </div>
  889. </div>
  890. <div class="ts divider"></div>
  891. <div id="sharingRemoveBtn" class="popupbuttons negative whiteTheme allowHover" onclick="removeSharing()">
  892. <i class="remove icon"></i> Remove Sharing
  893. </div>
  894. <div class="popupbuttons whiteTheme allowHover" onclick="hideShare()">
  895. <i class="checkmark icon"></i> OK
  896. </div>
  897. </div>
  898. </div>
  899. <!-- Open With Dialog-->
  900. <div id="openWith" class="popup whiteTheme" style="display:none;">
  901. <div class="popupheader whiteTheme">
  902. <i class="external icon"></i> Open File With
  903. <div class="popupcloser" onclick="hideAllPopupWindows();">
  904. <i class="remove icon"></i>
  905. </div>
  906. </div>
  907. <div class="popupcontent" style="padding:12px;">
  908. <p>Select a module from the list below:</p>
  909. <div id="openWithModuleList" class="ts segment whiteTheme" style="padding:0px;">
  910. <div class="item selectable">
  911. <div class="content" style="padding-left:12px;">
  912. <div class="header">Loading...</div>
  913. </div>
  914. </div>
  915. </div>
  916. <div class="openWithModule popupbuttons whiteTheme allowHover primary" onclick="openWithSelectedModule(this);";>
  917. <i class="external icon"></i> Open with Selected Module
  918. </div>
  919. <div class="openWithModule popupbuttons whiteTheme allowHover" onclick="openFileWithModuleInNewTab(this);">
  920. <i class="add icon"></i> Open in new tab
  921. </div>
  922. <div class="popupbuttons whiteTheme allowHover vdonly" onclick="openRawFileInFloatWindow(this);">
  923. <i class="window restore outline icon"></i> Open File directly in floatWindow
  924. </div>
  925. <div class="popupbuttons whiteTheme allowHover" onclick="hideAllPopupWindows();">
  926. <i class="remove icon"></i> Cancel
  927. </div>
  928. </div>
  929. </div>
  930. <!-- Context Menu -->
  931. <div id="contextmenu" class="ts small contextmenu visible whiteTheme" style="min-width:250px;">
  932. <div class="item" onclick="openViaButton();">
  933. <i class="folder open icon"></i> Open
  934. </div>
  935. <div class="item fileonly" onclick="openWith();">
  936. <i class="external icon"></i> Open With
  937. </div>
  938. <div class="item folderonly" onclick="openSelectedFolderInNewWindow();">
  939. <i class="external icon"></i> Open In New Window
  940. </div>
  941. <div class="item shareonly" onclick="openFileLocation();">
  942. <i class="folder outline icon"></i> Open File Location
  943. </div>
  944. <div class="item singleObjectOnlyHide" onclick="shareFile();">
  945. <i class="share alternate icon"></i> Share
  946. </div>
  947. <div class="item mobileonly" onclick="toggleCtrl();">
  948. <i class="mouse pointer icon"></i> Multi-select
  949. </div>
  950. <div class="item" onclick="copy();">
  951. <i class="copy icon"></i> Copy
  952. <span class="description">Ctrl + C</span>
  953. </div>
  954. <div class="item allowNoSelection" onclick="paste();">
  955. <i class="paste icon"></i> Paste
  956. <span class="description">Ctrl + V</span>
  957. </div>
  958. <div class="item" onclick="cut();">
  959. <i class="cut icon"></i> Cut
  960. <span class="description">Ctrl + X</span>
  961. </div>
  962. <div class="divider noSelectionOnly"></div>
  963. <div class="item noSelectionOnly" onclick="newfile();">
  964. <i class="file outline icon"></i> New File
  965. </div>
  966. <div class="item noSelectionOnly" onclick="newFolder();">
  967. <i class="folder outline icon"></i> New Folder
  968. </div>
  969. <div class="divider"></div>
  970. <div class="item noSelectionOnly" onclick="upload();">
  971. <i class="upload icon"></i> Upload
  972. </div>
  973. <div class="item" onclick="zipFile();">
  974. <i class="zip file icon"></i> Create Zip
  975. </div>
  976. <div class="item" onclick="rename();">
  977. <i class="i cursor icon"></i> Rename
  978. </div>
  979. <div class="item" onclick="deleteFile();">
  980. <i class="trash icon"></i> Delete
  981. </div>
  982. <div class="divider"></div>
  983. <div class="item noSelectionOnly" onclick="refreshList();">
  984. <i class="refresh icon"></i> Refresh
  985. </div>
  986. <div class="item" onclick="downloadFile();">
  987. <i class="download icon"></i> Download
  988. </div>
  989. <div class="item" onclick="showFileProperties();">
  990. <i class="notice icon"></i> Properties
  991. </div>
  992. <!-- This properties shows the currentDirectory properties instead of the selected file properties-->
  993. <div class="item noSelectionOnly" onclick="showCurrentDirectoryProperties();">
  994. <i class="notice icon"></i> Properties
  995. </div>
  996. </div>
  997. <!-- Upload Progress Bars-->
  998. <div id="uploadTab" class="ts segment whiteTheme" style="display:none;">
  999. <div class="statusBar whiteTheme">
  1000. <i class="upload icon"></i><span id="uploadCount">0</span> Files / <i class="wait icon"></i> <span id="waitingCount">0</span> Files
  1001. <div class="hideUploadButton" onclick="toggleUploadList();">
  1002. <i class="caret down icon"></i>
  1003. </div>
  1004. </div>
  1005. <div class="uploadList" id="uploadProgressList">
  1006. </div>
  1007. <div class="clearallButton">
  1008. <a onclick="clearAllUploadTask();">Clear All</a>
  1009. </div>
  1010. </div>
  1011. <script>
  1012. let directorySidebarWidth = 250; //Width of the sidebar
  1013. let sideBarShown = true; //Indicate if sidebar is shown
  1014. let rootDirs = []; //Storage location for rootDirs
  1015. let currentTheme = "whiteTheme"; //Default theme
  1016. let viewMode = "list"; //Viewmode, support {list, grid, detail}
  1017. let sortMode = "default"; //Sortmode, support {default, reverse, smallToLarge, largeToSmall, mostRecent, leastRecent}
  1018. let currentPath = "user:/"
  1019. let viewHistory = []; //View history
  1020. let enableBetaFilename = false; //Enable beta filename conversion from "inith..." to "normal"
  1021. let currentFilelist = []; //The current file list in the currentPath
  1022. let currentPathHash = ""; //The folder content hash
  1023. let enableAutoRefresh = true; //Enable directory updates on file change
  1024. let filesIconTheme = "default";
  1025. //File operations
  1026. let clipboard = []; //System clipboard
  1027. let cutMode = false; //If set to true, this is cut mode. Else copy mode
  1028. let useLocalstorage = lscheck();
  1029. let overwriteMode = "keep"; //Overwrite mode, support {skip, overwrite, keep}
  1030. let thumbRenderWebSocket = null;
  1031. let searchCaseSensitive = false;
  1032. //Keypress listeners
  1033. let ctrlHold = false;
  1034. let shiftHold = false;
  1035. //Upload related
  1036. let uploadingFileCount = 0;
  1037. let maxConcurrentUpload = 4; //Maxmium number of oncurrent upload
  1038. let uploadPendingList = []; //Upload pending queue for mass upoad
  1039. let lowMemoryMode = true; //Upload with low memory mode channel
  1040. let uploadFileChunkSize = 1024 * 512; //512KB, 4MB not working quite well on slow network
  1041. //File Sharing related
  1042. let shareEditingObject = "";
  1043. let shareEditingUUID = "";
  1044. //System Information
  1045. let systemUUID = "";
  1046. let systemIP = "";
  1047. //Browser detection
  1048. let isMobile = window.mobilecheck();
  1049. let isChromium = window.chrome;
  1050. let isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
  1051. let isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
  1052. let isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
  1053. //Intiiation functions
  1054. initRootDirs();
  1055. initSystemInfo();
  1056. initUploadMode();
  1057. if (isMobile){
  1058. //Mobile css adjustment
  1059. sideBarShown = false;
  1060. $("#directorySidebar").hide();
  1061. $("#directorySidebar").css("width",window.innerWidth + "px");
  1062. $("body").css("overflow","hidden");
  1063. directorySidebarWidth = window.innerWidth;
  1064. $("#folderView").css({
  1065. "padding-right":"1em",
  1066. "padding-left":"1em",
  1067. "padding-top":"1em",
  1068. });
  1069. $(".desktopOnly").hide();
  1070. $(".mobileOnly").show();
  1071. }else{
  1072. $(".mobileOnly").hide();
  1073. $(".desktopOnly").show();
  1074. }
  1075. //Initialize view mode buttons
  1076. updateViewmodeButtons();
  1077. loadListModeFromDB();
  1078. //Initialize system theme
  1079. loadPreference("file_explorer/theme",function(data){
  1080. if (data.error === undefined){
  1081. if (data == "darkTheme"){
  1082. toggleDarkTheme();
  1083. }else{
  1084. //White theme
  1085. }
  1086. }
  1087. });
  1088. if (window.location.hash != ""){
  1089. //Check if the hash is standard open protocol. If yes, translate it
  1090. if (ao_module_loadInputFiles() === null){
  1091. //Window location hash set. List the desire directory
  1092. currentPath = window.location.hash.substring(1,window.location.hash.length);
  1093. if (currentPath.substring(currentPath.length -1) != "/"){
  1094. currentPath = currentPath + "/";
  1095. }
  1096. currentPath = decodeURIComponent(currentPath);
  1097. loadListModeFromDB(function(){
  1098. listDirectory(currentPath);
  1099. });
  1100. }else{
  1101. //This is ao_module load file input. Handle the file opening
  1102. var filelist = ao_module_loadInputFiles();
  1103. if (filelist.length > 0){
  1104. filelist = filelist[0];
  1105. //Check if this is folder or file. Only opendir when it is folder
  1106. //Updates 27-12-2020: Open folder and highlight the file if it is file
  1107. if (filelist.filename.includes(".") == false){
  1108. //Try to open it and overwrite the hash to filesystem hash
  1109. loadListModeFromDB(function(){
  1110. listDirectory(filelist.filepath);
  1111. });
  1112. }else{
  1113. //File. Open its parent folder and highlight the target file if exists
  1114. var parentdir = filelist.filepath.split("/");
  1115. let focusFilename = JSON.parse(JSON.stringify(filelist.filename));
  1116. parentdir.pop();
  1117. parentdir = parentdir.join("/");
  1118. loadListModeFromDB(function(){
  1119. listDirectory(parentdir, function(){
  1120. focusFileObject(focusFilename);
  1121. });
  1122. });
  1123. }
  1124. }
  1125. }
  1126. }else{
  1127. //Initialized directory views
  1128. loadListModeFromDB(function(){
  1129. listDirectory(currentPath);
  1130. });
  1131. }
  1132. //Create a timer to check change in current folder
  1133. setInterval(function(){
  1134. if (enableAutoRefresh == false){
  1135. return;
  1136. }
  1137. getDirHash(function(hash){
  1138. if (hash.error !== undefined){
  1139. //Something went wrong. Ignore this request
  1140. console.log(hash.error)
  1141. }else{
  1142. //Check if the hash match with the last hash.
  1143. if (hash != currentPathHash){
  1144. //console.log(currentPathHash, hash);
  1145. refreshList();
  1146. currentPathHash = hash;
  1147. if (currentPath == "user:/"){
  1148. //Reload the User root folder list
  1149. initRootDirs();
  1150. }
  1151. }
  1152. }
  1153. });
  1154. }, 5000)
  1155. //END OF INIT FUNCTIONS
  1156. //Get the system ID and ip address from the system id services
  1157. function initSystemInfo(){
  1158. $.get("../../system/id/requestInfo",function(data){
  1159. if (data.error !== undefined){
  1160. msgbox("remove", data.error);
  1161. }else{
  1162. systemUUID = data.SystemUUID;
  1163. systemIP = data.IpAddress;
  1164. }
  1165. });
  1166. }
  1167. //Initiate the sidebar contents
  1168. function initRootDirs(){
  1169. //Load user directories
  1170. $.ajax({
  1171. url:"../../system/file_system/listRoots?user=true",
  1172. success: function(data){
  1173. $("#userroot").html("");
  1174. for (var i =0; i < data.length; i++){
  1175. var thisRootObject = data[i];
  1176. if (thisRootObject.IsDir == true && !(thisRootObject.Filename == ".cache" || thisRootObject.Filename == ".trash")){
  1177. //Files will not be listed in the root directory list
  1178. var icon = getUserRootIcons(thisRootObject.Filename);
  1179. var displayName = thisRootObject.Filename;
  1180. var vpath = thisRootObject.Filepath;
  1181. $("#userroot").append(`<div class="dir item ${currentTheme}" filepath="${vpath}" type="folder" onclick="openthis(this);"><i class="${icon} rightmargin icon"></i> ${displayName}</div>`);
  1182. }
  1183. }
  1184. }
  1185. });
  1186. //Load other storage devices
  1187. $.ajax({
  1188. url:"../../system/file_system/listRoots",
  1189. success: function(data){
  1190. $("#storageroot").html("");
  1191. for (var i =0; i < data.length; i++){
  1192. var thisRoot = data[i];
  1193. var displayName = thisRoot.RootName;
  1194. var rootPath = thisRoot.RootPath;
  1195. $("#storageroot").append(`<div class="dir item ${currentTheme}" filepath="${rootPath}" type="folder" rootname="${displayName}" onclick="openthis(this);"><i class="disk outline rightmargin icon"></i> ${displayName} (${rootPath})</div>`);
  1196. }
  1197. }
  1198. });
  1199. //Initial Host device drives
  1200. /*
  1201. $.ajax({
  1202. url: "../../system/file_system/listDrives",
  1203. success: function(data){
  1204. $("#deviceList").html("");
  1205. for (var i =0; i < data.length; i++){
  1206. var drivePath = data[i].Drivepath;
  1207. var usagePercentage = ((data[i].DriveTotalSpace - data[i].DriveFreeSpace) / data[i].DriveTotalSpace) * 100;
  1208. var className = "primary";
  1209. if (usagePercentage > 90){
  1210. className = "negative";
  1211. }
  1212. $("#deviceList").append(`<div class="dir item ${currentTheme}" filepath="${drivePath}" ><i class="disk outline rightmargin icon"></i> ${drivePath}
  1213. <div style="width:100px;height:15px !important; position:absolute;right:3px;top:6px;"">
  1214. <div class="ts ${className} tiny progress">
  1215. <div class="bar" style="width: ${usagePercentage}%"></div>
  1216. </div>
  1217. </div>
  1218. </div>`);
  1219. }
  1220. }
  1221. });
  1222. */
  1223. }
  1224. function getUserRootIcons(foldername){
  1225. var icon = "folder open";
  1226. if (foldername == "Desktop"){
  1227. icon = "computer";
  1228. }else if (foldername == "Document"){
  1229. icon = "file text outline";
  1230. }else if (foldername == "Music"){
  1231. icon = "music";
  1232. }else if (foldername == "Photo"){
  1233. icon = "image";
  1234. }else if (foldername == "Video"){
  1235. icon = "video";
  1236. }else if (foldername == "Trash"){
  1237. icon = "trash"
  1238. }else if (foldername == "Download"){
  1239. icon = "download"
  1240. }else if (foldername == "Model"){
  1241. icon = "cube"
  1242. }else if (foldername == "Appdata"){
  1243. icon = "code"
  1244. }
  1245. return icon;
  1246. }
  1247. // ============================== FOLDER LISTING FUNCTIONS ====================
  1248. function listDirectory(path, callback=undefined, recordUndo=true){
  1249. //If current mode is search mode, hide the serach bar
  1250. if (searchMode == true){
  1251. //Hide searchbar and skip refresh list
  1252. hideSearchBar(true);
  1253. }
  1254. var recordPreviousPage = true;
  1255. if (recordUndo == false){
  1256. recordPreviousPage = false;
  1257. }
  1258. //Backup the current selected files if it is an refresh operation
  1259. let selectedFiles = [];
  1260. if (path == currentPath){
  1261. $(".fileObject.item.selected").each(function(){
  1262. selectedFiles.push($(this).attr("filename"));
  1263. });
  1264. //Set record histroy to false on refresh
  1265. recordPreviousPage = false;
  1266. }
  1267. //Always pad slash to the end of path
  1268. if (path.substring(path.length - 1) != "/"){
  1269. path = path + "/";
  1270. }
  1271. //Clean the path if there are any malformat
  1272. if (path.indexOf("//") != -1){
  1273. path = path.split("//").join("/");
  1274. }
  1275. if (recordPreviousPage){
  1276. viewHistory.push(currentPath);
  1277. }
  1278. window.location.hash = path;
  1279. updatePathDisplay(path);
  1280. currentPath = path;
  1281. //Update floatWindow title if exists
  1282. if (ao_module_virtualDesktop){
  1283. var tmp = path.split("/");
  1284. tmp.pop();
  1285. ao_module_setWindowTitle("File Manager - " + tmp.pop());
  1286. }
  1287. //Check if there are parent path for curret path
  1288. if (checkIfParentDirExists(currentPath)){
  1289. $("#ppbtn").removeClass("disabled");
  1290. }else{
  1291. $("#ppbtn").addClass("disabled");
  1292. }
  1293. if (viewHistory.length < 1){
  1294. $("#backbtn").addClass("disabled");
  1295. }else{
  1296. $("#backbtn").removeClass("disabled");
  1297. }
  1298. //Add loading screen to the folderlists and fileList
  1299. $("#fileList").html("");
  1300. if (currentTheme == "darkTheme"){
  1301. $("#folderList").html(`<div style="height: 100px;">
  1302. <div class="ts active dimmer">
  1303. <div class="ts text loader">Loading</div>
  1304. </div>
  1305. </div>`);
  1306. }else{
  1307. $("#folderList").html(`<div style="height: 100px;">
  1308. <div class="ts active inverted dimmer">
  1309. <div class="ts text loader">Loading</div>
  1310. </div>
  1311. </div>`);
  1312. }
  1313. $.ajax({
  1314. url: "../../system/file_system/listDir",
  1315. method: "POST",
  1316. data: {dir: decodeURIComponent(path), sort: sortMode},
  1317. success: function(data){
  1318. //Parse the filelist into global variable
  1319. currentFilelist = [];
  1320. if (data === null){
  1321. //There is nothing is this folder.
  1322. $("#folderList").hide();
  1323. $("#fileList").hide();
  1324. return;
  1325. }
  1326. if (data.error !== undefined){
  1327. //Parse path error. Try to refresh the page
  1328. console.log("Path prase error! Redirecting to parent directory.", data.error);
  1329. var pdir = currentPath.split("/");
  1330. pdir.pop(); pdir.pop();
  1331. pdir = pdir.join("/");
  1332. currentPath = pdir;
  1333. //Check if it is already rooted and no more parent ahead
  1334. if (currentPath == ""){
  1335. currentPath = "user:/";
  1336. }
  1337. //listDirectory(currentPath, function(){
  1338. // window.location.reload();
  1339. //});
  1340. return;
  1341. }else{
  1342. //Filelist returned. Render it
  1343. renderDirectory(data,function(){
  1344. //Restore the selected file list
  1345. $(".fileObject.item").each(function(){
  1346. for (var i = 0; i < selectedFiles.length; i++){
  1347. var thisFilename = selectedFiles[i];
  1348. if (thisFilename == $(this).attr("filename")){
  1349. $(this).addClass("selected");
  1350. }
  1351. }
  1352. });
  1353. //Perform the callback
  1354. if (callback !== undefined){
  1355. callback();
  1356. }
  1357. });
  1358. }
  1359. }
  1360. });
  1361. }
  1362. //Render filelist --> Convert a file list object into the visable form of file list
  1363. function renderDirectory(filelist, callback=undefined){
  1364. var data = filelist;
  1365. $("#fileList").html("");
  1366. $("#folderList").html("");
  1367. //Build the css strcture of the list
  1368. if (viewMode == "list"){
  1369. $("#fileList").attr("class",`ts segmented fluid list ${currentTheme}`);
  1370. $("#folderList").attr("class",`ts segmented fluid list ${currentTheme}`);
  1371. }else if (viewMode == "details"){
  1372. }else if (viewMode == "grid"){
  1373. $("#fileList").attr("class",`${currentTheme}`).css("vertical-align","top");
  1374. $("#folderList").attr("class",`${currentTheme}`).css("vertical-align","top");
  1375. }
  1376. var files = [];
  1377. var folders = [];
  1378. for (var i =0; i < data.length; i++){
  1379. if (data[i].IsDir == true){
  1380. //This is folder
  1381. folders.push(data[i]);
  1382. }else{
  1383. //This is file
  1384. files.push(data[i]);
  1385. }
  1386. currentFilelist.push(JSON.parse(JSON.stringify(data[i].Filename)));
  1387. }
  1388. //Define the grid size for the interface
  1389. var gridSize = 150 ;
  1390. if (isMobile){
  1391. //Update 3/5/2021: Optimize the width calculation method to best fit
  1392. /*
  1393. if (window.innerWidth > window.innerHeight){
  1394. //Screen using in horizontal mode
  1395. gridSize = window.innerWidth /4 - 20 ;
  1396. }else{
  1397. //Screen using in vertical mode
  1398. gridSize = window.innerWidth /2 - 20 ;
  1399. }
  1400. */
  1401. //A hack to align the divs to center of the container
  1402. $("#folderView").attr("align", "center");
  1403. $("#folderList").attr("align", "left");
  1404. $("#fileList").attr("align", "left");
  1405. //Calculate the best width to fit all the grids
  1406. var bestCount = Math.floor(parseFloat($("#folderView").width()) / parseFloat(gridSize));
  1407. var bestOffset = $("#folderView").width() % gridSize;
  1408. gridSize = gridSize + (bestOffset / bestCount) - (window.innerWidth - $("#folderView").width()) / bestCount;
  1409. }
  1410. //List all folders
  1411. for (var i =0; i < folders.length; i++){
  1412. var filename = folders[i].Filename;
  1413. var filepath = folders[i].Filepath;
  1414. var realpath = folders[i].Realpath;
  1415. var isDir = folders[i].IsDir;
  1416. var filesize = folders[i].Filesize;
  1417. var Displaysize = folders[i].Displaysize;
  1418. var isShared = folders[i].IsShared;
  1419. var ext = getExtFromPath(filepath);
  1420. //var icon = ao_module_utils.getIconFromExt(ext);
  1421. var icon = "folder";
  1422. var shareicon = "";
  1423. if (isShared == true){
  1424. shareicon = `<button class="sharebtn ${currentTheme}" onclick='handleShareFilebuttonClick(event, this);' style="margin-left: 4px; height: 16px;">
  1425. <i class='share alternate icon'></i>
  1426. </button>`
  1427. }
  1428. if (viewMode == "list"){
  1429. var textclass = "normal object";
  1430. if (currentTheme == "darkTheme"){
  1431. textclass += " darkTheme";
  1432. }
  1433. var displayName = filename;
  1434. try{
  1435. //Try to decode it using ArozOS Beta naming scheme
  1436. if (enableBetaFilename && ao_module_codec.decodeHexFoldername(displayName) != displayName){
  1437. displayName = ao_module_codec.decodeHexFoldername(displayName, false);
  1438. textclass = "hex foldername";
  1439. }
  1440. }catch(ex){
  1441. //Codec decode failed. Fallback to default name
  1442. }
  1443. $("#folderList").append(`<div class="fileObject item ${currentTheme}" draggable="true" ondragstart="onFileObjectDragStart(this,event);" ondrop="dropToFolder(event)" ondragover="allowDrop(event)" fileID="${i}" filename="${filename}" filepath="${filepath}" ondblclick="openthis(this,event);" type="folder">
  1444. <span style="display:inline-block !important;word-break: break-all;" class="${textclass}">
  1445. <i class="${icon} icon" style="margin-right:12px; color:#eab54e;"></i> ${displayName} ${shareicon}
  1446. </span></div>`);
  1447. }else if (viewMode == "grid"){
  1448. var displayName = JSON.parse(JSON.stringify(filename));
  1449. var textclass = "normal object";
  1450. try{
  1451. //Try to decode it using ArozOS Beta naming scheme
  1452. if (enableBetaFilename && ao_module_codec.decodeHexFoldername(displayName) != displayName){
  1453. displayName = ao_module_codec.decodeHexFoldername(displayName, false);
  1454. textclass = "hex foldername";
  1455. }
  1456. }catch(ex){
  1457. //Codec decode failed. Fallback to default name
  1458. }
  1459. if (displayName.length > 16){
  1460. displayName = displayName.substring(0,16) + "...";
  1461. }
  1462. $("#folderList").append(`
  1463. <div class="ts card fileObject ${currentTheme}" draggable="true" ondragstart="onFileObjectDragStart(this,event);" ondrop="dropToFolder(event)" ondragover="allowDrop(event)" fileID="${i}" filename="${filename}" filepath="${filepath}" ondblclick="openthis(this,event);" type="folder" style="width:${gridSize}px; display:inline-block !important;vertical-align:top; height:15em; margin-top:0px !important; overflow:hidden;">
  1464. <div class="image" style="text-align: center;">
  1465. <img draggable="true"ondragstart="disableDrag(event);" src="../../../img/desktop/files_icon/${filesIconTheme}/folder.png" style="height: 148px; width: 148px; display: inline-block;">
  1466. </div>
  1467. <div class="content" style="font-size: 12px;">
  1468. <div class="header ${currentTheme} ${textclass}" title="${filename}">${displayName} ${shareicon}</div>
  1469. </div>
  1470. </div>`);
  1471. }
  1472. }
  1473. if (folders.length == 0){
  1474. $("#folderList").hide();
  1475. }else{
  1476. $("#folderList").show();
  1477. }
  1478. //List all files
  1479. var fl = folders.length;
  1480. for (var i =0; i < files.length; i++){
  1481. var filename = files[i].Filename;
  1482. var filepath = files[i].Filepath;
  1483. var realpath = files[i].Realpath;
  1484. var filesize = files[i].Filesize;
  1485. var Displaysize = files[i].Displaysize;
  1486. var isShared = files[i].IsShared;
  1487. var ext = getExtFromPath(filepath);
  1488. if (ext == ""){
  1489. var icon = "file outline";
  1490. }else{
  1491. var icon = ao_module_utils.getIconFromExt(ext);
  1492. }
  1493. var shareicon = "";
  1494. if (isShared){
  1495. shareicon = `<button class="sharebtn ${currentTheme}" onclick='handleShareFilebuttonClick(event, this);' style="margin-left: 4px; height: 16px;">
  1496. <i class='share alternate icon'></i>
  1497. </button>`
  1498. }
  1499. var fileType = "file";
  1500. if (ext == "shortcut"){
  1501. fileType = "shortcut";
  1502. }
  1503. if (viewMode == "list"){
  1504. var displayName = filename;
  1505. var textclass = "normal object";
  1506. if (currentTheme == "darkTheme"){
  1507. textclass += " darkTheme";
  1508. }
  1509. if (enableBetaFilename){
  1510. decodedName = ao_module_codec.decodeUmFilename(displayName);
  1511. if (decodedName != displayName){
  1512. displayName = decodedName;
  1513. textclass = "um filename";
  1514. }
  1515. filename = ao_module_codec.decodeUmFilename(filename);
  1516. }
  1517. $("#fileList").append(`<div class="fileObject item ${currentTheme}" draggable="true" ondragstart="onFileObjectDragStart(this,event);" fileID="${fl + i}" filename="${filename}" filepath="${filepath}" ondblclick="openthis(this,event);" type="${fileType}" filesize="${filesize}" displaysize="${Displaysize}">
  1518. <span style="display:inline-block !important;word-break: break-all;text-overflow: ellipsis !important;overflow: hidden;" class="${textclass}">
  1519. <i class="${icon} icon" style="margin-right:12px;"></i>
  1520. ${displayName} ${shareicon}
  1521. </span>
  1522. </div>`);
  1523. }else if (viewMode == "grid"){
  1524. var imagePath = "../../../img/desktop/files_icon/" + filesIconTheme + "/" + icon + ".png";
  1525. var displayName = JSON.parse(JSON.stringify(filename));
  1526. var textclass = "normal object";
  1527. if (enableBetaFilename){
  1528. decodedName = ao_module_codec.decodeUmFilename(displayName);
  1529. if (decodedName != displayName){
  1530. textclass = "um filename";
  1531. displayName = decodedName;
  1532. }
  1533. filename = ao_module_codec.decodeUmFilename(filename);
  1534. }
  1535. if (displayName.length > 20){
  1536. displayName = displayName.substring(0,20) + "...";
  1537. }
  1538. $("#fileList").append(`
  1539. <div class="ts card fileObject ${currentTheme}" draggable="true" ondragstart="onFileObjectDragStart(this,event);" fileID="${fl + i}" filename="${filename}" filepath="${filepath}" ondblclick="openthis(this,event);" type="${fileType}" style="width:${gridSize}px; display:inline-block !important;vertical-align:top; height:20em; margin-top:0px !important; overflow:hidden;">
  1540. <div class="image" style="text-align: center !important;">
  1541. <img draggable="true"ondragstart="disableDrag(event);" style="height: 148px; width: 148px; display:inline-block;" src="${imagePath}">
  1542. </div>
  1543. <div class="content">
  1544. <div class="header ${currentTheme} ${textclass}" title="${filename}" style="text-overflow: ellipsis; font-size: 100%">${displayName} ${shareicon}</div>
  1545. <div class="meta ${currentTheme}">
  1546. <div>.${ext}</div>
  1547. </div>
  1548. <div class="description ${currentTheme}">
  1549. ${Displaysize}
  1550. </div>
  1551. </div>
  1552. </div>
  1553. `);
  1554. }
  1555. }
  1556. if (files.length == 0){
  1557. $("#fileList").hide();
  1558. }else{
  1559. $("#fileList").show();
  1560. }
  1561. bindFileObjectEvents();
  1562. currentFilelist.sort();
  1563. //Update the filelist hash
  1564. enableAutoRefresh = false;
  1565. getDirHash(function(hash){
  1566. currentPathHash = hash;
  1567. enableAutoRefresh = true;
  1568. });
  1569. //If viewmode is grid, load file thumbnails
  1570. if (viewMode == "grid"){
  1571. startThumbnailLoader();
  1572. }
  1573. if (callback !== undefined){
  1574. callback();
  1575. }
  1576. }
  1577. function startThumbnailLoader(){
  1578. let path = currentPath;
  1579. let protocol = "wss://";
  1580. if (location.protocol !== 'https:') {
  1581. protocol = "ws://";
  1582. }
  1583. var port = window.location.port;
  1584. if (window.location.port == ""){
  1585. port = "80";
  1586. }
  1587. thumbRenderWebSocket = new WebSocket(protocol + window.location.hostname + ":" + port + "/system/file_system/handleCacheRender?folder=" + path);
  1588. thumbRenderWebSocket.onopen = function(e) {
  1589. };
  1590. thumbRenderWebSocket.onmessage = function(event) {
  1591. //Find the correct file in the current directory and place its image
  1592. if (path == currentPath){
  1593. var thumbData = JSON.parse(event.data);
  1594. $(".fileObject").each(function(){
  1595. if (thumbData[1].length > 0){
  1596. if ($(this).attr("filename") == thumbData[0]){
  1597. $(this).find("img").attr("src","data:image/jpg;base64," + thumbData[1]);
  1598. }
  1599. }
  1600. });
  1601. }
  1602. };
  1603. thumbRenderWebSocket.onclose = function(event) {
  1604. //Transfer ended
  1605. };
  1606. thumbRenderWebSocket.onerror = function(error) {
  1607. console.log(error);
  1608. };
  1609. }
  1610. //Make an div not draggable
  1611. function disableDrag(event){
  1612. event.preventDefault();
  1613. event.stopPropagation();
  1614. }
  1615. //Make fileObject draggable
  1616. function onFileObjectDragStart(object, event){
  1617. if ((ctrlHold) && $(object).hasClass("selected") == false){
  1618. $(object).addClass("selected");
  1619. }else if ($(object).hasClass("selected") == false){
  1620. $(".fileObject.selected").removeClass("selected");
  1621. $(object).addClass("selected");
  1622. }
  1623. var fileList = [];
  1624. $(".selected.fileObject").each(function(){
  1625. var filename = $(this).attr('filename');
  1626. var filepath = $(this).attr('filepath');
  1627. var sourceSystemUUID = systemUUID;
  1628. //Extra information is passed in due to the need for cross cluster communication in the future
  1629. fileList.push({
  1630. filename: filename,
  1631. filepath: filepath,
  1632. hostUUID: sourceSystemUUID
  1633. });
  1634. });
  1635. event.dataTransfer.setData("filedata", JSON.stringify(fileList));
  1636. }
  1637. //Bind onclicke events for fileObjects
  1638. var lastClickedFileID = 0;
  1639. function bindFileObjectEvents(){
  1640. $(".fileObject").off("click").on('click',function(evt){
  1641. if (!ctrlHold && isMobile){
  1642. //If on mobile, click means open
  1643. openthis(this,evt);
  1644. return
  1645. }
  1646. if (ctrlHold == true){
  1647. if ($(this).hasClass("selected")){
  1648. $(this).removeClass("selected");
  1649. }else{
  1650. $(this).addClass("selected");
  1651. }
  1652. lastClickedFileID = parseInt($(this).attr("fileid"));
  1653. }else if (shiftHold == true){
  1654. //Select everything in range lastClicked to this
  1655. var thisFileID = $(this).attr("fileid");
  1656. let start = parseInt(thisFileID);
  1657. let end = parseInt(lastClickedFileID);
  1658. if (start > end){
  1659. start = parseInt(lastClickedFileID);
  1660. end = parseInt(thisFileID);
  1661. }
  1662. //Select all fileObject in range.
  1663. $(".fileObject").each(function(){
  1664. let currentItemFileID = $(this).attr('fileid');
  1665. currentItemFileID = currentItemFileID - 0;
  1666. if (currentItemFileID >= start && currentItemFileID <= end){
  1667. $(this).addClass("selected");
  1668. }
  1669. });
  1670. }else{
  1671. //Nothing is pressed. Deselect everything and add this only
  1672. $(".fileObject.selected").removeClass("selected");
  1673. $(this).addClass("selected");
  1674. lastClickedFileID = $(this).attr("fileID");
  1675. }
  1676. if ($(".fileObject.selected").length != 1){
  1677. $(".singleObjectOnly").addClass("disabled");
  1678. $(".singleObjectOnlyHide").hide();
  1679. }else{
  1680. $(".singleObjectOnly").removeClass("disabled");
  1681. $(".singleObjectOnlyHide").show();
  1682. }
  1683. });
  1684. //Bind right click select on items
  1685. $(".fileObject").off("mousedown").on("mousedown",function(evt){
  1686. if (evt.which == 3){
  1687. //Right click on this file
  1688. if ($(this).hasClass('selected') == false){
  1689. $(".fileObject.selected").removeClass("selected");
  1690. $(this).addClass("selected");
  1691. }
  1692. }
  1693. });
  1694. //This function calculate and offset the context menu to not go out of the window area
  1695. function calculateContextMenuOffsets(evt){
  1696. var defaultLeftPost = evt.pageX;
  1697. var defaultTopPost =evt.pageY;
  1698. if (evt.pageX > window.innerWidth / 2){
  1699. defaultLeftPost = evt.pageX - $("#contextmenu").width() + "px";
  1700. }
  1701. if (evt.pageY > window.innerHeight / 2){
  1702. defaultTopPost = evt.pageY - $("#contextmenu").height() + "px";
  1703. }
  1704. $("#contextmenu").css({
  1705. left: defaultLeftPost,
  1706. top: defaultTopPost
  1707. });
  1708. }
  1709. //Rightclick on a file object
  1710. $(".fileObject").off("contextmenu").on("contextmenu", function(evt){
  1711. evt.preventDefault();
  1712. if (isMobile){
  1713. //Firefox Mobile. Fix select with context menu not working bug
  1714. var selectedObject = $(evt.target);
  1715. if ($(selectedObject).hasClass("fileObject")){
  1716. if (!ctrlHold){
  1717. $(".fileObject.selected").removeClass("selected");
  1718. }
  1719. $(selectedObject).addClass("selected");
  1720. }else{
  1721. //Uptrace 5 layers for fileObject
  1722. for (var i = 0; i < 5; i++){
  1723. if ($(selectedObject).hasClass("fileObject") == false){
  1724. selectedObject = $(selectedObject).parent();
  1725. }else{
  1726. break;
  1727. }
  1728. }
  1729. if (!ctrlHold){
  1730. $(".fileObject.selected").removeClass("selected");
  1731. }
  1732. $(selectedObject).addClass("selected");
  1733. }
  1734. }
  1735. calculateContextMenuOffsets(evt);
  1736. //Show all options by defaults
  1737. $("#contextmenu").find(".item").show();
  1738. $("#contextmenu").find(".noSelectionOnly").hide();
  1739. //Check if this is folder or file. Replace the suitable selections
  1740. if ($(this).attr("type") == "folder"){
  1741. //Use folder mode
  1742. $("#contextmenu").find(".folderonly").show();
  1743. $("#contextmenu").find(".fileonly").hide();
  1744. }else{
  1745. //Use file mode
  1746. $("#contextmenu").find(".folderonly").hide();
  1747. $("#contextmenu").find(".fileonly").show();
  1748. }
  1749. if (searchMode == true){
  1750. $("#contextmenu").find(".shareonly").show();
  1751. }else{
  1752. $("#contextmenu").find(".shareonly").hide();
  1753. }
  1754. $("#contextmenu").addClass("visible");
  1755. //Handle CSS offset of the contextmenu
  1756. if ($("#contextmenu").offset().top < 0){
  1757. $("#contextmenu").css("top","0px");
  1758. }else if($("#contextmenu").offset().top + $("#contextmenu").height() > window.innerHeight){
  1759. $("#contextmenu").css("top",window.innerHeight - $("#contextmenu").height() + "px");
  1760. }
  1761. if (isMobile){
  1762. $("#contextmenu").find(".mobileonly").show();
  1763. }else{
  1764. $("#contextmenu").find(".mobileonly").hide();
  1765. }
  1766. });
  1767. //Right click on empty space of the file selector
  1768. $("#folderView").off("contextmenu").on("contextmenu", function(e){
  1769. if ($(e.target).attr("id") == "folderView" || $(e.target).attr("id") == "fileList" || $(e.target).attr("id") == "folderList"){
  1770. //Context menu on the empty space of the folder / file list
  1771. e.preventDefault();
  1772. $("#contextmenu").find(".item").hide();
  1773. $("#contextmenu").find(".noSelectionOnly").show();
  1774. $("#contextmenu").find(".allowNoSelection").show();
  1775. //Calculate the position of the context menu
  1776. calculateContextMenuOffsets(e);
  1777. //Show context menu
  1778. $("#contextmenu").addClass("visible");
  1779. //Handle CSS offset of the contextmenu
  1780. if ($("#contextmenu").offset().top < 0){
  1781. $("#contextmenu").css("top","0px");
  1782. }else if($("#contextmenu").offset().top + $("#contextmenu").height() > window.innerHeight){
  1783. $("#contextmenu").css("top",window.innerHeight - $("#contextmenu").height() + "px");
  1784. }
  1785. }
  1786. });
  1787. $(document).on("click",function(evt){
  1788. $(".contextmenu").removeClass("visible");
  1789. });
  1790. //Force overwrite css
  1791. /*
  1792. $(".ts.contextmenu .item").css({
  1793. 'cssText':"padding: 8px !important"
  1794. });
  1795. */
  1796. }
  1797. //Change the current view mode
  1798. function changeViewMode(object){
  1799. var targetMode = $(object).attr("mode");
  1800. viewMode = targetMode;
  1801. listDirectory(currentPath);
  1802. updateViewmodeButtons();
  1803. setPreference("file_explorer/listmode",targetMode)
  1804. }
  1805. function updateViewmodeButtons(){
  1806. $(".videmode").removeClass('disabled');
  1807. $(".videmode").each(function(){
  1808. if ($(this).attr("mode") == viewMode){
  1809. $(this).addClass("disabled");
  1810. }
  1811. });
  1812. }
  1813. function previosPath(){
  1814. //Remove the current directory from history
  1815. if (viewHistory.length == 0){
  1816. //This is already the first page
  1817. return;
  1818. }
  1819. var previousPath = viewHistory.pop();
  1820. listDirectory(previousPath, undefined, false);
  1821. }
  1822. function parentDir(){
  1823. //If under searchmode, parentDir go back to the currentPath
  1824. if (searchMode){
  1825. hideSearchBar();
  1826. return;
  1827. }
  1828. //Check if there are any parent dir for this path
  1829. if (checkIfParentDirExists(currentPath)){
  1830. //There are parent path. Get it from currentPath
  1831. pathInfo = currentPath.split("/");
  1832. pathInfo.pop();
  1833. var parentFolderName = pathInfo.pop();
  1834. parentPath = pathInfo.join("/") + "/"
  1835. //List the parentDir
  1836. listDirectory(parentPath, function(){
  1837. focusFileObject(parentFolderName);
  1838. });
  1839. }
  1840. }
  1841. //Move the page focus to the given fileobject
  1842. function focusFileObject(targetFileName){
  1843. $(".fileObject").each(function(){
  1844. if ($(this).attr("filename") == targetFileName){
  1845. $(this).addClass("selected");
  1846. //Trying to vertically align the directory from its parent list
  1847. $("#folderView").stop().finish().animate({
  1848. scrollTop: $(this).offset().top - $("#folderView").offset().top - (window.innerHeight - $("#navibar").height())/2 + $(this).height()
  1849. }, 300);
  1850. }
  1851. });
  1852. }
  1853. function loadListModeFromDB(callback = undefined){
  1854. //Get list mode from storage
  1855. loadPreference("file_explorer/listmode",function(data){
  1856. if (data != "" && data.error === undefined){
  1857. viewMode = data;
  1858. updateViewmodeButtons();
  1859. }
  1860. if (callback !== undefined){
  1861. callback();
  1862. }
  1863. });
  1864. }
  1865. function rootDir(){
  1866. //Go to the root dir of the current path
  1867. var rootDir = currentPath.split("/").shift();
  1868. rootDir = rootDir + "/";
  1869. listDirectory(rootDir);
  1870. }
  1871. function checkIfParentDirExists(path){
  1872. if (path.includes("/")){
  1873. pathInfo = path.split("/");
  1874. if (pathInfo[1] == ""){
  1875. return false;
  1876. }else{
  1877. return true;
  1878. }
  1879. }else{
  1880. return false;
  1881. }
  1882. }
  1883. function getDirHash(callback){
  1884. $.ajax({
  1885. url: "../../system/file_system/listDirHash",
  1886. data: {dir: currentPath},
  1887. success: function(data){
  1888. if (data.error !== undefined){
  1889. if (data.error == "Invalid dir given"){
  1890. //Storage has been unmounted. Back to parent
  1891. var pdir = currentPath.split("/");
  1892. pdir.pop();pdir.pop();
  1893. pdir = pdir.join("/");
  1894. currentPath = pdir;
  1895. listDirectory(currentPath, function(){
  1896. window.location.reload();
  1897. });
  1898. return;
  1899. }
  1900. }
  1901. callback(data);
  1902. }
  1903. })
  1904. }
  1905. //=================================== FILE OPERATIONS ========================
  1906. function refreshList(){
  1907. shiftHold = false;
  1908. ctrlHold = false;
  1909. let currentScrollTop = JSON.parse(JSON.stringify($("#folderView").scrollTop()));
  1910. listDirectory(currentPath, function(){
  1911. //Scroll back to the original height
  1912. $("#folderView").scrollTop(currentScrollTop);
  1913. });
  1914. }
  1915. function zipFile(){
  1916. $(".popup").fadeOut('fast');
  1917. var zippingFiles = [];
  1918. $(".fileObject.selected").each(function(){
  1919. var filepath = $(this).attr("filepath");
  1920. zippingFiles.push(filepath);
  1921. });
  1922. console.log(zippingFiles);
  1923. //Request to create a zip file, named with the parent dir name
  1924. var oprConfig = {
  1925. opr: "zip",
  1926. src: zippingFiles,
  1927. dest: currentPath,
  1928. overwriteMode: "overwrite",
  1929. callbackWindowID: ao_module_windowID,
  1930. callbackFunction: `callRefresh("${currentPath}")`
  1931. }
  1932. var configHash = encodeURIComponent(JSON.stringify(oprConfig));
  1933. var title = "Zipping " + zippingFiles.length;
  1934. if (fileList.length > 1){
  1935. title += " files";
  1936. }else{
  1937. title += " file";
  1938. }
  1939. parent.newFloatWindow({
  1940. url: "SystemAO/file_system/file_operation.html#" + configHash,
  1941. width: 400,
  1942. height: 220,
  1943. appicon: "SystemAO/file_system/img/selector.png",
  1944. title: title
  1945. });
  1946. }
  1947. let renameFileObjects = [];
  1948. function rename(){
  1949. $(".popup").fadeOut('fast');
  1950. renameFileObjects = [];
  1951. var filenames = [];
  1952. $(".fileObject.selected").each(function(){
  1953. var fileObjectType = $(this).attr("type");
  1954. let fileObject = {
  1955. filename: $(this).attr('filename'),
  1956. filepath: $(this).attr("filepath"),
  1957. filetype: fileObjectType
  1958. }
  1959. renameFileObjects.push(JSON.parse(JSON.stringify(fileObject)));
  1960. filenames.push($(this).attr('filename'));
  1961. });
  1962. var oldname = "unknown file.txt";
  1963. if (renameFileObjects.length == 0){
  1964. return;
  1965. }else if (renameFileObjects.length > 0){
  1966. $("#renameBox").find(".multifileWarning").hide();
  1967. oldname = filenames[0];
  1968. }
  1969. $("#renameBox").find(".orgfn").val(oldname);
  1970. $("#renameBox").find(".newfn").val(oldname);
  1971. showPopupWrapper();
  1972. $("#renameBox").fadeIn(100);
  1973. }
  1974. function confirmRename(){
  1975. var oldName = $("#renameBox").find(".orgfn").val();
  1976. var newName = $("#renameBox").find(".newfn").val();
  1977. if (newName == oldName){
  1978. msgbox("remove","New filename is identical to the original filename.")
  1979. $("#renameBox").fadeOut(100);
  1980. return;
  1981. }
  1982. var newNameWithoutExt = newName;
  1983. var newnameExt = "";
  1984. if (newName.includes(".")){
  1985. tmp = newName.split(".");
  1986. newnameExt = tmp.pop();
  1987. newNameWithoutExt = tmp.join(".");
  1988. }
  1989. var counter = 0;
  1990. var srclist = [];
  1991. var newnamelist = [];
  1992. for (var i =0; i < renameFileObjects.length; i++){
  1993. var thisFilepath = renameFileObjects[i].filepath;
  1994. var thisFiletype = renameFileObjects[i].filetype;
  1995. var thisFilename = renameFileObjects[i].filename;
  1996. var newFilename = newName;
  1997. if ( i > 0){
  1998. if (thisFiletype == "file"){
  1999. var thisFileExt = thisFilename.split(".").pop();
  2000. newFilename = newNameWithoutExt + "(" + i + ")." + thisFileExt;
  2001. }else if (thisFiletype == "folder"){
  2002. newFilename = newNameWithoutExt + "(" + i + ")";
  2003. }
  2004. }
  2005. srclist.push(thisFilepath);
  2006. newnamelist.push(newFilename);
  2007. }
  2008. console.log(srclist, newnamelist);
  2009. //Send the request to serverside
  2010. $.ajax({
  2011. url: "../../system/file_system/fileOpr",
  2012. method: "POST",
  2013. data: {opr: "rename", src: JSON.stringify(srclist), new: JSON.stringify(newnamelist)},
  2014. success: function(data){
  2015. if (data.error !== undefined){
  2016. msgbox("remove",data.error);
  2017. $("#renameBox").fadeOut(100);
  2018. }else{
  2019. refreshList();
  2020. msgbox("checkmark","Rename suceed");
  2021. $("#renameBox").fadeOut(100);
  2022. }
  2023. }
  2024. });
  2025. renameFileObjects = [];
  2026. hideAllPopupWindows();
  2027. }
  2028. function changeOverwriteRule(mode, doPasteAgain=false){
  2029. switch (mode){
  2030. case 0:
  2031. overwriteMode = "overwrite";
  2032. break;
  2033. case 1:
  2034. overwriteMode = "skip";
  2035. break;
  2036. case 2:
  2037. overwriteMode = "keep";
  2038. break;
  2039. default:
  2040. overwriteMode = "keep";
  2041. }
  2042. if (doPasteAgain){
  2043. //Initiate paste without checking and close the overwritemode selector
  2044. paste(undefined, true);
  2045. $("#overwriteModeSelection").fadeOut(100);
  2046. }
  2047. }
  2048. function copy(){
  2049. cutMode = false;
  2050. clipboard = [];
  2051. if ($(".fileObject.selected").length == 0){
  2052. return;
  2053. }
  2054. $(".fileObject.selected").each(function(){
  2055. var thisFilepath = $(this).attr("filepath");
  2056. clipboard.push(thisFilepath);
  2057. });
  2058. if (useLocalstorage){
  2059. localStorage.setItem("ao/file_system/clipboard",JSON.stringify(clipboard));
  2060. localStorage.setItem("ao/file_system/cutmode","false");
  2061. }
  2062. msgbox("copy",clipboard.length + " objects copied.")
  2063. }
  2064. function cut(){
  2065. cutMode = true;
  2066. clipboard = [];
  2067. if ($(".fileObject.selected").length == 0){
  2068. return;
  2069. }
  2070. $(".fileObject.selected").each(function(){
  2071. var thisFilepath = $(this).attr("filepath");
  2072. clipboard.push(thisFilepath);
  2073. });
  2074. if (useLocalstorage){
  2075. localStorage.setItem("ao/file_system/clipboard",JSON.stringify(clipboard));
  2076. localStorage.setItem("ao/file_system/cutmode","true");
  2077. }
  2078. msgbox("cut",clipboard.length + " objects ready to be moved.")
  2079. }
  2080. function paste(redirectPasteTarget="", nocheck=false){
  2081. let thisOprCutMode = cutMode;
  2082. let fileList = clipboard;
  2083. let targetDir = currentPath;
  2084. if (redirectPasteTarget != ""){
  2085. //Allow redirection of paste target if necessary
  2086. targetDir = redirectPasteTarget;
  2087. }
  2088. if (useLocalstorage){
  2089. //There are localStorage. Always use localStorage if exists.
  2090. var crossFrameClipboard = localStorage.getItem("ao/file_system/clipboard");
  2091. var useCutMode = localStorage.getItem("ao/file_system/cutmode");
  2092. if (crossFrameClipboard !== "" && crossFrameClipboard !== undefined && crossFrameClipboard !== null){
  2093. fileList = JSON.parse(crossFrameClipboard);
  2094. }
  2095. if (useCutMode !== "" && useCutMode !== undefined && useCutMode !== null){
  2096. thisOprCutMode = (useCutMode == "true");
  2097. }
  2098. }
  2099. if (fileList.length == 0){
  2100. //There are nothing to paste
  2101. msgbox("question","There are nothing to paste.")
  2102. return;
  2103. }
  2104. //console.log(fileList,JSON.stringify(fileList));
  2105. if (thisOprCutMode == true){
  2106. //Cut and paste
  2107. $.ajax({
  2108. type: 'POST',
  2109. url: `../../system/file_system/validateFileOpr`,
  2110. data: {src: JSON.stringify(fileList), dest: targetDir},
  2111. success: function(data){
  2112. if (!nocheck && data !== null){
  2113. //There are problem with the copy target. Pop up overwrite rule selector
  2114. showDuplicateHandler(data);
  2115. }else{
  2116. //OK!
  2117. //Clear clipboard settings
  2118. localStorage.setItem("ao/file_system/clipboard", "");
  2119. clipboard = "";
  2120. //Stsart operations
  2121. if (!ao_module_virtualDesktop){
  2122. //Not under desktop mode. Use direct copy API
  2123. $.ajax({
  2124. type: 'POST',
  2125. url: `../../system/file_system/fileOpr`,
  2126. data: {opr: "move" ,src: JSON.stringify(fileList), dest: targetDir,existsresp: overwriteMode},
  2127. success: function(data){
  2128. if (data.error !== undefined){
  2129. msgbox("remove",data.error);
  2130. }else{
  2131. //OK
  2132. msgbox("checkmark",fileList.length + " objects moved.")
  2133. refreshList();
  2134. }
  2135. hideAllPopupWindows();
  2136. }
  2137. });
  2138. }else{
  2139. //Pass the request to operation handler
  2140. var oprConfig = {
  2141. opr: "move",
  2142. src: fileList,
  2143. dest: targetDir,
  2144. overwriteMode: overwriteMode,
  2145. callbackWindowID: ao_module_windowID,
  2146. callbackFunction: `callRefresh("${targetDir}")`
  2147. }
  2148. var configHash = encodeURIComponent(JSON.stringify(oprConfig));
  2149. var title = "Moving " + fileList.length;
  2150. if (fileList.length > 1){
  2151. title += " files";
  2152. }else{
  2153. title += " file";
  2154. }
  2155. parent.newFloatWindow({
  2156. url: "SystemAO/file_system/file_operation.html#" + configHash,
  2157. width: 400,
  2158. height: 220,
  2159. appicon: "SystemAO/file_system/img/selector.png",
  2160. title: title
  2161. });
  2162. hideAllPopupWindows();
  2163. }
  2164. }
  2165. }
  2166. });
  2167. }else{
  2168. //Copy and paste
  2169. //Check if the file list is OK for continue without the need for overwrite
  2170. $.ajax({
  2171. type: 'POST',
  2172. url: `../../system/file_system/validateFileOpr`,
  2173. data: {src: JSON.stringify(fileList), dest: targetDir},
  2174. success: function(data){
  2175. if (!nocheck && data !== null){
  2176. //There are problem with the copy target. Pop up overwrite rule selector
  2177. showDuplicateHandler(data);
  2178. }else{
  2179. //OK!
  2180. if (!ao_module_virtualDesktop){
  2181. $.ajax({
  2182. type: 'POST',
  2183. url: `../../system/file_system/fileOpr`,
  2184. data: {opr: "copy" ,src: JSON.stringify(fileList), dest: targetDir,existsresp: overwriteMode },
  2185. success: function(data){
  2186. if (data.error !== undefined){
  2187. msgbox("remove",data.error);
  2188. }else{
  2189. //OK
  2190. msgbox("checkmark",fileList.length + " objects copied.")
  2191. refreshList();
  2192. }
  2193. hideAllPopupWindows();
  2194. }
  2195. });
  2196. }else{
  2197. //Pass the request to operation handler
  2198. var oprConfig = {
  2199. opr: "copy",
  2200. src: fileList,
  2201. dest: targetDir,
  2202. overwriteMode: overwriteMode,
  2203. callbackWindowID: ao_module_windowID,
  2204. callbackFunction: `callRefresh("${targetDir}")`
  2205. }
  2206. var configHash = encodeURIComponent(JSON.stringify(oprConfig));
  2207. var title = "Copying " + fileList.length;
  2208. if (fileList.length > 1){
  2209. title += " files";
  2210. }else{
  2211. title += " file";
  2212. }
  2213. parent.newFloatWindow({
  2214. url: "SystemAO/file_system/file_operation.html#" + configHash,
  2215. width: 400,
  2216. height: 220,
  2217. appicon: "SystemAO/file_system/img/selector.png",
  2218. title: title
  2219. });
  2220. hideAllPopupWindows();
  2221. }
  2222. }
  2223. }
  2224. });
  2225. }
  2226. }
  2227. //Callback function for file operation display
  2228. window.callRefresh = function(targetdir){
  2229. console.log(currentPath, targetdir);
  2230. if (currentPath == targetdir){
  2231. refreshList();
  2232. }
  2233. }
  2234. //This action may duplicate files. Show handler
  2235. function showDuplicateHandler(duplicateFileList){
  2236. $(".popup").fadeOut(100);
  2237. var duplicatedFileCounts = duplicateFileList.length;
  2238. showPopupWrapper();
  2239. $("#overwriteModeSelection").fadeIn(100);
  2240. $("#overwriteModeSelection").find(".owm-fc").text(duplicatedFileCounts);
  2241. var srcpath = duplicateFileList[0];
  2242. srcpath = srcpath.split("/");
  2243. srcpath.pop();
  2244. srcpath = srcpath.join("/");
  2245. $("#overwriteModeSelection").find(".owm-srcdir").text(srcpath);
  2246. $("#overwriteModeSelection").find(".owm-destdir").text(currentPath);
  2247. }
  2248. //Force delete. Use normal delete fucntion if you want to move things to recycle bin instead.
  2249. let forceDeleteList = [];
  2250. function forceDelete(confirmed=false){
  2251. if (confirmed == false){
  2252. //Show confirm box
  2253. let deletePendingList = [];
  2254. var listObject = $("#forceDeleteConfirmBox").find(".deleteFilelist")[0];
  2255. $(listObject).html("");
  2256. $(".selected.fileObject").each(function(data){
  2257. var thispath = $(this).attr("filepath");
  2258. var thisfilename = $(this).attr("filename");
  2259. var ext = thisfilename.split(".").pop();
  2260. var icon = ao_module_utils.getIconFromExt(ext);
  2261. deletePendingList.push(thispath);
  2262. $(listObject).append(`<div class="item ${currentTheme}" ><span style="display:inline-block;">${thisfilename}</span></div>`);
  2263. });
  2264. showPopupWrapper();
  2265. $("#forceDeleteConfirmBox").fadeIn(100);
  2266. forceDeleteList = deletePendingList;
  2267. }else{
  2268. //Start force delete function
  2269. $("#forceDeleteConfirmBox").fadeOut(100);
  2270. let fdlistLength = forceDeleteList.length;
  2271. $.ajax({
  2272. url: "../../system/file_system/fileOpr",
  2273. method:"POST",
  2274. data: {opr: "delete", src: JSON.stringify(forceDeleteList)},
  2275. success: function(data){
  2276. if (data.error !== undefined){
  2277. msgbox("caution",data.error);
  2278. }else{
  2279. refreshList();
  2280. msgbox("checkmark",fdlistLength + " objects removed.")
  2281. }
  2282. hideAllPopupWindows();
  2283. }
  2284. });
  2285. //Finishing up delete sequence
  2286. forceDeleteList = [];
  2287. }
  2288. }
  2289. let deleteFileList = [];
  2290. function deleteFile(confirmed = false){
  2291. if (!confirmed){
  2292. //Show the confirm dialog
  2293. $("#deleteConfirmBox").find(".deleteFilelist").html("");
  2294. $(".fileObject.selected").each(function(data){
  2295. var thisfilename = $(this).attr('filename');
  2296. var thisFilepath = $(this).attr('filepath');
  2297. deleteFileList.push(thisFilepath);
  2298. $("#deleteConfirmBox").find(".deleteFilelist").append(`<div class="item ${currentTheme}" ><span style="display:inline-block;">${thisfilename}</span></div>`);
  2299. });
  2300. if (deleteFileList.length == 0){
  2301. //No files selected
  2302. return;
  2303. }else{
  2304. //File selected. Continue to delete
  2305. showPopupWrapper();
  2306. $("#deleteConfirmBox").fadeIn(100);
  2307. }
  2308. }else{
  2309. //Continue to delete files
  2310. let fdlistLength = deleteFileList.length;
  2311. $.ajax({
  2312. url: "../../system/file_system/fileOpr",
  2313. method:"POST",
  2314. data: {opr: "recycle", src: JSON.stringify(deleteFileList)},
  2315. success: function(data){
  2316. if (data.error !== undefined){
  2317. msgbox("caution",data.error);
  2318. }else{
  2319. refreshList();
  2320. msgbox("checkmark",fdlistLength + " objects moved to trash bin.")
  2321. }
  2322. if (currentPath == "user:/"){
  2323. //Reload the User root folder list
  2324. initRootDirs();
  2325. }
  2326. }
  2327. });
  2328. console.log(deleteFileList);
  2329. deleteFileList = [];
  2330. hideAllPopupWindows();
  2331. }
  2332. }
  2333. function cancelDelete(){
  2334. deleteFileList=[];
  2335. }
  2336. function cancelForceDelete(){
  2337. $("#forceDeleteConfirmBox").fadeOut(100);
  2338. forceDeleteList = [];
  2339. }
  2340. function upload(){
  2341. var input = document.createElement('input');
  2342. input.type = 'file';
  2343. input.multiple = true;
  2344. input.onchange = e => {
  2345. var files = e.target.files;
  2346. msgbox("upload","Upload Started");
  2347. for (var i = 0; i < files.length; i++){
  2348. uploadFile(files[i]);
  2349. }
  2350. }
  2351. input.click();
  2352. }
  2353. function updatePathDisplay(path){
  2354. var pathInfo = path.split("/");
  2355. var vdID = pathInfo[0];
  2356. //As path always end with /, pop the empty pathinfo from array
  2357. pathInfo.pop();
  2358. var l = pathInfo.length;
  2359. //Append the starting vdir
  2360. $(".pathDisplay").html("");
  2361. $(".pathDisplay").append(`<div class="section ${currentTheme} selectable" onclick="rootDir();"><i class="folder icon"></i> ${vdID}</div>`);
  2362. $(".pathDisplay").append(`<div class="divider ${currentTheme} whiteTheme">/</div>`);
  2363. //console.log(pathInfo);
  2364. if (l > 3){
  2365. //E.g. user:/Desktop/test/boo/ => Display as user:/.../test/boo/
  2366. $(".pathDisplay").append(`<div class="section ${currentTheme}">...</div>`);
  2367. $(".pathDisplay").append(`<div class="divider ${currentTheme} whiteTheme">/</div>`);
  2368. $(".pathDisplay").append(`<div class="section ${currentTheme} selectable" onclick="parentDir();">${shortenLongFoldername(pathInfo[l-2], 40)}</div>`);
  2369. $(".pathDisplay").append(`<div class="divider ${currentTheme} whiteTheme">/</div>`);
  2370. $(".pathDisplay").append(`<div class="section ${currentTheme} selectable" onclick="refreshList();">${shortenLongFoldername(pathInfo[l-1], 60)}</div>`);
  2371. }else if (l == 3){
  2372. $(".pathDisplay").append(`<div class="section ${currentTheme} selectable" onclick="parentDir();">${shortenLongFoldername(pathInfo[l-2], 40)}</div>`);
  2373. $(".pathDisplay").append(`<div class="divider ${currentTheme} whiteTheme">/</div>`);
  2374. $(".pathDisplay").append(`<div class="section ${currentTheme} selectable" onclick="refreshList();">${shortenLongFoldername(pathInfo[l-1], 60)}</div>`);
  2375. }else if (l == 2){
  2376. //E.g. user:/Desktop or user:/
  2377. $(".pathDisplay").append(`<div class="section ${currentTheme} selectable" onclick="refreshList();">${shortenLongFoldername(pathInfo[1], 80)}</div>`);
  2378. }
  2379. }
  2380. function shortenLongFoldername(name, maxchar = 20){
  2381. var resultname = name;
  2382. if (name.length > maxchar){
  2383. //Shorten it
  2384. var offset = parseInt((maxchar - 2) / 2);
  2385. resultname = name.substr(0, offset) + "..." + name.substr(name.length - offset)
  2386. }
  2387. return resultname
  2388. }
  2389. function getExtFromPath(path){
  2390. if (path.includes(".") == false){
  2391. return "";
  2392. }
  2393. return path.split(".").pop();
  2394. }
  2395. function getFileObjectFromFID(fid){
  2396. var targetFileObject = null;
  2397. $(".fileObject").each(function(){
  2398. if ($(this).attr("fileid") == fid){
  2399. targetFileObject = $(this);
  2400. }
  2401. });
  2402. return targetFileObject;
  2403. }
  2404. function openViaButton(){
  2405. let fileOpenList = [];
  2406. let foldersToBeOpened=[];
  2407. $(".fileObject.selected").each(function(){
  2408. let type = $(this).attr("type");
  2409. let filepath = $(this).attr("filepath");
  2410. if (type == "file"){
  2411. fileOpenList.push(filepath);
  2412. }else if (type == "folder"){
  2413. foldersToBeOpened.push(filepath);
  2414. }
  2415. });
  2416. //Open files
  2417. openPathWithDefaultOpener(fileOpenList);
  2418. //Open folders
  2419. openFolderInNewWindow(foldersToBeOpened);
  2420. }
  2421. function openthis(object,evt=null){
  2422. if (evt !== null){
  2423. evt.preventDefault();
  2424. }
  2425. var objType = $(object).attr("type");
  2426. if ( objType == "file"){
  2427. //Open this file. Generate the access path from filepath
  2428. var filepath = $(object).attr("filepath");
  2429. //Only one path to be opened. Pass in as a single object array
  2430. openPathWithDefaultOpener([filepath]);
  2431. }else if (objType == "folder"){
  2432. //Open this folder
  2433. var folderPath = $(object).attr('filepath');
  2434. listDirectory(folderPath, function(){
  2435. //Scroll to top of the list
  2436. $("#folderView").stop().finish().animate({
  2437. scrollTop: 0
  2438. }, 300);
  2439. if ($(object).hasClass('dir') && isMobile){
  2440. toggleSidebar();
  2441. }
  2442. });
  2443. }else if (objType == "shortcut"){
  2444. //Load the shortcut information
  2445. getShortcutInfo($(object).attr('filepath'), function(shortcutInfo){
  2446. /*
  2447. Shortcut Info format
  2448. 0: Shortcut type
  2449. 1: Shortcut Name
  2450. 2: Shortcut target
  2451. 3: Shortcut icon image
  2452. */
  2453. if (shortcutInfo[0] == "module"){
  2454. //This is a module
  2455. if (ao_module_virtualDesktop){
  2456. //Open Module with VDI API
  2457. parent.openModule(shortcutInfo[2]);
  2458. }else{
  2459. //Open module in new tab
  2460. $.get("../../system/modules/getLaunchPara?module=" + shortcutInfo[2], function(data) {
  2461. window.open("../../" + data.StartDir);
  2462. });
  2463. }
  2464. }else if (shortcutInfo[0] == "folder"){
  2465. //This is a folder
  2466. listDirectory(shortcutInfo[2]);
  2467. }else if (shortcutInfo[0] == "url"){
  2468. //This is a url shortcut
  2469. window.open(shortcutInfo[2]);
  2470. }
  2471. console.log(shortcutInfo);
  2472. });
  2473. }
  2474. //Check if this opened in sidebar and in mobile mode. Close sidebar if yes
  2475. }
  2476. /*
  2477. Shortcut Info format
  2478. 0: Shortcut type
  2479. 1: Shortcut Name
  2480. 2: Shortcut target
  2481. 3: Shortcut icon image
  2482. */
  2483. function getShortcutInfo(filepath, callback){
  2484. $.get("../../media?file=" + filepath, function(data){
  2485. //This return the shortcut information. Split it and see what shortcut is this
  2486. data = data.split("\r\n").join("\n");
  2487. var shortcutInfo = data.trim().split("\n");
  2488. callback(shortcutInfo);
  2489. });
  2490. }
  2491. //Download the selected files.
  2492. function downloadFile(){
  2493. var fileList = [];
  2494. if ($(".fileObject.selected").length == 1 && $(".fileObject.selected").attr("type") == "file"){
  2495. //One file. Download directly.
  2496. var downloadURL = "/media?file=" + encodeURIComponent($(".fileObject.selected").attr("filepath")) + "&download=true";
  2497. var filename = $(".fileObject.selected").attr("filename");
  2498. generateDownloadFromURL(downloadURL,escape(filename));
  2499. }else if ($(".fileObject.selected").length > 1 || ($(".fileObject.selected").length == 1 && $(".fileObject.selected").attr("type") == "folder")){
  2500. //Do zip and download for multiple files
  2501. $(".fileObject.selected").each(function(){
  2502. fileList.push($(this).attr("filepath"));
  2503. });
  2504. console.log(fileList);
  2505. //Zip the file or folder
  2506. $.ajax({
  2507. url: "../../system/file_system/zipHandler",
  2508. data: {opr: "tmpzip", src: JSON.stringify(fileList), dest: ""},
  2509. method: "POST",
  2510. success: function(data){
  2511. if (data.error !== undefined){
  2512. alert(data.error);
  2513. }else{
  2514. //Zip completed.
  2515. window.open("../../media?file=" + data + "&download=true");
  2516. }
  2517. }
  2518. });
  2519. }else{
  2520. alert("No file selected!")
  2521. }
  2522. }
  2523. //Create a new file
  2524. function newfile(){
  2525. $(".popup").fadeOut('fast');
  2526. showPopupWrapper();
  2527. $("#newFile").fadeIn('fast');
  2528. $("#newFile").find(".duplicateWarning").hide();
  2529. $("#createNewFileName").parent().removeClass("error");
  2530. //Update the newfile list
  2531. $("#newFile").find(".newfilelist").html("");
  2532. $.ajax({
  2533. url: "../../system/file_system/newItem",
  2534. success: function(data){
  2535. if (data.error !== undefined){
  2536. return;
  2537. }
  2538. for (var i =0; i < data.length; i++){
  2539. var desc = data[i].Desc;
  2540. var ext = data[i].Ext;
  2541. var icon = ao_module_utils.getIconFromExt(ext);
  2542. $("#newFile").find(".newfilelist").append(`<div class="item newFileFormat" ext="${ext}"><i class="${icon} icon" style="margin-right:12px;"></i> ${desc}</div>`);
  2543. }
  2544. //Initialize the new file as txt
  2545. var filename = "newfile";
  2546. var finalFilename = filename;
  2547. var i = 0;
  2548. while (currentFilelist.includes(finalFilename)){
  2549. finalFilename = finalFilename + "(" + i + ")";
  2550. i++;
  2551. }
  2552. $("#createNewFileName").val(finalFilename + ".txt");
  2553. //Hook events for on click
  2554. $(".newFileFormat").off("click").on("click",function(data){
  2555. $(".newFileFormat").removeClass("selected");
  2556. $(this).addClass("selected");
  2557. //Parse the newfilename
  2558. var selectedExt = $(this).attr("ext");
  2559. var filename = "newfile";
  2560. var finalFilename = filename;
  2561. var i = 0;
  2562. while (currentFilelist.includes(finalFilename)){
  2563. finalFilename = finalFilename + "(" + i + ")";
  2564. i++;
  2565. }
  2566. $("#createNewFileName").val(filename + "." + selectedExt);
  2567. });
  2568. }
  2569. });
  2570. }
  2571. function filePermission(){
  2572. //Open file permission window
  2573. if ($(".fileObject.selected").length > 0){
  2574. //Build the filelist
  2575. var fileList = [];
  2576. $(".fileObject.selected").each(function(){
  2577. var filepath = $(this).attr("filepath");
  2578. fileList.push(filepath);
  2579. });
  2580. var hashPassthrough = encodeURIComponent(JSON.stringify(fileList));
  2581. ao_module_newfw({
  2582. url: "SystemAO/file_system/file_permission.html#" + hashPassthrough,
  2583. width: 340,
  2584. height: 480,
  2585. appicon: "SystemAO/file_system/img/properties.png",
  2586. title: "File Permissions",
  2587. })
  2588. }
  2589. }
  2590. function newFolder(confirmed = false){
  2591. if (confirmed == false){
  2592. //Launch the dialog for newFolder
  2593. $(".popup").fadeOut(100);
  2594. $("#createNewFolder").val("");
  2595. $("#createNewFolder").parent().removeClass("error").removeClass("success");
  2596. $("#newFolder").find(".duplicateWarning").hide();
  2597. showPopupWrapper();
  2598. $("#newFolder").fadeIn(100);
  2599. }else{
  2600. //Create new folder
  2601. var newFoldername = $("#createNewFolder").val();
  2602. if (newFoldername == ""){
  2603. $("#createNewFolder").parent().addClass("error");
  2604. return;
  2605. }
  2606. if (currentFilelist.includes(newFoldername)){
  2607. //Current filelist already contain a folder with the same name
  2608. $("#createNewFolder").parent().addClass("error");
  2609. $("#newFolder").find(".duplicateWarning").show();
  2610. return;
  2611. }
  2612. //OK to proceed.
  2613. $("#createNewFolder").parent().removeClass("error").addClass("success");
  2614. $("#newFolder").find(".duplicateWarning").hide();
  2615. $.ajax({
  2616. url: "../../system/file_system/newItem",
  2617. data: {type: "folder", src: currentPath, filename: newFoldername},
  2618. success: function(data){
  2619. if (data.error !== undefined){
  2620. msgbox("remove", data.error);
  2621. }else{
  2622. msgbox("checkmark","New folder created.");
  2623. refreshList();
  2624. }
  2625. $("#newFolder").fadeOut('fast');
  2626. hideAllPopupWindows();
  2627. if (currentPath == "user:/"){
  2628. //Reload the User root folder list
  2629. initRootDirs();
  2630. }
  2631. }
  2632. });
  2633. }
  2634. }
  2635. function confirmNewFile(){
  2636. var filename = $("#createNewFileName").val();
  2637. if (filename == ""){
  2638. //Filename not set
  2639. $("#createNewFileName").parent().addClass("error");
  2640. return;
  2641. }else if(currentFilelist.includes(filename)){
  2642. //File with this name already exists
  2643. $("#createNewFileName").parent().addClass("error");
  2644. $("#newFile").find(".duplicateWarning").show();
  2645. return;
  2646. }
  2647. $("#createNewFileName").parent().removeClass("error");
  2648. //Ok to proceed
  2649. $.ajax({
  2650. url: "../../system/file_system/newItem",
  2651. data: {type: "file", src: currentPath, filename:filename},
  2652. success: function(data){
  2653. if (data.error !== undefined){
  2654. msgbox("remove",data.error);
  2655. }else{
  2656. msgbox("checkmark",filename + " created.");
  2657. refreshList();
  2658. }
  2659. }
  2660. });
  2661. hideAllPopupWindows();
  2662. $("#newFile").fadeOut('fast');
  2663. }
  2664. //Open File Location
  2665. function openFileLocation(){
  2666. var folders = [];
  2667. $(".selected.fileObject").each(function(){
  2668. var thisFilepath = $(this).attr('filepath');
  2669. var thisFilename = $(this).attr('filename');
  2670. openPathInNewWindow(encodeURIComponent(JSON.stringify([{
  2671. filename: thisFilename,
  2672. filepath: thisFilepath
  2673. }])))
  2674. });
  2675. }
  2676. //OpenWith dialog
  2677. function openWith(){
  2678. if ($(".selected.fileObject").length == 0){
  2679. msgbox("question","No file selected");
  2680. return;
  2681. }
  2682. //Get a list of modules and append it into the selection list
  2683. $.get("../../system/modules/list",function(data){
  2684. if (data.error !== undefined){
  2685. console.log(data.error);
  2686. }else{
  2687. $("#openWithModuleList").html("");
  2688. for (var i =0; i < data.length; i++){
  2689. var thisModule = data[i];
  2690. var supportFW = `<div class="ts horizontal mini label"><i class="checkmark icon"></i>floatWindow Window</div>`;
  2691. var supportEmb = `<div class="ts horizontal mini label"><i class="checkmark icon"></i>Embedded Window</div>`;
  2692. if (!thisModule.SupportFW){
  2693. supportFW = "";
  2694. }
  2695. if (!thisModule.LaunchEmb){
  2696. supportEmb = "";
  2697. }
  2698. var launchInfo = encodeURIComponent(JSON.stringify(thisModule));
  2699. $("#openWithModuleList").append(`<div class="item selectable openWithModule" launchInfo="${launchInfo}" onclick="selectOpenWithModule(this, event);" ondblclick="selectOpenWithModule(this, event); openWithSelectedModule();">
  2700. <img class="ts avatar image" src="../../${thisModule.IconPath}">
  2701. <div class="content" style="padding-left:12px;">
  2702. <div class="header">${thisModule.Name}</div>
  2703. <div class="description">
  2704. ${supportFW}
  2705. ${supportEmb}
  2706. </div>
  2707. </div>
  2708. </div>`);
  2709. }
  2710. }
  2711. });
  2712. $(".openWithModule.popupbuttons").addClass("disabled");
  2713. if (!ao_module_virtualDesktop){
  2714. $("#openWith").find(".vdonly").hide();
  2715. }
  2716. showPopupWrapper();
  2717. $("#openWith").fadeIn('fast');
  2718. }
  2719. //Functions for handling open with module selection and file opening
  2720. function selectOpenWithModule(object, event){
  2721. event.preventDefault();
  2722. $(".openWithModule.popupbuttons").removeClass("disabled");
  2723. $(".openWithModule.selected").removeClass("selected");
  2724. $(object).addClass("selected");
  2725. }
  2726. function openWithSelectedModule(btn){
  2727. if ($(btn).hasClass("disabled")){
  2728. return false;
  2729. }
  2730. var targetModuleInfo = JSON.parse(decodeURIComponent($(".openWithModule.selected").attr("launchInfo")));
  2731. var targetObjects = $(".selected.fileObject");
  2732. console.log(targetModuleInfo);
  2733. //Phrase launch mode from the module info
  2734. var launchURL = targetModuleInfo.StartDir
  2735. var launchSize = [undefined, undefined];
  2736. var iconPath = targetModuleInfo.IconPath;
  2737. var title = targetModuleInfo.Name;
  2738. if (targetModuleInfo.SupportEmb){
  2739. //Launch with embedded mode
  2740. launchURL = targetModuleInfo.LaunchEmb;
  2741. if (targetModuleInfo.InitEmbSize !== null){
  2742. launchSize = targetModuleInfo.InitEmbSize
  2743. }
  2744. }else if (targetModuleInfo.SupportFW){
  2745. //Launch with floatWindow mode
  2746. launchURL = targetModuleInfo.LaunchFWDir;
  2747. if (targetModuleInfo.InitFWSize !== null){
  2748. launchSize = targetModuleInfo.InitFWSize
  2749. }
  2750. }else if (targetModuleInfo.StartDir !== ""){
  2751. //Launch with default mode
  2752. }else{
  2753. msgbox("remove","This module has no endpoint for opening a file.");
  2754. return;
  2755. }
  2756. //Parse the filelist
  2757. var filelist = [];
  2758. $(targetObjects).each(function(){
  2759. var filename = $(this).attr("filename");
  2760. var filepath = $(this).attr("filepath");
  2761. filelist.push({
  2762. filename: filename,
  2763. filepath: filepath
  2764. });
  2765. });
  2766. fileHash = encodeURIComponent(JSON.stringify(filelist));
  2767. if (ao_module_virtualDesktop){
  2768. //Open the target module in a new fw
  2769. parent.newFloatWindow({
  2770. url: launchURL + "#" + fileHash,
  2771. width: launchSize[0],
  2772. height: launchSize[1],
  2773. appicon: iconPath,
  2774. title: title
  2775. });
  2776. }else{
  2777. //Redirect current window to the target module
  2778. window.location.href = "../../" + launchURL + "#" + fileHash;
  2779. }
  2780. hideAllPopupWindows();
  2781. }
  2782. function openFileWithModuleInNewTab(btn){
  2783. if ($(btn).hasClass("disabled")){
  2784. return false;
  2785. }
  2786. var targetModuleInfo = JSON.parse(decodeURIComponent($(".openWithModule.selected").attr("launchInfo")));
  2787. var targetObjects = $(".selected.fileObject");
  2788. //Parse the filelist
  2789. var filelist = [];
  2790. $(targetObjects).each(function(){
  2791. var filename = $(this).attr("filename");
  2792. var filepath = $(this).attr("filepath");
  2793. filelist.push({
  2794. filename: filename,
  2795. filepath: filepath
  2796. });
  2797. });
  2798. //Directly passing the file information to the startdir
  2799. fileHash = encodeURIComponent(JSON.stringify(filelist));
  2800. window.open("../../" + targetModuleInfo.StartDir + "#" + fileHash);
  2801. hideAllPopupWindows();
  2802. }
  2803. function openRawFileInFloatWindow(btn){
  2804. //Directly open this (or more than one) files / folder in floatWindow
  2805. var targetObjects = $(".selected.fileObject");
  2806. $(targetObjects).each(function(){
  2807. if ($(this).attr("type") == "file"){
  2808. var launchURL = "media?file=" + $(this).attr('filepath');
  2809. parent.newFloatWindow({
  2810. url: launchURL,
  2811. appicon: "img/system/file.png",
  2812. title: $(this).attr('filename'),
  2813. "background-color": "#1f1f1f"
  2814. });
  2815. }else if ($(this).attr("type") == "folder"){
  2816. var launchURL = "SystemAO/file_system/file_explorer.html#" + $(this).attr("filepath");
  2817. parent.newFloatWindow({
  2818. url: launchURL,
  2819. appicon: "SystemAO/file_system/img/small_icon.png",
  2820. title: "File Manager - " + $(this).attr('filename'),
  2821. });
  2822. }else{
  2823. //Not supported openeing type.
  2824. console.log("Failed to open file " + $(this).attr('filepath') + " . WIP")
  2825. }
  2826. });
  2827. hideAllPopupWindows();
  2828. }
  2829. //Open the filepaths in the given paramters
  2830. function openPathWithDefaultOpener(filepaths){
  2831. console.log("Opening: ", filepaths);
  2832. for (var i =0; i < filepaths.length; i++){
  2833. let filepath = JSON.parse(JSON.stringify(filepaths[i]));
  2834. var ext = "." + filepath.split(".").pop();
  2835. $.ajax({
  2836. url: "../../system/modules/getDefault",
  2837. method: "GET",
  2838. data: {opr: "launch", ext: ext, mode: "launch"},
  2839. success: function(data){
  2840. if (data.error !== undefined){
  2841. //No default opener assigned. Launch it with opener selector
  2842. var url = "SystemAO/file_system/defaultOpener.html";
  2843. var icon = "SystemAO/file_system/img/opener.png";
  2844. var title = "Select an opener WebApp: "
  2845. var openFileList = [];
  2846. var openFileObject = {
  2847. filepath: filepath,
  2848. filename: filepath.split("/").pop()
  2849. }
  2850. openFileList.push(openFileObject);
  2851. var openParamter = encodeURIComponent(JSON.stringify(openFileObject));
  2852. var ao_module_virtualDesktop = !(!parent.isDesktopMode);
  2853. console.log(window.innerHeight/2 - 510/20);
  2854. if (ao_module_virtualDesktop){
  2855. parent.newFloatWindow({
  2856. url: url + "#" + openParamter,
  2857. width: 320,
  2858. height: 510,
  2859. appicon: icon,
  2860. title: title
  2861. });
  2862. }else{
  2863. url = "defaultOpener.html";
  2864. window.open(url + "#" + openParamter);
  2865. }
  2866. }else{
  2867. //Assigned. Launch with given paramter
  2868. var url = data["StartDir"];
  2869. var size = [undefined, undefined];
  2870. var title = data["Name"];
  2871. var icon = "img/system/favicon.png";
  2872. if (data["IconPath"] != ""){
  2873. icon = data["IconPath"];
  2874. }
  2875. //Use floatWindow if exists
  2876. if (data["SupportFW"] == true && data["LaunchFWDir"] != ""){
  2877. url = data["LaunchFWDir"];
  2878. if (data["InitFWSize"] !== null){
  2879. size = data["InitFWSize"]
  2880. }
  2881. }
  2882. //Use embedded mode if exists
  2883. if (data["SupportEmb"] == true && data["LaunchEmb"] != ""){
  2884. url = data["LaunchEmb"];
  2885. if (data["InitEmbSize"] !== null){
  2886. size = data["InitEmbSize"]
  2887. }
  2888. }
  2889. //Build open File Hash Data Format
  2890. var openFileList = [];
  2891. var openFileObject = {
  2892. filepath: filepath,
  2893. filename: filepath.split("/").pop()
  2894. }
  2895. openFileList.push(openFileObject);
  2896. var openParamter = encodeURIComponent(JSON.stringify(openFileList));
  2897. //Add launch files info and launch floatWindow
  2898. var ao_module_virtualDesktop = !(!parent.isDesktopMode);
  2899. if (ao_module_virtualDesktop){
  2900. parent.newFloatWindow({
  2901. url: url + "#" + openParamter,
  2902. width: size[0],
  2903. height: size[1],
  2904. appicon: icon,
  2905. title: title
  2906. });
  2907. }else{
  2908. window.open("../../" + url + "#" + openParamter);
  2909. }
  2910. }
  2911. }
  2912. });
  2913. }
  2914. }
  2915. function openSelectedFolderInNewWindow(){
  2916. $(".fileObject.selected").each(function(){
  2917. if ($(this).attr("type") == "folder"){
  2918. console.log($(this).attr('filepath'));
  2919. openPathInNewWindow([$(this).attr('filepath')]);
  2920. }
  2921. })
  2922. }
  2923. //Always open the first object locally, and open others in new floatWindows
  2924. function openFolderInNewWindow(paths){
  2925. if (paths.length > 0){
  2926. listDirectory(paths[0]);
  2927. for (var i = 1; i < paths.length; i++){
  2928. //newFloatWindow(location.href.replace(location.hash,"") + "#" + path[i])
  2929. openPathInNewWindow(paths[i]);
  2930. }
  2931. }
  2932. }
  2933. function openPathInNewWindow(path){
  2934. console.log("Opening in new File Maanger: ", window.location.pathname + "#" + path);
  2935. ao_module_newfw({
  2936. url: window.location.pathname + "#" + path,
  2937. appicon: "SystemAO/file_system/img/small_icon.png",
  2938. title: "File Manager",
  2939. width: 1080,
  2940. height: 580,
  2941. parent: ao_module_windowID,
  2942. });
  2943. }
  2944. //Preference setting and loading functions.
  2945. function setPreference(key, value){
  2946. $.ajax({
  2947. url:"../../system/file_system/preference?key=" + key + "&value=" + value,
  2948. success: function(data){
  2949. if (data.error !== undefined){
  2950. console.log(data);
  2951. }
  2952. }
  2953. });
  2954. }
  2955. function loadPreference(key, callback){
  2956. $.get("../../system/file_system/preference?key=" + key,function(data){
  2957. callback(data);
  2958. });
  2959. }
  2960. // ============================== WINDOW RESIZE FUNCTIONS =====================
  2961. $(document).ready(function(data){
  2962. if (window.innerWidth < 620 && !isMobile){
  2963. toggleSidebar(false);
  2964. }
  2965. initWindowSizes(false);
  2966. });
  2967. $(window).on("resize",function(){
  2968. initWindowSizes(false);
  2969. if (!isMobile && window.innerWidth < 620 && sideBarShown == true){
  2970. toggleSidebar(false);
  2971. }else if (!isMobile && window.innerWidth > 650 && sideBarShown == false){
  2972. toggleSidebar(false);
  2973. }
  2974. if (isMobile){
  2975. refreshList();
  2976. }
  2977. });
  2978. function handleShareFilebuttonClick(event, object){
  2979. event.preventDefault();
  2980. event.stopImmediatePropagation();
  2981. $(".fileObject.selected").removeClass("selected");
  2982. if (viewMode == "list"){
  2983. $(object).parent().parent().addClass("selected");
  2984. }else if (viewMode == "grid"){
  2985. $(object).parent().parent().parent().addClass("selected");
  2986. }
  2987. shareFile();
  2988. }
  2989. function shareFile(){
  2990. var selectedFiles = [];
  2991. $(".fileObject.selected").each(function(){
  2992. var thisFilepath = $(this).attr("filepath");
  2993. selectedFiles.push(thisFilepath);
  2994. });
  2995. if (selectedFiles.length != 1){
  2996. //Try to share more than 1 files, which is not supported
  2997. console.log("Multi share is current not supported");
  2998. return
  2999. }
  3000. //OK! Continue to generate link
  3001. var selectedFile = selectedFiles[0];
  3002. shareEditingObject = selectedFile;
  3003. $.ajax({
  3004. url: "../../system/file_system/share/new",
  3005. data: {path: selectedFile},
  3006. success: function(data){
  3007. if (data.error !== undefined){
  3008. alert(data.error);
  3009. }else{
  3010. //Build the predicted share endpoint
  3011. let protocol = "https://";
  3012. if (location.protocol !== 'https:') {
  3013. protocol = "http://";
  3014. }
  3015. //Continue to render QR Code and UI contents
  3016. $("#qrcode").html("");
  3017. var shareURL = protocol + window.location.hostname + ":" + window.location.port + "/share?id=" + data.UUID;
  3018. shareEditingUUID = data.UUID;
  3019. new QRCode(document.getElementById("qrcode"), shareURL);
  3020. $("#sharelink").text(shareURL);
  3021. $("#sharelink").attr("href", shareURL);
  3022. $(".shareoption").parent().removeClass("disabled");
  3023. $("#sharingRemoveBtn").show();
  3024. //Check the correct checkbox
  3025. var tagetCheckbox = data.Permission;
  3026. if (tagetCheckbox == "anyone"){
  3027. $("#anyone")[0].checked = true;
  3028. }else if (tagetCheckbox == "signedin"){
  3029. $("#signedin")[0].checked = true;
  3030. }else if (tagetCheckbox == "samegroup"){
  3031. $("#samegroup")[0].checked = true;
  3032. }
  3033. //Show the share file interface
  3034. $(".popup").fadeOut('fast');
  3035. showPopupWrapper();
  3036. $("#shareFile").fadeIn("fast");
  3037. //Reload the list
  3038. listDirectory(currentPath);
  3039. }
  3040. }
  3041. });
  3042. }
  3043. function removeSharing(){
  3044. if (shareEditingObject == ""){
  3045. return
  3046. }
  3047. //The target file to remove
  3048. var selectedFile = shareEditingObject;
  3049. $.ajax({
  3050. url: "../../system/file_system/share/delete",
  3051. data: {path: selectedFile},
  3052. success: function(data){
  3053. console.log(data);
  3054. $("#qrcode").html(`<img src="img/private.png">`);
  3055. $(".shareoption").parent().addClass("disabled");
  3056. $("#sharelink").text("(Sharing Removed)");
  3057. $("#sharelink").removeAttr("href");
  3058. $("#sharingRemoveBtn").hide();
  3059. //Reload the current filelist and hide the share interface
  3060. listDirectory(currentPath);
  3061. //Reset sharing file settings
  3062. shareEditingObject = ""
  3063. shareEditingUUID = ""
  3064. }
  3065. });
  3066. }
  3067. function updateShareSettings(object){
  3068. $(object).addClass("loading");
  3069. var shareMode = $("#shareSettingForm [name='shareopt']:checked").val();
  3070. $.ajax({
  3071. url: "../../system/file_system/share/edit",
  3072. data: {uuid: shareEditingUUID, mode: shareMode},
  3073. success: function(data){
  3074. if (data.error !== undefined){
  3075. alert(data.error);
  3076. }
  3077. $(object).removeClass("loading");
  3078. $(object).html(`<i class="checkmark icon"></i> Updated`);
  3079. $(object).addClass("positive");
  3080. setTimeout(function(){
  3081. $(object).html("Update");
  3082. $(object).removeClass("positive");
  3083. }, 3000);
  3084. }
  3085. })
  3086. }
  3087. function hideShare(){
  3088. hideAllPopupWindows();
  3089. }
  3090. function toggleSidebar(useAnimation=true){
  3091. //Fixing desktop bugs on showing the sidebar
  3092. if (isMobile){
  3093. $("#directorySidebar").stop().finish().animate({left: "toggle"},200);
  3094. }else{
  3095. if ($("#directorySidebar").offset().left < 0){
  3096. $("#directorySidebar").stop().finish().animate({left: 0},200);
  3097. }else{
  3098. $("#directorySidebar").stop().finish().animate({left: -1 * directorySidebarWidth},200);
  3099. }
  3100. }
  3101. sideBarShown = !sideBarShown;
  3102. initWindowSizes(useAnimation);
  3103. }
  3104. function initWindowSizes(animate=true){
  3105. var h = $("#navibar").css("height");
  3106. var hint = $("#navibar").height();
  3107. //$("#mainWindow").css("padding-top",h);
  3108. var windowHeight = window.innerHeight - hint - 12;
  3109. //console.log(windowHeight);
  3110. if (sideBarShown){
  3111. //Resize the sidebar
  3112. $("#directorySidebar").css("top",h);
  3113. $("#directorySidebar").css("width",directorySidebarWidth);
  3114. $("#directorySidebar").css("height",windowHeight + "px");
  3115. //Resize the file viewer
  3116. $("#folderView").css("top",h);
  3117. if (window.innerWidth > 650){
  3118. if (animate){
  3119. $("#folderView").stop().finish().animate({
  3120. left: directorySidebarWidth + 'px',
  3121. width: window.innerWidth - directorySidebarWidth - 2 + "px"
  3122. },200);
  3123. }else{
  3124. $("#folderView").css({
  3125. left: directorySidebarWidth + 'px',
  3126. width: window.innerWidth - directorySidebarWidth - 2 + "px"
  3127. });
  3128. }
  3129. }else{
  3130. //Window width too small to allow resizing sidebar shown. Overlap it
  3131. if (animate){
  3132. $("#folderView").stop().finish().animate({
  3133. left: directorySidebarWidth + 'px',
  3134. width: window.innerWidth + "px"
  3135. },200);
  3136. }else{
  3137. $("#folderView").css({
  3138. left: directorySidebarWidth + 'px',
  3139. width: window.innerWidth + "px"
  3140. });
  3141. }
  3142. }
  3143. if (isChromium){
  3144. //$("#mainWindow").css("height", window.innerWidth);
  3145. }
  3146. //$("#folderView").css("left",directorySidebarWidth + "px");
  3147. $("#folderView").css("height",windowHeight + "px");
  3148. }else{
  3149. $("#folderView").css("top",h);
  3150. if (animate){
  3151. $("#folderView").stop().finish().animate({
  3152. left:'0px',
  3153. width:(window.innerWidth - 2 + "px")
  3154. },200);
  3155. }else{
  3156. $("#folderView").css({
  3157. left:'0px',
  3158. width:(window.innerWidth - 2 + "px")
  3159. });
  3160. }
  3161. $("#folderView").css("height",windowHeight + "px");
  3162. }
  3163. }
  3164. function toggleDarkTheme(){
  3165. if ($(".darkTheme").length > 0){
  3166. //Set To Whitetheme
  3167. $(".darkTheme").removeClass("darkTheme").addClass("whiteTheme");
  3168. currentTheme = "whiteTheme";
  3169. $("#darkthemebtn").attr("class","moon icon");
  3170. $("#darkthemebtn").parent().addClass("inverted");
  3171. $(".dropdown").removeClass("inverted");
  3172. setPreference("file_explorer/theme","whiteTheme");
  3173. //If in vdi mode, update desktop's listMenu as well
  3174. if (ao_module_virtualDesktop){
  3175. parent.initTheme("whiteTheme");
  3176. }
  3177. }else{
  3178. //Set to DarkTheme
  3179. $(".whiteTheme").removeClass("whiteTheme").addClass("darkTheme");
  3180. currentTheme = "darkTheme";
  3181. $("#darkthemebtn").attr("class","sun icon");
  3182. $("#darkthemebtn").parent().removeClass("inverted");
  3183. $(".dropdown").addClass("inverted");
  3184. setPreference("file_explorer/theme","darkTheme");
  3185. //If in vdi mode, update desktop's listMenu as well
  3186. if (ao_module_virtualDesktop){
  3187. parent.initTheme("darkTheme");
  3188. }
  3189. }
  3190. }
  3191. function msgbox(icon, text){
  3192. $($(".msgbox").find("span")[0]).text(text);
  3193. $($(".msgbox").find("i")[0]).attr("class", icon + " icon");
  3194. $(".msgbox").stop().finish().slideDown('fast').delay(3000).slideUp('fast');
  3195. }
  3196. //Keyboard hotkey events
  3197. $(document).keydown(function(event){
  3198. if ($(':focus').is("input")){
  3199. //Do not block operations on input fields.
  3200. return;
  3201. }
  3202. if(event.which==17 || event.which == 91){
  3203. ctrlHold = true;
  3204. }else if (event.which == 16){
  3205. shiftHold = true;
  3206. }else if (event.which == 67 && ctrlHold == true){
  3207. //Ctrl + C
  3208. if (!$(".popup").is(":visible")){
  3209. event.preventDefault();
  3210. copy();
  3211. }
  3212. }else if (event.which == 88 && ctrlHold == true){
  3213. //Ctrl + X
  3214. if (!$(".popup").is(":visible")){
  3215. event.preventDefault();
  3216. cut();
  3217. }
  3218. }else if (event.which == 65 && ctrlHold == true){
  3219. //Ctrl + A
  3220. event.preventDefault();
  3221. $(".fileObject").addClass("selected");
  3222. }else if (event.which == 78 && shiftHold == true){
  3223. //Shift + N, Open new file manager window with current path
  3224. event.preventDefault();
  3225. openPathInNewWindow(currentPath);
  3226. }else if (event.which == 86 && ctrlHold == true){
  3227. if (!$(".popup").is(":visible")){
  3228. paste();
  3229. }
  3230. }else if (event.which == 46 && shiftHold == true){
  3231. //Shift + delete
  3232. forceDelete();
  3233. }else if (event.which == 46){
  3234. //Delete
  3235. deleteFile();
  3236. }else if (event.which == 38){
  3237. //Up Arrow
  3238. if ($(".popup:visible").length == 0){
  3239. //No popup visiable
  3240. if (ctrlHold == true){
  3241. //Parenet path
  3242. parentDir();
  3243. }else{
  3244. //Select the file on the upper
  3245. selectPreviousFile(event);
  3246. }
  3247. }
  3248. }else if (event.which == 40){
  3249. //Down arrow
  3250. if ($(".popup:visible").length == 0){
  3251. //No popup visiable
  3252. selectNextFile(event);
  3253. }
  3254. }else if (event.which == 39){
  3255. //Right arrow
  3256. if ($(".popup:visible").length == 0 && viewMode == "grid"){
  3257. //No popup visiable and grid mode
  3258. selectRightFile(event);
  3259. }
  3260. }else if (event.which == 37){
  3261. //Left arrow
  3262. if ($(".popup:visible").length == 0 && viewMode == "grid"){
  3263. //No popup visiable and grid mode
  3264. selectLeftFile(event);
  3265. }
  3266. }else if (event.which == 13){
  3267. //Enter key
  3268. if ($(".fileObject.selected").length > 0){
  3269. openViaButton();
  3270. }
  3271. }else if (event.which == 27){
  3272. //Esc key
  3273. hideAllPopupWindows();
  3274. $(".fileObject.selected").removeClass("selected");
  3275. }else{
  3276. //console.log(event.which);
  3277. }
  3278. });
  3279. $(document).keyup(function(event){
  3280. if(event.which==17 || event.which == 91){
  3281. ctrlHold = false;
  3282. }else if (event.which == 16){
  3283. shiftHold = false;
  3284. }
  3285. });
  3286. $("#directorySidebar").on("click",function(evt){
  3287. //Clear the button holding
  3288. $(".fileObject.selected").removeClass("selected");
  3289. shiftHold = false;
  3290. ctrlHold = false;
  3291. });
  3292. //Check if localstorage is availble
  3293. function lscheck(){
  3294. var test = 'test';
  3295. try {
  3296. localStorage.setItem(test, test);
  3297. localStorage.removeItem(test);
  3298. return true;
  3299. } catch(e) {
  3300. return false;
  3301. }
  3302. }
  3303. function selectNextFile(e){
  3304. e.preventDefault();
  3305. //Check if there are no selection. If yes, select the first file object
  3306. if ($(".fileObject.selected").length == 0 && $(".fileObject").length > 0){
  3307. //Select the first file object
  3308. $($(".fileObject")[0]).addClass("selected");
  3309. return
  3310. }else if ( $(".fileObject").length == 0){
  3311. //No file in this folder
  3312. return
  3313. }
  3314. //Already contain selected file on the interface. Seleect it
  3315. var baseObject = $($(".fileObject.selected")[0]);
  3316. if ($(".fileObject.selected").length > 1){
  3317. $(".fileObject.selected").removeClass("selected");
  3318. }
  3319. if (viewMode == "list"){
  3320. //Select the next file
  3321. var nextObject = $(".fileObject").eq( $(".fileObject").index( $(baseObject) ) + 1 );
  3322. if (nextObject.length > 0){
  3323. nextObject.addClass("selected");
  3324. scrollToFileObject(nextObject);
  3325. $(baseObject).removeClass("selected");
  3326. }
  3327. }else if (viewMode == "grid"){
  3328. var colobj = getFileObjectInTheSameCol(baseObject);
  3329. var nextObject = baseObject;
  3330. for (var i = 0; i < colobj.length; i++){
  3331. if ($(colobj[i]).hasClass("selected") && i != colobj.length - 1){
  3332. nextObject = colobj[i + 1];
  3333. }
  3334. }
  3335. $(baseObject).removeClass("selected");
  3336. nextObject.addClass("selected");
  3337. scrollToFileObject(nextObject);
  3338. }
  3339. }
  3340. function selectPreviousFile(e){
  3341. e.preventDefault();
  3342. //Check if there are no selection. If yes, select the first file object
  3343. if ($(".fileObject.selected").length == 0 && $(".fileObject").length > 0){
  3344. //Select the first file object
  3345. $($(".fileObject")[$(".fileObject").length - 1]).addClass("selected");
  3346. return
  3347. }else if ( $(".fileObject").length == 0){
  3348. //No file in this folder
  3349. return
  3350. }
  3351. var baseObject = $($(".fileObject.selected")[0]);
  3352. if ($(".fileObject.selected").length > 1){
  3353. $(".fileObject.selected").removeClass("selected");
  3354. }
  3355. if (viewMode == "list"){
  3356. //Select the previous file
  3357. if ($(".fileObject").index( $(baseObject) ) -1 < 0){
  3358. return;
  3359. }
  3360. var previousObject = $(".fileObject").eq( $(".fileObject").index( $(baseObject) ) -1 );
  3361. if (previousObject.length > 0){
  3362. previousObject.addClass("selected");
  3363. scrollToFileObject(previousObject);
  3364. $(baseObject).removeClass("selected");
  3365. }
  3366. }else if (viewMode == "grid"){
  3367. var colobj = getFileObjectInTheSameCol(baseObject);
  3368. var prevObj = baseObject;
  3369. for (var i = 0; i < colobj.length; i++){
  3370. if ($(colobj[i]).hasClass("selected") && i > 0){
  3371. prevObj = colobj[i - 1];
  3372. }
  3373. }
  3374. $(baseObject).removeClass("selected");
  3375. prevObj.addClass("selected");
  3376. scrollToFileObject(prevObj);
  3377. }
  3378. }
  3379. function scrollToFileObject(fileObject){
  3380. if (viewMode == "grid"){
  3381. $('#folderView').scrollTop($(fileObject)[0].offsetTop - ($("#directorySidebar").height()/2 - 340));
  3382. }else{
  3383. $('#folderView').scrollTop($(fileObject)[0].offsetTop - ($("#directorySidebar").height()/2 - 140));
  3384. }
  3385. }
  3386. //Grid mode left right opr
  3387. function selectLeftFile(e){
  3388. e.preventDefault();
  3389. if (viewMode != "grid"){
  3390. return;
  3391. }
  3392. if ($(".fileObject.selected").length == 0 && $(".fileObject").length > 0){
  3393. //Select the first file object
  3394. $($(".fileObject")[$(".fileObject").length - 1]).addClass("selected");
  3395. return
  3396. }else if ( $(".fileObject").length == 0){
  3397. //No file in this folder
  3398. return
  3399. }
  3400. var baseObject = $($(".fileObject.selected")[0]);
  3401. if ($(".fileObject").index( $(baseObject) ) -1 < 0){
  3402. return;
  3403. }
  3404. var previousObject = $(".fileObject").eq( $(".fileObject").index( $(baseObject) ) -1 );
  3405. if (previousObject.length > 0){
  3406. previousObject.addClass("selected");
  3407. scrollToFileObject(previousObject);
  3408. $(baseObject).removeClass("selected");
  3409. }
  3410. }
  3411. function selectRightFile(e){
  3412. e.preventDefault();
  3413. if (viewMode != "grid"){
  3414. return;
  3415. }
  3416. if ($(".fileObject.selected").length == 0 && $(".fileObject").length > 0){
  3417. //Select the first file object
  3418. $($(".fileObject")[0]).addClass("selected");
  3419. return
  3420. }else if ( $(".fileObject").length == 0){
  3421. //No file in this folder
  3422. return
  3423. }
  3424. var baseObject = $($(".fileObject.selected")[0]);
  3425. var nextObject = $(".fileObject").eq( $(".fileObject").index( $(baseObject) ) + 1 );
  3426. if (nextObject.length > 0){
  3427. nextObject.addClass("selected");
  3428. scrollToFileObject(nextObject);
  3429. $(baseObject).removeClass("selected");
  3430. }
  3431. }
  3432. //Functions for getting file objects in the same collume
  3433. function getFileObjectInTheSameCol(baseFileObject){
  3434. if (viewMode != "grid"){
  3435. return;
  3436. }
  3437. var baseOffset = $(baseFileObject).offset().left;
  3438. var fileObjectInTheSameCol = [];
  3439. $(".fileObject").each(function(){
  3440. if ($(this).offset().left == baseOffset){
  3441. let thisFileObject = $(this);
  3442. fileObjectInTheSameCol.push(thisFileObject);
  3443. }
  3444. });
  3445. return fileObjectInTheSameCol;
  3446. }
  3447. //Function for getting file objects in the same row
  3448. function getFileObjectInTheSameRow(baseFileObject){
  3449. if (viewMode != "grid"){
  3450. return;
  3451. }
  3452. var baseOffset = $(baseFileObject).offset().top;
  3453. var fileObjectInTheSameRow = [];
  3454. $(".fileObject").each(function(){
  3455. if ($(this).offset().top == baseOffset){
  3456. let thisFileObject = $(this);
  3457. fileObjectInTheSameRow.push(thisFileObject);
  3458. }
  3459. });
  3460. return fileObjectInTheSameRow;
  3461. }
  3462. //Handle drag drop upload
  3463. function drop(event){
  3464. event.preventDefault();
  3465. console.log(event, event.target)
  3466. //Check if this is file upload or file move / copy function
  3467. let dt = event.dataTransfer
  3468. let files = dt.files
  3469. if (files.length > 0){
  3470. //Upload file via dragdrop
  3471. msgbox("upload","Upload Started");
  3472. let items = event.dataTransfer.items;
  3473. for (let i=0; i<items.length; i++) {
  3474. let item = items[i].webkitGetAsEntry();
  3475. if (item) {
  3476. recursiveScanFilesUpload(item);
  3477. }
  3478. }
  3479. }else{
  3480. //File transfer within system
  3481. let filedata = event.dataTransfer.getData("filedata");
  3482. if (filedata != ""){
  3483. try{
  3484. let fileList = JSON.parse(filedata);
  3485. //Check if the file objects are from the same host
  3486. let localFiles = [];
  3487. let remoteFiles = [];
  3488. fileList.forEach(file => {
  3489. if (file.hostUUID == systemUUID){
  3490. //Local file
  3491. localFiles.push(file);
  3492. }else{
  3493. //Remote files
  3494. remoteFiles.push(file);
  3495. }
  3496. });
  3497. //Start processing the local files
  3498. let currentVroot = currentPath.split(":/").shift();
  3499. clipboard = [];
  3500. //Assume all files are from the same directory
  3501. if (localFiles.length > 0){
  3502. //Check if drag drop from the same directory
  3503. let currentDirname = currentPath.split("/")
  3504. currentDirname.pop();
  3505. currentDirname = currentDirname.join("/");
  3506. let firstFileDirname = localFiles[0].filepath.split("/")
  3507. firstFileDirname.pop();
  3508. firstFileDirname = firstFileDirname.join("/");
  3509. if (currentDirname == firstFileDirname){
  3510. //Drag start and drop location are the same directory
  3511. msgbox("remove","Source and destination file names are the same")
  3512. return;
  3513. }
  3514. let fileVroot = localFiles[0].filepath.split(":/").shift();
  3515. if (currentVroot == fileVroot){
  3516. //Same device same root. Move the file
  3517. cutMode = true;
  3518. }else{
  3519. //Same device differnet root. Copy the file
  3520. cutMode = false;
  3521. }
  3522. //Move all localFiles into clipboard
  3523. localFiles.forEach(file => {
  3524. clipboard.push(file.filepath);
  3525. });
  3526. if (useLocalstorage){
  3527. localStorage.setItem("ao/file_system/clipboard",JSON.stringify(clipboard));
  3528. if (cutMode){
  3529. localStorage.setItem("ao/file_system/cutmode","true");
  3530. }else{
  3531. localStorage.setItem("ao/file_system/cutmode","false");
  3532. }
  3533. }
  3534. //Paste all the files to the current path
  3535. console.log(clipboard);
  3536. paste();
  3537. }
  3538. }catch(ex){
  3539. console.log(ex);
  3540. msgbox("remove","File drop failed. Unable to decode filelist.");
  3541. }
  3542. }
  3543. }
  3544. }
  3545. function recursiveScanFilesUpload(item, rootpath="", base=""){
  3546. var filesInside = [];
  3547. if (item.isDirectory) {
  3548. //This is a directory
  3549. let directoryReader = item.createReader();
  3550. directoryReader.readEntries(function(entries) {
  3551. entries.forEach(function(entry) {
  3552. recursiveScanFilesUpload(entry, rootpath + item.name + "/", base);
  3553. });
  3554. });
  3555. }else{
  3556. //This is a file. Upload it
  3557. item.file(function(fileObject){
  3558. if (isChrome || isSafari){
  3559. //WebKits
  3560. console.log("Upload Target", fileObject, rootpath);
  3561. uploadFile(fileObject, undefined, currentPath + rootpath);
  3562. }else{
  3563. //Firefox. Special handling for root path.
  3564. //Updates for Firefox 84.0.2 (64-bit), which changed minor implementation on relative path in folder updates
  3565. //This section of code is deprecated since then
  3566. /*
  3567. //As firefox will keep its file input relative path, we need to remove the root folder
  3568. //name from the rootpath passed in by the webkit API
  3569. if (rootpath.substr(rootpath.length - 1, 1) == "/"){
  3570. rootpath = rootpath.substr(0, rootpath.length - 1);
  3571. }
  3572. var rootpathInfo = rootpath.split("/");
  3573. if (rootpathInfo.length > 1){
  3574. //Uploading folder to folder. Extract the folder root name
  3575. rootpathInfo.pop();
  3576. }else{
  3577. //Uploading file to folder. Do nothing
  3578. }
  3579. rootpath = rootpathInfo.join("/") + "/";
  3580. console.log("Upload Target", fileObject, rootpath);
  3581. uploadFile(fileObject, undefined, currentPath + rootpath);
  3582. */
  3583. console.log(currentPath + rootpath);
  3584. uploadFile(fileObject, undefined, currentPath + base);
  3585. }
  3586. });
  3587. }
  3588. return filesInside;
  3589. }
  3590. function showCurrentDirectoryProperties(){
  3591. var fileList = [currentPath];
  3592. console.log(fileList);
  3593. var hashPassthrough = encodeURIComponent(JSON.stringify(fileList));
  3594. ao_module_newfw({
  3595. url: "SystemAO/file_system/file_properties.html#" + hashPassthrough,
  3596. width: 340,
  3597. height: 480,
  3598. appicon: "SystemAO/file_system/img/properties.png",
  3599. title: "File Properties",
  3600. });
  3601. }
  3602. function showFileProperties(){
  3603. //Show the file list of the selected files
  3604. if ($(".fileObject.selected").length > 0){
  3605. //Build the filelist
  3606. var fileList = [];
  3607. $(".fileObject.selected").each(function(){
  3608. var filepath = $(this).attr("filepath");
  3609. fileList.push(filepath);
  3610. });
  3611. var hashPassthrough = encodeURIComponent(JSON.stringify(fileList));
  3612. ao_module_newfw({
  3613. url: "SystemAO/file_system/file_properties.html#" + hashPassthrough,
  3614. width: 340,
  3615. height: 480,
  3616. appicon: "SystemAO/file_system/img/properties.png",
  3617. title: "File Properties",
  3618. });
  3619. }
  3620. }
  3621. function initUploadMode(){
  3622. //Get the amount of RAM on the server side to check if low memory mode should be used.
  3623. $.ajax({
  3624. url: "../../system/info/getRAMinfo",
  3625. success: function(data){
  3626. if (data.error !== undefined){
  3627. //Permission denied or other reasons that cannot access harwdare info. Use default mode
  3628. lowMemoryMode = true;
  3629. }else{
  3630. //Check if ramsize > 1.8 GB (2GB). If yes, switch to large memory upload mode
  3631. var memsize = JSON.parse(data);
  3632. if (parseFloat(memsize)/ 1024 / 1024 / 1024 >= 1.8){
  3633. console.log("[File Explorer] Entering large memory upload mode")
  3634. lowMemoryMode = false;
  3635. }
  3636. }
  3637. },
  3638. error: function(){
  3639. //Hardware mode disabled. Always use low memory upload mode instead
  3640. lowMemoryMode = true;
  3641. }
  3642. });
  3643. }
  3644. let uploadBufferedRefreshTimer;
  3645. function uploadFile(file, uuid=undefined, targetDir=undefined) {
  3646. if (lowMemoryMode){
  3647. /*
  3648. Low Memory Upload Mode (Experimental)
  3649. (For host with less than 2GB RAM)
  3650. */
  3651. var filename = encodeURIComponent(file.name);
  3652. var filesize = file.size;
  3653. //Generate a new file item
  3654. let taskUUID = uuid; //For queueing objects
  3655. if (taskUUID == undefined){
  3656. //If this is a new file to be uploaded
  3657. taskUUID = appendUploadFileItem(file.name, file.size);
  3658. }
  3659. //Push to upload pending list if the max concurrent upload is reached
  3660. if (uploadingFileCount >= maxConcurrentUpload){
  3661. let uploadDir = currentPath;
  3662. if (targetDir !== undefined){
  3663. uploadDir = targetDir;
  3664. }else if (isFirefox && uploadDir == currentPath && file.webkitRelativePath != ""){
  3665. //Use the webkitRelativePath instead of the name, this is a folder upload
  3666. //Deprecated for Firefox 84.0.2 updates
  3667. /*
  3668. let pathinfo = file.webkitRelativePath.split("/");
  3669. pathinfo.pop();
  3670. let subpath = pathinfo.join("/");
  3671. uploadDir = uploadDir + subpath;
  3672. */
  3673. uploadDir = targetDir;
  3674. }
  3675. uploadPendingList.push({
  3676. File: file,
  3677. UUID: taskUUID,
  3678. TargetDir: JSON.parse(JSON.stringify(uploadDir)),
  3679. });
  3680. return
  3681. }
  3682. function updateProgressForWebSocketUpload(uuid, progress){
  3683. $(".uploadTask").each(function(){
  3684. if ($(this).attr("taskID") == uuid){
  3685. //Update this progress bar
  3686. $(this).find(".bar").css("width",progress + "%");
  3687. if (progress == 100){
  3688. //When progress = 100 and the server is not response with 200,
  3689. //That means the upload has finish and server is processing the upload
  3690. $(this).find(".progress").addClass("indeterminate");
  3691. }
  3692. }
  3693. });
  3694. }
  3695. //Open the websocket
  3696. let path = currentPath;
  3697. let protocol = "wss://";
  3698. if (location.protocol !== 'https:') {
  3699. protocol = "ws://";
  3700. }
  3701. var port = window.location.port;
  3702. if (window.location.port == ""){
  3703. port = "80";
  3704. }
  3705. let uploadDir = currentPath;
  3706. if (targetDir !== undefined){
  3707. //Not uploading to current directory. Change upload path to target
  3708. uploadDir = targetDir;
  3709. }
  3710. //Fixing Firefox path issues on or above FF48.0
  3711. if (isFirefox && file.webkitRelativePath != ""){
  3712. //Use the webkitRelativePath instead of the name, this is a folder upload
  3713. let pathinfo = file.webkitRelativePath.split("/");
  3714. pathinfo.pop();
  3715. let subpath = pathinfo.join("/");
  3716. uploadDir = uploadDir + subpath;
  3717. //console.log("Firefox Mode: ", uploadDir, "Target Dir", targetDir)
  3718. }
  3719. let socket = new WebSocket(protocol + window.location.hostname + ":" + port + "/system/file_system/lowmemUpload?filename=" + filename + "&path=" + uploadDir);
  3720. let currentSendingIndex = 0;
  3721. let chunks = Math.ceil(file.size/uploadFileChunkSize,uploadFileChunkSize);
  3722. //Define a function for sending a particular chunk
  3723. function sendChunk(id){
  3724. var offsetStart = id*uploadFileChunkSize;
  3725. var offsetEnd = id*uploadFileChunkSize + uploadFileChunkSize;
  3726. var thisblob = file.slice(offsetStart,offsetEnd);
  3727. socket.send(thisblob);
  3728. console.log(id + "/" + chunks);
  3729. //Update progress to first percentage
  3730. var progress = id / (chunks-1) * 100.0;
  3731. if (progress > 100){
  3732. progress = 100;
  3733. }
  3734. updateProgressForWebSocketUpload(taskUUID, progress)
  3735. }
  3736. //Update all UI elements
  3737. updateUploadFileCount();
  3738. uploadingFileCount++;
  3739. //Start sending
  3740. socket.onopen = function(e) {
  3741. if (filesize < uploadFileChunkSize){
  3742. //This file is smaller than chunk size, set it to somwhere within 10% - 20% so it doesn't look like it is stuck
  3743. updateProgressForWebSocketUpload(taskUUID, 10 + Math.floor(Math.random() * Math.floor(10)))
  3744. }
  3745. //Send the first chunk
  3746. sendChunk(0);
  3747. currentSendingIndex++;
  3748. };
  3749. socket.onmessage = function(event) {
  3750. //Append to the send index
  3751. var incomingValue = event.data;
  3752. if (incomingValue == "next"){
  3753. if (currentSendingIndex == chunks + 1){
  3754. //Already finished
  3755. socket.send("done");
  3756. }else{
  3757. //Send next chunk
  3758. sendChunk(currentSendingIndex);
  3759. currentSendingIndex++;
  3760. }
  3761. }else if (incomingValue == "OK"){
  3762. //Merge completed
  3763. $(".uploadTask").each(function(){
  3764. if ($(this).attr("taskID") == taskUUID){
  3765. //Update this progress bar to completed
  3766. $(this).find(".bar").css("width","100%");
  3767. $(this).find(".progress").attr("class","ts tiny positive progress");
  3768. $(this).find(".uploadTaskRemoveIcon").show();
  3769. $(this).addClass("ended");
  3770. $.when($(this).delay(1000).fadeOut("fast")).then(function(){
  3771. $(this).remove();
  3772. updateUploadFileCount();
  3773. });
  3774. }
  3775. });
  3776. }else{
  3777. //Try to parse it as JSON
  3778. try{
  3779. var resp = JSON.parse(incomingValue.split('\\' + '"').join("\""));
  3780. console.log(resp);
  3781. if (resp.error !== undefined){
  3782. //This is an error message
  3783. msgbox("remove",resp.error);
  3784. //Update the progress bar to error
  3785. $(".uploadTask").each(function(){
  3786. if ($(this).attr("taskID") == taskUUID){
  3787. //Update this progress bar to completed
  3788. $(this).find(".bar").css("width","100%");
  3789. $(this).find(".progress").attr("class","ts tiny negative progress");
  3790. $(this).find(".uploadTaskRemoveIcon").show();
  3791. $(this).addClass("ended");
  3792. }
  3793. });
  3794. }
  3795. }catch(ex){
  3796. //Something else
  3797. console.log(incomingValue);
  3798. console.log(ex);
  3799. }
  3800. }
  3801. };
  3802. socket.onclose = function(event) {
  3803. uploadingFileCount--;
  3804. updateUploadFileCount();
  3805. //After the previous file has uploaded / errored, check if there are another file needed to be uploaded
  3806. setTimeout(function(){
  3807. if (uploadPendingList.length > 0){
  3808. let nextFile = uploadPendingList.shift();
  3809. uploadFile(nextFile.File, nextFile.UUID, nextFile.TargetDir);
  3810. }
  3811. }, 100)
  3812. };
  3813. socket.onerror = function(error) {
  3814. console.log(error.message);
  3815. console.log("Unable to open WebSocket connection. Fall back to FORM POST upload mode. (Check your nginx / reverse proxy settings!!!)")
  3816. //Try to fallback to FORM POST upload mode
  3817. lowMemoryMode = false;
  3818. uploadPendingList.push({
  3819. File: file,
  3820. UUID: taskUUID,
  3821. TargetDir: JSON.parse(JSON.stringify(targetDir)),
  3822. });
  3823. return
  3824. /*
  3825. msgbox("caution","Upload failed due to unknown reason");
  3826. //Something went wrong. Set the color to red
  3827. $(".uploadTask").each(function(){
  3828. if ($(this).attr("taskID") == taskUUID){
  3829. //Update this progress bar to completed
  3830. $(this).find(".bar").css("width","100%");
  3831. $(this).find(".progress").attr("class","ts tiny negative progress");
  3832. $(this).find(".uploadTaskRemoveIcon").show();
  3833. $(this).addClass("ended");
  3834. }
  3835. });
  3836. */
  3837. };
  3838. }else{
  3839. /*
  3840. Standard Upload Mode
  3841. (For host with RAM >= 2GB)
  3842. */
  3843. //Create the task progress Object
  3844. let taskUUID = uuid; //For queueing objects
  3845. if (taskUUID == undefined){
  3846. //If this is a new file to be uploaded
  3847. taskUUID = appendUploadFileItem(file.name, file.size);
  3848. }
  3849. //Updates 22-10-2020
  3850. //Added file upload queuing system to prevent too many request on-the-fly at the same time
  3851. if (uploadingFileCount >= maxConcurrentUpload){
  3852. //Push to upload pending list
  3853. //Sometime files will be recursively uploaded (aka retry multiple time), hence the targetDir needed to be copied as well
  3854. let uploadDir = currentPath;
  3855. if (targetDir !== undefined){
  3856. uploadDir = targetDir;
  3857. }
  3858. uploadPendingList.push({
  3859. File: file,
  3860. UUID: taskUUID,
  3861. TargetDir: JSON.parse(JSON.stringify(uploadDir)),
  3862. });
  3863. return
  3864. }
  3865. //Prase upload Form
  3866. let url = '../../system/file_system/upload'
  3867. let uploadCurrentPath = JSON.parse(JSON.stringify(currentPath));
  3868. if (targetDir !== undefined){
  3869. //The upload paramter supplied targetDir
  3870. uploadCurrentPath = targetDir;
  3871. }
  3872. //console.log("Uploading To => ", uploadCurrentPath, targetDir, currentPath);
  3873. let formData = new FormData()
  3874. let xhr = new XMLHttpRequest()
  3875. formData.append('file', file);
  3876. formData.append('path', uploadCurrentPath);
  3877. xhr.open('POST', url, true)
  3878. xhr.upload.addEventListener("progress", function(e) {
  3879. var progress = (e.loaded * 100.0 / e.total) || 100;
  3880. $(".uploadTask").each(function(){
  3881. if ($(this).attr("taskID") == taskUUID){
  3882. //Update this progress bar
  3883. $(this).find(".bar").css("width",progress + "%");
  3884. if (progress == 100){
  3885. //When progress = 100 and the server is not response with 200,
  3886. //That means the upload has finish and server is processing the upload
  3887. $(this).find(".progress").addClass("indeterminate");
  3888. }
  3889. }
  3890. });
  3891. })
  3892. xhr.addEventListener('readystatechange', function(e) {
  3893. if (xhr.readyState == 4 && xhr.status == 200) {
  3894. //Upload process ended
  3895. //Update task status
  3896. $(".uploadTask").each(function(){
  3897. if ($(this).attr("taskID") == taskUUID){
  3898. //Update this progress bar to completed
  3899. $(this).find(".bar").css("width","100%");
  3900. $(this).find(".progress").attr("class","ts tiny positive progress");
  3901. $(this).find(".uploadTaskRemoveIcon").show();
  3902. $(this).addClass("ended");
  3903. //Update 15-11-2020
  3904. //Remove this taskbar after 3 secounds to prevent lags during > 2000 uploads
  3905. $.when($(this).delay(1000).fadeOut("fast")).then(function(){
  3906. $(this).remove();
  3907. updateUploadFileCount();
  3908. });
  3909. }
  3910. });
  3911. var resp = JSON.parse(e.target.response);
  3912. if (resp.error !== undefined){
  3913. msgbox("caution",resp.error);
  3914. //Something went wrong. Set the color to red
  3915. $(".uploadTask").each(function(){
  3916. if ($(this).attr("taskID") == taskUUID){
  3917. //Update this progress bar to completed
  3918. $(this).find(".bar").css("width","100%");
  3919. $(this).find(".progress").attr("class","ts tiny negative progress");
  3920. $(this).find(".uploadTaskRemoveIcon").show();
  3921. $(this).addClass("ended");
  3922. }
  3923. });
  3924. }
  3925. uploadingFileCount--;
  3926. //After the previous file has uploaded / errored, check if there are another file needed to be uploaded
  3927. setTimeout(function(){
  3928. if (uploadPendingList.length > 0){
  3929. let nextFile = uploadPendingList.shift();
  3930. uploadFile(nextFile.File, nextFile.UUID, nextFile.TargetDir);
  3931. }
  3932. }, 100)
  3933. }else if (xhr.readyState == 4 && xhr.status != 200) {
  3934. msgbox("remove","File too big or the target disk is fulled");
  3935. console.log(xhr);
  3936. $(".uploadTask").each(function(){
  3937. if ($(this).attr("taskID") == taskUUID){
  3938. //Upload screwed up. Show negative
  3939. $(this).find(".progress").attr("class","ts tiny negative progress");
  3940. $(this).find(".uploadTaskRemoveIcon").show();
  3941. $(this).addClass("ended");
  3942. }
  3943. });
  3944. uploadingFileCount--;
  3945. //After the previous file has uploaded / errored, check if there are another file needed to be uploaded
  3946. setTimeout(function(){
  3947. if (uploadPendingList.length > 0){
  3948. let nextFile = uploadPendingList.shift();
  3949. uploadFile(nextFile.File, nextFile.UUID, nextFile.TargetDir);
  3950. }
  3951. }, 100)
  3952. }
  3953. updateUploadFileCount();
  3954. })
  3955. xhr.send(formData);
  3956. uploadingFileCount++;
  3957. updateUploadFileCount();
  3958. }
  3959. }
  3960. //Clear all finished upload tasks
  3961. function clearAllUploadTask(){
  3962. $(".uploadTask.ended").slideUp('300',function(){
  3963. $(this).remove();
  3964. updateUploadFileCount();
  3965. });
  3966. }
  3967. var searchMode = false;
  3968. function toggleSearch(){
  3969. //Start search mode
  3970. $(".searchbar").slideDown("fast", function(){
  3971. initWindowSizes(true);
  3972. });
  3973. $("#searhbtn").addClass("disabled");
  3974. //Force videmode to list
  3975. viewMode = "list"
  3976. $(".videmode.button").each(function(){
  3977. $(this).addClass('disabled');
  3978. });
  3979. searchMode = true;
  3980. //Clear current folderlist
  3981. $("#folderList").show();
  3982. $("#folderList").html(`<div class="ts basic segment ${currentTheme}">
  3983. <div class="ts header">
  3984. <i class="arrow up icon ${currentTheme}"></i> <span class="${currentTheme}">Type to Start Search</span>
  3985. <div class="sub header ${currentTheme}" style="margin-top:12px;">Type something in the search bar to start searching.<br>
  3986. Start wildcard matching with "/" (slash) and your wildcard string (e.g. /*.mp3)</div>
  3987. </div>
  3988. </div>`);
  3989. $("#fileList").hide();
  3990. }
  3991. function hideSearchBar(skipFilelistRefresh = false){
  3992. $(".searchbar").slideUp("fast", function(){
  3993. initWindowSizes(true);
  3994. });
  3995. $("#searchInput").val("");
  3996. $("#searhbtn").removeClass("disabled");
  3997. $(".videmode.button").each(function(){
  3998. if ($(this).attr("mode") != "list"){
  3999. $(this).removeClass('disabled');
  4000. }
  4001. });
  4002. if (skipFilelistRefresh == false){
  4003. listDirectory(currentPath);
  4004. }
  4005. searchMode = false;
  4006. }
  4007. //Handle case sensitive in keyword searching
  4008. function toggleCaseSensitive(btn){
  4009. if ($(btn).hasClass("active")){
  4010. $(btn).removeClass("active");
  4011. searchCaseSensitive = false;
  4012. }else{
  4013. $(btn).addClass("active");
  4014. searchCaseSensitive = true;
  4015. }
  4016. }
  4017. function handleSearch(){
  4018. var keyword = $("#searchInput").val();
  4019. $("#folderList").html(`<div class="ts basic segment ${currentTheme}">
  4020. <i class="loading spinner icon ${currentTheme}"></i> <span class="${currentTheme}">Searching</span>
  4021. </div>`);
  4022. $("#fileList").hide();
  4023. $("#fileList").html("");
  4024. $.ajax({
  4025. url: "../../system/file_system/search",
  4026. data: {path: currentPath, keyword: keyword, casesensitive: searchCaseSensitive},
  4027. success: function(data){
  4028. if (data.error !== undefined){
  4029. msgbox("remove", data.error);
  4030. }else{
  4031. //Render the filelist
  4032. console.log(data);
  4033. if (data.length == 0){
  4034. $("#folderList").show();
  4035. $("#folderList").html(`<div class="ts basic segment ${currentTheme}">
  4036. <div class="ts header ${currentTheme}">
  4037. <i class="question icon" ${currentTheme}></i> <span class="${currentTheme}">No Matching Results</span>
  4038. <div class="sub header ${currentTheme}">The host return no matching results for your keyword "${keyword}". <br>Check your spelling and if your wildcard are valid.</div>
  4039. </div>
  4040. </div>`);
  4041. }else{
  4042. renderDirectory(data);
  4043. }
  4044. }
  4045. }, error: function(){
  4046. $("#folderList").html(`<div class="ts basic segment">
  4047. <div class="ts header">
  4048. <i class="remove icon"></i> Search Error
  4049. <div class="sub header">Search timeout has occurred during file searching.</div>
  4050. </div>
  4051. </div>`);
  4052. }
  4053. })
  4054. }
  4055. function handleSearchBarPress(e){
  4056. if (e.keyCode == 13){
  4057. e.preventDefault();
  4058. handleSearch();
  4059. }
  4060. }
  4061. function toggleCtrl(){
  4062. ctrlHold = !ctrlHold;
  4063. }
  4064. function appendUploadFileItem(filename, filesize){
  4065. var newuuid = uuidv4();
  4066. var humanReadableFilesize = bytesToSize(filesize);
  4067. $("#uploadProgressList").append(`<div class="uploadTask" taskID="${newuuid}">
  4068. <p style="width: calc(100% - 15px);">${filename} (${humanReadableFilesize})</p>
  4069. <div class="ts tiny primary progress" style="margin-top:-12px;">
  4070. <div class="bar" style="width: 0%"></div>
  4071. </div>
  4072. <div class="uploadTaskRemoveIcon" onclick="removeThisTask(this);" style="display:none;">
  4073. <i class="remove icon"></i>
  4074. </div>
  4075. </div>`);
  4076. return newuuid;
  4077. }
  4078. function removeThisTask(object){
  4079. $(object).parent().fadeOut('fast',
  4080. function(){
  4081. $(this).remove();
  4082. updateUploadFileCount();
  4083. }
  4084. );
  4085. }
  4086. function toggleUploadList(){
  4087. $("#uploadProgressList").toggle();
  4088. if ($("#uploadProgressList").is(":visible")){
  4089. $("#hideUploadButton").html('<i class="caret down icon"></i>');
  4090. }else{
  4091. $("#hideUploadButton").html('<i class="caret up icon"></i>');
  4092. }
  4093. }
  4094. function updateUploadFileCount(){
  4095. $("#uploadCount").text(uploadingFileCount);
  4096. $("#waitingCount").text(uploadPendingList.length);
  4097. if (uploadingFileCount == 0 && $(".uploadTask").length == 0){
  4098. $("#uploadTab").hide();
  4099. }else{
  4100. $("#uploadTab").show();
  4101. }
  4102. }
  4103. function bytesToSize(bytes) {
  4104. var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
  4105. if (bytes == 0) return '0 Byte';
  4106. var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
  4107. return Math.round(bytes / Math.pow(1024, i) * 100, 2) / 100 + ' ' + sizes[i];
  4108. }
  4109. function uuidv4() {
  4110. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  4111. var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
  4112. return v.toString(16);
  4113. });
  4114. }
  4115. function dropToFolder(event){
  4116. event.preventDefault();
  4117. event.stopImmediatePropagation();
  4118. console.log("Drop to folder detected");
  4119. //Extract target folder path from object
  4120. var targetPath = $(event.target).attr("filepath");
  4121. if (targetPath == ""){
  4122. return
  4123. }
  4124. //Check if this is upload or file move drag
  4125. var files = event.dataTransfer.files;
  4126. if (files.length > 0){
  4127. //Upload mode. Extract the target folder basename from path
  4128. if (targetPath.substr(targetPath.length -1,1) == "/"){
  4129. targetPath = targetPath.substr(0, targetPath.length-1);
  4130. }
  4131. var folderBase = targetPath.split("/").pop() + "/";
  4132. var items = event.dataTransfer.items;
  4133. for (let i=0; i<items.length; i++) {
  4134. let item = items[i].webkitGetAsEntry();
  4135. if (item) {
  4136. recursiveScanFilesUpload(item, folderBase, folderBase);
  4137. }
  4138. }
  4139. }else if (event.dataTransfer.getData("filedata") != ""){
  4140. var targetVroot = targetPath.split(":/").shift();
  4141. //Get the source files
  4142. var filelist = JSON.parse(event.dataTransfer.getData("filedata"));
  4143. if (filelist.length > 0){
  4144. var srcVroot = filelist[0].filepath.split(":/").shift();
  4145. if (srcVroot == targetVroot){
  4146. //Use move mode
  4147. cutMode = true;
  4148. }else{
  4149. //Use copy mode
  4150. cutMode = false;
  4151. }
  4152. //Parse the filelist
  4153. clipboard = [];
  4154. filelist.forEach(file=>{
  4155. clipboard.push(file.filepath);
  4156. });
  4157. if (useLocalstorage){
  4158. localStorage.setItem("ao/file_system/clipboard",JSON.stringify(clipboard));
  4159. localStorage.setItem("ao/file_system/cutmode","true");
  4160. }
  4161. //Perform operations
  4162. paste(targetPath, false)
  4163. }
  4164. }
  4165. }
  4166. function allowDrop(event){
  4167. event.preventDefault();
  4168. }
  4169. $(".popupWrapper").on("click",function(){
  4170. hideAllPopupWindows();
  4171. });
  4172. function hideAllPopupWindows(){
  4173. $(".popup").fadeOut(100);
  4174. $(".popupWrapper").fadeOut(100);
  4175. $('body').css("overflow","");
  4176. }
  4177. function showPopupWrapper(){
  4178. $(".popupWrapper").fadeIn('fast');
  4179. $('body').css("overflow","hidden");
  4180. }
  4181. //Handle keydown of enter on certain input boxes
  4182. function handleEnterKeyDown(event, handler){
  4183. if (event.which == 13){
  4184. handler();
  4185. }
  4186. }
  4187. //Generate a download link and press it
  4188. function generateDownloadFromURL(url, filename){
  4189. let a = document.createElement('a')
  4190. a.href = url;
  4191. a.download = filename;
  4192. document.body.appendChild(a)
  4193. a.click()
  4194. document.body.removeChild(a)
  4195. }
  4196. //Update sorting method for file listing
  4197. function updateSortingMethods(){
  4198. var method = $("#sortingMethodSelector").val();
  4199. sortMode = method;
  4200. refreshList();
  4201. }
  4202. </script>
  4203. </body>
  4204. </html>