editor.js 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942
  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. "jquery",
  26. "jquery-ui",
  27. "jquery-encoder-0.1.0"
  28. ], function( module, version, view, utility, $ ) {
  29. return view.load( module, {
  30. // == Module Definition ====================================================================
  31. initialize: function() {
  32. var self = this;
  33. this.nodes = {};
  34. this.scenes = {};
  35. this.allScripts = {};
  36. // EDITOR CLOSED --> 0
  37. // HIERARCHY OPEN --> 1
  38. // USER LIST OPEN --> 2
  39. // TIMELINE OPEN --> 3
  40. // ABOUT OPEN --> 4
  41. this.editorView = 0;
  42. this.editorOpen = false;
  43. this.timelineInit = false;
  44. this.aboutInit = false;
  45. this.modelsInit = false;
  46. this.editingScript = false;
  47. this.topdownName = '#topdown_a';
  48. this.topdownTemp = '#topdown_b';
  49. this.clientList = '#client_list';
  50. this.timeline = '#time_control';
  51. this.about = '#about_tab';
  52. this.models = '#model_a';
  53. this.modelsTemp = '#model_b';
  54. this.currentNodeID = '';
  55. this.currentModelID = '';
  56. this.currentModelURL = '';
  57. this.highlightedChild = '';
  58. this.intervalTimer = 0;
  59. this.activeCameraID = undefined;
  60. $('body').append(
  61. "<div id='editor' class='relClass'>\n" +
  62. " <div class='uiContainer'>\n" +
  63. " <div class='editor-tabs' id='tabs'>\n" +
  64. " <img id='x' style='display:none' src='images/tab_X.png' alt='x' />\n" +
  65. " <img id='hierarchy' src='images/tab_Application.png' alt='application' />\n" +
  66. " <img id='userlist' src='images/tab_Users.png' alt='users' />\n" +
  67. " <img id='timeline' src='images/tab_Time.png' alt='time' />\n" +
  68. " <img id='models' src='images/tab_Models.png' alt='models' />\n" +
  69. " <img id='about' src='images/tab_About.png' alt='about' />\n" +
  70. " </div>\n" +
  71. " </div>\n" +
  72. "</div>" +
  73. "<div class='relClass'><div class='uiContainer'><div class='vwf-tree' id='topdown_a'></div></div></div>" +
  74. "<div class='relClass'><div class='uiContainer'><div class='vwf-tree' id='topdown_b'></div></div></div>" +
  75. "<div class='relClass'><div class='uiContainer'><div class='vwf-tree' id='client_list'></div></div></div>" +
  76. "<div class='relClass'><div class='uiContainer'><div class='vwf-tree' id='time_control'></div></div></div>" +
  77. "<div class='relClass'><div class='uiContainer'><div class='vwf-tree' id='about_tab'></div></div></div>" +
  78. "<div class='relClass'><div class='uiContainer'><div class='vwf-tree' id='model_a'></div></div></div>" +
  79. "<div class='relClass'><div class='uiContainer'><div class='vwf-tree' id='model_b'></div></div></div>"
  80. );
  81. $('#tabs').stop().animate({ opacity:0.0 }, 0);
  82. $('#tabs').mouseenter( function(evt) {
  83. evt.stopPropagation();
  84. $('#tabs').stop().animate({ opacity:1.0 }, 175);
  85. return false;
  86. });
  87. $('#tabs').mouseleave( function(evt) {
  88. evt.stopPropagation();
  89. $('#tabs').stop().animate({ opacity:0.0 }, 175);
  90. return false;
  91. });
  92. $('#hierarchy').click ( function(evt) {
  93. openEditor.call(self, 1);
  94. });
  95. $('#userlist').click ( function(evt) {
  96. openEditor.call(self, 2);
  97. });
  98. $('#timeline').click ( function(evt) {
  99. openEditor.call(self, 3);
  100. });
  101. $('#about').click ( function(evt) {
  102. openEditor.call(self, 4);
  103. });
  104. $('#models').click ( function(evt) {
  105. openEditor.call(self, 5);
  106. });
  107. $('#x').click ( function(evt) {
  108. closeEditor.call(self);
  109. });
  110. $('#topdown_a').hide();
  111. $('#topdown_b').hide();
  112. $('#client_list').hide();
  113. $('#time_control').hide();
  114. $('#about_tab').hide();
  115. $('#model_a').hide();
  116. $('#model_b').hide();
  117. var canvas = document.getElementById(vwf_view.kernel.find("", "/")[0]);
  118. if ( canvas ) {
  119. $('#topdown_a').height(canvas.height);
  120. $('#topdown_b').height(canvas.height);
  121. $('#client_list').height(canvas.height);
  122. $('#time_control').height(canvas.height);
  123. $('#about_tab').height(canvas.height);
  124. $('#model_a').height(canvas.height);
  125. $('#model_b').height(canvas.height);
  126. }
  127. else
  128. {
  129. $('#topdown_a').height(window.innerHeight-20);
  130. $('#topdown_b').height(window.innerHeight-20);
  131. $('#client_list').height(window.innerHeight-20);
  132. $('#time_control').height(window.innerHeight-20);
  133. $('#about_tab').height(window.innerHeight-20);
  134. $('#model_a').height(window.innerHeight-20);
  135. $('#model_b').height(window.innerHeight-20);
  136. }
  137. },
  138. createdNode: function( nodeID, childID, childExtendsID, childImplementsIDs,
  139. childSource, childType, childIndex, childName, callback /* ( ready ) */ ) {
  140. var nodeIDAttribute = $.encoder.encodeForHTMLAttribute("id", nodeID, true);
  141. var childIDAttribute = $.encoder.encodeForHTMLAttribute("id", childID, true);
  142. var childIDAlpha = $.encoder.encodeForAlphaNumeric(childID);
  143. var kernel = this.kernel;
  144. var self = this;
  145. var parent = this.nodes[ nodeID ];
  146. var node = this.nodes[ childID ] = {
  147. children: [],
  148. properties: [],
  149. events: {},
  150. methods: {},
  151. parent: parent,
  152. parentID: nodeID,
  153. ID: childID,
  154. extendsID: childExtendsID,
  155. implementsIDs: childImplementsIDs,
  156. source: childSource,
  157. name: childName,
  158. };
  159. if ( parent ) {
  160. parent.children.push( node );
  161. }
  162. if ( childID == vwf_view.kernel.find("", "/")[0] && childExtendsID && this.kernel.test( childExtendsID,
  163. "self::element(*,'http://vwf.example.com/scene.vwf')", childExtendsID ) ) {
  164. this.scenes[ childID ] = node;
  165. }
  166. if ( nodeID === this.currentNodeID && this.editingScript == false )
  167. {
  168. $('#children > div:last').css('border-bottom-width', '1px');
  169. $("#children").append("<div id='" + childIDAlpha + "' data-nodeID='" + childIDAttribute + "' class='childContainer'><div class='childEntry'><b>" + $.encoder.encodeForHTML(childName) + "</b></div></div>");
  170. $('#' + childIDAlpha).click( function(evt) {
  171. drillDown.call(self, $(this).attr("data-nodeID"), nodeIDAttribute);
  172. });
  173. $('#children > div:last').css('border-bottom-width', '3px');
  174. }
  175. if ( nodeID === this.kernel.application() && childName === 'camera' ) {
  176. this.activeCameraID = childID;
  177. }
  178. },
  179. createdProperty: function (nodeID, propertyName, propertyValue) {
  180. return this.initializedProperty(nodeID, propertyName, propertyValue);
  181. },
  182. initializedProperty: function (nodeID, propertyName, propertyValue) {
  183. var node = this.nodes[ nodeID ];
  184. if ( ! node ) return; // TODO: patch until full-graph sync is working; drivers should be able to assume that nodeIDs refer to valid objects
  185. var property = node.properties[ propertyName ] = createProperty.call( this, node, propertyName, propertyValue );
  186. node.properties.push( property );
  187. },
  188. deletedNode: function (nodeID) {
  189. var node = this.nodes[ nodeID ];
  190. node.parent.children.splice( node.parent.children.indexOf(node), 1 );
  191. delete this.nodes[ nodeID ];
  192. var nodeIDAttribute = $.encoder.encodeForAlphaNumeric(nodeID); // $.encoder.encodeForHTMLAttribute("id", nodeID, true);
  193. $('#' + nodeIDAttribute).remove();
  194. $('#children > div:last').css('border-bottom-width', '3px');
  195. },
  196. //addedChild: [ /* nodeID, childID, childName */ ],
  197. //removedChild: [ /* nodeID, childID */ ],
  198. satProperty: function (nodeID, propertyName, propertyValue) {
  199. var node = this.nodes[ nodeID ];
  200. if ( ! node ) return; // TODO: patch until full-graph sync is working; drivers should be able to assume that nodeIDs refer to valid objects
  201. // It is possible for a property to have satProperty called for it without ever getting an
  202. // initializedProperty (if that property delegated to itself or another on replication)
  203. // Catch that case here and create the property
  204. if ( ! node.properties[ propertyName ] ) {
  205. var property = node.properties[ propertyName ] = createProperty.call( this, node, propertyName, propertyValue );
  206. node.properties.push( property );
  207. }
  208. if ( propertyName === "activeCamera" ) {
  209. if ( this.nodes[ propertyValue ] !== undefined ) {
  210. this.activeCameraID = propertyValue;
  211. }
  212. }
  213. try {
  214. propertyValue = utility.transform( propertyValue, utility.transforms.transit );
  215. node.properties[ propertyName ].value = JSON.stringify( propertyValue );
  216. } catch (e) {
  217. this.logger.warnx( "satProperty", nodeID, propertyName, propertyValue,
  218. "stringify error:", e.message );
  219. node.properties[ propertyName ].value = propertyValue;
  220. }
  221. if ( ( this.editorView == 1 ) && ( this.currentNodeID == nodeID ) ) {
  222. var nodeIDAttribute = $.encoder.encodeForAlphaNumeric(nodeID); // $.encoder.encodeForHTMLAttribute("id", nodeID, true);
  223. var propertyNameAttribute = $.encoder.encodeForAlphaNumeric("id", propertyName, true);
  224. // No need to escape propertyValue, because .val does its own escaping
  225. $( '#input-' + nodeIDAttribute + '-' + propertyNameAttribute ).val( node.properties[ propertyName ].getValue() );
  226. }
  227. },
  228. //gotProperty: [ /* nodeID, propertyName, propertyValue */ ],
  229. createdMethod: function( nodeID, methodName, methodParameters, methodBody ){
  230. var node = this.nodes[ nodeID ];
  231. if ( node ) {
  232. node.methods[ methodName ] = methodParameters;
  233. }
  234. },
  235. //calledMethod: function( nodeID, methodName, methodParameters, methodValue ) {
  236. //},
  237. createdEvent: function( nodeID, eventName, eventParameters ) {
  238. var node = this.nodes[ nodeID ];
  239. if ( node ) {
  240. node.events[ eventName ] = eventParameters;
  241. }
  242. },
  243. firedEvent: function ( nodeID, eventName, eventParameters ) {
  244. if(eventName == "pointerHover") {
  245. highlightChildInHierarchy.call(this, nodeID);
  246. }
  247. },
  248. executed: function( nodeID, scriptText, scriptType ) {
  249. var nodeScript = {
  250. text: scriptText,
  251. type: scriptType,
  252. };
  253. if ( !this.allScripts[ nodeID ] ) {
  254. var nodeScripts = new Array();
  255. nodeScripts.push(nodeScript);
  256. this.allScripts[ nodeID ] = nodeScripts;
  257. }
  258. else {
  259. this.allScripts[ nodeID ].push(nodeScript);
  260. }
  261. },
  262. //ticked: [ /* time */ ],
  263. } );
  264. // -- getChildByName --------------------------------------------------------------------
  265. function getChildByName( node, childName ) {
  266. var childNode = undefined;
  267. for ( var i = 0; i < node.children.length && childNode === undefined; i++ ) {
  268. if ( node.children[i].name == childName ) {
  269. childNode = node.children[i];
  270. }
  271. }
  272. return childNode;
  273. };
  274. function updateCameraProperties () {
  275. if ( this.currentNodeID == this.activeCameraID ) {
  276. if ( !this.intervalTimer ) {
  277. var self = this;
  278. this.intervalTimer = setInterval( function() { updateProperties.call( self, self.activeCameraID ) }, 200 );
  279. }
  280. }
  281. else {
  282. if ( this.intervalTimer ) {
  283. clearInterval( this.intervalTimer );
  284. this.intervalTimer = 0;
  285. }
  286. }
  287. }
  288. function updateProperties( nodeName ) {
  289. var nodeID = nodeName;
  290. var properties = getProperties.call( this, this.kernel, nodeID );
  291. for ( var i in properties ) {
  292. try {
  293. var propertyName = properties[i].prop.name;
  294. var propertyValue = JSON.stringify( utility.transform( vwf.getProperty( nodeID, propertyName, [] ), utility.transforms.transit ));
  295. } catch ( e ) {
  296. this.logger.warnx( "satProperty", nodeID, propertyName, propertyValue, "stringify error:", e.message );
  297. }
  298. if ( propertyValue ) {
  299. var nodeIDAttribute = $.encoder.encodeForAlphaNumeric( nodeID );
  300. var propertyNameAttribute = $.encoder.encodeForHTMLAttribute( "id", propertyName, true );
  301. var inputElement$ = $( '#input-' + nodeIDAttribute + '-' + propertyNameAttribute );
  302. // Only update if property value input is not in focus
  303. // If in focus, change font style to italic
  304. if ( ! inputElement$.is(":focus") ) {
  305. inputElement$.val( propertyValue );
  306. inputElement$.css( "font-style", "normal");
  307. } else {
  308. inputElement$.css( "font-style", "italic");
  309. }
  310. }
  311. }
  312. }
  313. // -- openEditor ------------------------------------------------------------------------
  314. function openEditor(eView) // invoke with the view as "this"
  315. {
  316. if(eView == 0)
  317. {
  318. closeEditor.call(this);
  319. }
  320. if(this.editorView != eView)
  321. {
  322. // Hierarchy
  323. if(eView == 1)
  324. {
  325. var topdownName = this.topdownName;
  326. var topdownTemp = this.topdownTemp;
  327. if( !this.currentNodeID )
  328. {
  329. this.currentNodeID = vwf_view.kernel.find("", "/")[0];
  330. }
  331. drill.call(this, this.currentNodeID, undefined);
  332. $(this.clientList).hide();
  333. $(this.timeline).hide();
  334. $(this.about).hide();
  335. $(this.models).hide();
  336. if(this.editorOpen)
  337. {
  338. $(topdownName).hide();
  339. $(topdownTemp).show();
  340. }
  341. else
  342. {
  343. $(topdownTemp).show('slide', {direction: 'right'}, 175);
  344. }
  345. this.topdownName = topdownTemp;
  346. this.topdownTemp = topdownName;
  347. }
  348. else if (this.editingScript)
  349. {
  350. // Reset width if on script
  351. this.editingScript = false;
  352. $('#editor').animate({ 'left' : "-260px" }, 175);
  353. $('.vwf-tree').animate({ 'width' : "260px" }, 175);
  354. }
  355. // User List
  356. if(eView == 2)
  357. {
  358. $(this.topdownName).hide();
  359. $(this.topdownTemp).hide();
  360. $(this.timeline).hide();
  361. $(this.about).hide();
  362. $(this.models).hide();
  363. $(this.modelsTemp).hide();
  364. showUserList.call(this);
  365. }
  366. // Timeline
  367. else if(eView == 3)
  368. {
  369. $(this.topdownName).hide();
  370. $(this.topdownTemp).hide();
  371. $(this.clientList).hide();
  372. $(this.about).hide();
  373. $(this.models).hide();
  374. $(this.modelsTemp).hide();
  375. showTimeline.call(this);
  376. }
  377. // About
  378. else if(eView == 4)
  379. {
  380. $(this.topdownName).hide();
  381. $(this.topdownTemp).hide();
  382. $(this.clientList).hide();
  383. $(this.timeline).hide();
  384. $(this.models).hide();
  385. $(this.modelsTemp).hide();
  386. showAboutTab.call(this);
  387. }
  388. // Models
  389. else if(eView == 5)
  390. {
  391. var models = this.models;
  392. var modelsTemp = this.modelsTemp;
  393. showModelsTab.call(this, this.currentModelID, this.currentModelURL);
  394. $(this.topdownName).hide();
  395. $(this.topdownTemp).hide();
  396. $(this.clientList).hide();
  397. $(this.timeline).hide();
  398. $(this.about).hide();
  399. if(this.editorOpen)
  400. {
  401. $(models).hide();
  402. $(modelsTemp).show();
  403. }
  404. else
  405. {
  406. $(modelsTemp).show('slide', {direction: 'right'}, 175);
  407. }
  408. this.models = modelsTemp;
  409. this.modelsTemp = models;
  410. }
  411. if(this.editorView == 0)
  412. {
  413. $('#vwf-root').animate({ 'left' : "-=260px" }, 175);
  414. $('#editor').animate({ 'left' : "-260px" }, 175);
  415. $('#x').delay(1000).css({ 'display' : 'inline' });
  416. }
  417. this.editorView = eView;
  418. this.editorOpen = true;
  419. }
  420. }
  421. // -- closeEditor -----------------------------------------------------------------------
  422. function closeEditor() // invoke with the view as "this"
  423. {
  424. var topdownName = this.topdownName;
  425. if (this.editorOpen && this.editorView == 1) // Hierarchy view open
  426. {
  427. $(topdownName).hide('slide', {direction: 'right'}, 175);
  428. $(topdownName).empty();
  429. $(this.clientList).hide();
  430. $(this.timeline).hide();
  431. $(this.about).hide();
  432. $(this.models).hide();
  433. }
  434. else if (this.editorOpen && this.editorView == 2) // Client list open
  435. {
  436. $(this.clientList).hide('slide', {direction: 'right'}, 175);
  437. $(topdownName).hide();
  438. $(this.timeline).hide();
  439. $(this.about).hide();
  440. $(this.models).hide();
  441. }
  442. else if (this.editorOpen && this.editorView == 3) // Timeline open
  443. {
  444. $(this.timeline).hide('slide', {direction: 'right'}, 175);
  445. $(topdownName).hide();
  446. $(this.clientList).hide();
  447. $(this.about).hide();
  448. $(this.models).hide();
  449. }
  450. else if (this.editorOpen && this.editorView == 4) // About open
  451. {
  452. $(this.about).hide('slide', {direction: 'right'}, 175);
  453. $(topdownName).hide();
  454. $(this.clientList).hide();
  455. $(this.timeline).hide();
  456. $(this.models).hide();
  457. }
  458. else if (this.editorOpen && this.editorView == 5) // Models open
  459. {
  460. $(this.models).hide('slide', {direction: 'right'}, 175);
  461. $(topdownName).hide();
  462. $(this.clientList).hide();
  463. $(this.timeline).hide();
  464. $(this.about).hide();
  465. }
  466. $('#vwf-root').animate({ 'left' : "+=260px" }, 175);
  467. $('#editor').animate({ 'left' : "0px" }, 175);
  468. $('#x').css({ 'display' : 'none' });
  469. this.editorView = 0;
  470. this.editorOpen = false;
  471. }
  472. // -- showUserList ----------------------------------------------------------------------
  473. function showUserList() // invoke with the view as "this"
  474. {
  475. var clientList = this.clientList;
  476. viewClients.call(this);
  477. if (!this.editorOpen)
  478. {
  479. $(clientList).show('slide', {direction: 'right'}, 175);
  480. }
  481. else
  482. {
  483. $(clientList).show();
  484. }
  485. }
  486. // -- viewClients -----------------------------------------------------------------------
  487. function viewClients() {
  488. var self = this;
  489. var app = window.location.pathname;
  490. var pathSplit = app.split('/');
  491. if ( pathSplit[0] == "" ) {
  492. pathSplit.shift();
  493. }
  494. if ( pathSplit[ pathSplit.length - 1 ] == "" ) {
  495. pathSplit.pop();
  496. }
  497. var instIndex = pathSplit.length - 1;
  498. if ( pathSplit.length > 2 ) {
  499. if ( pathSplit[ pathSplit.length - 2 ] == "load" ) {
  500. instIndex = pathSplit.length - 3;
  501. }
  502. }
  503. if ( pathSplit.length > 3 ) {
  504. if ( pathSplit[ pathSplit.length - 3 ] == "load" ) {
  505. instIndex = pathSplit.length - 4;
  506. }
  507. }
  508. var root = "";
  509. for ( var i=0; i < instIndex; i++ ) {
  510. if ( root != "" ) {
  511. root = root + "/";
  512. }
  513. root = root + pathSplit[i];
  514. }
  515. if(root.indexOf('.vwf') != -1) root = root.substring(0, root.lastIndexOf('/'));
  516. var clients$ = $(this.clientList);
  517. var node = this.nodes[ "http://vwf.example.com/clients.vwf" ];
  518. clients$.html("<div class='header'>Connected Clients</div>");
  519. // Add node children
  520. clients$.append("<div id='clientsChildren'></div>");
  521. for ( var i = 0; i < node.children.length; i++ ) {
  522. var nodeChildIDAttribute = $.encoder.encodeForHTMLAttribute("id", node.children[i].ID, true);
  523. var nodeChildIDAlpha = $.encoder.encodeForAlphaNumeric(node.children[i].ID);
  524. var nodeChildNameHTML = $.encoder.encodeForHTML(node.children[i].name);
  525. $('#clientsChildren').append("<div id='" + nodeChildIDAlpha + "' data-nodeID='" + nodeChildIDAttribute + "' class='childContainer'><div class='childEntry'><b>" + nodeChildNameHTML + "</b></div></div>");
  526. $('#' + nodeChildIDAlpha).click( function(evt) {
  527. viewClient.call(self, $(this).attr("data-nodeID"));
  528. });
  529. }
  530. // Login Information
  531. 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>");
  532. clients$.append("<hr/>");
  533. $('#userName').keydown( function(evt) {
  534. evt.stopPropagation();
  535. });
  536. $('#userName').keypress( function(evt) {
  537. evt.stopPropagation();
  538. });
  539. $('#userName').keyup( function(evt) {
  540. evt.stopPropagation();
  541. });
  542. $('#password').keydown( function(evt) {
  543. evt.stopPropagation();
  544. });
  545. $('#password').keypress( function(evt) {
  546. evt.stopPropagation();
  547. });
  548. $('#password').keyup( function(evt) {
  549. evt.stopPropagation();
  550. });
  551. $('#login').click(function(evt) {
  552. // Future call to validate username and password
  553. //login.call(self, $('#userName').val(), $('#password').val());
  554. var moniker = vwf_view.kernel.moniker();
  555. var clients = vwf_view.kernel.findClients("", "/*");
  556. var client = undefined;
  557. for (var i=0; i < clients.length; i++)
  558. {
  559. if ( clients[i].indexOf(moniker) != -1 )
  560. {
  561. client = clients[i];
  562. break;
  563. }
  564. }
  565. // var client = vwf_view.kernel.findClients("", "/" + moniker)[0];
  566. if ( client ) {
  567. vwf_view.kernel.setProperty( client, "displayName", $('#userName').val() );
  568. }
  569. });
  570. // Save / Load
  571. 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>");
  572. $('#fileName').keydown( function(evt) {
  573. evt.stopPropagation();
  574. });
  575. $('#fileName').keypress( function(evt) {
  576. evt.stopPropagation();
  577. });
  578. $('#fileName').keyup( function(evt) {
  579. evt.stopPropagation();
  580. });
  581. $('#save').click(function(evt) {
  582. saveStateAsFile.call(self, $('#fileName').val());
  583. });
  584. clients$.append("<div style='padding:6px'><select class='filename_select' id='fileToLoad' /></select></div>");
  585. $('#fileToLoad').append("<option value='none'></option>");
  586. $.getJSON( "/" + root + "/listallsaves", function( data ) {
  587. $.each( data, function( key, value ) {
  588. var applicationName = value[ 'applicationpath' ].split( "/" );
  589. if ( applicationName.length > 0 ) {
  590. applicationName = applicationName[ applicationName.length - 1 ];
  591. }
  592. if ( applicationName.length > 0 ) {
  593. applicationName = applicationName.charAt(0).toUpperCase() + applicationName.slice(1);
  594. }
  595. if ( value['latestsave'] ) {
  596. $('#fileToLoad').append("<option value='"+value['savename']+"' applicationpath='"+value['applicationpath']+"'>"+applicationName+": "+value['savename']+"</option>");
  597. }
  598. else {
  599. $('#fileToLoad').append("<option value='"+value['savename']+"' applicationpath='"+value['applicationpath']+"' revision='"+value['revision']+"'>"+applicationName+": "+value['savename']+" Rev(" + value['revision'] + ")</option>");
  600. }
  601. } );
  602. } );
  603. clients$.append("<div style='padding:6px'><input class='update_button' type='button' id='load' value='Load' /></div>");
  604. $('#load').click(function(evt) {
  605. loadSavedState.call(self, $('#fileToLoad').val(), $('#fileToLoad').find(':selected').attr('applicationpath'), $('#fileToLoad').find(':selected').attr('revision'));
  606. });
  607. }
  608. // -- viewClient ------------------------------------------------------------------------
  609. function viewClient( clientID ) {
  610. var self = this;
  611. var clients$ = $(this.clientList);
  612. var node = this.nodes[ clientID ];
  613. clients$.html("<div class='header'><img src='images/back.png' id='back' alt='back'/> " + $.encoder.encodeForHTML(node.name) + "</div>");
  614. $('#back').click ( function(evt) {
  615. viewClients.call( self );
  616. });
  617. // Add node properties
  618. clients$.append("<div id='clientProperties'></div>");
  619. var displayedProperties = {};
  620. for ( var i = 0; i < node.properties.length; i++ ) {
  621. if ( !displayedProperties[ node.properties[i].name ] ) {
  622. displayedProperties[ node.properties[i].name ] = "instance";
  623. var nodeIDAlpha = $.encoder.encodeForAlphaNumeric(clientID);
  624. var propertyNameAttribute = $.encoder.encodeForHTMLAttribute("id", node.properties[i].name, true);
  625. var propertyNameAlpha = $.encoder.encodeForAlphaNumeric(node.properties[i].name);
  626. var propertyNameHTML = $.encoder.encodeForHTML(node.properties[i].name);
  627. var propertyValueAttribute = $.encoder.encodeForHTMLAttribute("val", node.properties[i].getValue(), true);
  628. $('#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>");
  629. }
  630. }
  631. }
  632. // -- drillDown -------------------------------------------------------------------------
  633. function drillDown(nodeID, drillBackID) // invoke with the view as "this"
  634. {
  635. var topdownName = this.topdownName;
  636. var topdownTemp = this.topdownTemp;
  637. drill.call(this, nodeID, drillBackID);
  638. if(nodeID != vwf_view.kernel.find("", "/")[0]) $(topdownName).hide('slide', {direction: 'left'}, 175);
  639. $(topdownTemp).show('slide', {direction: 'right'}, 175);
  640. this.topdownName = topdownTemp;
  641. this.topdownTemp = topdownName;
  642. }
  643. // -- drillUp ---------------------------------------------------------------------------
  644. function drillUp(nodeID) // invoke with the view as "this"
  645. {
  646. var topdownName = this.topdownName;
  647. var topdownTemp = this.topdownTemp;
  648. drill.call(this, nodeID, undefined);
  649. $(topdownName).hide('slide', {direction: 'right'}, 175);
  650. $(topdownTemp).show('slide', {direction: 'left'}, 175);
  651. this.topdownName = topdownTemp;
  652. this.topdownTemp = topdownName;
  653. }
  654. // -- drillBack---------------------------------------------------------------------------
  655. function drillBack(nodeID) // invoke with the view as "this"
  656. {
  657. var topdownName = this.topdownName;
  658. var topdownTemp = this.topdownTemp;
  659. drill.call(this, nodeID, undefined);
  660. // No slide motion, when resizing script window back to normal
  661. $(topdownName).hide();
  662. $(topdownTemp).show();
  663. this.topdownName = topdownTemp;
  664. this.topdownTemp = topdownName;
  665. }
  666. // -- drill -----------------------------------------------------------------------------
  667. function drill(nodeID, drillBackID) // invoke with the view as "this"
  668. {
  669. var node = this.nodes[ nodeID ];
  670. if ( !node ) {
  671. this.logger.errorx( "drill: Cannot find node '" + nodeID + "'" );
  672. return;
  673. }
  674. var self = this;
  675. var topdownName = this.topdownName;
  676. var topdownTemp = this.topdownTemp;
  677. var nodeIDAlpha = $.encoder.encodeForAlphaNumeric(nodeID);
  678. $(topdownName).html(''); // Clear alternate div first to ensure content is added correctly
  679. this.currentNodeID = nodeID;
  680. if(!drillBackID) drillBackID = node.parentID;
  681. if(nodeID == vwf_view.kernel.find("", "/")[0])
  682. {
  683. $(topdownTemp).html("<div class='header'>index</div>");
  684. }
  685. else
  686. {
  687. $(topdownTemp).html("<div class='header'><img src='images/back.png' id='" + nodeIDAlpha + "-back' alt='back'/> " + $.encoder.encodeForHTML(node.name) + "</div>");
  688. $('#' + nodeIDAlpha + '-back').click ( function(evt) {
  689. drillUp.call(self, drillBackID);
  690. });
  691. }
  692. // Add node children
  693. $(topdownTemp).append("<div id='children'></div>");
  694. for ( var i = 0; i < node.children.length; i++ ) {
  695. var nodeChildIDAttribute = $.encoder.encodeForHTMLAttribute("id", node.children[i].ID, true);
  696. var nodeChildIDAlpha = $.encoder.encodeForAlphaNumeric(node.children[i].ID);
  697. $('#children').append("<div id='" + nodeChildIDAlpha + "' data-nodeID='" + nodeChildIDAttribute + "' class='childContainer'><div class='childEntry'><b>" + $.encoder.encodeForHTML(node.children[i].name) + "</b></div></div>");
  698. $('#' + nodeChildIDAlpha).click( function(evt) {
  699. drillDown.call(self, $(this).attr("data-nodeID"), nodeID);
  700. });
  701. }
  702. $('#children > div:last').css('border-bottom-width', '3px');
  703. // Add prototype children
  704. // TODO: Commented out until prototype children inherit from prototypes
  705. /*
  706. $(topdownTemp).append("<div id='prototypeChildren'></div>");
  707. var prototypeChildren = getChildren.call( this, this.kernel, node.extendsID );
  708. for ( var key in prototypeChildren)
  709. {
  710. var child = prototypeChildren[key];
  711. var prototypeChildIDAttribute = $.encoder.encodeForHTMLAttribute("id", child.ID, true);
  712. var prototypeChildIDAlpha = $.encoder.encodeForAlphaNumeric(child.ID);
  713. $('#prototypeChildren').append("<div id='" + prototypeChildIDAlpha + "' data-nodeID='" + prototypeChildIDAttribute + "' class='childContainer'><div class='childEntry'><b>" + $.encoder.encodeForHTML(child.name) + "</b></div></div>");
  714. $('#' + prototypeChildIDAlpha).click( function(evt) {
  715. drillDown.call(self, $(this).attr("data-nodeID"), nodeID);
  716. });
  717. }
  718. */ // END TODO:
  719. $('#prototypeChildren > div:last').css('border-bottom-width', '3px');
  720. // Add node properties
  721. $(topdownTemp).append("<div id='properties'></div>");
  722. var displayedProperties = {};
  723. for ( var i = 0; i < node.properties.length; i++ ) {
  724. if ( !displayedProperties[ node.properties[i].name ] && node.properties[i].name.indexOf('$') === -1) {
  725. displayedProperties[ node.properties[i].name ] = "instance";
  726. var propertyNameAttribute = $.encoder.encodeForHTMLAttribute("id", node.properties[i].name, true);
  727. var propertyNameAlpha = $.encoder.encodeForAlphaNumeric(node.properties[i].name);
  728. var propertyNameHTML = $.encoder.encodeForHTML(node.properties[i].name);
  729. var propertyValueAttribute = $.encoder.encodeForHTMLAttribute("val", node.properties[i].getValue(), true);
  730. $('#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>");
  731. $('#input-' + nodeIDAlpha + '-' + propertyNameAttribute).change( function(evt) {
  732. var propName = $.encoder.canonicalize($(this).attr("data-propertyName"));
  733. var propValue = $(this).val();
  734. try {
  735. propValue = JSON.parse($.encoder.canonicalize(propValue));
  736. self.kernel.setProperty(nodeID, propName, propValue);
  737. } catch (e) {
  738. // restore the original value on error
  739. $(this).val(propValue);
  740. }
  741. } );
  742. $('#input-' + nodeIDAlpha + '-' + propertyNameAlpha).keydown( function(evt) {
  743. evt.stopPropagation();
  744. });
  745. $('#input-' + nodeIDAlpha + '-' + propertyNameAlpha).keypress( function(evt) {
  746. evt.stopPropagation();
  747. });
  748. $('#input-' + nodeIDAlpha + '-' + propertyNameAlpha).keyup( function(evt) {
  749. evt.stopPropagation();
  750. });
  751. }
  752. }
  753. $('#properties > div:last').css('border-bottom-width', '3px');
  754. this.logger.info(self + " " + nodeID);
  755. // Add prototype properties
  756. $(topdownTemp).append("<div id='prototypeProperties'></div>");
  757. var prototypeProperties = getProperties.call( this, this.kernel, node.extendsID );
  758. for ( var key in prototypeProperties ) {
  759. var prop = prototypeProperties[key].prop;
  760. if ( !displayedProperties[ prop.name ] ) {
  761. displayedProperties[ prop.name ] = prototypeProperties[key].prototype;
  762. if(prop.value == undefined)
  763. {
  764. prop.value = JSON.stringify( utility.transform( vwf.getProperty( nodeID, prop.name, []), utility.transforms.transit ) );
  765. }
  766. var propertyNameAttribute = $.encoder.encodeForHTMLAttribute("id", prop.name, true);
  767. var propertyNameAlpha = $.encoder.encodeForAlphaNumeric(prop.name);
  768. var propertyNameHTML = $.encoder.encodeForHTML(prop.name);
  769. var propertyValueAttribute = $.encoder.encodeForHTMLAttribute("val", prop.value, true);
  770. $('#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>");
  771. $('#input-' + nodeIDAlpha + '-' + propertyNameAlpha).change( function(evt) {
  772. var propName = $.encoder.canonicalize($(this).attr("data-propertyName"));
  773. var propValue = $(this).val();
  774. try {
  775. propValue = JSON.parse($.encoder.canonicalize(propValue));
  776. self.kernel.setProperty(nodeID, propName, propValue);
  777. } catch (e) {
  778. // restore the original value on error
  779. $(this).val(propValue);
  780. }
  781. } );
  782. $('#input-' + nodeIDAlpha + '-' + propertyNameAlpha).keydown( function(evt) {
  783. evt.stopPropagation();
  784. });
  785. $('#input-' + nodeIDAlpha + '-' + propertyNameAlpha).keypress( function(evt) {
  786. evt.stopPropagation();
  787. });
  788. $('#input-' + nodeIDAlpha + '-' + propertyNameAlpha).keyup( function(evt) {
  789. evt.stopPropagation();
  790. });
  791. }
  792. }
  793. $('#prototypeProperties > div:last').css('border-bottom-width', '3px');
  794. // Add node methods
  795. $(topdownTemp).append("<div id='methods'></div>");
  796. for ( var key in node.methods ) {
  797. var method = node.methods[key];
  798. var methodNameAlpha = $.encoder.encodeForAlphaNumeric(key);
  799. var methodNameAttribute = $.encoder.encodeForHTMLAttribute("id", key, true);
  800. var methodNameHTML = $.encoder.encodeForHTML(key);
  801. $('#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>");
  802. $('#rollover-' + methodNameAlpha).mouseover( function(evt) {
  803. $('#param-' + $(this).attr("id").substring(9)).css('visibility', 'visible');
  804. });
  805. $('#rollover-' + methodNameAlpha).mouseleave( function(evt) {
  806. $('#param-' + $(this).attr("id").substring(9)).css('visibility', 'hidden');
  807. });
  808. $('#call-' + methodNameAlpha).click( function(evt) {
  809. self.kernel.callMethod( nodeID, $.encoder.canonicalize($(this).attr("data-methodName")) );
  810. });
  811. $('#param-' + methodNameAlpha).click( function(evt) {
  812. setParams.call(self, $.encoder.canonicalize($(this).attr("data-methodName")), method, nodeID);
  813. });
  814. }
  815. $('#methods > div:last').css('border-bottom-width', '3px');
  816. // Add prototype methods
  817. $(topdownTemp).append("<div id='prototypeMethods'></div>");
  818. var prototypeMethods = getMethods.call( this, this.kernel, node.extendsID );
  819. for ( var key in prototypeMethods ) {
  820. var method = prototypeMethods[key];
  821. var prototypeMethodNameAlpha = $.encoder.encodeForAlphaNumeric(key);
  822. var prototypeMethodNameAttribute = $.encoder.encodeForHTMLAttribute("id", key, true);
  823. var prototypeMethodNameHTML = $.encoder.encodeForHTML(key);
  824. $('#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>");
  825. $('#rollover-' + prototypeMethodNameAlpha).mouseover( function(evt) {
  826. $('#param-' + $(this).attr("id").substring(9)).css('visibility', 'visible');
  827. });
  828. $('#rollover-' + prototypeMethodNameAlpha).mouseleave( function(evt) {
  829. $('#param-' + $(this).attr("id").substring(9)).css('visibility', 'hidden');
  830. });
  831. $('#call-' + prototypeMethodNameAlpha).click( function(evt) {
  832. self.kernel.callMethod( nodeID, $.encoder.canonicalize($(this).attr("data-methodName")) );
  833. });
  834. $('#param-' + prototypeMethodNameAlpha).click( function(evt) {
  835. setParams.call(self, $.encoder.canonicalize($(this).attr("data-methodName")), method, nodeID);
  836. });
  837. }
  838. $('#prototypeMethods > div:last').css('border-bottom-width', '3px');
  839. // Add node events
  840. $(topdownTemp).append("<div id='events'></div>");
  841. for ( var key in node.events ) {
  842. var nodeEvent = node.events[key];
  843. var eventNameAlpha = $.encoder.encodeForAlphaNumeric(key);
  844. var eventNameAttribute = $.encoder.encodeForHTMLAttribute("id", key, true);
  845. var eventNameHTML = $.encoder.encodeForHTML(key);
  846. $('#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>");
  847. $('#rollover-' + eventNameAlpha).mouseover( function(evt) {
  848. $('#arg-' + $(this).attr("id").substring(9)).css('visibility', 'visible');
  849. });
  850. $('#rollover-' + eventNameAlpha).mouseleave( function(evt) {
  851. $('#arg-' + $(this).attr("id").substring(9)).css('visibility', 'hidden');
  852. });
  853. $('#fire-' + eventNameAlpha).click( function(evt) {
  854. self.kernel.fireEvent( nodeID, $.encoder.canonicalize($(this).attr("data-eventName")) );
  855. });
  856. $('#arg-' + eventNameAlpha).click( function(evt) {
  857. setArgs.call(self, $.encoder.canonicalize($(this).attr("data-eventName")), nodeEvent, nodeID);
  858. });
  859. }
  860. $('#events > div:last').css('border-bottom-width', '3px');
  861. // Add prototype events
  862. $(topdownTemp).append("<div id='prototypeEvents'></div>");
  863. var prototypeEvents = getEvents.call( this, this.kernel, node.extendsID );
  864. for ( var key in prototypeEvents ) {
  865. var nodeEvent = prototypeEvents[key];
  866. var prototypeEventNameAlpha = $.encoder.encodeForAlphaNumeric(key);
  867. var prototypeEventNameAttribute = $.encoder.encodeForHTMLAttribute("id", key, true);
  868. var prototypeEventNameHTML = $.encoder.encodeForHTML(key);
  869. $('#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>");
  870. $('#rollover-' + prototypeEventNameAlpha).mouseover( function(evt) {
  871. $('#arg-' + $(this).attr("id").substring(9)).css('visibility', 'visible');
  872. });
  873. $('#rollover-' + prototypeEventNameAlpha).mouseleave( function(evt) {
  874. $('#arg-' + $(this).attr("id").substring(9)).css('visibility', 'hidden');
  875. });
  876. $('#fire-' + prototypeEventNameAlpha).click( function(evt) {
  877. self.kernel.fireEvent( nodeID, $.encoder.canonicalize($(this).attr("data-eventName")) );
  878. });
  879. $('#arg-' + prototypeEventNameAlpha).click( function(evt) {
  880. setArgs.call(self, $.encoder.canonicalize($(this).attr("data-eventName")), nodeEvent, nodeID);
  881. });
  882. }
  883. $('#prototypeEvents > div:last').css('border-bottom-width', '3px');
  884. // Add node behaviors
  885. $(topdownTemp).append("<div id='behaviors'></div>");
  886. for ( var i = 0; i < node.implementsIDs.length; i++ ) {
  887. var nodeImplementsIDAlpha = $.encoder.encodeForAlphaNumeric(node.implementsIDs[i]);
  888. var nodeImplementsIDHTML = $.encoder.encodeForHTML(node.implementsIDs[i]);
  889. $('#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>");
  890. /*
  891. //Placeholder to Enable/Disable behaviors
  892. $('#' + node.implementsID[i] + '-enable').change( function(evt) {
  893. });
  894. */
  895. }
  896. $('#behaviors > div:last').css('border-bottom-width', '3px');
  897. // Add prototype behaviors
  898. $(topdownTemp).append("<div id='prototypeBehaviors'></div>");
  899. var prototypeNode = this.nodes[ node.extendsID ];
  900. for ( var i=0; i < prototypeNode.implementsIDs.length; i++)
  901. {
  902. var prototypeImplementsIDAlpha = $.encoder.encodeForAlphaNumeric(prototypeNode.implementsIDs[i]);
  903. var prototypeImplementsIDHTML = $.encoder.encodeForHTML(prototypeNode.implementsIDs[i]);
  904. $('#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>");
  905. }
  906. $('#prototypeBehaviors > div:last').css('border-bottom-width', '3px');
  907. // Create new script
  908. $(topdownTemp).append("<div id='createScript'></div>");
  909. $('#createScript').append("<div class='childContainer'><div class='childEntry'><b>New Script</div></div>");
  910. $('#createScript').click( function (evt) {
  911. createScript.call(self, nodeID);
  912. });
  913. $('#createScript > div:last').css('border-bottom-width', '3px');
  914. if ( this.allScripts[ nodeID ] !== undefined ) {
  915. // Add node scripts
  916. $(topdownTemp).append("<div id='scripts'></div>");
  917. for( var i=0; i < this.allScripts[ nodeID ].length; i++ )
  918. {
  919. var scriptFull = this.allScripts[nodeID][i].text;
  920. if(scriptFull != undefined)
  921. {
  922. var scriptName = scriptFull.substring(0, scriptFull.indexOf('='));
  923. $('#scripts').append("<div id='script-" + nodeIDAlpha + "-" + i + "' class='childContainer'><div class='childEntry'><b>script </b>" + scriptName + "</div></div>");
  924. $('#script-' + nodeIDAlpha + "-" + i).click( function(evt) {
  925. var scriptID = $(this).attr("id").substring($(this).attr("id").lastIndexOf('-')+1);
  926. viewScript.call(self, nodeID, scriptID, undefined);
  927. });
  928. }
  929. }
  930. $('#scripts > div:last').css('border-bottom-width', '3px');
  931. }
  932. if ( this.allScripts[ node.extendsID ] !== undefined ) {
  933. // Add prototype scripts
  934. $(topdownTemp).append("<div id='prototypeScripts'></div>");
  935. for( var i=0; i < this.allScripts[ node.extendsID ].length; i++ )
  936. {
  937. var scriptFull = this.allScripts[node.extendsID][i].text;
  938. if(scriptFull != undefined)
  939. {
  940. var nodeExtendsIDAlpha = $.encoder.encodeForAlphaNumeric(node.extendsID);
  941. var nodeExtendsIDAttribute = $.encoder.encodeForHTMLAttribute("id", node.extendsID, true);
  942. var scriptName = scriptFull.substring(0, scriptFull.indexOf('='));
  943. $('#prototypeScripts').append("<div id='script-" + nodeExtendsIDAlpha + "-" + i + "' class='childContainer' data-nodeExtendsID='" + nodeExtendsIDAttribute + "'><div class='childEntry'><b>script </b>" + scriptName + "</div></div>");
  944. $('#script-' + nodeExtendsIDAlpha + "-" + i).click( function(evt) {
  945. var extendsId = $.encoder.canonicalize($(this).attr("data-nodeExtendsID"));
  946. var scriptID = $(this).attr("id").substring($(this).attr("id").lastIndexOf('-')+1);
  947. viewScript.call(self, nodeID, scriptID, extendsId);
  948. });
  949. }
  950. }
  951. $('#prototypeScripts > div:last').css('border-bottom-width', '3px');
  952. }
  953. updateCameraProperties.call(self);
  954. }
  955. // -- createScript ----------------------------------------------------------------------
  956. function createScript (nodeID) // invoke with the view as "this"
  957. {
  958. var self = this;
  959. var topdownName = this.topdownName;
  960. var topdownTemp = this.topdownTemp;
  961. var allScripts = this.allScripts;
  962. var nodeIDAlpha = $.encoder.encodeForAlphaNumeric(nodeID);
  963. $(topdownTemp).html("<div class='header'><img src='images/back.png' id='script-" + nodeIDAlpha + "-back' alt='back'/> script</div>");
  964. $('#script-' + nodeIDAlpha + '-back').click ( function(evt) {
  965. self.editingScript = false;
  966. drillBack.call(self, nodeID);
  967. // Return editor to normal width
  968. $('#editor').animate({ 'left' : "-260px" }, 175);
  969. $('.vwf-tree').animate({ 'width' : "260px" }, 175);
  970. });
  971. $(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>");
  972. $("#create-" + nodeIDAlpha).click ( function(evt) {
  973. self.kernel.execute( nodeID, $("#newScriptArea").val() );
  974. });
  975. $('#newScriptArea').focus( function(evt) {
  976. // Expand the script editor
  977. self.editingScript = true;
  978. $('#editor').animate({ 'left' : "-500px" }, 175);
  979. $('.vwf-tree').animate({ 'width' : "500px" }, 175);
  980. });
  981. $('#newScriptArea').keydown( function(evt) {
  982. evt.stopPropagation();
  983. });
  984. $(topdownName).hide();
  985. $(topdownTemp).show();
  986. this.topdownName = topdownTemp;
  987. this.topdownTemp = topdownName;
  988. }
  989. // -- viewScript ------------------------------------------------------------------------
  990. function viewScript (nodeID, scriptID, extendsID) // invoke with the view as "this"
  991. {
  992. var self = this;
  993. var topdownName = this.topdownName;
  994. var topdownTemp = this.topdownTemp;
  995. var allScripts = this.allScripts;
  996. var nodeIDAlpha = $.encoder.encodeForAlphaNumeric(nodeID);
  997. $(topdownTemp).html("<div class='header'><img src='images/back.png' id='script-" + nodeIDAlpha + "-back' alt='back'/> script</div>");
  998. $('#script-' + nodeIDAlpha + '-back').click ( function(evt) {
  999. self.editingScript = false;
  1000. drillBack.call(self, nodeID);
  1001. // Return editor to normal width
  1002. $('#editor').animate({ 'left' : "-260px" }, 175);
  1003. $('.vwf-tree').animate({ 'width' : "260px" }, 175);
  1004. });
  1005. if(extendsID) {
  1006. nodeID = extendsID;
  1007. nodeIDAlpha = $.encoder.encodeForAlphaNumeric(extendsID);
  1008. }
  1009. var scriptText = self.allScripts[nodeID][scriptID].text;
  1010. if(scriptText != undefined)
  1011. {
  1012. $(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>");
  1013. $("#update-" + nodeIDAlpha + "-" + scriptID).click ( function(evt) {
  1014. var s_id = $(this).attr("id").substring($(this).attr("id").lastIndexOf('-') + 1);
  1015. self.allScripts[nodeID][s_id].text = undefined;
  1016. self.kernel.execute( nodeID, $("#scriptTextArea").val() );
  1017. });
  1018. $('#scriptTextArea').focus( function(evt) {
  1019. // Expand the script editor
  1020. self.editingScript = true;
  1021. $('#editor').animate({ 'left' : "-500px" }, 175);
  1022. $('.vwf-tree').animate({ 'width' : "500px" }, 175);
  1023. });
  1024. $('#scriptTextArea').keydown( function(evt) {
  1025. evt.stopPropagation();
  1026. });
  1027. }
  1028. $(topdownName).hide();
  1029. $(topdownTemp).show();
  1030. this.topdownName = topdownTemp;
  1031. this.topdownTemp = topdownName;
  1032. }
  1033. // -- setParams -------------------------------------------------------------------------
  1034. function setParams (methodName, methodParams, nodeID) // invoke with the view as "this"
  1035. {
  1036. var self = this;
  1037. var topdownName = this.topdownName;
  1038. var topdownTemp = this.topdownTemp;
  1039. var methodNameAlpha = $.encoder.encodeForAlphaNumeric(methodName);
  1040. var methodNameHTML = $.encoder.encodeForHTML(methodName);
  1041. $(topdownTemp).html("<div class='header'><img src='images/back.png' id='" + methodNameAlpha + "-back' alt='back'/> " + methodNameHTML + "<input type='button' class='input_button_call' id='call' value='Call' style='float:right;position:relative;top:5px;right:33px'></input></div>");
  1042. $('#' + methodNameAlpha + '-back').click ( function(evt) {
  1043. drillUp.call(self, nodeID);
  1044. });
  1045. for(var i=1; i<=16; i++)
  1046. {
  1047. $(topdownTemp).append("<div id='param" + i + "' class='propEntry'><table><tr><td><b>Parameter " + i + ": </b></td><td><input type='text' class='input_text' id='input-param" + i + "'></td></tr></table></div>");
  1048. $('#input-param'+ i).keydown( function(evt) {
  1049. evt.stopPropagation();
  1050. });
  1051. $('#input-param'+ i).keypress( function(evt) {
  1052. evt.stopPropagation();
  1053. });
  1054. $('#input-param'+ i).keyup( function(evt) {
  1055. evt.stopPropagation();
  1056. });
  1057. }
  1058. $('#call').click ( function (evt) {
  1059. var parameters = new Array();
  1060. for(var i=1; i<=16; i++)
  1061. {
  1062. if( $('#input-param'+ i).val() )
  1063. {
  1064. var prmtr = $('#input-param'+ i).val();
  1065. try {
  1066. prmtr = JSON.parse(JSON.stringify($.encoder.canonicalize(prmtr)));
  1067. parameters.push( prmtr );
  1068. } catch (e) {
  1069. self.logger.error('Invalid Value');
  1070. }
  1071. }
  1072. }
  1073. self.kernel.callMethod(nodeID, methodName, parameters);
  1074. });
  1075. $(topdownName).hide('slide', {direction: 'left'}, 175);
  1076. $(topdownTemp).show('slide', {direction: 'right'}, 175);
  1077. this.topdownName = topdownTemp;
  1078. this.topdownTemp = topdownName;
  1079. }
  1080. // -- setArgs ---------------------------------------------------------------------------
  1081. function setArgs (eventName, eventArgs, nodeID) // invoke with the view as "this"
  1082. {
  1083. var self = this;
  1084. var topdownName = this.topdownName;
  1085. var topdownTemp = this.topdownTemp;
  1086. var eventNameAlpha = $.encoder.encodeForAlphaNumeric(eventName);
  1087. var eventNameHTML = $.encoder.encodeForHTML(eventName);
  1088. $(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>");
  1089. $('#' + eventNameAlpha + '-back').click ( function(evt) {
  1090. drillUp.call(self, nodeID);
  1091. });
  1092. for(var i=1; i<=8; i++)
  1093. {
  1094. $(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>");
  1095. $('#input-arg'+ i).keydown( function(evt) {
  1096. evt.stopPropagation();
  1097. });
  1098. $('#input-arg'+ i).keypress( function(evt) {
  1099. evt.stopPropagation();
  1100. });
  1101. $('#input-arg'+ i).keyup( function(evt) {
  1102. evt.stopPropagation();
  1103. });
  1104. }
  1105. $(topdownTemp).append("<div style='font-weight:bold;text-align:right;padding-right:10px'></div>");
  1106. $('#fire').click ( function (evt) {
  1107. var args = new Array();
  1108. for(var i=1; i<=8; i++)
  1109. {
  1110. if( $('#input-arg'+ i).val() )
  1111. {
  1112. var arg = $('#input-arg'+ i).val();
  1113. try {
  1114. arg = JSON.parse($.encoder.canonicalize(arg));
  1115. args.push( arg );
  1116. } catch (e) {
  1117. self.logger.error('Invalid Value');
  1118. }
  1119. }
  1120. }
  1121. self.kernel.fireEvent(nodeID, eventName, args);
  1122. });
  1123. $(topdownName).hide('slide', {direction: 'left'}, 175);
  1124. $(topdownTemp).show('slide', {direction: 'right'}, 175);
  1125. this.topdownName = topdownTemp;
  1126. this.topdownTemp = topdownName;
  1127. }
  1128. function getPrototypes( kernel, extendsID ) {
  1129. var prototypes = [];
  1130. var id = extendsID;
  1131. while ( id !== undefined ) {
  1132. prototypes.push( id );
  1133. id = kernel.prototype( id );
  1134. }
  1135. return prototypes;
  1136. }
  1137. function createProperty( node, propertyName, propertyValue ) {
  1138. var property = {
  1139. name: propertyName,
  1140. rawValue: propertyValue,
  1141. value: undefined,
  1142. getValue: function() {
  1143. var propertyValue;
  1144. if ( this.value == undefined ) {
  1145. try {
  1146. propertyValue = utility.transform( this.rawValue, utility.transforms.transit );
  1147. this.value = JSON.stringify( propertyValue );
  1148. } catch (e) {
  1149. this.logger.warnx( "createdProperty", nodeID, this.propertyName, this.rawValue,
  1150. "stringify error:", e.message );
  1151. this.value = this.rawValue;
  1152. }
  1153. }
  1154. return this.value;
  1155. }
  1156. };
  1157. return property;
  1158. }
  1159. function getProperties( kernel, extendsID ) {
  1160. var pTypes = getPrototypes( kernel, extendsID );
  1161. var pProperties = {};
  1162. if ( pTypes ) {
  1163. for ( var i=0; i < pTypes.length; i++ ) {
  1164. var nd = this.nodes[ pTypes[i] ];
  1165. if ( nd && nd.properties ) {
  1166. for ( var key in nd.properties ) {
  1167. pProperties[ key ] = { "prop": nd.properties[ key ], "prototype": pTypes[i] };
  1168. }
  1169. }
  1170. }
  1171. }
  1172. return pProperties;
  1173. }
  1174. function getChildren( kernel, extendsID ) {
  1175. var pTypes = getPrototypes( kernel, extendsID );
  1176. var pChildren = {};
  1177. if ( pTypes ) {
  1178. for ( var i=0; i < pTypes.length; i++ ) {
  1179. var nd = this.nodes[ pTypes[i] ];
  1180. if ( nd && nd.children ) {
  1181. for ( var key in nd.children ) {
  1182. pChildren[ key ] = nd.children[key];
  1183. }
  1184. }
  1185. }
  1186. }
  1187. return pChildren;
  1188. }
  1189. function getEvents( kernel, extendsID ) {
  1190. var pTypes = getPrototypes( kernel, extendsID );
  1191. var events = {};
  1192. if ( pTypes ) {
  1193. for ( var i = 0; i < pTypes.length; i++ ) {
  1194. var nd = this.nodes[ pTypes[i] ];
  1195. if ( nd && nd.events ) {
  1196. for ( var key in nd.events ) {
  1197. events[ key ] = nd.events[key];
  1198. }
  1199. }
  1200. }
  1201. }
  1202. return events;
  1203. }
  1204. function getMethods( kernel, extendsID ) {
  1205. var pTypes = getPrototypes( kernel, extendsID );
  1206. var methods = {};
  1207. if ( pTypes ) {
  1208. for ( var i = 0; i < pTypes.length; i++ ) {
  1209. var nd = this.nodes[ pTypes[i] ];
  1210. if ( nd && nd.methods ) {
  1211. for ( var key in nd.methods ) {
  1212. methods[ key ] = nd.methods[key];
  1213. }
  1214. }
  1215. }
  1216. }
  1217. return methods;
  1218. }
  1219. function highlightChildInHierarchy(nodeID) {
  1220. if (this.editorOpen && this.editorView == 1) // Hierarchy view open
  1221. {
  1222. var childDiv = $("div[id='" + nodeID +"']");
  1223. if(childDiv.length > 0) {
  1224. var previousChild = $("div[id='" + this.highlightedChild +"']");
  1225. if(previousChild.length > 0) {
  1226. previousChild.removeClass('childContainerHighlight');
  1227. }
  1228. childDiv.addClass('childContainerHighlight');
  1229. this.highlightedChild = nodeID;
  1230. }
  1231. }
  1232. }
  1233. // -- showTimeline ----------------------------------------------------------------------
  1234. function showTimeline() // invoke with the view as "this"
  1235. {
  1236. var timeline = this.timeline;
  1237. if(!this.timelineInit)
  1238. {
  1239. $('#time_control').append("<div class='header'>Timeline</div>" +
  1240. "<div style='text-align:center;padding-top:10px'><span><button id='play'></button><button id='stop'></button></span>" +
  1241. "<span><span class='rate slider'></span>&nbsp;" +
  1242. "<span class='rate vwf-label' style='display: inline-block; width:8ex'></span></span></div>");
  1243. var options = {};
  1244. [ "play", "pause", "stop" ].forEach( function( state ) {
  1245. options[state] = { icons: { primary: "ui-icon-" + state }, label: state, text: false };
  1246. } );
  1247. options.rate = { value: 0, min: -2, max: 2, step: 0.1, };
  1248. var state = {};
  1249. $.get(
  1250. "admin/state",
  1251. undefined,
  1252. function( data ) {
  1253. state = data;
  1254. $( "button#play" ).button( "option", state.playing ? options.pause : options.play );
  1255. $( "button#stop" ).button( "option", "disabled", state.stopped );
  1256. $( ".rate.slider" ).slider( "value", Math.log( state.rate ) / Math.LN10 );
  1257. if ( state.rate < 1.0 ) {
  1258. var label_rate = 1.0 / state.rate;
  1259. }
  1260. else {
  1261. var label_rate = state.rate;
  1262. }
  1263. var label = label_rate.toFixed(2).toString().replace( /(\.\d*?)0+$/, "$1" ).replace( /\.$/, "" );
  1264. if ( state.rate < 1.0 ) {
  1265. label = "&#x2215; " + label;
  1266. } else {
  1267. label = label + " &times;";
  1268. }
  1269. $( ".rate.vwf-label" ).html( label );
  1270. },
  1271. "json"
  1272. );
  1273. $( "button#play" ).button(
  1274. options.pause
  1275. ). click( function() {
  1276. $.post(
  1277. state.playing ? "admin/pause" : "admin/play",
  1278. undefined,
  1279. function( data ) {
  1280. state = data;
  1281. $( "button#play" ).button( "option", state.playing ? options.pause : options.play );
  1282. $( "button#stop" ).button( "option", "disabled", state.stopped );
  1283. },
  1284. "json"
  1285. );
  1286. } );
  1287. $( "button#stop" ).button(
  1288. options.stop
  1289. ). click( function() {
  1290. $.post(
  1291. "admin/stop",
  1292. undefined,
  1293. function( data ) {
  1294. state = data;
  1295. $( "button#play" ).button( "option", state.playing ? options.pause : options.play );
  1296. $( "button#stop" ).button( "option", "disabled", state.stopped );
  1297. },
  1298. "json"
  1299. );
  1300. } );
  1301. $( ".rate.slider" ).slider(
  1302. options.rate
  1303. ) .bind( "slide", function( event, ui ) {
  1304. $.get(
  1305. "admin/state",
  1306. { "rate": Math.pow( 10, Number(ui.value) ) },
  1307. function( data ) {
  1308. state = data;
  1309. $( ".rate.slider" ).slider( "value", Math.log( state.rate ) / Math.LN10 );
  1310. if ( state.rate < 1.0 ) {
  1311. var label_rate = 1.0 / state.rate;
  1312. }
  1313. else {
  1314. var label_rate = state.rate;
  1315. }
  1316. var label = label_rate.toFixed(2).toString().replace( /(\.\d*?)0+$/, "$1" ).replace( /\.$/, "" );
  1317. if ( state.rate < 1.0 ) {
  1318. label = "&#x2215; " + label;
  1319. } else {
  1320. label = label + " &times;";
  1321. }
  1322. $( ".rate.vwf-label" ).html( label );
  1323. },
  1324. "json"
  1325. );
  1326. } );
  1327. this.timelineInit = true;
  1328. }
  1329. if (!this.editorOpen)
  1330. {
  1331. $(timeline).show('slide', {direction: 'right'}, 175);
  1332. }
  1333. else
  1334. {
  1335. $(timeline).show();
  1336. }
  1337. }
  1338. // -- showAboutTab ----------------------------------------------------------------------
  1339. function showAboutTab() // invoke with the view as "this"
  1340. {
  1341. var about = this.about;
  1342. if(!this.aboutInit)
  1343. {
  1344. $('#about_tab').append("<div class='header'>About</div>" +
  1345. "<div class='about'><p style='font:bold 12pt Arial'>Virtual World Framework</p>" +
  1346. "<p><b>Version: </b>" + version.toString() + "</p>" +
  1347. "<p><b>Site: </b><a href='http://virtualworldframework.com' target='_blank'>http://virtualworldframework.com</a></p>" +
  1348. "<p><b>Source: </b><a href='https://github.com/virtual-world-framework' target='_blank'>https://github.com/virtual-world-framework</a></p></div>");
  1349. this.aboutInit = true;
  1350. }
  1351. if (!this.editorOpen)
  1352. {
  1353. $(about).show('slide', {direction: 'right'}, 175);
  1354. }
  1355. else
  1356. {
  1357. $(about).show();
  1358. }
  1359. }
  1360. // -- showModelsTab ----------------------------------------------------------------------
  1361. function showModelsTab(modelID, modelURL) // invoke with the view as "this"
  1362. {
  1363. var self = this;
  1364. var models = this.models;
  1365. var modelsTemp = this.modelsTemp;
  1366. this.currentModelID = modelID;
  1367. this.currentModelURL = modelURL;
  1368. $(models).html("");
  1369. if(modelID == "") {
  1370. $(modelsTemp).html("<div class='header'>Models</div>");
  1371. $.getJSON("admin/models", function( data ) {
  1372. if(data.length > 0) {
  1373. $.each( data, function( key, value ) {
  1374. var fileName = encodeURIComponent(value['basename']);
  1375. var divId = fileName;
  1376. if(divId.indexOf('.') != -1) {
  1377. divId = divId.replace(/\./g, "_");
  1378. }
  1379. var url = value['url'];
  1380. $(modelsTemp).append("<div class='childContainer'><div id='" + divId + "' class='modelEntry' data-url='" + url + "'>"
  1381. + fileName + "</div></div>");
  1382. $("#" + divId).click(function(e) {
  1383. modelDrillDown.call(self, e.target.textContent, e.target.getAttribute("data-url"));
  1384. })
  1385. });
  1386. }
  1387. else {
  1388. $(modelsTemp).append("<div class='childEntry'><p style='font:bold 12pt Arial'>No Models Found</p></div>");
  1389. }
  1390. } );
  1391. }
  1392. else {
  1393. var divId = modelID;
  1394. if(divId.indexOf('.') != -1) {
  1395. divId = divId.replace(/\./g, "_");
  1396. }
  1397. $(modelsTemp).html("<div id='" + divId + "-backDiv' class='header'><img src='images/back.png' id='" + divId + "-back' alt='back'/>" + modelID + "</div>");
  1398. $("#" + divId + "-back").click(function(e) {
  1399. modelDrillUp.call(self, '');
  1400. });
  1401. $(modelsTemp).append("<div id='" + divId + "-rotation' class='propEntry'><table><tr><td><b>Rotation</b></td><td>" +
  1402. "<input type='text' class='input_text' id='input-" + divId + "-rotation' value='[1,0,0,0]'></td></tr></table></div>");
  1403. $('#input-' + divId + '-rotation').keydown( function(evt) {
  1404. evt.stopPropagation();
  1405. });
  1406. $('#input-' + divId + '-rotation').keypress( function(evt) {
  1407. evt.stopPropagation();
  1408. });
  1409. $('#input-' + divId + '-rotation').keyup( function(evt) {
  1410. evt.stopPropagation();
  1411. });
  1412. $(modelsTemp).append("<div id='" + divId + "-scale' class='propEntry'><table><tr><td><b>Scale</b></td><td>" +
  1413. "<input type='text' class='input_text' id='input-" + divId + "-scale' value='[1,1,1]'></td></tr></table></div>");
  1414. $('#input-' + divId + '-scale').keydown( function(evt) {
  1415. evt.stopPropagation();
  1416. });
  1417. $('#input-' + divId + '-scale').keypress( function(evt) {
  1418. evt.stopPropagation();
  1419. });
  1420. $('#input-' + divId + '-scale').keyup( function(evt) {
  1421. evt.stopPropagation();
  1422. });
  1423. $(modelsTemp).append("<div id='" + divId + "-translation' class='propEntry'><table><tr><td><b>Translation Offset</b></td><td>" +
  1424. "<input type='text' class='input_text' id='input-" + divId + "-translation' value='[0,0,0]'></td></tr></table></div>");
  1425. $('#input-' + divId + '-translation').keydown( function(evt) {
  1426. evt.stopPropagation();
  1427. });
  1428. $('#input-' + divId + '-translation').keypress( function(evt) {
  1429. evt.stopPropagation();
  1430. });
  1431. $('#input-' + divId + '-translation').keyup( function(evt) {
  1432. evt.stopPropagation();
  1433. });
  1434. $(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>");
  1435. $("#" + divId + "-drag").on("dragstart", function (e) {
  1436. var fileName = $("#" + e.target.getAttribute("data-escaped-name") + "-backDiv").text();
  1437. var rotation = encodeURIComponent($("#input-" + e.target.getAttribute("data-escaped-name") + "-rotation").val());
  1438. var scale = encodeURIComponent($("#input-" + e.target.getAttribute("data-escaped-name") + "-scale").val());
  1439. var translation = encodeURIComponent($("#input-" + e.target.getAttribute("data-escaped-name") + "-translation").val());
  1440. var fileData = "{\"fileName\":\""+fileName+"\", \"fileUrl\":\""+e.target.getAttribute("data-url")+"\", " +
  1441. "\"rotation\":\"" + rotation + "\", \"scale\":\"" + scale + "\", \"translation\":\"" + translation + "\"}";
  1442. e.originalEvent.dataTransfer.setData('text/plain', fileData);
  1443. e.originalEvent.dataTransfer.setDragImage(e.target, 0, 0);
  1444. return true;
  1445. });
  1446. }
  1447. }
  1448. // -- Model drillDown -------------------------------------------------------------------------
  1449. function modelDrillDown(modelID, modelURL) // invoke with the view as "this"
  1450. {
  1451. var models = this.models;
  1452. var modelsTemp = this.modelsTemp;
  1453. showModelsTab.call(this, modelID, modelURL);
  1454. if(modelID != "") $(models).hide('slide', {direction: 'left'}, 175);
  1455. $(modelsTemp).show('slide', {direction: 'right'}, 175);
  1456. this.models = modelsTemp;
  1457. this.modelsTemp = models;
  1458. }
  1459. // -- Model drillUp ---------------------------------------------------------------------------
  1460. function modelDrillUp(modelID) // invoke with the view as "this"
  1461. {
  1462. var models = this.models;
  1463. var modelsTemp = this.modelsTemp;
  1464. showModelsTab.call(this, modelID);
  1465. $(models).hide('slide', {direction: 'right'}, 175);
  1466. $(modelsTemp).show('slide', {direction: 'left'}, 175);
  1467. this.models = modelsTemp;
  1468. this.modelsTemp = models;
  1469. }
  1470. // -- SaveStateAsFile -------------------------------------------------------------------------
  1471. function saveStateAsFile(filename) // invoke with the view as "this"
  1472. {
  1473. this.logger.info("Saving: " + filename);
  1474. if(supportAjaxUploadWithProgress.call(this))
  1475. {
  1476. var xhr = new XMLHttpRequest();
  1477. // Save State Information
  1478. var state = vwf.getState();
  1479. var timestamp = state["queue"].time;
  1480. timestamp = Math.round(timestamp * 1000);
  1481. var objectIsTypedArray = function( candidate ) {
  1482. var typedArrayTypes = [
  1483. Int8Array,
  1484. Uint8Array,
  1485. // Uint8ClampedArray,
  1486. Int16Array,
  1487. Uint16Array,
  1488. Int32Array,
  1489. Uint32Array,
  1490. Float32Array,
  1491. Float64Array
  1492. ];
  1493. var isTypedArray = false;
  1494. if ( typeof candidate == "object" && candidate != null ) {
  1495. typedArrayTypes.forEach( function( typedArrayType ) {
  1496. isTypedArray = isTypedArray || candidate instanceof typedArrayType;
  1497. } );
  1498. }
  1499. return isTypedArray;
  1500. };
  1501. var transitTransformation = function( object ) {
  1502. return objectIsTypedArray( object ) ?
  1503. Array.prototype.slice.call( object ) : object;
  1504. };
  1505. var json = JSON.stringify(
  1506. require("vwf/utility").transform(
  1507. state, transitTransformation
  1508. )
  1509. );
  1510. json = $.encoder.encodeForURL(json);
  1511. var path = window.location.pathname;
  1512. var pathSplit = path.split('/');
  1513. if ( pathSplit[0] == "" ) {
  1514. pathSplit.shift();
  1515. }
  1516. if ( pathSplit[ pathSplit.length - 1 ] == "" ) {
  1517. pathSplit.pop();
  1518. }
  1519. var inst = undefined;
  1520. var instIndex = pathSplit.length - 1;
  1521. if ( pathSplit.length > 2 ) {
  1522. if ( pathSplit[ pathSplit.length - 2 ] == "load" ) {
  1523. instIndex = pathSplit.length - 3;
  1524. }
  1525. }
  1526. if ( pathSplit.length > 3 ) {
  1527. if ( pathSplit[ pathSplit.length - 3 ] == "load" ) {
  1528. instIndex = pathSplit.length - 4;
  1529. }
  1530. }
  1531. inst = pathSplit[ instIndex ];
  1532. var root = "";
  1533. for ( var i=0; i < instIndex; i++ ) {
  1534. if ( root != "" ) {
  1535. root = root + "/";
  1536. }
  1537. root = root + pathSplit[i];
  1538. }
  1539. if(filename == '') filename = inst;
  1540. if(root.indexOf('.vwf') != -1) root = root.substring(0, root.lastIndexOf('/'));
  1541. xhr.open("POST", "/"+root+"/save/"+filename, true);
  1542. xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  1543. xhr.send("root="+root+"/"+filename+"&filename=saveState&inst="+inst+"&timestamp="+timestamp+"&extension=.vwf.json"+"&jsonState="+json);
  1544. // Save Config Information
  1545. var config = {"info":{}, "model":{}, "view":{} };
  1546. // Save browser title
  1547. config["info"]["title"] = $('title').html();
  1548. // Save model drivers
  1549. Object.keys(vwf_view.kernel.kernel.models).forEach(function(modelDriver) {
  1550. if(modelDriver.indexOf('vwf/model/') != -1) config["model"][modelDriver] = "";
  1551. });
  1552. // If neither glge or threejs model drivers are defined, specify nodriver
  1553. if(config["model"]["vwf/model/glge"] === undefined && config["model"]["vwf/model/threejs"] === undefined) config["model"]["nodriver"] = "";
  1554. // Save view drivers and associated parameters, if any
  1555. Object.keys(vwf_view.kernel.kernel.views).forEach(function(viewDriver) {
  1556. if(viewDriver.indexOf('vwf/view/') != -1)
  1557. {
  1558. if( vwf_view.kernel.kernel.views[viewDriver].parameters )
  1559. {
  1560. config["view"][viewDriver] = vwf_view.kernel.kernel.views[viewDriver].parameters;
  1561. }
  1562. else config["view"][viewDriver] = "";
  1563. }
  1564. });
  1565. var jsonConfig = $.encoder.encodeForURL( JSON.stringify( config ) );
  1566. // Save config file to server
  1567. var xhrConfig = new XMLHttpRequest();
  1568. xhrConfig.open("POST", "/"+root+"/save/"+filename, true);
  1569. xhrConfig.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  1570. xhrConfig.send("root="+root+"/"+filename+"&filename=saveState&inst="+inst+"&timestamp="+timestamp+"&extension=.vwf.config.json"+"&jsonState="+jsonConfig);
  1571. }
  1572. else
  1573. {
  1574. console.error("Unable to save state.");
  1575. }
  1576. }
  1577. // -- LoadSavedState --------------------------------------------------------------------------
  1578. function loadSavedState(filename, applicationpath, revision)
  1579. {
  1580. this.logger.info("Loading: " + filename);
  1581. // Redirect until setState ID conflict is resolved
  1582. var path = window.location.pathname;
  1583. var inst = path.substring(path.length-17, path.length-1);
  1584. var pathSplit = path.split('/');
  1585. if ( pathSplit[0] == "" ) {
  1586. pathSplit.shift();
  1587. }
  1588. if ( pathSplit[ pathSplit.length - 1 ] == "" ) {
  1589. pathSplit.pop();
  1590. }
  1591. var inst = undefined;
  1592. var instIndex = pathSplit.length - 1;
  1593. if ( pathSplit.length > 2 ) {
  1594. if ( pathSplit[ pathSplit.length - 2 ] == "load" ) {
  1595. instIndex = pathSplit.length - 3;
  1596. }
  1597. }
  1598. if ( pathSplit.length > 3 ) {
  1599. if ( pathSplit[ pathSplit.length - 3 ] == "load" ) {
  1600. instIndex = pathSplit.length - 4;
  1601. }
  1602. }
  1603. inst = pathSplit[ instIndex ];
  1604. if ( revision ) {
  1605. window.location.pathname = applicationpath + "/" + inst + '/load/' + filename + '/' + revision + '/';
  1606. }
  1607. else {
  1608. window.location.pathname = applicationpath + "/" + inst + '/load/' + filename + '/';
  1609. }
  1610. // $.get(filename,function(data,status){
  1611. // vwf.setState(data);
  1612. // });
  1613. }
  1614. // -- SupportAjax -----------------------------------------------------------------------------
  1615. function supportAjaxUploadWithProgress()
  1616. {
  1617. return supportAjaxUploadProgressEvents();
  1618. function supportAjaxUploadProgressEvents()
  1619. {
  1620. var xhr = new XMLHttpRequest();
  1621. return !! (xhr && ('upload' in xhr) && ('onprogress' in xhr.upload));
  1622. }
  1623. }
  1624. } );