editor-new.js 123 KB

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