editor-new.js 147 KB

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