editor-new.js 142 KB

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