file_explorer.html 269 KB

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