editor-new.js 216 KB

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