editor-new.js 125 KB

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