file_explorer.html 239 KB

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