file_explorer.html 245 KB

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