editor-new.js 116 KB

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