editor-new.js 170 KB

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