editor-new.js 203 KB

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