editor-new.js 143 KB

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