editor-new.js 141 KB

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