editor-new.js 217 KB

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