editor-new.js 223 KB

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