editor-new.js 171 KB

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