file_explorer.html 240 KB

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