editor-new.js 209 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786
  1. "use strict";
  2. // Copyright 2012 United States Government, as represented by the Secretary of Defense, Under
  3. // Secretary of Defense (Personnel & Readiness).
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  6. // in compliance with the License. You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software distributed under the License
  11. // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
  12. // or implied. See the License for the specific language governing permissions and limitations under
  13. // the License.
  14. /// vwf/view/editor creates a view interface for editor functions.
  15. ///
  16. /// @module vwf/view/editor
  17. /// @requires version
  18. /// @requires vwf/view
  19. /// @requires vwf/utility
  20. define([
  21. "module",
  22. "version",
  23. "vwf/view",
  24. "vwf/utility",
  25. "vwf/view/lib/ace/ace",
  26. "vwf/view/lib/colorpicker/colorpicker.min",
  27. "jquery",
  28. "jquery-ui",
  29. "jquery-encoder-0.1.0"
  30. ], function (module, version, view, utility, ace, colorpicker, $) {
  31. var self;
  32. return view.load(module, {
  33. // == Module Definition ====================================================================
  34. initialize: function () {
  35. self = this;
  36. this.ace = window.ace;
  37. this.nodes = {};
  38. this.scenes = {};
  39. this.allScripts = {};
  40. // EDITOR CLOSED --> 0
  41. // HIERARCHY OPEN --> 1
  42. // USER LIST OPEN --> 2
  43. // TIMELINE OPEN --> 3
  44. // ABOUT OPEN --> 4
  45. this.editorView = 0;
  46. this.editorOpen = false;
  47. this.timelineInit = false;
  48. this.aboutInit = false;
  49. this.codeEditorInit = false;
  50. this.modelsInit = false;
  51. this.editingScript = false;
  52. this.topdownName = '#topdown_a';
  53. this.topdownTemp = '#topdown_b';
  54. this.clientList = '#client_list';
  55. this.timeline = '#time_control';
  56. this.about = '#about_tab';
  57. this.codeEditor = '#codeEditor_tab';
  58. this.models = '#model_a';
  59. this.modelsTemp = '#model_b';
  60. this.currentNodeID = '';
  61. this.currentModelID = '';
  62. this.currentModelURL = '';
  63. this.highlightedChild = '';
  64. this.intervalTimer = 0;
  65. this.activeCameraID = undefined;
  66. $(document.head).append('<style type="text/css" media="screen"> #editorlive { height: 500px; width: 800px; } </style>');
  67. document.querySelector('head').innerHTML += '<link rel="stylesheet" href="vwf/view/lib/editorLive.css">';
  68. //document.querySelector('head').innerHTML += '<script type="text/javascript" src="vwf/view/lib/colorpicker/colorpicker.min.js">';
  69. document.querySelector('head').innerHTML += '<link rel="stylesheet" href="vwf/view/lib/colorpicker/themes.css">';
  70. $(document.head).append('<meta name="viewport" content="width=device-width, initial-scale=1">');
  71. // $('body').append('<script>mdc.autoInit()</script>');
  72. this.getRoot = function () {
  73. var app = window.location.pathname;
  74. var pathSplit = app.split('/');
  75. if (pathSplit[0] == "") {
  76. pathSplit.shift();
  77. }
  78. if (pathSplit[pathSplit.length - 1] == "") {
  79. pathSplit.pop();
  80. }
  81. var instIndex = pathSplit.length - 1;
  82. if (pathSplit.length > 2) {
  83. if (pathSplit[pathSplit.length - 2] == "load") {
  84. instIndex = pathSplit.length - 3;
  85. }
  86. }
  87. if (pathSplit.length > 3) {
  88. if (pathSplit[pathSplit.length - 3] == "load") {
  89. instIndex = pathSplit.length - 4;
  90. }
  91. }
  92. var root = "";
  93. for (var i = 0; i < instIndex; i++) {
  94. if (root != "") {
  95. root = root + "/";
  96. }
  97. root = root + pathSplit[i];
  98. }
  99. if (root.indexOf('.vwf') != -1) root = root.substring(0, root.lastIndexOf('/'));
  100. return root
  101. }
  102. $('body').append(
  103. "<div id='editor' class='relClass'>\n" +
  104. " <div class='uiContainer'>\n" +
  105. " <div class='editor-tabs' id='tabs'>\n" +
  106. " <img id='x' style='display:none' src='images/tab_X.png' alt='x' />\n" +
  107. " <img id='hierarchy' src='images/tab_Application.png' alt='application' />\n" +
  108. " <img id='userlist' src='images/tab_Users.png' alt='users' />\n" +
  109. " <img id='timeline' src='images/tab_Time.png' alt='time' />\n" +
  110. " <img id='models' src='images/tab_Models.png' alt='models' />\n" +
  111. " <img id='about' src='images/tab_About.png' alt='about' />\n" +
  112. " <img id='codeEditor' src='images/tab_CodeEditor.png' alt='code' />\n" +
  113. " </div>\n" +
  114. " </div>\n" +
  115. "</div>" +
  116. "<div class='relClass'><div class='uiContainer'><div class='vwf-tree' id='topdown_a'></div></div></div>" +
  117. "<div class='relClass'><div class='uiContainer'><div class='vwf-tree' id='topdown_b'></div></div></div>" +
  118. "<div class='relClass'><div class='uiContainer'><div class='vwf-tree' id='client_list'></div></div></div>" +
  119. "<div class='relClass'><div class='uiContainer'><div class='vwf-tree' id='time_control'></div></div></div>" +
  120. "<div class='relClass'><div class='uiContainer'><div class='vwf-tree' id='about_tab'></div></div></div>" +
  121. "<div class='relClass'><div class='uiContainer'><div class='vwf-tree' id='codeEditor_tab'></div></div></div>" +
  122. "<div class='relClass'><div class='uiContainer'><div class='vwf-tree' id='model_a'></div></div></div>" +
  123. "<div class='relClass'><div class='uiContainer'><div class='vwf-tree' id='model_b'></div></div></div>"
  124. );
  125. //style: "position: absolute; top: 0; left: 0; z-index: 2",
  126. // let draggie = new Draggabilly('.draggable');
  127. // let dragDiv = document.querySelector("#dragDiv").style.visibility = 'hidden';
  128. // let propDiv = document.createElement("div");
  129. // var newContent = document.createTextNode("Hi there and greetings!");
  130. // newDiv.appendChild(newContent); //add the text node to the newly created div.
  131. //<div id='drawer'></div><div id='toolbar'></div><div id='clientsList'></div>
  132. ["drawer", "toolbar", "sideBar", "propWindow", "clientsWindow", "codeEditorWindow", "propEditorWindow", "viewSceneProps"].forEach(item => {
  133. let el = document.createElement("div");
  134. el.setAttribute("id", item);
  135. document.body.appendChild(el);
  136. }
  137. );
  138. function avatarCardDef(src, desc, onclickfunc) {
  139. return {
  140. $cell: true,
  141. $type: "div",
  142. class: "mdc-card avatar-card",
  143. $init: function () {
  144. this.style.backgroundImage = 'linear-gradient(0deg, rgba(0, 0, 0, 0.0), rgba(0, 0, 0, 0.0) ), url(' + src + ')'
  145. },
  146. onclick: onclickfunc,
  147. $components: [
  148. {
  149. $type: "section",
  150. class: "mdc-card__primary",
  151. $components: [
  152. {
  153. $type: "h1",
  154. class: "mdc-card__title mdc-card__title--large",
  155. $text: desc.subtitle
  156. },
  157. {
  158. $type: "h2",
  159. class: "mdc-card__subtitle",
  160. $text: desc.title
  161. }
  162. ]
  163. },
  164. {
  165. $type: "section",
  166. class: "mdc-card__actions",
  167. $components: [
  168. {
  169. $type: "button",
  170. class: "mdc-button mdc-button--compact mdc-card__action",
  171. //$text: "Use it",
  172. onclick: onclickfunc
  173. }
  174. ]
  175. }
  176. ]
  177. }
  178. }
  179. let avatarSettings =
  180. {
  181. $cell: true,
  182. $type: "div",
  183. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  184. $components: [
  185. {
  186. $cell: true,
  187. $type: "div",
  188. class: "mdc-layout-grid__inner",
  189. $components: [
  190. {
  191. $cell: true,
  192. $type: "div",
  193. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  194. $components: [
  195. {
  196. $cell: true,
  197. $type: "button",
  198. class: "mdc-button mdc-button--raised",
  199. $text: "Reset camera view",
  200. onclick: function (e) {
  201. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  202. let controlEl = document.querySelector('#avatarControl');
  203. controlEl.setAttribute('camera', 'active', true);
  204. }
  205. },
  206. {
  207. $cell: true,
  208. $type: "button",
  209. class: "mdc-button mdc-button--raised",
  210. $text: "Hide cursor",
  211. onclick: function (e) {
  212. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  213. let avatarID = 'avatar-' + self.kernel.moniker();
  214. let cursorID = 'myCursor-' + avatarID;
  215. let controlEl = document.querySelector("[id='" + cursorID + "']");
  216. let vis = controlEl.getAttribute('visible');
  217. this.$text = vis ? 'Show cursor' : 'Hide cursor';
  218. vwf_view.kernel.callMethod(avatarID, "showHideCursor", [!vis]);
  219. //controlEl.setAttribute('visible', !vis);
  220. }
  221. }
  222. ]
  223. },
  224. {
  225. $cell: true,
  226. $type: "div",
  227. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  228. $components: [
  229. {
  230. $type: "div",
  231. class: "mdc-layout-grid",
  232. $components: [
  233. {
  234. $type: "div",
  235. class: "mdc-layout-grid__inner",
  236. $components: [
  237. {
  238. $cell: true,
  239. $type: "div",
  240. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  241. $components: [
  242. avatarCardDef("/../assets/avatars/ico/simple.jpg", { title: "Simple", subtitle: "Cube" },
  243. function (e) {
  244. let avatarID = 'avatar-' + self.kernel.moniker();
  245. vwf_view.kernel.callMethod(avatarID, "createSimpleAvatar");
  246. }
  247. )
  248. ]
  249. },
  250. {
  251. $cell: true,
  252. $type: "div",
  253. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  254. $components: [
  255. avatarCardDef("/../assets/avatars/ico/female.jpg", { title: "Human", subtitle: "Female" },
  256. function (e) {
  257. let avatarID = 'avatar-' + self.kernel.moniker();
  258. vwf_view.kernel.callMethod(avatarID, "createAvatarFromGLTF", ["/../assets/avatars/female/avatar1.gltf"]);
  259. }
  260. )]
  261. },
  262. {
  263. $cell: true,
  264. $type: "div",
  265. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  266. $components: [
  267. avatarCardDef("/../assets/avatars/ico/male.jpg", { title: "Human", subtitle: "Male" },
  268. function (e) {
  269. let avatarID = 'avatar-' + self.kernel.moniker();
  270. vwf_view.kernel.callMethod(avatarID, "createAvatarFromGLTF", ["/../assets/avatars/male/avatar1.gltf"]);
  271. }
  272. )]
  273. }
  274. ]
  275. }
  276. ]
  277. },
  278. // {
  279. // $cell: true,
  280. // $type: "button",
  281. // class: "mdc-button mdc-button--raised",
  282. // $text: "Simple Avatar",
  283. // onclick: function (e) {
  284. // let avatarID = 'avatar-' + self.kernel.moniker();
  285. // vwf_view.kernel.callMethod(avatarID, "createSimpleAvatar");
  286. // }
  287. // },
  288. // {
  289. // $cell: true,
  290. // $type: "button",
  291. // class: "mdc-button mdc-button--raised",
  292. // $text: "Male Avatar",
  293. // onclick: function (e) {
  294. // let avatarID = 'avatar-' + self.kernel.moniker();
  295. // vwf_view.kernel.callMethod(avatarID, "createAvatarFromGLTF", ["/../assets/avatars/male/avatar1.gltf"]);
  296. // }
  297. // },
  298. // {
  299. // $cell: true,
  300. // $type: "button",
  301. // class: "mdc-button mdc-button--raised",
  302. // $text: "Female Avatar",
  303. // onclick: function (e) {
  304. // let avatarID = 'avatar-' + self.kernel.moniker();
  305. // vwf_view.kernel.callMethod(avatarID, "createAvatarFromGLTF", ["/../assets/avatars/female/avatar1.gltf"]);
  306. // }
  307. // },
  308. ]
  309. }
  310. ]
  311. }
  312. ]
  313. }
  314. let viewSettings =
  315. {
  316. $cell: true,
  317. $type: "div",
  318. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  319. $components: [
  320. {
  321. $cell: true,
  322. $type: "div",
  323. class: "mdc-layout-grid__inner",
  324. $components: [
  325. {
  326. $cell: true,
  327. $type: "div",
  328. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  329. $components: [
  330. {
  331. $cell: true,
  332. $type: "button",
  333. class: "mdc-button mdc-button--raised",
  334. $text: "Settings",
  335. onclick: function (e) {
  336. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  337. }
  338. }
  339. ]
  340. }
  341. ]
  342. }
  343. ]
  344. }
  345. let savedStateEl = function (item) {
  346. return {
  347. $type: "li",
  348. class: "mdc-list-item",
  349. role: "option",
  350. $components: [
  351. {
  352. $text: "Saved world"
  353. }
  354. ]
  355. }
  356. }
  357. let stateListElement = function (item) {
  358. let liEl = {
  359. $type: "li",
  360. class: "mdc-list-item",
  361. role: "option",
  362. id: "",
  363. applicationpath: "",
  364. $components: [
  365. {
  366. $text: "no saves"
  367. }
  368. ]
  369. }
  370. let applicationName = item.applicationpath.split("/");
  371. if (applicationName == "") {
  372. return liEl
  373. }
  374. if (applicationName.length > 0) {
  375. applicationName = applicationName[applicationName.length - 1];
  376. }
  377. if (applicationName.length > 0) {
  378. applicationName = applicationName.charAt(0).toUpperCase() + applicationName.slice(1);
  379. }
  380. if (item.latestsave) {
  381. liEl = {
  382. $type: "li",
  383. class: "mdc-list-item",
  384. role: "option",
  385. id: item.savename,
  386. applicationpath: item.applicationpath,
  387. $components: [
  388. {
  389. $text: applicationName + ": " + item.savename
  390. }
  391. ]
  392. }
  393. }
  394. else {
  395. liEl = {
  396. $type: "li",
  397. class: "mdc-list-item",
  398. role: "option",
  399. id: item.savename,
  400. revision: item.revision,
  401. applicationpath: item.applicationpath,
  402. $components: [
  403. {
  404. $text: applicationName + ": " + item.savename + " Rev(" + item.revision + ")"
  405. }
  406. ]
  407. }
  408. }
  409. return liEl
  410. }
  411. let loadSaveSettings =
  412. {
  413. $cell: true,
  414. $type: "div",
  415. id: "loadSaveSettings",
  416. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  417. _saveStates: [],
  418. _getStates: async function () {
  419. let response = await fetch("/" + self.getRoot() + "/listallsaves");
  420. let data = await response.json();
  421. //this._saveStates = data;
  422. //let appName = self.getRoot();
  423. //console.log(data.filter(item => item.applicationpath.split("/")[1] == appName));
  424. let filterData = data.filter(item => item.applicationpath.split("/")[1] == self.getRoot());
  425. if (filterData.length !== 0) {
  426. this._saveStates = filterData
  427. //return filterData
  428. } else {
  429. this._saveStates = [{
  430. savename: "",
  431. latestsave: "",
  432. revision: "",
  433. applicationpath: "",
  434. url: ""
  435. }]
  436. }
  437. // this._saveStates.filter(item => item.applicationpath.split("/")[1] == self.getRoot()).map(stateListElement)
  438. //return data
  439. //console.log(data);
  440. return this._saveStates
  441. },
  442. $init: function () {
  443. this._getStates();
  444. },
  445. $update: function () {
  446. this.$components =
  447. [
  448. {
  449. $cell: true,
  450. $type: "div",
  451. class: "mdc-layout-grid__inner",
  452. $components: [
  453. {
  454. $cell: true,
  455. $type: "div",
  456. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  457. $components: [
  458. {
  459. class: "mdc-textfield",
  460. $cell: true,
  461. $type: "span",
  462. $components: [
  463. {
  464. class: "mdc-textfield__input",
  465. id: "fileName",
  466. $cell: true,
  467. $type: "input",
  468. type: "text",
  469. value: self.getRoot()
  470. }]
  471. }
  472. ]
  473. },
  474. {
  475. $cell: true,
  476. $type: "div",
  477. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  478. $components: [
  479. {
  480. $cell: true,
  481. $type: "button",
  482. class: "mdc-button mdc-button--raised",
  483. $text: "Save",
  484. onclick: function (e) {
  485. let fileName = document.querySelector('#fileName')
  486. saveStateAsFile.call(self, fileName.value);
  487. document.querySelector("#fileName").value = '';
  488. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  489. }
  490. }
  491. ]
  492. },
  493. {
  494. $cell: true,
  495. $type: "div",
  496. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  497. $components: [
  498. {
  499. $cell: true,
  500. $type: "div",
  501. class: "mdc-select",
  502. $init: function () {
  503. var MDCSelect = mdc.select.MDCSelect;
  504. const select = new MDCSelect(document.querySelector('.mdc-select'));
  505. select.listen('MDCSelect:change', () => {
  506. //this._selectedState = select.value;
  507. document.querySelector('#loadStateButton')._selectedState = select.selectedOptions[0];
  508. //console.log(select.value);
  509. //.selectedOptions[0]
  510. });
  511. },
  512. role: "listbox",
  513. $components: [
  514. {
  515. $type: "span",
  516. class: "mdc-select__selected-text",
  517. $text: "Select saved state"
  518. },
  519. {
  520. $type: "div",
  521. class: "mdc-simple-menu mdc-select__menu",
  522. $components: [
  523. {
  524. $type: "ul",
  525. class: "mdc-list mdc-simple-menu__items",
  526. $components: this._saveStates.map(stateListElement)
  527. }
  528. ]
  529. }
  530. ]
  531. }
  532. ]
  533. },
  534. {
  535. $cell: true,
  536. $type: "div",
  537. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  538. $components: [
  539. {
  540. $cell: true,
  541. $type: "button",
  542. _selectedState: {},
  543. id: "loadStateButton",
  544. class: "mdc-button mdc-button--raised",
  545. $text: "Load",
  546. onclick: function (e) {
  547. loadSavedState.call(self, this._selectedState.getAttribute('id'), this._selectedState.getAttribute('applicationpath'), this._selectedState.getAttribute('revision'));
  548. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  549. }
  550. }
  551. ]
  552. }
  553. ]
  554. }
  555. ]
  556. }
  557. }
  558. // document.querySelector('#' + 'viewSettings').$cell({
  559. // $cell: true,
  560. // $type: "div",
  561. // id: 'viewSettings',
  562. // //style:'z-index: 10; position: absolute; margin-left: 240px;',
  563. // class: "settingsDiv mdc-toolbar-fixed-adjust",
  564. // $init: function(){
  565. // this.style.visibility = 'hidden';
  566. // },
  567. // $components: [viewSettings]
  568. // })
  569. // document.querySelector('#' + 'viewSettings').$cell({
  570. // $cell: true,
  571. // $type: "div",
  572. // id: 'viewSettings',
  573. // style:'z-index: 10; position: absolute; margin-left: 240px;',
  574. // class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left mdc-toolbar-fixed-adjust",
  575. // $init: function(){
  576. // this.style.visibility = 'hidden';
  577. // },
  578. // $components: [viewSettings]
  579. // })
  580. let protoPropertiesCell = function (m) {
  581. return {
  582. $type: "div",
  583. class: "mdc-layout-grid__inner",
  584. _prop: {},
  585. $init: function () {
  586. let prop = m[1].prop;
  587. if (prop.value == undefined) {
  588. prop.value = JSON.stringify(utility.transform(vwf.getProperty(this._currentNode, prop.name, []), utility.transforms.transit));
  589. }
  590. this._prop = prop
  591. },
  592. $update: function () {
  593. this.$components = [
  594. {
  595. $type: "div",
  596. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  597. $components: [
  598. { $text: this._prop.name }
  599. ]
  600. },
  601. {
  602. $type: "div",
  603. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  604. },
  605. {
  606. $type: "div",
  607. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-7",
  608. $components: [
  609. {
  610. class: "mdc-textfield",
  611. $cell: true,
  612. $type: "div",
  613. $components: [{
  614. class: "mdc-textfield__input",
  615. $cell: true,
  616. $type: "input",
  617. type: "text",
  618. value: this._prop.value,
  619. onchange: function (e) {
  620. let propValue = this.value;
  621. try {
  622. propValue = JSON.parse(propValue);
  623. self.kernel.setProperty(this._currentNode, this._prop.name, propValue);
  624. } catch (e) {
  625. // restore the original value on error
  626. this.value = propValue;
  627. }
  628. }
  629. }]
  630. }
  631. ]
  632. }
  633. ]
  634. }
  635. }
  636. }
  637. let propertiesCell = function (m) {
  638. var editComponents = [{}, {}]
  639. if (m.name.indexOf("semantics") > -1) { }
  640. else if (m.name.indexOf("grammar") > -1) { }
  641. else if (m.name.indexOf("ohm") > -1) {
  642. editComponents = [
  643. {
  644. $type: "div",
  645. $cell: true,
  646. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-6",
  647. $components: [
  648. {
  649. $cell: true,
  650. $type: "button",
  651. class: "mdc-button",
  652. $text: "Edit", //edit grammar
  653. onclick: function (e) {
  654. var currentNode = document.querySelector('#currentNode')._currentNode;
  655. if (currentNode == '') {
  656. currentNode = vwf_view.kernel.find("", "/")[0];
  657. }
  658. let editor = document.querySelector('#livePropEditor');
  659. editor._setNode(currentNode);
  660. editor._propName = m.name;
  661. editor._prop = { body: m.rawValue, type: 'complex' }
  662. document.querySelector('#propEditorWindow').style.visibility = 'visible';
  663. }
  664. }
  665. ]
  666. },
  667. {
  668. $type: "div",
  669. $cell: true,
  670. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  671. $components: []
  672. }
  673. ]
  674. } else {
  675. editComponents = [
  676. {
  677. $type: "div",
  678. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-6",
  679. $components: [
  680. {
  681. class: "mdc-textfield",
  682. $cell: true,
  683. $type: "span",
  684. $components: [
  685. {
  686. class: "mdc-textfield__input",
  687. id: "prop-" + m.name,
  688. $cell: true,
  689. $type: "input",
  690. type: "text",
  691. value: m.getValue(),
  692. onchange: function (e) {
  693. let propValue = this.value;
  694. try {
  695. propValue = JSON.parse(propValue);
  696. self.kernel.setProperty(this._currentNode, m.name, propValue);
  697. } catch (e) {
  698. // restore the original value on error
  699. this.value = propValue;
  700. }
  701. }
  702. }
  703. ]
  704. }
  705. ]
  706. },
  707. {
  708. $type: "div",
  709. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  710. $components: [
  711. {
  712. $cell: true,
  713. $type: "button",
  714. class: "mdc-button",
  715. $text: "^", //edit grammar
  716. onclick: function (e) {
  717. var currentNode = document.querySelector('#currentNode')._currentNode;
  718. if (currentNode == '') {
  719. currentNode = vwf_view.kernel.find("", "/")[0];
  720. }
  721. let editor = document.querySelector('#livePropEditor');
  722. editor._setNode(currentNode);
  723. editor._propName = m.name;
  724. editor._prop = { body: m.getValue(), type: 'simple' }
  725. document.querySelector('#propEditorWindow').style.visibility = 'visible';
  726. }
  727. }
  728. ]
  729. }
  730. ];
  731. }
  732. return {
  733. $type: "div",
  734. class: "mdc-layout-grid__inner",
  735. $components: [
  736. {
  737. $type: "div",
  738. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  739. $components: [
  740. { $text: m.name }
  741. ]
  742. },
  743. {
  744. $type: "div",
  745. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  746. },
  747. editComponents[0],
  748. editComponents[1]
  749. ]
  750. }
  751. }
  752. let nodeLink = function (m) {
  753. var myClass = "nodeItem";
  754. let myAvatarName = 'avatar-' + self.kernel.moniker();
  755. (myAvatarName == m.name) ? (myClass = "avatarName mdc-typography--subheading2") :
  756. myClass = "nodeItem"
  757. return {
  758. $type: "li",
  759. class: "mdc-list-item",
  760. $components: [{
  761. $type: "a",
  762. class: "mdc-list-item",
  763. $href: "#",
  764. $components: [{
  765. $type: 'span',
  766. class: myClass,
  767. $text: m.name
  768. }
  769. ],
  770. onclick: function (e) {
  771. //self.currentNodeID = m.ID;
  772. document.querySelector('#currentNode')._setNode(m.ID);
  773. // document.querySelector('#liveCodeEditor')._editorNode = m.ID;
  774. // createAceEditor(self, m.ID);
  775. }
  776. }]
  777. }
  778. };
  779. let listDivider = {
  780. $cell: true,
  781. $type: "hr",
  782. class: "mdc-list-divider",
  783. }
  784. let nodesCell = {
  785. $cell: true,
  786. $type: "div",
  787. id: "currentNode",
  788. _childNodes: [],
  789. _currentNode: '',
  790. _displayedProperties: {},
  791. _setNode: function (aNode) {
  792. this._currentNode = aNode;
  793. document.querySelector('#sideBar')._sideCurrentNode = this._currentNode
  794. },
  795. $init: function () {
  796. this._currentNode = document.querySelector('#sideBar')._sideCurrentNode
  797. //this._currentNode = vwf_view.kernel.find("", "/")[0];
  798. //this._currentNode = '3333';
  799. },
  800. _getChildNodes: function () {
  801. this._childNodes = self.nodes[this._currentNode];
  802. if (this._childNodes !== undefined) {
  803. return this._childNodes.children
  804. } else {
  805. return []
  806. }
  807. //let nodeIDAlpha = he.encode(this._currentNode);
  808. },
  809. // _getNodeComplexProperties: function () {
  810. // let node = self.nodes[this._currentNode];
  811. // let props = this._getNodeProperties();
  812. // let filterFunction = function (prop) {
  813. // return (prop.name == 'ohmLang')
  814. // };
  815. // let complexProps = props.filter(filterFunction.bind(this));
  816. // return complexProps
  817. // },
  818. _getNodeProperties: function () {
  819. let node = self.nodes[this._currentNode];
  820. this._displayedProperties = {};
  821. let filterFunction = function (prop) {
  822. return (!this._displayedProperties[prop.name] && prop.name.indexOf('$') === -1) ? (this._displayedProperties[prop.name] = "instance", true) : (false);
  823. };
  824. let props = node.properties.filter(filterFunction.bind(this));
  825. return props
  826. },
  827. _getNodeProtoProperties: function () {
  828. let node = self.nodes[this._currentNode];
  829. let filterFunction = function (prop) {
  830. return (!this._displayedProperties[prop[1].prop.name]) ? (this._displayedProperties[prop[1].prop.name] = prop[1].prototype, true) : (false);
  831. };
  832. let props = Object.entries(getProperties.call(self, self.kernel, node.extendsID)).filter(filterFunction.bind(this));
  833. return props
  834. },
  835. $update: function () {
  836. //this.$text = this._currentNode;
  837. var viewerProps = {};
  838. var viewerPropsCell = {};
  839. let node = self.nodes[this._currentNode];
  840. if (node !== undefined) {
  841. if (node.extendsID == "http://vwf.example.com/aframe/acamera.vwf") {
  842. viewerProps = {
  843. $type: "li",
  844. class: "mdc-list-item",
  845. $components: [
  846. {
  847. $text: "Viewer properties",
  848. $type: "span",
  849. class: "mdc-list-item__text mdc-typography--button"
  850. }
  851. ]
  852. }
  853. viewerPropsCell = {
  854. $cell: true,
  855. $type: "div",
  856. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  857. $components: [
  858. {
  859. $cell: true,
  860. $type: "div",
  861. class: "mdc-layout-grid__inner",
  862. $components: [
  863. {
  864. $cell: true,
  865. $type: "div",
  866. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  867. $components: [
  868. {
  869. $cell: true,
  870. $type: "button",
  871. class: "mdc-button mdc-button--raised",
  872. $text: "Active",
  873. onclick: function (e) {
  874. let camera = document.querySelector('#' + this._currentNode);
  875. camera.setAttribute('active', true);
  876. }
  877. }
  878. ]
  879. }
  880. ]
  881. }
  882. ]
  883. //$components: this._getNodeProtoProperties().map(protoPropertiesCell)
  884. }
  885. } else {
  886. viewerProps = {};
  887. viewerPropsCell = {};
  888. }
  889. }
  890. this.$components = [
  891. {
  892. $cell: true,
  893. $type: "ul",
  894. class: "mdc-list",
  895. $components: [
  896. {
  897. $cell: true,
  898. $type: "button",
  899. class: "mdc-list-item mdc-button mdc-button--raised",
  900. $text: "<--",
  901. onclick: function (e) {
  902. let node = self.nodes[this._currentNode];
  903. if (node.parentID !== 0) {
  904. //self.currentNodeID = node.parentID,
  905. document.querySelector('#currentNode')._setNode(node.parentID)
  906. }
  907. }
  908. },
  909. {
  910. $type: "li",
  911. class: "mdc-list-item",
  912. $components: [
  913. {
  914. $text: "name",
  915. $type: "span",
  916. $init: function () {
  917. let node = self.nodes[this._currentNode];
  918. this.$text = node.name
  919. },
  920. class: "mdc-list-item__text mdc-typography--headline"
  921. //<h1 class="mdc-typography--display4">Big header</h1>
  922. }]
  923. }, listDivider,
  924. {
  925. // $cell: true,
  926. // $type: "ul",
  927. // class: "mdc-list",
  928. $type: "div",
  929. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  930. $components: [
  931. {
  932. $type: "div",
  933. class: "mdc-layout-grid__inner",
  934. $components: [
  935. {
  936. $type: "div",
  937. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  938. $components: [
  939. {
  940. $cell: true,
  941. $type: "button",
  942. class: "mdc-button mdc-button--raised",
  943. $text: "Open in code editor",
  944. onclick: function (e) {
  945. var currentNode = document.querySelector('#currentNode')._currentNode;
  946. if (currentNode == '') {
  947. currentNode = vwf_view.kernel.find("", "/")[0];
  948. }
  949. document.querySelector('#liveCodeEditor')._setNode(currentNode);
  950. //createAceEditor(self, currentNode);
  951. document.querySelector('#codeEditorWindow').style.visibility = 'visible';
  952. }
  953. }
  954. ]
  955. }
  956. ]
  957. }
  958. ]
  959. },
  960. listDivider,
  961. {
  962. $type: "li",
  963. class: "mdc-list-item",
  964. $components: [
  965. {
  966. $text: "Children",
  967. $type: "span",
  968. class: "mdc-list-item__text mdc-typography--button"
  969. }]
  970. },
  971. {
  972. $cell: true,
  973. $type: "ul",
  974. class: "mdc-list",
  975. $components: this._getChildNodes().map(nodeLink)
  976. }, listDivider, {
  977. $type: "li",
  978. class: "mdc-list-item",
  979. $components: [
  980. {
  981. $text: "Properties",
  982. $type: "span",
  983. class: "mdc-list-item__text mdc-typography--button"
  984. //<h1 class="mdc-typography--display4">Big header</h1>
  985. }]
  986. },
  987. {
  988. // $cell: true,
  989. // $type: "ul",
  990. // class: "mdc-list",
  991. $type: "div",
  992. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  993. $components: this._getNodeProperties().map(propertiesCell)
  994. },
  995. listDivider,
  996. {
  997. $type: "li",
  998. class: "mdc-list-item",
  999. $components: [
  1000. {
  1001. $text: "Proto properties",
  1002. $type: "span",
  1003. class: "mdc-list-item__text mdc-typography--button"
  1004. }]
  1005. },
  1006. {
  1007. $cell: true,
  1008. $type: "div",
  1009. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1010. $components: this._getNodeProtoProperties().map(protoPropertiesCell)
  1011. }, listDivider,
  1012. viewerProps,
  1013. viewerPropsCell
  1014. ]
  1015. }
  1016. ]
  1017. }
  1018. }
  1019. let propEditorWindow = {
  1020. $cell: true,
  1021. $type: "div",
  1022. _editorNode: '',
  1023. _prop: { body: '', type: 'simple' },
  1024. _propName: '',
  1025. id: "livePropEditor",
  1026. _setNode: function (node) {
  1027. this._editorNode = node;
  1028. this._prop.body = ''
  1029. },
  1030. class: "propEditorGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1031. $update: function () {
  1032. this.$components = [
  1033. {
  1034. $cell: true,
  1035. $type: "div",
  1036. class: "mdc-layout-grid__inner",
  1037. $components: [
  1038. {
  1039. $cell: true,
  1040. $type: "div",
  1041. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1042. $components: [
  1043. {
  1044. $cell: true,
  1045. $type: "button",
  1046. class: "mdc-button mdc-button--raised",
  1047. $text: "Update",
  1048. onclick: function (e) {
  1049. let editor = document.querySelector("#propAceEditor").env.editor;
  1050. let value = editor.getValue();
  1051. try {
  1052. let propValue = (this._prop.type == 'simple') ? (JSON.parse(value)) : (value)
  1053. //propValue = JSON.parse(value);
  1054. self.kernel.setProperty(this._editorNode, this._propName, propValue);
  1055. } catch (e) {
  1056. // restore the original value on error
  1057. this.value = propValue;
  1058. }
  1059. }
  1060. }]
  1061. },
  1062. {
  1063. $cell: true,
  1064. $type: "div",
  1065. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-5",
  1066. $components: [
  1067. {
  1068. $type: "h3",
  1069. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  1070. $text: this._editorNode
  1071. }
  1072. ]
  1073. },
  1074. {
  1075. $cell: true,
  1076. $type: "div",
  1077. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-5",
  1078. $components: [
  1079. {
  1080. $type: "h3",
  1081. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  1082. $text: this._propName
  1083. }
  1084. ]
  1085. }
  1086. ]
  1087. },
  1088. {
  1089. $cell: true,
  1090. $type: "div",
  1091. class: "mdc-layout-grid__inner",
  1092. $components: [
  1093. {
  1094. $cell: true,
  1095. $type: "div",
  1096. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-8",
  1097. $components: [
  1098. {
  1099. $cell: true,
  1100. class: "aceEditor",
  1101. id: "propAceEditor",
  1102. $type: "div",
  1103. $text: this._prop.body,
  1104. $init: function () {
  1105. createAceEditor(self, this._editorNode, "propAceEditor");
  1106. this.env.editor.$blockScrolling = Infinity
  1107. }
  1108. }
  1109. ]
  1110. },
  1111. // {
  1112. // $cell: true,
  1113. // $type: "div",
  1114. // class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1115. // $components: []
  1116. // },
  1117. {
  1118. $cell: true,
  1119. $type: "div",
  1120. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-4",
  1121. $init: function () {
  1122. let myEl = this;
  1123. let cp = ColorPicker(
  1124. document.getElementById('slide'),
  1125. document.getElementById('picker'),
  1126. function (hex, hsv, rgb, mousePicker, mouseSlide) {
  1127. ColorPicker.positionIndicators(
  1128. document.getElementById('slide-indicator'),
  1129. document.getElementById('picker-indicator'),
  1130. mouseSlide, mousePicker
  1131. );
  1132. if (myEl._propName == 'color') {
  1133. // console.log(hex);
  1134. document.querySelector('#propAceEditor').env.editor.setValue(JSON.stringify(hex));
  1135. self.kernel.setProperty(myEl._editorNode, myEl._propName, hex);
  1136. }
  1137. });
  1138. if (myEl._propName == 'color') {
  1139. cp.setHex(JSON.parse(myEl._prop.body));
  1140. }
  1141. },
  1142. $components: [
  1143. {
  1144. $cell: true,
  1145. $type: "div",
  1146. id: "color-picker",
  1147. class: "cp-default",
  1148. $components:[
  1149. {
  1150. $cell: true,
  1151. $type: "div",
  1152. class: "picker-wrapper",
  1153. $components: [
  1154. {
  1155. $cell: true,
  1156. $type: "div",
  1157. id: "picker",
  1158. class: "picker",
  1159. style: "width: 130px; height: 130px"
  1160. },
  1161. {
  1162. $cell: true,
  1163. $type: "div",
  1164. id: "picker-indicator",
  1165. class: "picker-indicator"
  1166. }
  1167. ]
  1168. },
  1169. {
  1170. $cell: true,
  1171. $type: "div",
  1172. class: "slide-wrapper",
  1173. $components: [
  1174. {
  1175. $cell: true,
  1176. $type: "div",
  1177. id: "slide",
  1178. class: "slide",
  1179. style: "width: 30px; height: 130px"
  1180. },
  1181. {
  1182. $cell: true,
  1183. $type: "div",
  1184. id: "slide-indicator",
  1185. class: "slide-indicator"
  1186. }
  1187. ]
  1188. }
  1189. ]
  1190. }
  1191. // {
  1192. // $cell: true,
  1193. // $type: "div",
  1194. // id: "color-picker",
  1195. // $init: function () {
  1196. // }
  1197. // }
  1198. ]
  1199. }
  1200. ]
  1201. }
  1202. ]
  1203. //$components:
  1204. }
  1205. }
  1206. let codeEditorWindow = {
  1207. $cell: true,
  1208. $type: "div",
  1209. _editorNode: '',
  1210. _method: { body: '' },
  1211. _methodName: '',
  1212. _getNodeMethods: function () {
  1213. let node = self.nodes[this._editorNode];
  1214. return node.methods
  1215. },
  1216. _getProtoNodeMethods: function () {
  1217. let node = self.nodes[this._editorNode];
  1218. let prototypeMethods = getMethods.call(self, self.kernel, node.extendsID);
  1219. return prototypeMethods
  1220. },
  1221. id: "liveCodeEditor",
  1222. _setNode: function (node) {
  1223. this._editorNode = node;
  1224. this._method.body = ''
  1225. },
  1226. class: "codeEditorGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1227. // _getComplexProps: function(){
  1228. // let node = self.nodes[this._editorNode];
  1229. // let currentNode = document.querySelector('#currentNode');
  1230. // var props = {}
  1231. // if (currentNode !== null) {
  1232. // props = currentNode._getNodeComplexProperties();
  1233. // }
  1234. // return props
  1235. // },
  1236. // _listPropertyElement: function (m) {
  1237. // return {
  1238. // $type: "li",
  1239. // class: "mdc-list-item",
  1240. // $components: [{
  1241. // $type: "a",
  1242. // class: "mdc-list-item",
  1243. // $href: "#",
  1244. // $text: m[1].name,
  1245. // onclick: function (e) {
  1246. // this._method = {};
  1247. // this._methodName = m[1].name;
  1248. // this._method.body = m[1].rawValue
  1249. // this._method.type = "complexProperty"
  1250. // }
  1251. // }]
  1252. // }
  1253. // },
  1254. _listElement: function (m) {
  1255. return {
  1256. $type: "li",
  1257. class: "mdc-list-item",
  1258. $components: [{
  1259. $type: "a",
  1260. class: "mdc-list-item",
  1261. $href: "#",
  1262. $text: m[0],
  1263. onclick: function (e) {
  1264. let method = vwf.getMethod(this._editorNode, m[0]);
  1265. //document.querySelector('#aceEditor').
  1266. this._method = method;
  1267. this._methodName = m[0];
  1268. //self.currentNodeID = m.ID;
  1269. //document.querySelector('#currentNode')._setNode(m.ID);
  1270. }
  1271. }]
  1272. }
  1273. },
  1274. $update: function () {
  1275. this.$components = [
  1276. {
  1277. $cell: true,
  1278. $type: "div",
  1279. class: "mdc-layout-grid__inner",
  1280. $components: [
  1281. {
  1282. $cell: true,
  1283. $type: "div",
  1284. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1285. $components: [
  1286. {
  1287. $type: "h3",
  1288. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  1289. $text: this._editorNode
  1290. }
  1291. ]
  1292. },
  1293. {
  1294. $cell: true,
  1295. $type: "div",
  1296. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1297. $components: [
  1298. {
  1299. $cell: true,
  1300. $type: "button",
  1301. class: "mdc-button mdc-button--raised",
  1302. $text: "Update",
  1303. onclick: function (e) {
  1304. let editor = document.querySelector("#aceEditor").env.editor;
  1305. let evalText = editor.getValue();
  1306. // if (this._method.type == 'complexProperty') {
  1307. // let propValue = evalText;
  1308. // try {
  1309. // //propValue = JSON.parse(propValue);
  1310. // self.kernel.setProperty(this._editorNode, this._methodName, propValue);
  1311. // } catch (e) {
  1312. // // restore the original value on error
  1313. // this.value = propValue;
  1314. // }
  1315. // } else {
  1316. // }
  1317. self.kernel.setMethod(this._editorNode, this._methodName,
  1318. { body: evalText, type: "application/javascript", parameters: this._method.parameters });
  1319. }
  1320. }]
  1321. },
  1322. {
  1323. $cell: true,
  1324. $type: "div",
  1325. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1326. $components: [
  1327. {
  1328. $cell: true,
  1329. $type: "button",
  1330. class: "mdc-button mdc-button--raised",
  1331. $text: "Call",
  1332. onclick: function (e) {
  1333. var params = [];
  1334. if (this._method.parameters) {
  1335. let paramsLength = this._method.parameters.length
  1336. if (paramsLength >= 1) {
  1337. let paramsVal = document.querySelector("#methodParams").value;
  1338. try {
  1339. params = JSON.parse(paramsVal);
  1340. //params.push(prmtr);
  1341. } catch (e) {
  1342. self.logger.error('Invalid Value');
  1343. }
  1344. }
  1345. };
  1346. self.kernel.callMethod(this._editorNode, this._methodName, params);
  1347. }
  1348. }]
  1349. },
  1350. {
  1351. $cell: true,
  1352. $type: "div",
  1353. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1354. $components: [
  1355. {
  1356. $cell: true,
  1357. $type: "button",
  1358. class: "mdc-button mdc-button--raised",
  1359. $text: "Do It",
  1360. onclick: function (e) {
  1361. let editor = document.querySelector("#aceEditor").env.editor;
  1362. codeEditorDoit.call(self, editor, this._editorNode);
  1363. }
  1364. }]
  1365. },
  1366. {
  1367. $cell: true,
  1368. $type: "div",
  1369. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1370. $components: [
  1371. {
  1372. $cell: true,
  1373. $type: "button",
  1374. class: "mdc-button mdc-button--raised",
  1375. $text: "Print It",
  1376. onclick: function (e) {
  1377. let editor = document.querySelector("#aceEditor").env.editor;
  1378. codeEditorPrintit.call(self, editor, this._editorNode);
  1379. }
  1380. }]
  1381. }
  1382. ]
  1383. },
  1384. {
  1385. $cell: true,
  1386. $type: "div",
  1387. class: "mdc-layout-grid__inner",
  1388. $components: [
  1389. {
  1390. $cell: true,
  1391. $type: "div",
  1392. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1393. style: "overflow-y: scroll; max-height: 400px;",
  1394. $components: [
  1395. {
  1396. $cell: true,
  1397. $type: "div",
  1398. class: "mdc-list-group",
  1399. $components: [
  1400. {
  1401. $type: "h3",
  1402. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  1403. $text: "Node methods"
  1404. },
  1405. {
  1406. $cell: true,
  1407. $type: "ul",
  1408. class: "mdc-list",
  1409. $components: Object.entries(this._getNodeMethods()).map(this._listElement)
  1410. }, listDivider,
  1411. {
  1412. $type: "h3",
  1413. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  1414. $text: "Proto methods"
  1415. },
  1416. {
  1417. $cell: true,
  1418. $type: "ul",
  1419. class: "mdc-list",
  1420. $components: Object.entries(this._getProtoNodeMethods()).map(this._listElement)
  1421. }, listDivider,
  1422. {
  1423. $type: "h3",
  1424. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  1425. $text: "Events"
  1426. }
  1427. // {
  1428. // $cell: true,
  1429. // $type: "ul",
  1430. // class: "mdc-list",
  1431. // $components: Object.entries(this._getComplexProps()).map(this._listPropertyElement)
  1432. // }
  1433. ]
  1434. }
  1435. ]
  1436. },
  1437. {
  1438. $cell: true,
  1439. $type: "div",
  1440. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-9",
  1441. $components: [
  1442. {
  1443. $cell: true,
  1444. class: "aceEditor",
  1445. id: "aceEditor",
  1446. $type: "div",
  1447. $text: this._method.body,
  1448. $init: function () {
  1449. createAceEditor(self, this._editorNode, "aceEditor");
  1450. }
  1451. }
  1452. ]
  1453. }
  1454. ]
  1455. },
  1456. {
  1457. $cell: true,
  1458. $type: "div",
  1459. class: "mdc-layout-grid__inner",
  1460. $components: [
  1461. {
  1462. $cell: true,
  1463. $type: "div",
  1464. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1465. $components: [
  1466. {
  1467. $type: "span",
  1468. $text: "-"
  1469. }
  1470. ]
  1471. }
  1472. ]
  1473. },
  1474. { //params input
  1475. $cell: true,
  1476. $type: "div",
  1477. class: "mdc-layout-grid__inner",
  1478. $components: [
  1479. {
  1480. $cell: true,
  1481. $type: "div",
  1482. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1483. $components: [
  1484. {
  1485. class: "mdc-textfield",
  1486. $cell: true,
  1487. $type: "div",
  1488. $components: [{
  1489. class: "mdc-textfield__input",
  1490. id: "methodName",
  1491. $cell: true,
  1492. $type: "input",
  1493. type: "text",
  1494. value: "newMethodName",
  1495. onchange: function (e) {
  1496. let propValue = this.value;
  1497. try {
  1498. } catch (e) {
  1499. // restore the original value on error
  1500. }
  1501. }
  1502. }]
  1503. }
  1504. ]
  1505. },
  1506. {
  1507. $cell: true,
  1508. $type: "div",
  1509. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-7",
  1510. $components: [
  1511. {
  1512. class: "mdc-textfield params-textfield-input",
  1513. $cell: true,
  1514. $type: "div",
  1515. $components: [{
  1516. class: "mdc-textfield__input",
  1517. id: "methodParams",
  1518. $cell: true,
  1519. $type: "input",
  1520. type: "text",
  1521. value: JSON.stringify(this._method.parameters),
  1522. onchange: function (e) {
  1523. let propValue = this.value;
  1524. try {
  1525. } catch (e) {
  1526. // restore the original value on error
  1527. }
  1528. }
  1529. }]
  1530. }
  1531. ]
  1532. },
  1533. {
  1534. $cell: true,
  1535. $type: "div",
  1536. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1537. $components: [
  1538. {
  1539. $cell: true,
  1540. $type: "button",
  1541. class: "mdc-button mdc-button--raised",
  1542. $text: "Create",
  1543. onclick: function (e) {
  1544. let methodName = document.querySelector('#methodName').value;
  1545. //let methodParams = document.querySelector('#methodParams');
  1546. var params = [];
  1547. let body = '';
  1548. let paramsVal = document.querySelector("#methodParams").value;
  1549. if (paramsVal !== '') {
  1550. try {
  1551. params = JSON.parse(paramsVal);
  1552. //params.push(prmtr);
  1553. } catch (e) {
  1554. self.logger.error('Invalid Value');
  1555. }
  1556. }
  1557. self.kernel.createMethod(this._editorNode, methodName, params, body);
  1558. this._setNode(this._editorNode);
  1559. // let editor = document.querySelector("#aceEditor").env.editor;
  1560. // codeEditorDoit.call(self, editor, this._editorNode);
  1561. }
  1562. }
  1563. ]
  1564. }
  1565. ]
  1566. }
  1567. ]
  1568. //$components:
  1569. }
  1570. }
  1571. let propWindow = {
  1572. $cell: true,
  1573. $type: "div",
  1574. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1575. style: "overflow-y: scroll; max-height: 800px;",
  1576. $components: [
  1577. {
  1578. $type: "div",
  1579. class: "mdc-layout-grid__inner",
  1580. $components: [
  1581. {
  1582. $cell: true,
  1583. $type: "div",
  1584. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1585. $components: [
  1586. nodesCell
  1587. ]
  1588. }
  1589. ]
  1590. }
  1591. // <button class="mdc-button">
  1592. // Flat button
  1593. // </button>
  1594. ]
  1595. }
  1596. let clientListCell = {
  1597. $cell: true,
  1598. $type: "div",
  1599. class: "mdc-list",
  1600. id: "clientsList",
  1601. _watchNodes: [],
  1602. _listElement: function (m) {
  1603. return {
  1604. $type: "a",
  1605. class: "mdc-list-item",
  1606. $href: "#",
  1607. $text: m.name,
  1608. onclick: function (e) {
  1609. //self.currentNodeID = m.ID;
  1610. //document.querySelector('#currentNode')._setNode(m.ID);
  1611. }
  1612. }
  1613. },
  1614. $init: function () {
  1615. var t = this;
  1616. setInterval(function () {
  1617. t._updateMe();
  1618. }, 1000);
  1619. },
  1620. _updateMe: function () {
  1621. this._watchNodes = self.nodes["http://vwf.example.com/clients.vwf"].children.slice()
  1622. },
  1623. $update: function () {
  1624. //this._clientNodes
  1625. this.$components = this._watchNodes.map(this._listElement)
  1626. }
  1627. }
  1628. //createCellWindow("clientsWindow", clientListCell, "Clients");
  1629. //createCellWindow("propWindow", propWindow, "Scene");
  1630. createCellWindow("codeEditorWindow", codeEditorWindow, "Code editor");
  1631. createCellWindow("propEditorWindow", propEditorWindow, "Prop editor");
  1632. let viewSceneProps = {
  1633. $cell: true,
  1634. $type: "div",
  1635. class: "propGrid mdc-layout-grid mdc-layout-grid--align-left",
  1636. //style: "overflow-y: scroll; max-height: 500px; overflow-x: hidden;",
  1637. $components: [
  1638. {
  1639. $type: "div",
  1640. class: "mdc-layout-grid__inner",
  1641. $components: [
  1642. {
  1643. $cell: true,
  1644. $type: "div",
  1645. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1646. $components: [
  1647. nodesCell
  1648. ]
  1649. }
  1650. ]
  1651. }
  1652. ]
  1653. }
  1654. let sideBar = {
  1655. $cell: true,
  1656. $type: "div",
  1657. id: 'sideBar',
  1658. class: "sideBar mdc-toolbar-fixed-adjust",
  1659. _sideBarComponent: {},
  1660. _sideCurrentNode: '',
  1661. $init: function () {
  1662. this.style.visibility = 'hidden';
  1663. this._importScript("/" + self.getRoot() + "/appui.js");
  1664. },
  1665. _importScript: function (sSrc, fOnload) {
  1666. var oScript = document.createElement("script");
  1667. oScript.type = "text\/javascript";
  1668. oScript.async = false;
  1669. //oScript.onerror = loadError;
  1670. if (fOnload) { oScript.onload = fOnload; }
  1671. oScript.src = sSrc;
  1672. //let sideBar = document.querySelector('#sideBar');
  1673. this.appendChild(oScript);
  1674. },
  1675. _getAppDef: async function () {
  1676. let response = await fetch("/" + self.getRoot() + "/appui.js");
  1677. let data = await response.text();
  1678. //console.log(data)
  1679. return data
  1680. },
  1681. $update: function () {
  1682. this.$components = [
  1683. {
  1684. $cell: true,
  1685. $type: "button",
  1686. class: "mdc-button mdc-button--compact",
  1687. $text: "X",
  1688. onclick: function (e) {
  1689. document.querySelector('#sideBar').style.visibility = 'hidden';
  1690. }
  1691. },
  1692. this._sideBarComponent
  1693. ]
  1694. }
  1695. //$components: [this._sideComponents]
  1696. }
  1697. document.querySelector('#' + 'sideBar').$cell(sideBar)
  1698. let defaultApp = function () {
  1699. return {
  1700. $cell: true,
  1701. $type: "div",
  1702. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  1703. $components: [
  1704. {
  1705. $cell: true,
  1706. $type: "div",
  1707. class: "mdc-layout-grid__inner",
  1708. $components: [
  1709. {
  1710. $cell: true,
  1711. $type: "div",
  1712. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1713. $components: [
  1714. {
  1715. $cell: true,
  1716. $type: "h3",
  1717. class: "mdc-typography--headline",
  1718. $text: "Application",
  1719. }
  1720. ]
  1721. }
  1722. ]
  1723. }
  1724. ]
  1725. }
  1726. }
  1727. let drawerCell = {
  1728. $cell: true,
  1729. $type: "nav",
  1730. class: "mdc-temporary-drawer__drawer",
  1731. $components: [
  1732. {
  1733. $cell: true,
  1734. $type: "header",
  1735. class: "mdc-temporary-drawer__header",
  1736. $components: [
  1737. {
  1738. $cell: true,
  1739. $type: "div",
  1740. class: "mdc-temporary-drawer__header-content mdc-theme--primary-bg mdc-theme--text-primary-on-primary",
  1741. $text: "Home"
  1742. }
  1743. ]
  1744. },
  1745. {
  1746. $cell: true,
  1747. $type: "nav",
  1748. class: "mdc-temporary-drawer__content mdc-list-group",
  1749. $components: [
  1750. {
  1751. $cell: true,
  1752. $type: "div",
  1753. class: "mdc-list",
  1754. $components: [
  1755. {
  1756. $cell: true,
  1757. $type: "a",
  1758. class: "mdc-list-item",
  1759. $href: "#",
  1760. onclick: function (e) {
  1761. let sideBar = document.querySelector('#sideBar');
  1762. try {
  1763. sideBar._sideBarComponent = createApp();
  1764. } catch (e) {
  1765. sideBar._sideBarComponent = defaultApp();
  1766. }
  1767. drawer.open = !drawer.open
  1768. document.querySelector('#sideBar').style.visibility = 'visible';
  1769. },
  1770. $components: [{
  1771. $type: "i",
  1772. class: "material-icons mdc-list-item__start-detail",
  1773. 'aria-hidden': "true",
  1774. $text: "play_arrow"
  1775. },
  1776. {
  1777. $text: "App"
  1778. }]
  1779. },
  1780. {
  1781. $cell: true,
  1782. $type: "a",
  1783. class: "mdc-list-item",
  1784. $href: "#",
  1785. onclick: function (e) {
  1786. let sideBar = document.querySelector('#sideBar');
  1787. sideBar._sideBarComponent = viewSceneProps;
  1788. let currentNode = document.querySelector('#sideBar')._sideCurrentNode;
  1789. currentNode == '' ? document.querySelector('#sideBar')._sideCurrentNode = (vwf_view.kernel.find("", "/")[0]) :
  1790. document.querySelector('#sideBar')._sideCurrentNode = currentNode;
  1791. document.querySelector('#sideBar').style.visibility = 'visible';
  1792. drawer.open = !drawer.open
  1793. // let currentNode = document.querySelector('#currentNode')._currentNode;
  1794. // currentNode == '' ? document.querySelector('#currentNode')._setNode(vwf_view.kernel.find("", "/")[0]) :
  1795. // document.querySelector('#currentNode')._setNode(currentNode);
  1796. },
  1797. $components: [{
  1798. $cell: true,
  1799. $type: "i",
  1800. class: "material-icons mdc-list-item__start-detail",
  1801. $text: "description"
  1802. },
  1803. {
  1804. $text: "Scene"
  1805. }
  1806. ]
  1807. },
  1808. {
  1809. $cell: true,
  1810. $type: "a",
  1811. class: "mdc-list-item",
  1812. $href: "#",
  1813. onclick: function (e) {
  1814. // var currentNode = document.querySelector('#currentNode')._currentNode;
  1815. // if (currentNode == '') {
  1816. // currentNode = vwf_view.kernel.find("", "/")[0];
  1817. // }
  1818. document.querySelector('#liveCodeEditor')._setNode(vwf_view.kernel.find("", "/")[0]);
  1819. //createAceEditor(self, currentNode);
  1820. document.querySelector('#codeEditorWindow').style.visibility = 'visible';
  1821. },
  1822. $components: [{
  1823. $type: "i",
  1824. class: "material-icons mdc-list-item__start-detail",
  1825. 'aria-hidden': "true",
  1826. $text: "code"
  1827. },
  1828. {
  1829. $text: "Code editor"
  1830. }]
  1831. },
  1832. {
  1833. $cell: true,
  1834. $type: "a",
  1835. class: "mdc-list-item",
  1836. $href: "#",
  1837. onclick: function (e) {
  1838. //self.currentNodeID = m.ID;
  1839. // document.querySelector('#clientsList')._setClientNodes(self.nodes["http://vwf.example.com/clients.vwf"]);
  1840. // document.querySelector('#clientsWindow').style.visibility = 'visible';
  1841. let sideBar = document.querySelector('#sideBar');
  1842. sideBar._sideBarComponent = avatarSettings;
  1843. drawer.open = !drawer.open
  1844. document.querySelector('#sideBar').style.visibility = 'visible';
  1845. },
  1846. $components: [{
  1847. $type: "i",
  1848. class: "material-icons mdc-list-item__start-detail",
  1849. 'aria-hidden': "true",
  1850. $text: "account_circle"
  1851. },
  1852. {
  1853. $text: "My Avatar"
  1854. }]
  1855. },
  1856. {
  1857. $cell: true,
  1858. $type: "a",
  1859. class: "mdc-list-item",
  1860. $href: "#",
  1861. onclick: function (e) {
  1862. //self.currentNodeID = m.ID;
  1863. // document.querySelector('#clientsList')._setClientNodes(self.nodes["http://vwf.example.com/clients.vwf"]);
  1864. let sideBar = document.querySelector('#sideBar');
  1865. sideBar._sideBarComponent = viewSettings;
  1866. drawer.open = !drawer.open
  1867. document.querySelector('#sideBar').style.visibility = 'visible';
  1868. },
  1869. $components: [{
  1870. $type: "i",
  1871. class: "material-icons mdc-list-item__start-detail",
  1872. 'aria-hidden': "true",
  1873. $text: "settings"
  1874. },
  1875. {
  1876. $text: "Settings"
  1877. }]
  1878. },
  1879. {
  1880. $cell: true,
  1881. $type: "a",
  1882. class: "mdc-list-item",
  1883. $href: "#",
  1884. onclick: function (e) {
  1885. //self.currentNodeID = m.ID;
  1886. // document.querySelector('#clientsList')._setClientNodes(self.nodes["http://vwf.example.com/clients.vwf"]);
  1887. let sideBar = document.querySelector('#sideBar');
  1888. sideBar._sideBarComponent = loadSaveSettings;
  1889. if (document.querySelector('#loadSaveSettings')) {
  1890. document.querySelector('#loadSaveSettings')._getStates();
  1891. }
  1892. //sideBar._sideBarComponent._getStates();
  1893. drawer.open = !drawer.open
  1894. document.querySelector('#sideBar').style.visibility = 'visible';
  1895. },
  1896. $components: [{
  1897. $type: "i",
  1898. class: "material-icons mdc-list-item__start-detail",
  1899. 'aria-hidden': "true",
  1900. $text: "save"
  1901. },
  1902. {
  1903. $text: "Load/Save"
  1904. }]
  1905. }
  1906. ]
  1907. },
  1908. {
  1909. $cell: true,
  1910. $type: "hr",
  1911. class: "mdc-list-divider",
  1912. },
  1913. {
  1914. $cell: true,
  1915. $type: "h3",
  1916. class: "userList mdc-list-group__subheader",
  1917. $text: "Users online"
  1918. },
  1919. clientListCell
  1920. ]
  1921. }
  1922. // {
  1923. // $cell: true,
  1924. // $type: "div",
  1925. // class: "mdc-persistent-drawer__toolbar-spacer",
  1926. // },
  1927. // {
  1928. // $cell: true,
  1929. // $type: "div",
  1930. // class: "mdc-list-group",
  1931. // $components: [{
  1932. // $cell: true,
  1933. // $type: "nav",
  1934. // class: "mdc-list",
  1935. // $components: [
  1936. // ]
  1937. // }]
  1938. // }
  1939. ]
  1940. };
  1941. // <div class="mdc-form-field">
  1942. // <input type="checkbox" id="input">
  1943. // <label for="input">Input Label</label>
  1944. // </div>
  1945. document.querySelector("#drawer").$cell({
  1946. $cell: true,
  1947. $type: "aside",
  1948. class: "mdc-temporary-drawer",
  1949. $components: [drawerCell]
  1950. }
  1951. );
  1952. let toolbar = {
  1953. $cell: true,
  1954. $type: "div",
  1955. class: "mdc-toolbar__row",
  1956. $components: [{
  1957. $type: "section",
  1958. class: "mdc-toolbar__section mdc-toolbar__section--align-start",
  1959. $components: [
  1960. {
  1961. $type: "button",
  1962. class: "demo-menu material-icons mdc-toolbar__icon--menu",
  1963. $text: "menu"
  1964. },
  1965. {
  1966. $type: "span",
  1967. class: "mdc-toolbar__title catalog-title",
  1968. $text: "LiveCoding.space"
  1969. }
  1970. ]
  1971. }]
  1972. };
  1973. document.querySelector("#toolbar").$cell({
  1974. $cell: true,
  1975. $type: "div",
  1976. class: "mdc-toolbar mdc-toolbar--fixed",
  1977. $components: [toolbar]
  1978. }
  1979. );
  1980. // let drawer = new mdc.drawer.MDCTemporaryDrawer(document.querySelector('.mdc-temporary-drawer'));
  1981. // document.querySelector('.menu').addEventListener('click', () => drawer.open = true);
  1982. var drawerEl = document.querySelector('.mdc-temporary-drawer');
  1983. var MDCTemporaryDrawer = mdc.drawer.MDCTemporaryDrawer;
  1984. var drawer = new MDCTemporaryDrawer(drawerEl);
  1985. document.querySelector('.demo-menu').addEventListener('click', function () {
  1986. //self.currentNodeID = (self.currentNodeID == '') ? (vwf_view.kernel.find("", "/")[0]) : self.currentNodeID;
  1987. // let currentNode = document.querySelector('#currentNode')._currentNode;
  1988. // currentNode == '' ? document.querySelector('#currentNode')._setNode(vwf_view.kernel.find("", "/")[0]) :
  1989. // document.querySelector('#currentNode')._setNode(currentNode);
  1990. //document.querySelector('#currentNode')._setNode(self.currentNodeID);
  1991. drawer.open = !drawer.open;
  1992. });
  1993. drawerEl.addEventListener('MDCTemporaryDrawer:open', function () {
  1994. //console.log('Received MDCPersistentDrawer:open');
  1995. });
  1996. drawerEl.addEventListener('MDCTemporaryDrawer:close', function () {
  1997. //console.log('Received MDCPersistentDrawer:close');
  1998. });
  1999. //==============
  2000. $('#tabs').stop().animate({ opacity: 0.0 }, 0);
  2001. $('#tabs').mouseenter(function (evt) {
  2002. evt.stopPropagation();
  2003. $('#tabs').stop().animate({ opacity: 1.0 }, 175);
  2004. return false;
  2005. });
  2006. $('#tabs').mouseleave(function (evt) {
  2007. evt.stopPropagation();
  2008. $('#tabs').stop().animate({ opacity: 0.0 }, 175);
  2009. return false;
  2010. });
  2011. $('#hierarchy').click(function (evt) {
  2012. openEditor.call(self, 1);
  2013. });
  2014. $('#userlist').click(function (evt) {
  2015. openEditor.call(self, 2);
  2016. });
  2017. $('#timeline').click(function (evt) {
  2018. openEditor.call(self, 3);
  2019. });
  2020. $('#about').click(function (evt) {
  2021. openEditor.call(self, 4);
  2022. });
  2023. $('#models').click(function (evt) {
  2024. openEditor.call(self, 5);
  2025. });
  2026. $('#codeEditor').click(function (evt) {
  2027. openEditor.call(self, 6);
  2028. });
  2029. $('#x').click(function (evt) {
  2030. closeEditor.call(self);
  2031. });
  2032. $('#topdown_a').hide();
  2033. $('#topdown_b').hide();
  2034. $('#client_list').hide();
  2035. $('#time_control').hide();
  2036. $('#about_tab').hide();
  2037. $('#codeEditor_tab').hide();
  2038. $('#model_a').hide();
  2039. $('#model_b').hide();
  2040. var canvas = document.getElementById(vwf_view.kernel.find("", "/")[0]);
  2041. if (canvas) {
  2042. $('#topdown_a').height(canvas.height);
  2043. $('#topdown_b').height(canvas.height);
  2044. $('#client_list').height(canvas.height);
  2045. $('#time_control').height(canvas.height);
  2046. $('#about_tab').height(canvas.height);
  2047. $('#codeEditor_tab').height(canvas.height);
  2048. $('#model_a').height(canvas.height);
  2049. $('#model_b').height(canvas.height);
  2050. }
  2051. else {
  2052. $('#topdown_a').height(window.innerHeight - 20);
  2053. $('#topdown_b').height(window.innerHeight - 20);
  2054. $('#client_list').height(window.innerHeight - 20);
  2055. $('#time_control').height(window.innerHeight - 20);
  2056. $('#about_tab').height(window.innerHeight - 20);
  2057. $('#codeEditor_tab').height(window.innerHeight - 20);
  2058. $('#model_a').height(window.innerHeight - 20);
  2059. $('#model_b').height(window.innerHeight - 20);
  2060. }
  2061. },
  2062. createdNode: function (nodeID, childID, childExtendsID, childImplementsIDs,
  2063. childSource, childType, childIndex, childName, callback /* ( ready ) */) {
  2064. var nodeIDAttribute = $.encoder.encodeForHTMLAttribute("id", nodeID, true);
  2065. var childIDAttribute = $.encoder.encodeForHTMLAttribute("id", childID, true);
  2066. var childIDAlpha = $.encoder.encodeForAlphaNumeric(childID);
  2067. var kernel = this.kernel;
  2068. var self = this;
  2069. var parent = this.nodes[nodeID];
  2070. var node = this.nodes[childID] = {
  2071. children: [],
  2072. properties: [],
  2073. events: {},
  2074. methods: {},
  2075. parent: parent,
  2076. parentID: nodeID,
  2077. ID: childID,
  2078. extendsID: childExtendsID,
  2079. implementsIDs: childImplementsIDs,
  2080. source: childSource,
  2081. name: childName,
  2082. };
  2083. if (parent) {
  2084. parent.children.push(node);
  2085. }
  2086. if (childID == vwf_view.kernel.find("", "/")[0] && childExtendsID && this.kernel.test(childExtendsID,
  2087. "self::element(*,'http://vwf.example.com/aframe/ascene.vwf')", childExtendsID)) {
  2088. this.scenes[childID] = node;
  2089. }
  2090. if (nodeID === this.currentNodeID && this.editingScript == false) {
  2091. $('#children > div:last').css('border-bottom-width', '1px');
  2092. $("#children").append("<div id='" + childIDAlpha + "' data-nodeID='" + childIDAttribute + "' class='childContainer'><div class='childEntry'><b>" + $.encoder.encodeForHTML(childName) + "</b></div></div>");
  2093. $('#' + childIDAlpha).click(function (evt) {
  2094. drillDown.call(self, $(this).attr("data-nodeID"), nodeIDAttribute);
  2095. });
  2096. $('#children > div:last').css('border-bottom-width', '3px');
  2097. }
  2098. if (nodeID === this.kernel.application() && childName === 'camera') {
  2099. this.activeCameraID = childID;
  2100. }
  2101. let nodeCell = document.querySelector("#currentNode");
  2102. if (nodeCell !== null) {
  2103. if (nodeCell._currentNode === nodeID) {
  2104. nodeCell._getChildNodes();
  2105. }
  2106. }
  2107. if (nodeID === this.kernel.application()) {
  2108. // document.querySelector('a-scene').classList.add("mdc-toolbar-fixed-adjust");
  2109. document.querySelector('body').classList.add("editor-body");
  2110. }
  2111. },
  2112. createdProperty: function (nodeID, propertyName, propertyValue) {
  2113. return this.initializedProperty(nodeID, propertyName, propertyValue);
  2114. },
  2115. initializedProperty: function (nodeID, propertyName, propertyValue) {
  2116. var node = this.nodes[nodeID];
  2117. if (!node) return; // TODO: patch until full-graph sync is working; drivers should be able to assume that nodeIDs refer to valid objects
  2118. var property = node.properties[propertyName] = createProperty.call(this, node, propertyName, propertyValue);
  2119. node.properties.push(property);
  2120. },
  2121. deletedNode: function (nodeID) {
  2122. var node = this.nodes[nodeID];
  2123. node.parent.children.splice(node.parent.children.indexOf(node), 1);
  2124. delete this.nodes[nodeID];
  2125. var nodeIDAttribute = $.encoder.encodeForAlphaNumeric(nodeID); // $.encoder.encodeForHTMLAttribute("id", nodeID, true);
  2126. $('#' + nodeIDAttribute).remove();
  2127. $('#children > div:last').css('border-bottom-width', '3px');
  2128. let nodeCell = document.querySelector("#currentNode");
  2129. if (nodeCell) {
  2130. if (nodeCell._currentNode !== "") {
  2131. if (nodeCell._currentNode !== nodeID && (this.nodes[nodeID] !== undefined)) {
  2132. nodeCell._getChildNodes();
  2133. } else {
  2134. nodeCell._setNode(vwf_view.kernel.find("", "/")[0]);
  2135. nodeCell._getChildNodes();
  2136. }
  2137. }
  2138. }
  2139. },
  2140. //addedChild: [ /* nodeID, childID, childName */ ],
  2141. //removedChild: [ /* nodeID, childID */ ],
  2142. satProperty: function (nodeID, propertyName, propertyValue) {
  2143. var node = this.nodes[nodeID];
  2144. if (!node) return; // TODO: patch until full-graph sync is working; drivers should be able to assume that nodeIDs refer to valid objects
  2145. // It is possible for a property to have satProperty called for it without ever getting an
  2146. // initializedProperty (if that property delegated to itself or another on replication)
  2147. // Catch that case here and create the property
  2148. if (!node.properties[propertyName]) {
  2149. var property = node.properties[propertyName] = createProperty.call(this, node, propertyName, propertyValue);
  2150. node.properties.push(property);
  2151. }
  2152. if (propertyName === "activeCamera") {
  2153. if (this.nodes[propertyValue] !== undefined) {
  2154. this.activeCameraID = propertyValue;
  2155. }
  2156. }
  2157. try {
  2158. propertyValue = utility.transform(propertyValue, utility.transforms.transit);
  2159. node.properties[propertyName].value = JSON.stringify(propertyValue);
  2160. node.properties[propertyName].rawValue = propertyValue;
  2161. } catch (e) {
  2162. this.logger.warnx("satProperty", nodeID, propertyName, propertyValue,
  2163. "stringify error:", e.message);
  2164. node.properties[propertyName].value = propertyValue;
  2165. }
  2166. if ((this.editorView == 1) && (this.currentNodeID == nodeID)) {
  2167. var nodeIDAttribute = $.encoder.encodeForAlphaNumeric(nodeID); // $.encoder.encodeForHTMLAttribute("id", nodeID, true);
  2168. var propertyNameAttribute = $.encoder.encodeForAlphaNumeric("id", propertyName, true);
  2169. // No need to escape propertyValue, because .val does its own escaping
  2170. $('#input-' + nodeIDAttribute + '-' + propertyNameAttribute).val(node.properties[propertyName].getValue());
  2171. }
  2172. let propCell = document.querySelector("#currentNode #prop-" + propertyName);
  2173. if (propCell !== null) {
  2174. if (propCell._currentNode == nodeID) {
  2175. propCell.value = node.properties[propertyName].getValue();
  2176. }
  2177. }
  2178. },
  2179. //gotProperty: [ /* nodeID, propertyName, propertyValue */ ],
  2180. createdMethod: function (nodeID, methodName, methodParameters, methodBody) {
  2181. var node = this.nodes[nodeID];
  2182. if (node) {
  2183. node.methods[methodName] = methodParameters;
  2184. }
  2185. },
  2186. //calledMethod: function( nodeID, methodName, methodParameters, methodValue ) {
  2187. //},
  2188. createdEvent: function (nodeID, eventName, eventParameters) {
  2189. var node = this.nodes[nodeID];
  2190. if (node) {
  2191. node.events[eventName] = eventParameters;
  2192. }
  2193. },
  2194. firedEvent: function (nodeID, eventName, eventParameters) {
  2195. if (eventName == "pointerHover") {
  2196. highlightChildInHierarchy.call(this, nodeID);
  2197. }
  2198. },
  2199. executed: function (nodeID, scriptText, scriptType) {
  2200. // var nodeScript = {
  2201. // text: scriptText,
  2202. // type: scriptType,
  2203. // };
  2204. // if ( !this.allScripts[ nodeID ] ) {
  2205. // var nodeScripts = new Array();
  2206. // nodeScripts.push(nodeScript);
  2207. // this.allScripts[ nodeID ] = nodeScripts;
  2208. // }
  2209. // else {
  2210. // this.allScripts[ nodeID ].push(nodeScript);
  2211. // }
  2212. },
  2213. //ticked: [ /* time */ ],
  2214. });
  2215. function createCellWindow(elementID, cellNode, title) {
  2216. document.querySelector('#' + elementID).$cell({
  2217. $cell: true,
  2218. $type: "div",
  2219. id: elementID,
  2220. class: 'draggable',
  2221. $init: function () {
  2222. // let draggie = new Draggabilly('.draggable', {
  2223. // handle: '.handle',
  2224. // containment: true
  2225. // });
  2226. // get all draggie elements
  2227. var draggableElems = document.querySelectorAll('.draggable');
  2228. // array of Draggabillies
  2229. var draggies = []
  2230. // init Draggabillies
  2231. for (var i = 0, len = draggableElems.length; i < len; i++) {
  2232. var draggableElem = draggableElems[i];
  2233. var draggie = new Draggabilly(draggableElem, {
  2234. handle: '.handle',
  2235. containment: true
  2236. });
  2237. draggies.push(draggie);
  2238. }
  2239. this.style.visibility = 'hidden';
  2240. },
  2241. $components: [
  2242. {
  2243. $cell: true,
  2244. $type: "div",
  2245. class: "handle",
  2246. $components: [
  2247. {
  2248. $cell: true,
  2249. $type: "button",
  2250. class: "mdc-button mdc-button--compact",
  2251. $text: "X",
  2252. onclick: function (e) {
  2253. //self.currentNodeID = m.ID;
  2254. document.querySelector('#' + elementID).style.visibility = 'hidden';
  2255. }
  2256. },
  2257. {
  2258. $cell: true,
  2259. $type: "span",
  2260. class: "mdc-typography--button",
  2261. $text: title
  2262. }
  2263. ]
  2264. },
  2265. cellNode,
  2266. {
  2267. $cell: true,
  2268. $type: "div",
  2269. class: "handle",
  2270. style: "height: 10px; width: inherit;",
  2271. //$text: "sdfsdf"
  2272. }
  2273. // { $text: "23423"}
  2274. ]
  2275. }
  2276. );
  2277. }
  2278. // -- getChildByName --------------------------------------------------------------------
  2279. function getChildByName(node, childName) {
  2280. var childNode = undefined;
  2281. for (var i = 0; i < node.children.length && childNode === undefined; i++) {
  2282. if (node.children[i].name == childName) {
  2283. childNode = node.children[i];
  2284. }
  2285. }
  2286. return childNode;
  2287. };
  2288. function updateCameraProperties() {
  2289. if (this.currentNodeID == this.activeCameraID) {
  2290. if (!this.intervalTimer) {
  2291. var self = this;
  2292. this.intervalTimer = setInterval(function () { updateProperties.call(self, self.activeCameraID) }, 200);
  2293. }
  2294. }
  2295. else {
  2296. if (this.intervalTimer) {
  2297. clearInterval(this.intervalTimer);
  2298. this.intervalTimer = 0;
  2299. }
  2300. }
  2301. }
  2302. function updateProperties(nodeName) {
  2303. var nodeID = nodeName;
  2304. var properties = getProperties.call(this, this.kernel, nodeID);
  2305. for (var i in properties) {
  2306. try {
  2307. var propertyName = properties[i].prop.name;
  2308. var propertyValue = JSON.stringify(utility.transform(vwf.getProperty(nodeID, propertyName, []), utility.transforms.transit));
  2309. } catch (e) {
  2310. this.logger.warnx("satProperty", nodeID, propertyName, propertyValue, "stringify error:", e.message);
  2311. }
  2312. if (propertyValue) {
  2313. var nodeIDAttribute = $.encoder.encodeForAlphaNumeric(nodeID);
  2314. var propertyNameAttribute = $.encoder.encodeForHTMLAttribute("id", propertyName, true);
  2315. var inputElement$ = $('#input-' + nodeIDAttribute + '-' + propertyNameAttribute);
  2316. // Only update if property value input is not in focus
  2317. // If in focus, change font style to italic
  2318. if (!inputElement$.is(":focus")) {
  2319. inputElement$.val(propertyValue);
  2320. inputElement$.css("font-style", "normal");
  2321. } else {
  2322. inputElement$.css("font-style", "italic");
  2323. }
  2324. }
  2325. }
  2326. }
  2327. // -- openEditor ------------------------------------------------------------------------
  2328. function openEditor(eView) // invoke with the view as "this"
  2329. {
  2330. if (eView == 0) {
  2331. closeEditor.call(this);
  2332. }
  2333. if (this.editorView != eView) {
  2334. // Hierarchy
  2335. if (eView == 1) {
  2336. var topdownName = this.topdownName;
  2337. var topdownTemp = this.topdownTemp;
  2338. if (!this.currentNodeID) {
  2339. this.currentNodeID = vwf_view.kernel.find("", "/")[0];
  2340. }
  2341. drill.call(this, this.currentNodeID, undefined);
  2342. $(this.clientList).hide();
  2343. $(this.timeline).hide();
  2344. $(this.about).hide();
  2345. $(this.codeEditor).hide();
  2346. $(this.models).hide();
  2347. if (this.editorOpen) {
  2348. $(topdownName).hide();
  2349. $(topdownTemp).show();
  2350. }
  2351. else {
  2352. $(topdownTemp).show('slide', { direction: 'right' }, 175);
  2353. }
  2354. this.topdownName = topdownTemp;
  2355. this.topdownTemp = topdownName;
  2356. }
  2357. else if (this.editingScript) {
  2358. // Reset width if on script
  2359. this.editingScript = false;
  2360. $('#editor').animate({ 'left': "-260px" }, 175);
  2361. $('.vwf-tree').animate({ 'width': "260px" }, 175);
  2362. }
  2363. // User List
  2364. if (eView == 2) {
  2365. $(this.topdownName).hide();
  2366. $(this.topdownTemp).hide();
  2367. $(this.timeline).hide();
  2368. $(this.about).hide();
  2369. $(this.codeEditor).hide();
  2370. $(this.models).hide();
  2371. $(this.modelsTemp).hide();
  2372. showUserList.call(this);
  2373. }
  2374. // Timeline
  2375. else if (eView == 3) {
  2376. $(this.topdownName).hide();
  2377. $(this.topdownTemp).hide();
  2378. $(this.clientList).hide();
  2379. $(this.about).hide();
  2380. $(this.codeEditor).hide();
  2381. $(this.models).hide();
  2382. $(this.modelsTemp).hide();
  2383. showTimeline.call(this);
  2384. }
  2385. // About
  2386. else if (eView == 4) {
  2387. $(this.topdownName).hide();
  2388. $(this.topdownTemp).hide();
  2389. $(this.clientList).hide();
  2390. $(this.timeline).hide();
  2391. $(this.models).hide();
  2392. $(this.modelsTemp).hide();
  2393. $(this.codeEditor).hide();
  2394. showAboutTab.call(this);
  2395. }
  2396. // Models
  2397. else if (eView == 5) {
  2398. var models = this.models;
  2399. var modelsTemp = this.modelsTemp;
  2400. showModelsTab.call(this, this.currentModelID, this.currentModelURL);
  2401. $(this.topdownName).hide();
  2402. $(this.topdownTemp).hide();
  2403. $(this.clientList).hide();
  2404. $(this.timeline).hide();
  2405. $(this.about).hide();
  2406. $(this.codeEditor).hide();
  2407. if (this.editorOpen) {
  2408. $(models).hide();
  2409. $(modelsTemp).show();
  2410. }
  2411. else {
  2412. $(modelsTemp).show('slide', { direction: 'right' }, 175);
  2413. }
  2414. this.models = modelsTemp;
  2415. this.modelsTemp = models;
  2416. }
  2417. // Code Editor
  2418. else if (eView == 6) {
  2419. $(this.topdownName).hide();
  2420. $(this.topdownTemp).hide();
  2421. $(this.clientList).hide();
  2422. $(this.timeline).hide();
  2423. $(this.models).hide();
  2424. $(this.modelsTemp).hide();
  2425. $(this.about).hide();
  2426. showCodeEditorTab.call(this);
  2427. }
  2428. if (this.editorView == 0) {
  2429. $('#vwf-root').animate({ 'left': "-=260px" }, 175);
  2430. $('#editor').animate({ 'left': "-260px" }, 175);
  2431. $('#x').delay(1000).css({ 'display': 'inline' });
  2432. }
  2433. this.editorView = eView;
  2434. this.editorOpen = true;
  2435. }
  2436. }
  2437. // -- closeEditor -----------------------------------------------------------------------
  2438. function closeEditor() // invoke with the view as "this"
  2439. {
  2440. var topdownName = this.topdownName;
  2441. if (this.editorOpen && this.editorView == 1) // Hierarchy view open
  2442. {
  2443. $(topdownName).hide('slide', { direction: 'right' }, 175);
  2444. $(topdownName).empty();
  2445. $(this.clientList).hide();
  2446. $(this.timeline).hide();
  2447. $(this.about).hide();
  2448. $(this.codeEditor).hide();
  2449. $(this.models).hide();
  2450. }
  2451. else if (this.editorOpen && this.editorView == 2) // Client list open
  2452. {
  2453. $(this.clientList).hide('slide', { direction: 'right' }, 175);
  2454. $(topdownName).hide();
  2455. $(this.timeline).hide();
  2456. $(this.about).hide();
  2457. $(this.codeEditor).hide();
  2458. $(this.models).hide();
  2459. }
  2460. else if (this.editorOpen && this.editorView == 3) // Timeline open
  2461. {
  2462. $(this.timeline).hide('slide', { direction: 'right' }, 175);
  2463. $(topdownName).hide();
  2464. $(this.clientList).hide();
  2465. $(this.about).hide();
  2466. $(this.models).hide();
  2467. }
  2468. else if (this.editorOpen && this.editorView == 4) // About open
  2469. {
  2470. $(this.about).hide('slide', { direction: 'right' }, 175);
  2471. $(this.codeEditor).hide();
  2472. $(topdownName).hide();
  2473. $(this.clientList).hide();
  2474. $(this.timeline).hide();
  2475. $(this.models).hide();
  2476. }
  2477. else if (this.editorOpen && this.editorView == 5) // Models open
  2478. {
  2479. $(this.models).hide('slide', { direction: 'right' }, 175);
  2480. $(topdownName).hide();
  2481. $(this.clientList).hide();
  2482. $(this.timeline).hide();
  2483. $(this.about).hide();
  2484. $(this.codeEditor).hide();
  2485. }
  2486. else if (this.editorOpen && this.editorView == 6) // Code Editor open
  2487. {
  2488. $(this.codeEditor).hide('slide', { direction: 'right' }, 175);
  2489. $(this.about).hide();
  2490. $(topdownName).hide();
  2491. $(this.clientList).hide();
  2492. $(this.timeline).hide();
  2493. $(this.models).hide();
  2494. }
  2495. $('#vwf-root').animate({ 'left': "+=260px" }, 175);
  2496. $('#editor').animate({ 'left': "0px" }, 175);
  2497. $('#x').css({ 'display': 'none' });
  2498. this.editorView = 0;
  2499. this.editorOpen = false;
  2500. }
  2501. // -- showUserList ----------------------------------------------------------------------
  2502. function showUserList() // invoke with the view as "this"
  2503. {
  2504. var clientList = this.clientList;
  2505. viewClients.call(this);
  2506. if (!this.editorOpen) {
  2507. $(clientList).show('slide', { direction: 'right' }, 175);
  2508. }
  2509. else {
  2510. $(clientList).show();
  2511. }
  2512. }
  2513. // -- viewClients -----------------------------------------------------------------------
  2514. function viewClients() {
  2515. var self = this;
  2516. var app = window.location.pathname;
  2517. var pathSplit = app.split('/');
  2518. if (pathSplit[0] == "") {
  2519. pathSplit.shift();
  2520. }
  2521. if (pathSplit[pathSplit.length - 1] == "") {
  2522. pathSplit.pop();
  2523. }
  2524. var instIndex = pathSplit.length - 1;
  2525. if (pathSplit.length > 2) {
  2526. if (pathSplit[pathSplit.length - 2] == "load") {
  2527. instIndex = pathSplit.length - 3;
  2528. }
  2529. }
  2530. if (pathSplit.length > 3) {
  2531. if (pathSplit[pathSplit.length - 3] == "load") {
  2532. instIndex = pathSplit.length - 4;
  2533. }
  2534. }
  2535. var root = "";
  2536. for (var i = 0; i < instIndex; i++) {
  2537. if (root != "") {
  2538. root = root + "/";
  2539. }
  2540. root = root + pathSplit[i];
  2541. }
  2542. if (root.indexOf('.vwf') != -1) root = root.substring(0, root.lastIndexOf('/'));
  2543. var clients$ = $(this.clientList);
  2544. var node = this.nodes["http://vwf.example.com/clients.vwf"];
  2545. clients$.html("<div class='header'>Connected Clients</div>");
  2546. // Add node children
  2547. clients$.append("<div id='clientsChildren'></div>");
  2548. for (var i = 0; i < node.children.length; i++) {
  2549. var nodeChildIDAttribute = $.encoder.encodeForHTMLAttribute("id", node.children[i].ID, true);
  2550. var nodeChildIDAlpha = $.encoder.encodeForAlphaNumeric(node.children[i].ID);
  2551. var nodeChildNameHTML = $.encoder.encodeForHTML(node.children[i].name);
  2552. $('#clientsChildren').append("<div id='" + nodeChildIDAlpha + "' data-nodeID='" + nodeChildIDAttribute + "' class='childContainer'><div class='childEntry'><b>" + nodeChildNameHTML + "</b></div></div>");
  2553. $('#' + nodeChildIDAlpha).click(function (evt) {
  2554. viewClient.call(self, $(this).attr("data-nodeID"));
  2555. });
  2556. }
  2557. // Login Information
  2558. clients$.append("<div style='padding:6px'><input class='filename_entry' type='text' id='userName' placeholder='Username' /><!-- <input class='filename_entry' type='password' id='password' placeholder='Password'/> --><input class='update_button' type='button' id='login' value='Login' /></div>");
  2559. clients$.append("<hr/>");
  2560. $('#userName').keydown(function (evt) {
  2561. evt.stopPropagation();
  2562. });
  2563. $('#userName').keypress(function (evt) {
  2564. evt.stopPropagation();
  2565. });
  2566. $('#userName').keyup(function (evt) {
  2567. evt.stopPropagation();
  2568. });
  2569. $('#password').keydown(function (evt) {
  2570. evt.stopPropagation();
  2571. });
  2572. $('#password').keypress(function (evt) {
  2573. evt.stopPropagation();
  2574. });
  2575. $('#password').keyup(function (evt) {
  2576. evt.stopPropagation();
  2577. });
  2578. $('#login').click(function (evt) {
  2579. // Future call to validate username and password
  2580. //login.call(self, $('#userName').val(), $('#password').val());
  2581. var moniker = vwf_view.kernel.moniker();
  2582. var clients = vwf_view.kernel.findClients("", "/*");
  2583. var client = undefined;
  2584. for (var i = 0; i < clients.length; i++) {
  2585. if (clients[i].indexOf(moniker) != -1) {
  2586. client = clients[i];
  2587. break;
  2588. }
  2589. }
  2590. // var client = vwf_view.kernel.findClients("", "/" + moniker)[0];
  2591. if (client) {
  2592. vwf_view.kernel.setProperty(client, "displayName", $('#userName').val());
  2593. }
  2594. });
  2595. // clients$.append("<div style='padding:6px'><input class='live_button' type='button' id='liveeditor' value='Open Code Editor' /></div>");
  2596. // $('#liveeditor').click(function(evt) {
  2597. // openLiveEditor.call(self);
  2598. // });
  2599. // Save / Load
  2600. clients$.append("<div style='padding:6px'><input class='filename_entry' type='text' id='fileName' /><input class='update_button' type='button' id='save' value='Save' /></div>");
  2601. $('#fileName').keydown(function (evt) {
  2602. evt.stopPropagation();
  2603. });
  2604. $('#fileName').keypress(function (evt) {
  2605. evt.stopPropagation();
  2606. });
  2607. $('#fileName').keyup(function (evt) {
  2608. evt.stopPropagation();
  2609. });
  2610. $('#save').click(function (evt) {
  2611. saveStateAsFile.call(self, $('#fileName').val());
  2612. });
  2613. clients$.append("<div style='padding:6px'><select class='filename_select' id='fileToLoad' /></select></div>");
  2614. $('#fileToLoad').append("<option value='none'></option>");
  2615. $.getJSON("/" + root + "/listallsaves", function (data) {
  2616. $.each(data, function (key, value) {
  2617. var applicationName = value['applicationpath'].split("/");
  2618. if (applicationName.length > 0) {
  2619. applicationName = applicationName[applicationName.length - 1];
  2620. }
  2621. if (applicationName.length > 0) {
  2622. applicationName = applicationName.charAt(0).toUpperCase() + applicationName.slice(1);
  2623. }
  2624. if (value['latestsave']) {
  2625. $('#fileToLoad').append("<option value='" + value['savename'] + "' applicationpath='" + value['applicationpath'] + "'>" + applicationName + ": " + value['savename'] + "</option>");
  2626. }
  2627. else {
  2628. $('#fileToLoad').append("<option value='" + value['savename'] + "' applicationpath='" + value['applicationpath'] + "' revision='" + value['revision'] + "'>" + applicationName + ": " + value['savename'] + " Rev(" + value['revision'] + ")</option>");
  2629. }
  2630. });
  2631. });
  2632. clients$.append("<div style='padding:6px'><input class='update_button' type='button' id='load' value='Load' /></div>");
  2633. $('#load').click(function (evt) {
  2634. loadSavedState.call(self, $('#fileToLoad').val(), $('#fileToLoad').find(':selected').attr('applicationpath'), $('#fileToLoad').find(':selected').attr('revision'));
  2635. });
  2636. }
  2637. // -- editor ---
  2638. function openLiveEditor(value) {
  2639. //this.liveditor = document.createElement('div');
  2640. //this.liveditor.setAttribute('id', "editorlive");
  2641. // $('body').append(this.liveditor);
  2642. var editor = this.ace.edit("editorlive");
  2643. editor.setTheme("ace/theme/monokai");
  2644. editor.getSession().setMode("ace/mode/javascript");
  2645. }
  2646. // -- viewClient ------------------------------------------------------------------------
  2647. function viewClient(clientID) {
  2648. var self = this;
  2649. var clients$ = $(this.clientList);
  2650. var node = this.nodes[clientID];
  2651. clients$.html("<div class='header'><img src='images/back.png' id='back' alt='back'/> " + $.encoder.encodeForHTML(node.name) + "</div>");
  2652. $('#back').click(function (evt) {
  2653. viewClients.call(self);
  2654. });
  2655. // Add node properties
  2656. clients$.append("<div id='clientProperties'></div>");
  2657. var displayedProperties = {};
  2658. for (var i = 0; i < node.properties.length; i++) {
  2659. if (!displayedProperties[node.properties[i].name]) {
  2660. displayedProperties[node.properties[i].name] = "instance";
  2661. var nodeIDAlpha = $.encoder.encodeForAlphaNumeric(clientID);
  2662. var propertyNameAttribute = $.encoder.encodeForHTMLAttribute("id", node.properties[i].name, true);
  2663. var propertyNameAlpha = $.encoder.encodeForAlphaNumeric(node.properties[i].name);
  2664. var propertyNameHTML = $.encoder.encodeForHTML(node.properties[i].name);
  2665. var propertyValueAttribute = $.encoder.encodeForHTMLAttribute("val", node.properties[i].getValue(), true);
  2666. $('#clientProperties').append("<div id='" + nodeIDAlpha + "-" + propertyNameAlpha + "' class='propEntry'><table><tr><td><b>" + propertyNameHTML + " </b></td><td><input type='text' class='input_text' id='input-" + nodeIDAlpha + "-" + propertyNameAlpha + "' value='" + propertyValueAttribute + "' data-propertyName='" + propertyNameAttribute + "' readonly></td></tr></table></div>");
  2667. }
  2668. }
  2669. }
  2670. // -- drillDown -------------------------------------------------------------------------
  2671. function drillDown(nodeID, drillBackID) // invoke with the view as "this"
  2672. {
  2673. var topdownName = this.topdownName;
  2674. var topdownTemp = this.topdownTemp;
  2675. drill.call(this, nodeID, drillBackID);
  2676. if (nodeID != vwf_view.kernel.find("", "/")[0]) $(topdownName).hide('slide', { direction: 'left' }, 175);
  2677. $(topdownTemp).show('slide', { direction: 'right' }, 175);
  2678. this.topdownName = topdownTemp;
  2679. this.topdownTemp = topdownName;
  2680. }
  2681. // -- drillUp ---------------------------------------------------------------------------
  2682. function drillUp(nodeID) // invoke with the view as "this"
  2683. {
  2684. var topdownName = this.topdownName;
  2685. var topdownTemp = this.topdownTemp;
  2686. drill.call(this, nodeID, undefined);
  2687. $(topdownName).hide('slide', { direction: 'right' }, 175);
  2688. $(topdownTemp).show('slide', { direction: 'left' }, 175);
  2689. this.topdownName = topdownTemp;
  2690. this.topdownTemp = topdownName;
  2691. }
  2692. // -- drillBack---------------------------------------------------------------------------
  2693. function drillBack(nodeID) // invoke with the view as "this"
  2694. {
  2695. var topdownName = this.topdownName;
  2696. var topdownTemp = this.topdownTemp;
  2697. drill.call(this, nodeID, undefined);
  2698. // No slide motion, when resizing script window back to normal
  2699. $(topdownName).hide();
  2700. $(topdownTemp).show();
  2701. this.topdownName = topdownTemp;
  2702. this.topdownTemp = topdownName;
  2703. }
  2704. // -- drill -----------------------------------------------------------------------------
  2705. function drill(nodeID, drillBackID) // invoke with the view as "this"
  2706. {
  2707. var node = this.nodes[nodeID];
  2708. if (!node) {
  2709. this.logger.errorx("drill: Cannot find node '" + nodeID + "'");
  2710. return;
  2711. }
  2712. var self = this;
  2713. var topdownName = this.topdownName;
  2714. var topdownTemp = this.topdownTemp;
  2715. var nodeIDAlpha = $.encoder.encodeForAlphaNumeric(nodeID);
  2716. $(topdownName).html(''); // Clear alternate div first to ensure content is added correctly
  2717. this.currentNodeID = nodeID;
  2718. if (!drillBackID) drillBackID = node.parentID;
  2719. if (nodeID == vwf_view.kernel.find("", "/")[0]) {
  2720. $(topdownTemp).html("<div class='header'>index</div>");
  2721. }
  2722. else {
  2723. $(topdownTemp).html("<div class='header'><img src='images/back.png' id='" + nodeIDAlpha + "-back' alt='back'/> " + $.encoder.encodeForHTML(node.name) + "</div>");
  2724. $('#' + nodeIDAlpha + '-back').click(function (evt) {
  2725. drillUp.call(self, drillBackID);
  2726. });
  2727. }
  2728. // Add node children
  2729. $(topdownTemp).append("<div id='children'></div>");
  2730. for (var i = 0; i < node.children.length; i++) {
  2731. var nodeChildIDAttribute = $.encoder.encodeForHTMLAttribute("id", node.children[i].ID, true);
  2732. var nodeChildIDAlpha = $.encoder.encodeForAlphaNumeric(node.children[i].ID);
  2733. $('#children').append("<div id='" + nodeChildIDAlpha + "' data-nodeID='" + nodeChildIDAttribute + "' class='childContainer'><div class='childEntry'><b>" + $.encoder.encodeForHTML(node.children[i].name) + "</b></div></div>");
  2734. $('#' + nodeChildIDAlpha).click(function (evt) {
  2735. drillDown.call(self, $(this).attr("data-nodeID"), nodeID);
  2736. });
  2737. }
  2738. $('#children > div:last').css('border-bottom-width', '3px');
  2739. // Add prototype children
  2740. // TODO: Commented out until prototype children inherit from prototypes
  2741. /*
  2742. $(topdownTemp).append("<div id='prototypeChildren'></div>");
  2743. var prototypeChildren = getChildren.call( this, this.kernel, node.extendsID );
  2744. for ( var key in prototypeChildren)
  2745. {
  2746. var child = prototypeChildren[key];
  2747. var prototypeChildIDAttribute = $.encoder.encodeForHTMLAttribute("id", child.ID, true);
  2748. var prototypeChildIDAlpha = $.encoder.encodeForAlphaNumeric(child.ID);
  2749. $('#prototypeChildren').append("<div id='" + prototypeChildIDAlpha + "' data-nodeID='" + prototypeChildIDAttribute + "' class='childContainer'><div class='childEntry'><b>" + $.encoder.encodeForHTML(child.name) + "</b></div></div>");
  2750. $('#' + prototypeChildIDAlpha).click( function(evt) {
  2751. drillDown.call(self, $(this).attr("data-nodeID"), nodeID);
  2752. });
  2753. }
  2754. */ // END TODO:
  2755. $('#prototypeChildren > div:last').css('border-bottom-width', '3px');
  2756. // Add node properties
  2757. $(topdownTemp).append("<div id='properties'></div>");
  2758. var displayedProperties = {};
  2759. for (var i = 0; i < node.properties.length; i++) {
  2760. if (!displayedProperties[node.properties[i].name] && node.properties[i].name.indexOf('$') === -1) {
  2761. displayedProperties[node.properties[i].name] = "instance";
  2762. var propertyNameAttribute = $.encoder.encodeForHTMLAttribute("id", node.properties[i].name, true);
  2763. var propertyNameAlpha = $.encoder.encodeForAlphaNumeric(node.properties[i].name);
  2764. var propertyNameHTML = $.encoder.encodeForHTML(node.properties[i].name);
  2765. var propertyValueAttribute = $.encoder.encodeForHTMLAttribute("val", node.properties[i].getValue(), true);
  2766. if (propertyNameAlpha.indexOf("semantics") > -1) {
  2767. } else if (propertyNameAlpha.indexOf("grammar") > -1) {
  2768. } else if (propertyNameAlpha.indexOf("ohm") > -1) {
  2769. let propName = propertyNameAlpha;
  2770. let propValue = node.properties[i].rawValue;
  2771. $(topdownTemp).append("<div id='" + nodeIDAlpha + "-" + propertyNameAlpha + "'></div>");
  2772. $('#' + nodeIDAlpha + '-' + propertyNameAlpha).append("<div class='childContainer'><div class='childEntry'><b>" + propertyNameHTML + "</div></div>");
  2773. $('#' + nodeIDAlpha + '-' + propertyNameAlpha).click(function (evt) {
  2774. editOhmLang.call(self, nodeID, propName, propValue);
  2775. });
  2776. // $('#properties').append("<div id='" + nodeIDAlpha + "-" + propertyNameAlpha + "' class='propEntry'><table><tr><td><b>" + propertyNameHTML + " </b></td><td><input type='text' class='input_text' id='input-" + nodeIDAlpha + "-" + propertyNameAlpha + "' value='" + propertyValueAttribute + "' data-propertyName='" + propertyNameAttribute + "'></td></tr></table></div>");
  2777. } else {
  2778. $('#properties').append("<div id='" + nodeIDAlpha + "-" + propertyNameAlpha + "' class='propEntry'><table><tr><td><b>" + propertyNameHTML + " </b></td><td><input type='text' class='input_text' id='input-" + nodeIDAlpha + "-" + propertyNameAlpha + "' value='" + propertyValueAttribute + "' data-propertyName='" + propertyNameAttribute + "'></td></tr></table></div>");
  2779. }
  2780. $('#input-' + nodeIDAlpha + '-' + propertyNameAttribute).change(function (evt) {
  2781. var propName = $.encoder.canonicalize($(this).attr("data-propertyName"));
  2782. var propValue = $(this).val();
  2783. try {
  2784. propValue = JSON.parse($.encoder.canonicalize(propValue));
  2785. self.kernel.setProperty(nodeID, propName, propValue);
  2786. } catch (e) {
  2787. // restore the original value on error
  2788. $(this).val(propValue);
  2789. }
  2790. });
  2791. $('#input-' + nodeIDAlpha + '-' + propertyNameAlpha).keydown(function (evt) {
  2792. evt.stopPropagation();
  2793. });
  2794. $('#input-' + nodeIDAlpha + '-' + propertyNameAlpha).keypress(function (evt) {
  2795. evt.stopPropagation();
  2796. });
  2797. $('#input-' + nodeIDAlpha + '-' + propertyNameAlpha).keyup(function (evt) {
  2798. evt.stopPropagation();
  2799. });
  2800. }
  2801. }
  2802. $('#properties > div:last').css('border-bottom-width', '3px');
  2803. this.logger.info(self + " " + nodeID);
  2804. // Add prototype properties
  2805. $(topdownTemp).append("<div id='prototypeProperties'></div>");
  2806. var prototypeProperties = getProperties.call(this, this.kernel, node.extendsID);
  2807. for (var key in prototypeProperties) {
  2808. var prop = prototypeProperties[key].prop;
  2809. if (!displayedProperties[prop.name]) {
  2810. displayedProperties[prop.name] = prototypeProperties[key].prototype;
  2811. if (prop.value == undefined) {
  2812. prop.value = JSON.stringify(utility.transform(vwf.getProperty(nodeID, prop.name, []), utility.transforms.transit));
  2813. }
  2814. var propertyNameAttribute = $.encoder.encodeForHTMLAttribute("id", prop.name, true);
  2815. var propertyNameAlpha = $.encoder.encodeForAlphaNumeric(prop.name);
  2816. var propertyNameHTML = $.encoder.encodeForHTML(prop.name);
  2817. var propertyValueAttribute = $.encoder.encodeForHTMLAttribute("val", prop.value, true);
  2818. $('#prototypeProperties').append("<div id='" + nodeIDAlpha + "-" + propertyNameAlpha + "' class='propEntry'><table><tr><td><b>" + propertyNameHTML + " </b></td><td><input type='text' class='input_text' id='input-" + nodeIDAlpha + "-" + propertyNameAlpha + "' value='" + propertyValueAttribute + "' data-propertyName='" + propertyNameAttribute + "'></td></tr></table></div>");
  2819. $('#input-' + nodeIDAlpha + '-' + propertyNameAlpha).change(function (evt) {
  2820. var propName = $.encoder.canonicalize($(this).attr("data-propertyName"));
  2821. var propValue = $(this).val();
  2822. try {
  2823. propValue = JSON.parse($.encoder.canonicalize(propValue));
  2824. self.kernel.setProperty(nodeID, propName, propValue);
  2825. } catch (e) {
  2826. // restore the original value on error
  2827. $(this).val(propValue);
  2828. }
  2829. });
  2830. $('#input-' + nodeIDAlpha + '-' + propertyNameAlpha).keydown(function (evt) {
  2831. evt.stopPropagation();
  2832. });
  2833. $('#input-' + nodeIDAlpha + '-' + propertyNameAlpha).keypress(function (evt) {
  2834. evt.stopPropagation();
  2835. });
  2836. $('#input-' + nodeIDAlpha + '-' + propertyNameAlpha).keyup(function (evt) {
  2837. evt.stopPropagation();
  2838. });
  2839. }
  2840. }
  2841. $('#prototypeProperties > div:last').css('border-bottom-width', '3px');
  2842. // Add node methods
  2843. $(topdownTemp).append("<div id='methods'></div>");
  2844. for (var key in node.methods) {
  2845. var method = node.methods[key];
  2846. var methodNameAlpha = $.encoder.encodeForAlphaNumeric(key);
  2847. var methodNameAttribute = $.encoder.encodeForHTMLAttribute("id", key, true);
  2848. var methodNameHTML = $.encoder.encodeForHTML(key);
  2849. $('#methods').append("<div id='" + methodNameAlpha + "' class='methodEntry'><table><tr><td><b>" + methodNameHTML + " </b></td><td style='text-align:right;overflow:visible'><div id='rollover-" + methodNameAlpha + "' style='position:relative;left:12px'><input type='button' class='input_button_call' id='call-" + methodNameAlpha + "' value='Call' data-methodName='" + methodNameAttribute + "'><img id='param-" + methodNameAlpha + "' data-methodName='" + methodNameAttribute + "' src='images/arrow.png' alt='arrow' style='position:relative;top:4px;left:2px;visibility:hidden'></div></td></tr></table></div>");
  2850. $('#rollover-' + methodNameAlpha).mouseover(function (evt) {
  2851. $('#param-' + $(this).attr("id").substring(9)).css('visibility', 'visible');
  2852. });
  2853. $('#rollover-' + methodNameAlpha).mouseleave(function (evt) {
  2854. $('#param-' + $(this).attr("id").substring(9)).css('visibility', 'hidden');
  2855. });
  2856. $('#call-' + methodNameAlpha).click(function (evt) {
  2857. self.kernel.callMethod(nodeID, $.encoder.canonicalize($(this).attr("data-methodName")));
  2858. });
  2859. $('#param-' + methodNameAlpha).click(function (evt) {
  2860. setParams.call(self, $.encoder.canonicalize($(this).attr("data-methodName")), method, nodeID);
  2861. });
  2862. }
  2863. $('#methods > div:last').css('border-bottom-width', '3px');
  2864. // Add prototype methods
  2865. $(topdownTemp).append("<div id='prototypeMethods'></div>");
  2866. var prototypeMethods = getMethods.call(this, this.kernel, node.extendsID);
  2867. for (var key in prototypeMethods) {
  2868. var method = prototypeMethods[key];
  2869. var prototypeMethodNameAlpha = $.encoder.encodeForAlphaNumeric(key);
  2870. var prototypeMethodNameAttribute = $.encoder.encodeForHTMLAttribute("id", key, true);
  2871. var prototypeMethodNameHTML = $.encoder.encodeForHTML(key);
  2872. $('#prototypeMethods').append("<div id='" + prototypeMethodNameAlpha + "' class='methodEntry'><table><tr><td><b>" + prototypeMethodNameHTML + " </b></td><td style='text-align:right;overflow:visible'><div id='rollover-" + prototypeMethodNameAlpha + "' style='position:relative;left:12px'><input type='button' class='input_button_call' id='call-" + prototypeMethodNameAlpha + "' value='Call' data-methodName='" + prototypeMethodNameAttribute + "'><img id='param-" + prototypeMethodNameAlpha + "' data-methodName='" + prototypeMethodNameAttribute + "' src='images/arrow.png' alt='arrow' style='position:relative;top:4px;left:2px;visibility:hidden'></div></td></tr></table></div>");
  2873. $('#rollover-' + prototypeMethodNameAlpha).mouseover(function (evt) {
  2874. $('#param-' + $(this).attr("id").substring(9)).css('visibility', 'visible');
  2875. });
  2876. $('#rollover-' + prototypeMethodNameAlpha).mouseleave(function (evt) {
  2877. $('#param-' + $(this).attr("id").substring(9)).css('visibility', 'hidden');
  2878. });
  2879. $('#call-' + prototypeMethodNameAlpha).click(function (evt) {
  2880. self.kernel.callMethod(nodeID, $.encoder.canonicalize($(this).attr("data-methodName")));
  2881. });
  2882. $('#param-' + prototypeMethodNameAlpha).click(function (evt) {
  2883. setParams.call(self, $.encoder.canonicalize($(this).attr("data-methodName")), method, nodeID);
  2884. });
  2885. }
  2886. $('#prototypeMethods > div:last').css('border-bottom-width', '3px');
  2887. // Add node events
  2888. $(topdownTemp).append("<div id='events'></div>");
  2889. for (var key in node.events) {
  2890. var nodeEvent = node.events[key];
  2891. var eventNameAlpha = $.encoder.encodeForAlphaNumeric(key);
  2892. var eventNameAttribute = $.encoder.encodeForHTMLAttribute("id", key, true);
  2893. var eventNameHTML = $.encoder.encodeForHTML(key);
  2894. $('#events').append("<div id='" + eventNameAlpha + "' class='methodEntry'><table><tr><td><b>" + eventNameHTML + " </b></td><td style='text-align:right;overflow:visible'><div id='rollover-" + eventNameAlpha + "' style='position:relative;left:12px'><input type='button' class='input_button_call' id='fire-" + eventNameAlpha + "' value='Fire' data-eventName='" + eventNameAttribute + "'><img id='arg-" + eventNameAlpha + "' data-eventName='" + eventNameAttribute + "' src='images/arrow.png' alt='arrow' style='position:relative;top:4px;left:2px;visibility:hidden'></div></td></tr></table></div>");
  2895. $('#rollover-' + eventNameAlpha).mouseover(function (evt) {
  2896. $('#arg-' + $(this).attr("id").substring(9)).css('visibility', 'visible');
  2897. });
  2898. $('#rollover-' + eventNameAlpha).mouseleave(function (evt) {
  2899. $('#arg-' + $(this).attr("id").substring(9)).css('visibility', 'hidden');
  2900. });
  2901. $('#fire-' + eventNameAlpha).click(function (evt) {
  2902. self.kernel.fireEvent(nodeID, $.encoder.canonicalize($(this).attr("data-eventName")));
  2903. });
  2904. $('#arg-' + eventNameAlpha).click(function (evt) {
  2905. setArgs.call(self, $.encoder.canonicalize($(this).attr("data-eventName")), nodeEvent, nodeID);
  2906. });
  2907. }
  2908. $('#events > div:last').css('border-bottom-width', '3px');
  2909. // Add prototype events
  2910. $(topdownTemp).append("<div id='prototypeEvents'></div>");
  2911. var prototypeEvents = getEvents.call(this, this.kernel, node.extendsID);
  2912. for (var key in prototypeEvents) {
  2913. var nodeEvent = prototypeEvents[key];
  2914. var prototypeEventNameAlpha = $.encoder.encodeForAlphaNumeric(key);
  2915. var prototypeEventNameAttribute = $.encoder.encodeForHTMLAttribute("id", key, true);
  2916. var prototypeEventNameHTML = $.encoder.encodeForHTML(key);
  2917. $('#prototypeEvents').append("<div id='" + prototypeEventNameAlpha + "' class='methodEntry'><table><tr><td><b>" + prototypeEventNameHTML + " </b></td><td style='text-align:right;overflow:visible'><div id='rollover-" + prototypeEventNameAlpha + "' style='position:relative;left:12px'><input type='button' class='input_button_call' id='fire-" + prototypeEventNameAlpha + "' value='Fire' data-eventName='" + prototypeEventNameAttribute + "'><img id='arg-" + prototypeEventNameAlpha + "' data-eventName='" + prototypeEventNameAttribute + "' src='images/arrow.png' alt='arrow' style='position:relative;top:4px;left:2px;visibility:hidden'></div></td></tr></table></div>");
  2918. $('#rollover-' + prototypeEventNameAlpha).mouseover(function (evt) {
  2919. $('#arg-' + $(this).attr("id").substring(9)).css('visibility', 'visible');
  2920. });
  2921. $('#rollover-' + prototypeEventNameAlpha).mouseleave(function (evt) {
  2922. $('#arg-' + $(this).attr("id").substring(9)).css('visibility', 'hidden');
  2923. });
  2924. $('#fire-' + prototypeEventNameAlpha).click(function (evt) {
  2925. self.kernel.fireEvent(nodeID, $.encoder.canonicalize($(this).attr("data-eventName")));
  2926. });
  2927. $('#arg-' + prototypeEventNameAlpha).click(function (evt) {
  2928. setArgs.call(self, $.encoder.canonicalize($(this).attr("data-eventName")), nodeEvent, nodeID);
  2929. });
  2930. }
  2931. $('#prototypeEvents > div:last').css('border-bottom-width', '3px');
  2932. // Add node behaviors
  2933. $(topdownTemp).append("<div id='behaviors'></div>");
  2934. for (var i = 0; i < node.implementsIDs.length; i++) {
  2935. var nodeImplementsIDAlpha = $.encoder.encodeForAlphaNumeric(node.implementsIDs[i]);
  2936. var nodeImplementsIDHTML = $.encoder.encodeForHTML(node.implementsIDs[i]);
  2937. $('#behaviors').append("<div class='propEntry'><table><tr><td style='width:92%'><b>" + nodeImplementsIDHTML + "</b></td><td><input id='" + nodeImplementsIDAlpha + "-enable' type='checkbox' checked='checked' disabled='disabled' /></td></tr></table></div>");
  2938. /*
  2939. //Placeholder to Enable/Disable behaviors
  2940. $('#' + node.implementsID[i] + '-enable').change( function(evt) {
  2941. });
  2942. */
  2943. }
  2944. $('#behaviors > div:last').css('border-bottom-width', '3px');
  2945. // Add prototype behaviors
  2946. $(topdownTemp).append("<div id='prototypeBehaviors'></div>");
  2947. var prototypeNode = this.nodes[node.extendsID];
  2948. for (var i = 0; i < prototypeNode.implementsIDs.length; i++) {
  2949. var prototypeImplementsIDAlpha = $.encoder.encodeForAlphaNumeric(prototypeNode.implementsIDs[i]);
  2950. var prototypeImplementsIDHTML = $.encoder.encodeForHTML(prototypeNode.implementsIDs[i]);
  2951. $('#prototypeBehaviors').append("<div class='propEntry'><table><tr><td style='width:92%'><b>" + prototypeImplementsIDHTML + "</b></td><td><input id='" + prototypeImplementsIDAlpha + "-enable' type='checkbox' checked='checked' disabled='disabled' /></td></tr></table></div>");
  2952. }
  2953. $('#prototypeBehaviors > div:last').css('border-bottom-width', '3px');
  2954. // Create new method
  2955. $(topdownTemp).append("<div id='createMethodID'></div>");
  2956. $('#createMethodID').append("<div class='childContainer'><div class='childEntry'><b>New Method</div></div>");
  2957. $('#createMethodID').click(function (evt) {
  2958. createMethod.call(self, nodeID);
  2959. });
  2960. // Create new Event
  2961. $(topdownTemp).append("<div id='createEventID'></div>");
  2962. $('#createEventID').append("<div class='childContainer'><div class='childEntry'><b>New Event</div></div>");
  2963. $('#createEventID').click(function (evt) {
  2964. createEvent.call(self, nodeID);
  2965. });
  2966. // Create new script
  2967. $(topdownTemp).append("<div id='createScript'></div>");
  2968. $('#createScript').append("<div class='childContainer'><div class='childEntry'><b>New Script</div></div>");
  2969. $('#createScript').click(function (evt) {
  2970. createScript.call(self, nodeID);
  2971. });
  2972. $('#createScript > div:last').css('border-bottom-width', '3px');
  2973. if (this.allScripts[nodeID] !== undefined) {
  2974. // Add node scripts
  2975. $(topdownTemp).append("<div id='scripts'></div>");
  2976. for (var i = 0; i < this.allScripts[nodeID].length; i++) {
  2977. var scriptFull = this.allScripts[nodeID][i].text;
  2978. if (scriptFull != undefined) {
  2979. var scriptName = scriptFull.substring(0, scriptFull.indexOf('='));
  2980. $('#scripts').append("<div id='script-" + nodeIDAlpha + "-" + i + "' class='childContainer'><div class='childEntry'><b>script </b>" + scriptName + "</div></div>");
  2981. $('#script-' + nodeIDAlpha + "-" + i).click(function (evt) {
  2982. var scriptID = $(this).attr("id").substring($(this).attr("id").lastIndexOf('-') + 1);
  2983. viewScript.call(self, nodeID, scriptID, undefined);
  2984. });
  2985. }
  2986. }
  2987. $('#scripts > div:last').css('border-bottom-width', '3px');
  2988. }
  2989. if (this.allScripts[node.extendsID] !== undefined) {
  2990. // Add prototype scripts
  2991. $(topdownTemp).append("<div id='prototypeScripts'></div>");
  2992. for (var i = 0; i < this.allScripts[node.extendsID].length; i++) {
  2993. var scriptFull = this.allScripts[node.extendsID][i].text;
  2994. if (scriptFull != undefined) {
  2995. var nodeExtendsIDAlpha = $.encoder.encodeForAlphaNumeric(node.extendsID);
  2996. var nodeExtendsIDAttribute = $.encoder.encodeForHTMLAttribute("id", node.extendsID, true);
  2997. var scriptName = scriptFull.substring(0, scriptFull.indexOf('='));
  2998. $('#prototypeScripts').append("<div id='script-" + nodeExtendsIDAlpha + "-" + i + "' class='childContainer' data-nodeExtendsID='" + nodeExtendsIDAttribute + "'><div class='childEntry'><b>script </b>" + scriptName + "</div></div>");
  2999. $('#script-' + nodeExtendsIDAlpha + "-" + i).click(function (evt) {
  3000. var extendsId = $.encoder.canonicalize($(this).attr("data-nodeExtendsID"));
  3001. var scriptID = $(this).attr("id").substring($(this).attr("id").lastIndexOf('-') + 1);
  3002. viewScript.call(self, nodeID, scriptID, extendsId);
  3003. });
  3004. }
  3005. }
  3006. $('#prototypeScripts > div:last').css('border-bottom-width', '3px');
  3007. }
  3008. updateCameraProperties.call(self);
  3009. }
  3010. // createEvent
  3011. function createEvent(nodeID) // invoke with the view as "this"
  3012. {
  3013. var self = this;
  3014. var topdownName = this.topdownName;
  3015. var topdownTemp = this.topdownTemp;
  3016. var nodeIDAlpha = $.encoder.encodeForAlphaNumeric(nodeID);
  3017. $(topdownTemp).html("<div class='header'><img src='images/back.png' id='script-" + nodeIDAlpha + "-back' alt='back'/> New event</div>");
  3018. $('#script-' + nodeIDAlpha + '-back').click(function (evt) {
  3019. self.editingScript = false;
  3020. drillBack.call(self, nodeID);
  3021. // Return editor to normal width
  3022. $('#editor').animate({ 'left': "-260px" }, 175);
  3023. $('.vwf-tree').animate({ 'width': "260px" }, 175);
  3024. });
  3025. $(topdownTemp).append("<div id='cm'>Name:<br/><input type='text' class='input_text' id='eventName'/><br/>Parameters:<br/><input type='text' class='input_text' id='eventParams'/></div><hr><input class='update_button' type='button' id='createEvent' value='Create' />");
  3026. $("#createEvent").click(function (evt) {
  3027. console.log("not yet created");
  3028. if ($('#eventName').val()) {
  3029. var eventName = $('#eventName').val();
  3030. //prmtr = JSON.parse(JSON.stringify($.encoder.canonicalize(prmtr)));
  3031. console.log(eventName);
  3032. if ($('#eventParams').val()) {
  3033. var params = $('#eventParams').val();
  3034. params = params.split(',');
  3035. var cleanParams = [];
  3036. for (var i = 0; i < params.length; i++) {
  3037. params[i] = $.trim(params[i]);
  3038. if (params[i] != '' && params[i] != null && params[i] !== undefined)
  3039. cleanParams.push(params[i]);
  3040. }
  3041. console.log(cleanParams);
  3042. //prmtr = JSON.parse(JSON.stringify($.encoder.canonicalize(prmtr)));
  3043. }
  3044. let body = '';
  3045. self.kernel.createEvent(nodeID, eventName, cleanParams);
  3046. }
  3047. //self.kernel.execute( nodeID, editor.getValue() );
  3048. // self.kernel.execute( nodeID, $("#newScriptArea").val() );
  3049. });
  3050. $(topdownName).hide();
  3051. $(topdownTemp).show();
  3052. this.topdownName = topdownTemp;
  3053. this.topdownTemp = topdownName;
  3054. }
  3055. // -- createMethod
  3056. function createMethod(nodeID) // invoke with the view as "this"
  3057. {
  3058. var self = this;
  3059. var topdownName = this.topdownName;
  3060. var topdownTemp = this.topdownTemp;
  3061. var nodeIDAlpha = $.encoder.encodeForAlphaNumeric(nodeID);
  3062. $(topdownTemp).html("<div class='header'><img src='images/back.png' id='script-" + nodeIDAlpha + "-back' alt='back'/> New method</div>");
  3063. $('#script-' + nodeIDAlpha + '-back').click(function (evt) {
  3064. self.editingScript = false;
  3065. drillBack.call(self, nodeID);
  3066. // Return editor to normal width
  3067. $('#editor').animate({ 'left': "-260px" }, 175);
  3068. $('.vwf-tree').animate({ 'width': "260px" }, 175);
  3069. });
  3070. $(topdownTemp).append("<div id='cm'>Name:<br/><input type='text' class='input_text' id='methodName'/><br/>Parameters:<br/><input type='text' class='input_text' id='methodParams'/></div><hr><input class='update_button' type='button' id='createMethod' value='Create' />");
  3071. $("#createMethod").click(function (evt) {
  3072. console.log("not yet created");
  3073. if ($('#methodName').val()) {
  3074. var methodName = $('#methodName').val();
  3075. //prmtr = JSON.parse(JSON.stringify($.encoder.canonicalize(prmtr)));
  3076. console.log(methodName);
  3077. if ($('#methodParams').val()) {
  3078. var params = $('#methodParams').val();
  3079. params = params.split(',');
  3080. var cleanParams = [];
  3081. for (var i = 0; i < params.length; i++) {
  3082. params[i] = $.trim(params[i]);
  3083. if (params[i] != '' && params[i] != null && params[i] !== undefined)
  3084. cleanParams.push(params[i]);
  3085. }
  3086. console.log(cleanParams);
  3087. //prmtr = JSON.parse(JSON.stringify($.encoder.canonicalize(prmtr)));
  3088. }
  3089. let body = '';
  3090. self.kernel.createMethod(nodeID, methodName, cleanParams, body);
  3091. }
  3092. //self.kernel.execute( nodeID, editor.getValue() );
  3093. // self.kernel.execute( nodeID, $("#newScriptArea").val() );
  3094. });
  3095. $(topdownName).hide();
  3096. $(topdownTemp).show();
  3097. this.topdownName = topdownTemp;
  3098. this.topdownTemp = topdownName;
  3099. }
  3100. // -- createScript ----------------------------------------------------------------------
  3101. function createScript(nodeID) // invoke with the view as "this"
  3102. {
  3103. var self = this;
  3104. var topdownName = this.topdownName;
  3105. var topdownTemp = this.topdownTemp;
  3106. var allScripts = this.allScripts;
  3107. var nodeIDAlpha = $.encoder.encodeForAlphaNumeric(nodeID);
  3108. $(topdownTemp).html("<div class='header'><img src='images/back.png' id='script-" + nodeIDAlpha + "-back' alt='back'/> script</div>");
  3109. $('#script-' + nodeIDAlpha + '-back').click(function (evt) {
  3110. self.editingScript = false;
  3111. drillBack.call(self, nodeID);
  3112. // Return editor to normal width
  3113. $('#editor').animate({ 'left': "-260px" }, 175);
  3114. $('.vwf-tree').animate({ 'width': "260px" }, 175);
  3115. });
  3116. // $(topdownTemp).append("<div class='scriptEntry'><pre class='scriptCode'><textarea id='newScriptArea' class='scriptEdit' spellcheck='false' wrap='off'></textarea></pre><input class='update_button' type='button' id='create-" + nodeIDAlpha + "' value='Create' /></div><hr>");
  3117. $(topdownTemp).append("<div class='scriptEntry'><pre class='scriptCode'> <div id='editorlive'></div></pre><input class='update_button' type='button' id='create-" + nodeIDAlpha + "' value='Create' /></div><hr>");
  3118. var editor = createAceEditor(self, nodeID);
  3119. $("#create-" + nodeIDAlpha).click(function (evt) {
  3120. self.kernel.execute(nodeID, editor.getValue());
  3121. // self.kernel.execute( nodeID, $("#newScriptArea").val() );
  3122. });
  3123. // $('#newScriptArea').focus( function(evt) {
  3124. // // Expand the script editor
  3125. // self.editingScript = true;
  3126. // $('#editor').animate({ 'left' : "-500px" }, 175);
  3127. // $('.vwf-tree').animate({ 'width' : "500px" }, 175);
  3128. // });
  3129. $('#editorlive').keydown(function (evt) {
  3130. evt.stopPropagation();
  3131. });
  3132. $(topdownName).hide();
  3133. $(topdownTemp).show();
  3134. this.topdownName = topdownTemp;
  3135. this.topdownTemp = topdownName;
  3136. }
  3137. // -- viewScript ------------------------------------------------------------------------
  3138. function createAceEditor(view, nodeID, elID) {
  3139. var editor = view.ace.edit(elID);
  3140. editor.setTheme("ace/theme/monokai");
  3141. editor.setFontSize(16);
  3142. editor.getSession().setMode("ace/mode/javascript");
  3143. editor.commands.addCommand({
  3144. name: "doit",
  3145. bindKey: { win: "Ctrl-e", mac: "Command-e" },
  3146. exec: function () {
  3147. codeEditorDoit(editor, nodeID);
  3148. }
  3149. });
  3150. editor.commands.addCommand({
  3151. name: "printit",
  3152. bindKey: { win: "Ctrl-b", mac: "Command-b" },
  3153. exec: function () {
  3154. codeEditorPrintit(editor, nodeID);
  3155. }
  3156. });
  3157. return editor;
  3158. }
  3159. function editOhmLang(nodeID, propertyName, propertyValue) {
  3160. var self = this;
  3161. var topdownName = this.topdownName;
  3162. var topdownTemp = this.topdownTemp;
  3163. var nodeIDAlpha = $.encoder.encodeForAlphaNumeric(nodeID);
  3164. $(topdownTemp).html("<div class='header'><img src='images/back.png' id='script-" + nodeIDAlpha + "-back' alt='back'/> script</div>");
  3165. $('#script-' + nodeIDAlpha + '-back').click(function (evt) {
  3166. self.editingScript = false;
  3167. drillBack.call(self, nodeID);
  3168. // Return editor to normal width
  3169. $('#editor').animate({ 'left': "-260px" }, 175);
  3170. $('.vwf-tree').animate({ 'width': "260px" }, 175);
  3171. });
  3172. if (propertyValue != undefined) {
  3173. var propText = propertyValue;
  3174. // var propText = propertyValue.split("\n").map($.trim).filter(function(line) { return line != "" }).join("\n");
  3175. $(topdownTemp).append("<div style='padding:6px'><input class='live_button' type='button' id='update-" + nodeIDAlpha + "-" + propertyName + "' value='Update' /></div>");
  3176. $(topdownTemp).append("<div class='scriptEntry'><pre class='scriptCode'> <div id='editorlive'> </div></pre></div><hr>");
  3177. var editor = createAceEditor(self, nodeID);
  3178. editor.setValue(propText);
  3179. $("#update-" + nodeIDAlpha + "-" + propertyName).click(function (evt) {
  3180. var evalText = editor.getValue();
  3181. self.kernel.setProperty(nodeID, propertyName, evalText);
  3182. });
  3183. $('#editorlive').keydown(function (evt) {
  3184. evt.stopPropagation();
  3185. });
  3186. }
  3187. $(topdownName).hide();
  3188. $(topdownTemp).show();
  3189. this.topdownName = topdownTemp;
  3190. this.topdownTemp = topdownName;
  3191. }
  3192. function viewScript(nodeID, scriptID, extendsID) // invoke with the view as "this"
  3193. {
  3194. var self = this;
  3195. var topdownName = this.topdownName;
  3196. var topdownTemp = this.topdownTemp;
  3197. var allScripts = this.allScripts;
  3198. var nodeIDAlpha = $.encoder.encodeForAlphaNumeric(nodeID);
  3199. $(topdownTemp).html("<div class='header'><img src='images/back.png' id='script-" + nodeIDAlpha + "-back' alt='back'/> script</div>");
  3200. $('#script-' + nodeIDAlpha + '-back').click(function (evt) {
  3201. self.editingScript = false;
  3202. drillBack.call(self, nodeID);
  3203. // Return editor to normal width
  3204. $('#editor').animate({ 'left': "-260px" }, 175);
  3205. $('.vwf-tree').animate({ 'width': "260px" }, 175);
  3206. });
  3207. if (extendsID) {
  3208. nodeID = extendsID;
  3209. nodeIDAlpha = $.encoder.encodeForAlphaNumeric(extendsID);
  3210. }
  3211. var scriptText = self.allScripts[nodeID][scriptID].text;
  3212. if (scriptText != undefined) {
  3213. // $(topdownTemp).append("<div class='scriptEntry'><pre class='scriptCode'><textarea id='scriptTextArea' class='scriptEdit' spellcheck='false' wrap='off'>" + scriptText + "</textarea></pre><input class='update_button' type='button' id='update-" + nodeIDAlpha + "-" + scriptID + "' value='Update' /></div><hr>");
  3214. //Open Live Editor
  3215. $(topdownTemp).append("<div style='padding:6px'><input class='live_button' type='button' id='printit' value='Print It' /><span> </span><input class='live_button' type='button' id='doit-" + nodeIDAlpha + "-" + scriptID + "' value='DoIt' /><span> </span><input class='live_button' type='button' id='update-" + nodeIDAlpha + "-" + scriptID + "' value='Update' /></div>");
  3216. $(topdownTemp).append("<div class='scriptEntry'><pre class='scriptCode'> <div id='editorlive'>" + scriptText + "</div></pre></div><hr>");
  3217. var editor = createAceEditor(self, nodeID);
  3218. // $(topdownTemp).append("<div style='padding:6px'><input class='live_button' type='button' id='doit' value='DoIt' /></div>");
  3219. $("#doit-" + nodeIDAlpha + "-" + scriptID).click(function (evt) {
  3220. var s_id = $(this).attr("id").substring($(this).attr("id").lastIndexOf('-') + 1);
  3221. self.allScripts[nodeID][s_id].text = undefined;;
  3222. codeEditorDoit.call(self, editor, nodeID);
  3223. });
  3224. $("#printit").click(function (evt) {
  3225. codeEditorPrintit.call(self, editor, nodeID);
  3226. });
  3227. $("#update-" + nodeIDAlpha + "-" + scriptID).click(function (evt) {
  3228. var s_id = $(this).attr("id").substring($(this).attr("id").lastIndexOf('-') + 1);
  3229. self.allScripts[nodeID][s_id].text = undefined;
  3230. var evalText = editor.getValue();
  3231. self.kernel.execute(nodeID, evalText);
  3232. });
  3233. // $('#editorlive').focus( function(evt) {
  3234. // // Expand the script editor
  3235. // self.editingScript = true;
  3236. // $('#editor').animate({ 'left' : "-500px" }, 175);
  3237. // $('.vwf-tree').animate({ 'width' : "500px" }, 175);
  3238. // });
  3239. $('#editorlive').keydown(function (evt) {
  3240. evt.stopPropagation();
  3241. });
  3242. }
  3243. $(topdownName).hide();
  3244. $(topdownTemp).show();
  3245. this.topdownName = topdownTemp;
  3246. this.topdownTemp = topdownName;
  3247. }
  3248. // -- setParams -------------------------------------------------------------------------
  3249. function setParams(methodName, methodParams, nodeID) // invoke with the view as "this"
  3250. {
  3251. var self = this;
  3252. var topdownName = this.topdownName;
  3253. var topdownTemp = this.topdownTemp;
  3254. var methodNameAlpha = $.encoder.encodeForAlphaNumeric(methodName);
  3255. var methodNameHTML = $.encoder.encodeForHTML(methodName);
  3256. $(topdownTemp).html("<div class='header'><img src='images/back.png' id='" + methodNameAlpha + "-back' alt='back'/> " + methodNameHTML + "</div>");
  3257. $('#' + methodNameAlpha + '-back').click(function (evt) {
  3258. self.editingScript = false;
  3259. drillUp.call(self, nodeID);
  3260. // Return editor to normal width
  3261. $('#editor').animate({ 'left': "-260px" }, 175);
  3262. $('.vwf-tree').animate({ 'width': "260px" }, 175);
  3263. });
  3264. var nodeIDAlpha = $.encoder.encodeForAlphaNumeric(nodeID);
  3265. var method = vwf.getMethod(nodeID, methodNameAlpha);
  3266. $(topdownTemp).append("<div style='padding:6px'><input class='live_button' type='button' id='printit' value='Print It' /><span> </span><input class='live_button' type='button' id='doit' value='Do It' /><span> </span><input class='live_button' type='button' id='update-" + nodeIDAlpha + "-" + methodNameAlpha + "' value='Update' /><span> </span> <input class='live_button' type='button' id='call' value='Call' /></div>");
  3267. //$(topdownTemp).append("<input class='update_button' type='button' id='call' value='Call' />");
  3268. $(topdownTemp).append("<div id='editorlive'>" + method.body + "</div>");
  3269. var editor = createAceEditor(self, nodeID);
  3270. $("#printit").click(function (evt) {
  3271. codeEditorPrintit.call(self, editor, nodeID);
  3272. });
  3273. $("#doit").click(function (evt) {
  3274. codeEditorDoit.call(self, editor, nodeID);
  3275. });
  3276. $("#update-" + nodeIDAlpha + "-" + methodNameAlpha).click(function (evt) {
  3277. var evalText = editor.getValue();
  3278. self.kernel.setMethod(nodeID, methodNameAlpha,
  3279. { body: evalText, type: "application/javascript", parameters: method.parameters });
  3280. });
  3281. var params = [];
  3282. if (method.parameters) {
  3283. params = method.parameters.length
  3284. };
  3285. if (params >= 1) {
  3286. for (var i = 1; i <= params; i++) {
  3287. $(topdownTemp).append("<div id='param" + i + "' class='propEntry'><table><tr><td><b>" + method.parameters[i - 1] + ": " + i + ": </b></td><td><input type='text' class='input_text' id='input-param" + i + "'></td></tr></table></div>");
  3288. $('#input-param' + i).keydown(function (evt) {
  3289. evt.stopPropagation();
  3290. });
  3291. $('#input-param' + i).keypress(function (evt) {
  3292. evt.stopPropagation();
  3293. });
  3294. $('#input-param' + i).keyup(function (evt) {
  3295. evt.stopPropagation();
  3296. });
  3297. }
  3298. }
  3299. $('#call').click(function (evt) {
  3300. if (params >= 1) {
  3301. var parameters = new Array();
  3302. for (var i = 1; i <= params; i++) {
  3303. if ($('#input-param' + i).val()) {
  3304. var prmtr = $('#input-param' + i).val();
  3305. try {
  3306. prmtr = JSON.parse(JSON.stringify($.encoder.canonicalize(prmtr)));
  3307. parameters.push(prmtr);
  3308. } catch (e) {
  3309. self.logger.error('Invalid Value');
  3310. }
  3311. }
  3312. }
  3313. }
  3314. self.kernel.callMethod(nodeID, methodName, parameters);
  3315. });
  3316. $(topdownName).hide('slide', { direction: 'left' }, 175);
  3317. $(topdownTemp).show('slide', { direction: 'right' }, 175);
  3318. this.topdownName = topdownTemp;
  3319. this.topdownTemp = topdownName;
  3320. }
  3321. // -- setArgs ---------------------------------------------------------------------------
  3322. function setArgs(eventName, eventArgs, nodeID) // invoke with the view as "this"
  3323. {
  3324. var self = this;
  3325. var topdownName = this.topdownName;
  3326. var topdownTemp = this.topdownTemp;
  3327. var eventNameAlpha = $.encoder.encodeForAlphaNumeric(eventName);
  3328. var eventNameHTML = $.encoder.encodeForHTML(eventName);
  3329. $(topdownTemp).html("<div class='header'><img src='images/back.png' id='" + eventNameAlpha + "-back' alt='back'/> " + eventNameHTML + "<input type='button' class='input_button_call' id='fire' value='Fire' style='float:right;position:relative;top:5px;right:33px'></input></div>");
  3330. $('#' + eventNameAlpha + '-back').click(function (evt) {
  3331. drillUp.call(self, nodeID);
  3332. });
  3333. for (var i = 1; i <= 8; i++) {
  3334. $(topdownTemp).append("<div id='arg" + i + "' class='propEntry'><table><tr><td><b>Argument " + i + ": </b></td><td><input type='text' class='input_text' id='input-arg" + i + "'></td></tr></table></div>");
  3335. $('#input-arg' + i).keydown(function (evt) {
  3336. evt.stopPropagation();
  3337. });
  3338. $('#input-arg' + i).keypress(function (evt) {
  3339. evt.stopPropagation();
  3340. });
  3341. $('#input-arg' + i).keyup(function (evt) {
  3342. evt.stopPropagation();
  3343. });
  3344. }
  3345. $(topdownTemp).append("<div style='font-weight:bold;text-align:right;padding-right:10px'></div>");
  3346. $('#fire').click(function (evt) {
  3347. var args = new Array();
  3348. for (var i = 1; i <= 8; i++) {
  3349. if ($('#input-arg' + i).val()) {
  3350. var arg = $('#input-arg' + i).val();
  3351. try {
  3352. arg = JSON.parse($.encoder.canonicalize(arg));
  3353. args.push(arg);
  3354. } catch (e) {
  3355. self.logger.error('Invalid Value');
  3356. }
  3357. }
  3358. }
  3359. self.kernel.fireEvent(nodeID, eventName, args);
  3360. });
  3361. $(topdownName).hide('slide', { direction: 'left' }, 175);
  3362. $(topdownTemp).show('slide', { direction: 'right' }, 175);
  3363. this.topdownName = topdownTemp;
  3364. this.topdownTemp = topdownName;
  3365. }
  3366. function getPrototypes(kernel, extendsID) {
  3367. var prototypes = [];
  3368. var id = extendsID;
  3369. while (id !== undefined) {
  3370. prototypes.push(id);
  3371. id = kernel.prototype(id);
  3372. }
  3373. return prototypes;
  3374. }
  3375. function getPrototypes(kernel, extendsID) {
  3376. var prototypes = [];
  3377. var id = extendsID;
  3378. while (id !== undefined) {
  3379. prototypes.push(id);
  3380. id = kernel.prototype(id);
  3381. }
  3382. return prototypes;
  3383. }
  3384. function createProperty(node, propertyName, propertyValue) {
  3385. var property = {
  3386. name: propertyName,
  3387. rawValue: propertyValue,
  3388. value: undefined,
  3389. getValue: function () {
  3390. var propertyValue;
  3391. if (this.value == undefined) {
  3392. try {
  3393. propertyValue = utility.transform(this.rawValue, utility.transforms.transit);
  3394. this.value = JSON.stringify(propertyValue);
  3395. } catch (e) {
  3396. this.logger.warnx("createdProperty", nodeID, this.propertyName, this.rawValue,
  3397. "stringify error:", e.message);
  3398. this.value = this.rawValue;
  3399. }
  3400. }
  3401. return this.value;
  3402. }
  3403. };
  3404. return property;
  3405. }
  3406. function getProperties(kernel, extendsID) {
  3407. var pTypes = getPrototypes(kernel, extendsID);
  3408. var pProperties = {};
  3409. if (pTypes) {
  3410. for (var i = 0; i < pTypes.length; i++) {
  3411. var nd = this.nodes[pTypes[i]];
  3412. if (nd && nd.properties) {
  3413. for (var key in nd.properties) {
  3414. pProperties[key] = { "prop": nd.properties[key], "prototype": pTypes[i] };
  3415. }
  3416. }
  3417. }
  3418. }
  3419. return pProperties;
  3420. }
  3421. function getChildren(kernel, extendsID) {
  3422. var pTypes = getPrototypes(kernel, extendsID);
  3423. var pChildren = {};
  3424. if (pTypes) {
  3425. for (var i = 0; i < pTypes.length; i++) {
  3426. var nd = this.nodes[pTypes[i]];
  3427. if (nd && nd.children) {
  3428. for (var key in nd.children) {
  3429. pChildren[key] = nd.children[key];
  3430. }
  3431. }
  3432. }
  3433. }
  3434. return pChildren;
  3435. }
  3436. function getEvents(kernel, extendsID) {
  3437. var pTypes = getPrototypes(kernel, extendsID);
  3438. var events = {};
  3439. if (pTypes) {
  3440. for (var i = 0; i < pTypes.length; i++) {
  3441. var nd = this.nodes[pTypes[i]];
  3442. if (nd && nd.events) {
  3443. for (var key in nd.events) {
  3444. events[key] = nd.events[key];
  3445. }
  3446. }
  3447. }
  3448. }
  3449. return events;
  3450. }
  3451. function getMethods(kernel, extendsID) {
  3452. var pTypes = getPrototypes(kernel, extendsID);
  3453. var methods = {};
  3454. if (pTypes) {
  3455. for (var i = 0; i < pTypes.length; i++) {
  3456. var nd = this.nodes[pTypes[i]];
  3457. if (nd && nd.methods) {
  3458. for (var key in nd.methods) {
  3459. methods[key] = nd.methods[key];
  3460. }
  3461. }
  3462. }
  3463. }
  3464. return methods;
  3465. }
  3466. function highlightChildInHierarchy(nodeID) {
  3467. if (this.editorOpen && this.editorView == 1) // Hierarchy view open
  3468. {
  3469. var childDiv = $("div[id='" + nodeID + "']");
  3470. if (childDiv.length > 0) {
  3471. var previousChild = $("div[id='" + this.highlightedChild + "']");
  3472. if (previousChild.length > 0) {
  3473. previousChild.removeClass('childContainerHighlight');
  3474. }
  3475. childDiv.addClass('childContainerHighlight');
  3476. this.highlightedChild = nodeID;
  3477. }
  3478. }
  3479. }
  3480. // -- showTimeline ----------------------------------------------------------------------
  3481. function showTimeline() // invoke with the view as "this"
  3482. {
  3483. var timeline = this.timeline;
  3484. if (!this.timelineInit) {
  3485. $('#time_control').append("<div class='header'>Timeline</div>" +
  3486. "<div style='text-align:center;padding-top:10px'><span><button id='play'></button><button id='stop'></button></span>" +
  3487. "<span><span class='rate slider'></span>&nbsp;" +
  3488. "<span class='rate vwf-label' style='display: inline-block; width:8ex'></span></span></div>");
  3489. var options = {};
  3490. ["play", "pause", "stop"].forEach(function (state) {
  3491. options[state] = { icons: { primary: "ui-icon-" + state }, label: state, text: false };
  3492. });
  3493. options.rate = { value: 0, min: -2, max: 2, step: 0.1, };
  3494. var state = {};
  3495. $.get(
  3496. "admin/state",
  3497. undefined,
  3498. function (data) {
  3499. state = data;
  3500. $("button#play").button("option", state.playing ? options.pause : options.play);
  3501. $("button#stop").button("option", "disabled", state.stopped);
  3502. $(".rate.slider").slider("value", Math.log(state.rate) / Math.LN10);
  3503. if (state.rate < 1.0) {
  3504. var label_rate = 1.0 / state.rate;
  3505. }
  3506. else {
  3507. var label_rate = state.rate;
  3508. }
  3509. var label = label_rate.toFixed(2).toString().replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "");
  3510. if (state.rate < 1.0) {
  3511. label = "&#x2215; " + label;
  3512. } else {
  3513. label = label + " &times;";
  3514. }
  3515. $(".rate.vwf-label").html(label);
  3516. },
  3517. "json"
  3518. );
  3519. $("button#play").button(
  3520. options.pause
  3521. ).click(function () {
  3522. $.post(
  3523. state.playing ? "admin/pause" : "admin/play",
  3524. undefined,
  3525. function (data) {
  3526. state = data;
  3527. $("button#play").button("option", state.playing ? options.pause : options.play);
  3528. $("button#stop").button("option", "disabled", state.stopped);
  3529. },
  3530. "json"
  3531. );
  3532. });
  3533. $("button#stop").button(
  3534. options.stop
  3535. ).click(function () {
  3536. $.post(
  3537. "admin/stop",
  3538. undefined,
  3539. function (data) {
  3540. state = data;
  3541. $("button#play").button("option", state.playing ? options.pause : options.play);
  3542. $("button#stop").button("option", "disabled", state.stopped);
  3543. },
  3544. "json"
  3545. );
  3546. });
  3547. $(".rate.slider").slider(
  3548. options.rate
  3549. ).bind("slide", function (event, ui) {
  3550. $.get(
  3551. "admin/state",
  3552. { "rate": Math.pow(10, Number(ui.value)) },
  3553. function (data) {
  3554. state = data;
  3555. $(".rate.slider").slider("value", Math.log(state.rate) / Math.LN10);
  3556. if (state.rate < 1.0) {
  3557. var label_rate = 1.0 / state.rate;
  3558. }
  3559. else {
  3560. var label_rate = state.rate;
  3561. }
  3562. var label = label_rate.toFixed(2).toString().replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "");
  3563. if (state.rate < 1.0) {
  3564. label = "&#x2215; " + label;
  3565. } else {
  3566. label = label + " &times;";
  3567. }
  3568. $(".rate.vwf-label").html(label);
  3569. },
  3570. "json"
  3571. );
  3572. });
  3573. this.timelineInit = true;
  3574. }
  3575. if (!this.editorOpen) {
  3576. $(timeline).show('slide', { direction: 'right' }, 175);
  3577. }
  3578. else {
  3579. $(timeline).show();
  3580. }
  3581. }
  3582. // -- Show Code Editor tab
  3583. function showCodeEditorTab() // invoke with the view as "this"
  3584. {
  3585. var self = this;
  3586. var codeEditor = this.codeEditor;
  3587. if (!this.codeEditorInit) {
  3588. $('#codeEditor_tab').append("<div class='header'>Live Code Editor</div>");
  3589. $('#codeEditor_tab').append("<div style='padding:6px'><input type='button' id='min' value='Min Window' /><span> </span><input class='live_button' type='button' id='printit' value='Print It' /><span> </span><input class='live_button' type='button' id='doit' value='Do It' /></div>");
  3590. $("#doit").click(function (evt) {
  3591. codeEditorDoit.call(self, editor, sceneID);
  3592. });
  3593. $("#printit").click(function (evt) {
  3594. codeEditorPrintit.call(self, editor, sceneID);
  3595. });
  3596. // $('#codeEditor_tab').append("<div style='padding:6px'></div>");
  3597. $('#min').click(function (evt) {
  3598. $('#editor').animate({ 'left': "-260px" }, 175);
  3599. $('.vwf-tree').animate({ 'width': "260px" }, 175);
  3600. });
  3601. //Open Live Editor
  3602. $('#codeEditor_tab').append('<div id="editorlive">console.log("test")</div>');
  3603. var sceneID = self.kernel.application();
  3604. var editor = createAceEditor(self, sceneID);
  3605. editor.on('blur', function (event, editor) {
  3606. // $('#editor').animate({ 'left' : "-260px" }, 175);
  3607. // $('.vwf-tree').animate({ 'width' : "260px" }, 175);
  3608. });
  3609. this.codeEditorInit = true;
  3610. }
  3611. if (!this.editorOpen) {
  3612. $(codeEditor).show('slide', { direction: 'right' }, 175);
  3613. }
  3614. else {
  3615. $(codeEditor).show();
  3616. // $('#editor').animate({ 'left' : "-500px" }, 175);
  3617. // $('.vwf-tree').animate({ 'width' : "500px" }, 175);
  3618. }
  3619. }
  3620. function codeEditorDoit(editor, nodeID) {
  3621. var selectedText = editor.getSession().doc.getTextRange(editor.selection.getRange());
  3622. if (selectedText == "") {
  3623. var currline = editor.getSelectionRange().start.row;
  3624. var selectedText = editor.session.getLine(currline);
  3625. }
  3626. //console.log(selectedText);
  3627. //var sceneID = self.kernel.application();
  3628. vwf_view.kernel.execute(nodeID, selectedText);
  3629. }
  3630. function codeEditorPrintit(editor, nodeID) {
  3631. var selectedText = editor.getSession().doc.getTextRange(editor.selection.getRange());
  3632. if (selectedText == "") {
  3633. var currline = editor.getSelectionRange().start.row;
  3634. var selectedText = editor.session.getLine(currline);
  3635. }
  3636. //console.log(selectedText);
  3637. //var sceneID = self.kernel.application();
  3638. let scriptText = 'console.log(' + selectedText + ');'
  3639. self.kernel.execute(nodeID, scriptText);
  3640. }
  3641. // -- showAboutTab ----------------------------------------------------------------------
  3642. function showAboutTab() // invoke with the view as "this"
  3643. {
  3644. var about = this.about;
  3645. if (!this.aboutInit) {
  3646. $('#about_tab').append("<div id='aboutHeader' class='header'>About</div>" +
  3647. "<div class='about'><p style='font:bold 12pt Arial'>Virtual World Framework & LiveCode editor</p>" +
  3648. "<p><b>Version: </b> 0.1 <b>VWF version: </b>" + version.toString() + "</p>" +
  3649. "<p><b>This project site: </b><a href='http://demo.krestianstvo.org' target='_blank'>http://demo.krestianstvo.org</a></p>" +
  3650. "<p><b>Site VWF: </b><a href='http://virtualworldframework.com' target='_blank'>http://virtualworldframework.com</a></p>" +
  3651. "<p><b>Project source: </b><a href='https://github.com/NikolaySuslov/vwf/tree/aframe' target='_blank'>https://github.com/NikolaySuslov/vwf/tree/aframe</a></p></div>");
  3652. let anotherCell =
  3653. {
  3654. $cell: true,
  3655. $text: "About: ",
  3656. class: "mdc-typography--display2",
  3657. $type: "h2"
  3658. }
  3659. let andAnotherCell =
  3660. {
  3661. $cell: true,
  3662. $text: "hello world"
  3663. }
  3664. document.querySelector("#aboutHeader").$cell({
  3665. $cell: true,
  3666. class: 'header',
  3667. $components: [anotherCell, andAnotherCell]
  3668. });
  3669. // document.querySelector("body").$cell({
  3670. // $cell: true,
  3671. // $components: [toolbarCell]
  3672. // });
  3673. this.aboutInit = true;
  3674. }
  3675. if (!this.editorOpen) {
  3676. $(about).show('slide', { direction: 'right' }, 175);
  3677. }
  3678. else {
  3679. $(about).show();
  3680. }
  3681. }
  3682. // -- showModelsTab ----------------------------------------------------------------------
  3683. function showModelsTab(modelID, modelURL) // invoke with the view as "this"
  3684. {
  3685. var self = this;
  3686. var models = this.models;
  3687. var modelsTemp = this.modelsTemp;
  3688. this.currentModelID = modelID;
  3689. this.currentModelURL = modelURL;
  3690. $(models).html("");
  3691. if (modelID == "") {
  3692. $(modelsTemp).html("<div class='header'>Models</div>");
  3693. $.getJSON("admin/models", function (data) {
  3694. if (data.length > 0) {
  3695. $.each(data, function (key, value) {
  3696. var fileName = encodeURIComponent(value['basename']);
  3697. var divId = fileName;
  3698. if (divId.indexOf('.') != -1) {
  3699. divId = divId.replace(/\./g, "_");
  3700. }
  3701. var url = value['url'];
  3702. $(modelsTemp).append("<div class='childContainer'><div id='" + divId + "' class='modelEntry' data-url='" + url + "'>"
  3703. + fileName + "</div></div>");
  3704. $("#" + divId).click(function (e) {
  3705. modelDrillDown.call(self, e.target.textContent, e.target.getAttribute("data-url"));
  3706. })
  3707. });
  3708. }
  3709. else {
  3710. $(modelsTemp).append("<div class='childEntry'><p style='font:bold 12pt Arial'>No Models Found</p></div>");
  3711. }
  3712. });
  3713. }
  3714. else {
  3715. var divId = modelID;
  3716. if (divId.indexOf('.') != -1) {
  3717. divId = divId.replace(/\./g, "_");
  3718. }
  3719. $(modelsTemp).html("<div id='" + divId + "-backDiv' class='header'><img src='images/back.png' id='" + divId + "-back' alt='back'/>" + modelID + "</div>");
  3720. $("#" + divId + "-back").click(function (e) {
  3721. modelDrillUp.call(self, '');
  3722. });
  3723. $(modelsTemp).append("<div id='" + divId + "-rotation' class='propEntry'><table><tr><td><b>Rotation</b></td><td>" +
  3724. "<input type='text' class='input_text' id='input-" + divId + "-rotation' value='[1,0,0,0]'></td></tr></table></div>");
  3725. $('#input-' + divId + '-rotation').keydown(function (evt) {
  3726. evt.stopPropagation();
  3727. });
  3728. $('#input-' + divId + '-rotation').keypress(function (evt) {
  3729. evt.stopPropagation();
  3730. });
  3731. $('#input-' + divId + '-rotation').keyup(function (evt) {
  3732. evt.stopPropagation();
  3733. });
  3734. $(modelsTemp).append("<div id='" + divId + "-scale' class='propEntry'><table><tr><td><b>Scale</b></td><td>" +
  3735. "<input type='text' class='input_text' id='input-" + divId + "-scale' value='[1,1,1]'></td></tr></table></div>");
  3736. $('#input-' + divId + '-scale').keydown(function (evt) {
  3737. evt.stopPropagation();
  3738. });
  3739. $('#input-' + divId + '-scale').keypress(function (evt) {
  3740. evt.stopPropagation();
  3741. });
  3742. $('#input-' + divId + '-scale').keyup(function (evt) {
  3743. evt.stopPropagation();
  3744. });
  3745. $(modelsTemp).append("<div id='" + divId + "-translation' class='propEntry'><table><tr><td><b>Translation Offset</b></td><td>" +
  3746. "<input type='text' class='input_text' id='input-" + divId + "-translation' value='[0,0,0]'></td></tr></table></div>");
  3747. $('#input-' + divId + '-translation').keydown(function (evt) {
  3748. evt.stopPropagation();
  3749. });
  3750. $('#input-' + divId + '-translation').keypress(function (evt) {
  3751. evt.stopPropagation();
  3752. });
  3753. $('#input-' + divId + '-translation').keyup(function (evt) {
  3754. evt.stopPropagation();
  3755. });
  3756. $(modelsTemp).append("<div class='drag'><div id='" + divId + "-drag' class='modelEntry' draggable='true' data-escaped-name='" + divId + "' data-url='" + modelURL + "'>Drag To Create</div></div>");
  3757. $("#" + divId + "-drag").on("dragstart", function (e) {
  3758. var fileName = $("#" + e.target.getAttribute("data-escaped-name") + "-backDiv").text();
  3759. var rotation = encodeURIComponent($("#input-" + e.target.getAttribute("data-escaped-name") + "-rotation").val());
  3760. var scale = encodeURIComponent($("#input-" + e.target.getAttribute("data-escaped-name") + "-scale").val());
  3761. var translation = encodeURIComponent($("#input-" + e.target.getAttribute("data-escaped-name") + "-translation").val());
  3762. var fileData = "{\"fileName\":\"" + fileName + "\", \"fileUrl\":\"" + e.target.getAttribute("data-url") + "\", " +
  3763. "\"rotation\":\"" + rotation + "\", \"scale\":\"" + scale + "\", \"translation\":\"" + translation + "\"}";
  3764. e.originalEvent.dataTransfer.setData('text/plain', fileData);
  3765. e.originalEvent.dataTransfer.setDragImage(e.target, 0, 0);
  3766. return true;
  3767. });
  3768. }
  3769. }
  3770. // -- Model drillDown -------------------------------------------------------------------------
  3771. function modelDrillDown(modelID, modelURL) // invoke with the view as "this"
  3772. {
  3773. var models = this.models;
  3774. var modelsTemp = this.modelsTemp;
  3775. showModelsTab.call(this, modelID, modelURL);
  3776. if (modelID != "") $(models).hide('slide', { direction: 'left' }, 175);
  3777. $(modelsTemp).show('slide', { direction: 'right' }, 175);
  3778. this.models = modelsTemp;
  3779. this.modelsTemp = models;
  3780. }
  3781. // -- Model drillUp ---------------------------------------------------------------------------
  3782. function modelDrillUp(modelID) // invoke with the view as "this"
  3783. {
  3784. var models = this.models;
  3785. var modelsTemp = this.modelsTemp;
  3786. showModelsTab.call(this, modelID);
  3787. $(models).hide('slide', { direction: 'right' }, 175);
  3788. $(modelsTemp).show('slide', { direction: 'left' }, 175);
  3789. this.models = modelsTemp;
  3790. this.modelsTemp = models;
  3791. }
  3792. // -- SaveStateAsFile -------------------------------------------------------------------------
  3793. function saveStateAsFile(filename) // invoke with the view as "this"
  3794. {
  3795. this.logger.info("Saving: " + filename);
  3796. var clients = this.nodes["http://vwf.example.com/clients.vwf"];
  3797. if (supportAjaxUploadWithProgress.call(this)) {
  3798. var xhr = new XMLHttpRequest();
  3799. // Save State Information
  3800. var state = vwf.getState();
  3801. state.nodes[0].children = {};
  3802. var timestamp = state["queue"].time;
  3803. timestamp = Math.round(timestamp * 1000);
  3804. var objectIsTypedArray = function (candidate) {
  3805. var typedArrayTypes = [
  3806. Int8Array,
  3807. Uint8Array,
  3808. // Uint8ClampedArray,
  3809. Int16Array,
  3810. Uint16Array,
  3811. Int32Array,
  3812. Uint32Array,
  3813. Float32Array,
  3814. Float64Array
  3815. ];
  3816. var isTypedArray = false;
  3817. if (typeof candidate == "object" && candidate != null) {
  3818. typedArrayTypes.forEach(function (typedArrayType) {
  3819. isTypedArray = isTypedArray || candidate instanceof typedArrayType;
  3820. });
  3821. }
  3822. return isTypedArray;
  3823. };
  3824. var transitTransformation = function (object) {
  3825. return objectIsTypedArray(object) ?
  3826. Array.prototype.slice.call(object) : object;
  3827. };
  3828. var json = JSON.stringify(
  3829. require("vwf/utility").transform(
  3830. state, transitTransformation
  3831. )
  3832. );
  3833. json = $.encoder.encodeForURL(json);
  3834. var path = window.location.pathname;
  3835. var pathSplit = path.split('/');
  3836. if (pathSplit[0] == "") {
  3837. pathSplit.shift();
  3838. }
  3839. if (pathSplit[pathSplit.length - 1] == "") {
  3840. pathSplit.pop();
  3841. }
  3842. var inst = undefined;
  3843. var instIndex = pathSplit.length - 1;
  3844. if (pathSplit.length > 2) {
  3845. if (pathSplit[pathSplit.length - 2] == "load") {
  3846. instIndex = pathSplit.length - 3;
  3847. }
  3848. }
  3849. if (pathSplit.length > 3) {
  3850. if (pathSplit[pathSplit.length - 3] == "load") {
  3851. instIndex = pathSplit.length - 4;
  3852. }
  3853. }
  3854. inst = pathSplit[instIndex];
  3855. var root = "";
  3856. for (var i = 0; i < instIndex; i++) {
  3857. if (root != "") {
  3858. root = root + "/";
  3859. }
  3860. root = root + pathSplit[i];
  3861. }
  3862. if (filename == '') filename = inst;
  3863. if (root.indexOf('.vwf') != -1) root = root.substring(0, root.lastIndexOf('/'));
  3864. xhr.open("POST", "/" + root + "/save/" + filename, true);
  3865. xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  3866. xhr.send("root=" + root + "/" + filename + "&filename=saveState&inst=" + inst + "&timestamp=" + timestamp + "&extension=.vwf.json" + "&jsonState=" + json);
  3867. // Save Config Information
  3868. var config = { "info": {}, "model": {}, "view": {} };
  3869. // Save browser title
  3870. config["info"]["title"] = $('title').html();
  3871. // Save model drivers
  3872. Object.keys(vwf_view.kernel.kernel.models).forEach(function (modelDriver) {
  3873. if (modelDriver.indexOf('vwf/model/') != -1) config["model"][modelDriver] = "";
  3874. });
  3875. // If neither glge or threejs model drivers are defined, specify nodriver
  3876. if (config["model"]["vwf/model/glge"] === undefined && config["model"]["vwf/model/threejs"] === undefined) config["model"]["nodriver"] = "";
  3877. // Save view drivers and associated parameters, if any
  3878. Object.keys(vwf_view.kernel.kernel.views).forEach(function (viewDriver) {
  3879. if (viewDriver.indexOf('vwf/view/') != -1) {
  3880. if (vwf_view.kernel.kernel.views[viewDriver].parameters) {
  3881. config["view"][viewDriver] = vwf_view.kernel.kernel.views[viewDriver].parameters;
  3882. }
  3883. else config["view"][viewDriver] = "";
  3884. }
  3885. });
  3886. var jsonConfig = $.encoder.encodeForURL(JSON.stringify(config));
  3887. // Save config file to server
  3888. var xhrConfig = new XMLHttpRequest();
  3889. xhrConfig.open("POST", "/" + root + "/save/" + filename, true);
  3890. xhrConfig.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  3891. xhrConfig.send("root=" + root + "/" + filename + "&filename=saveState&inst=" + inst + "&timestamp=" + timestamp + "&extension=.vwf.config.json" + "&jsonState=" + jsonConfig);
  3892. }
  3893. else {
  3894. console.error("Unable to save state.");
  3895. }
  3896. }
  3897. // -- LoadSavedState --------------------------------------------------------------------------
  3898. function loadSavedState(filename, applicationpath, revision) {
  3899. this.logger.info("Loading: " + filename);
  3900. // Redirect until setState ID conflict is resolved
  3901. var path = window.location.pathname;
  3902. var inst = path.substring(path.length - 17, path.length - 1);
  3903. var pathSplit = path.split('/');
  3904. if (pathSplit[0] == "") {
  3905. pathSplit.shift();
  3906. }
  3907. if (pathSplit[pathSplit.length - 1] == "") {
  3908. pathSplit.pop();
  3909. }
  3910. var inst = undefined;
  3911. var instIndex = pathSplit.length - 1;
  3912. if (pathSplit.length > 2) {
  3913. if (pathSplit[pathSplit.length - 2] == "load") {
  3914. instIndex = pathSplit.length - 3;
  3915. }
  3916. }
  3917. if (pathSplit.length > 3) {
  3918. if (pathSplit[pathSplit.length - 3] == "load") {
  3919. instIndex = pathSplit.length - 4;
  3920. }
  3921. }
  3922. inst = pathSplit[instIndex];
  3923. if (revision) {
  3924. window.location.pathname = applicationpath + "/" + inst + '/load/' + filename + '/' + revision + '/';
  3925. }
  3926. else {
  3927. window.location.pathname = applicationpath + "/" + inst + '/load/' + filename + '/';
  3928. }
  3929. // $.get(filename,function(data,status){
  3930. // vwf.setState(data);
  3931. // });
  3932. }
  3933. // -- SupportAjax -----------------------------------------------------------------------------
  3934. function supportAjaxUploadWithProgress() {
  3935. return supportAjaxUploadProgressEvents();
  3936. function supportAjaxUploadProgressEvents() {
  3937. var xhr = new XMLHttpRequest();
  3938. return !!(xhr && ('upload' in xhr) && ('onprogress' in xhr.upload));
  3939. }
  3940. }
  3941. });