editor-new.js 196 KB

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