file_explorer.html 227 KB

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