file_explorer.html 207 KB

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