file_explorer.html 250 KB

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