editor-new.js 136 KB

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