editor-new.js 139 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225
  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. "vwf/view/lib/colorpicker/colorpicker.min"
  27. ], function (module, version, view, utility, ace, colorpicker) {
  28. var self;
  29. return view.load(module, {
  30. // == Module Definition ====================================================================
  31. initialize: function () {
  32. self = this;
  33. this.ace = window.ace;
  34. this.nodes = {};
  35. this.scenes = {};
  36. this.allScripts = {};
  37. //$(document.head).append('<style type="text/css" media="screen"> #editorlive { height: 500px; width: 800px; } </style>');
  38. document.querySelector('head').innerHTML += '<style type="text/css" media="screen"> #editorlive { height: 500px; width: 800px; } </style>';
  39. document.querySelector('head').innerHTML += '<link rel="stylesheet" href="vwf/view/lib/editorLive.css">';
  40. //document.querySelector('head').innerHTML += '<script type="text/javascript" src="vwf/view/lib/colorpicker/colorpicker.min.js">';
  41. document.querySelector('head').innerHTML += '<link rel="stylesheet" href="vwf/view/lib/colorpicker/themes.css">';
  42. //$(document.head).append('<meta name="viewport" content="width=device-width, initial-scale=1">');
  43. document.querySelector('head').innerHTML += '<meta name="viewport" content="width=device-width, initial-scale=1">';
  44. // $('body').append('<script>mdc.autoInit()</script>');
  45. this.removeProps = (obj) => {
  46. Object.keys(obj).forEach(key =>
  47. (key === 'id' || key === 'patches' || key === 'random' || key === 'sequence') && delete obj[key] ||
  48. (obj[key] && typeof obj[key] === 'object') && this.removeProps(obj[key])
  49. );
  50. return obj;
  51. };
  52. this.getNodeDef = function (nodeID) {
  53. let node = vwf.getNode(nodeID, true);
  54. let nodeDef = self.removeProps(node);
  55. return nodeDef
  56. }
  57. this.GUID = function () {
  58. var S4 = function () {
  59. return Math.floor(
  60. Math.random() * 0x10000 /* 65536 */
  61. ).toString(16);
  62. };
  63. return (
  64. S4() + S4() + "-" +
  65. S4() + "-" +
  66. S4() + "-" +
  67. S4() + "-" +
  68. S4() + S4() + S4()
  69. );
  70. }
  71. this.getRoot = function () {
  72. var app = window.location.pathname;
  73. var pathSplit = app.split('/');
  74. if (pathSplit[0] == "") {
  75. pathSplit.shift();
  76. }
  77. if (pathSplit[pathSplit.length - 1] == "") {
  78. pathSplit.pop();
  79. }
  80. var instIndex = pathSplit.length - 1;
  81. if (pathSplit.length > 2) {
  82. if (pathSplit[pathSplit.length - 2] == "load") {
  83. instIndex = pathSplit.length - 3;
  84. }
  85. }
  86. if (pathSplit.length > 3) {
  87. if (pathSplit[pathSplit.length - 3] == "load") {
  88. instIndex = pathSplit.length - 4;
  89. }
  90. }
  91. var root = "";
  92. for (var i = 0; i < instIndex; i++) {
  93. if (root != "") {
  94. root = root + "/";
  95. }
  96. root = root + pathSplit[i];
  97. }
  98. if (root.indexOf('.vwf') != -1) root = root.substring(0, root.lastIndexOf('/'));
  99. return root
  100. };
  101. ["drawer", "toolbar", "sideBar", "propWindow", "clientsWindow", "codeEditorWindow", "propEditorWindow", "viewSceneProps"].forEach(item => {
  102. let el = document.createElement("div");
  103. el.setAttribute("id", item);
  104. document.body.appendChild(el);
  105. }
  106. );
  107. this.avatarCardDef = function (src, desc, onclickfunc) {
  108. return {
  109. $cell: true,
  110. $type: "div",
  111. class: "mdc-card avatar-card",
  112. $init: function () {
  113. this.style.backgroundImage = 'linear-gradient(0deg, rgba(0, 0, 0, 0.0), rgba(0, 0, 0, 0.0) ), url(' + src + ')'
  114. },
  115. onclick: onclickfunc,
  116. $components: [
  117. {
  118. $type: "section",
  119. class: "mdc-card__primary",
  120. $components: [
  121. {
  122. $type: "h1",
  123. class: "mdc-card__title mdc-card__title--large",
  124. $text: desc.subtitle
  125. },
  126. {
  127. $type: "h2",
  128. class: "mdc-card__subtitle",
  129. $text: desc.title
  130. }
  131. ]
  132. },
  133. {
  134. $type: "section",
  135. class: "mdc-card__actions",
  136. $components: [
  137. {
  138. $type: "button",
  139. class: "mdc-button mdc-button--compact mdc-card__action",
  140. //$text: "Use it",
  141. onclick: onclickfunc
  142. }
  143. ]
  144. }
  145. ]
  146. }
  147. }
  148. let avatarSettings =
  149. {
  150. $cell: true,
  151. $type: "div",
  152. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  153. $components: [
  154. {
  155. $cell: true,
  156. $type: "div",
  157. class: "mdc-layout-grid__inner",
  158. $components: [
  159. {
  160. $cell: true,
  161. $type: "div",
  162. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  163. $components: [
  164. {
  165. $cell: true,
  166. $type: "button",
  167. class: "mdc-button mdc-button--raised",
  168. $text: "Reset camera view",
  169. onclick: function (e) {
  170. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  171. let controlEl = document.querySelector('#avatarControl');
  172. controlEl.setAttribute('camera', 'active', true);
  173. }
  174. },
  175. {
  176. $cell: true,
  177. $type: "button",
  178. class: "mdc-button mdc-button--raised",
  179. $text: "Hide cursor",
  180. onclick: function (e) {
  181. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  182. let avatarID = 'avatar-' + self.kernel.moniker();
  183. let cursorID = 'myCursor-' + avatarID;
  184. let controlEl = document.querySelector("[id='" + cursorID + "']");
  185. let vis = controlEl.getAttribute('visible');
  186. this.$text = vis ? 'Show cursor' : 'Hide cursor';
  187. vwf_view.kernel.callMethod(avatarID, "showHideCursor", [!vis]);
  188. //controlEl.setAttribute('visible', !vis);
  189. }
  190. }
  191. ]
  192. },
  193. {
  194. $cell: true,
  195. $type: "div",
  196. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  197. $components: [
  198. {
  199. $type: "div",
  200. class: "mdc-layout-grid",
  201. $components: [
  202. {
  203. $type: "div",
  204. class: "mdc-layout-grid__inner",
  205. $components: [
  206. {
  207. $cell: true,
  208. $type: "div",
  209. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  210. $components: [
  211. self.avatarCardDef("/../assets/avatars/ico/simple.jpg", { title: "Simple", subtitle: "Cube" },
  212. function (e) {
  213. let avatarID = 'avatar-' + self.kernel.moniker();
  214. vwf_view.kernel.callMethod(avatarID, "createSimpleAvatar");
  215. }
  216. )
  217. ]
  218. },
  219. {
  220. $cell: true,
  221. $type: "div",
  222. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  223. $components: [
  224. self.avatarCardDef("/../assets/avatars/ico/female.jpg", { title: "Human", subtitle: "Female" },
  225. function (e) {
  226. let avatarID = 'avatar-' + self.kernel.moniker();
  227. vwf_view.kernel.callMethod(avatarID, "createAvatarFromGLTF", ["/../assets/avatars/female/avatar1.gltf"]);
  228. }
  229. )]
  230. },
  231. {
  232. $cell: true,
  233. $type: "div",
  234. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  235. $components: [
  236. self.avatarCardDef("/../assets/avatars/ico/male.jpg", { title: "Human", subtitle: "Male" },
  237. function (e) {
  238. let avatarID = 'avatar-' + self.kernel.moniker();
  239. vwf_view.kernel.callMethod(avatarID, "createAvatarFromGLTF", ["/../assets/avatars/male/avatar1.gltf"]);
  240. }
  241. )]
  242. }
  243. ]
  244. }
  245. ]
  246. }
  247. ]
  248. }
  249. ]
  250. }
  251. ]
  252. }
  253. let viewSettings =
  254. {
  255. $cell: true,
  256. $type: "div",
  257. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  258. $components: [
  259. {
  260. $cell: true,
  261. $type: "div",
  262. class: "mdc-layout-grid__inner",
  263. $components: [
  264. {
  265. $cell: true,
  266. $type: "div",
  267. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  268. $components: [
  269. {
  270. $cell: true,
  271. $type: "button",
  272. class: "mdc-button mdc-button--raised",
  273. $text: "OSC Settings",
  274. onclick: function (e) {
  275. let sideBar = document.querySelector('#sideBar');
  276. sideBar._sideBarComponent = oscSettings;
  277. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  278. }
  279. }
  280. ]
  281. }
  282. ]
  283. }
  284. ]
  285. }
  286. let savedStateEl = function (item) {
  287. return {
  288. $type: "li",
  289. class: "mdc-list-item",
  290. role: "option",
  291. $components: [
  292. {
  293. $text: "Saved world"
  294. }
  295. ]
  296. }
  297. }
  298. let stateListElement = function (item) {
  299. let liEl = {
  300. $type: "li",
  301. class: "mdc-list-item",
  302. role: "option",
  303. id: "",
  304. applicationpath: "",
  305. $components: [
  306. {
  307. $text: "no saves"
  308. }
  309. ]
  310. }
  311. let applicationName = item.applicationpath.split("/");
  312. if (applicationName == "") {
  313. return liEl
  314. }
  315. if (applicationName.length > 0) {
  316. applicationName = applicationName[applicationName.length - 1];
  317. }
  318. if (applicationName.length > 0) {
  319. applicationName = applicationName.charAt(0).toUpperCase() + applicationName.slice(1);
  320. }
  321. if (item.latestsave) {
  322. liEl = {
  323. $type: "li",
  324. class: "mdc-list-item",
  325. role: "option",
  326. id: item.savename,
  327. applicationpath: item.applicationpath,
  328. $components: [
  329. {
  330. $text: applicationName + ": " + item.savename
  331. }
  332. ]
  333. }
  334. }
  335. else {
  336. liEl = {
  337. $type: "li",
  338. class: "mdc-list-item",
  339. role: "option",
  340. id: item.savename,
  341. revision: item.revision,
  342. applicationpath: item.applicationpath,
  343. $components: [
  344. {
  345. $text: applicationName + ": " + item.savename + " Rev(" + item.revision + ")"
  346. }
  347. ]
  348. }
  349. }
  350. return liEl
  351. }
  352. let oscSettings =
  353. {
  354. $cell: true,
  355. $type: "div",
  356. id: "oscSettings",
  357. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  358. _oscHost: '',
  359. _oscPort: '',
  360. _oscStatus: '',
  361. _updateStatus: function () {
  362. this._oscStatus = window._OSCManager.getStatus()
  363. },
  364. $init: function () {
  365. if (window._OSCManager) {
  366. this._oscHost = window._OSCManager.hostValue;
  367. this._oscPort = window._OSCManager.portValue;
  368. this._oscStatus = window._OSCManager.getStatus();
  369. // var t = this;
  370. // setInterval(function () {
  371. // t._updateStatus();
  372. // }, 1000);
  373. }
  374. },
  375. $update: function () {
  376. let that = this
  377. var buttonText = "Connect";
  378. var buttonFunc = function (e) {
  379. }
  380. if (this._oscStatus == 1) {
  381. buttonText = "Disconnect";
  382. buttonFunc = function (e) {
  383. window._OSCManager.disconnect();
  384. }
  385. } else {
  386. var buttonFunc = function (e) {
  387. window._OSCManager.connect();
  388. window._OSCManager.port.on("open", function () {
  389. that._oscStatus = window._OSCManager.getStatus();
  390. console.log("connected");
  391. });
  392. window._OSCManager.port.on("close", function () {
  393. that._oscStatus = window._OSCManager.getStatus();
  394. console.log("disconnected");
  395. });
  396. }
  397. }
  398. this.$components = [
  399. {
  400. $cell: true,
  401. $type: "div",
  402. class: "mdc-layout-grid__inner",
  403. $components: [
  404. {
  405. $cell: true,
  406. $type: "div",
  407. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  408. $components: [
  409. {
  410. $type: "span",
  411. $text: "Host: "
  412. },
  413. {
  414. class: "mdc-textfield",
  415. $cell: true,
  416. $type: "span",
  417. $components: [
  418. {
  419. class: "mdc-textfield__input",
  420. id: "oscHost",
  421. $cell: true,
  422. $type: "input",
  423. type: "text",
  424. value: this._oscHost,
  425. onchange: function (e) {
  426. this._oscHost = this.value;
  427. window._OSCManager.setOSCHostAndPort(this._oscHost, this._oscPort);
  428. }
  429. }
  430. ]
  431. }
  432. ]
  433. },
  434. {
  435. $cell: true,
  436. $type: "div",
  437. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  438. $components: [
  439. {
  440. $type: "span",
  441. $text: "Port: "
  442. },
  443. {
  444. class: "mdc-textfield",
  445. $cell: true,
  446. $type: "span",
  447. $components: [
  448. {
  449. class: "mdc-textfield__input",
  450. id: "oscPort",
  451. $cell: true,
  452. $type: "input",
  453. type: "text",
  454. value: this._oscPort,
  455. onchange: function (e) {
  456. this._oscPort = this.value;
  457. window._OSCManager.setOSCHostAndPort(this._oscHost, this._oscPort);
  458. }
  459. }
  460. ]
  461. }
  462. ]
  463. },
  464. {
  465. $cell: true,
  466. $type: "div",
  467. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  468. $components: [
  469. {
  470. $cell: true,
  471. $type: "button",
  472. class: "mdc-button mdc-button--raised",
  473. $text: buttonText,
  474. onclick: buttonFunc
  475. }
  476. ]
  477. }
  478. ]
  479. }
  480. ]
  481. }
  482. }
  483. let loadSaveSettings =
  484. {
  485. $cell: true,
  486. $type: "div",
  487. id: "loadSaveSettings",
  488. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  489. _saveStates: [],
  490. _getStates: async function () {
  491. let response = await fetch("/" + self.getRoot() + "/listallsaves");
  492. let data = await response.json();
  493. //this._saveStates = data;
  494. //let appName = self.getRoot();
  495. //console.log(data.filter(item => item.applicationpath.split("/")[1] == appName));
  496. let filterData = data.filter(item => item.applicationpath.split("/")[1] == self.getRoot());
  497. if (filterData.length !== 0) {
  498. this._saveStates = filterData
  499. //return filterData
  500. } else {
  501. this._saveStates = [{
  502. savename: "",
  503. latestsave: "",
  504. revision: "",
  505. applicationpath: "",
  506. url: ""
  507. }]
  508. }
  509. // this._saveStates.filter(item => item.applicationpath.split("/")[1] == self.getRoot()).map(stateListElement)
  510. //return data
  511. //console.log(data);
  512. return this._saveStates
  513. },
  514. $init: function () {
  515. this._getStates();
  516. },
  517. $update: function () {
  518. this.$components =
  519. [
  520. {
  521. $cell: true,
  522. $type: "div",
  523. class: "mdc-layout-grid__inner",
  524. $components: [
  525. {
  526. $cell: true,
  527. $type: "div",
  528. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  529. $components: [
  530. {
  531. class: "mdc-textfield",
  532. $cell: true,
  533. $type: "span",
  534. $components: [
  535. {
  536. class: "mdc-textfield__input",
  537. id: "fileName",
  538. $cell: true,
  539. $type: "input",
  540. type: "text",
  541. value: self.getRoot()
  542. }]
  543. }
  544. ]
  545. },
  546. {
  547. $cell: true,
  548. $type: "div",
  549. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  550. $components: [
  551. {
  552. $cell: true,
  553. $type: "button",
  554. class: "mdc-button mdc-button--raised",
  555. $text: "Save",
  556. onclick: function (e) {
  557. let fileName = document.querySelector('#fileName')
  558. saveStateAsFile.call(self, fileName.value);
  559. document.querySelector("#fileName").value = '';
  560. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  561. }
  562. }
  563. ]
  564. },
  565. {
  566. $cell: true,
  567. $type: "div",
  568. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  569. $components: [
  570. {
  571. $cell: true,
  572. $type: "div",
  573. class: "mdc-select",
  574. $init: function () {
  575. var MDCSelect = mdc.select.MDCSelect;
  576. const select = new MDCSelect(document.querySelector('.mdc-select'));
  577. select.listen('MDCSelect:change', () => {
  578. //this._selectedState = select.value;
  579. document.querySelector('#loadStateButton')._selectedState = select.selectedOptions[0];
  580. //console.log(select.value);
  581. //.selectedOptions[0]
  582. });
  583. },
  584. role: "listbox",
  585. $components: [
  586. {
  587. $type: "span",
  588. class: "mdc-select__selected-text",
  589. $text: "Select saved state"
  590. },
  591. {
  592. $type: "div",
  593. class: "mdc-simple-menu mdc-select__menu",
  594. $components: [
  595. {
  596. $type: "ul",
  597. class: "mdc-list mdc-simple-menu__items",
  598. $components: this._saveStates.map(stateListElement)
  599. }
  600. ]
  601. }
  602. ]
  603. }
  604. ]
  605. },
  606. {
  607. $cell: true,
  608. $type: "div",
  609. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  610. $components: [
  611. {
  612. $cell: true,
  613. $type: "button",
  614. _selectedState: {},
  615. id: "loadStateButton",
  616. class: "mdc-button mdc-button--raised",
  617. $text: "Load",
  618. onclick: function (e) {
  619. loadSavedState.call(self, this._selectedState.getAttribute('id'), this._selectedState.getAttribute('applicationpath'), this._selectedState.getAttribute('revision'));
  620. //document.querySelector('#' + 'viewSettings').style.visibility = 'hidden';
  621. }
  622. }
  623. ]
  624. }
  625. ]
  626. }
  627. ]
  628. }
  629. }
  630. let protoPropertiesCell = function (m) {
  631. return {
  632. $type: "div",
  633. class: "mdc-layout-grid__inner",
  634. _prop: {},
  635. $init: function () {
  636. let prop = m[1].prop;
  637. if (prop.value == undefined && this._currentNode !== undefined) {
  638. prop.value = JSON.stringify(utility.transform(vwf.getProperty(this._currentNode, prop.name, []), utility.transforms.transit));
  639. }
  640. this._prop = prop
  641. },
  642. $update: function () {
  643. this.$components = [
  644. {
  645. $type: "div",
  646. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  647. $components: [
  648. { $text: this._prop.name }
  649. ]
  650. },
  651. {
  652. $type: "div",
  653. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  654. },
  655. {
  656. $type: "div",
  657. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-7",
  658. $components: [
  659. {
  660. class: "mdc-textfield",
  661. $cell: true,
  662. $type: "div",
  663. $components: [{
  664. class: "mdc-textfield__input",
  665. $cell: true,
  666. $type: "input",
  667. type: "text",
  668. value: this._prop.value,
  669. onchange: function (e) {
  670. let propValue = this.value;
  671. try {
  672. propValue = JSON.parse(propValue);
  673. self.kernel.setProperty(this._currentNode, this._prop.name, propValue);
  674. } catch (e) {
  675. // restore the original value on error
  676. this.value = propValue;
  677. }
  678. }
  679. }]
  680. }
  681. ]
  682. }
  683. ]
  684. }
  685. }
  686. }
  687. let propertiesCell = function (m) {
  688. var editComponents = [{}, {}]
  689. if (m.name.indexOf("semantics") > -1) { }
  690. else if (m.name.indexOf("grammar") > -1) { }
  691. else if (m.name.indexOf("ohm") > -1) {
  692. editComponents = [
  693. {
  694. $type: "div",
  695. $cell: true,
  696. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-6",
  697. $components: [
  698. {
  699. $cell: true,
  700. $type: "button",
  701. class: "mdc-button",
  702. $text: "Edit", //edit grammar
  703. onclick: function (e) {
  704. var currentNode = document.querySelector('#currentNode')._currentNode;
  705. if (currentNode == '') {
  706. currentNode = vwf_view.kernel.find("", "/")[0];
  707. }
  708. let editor = document.querySelector('#livePropEditor');
  709. editor._setNode(currentNode);
  710. editor._propName = m.name;
  711. editor._prop = { body: m.rawValue, type: 'complex' }
  712. document.querySelector('#propEditorWindow').style.visibility = 'visible';
  713. }
  714. }
  715. ]
  716. },
  717. {
  718. $type: "div",
  719. $cell: true,
  720. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  721. $components: []
  722. }
  723. ]
  724. } else {
  725. editComponents = [
  726. {
  727. $type: "div",
  728. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-6",
  729. $components: [
  730. {
  731. class: "mdc-textfield",
  732. $cell: true,
  733. $type: "span",
  734. $components: [
  735. {
  736. class: "mdc-textfield__input",
  737. id: "prop-" + m.name,
  738. $cell: true,
  739. $type: "input",
  740. type: "text",
  741. value: m.getValue(),
  742. onchange: function (e) {
  743. let propValue = this.value;
  744. try {
  745. propValue = JSON.parse(propValue);
  746. self.kernel.setProperty(this._currentNode, m.name, propValue);
  747. } catch (e) {
  748. // restore the original value on error
  749. this.value = propValue;
  750. }
  751. }
  752. }
  753. ]
  754. }
  755. ]
  756. },
  757. {
  758. $type: "div",
  759. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  760. $components: [
  761. {
  762. $cell: true,
  763. $type: "button",
  764. class: "mdc-button",
  765. $text: "^", //edit grammar
  766. onclick: function (e) {
  767. var currentNode = document.querySelector('#currentNode')._currentNode;
  768. if (currentNode == '') {
  769. currentNode = vwf_view.kernel.find("", "/")[0];
  770. }
  771. let editor = document.querySelector('#livePropEditor');
  772. editor._setNode(currentNode);
  773. editor._propName = m.name;
  774. editor._prop = { body: m.getValue(), type: 'simple' }
  775. document.querySelector('#propEditorWindow').style.visibility = 'visible';
  776. }
  777. }
  778. ]
  779. }
  780. ];
  781. }
  782. return {
  783. $type: "div",
  784. class: "mdc-layout-grid__inner",
  785. $components: [
  786. {
  787. $type: "div",
  788. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  789. $components: [
  790. { $text: m.name }
  791. ]
  792. },
  793. {
  794. $type: "div",
  795. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  796. },
  797. editComponents[0],
  798. editComponents[1]
  799. ]
  800. }
  801. }
  802. let nodeLink = function (m) {
  803. var myClass = "nodeItem";
  804. let myAvatarName = 'avatar-' + self.kernel.moniker();
  805. (myAvatarName == m.name) ? (myClass = "avatarName mdc-typography--subheading2") :
  806. myClass = "nodeItem"
  807. return {
  808. $type: "li",
  809. class: "mdc-list-item",
  810. $components: [{
  811. $type: "a",
  812. class: "mdc-list-item",
  813. $href: "#",
  814. $components: [{
  815. $type: 'span',
  816. class: myClass,
  817. $text: m.name
  818. }
  819. ],
  820. onclick: function (e) {
  821. //self.currentNodeID = m.ID;
  822. document.querySelector('#currentNode')._setNode(m.ID);
  823. // document.querySelector('#liveCodeEditor')._editorNode = m.ID;
  824. // createAceEditor(self, m.ID);
  825. }
  826. }]
  827. }
  828. };
  829. let listDivider = {
  830. $cell: true,
  831. $type: "hr",
  832. class: "mdc-list-divider",
  833. }
  834. let gizmoEdit = {
  835. $type: "div",
  836. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  837. $components: [
  838. {
  839. $type: "div",
  840. class: "mdc-layout-grid__inner",
  841. $components: [
  842. {
  843. $type: "div",
  844. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  845. $components: [
  846. {
  847. $cell: true,
  848. $type: "span",
  849. $text: "Edit: ",
  850. }
  851. ]
  852. },
  853. {
  854. $type: "div",
  855. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-7",
  856. $components: [
  857. {
  858. $cell: true,
  859. $type: "div",
  860. class: "mdc-switch",
  861. $components: [
  862. {
  863. $type: "input",
  864. type: "checkbox",
  865. class: "mdc-switch__native-control",
  866. id: 'editnode',
  867. $init: function () {
  868. vwf_view.kernel.getProperty(this._currentNode, 'edit');
  869. },
  870. //id: "basic-switch",
  871. onchange: function (e) {
  872. var nodeID = document.querySelector('#currentNode')._currentNode;
  873. let chkAttr = this.getAttribute('checked');
  874. if (chkAttr == "") {
  875. self.kernel.setProperty(this._currentNode, 'edit', false);
  876. } else {
  877. self.kernel.setProperty(this._currentNode, 'edit', true);
  878. }
  879. vwf_view.kernel.callMethod(nodeID, "showCloseGizmo");
  880. }
  881. },
  882. {
  883. $type: "div",
  884. class: "mdc-switch__background",
  885. $components: [
  886. {
  887. $type: "div",
  888. class: "mdc-switch__knob"
  889. }
  890. ]
  891. }
  892. ]
  893. }
  894. ]
  895. },
  896. {
  897. $type: "div",
  898. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  899. $components: [
  900. {
  901. $cell: true,
  902. $type: "a",
  903. class: "gizmomode",
  904. $text: "T",
  905. onclick: function (e) {
  906. vwf_view.kernel.callMethod(this._currentNode, "setGizmoMode", ['translate'])
  907. }
  908. }
  909. ]
  910. },
  911. {
  912. $type: "div",
  913. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  914. $components: [
  915. {
  916. $cell: true,
  917. $type: "a",
  918. class: "gizmomode",
  919. $text: "R",
  920. onclick: function (e) {
  921. vwf_view.kernel.callMethod(this._currentNode, "setGizmoMode", ['rotate'])
  922. }
  923. }
  924. ]
  925. },
  926. {
  927. $type: "div",
  928. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-1",
  929. $components: [
  930. {
  931. $cell: true,
  932. $type: "a",
  933. class: "gizmomode",
  934. $text: "S",
  935. onclick: function (e) {
  936. vwf_view.kernel.callMethod(this._currentNode, "setGizmoMode", ['scale'])
  937. }
  938. }
  939. ]
  940. }
  941. ]
  942. }
  943. ]
  944. }
  945. let nodesCell = {
  946. $cell: true,
  947. $type: "div",
  948. id: "currentNode",
  949. _childNodes: [],
  950. _currentNode: '',
  951. _displayedProperties: {},
  952. _setNode: function (aNode) {
  953. this._currentNode = aNode;
  954. document.querySelector('#sideBar')._sideCurrentNode = this._currentNode
  955. },
  956. $init: function () {
  957. this._currentNode = document.querySelector('#sideBar')._sideCurrentNode
  958. //this._currentNode = vwf_view.kernel.find("", "/")[0];
  959. //this._currentNode = '3333';
  960. },
  961. _getChildNodes: function () {
  962. this._childNodes = self.nodes[this._currentNode];
  963. if (this._childNodes !== undefined) {
  964. return this._childNodes.children
  965. } else {
  966. return []
  967. }
  968. //let nodeIDAlpha = he.encode(this._currentNode);
  969. },
  970. // _getNodeComplexProperties: function () {
  971. // let node = self.nodes[this._currentNode];
  972. // let props = this._getNodeProperties();
  973. // let filterFunction = function (prop) {
  974. // return (prop.name == 'ohmLang')
  975. // };
  976. // let complexProps = props.filter(filterFunction.bind(this));
  977. // return complexProps
  978. // },
  979. _getNodeProperties: function () {
  980. let node = self.nodes[this._currentNode];
  981. this._displayedProperties = {};
  982. let filterFunction = function (prop) {
  983. return (!this._displayedProperties[prop.name] && prop.name.indexOf('$') === -1) ? (this._displayedProperties[prop.name] = "instance", true) : (false);
  984. };
  985. let props = node.properties.filter(filterFunction.bind(this));
  986. return props
  987. },
  988. _getNodeProtoProperties: function () {
  989. let node = self.nodes[this._currentNode];
  990. let filterFunction = function (prop) {
  991. return (!this._displayedProperties[prop[1].prop.name]) ? (this._displayedProperties[prop[1].prop.name] = prop[1].prototype, true) : (false);
  992. };
  993. let props = Object.entries(getProperties.call(self, self.kernel, node.extendsID)).filter(filterFunction.bind(this));
  994. return props
  995. },
  996. $update: function () {
  997. //this.$text = this._currentNode;
  998. let node = self.nodes[this._currentNode];
  999. let nodeProtos = getPrototypes(self.kernel, node.extendsID);
  1000. var viewerProps = {};
  1001. var viewerPropsCell = {};
  1002. var gizmoCell = {};
  1003. if (this._currentNode !== self.kernel.application()) {
  1004. if (nodeProtos.includes('http://vwf.example.com/aframe/componentNode.vwf')) {
  1005. //gizmoCell = {};
  1006. } else {
  1007. gizmoCell = gizmoEdit
  1008. }
  1009. }
  1010. if (node !== undefined) {
  1011. if (node.extendsID == "http://vwf.example.com/aframe/acamera.vwf") {
  1012. viewerProps = {
  1013. $type: "li",
  1014. class: "mdc-list-item",
  1015. $components: [
  1016. {
  1017. $text: "Viewer properties",
  1018. $type: "span",
  1019. class: "mdc-list-item__text mdc-typography--button"
  1020. }
  1021. ]
  1022. }
  1023. viewerPropsCell = {
  1024. $cell: true,
  1025. $type: "div",
  1026. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1027. $components: [
  1028. {
  1029. $cell: true,
  1030. $type: "div",
  1031. class: "mdc-layout-grid__inner",
  1032. $components: [
  1033. {
  1034. $cell: true,
  1035. $type: "div",
  1036. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1037. $components: [
  1038. {
  1039. $cell: true,
  1040. $type: "button",
  1041. class: "mdc-button mdc-button--raised",
  1042. $text: "Active",
  1043. onclick: function (e) {
  1044. let camera = document.querySelector('#' + this._currentNode);
  1045. camera.setAttribute('active', true);
  1046. }
  1047. }
  1048. ]
  1049. }
  1050. ]
  1051. }
  1052. ]
  1053. //$components: this._getNodeProtoProperties().map(protoPropertiesCell)
  1054. }
  1055. } else {
  1056. viewerProps = {};
  1057. viewerPropsCell = {};
  1058. }
  1059. }
  1060. this.$components = [
  1061. {
  1062. $cell: true,
  1063. $type: "ul",
  1064. class: "mdc-list",
  1065. $components: [
  1066. {
  1067. $cell: true,
  1068. $type: "button",
  1069. class: "mdc-list-item mdc-button mdc-button--raised",
  1070. $text: "<--",
  1071. onclick: function (e) {
  1072. let node = self.nodes[this._currentNode];
  1073. if (node.parentID !== 0) {
  1074. //self.currentNodeID = node.parentID,
  1075. document.querySelector('#currentNode')._setNode(node.parentID)
  1076. }
  1077. }
  1078. },
  1079. {
  1080. $type: "li",
  1081. class: "mdc-list-item",
  1082. $components: [
  1083. {
  1084. $text: "name",
  1085. $type: "span",
  1086. $init: function () {
  1087. let node = self.nodes[this._currentNode];
  1088. if (node) this.$text = node.name
  1089. },
  1090. class: "mdc-list-item__text mdc-typography--headline"
  1091. //<h1 class="mdc-typography--display4">Big header</h1>
  1092. }]
  1093. }, listDivider,
  1094. {
  1095. // $cell: true,
  1096. // $type: "ul",
  1097. // class: "mdc-list",
  1098. $type: "div",
  1099. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1100. $components: [
  1101. {
  1102. $type: "div",
  1103. class: "mdc-layout-grid__inner",
  1104. $components: [
  1105. {
  1106. $type: "div",
  1107. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1108. $components: [
  1109. {
  1110. $cell: true,
  1111. $type: "button",
  1112. class: "mdc-button mdc-button--raised",
  1113. $text: "Methods browser",
  1114. onclick: function (e) {
  1115. var currentNode = document.querySelector('#currentNode')._currentNode;
  1116. if (currentNode == '') {
  1117. currentNode = vwf_view.kernel.find("", "/")[0];
  1118. }
  1119. document.querySelector('#liveCodeEditor')._setNode(currentNode);
  1120. //createAceEditor(self, currentNode);
  1121. document.querySelector('#codeEditorWindow').style.visibility = 'visible';
  1122. }
  1123. }
  1124. ]
  1125. }
  1126. ]
  1127. }
  1128. ]
  1129. },
  1130. gizmoCell,
  1131. listDivider,
  1132. {
  1133. $type: "li",
  1134. class: "mdc-list-item",
  1135. $components: [
  1136. {
  1137. $text: "Children",
  1138. $type: "span",
  1139. class: "mdc-list-item__text mdc-typography--button"
  1140. }]
  1141. },
  1142. {
  1143. $cell: true,
  1144. $type: "ul",
  1145. class: "mdc-list",
  1146. $components: this._getChildNodes().map(nodeLink)
  1147. }, listDivider, {
  1148. $type: "li",
  1149. class: "mdc-list-item",
  1150. $components: [
  1151. {
  1152. $text: "Properties",
  1153. $type: "span",
  1154. class: "mdc-list-item__text mdc-typography--button"
  1155. //<h1 class="mdc-typography--display4">Big header</h1>
  1156. }]
  1157. },
  1158. {
  1159. // $cell: true,
  1160. // $type: "ul",
  1161. // class: "mdc-list",
  1162. $type: "div",
  1163. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1164. $components: this._getNodeProperties().map(propertiesCell)
  1165. },
  1166. listDivider,
  1167. {
  1168. $type: "li",
  1169. class: "mdc-list-item",
  1170. $components: [
  1171. {
  1172. $text: "Proto properties",
  1173. $type: "span",
  1174. class: "mdc-list-item__text mdc-typography--button"
  1175. }]
  1176. },
  1177. {
  1178. $cell: true,
  1179. $type: "div",
  1180. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1181. $components: this._getNodeProtoProperties().map(protoPropertiesCell)
  1182. }, listDivider,
  1183. viewerProps,
  1184. viewerPropsCell
  1185. ]
  1186. }
  1187. ]
  1188. }
  1189. }
  1190. let colorPickerComponent = {
  1191. $cell: true,
  1192. $type: "div",
  1193. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-4",
  1194. $init: function () {
  1195. let myEl = this;
  1196. let cp = ColorPicker(
  1197. document.getElementById('slide'),
  1198. document.getElementById('picker'),
  1199. function (hex, hsv, rgb, mousePicker, mouseSlide) {
  1200. ColorPicker.positionIndicators(
  1201. document.getElementById('slide-indicator'),
  1202. document.getElementById('picker-indicator'),
  1203. mouseSlide, mousePicker
  1204. );
  1205. if (myEl._propName == 'color') {
  1206. // console.log(hex);
  1207. document.querySelector('#propAceEditor').env.editor.setValue(JSON.stringify(hex));
  1208. self.kernel.setProperty(myEl._editorNode, myEl._propName, hex);
  1209. }
  1210. });
  1211. if (myEl._propName == 'color') {
  1212. cp.setHex(JSON.parse(myEl._prop.body));
  1213. }
  1214. },
  1215. $components: [
  1216. {
  1217. $cell: true,
  1218. $type: "div",
  1219. id: "color-picker",
  1220. class: "cp-default",
  1221. $components: [
  1222. {
  1223. $cell: true,
  1224. $type: "div",
  1225. class: "picker-wrapper",
  1226. $components: [
  1227. {
  1228. $cell: true,
  1229. $type: "div",
  1230. id: "picker",
  1231. class: "picker",
  1232. style: "width: 130px; height: 130px"
  1233. },
  1234. {
  1235. $cell: true,
  1236. $type: "div",
  1237. id: "picker-indicator",
  1238. class: "picker-indicator"
  1239. }
  1240. ]
  1241. },
  1242. {
  1243. $cell: true,
  1244. $type: "div",
  1245. class: "slide-wrapper",
  1246. $components: [
  1247. {
  1248. $cell: true,
  1249. $type: "div",
  1250. id: "slide",
  1251. class: "slide",
  1252. style: "width: 30px; height: 130px"
  1253. },
  1254. {
  1255. $cell: true,
  1256. $type: "div",
  1257. id: "slide-indicator",
  1258. class: "slide-indicator"
  1259. }
  1260. ]
  1261. }
  1262. ]
  1263. }
  1264. // {
  1265. // $cell: true,
  1266. // $type: "div",
  1267. // id: "color-picker",
  1268. // $init: function () {
  1269. // }
  1270. // }
  1271. ]
  1272. }
  1273. let propEditorWindow = {
  1274. $cell: true,
  1275. $type: "div",
  1276. _editorNode: '',
  1277. _prop: { body: '', type: 'simple' },
  1278. _propName: '',
  1279. id: "livePropEditor",
  1280. _setNode: function (node) {
  1281. this._editorNode = node;
  1282. this._prop.body = ''
  1283. },
  1284. class: "propEditorGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1285. $update: function () {
  1286. var editorClass = "mdc-layout-grid__cell mdc-layout-grid__cell--span-8"
  1287. var livePropertyComponent = {}
  1288. if (this._prop.type == 'simple') {
  1289. if (this._propName == 'color') {
  1290. livePropertyComponent = colorPickerComponent
  1291. }
  1292. } else {
  1293. editorClass = "mdc-layout-grid__cell mdc-layout-grid__cell--span-12"
  1294. }
  1295. this.$components = [
  1296. {
  1297. $cell: true,
  1298. $type: "div",
  1299. class: "mdc-layout-grid__inner",
  1300. $components: [
  1301. {
  1302. $cell: true,
  1303. $type: "div",
  1304. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1305. $components: [
  1306. {
  1307. $cell: true,
  1308. $type: "button",
  1309. class: "mdc-button mdc-button--raised",
  1310. $text: "Update",
  1311. onclick: function (e) {
  1312. let editor = document.querySelector("#propAceEditor").env.editor;
  1313. let value = editor.getValue();
  1314. try {
  1315. let propValue = (this._prop.type == 'simple') ? (JSON.parse(value)) : (value)
  1316. //propValue = JSON.parse(value);
  1317. self.kernel.setProperty(this._editorNode, this._propName, propValue);
  1318. } catch (e) {
  1319. // restore the original value on error
  1320. this.value = propValue;
  1321. }
  1322. }
  1323. }]
  1324. },
  1325. {
  1326. $cell: true,
  1327. $type: "div",
  1328. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-5",
  1329. $components: [
  1330. {
  1331. $type: "h3",
  1332. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  1333. $text: this._editorNode
  1334. }
  1335. ]
  1336. },
  1337. {
  1338. $cell: true,
  1339. $type: "div",
  1340. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-5",
  1341. $components: [
  1342. {
  1343. $type: "h3",
  1344. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  1345. $text: this._propName
  1346. }
  1347. ]
  1348. }
  1349. ]
  1350. },
  1351. {
  1352. $cell: true,
  1353. $type: "div",
  1354. class: "mdc-layout-grid__inner",
  1355. $components: [
  1356. {
  1357. $cell: true,
  1358. $type: "div",
  1359. class: editorClass,
  1360. $components: [
  1361. {
  1362. $cell: true,
  1363. class: "aceEditor",
  1364. id: "propAceEditor",
  1365. $type: "div",
  1366. $text: this._prop.body,
  1367. $init: function () {
  1368. createAceEditor(self, this._editorNode, "propAceEditor");
  1369. this.env.editor.$blockScrolling = Infinity
  1370. }
  1371. }
  1372. ]
  1373. }, livePropertyComponent
  1374. // {
  1375. // $cell: true,
  1376. // $type: "div",
  1377. // class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1378. // $components: []
  1379. // },
  1380. ]
  1381. }
  1382. ]
  1383. //$components:
  1384. }
  1385. }
  1386. let codeEditorWindow = {
  1387. $cell: true,
  1388. $type: "div",
  1389. _editorNode: '',
  1390. _method: { body: '' },
  1391. _methodName: '',
  1392. _getNodeMethods: function () {
  1393. let node = self.nodes[this._editorNode];
  1394. return node.methods
  1395. },
  1396. _getProtoNodeMethods: function () {
  1397. let node = self.nodes[this._editorNode];
  1398. let prototypeMethods = getMethods.call(self, self.kernel, node.extendsID);
  1399. return prototypeMethods
  1400. },
  1401. id: "liveCodeEditor",
  1402. _setNode: function (node) {
  1403. this._editorNode = node;
  1404. this._method.body = ''
  1405. },
  1406. class: "codeEditorGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1407. // _getComplexProps: function(){
  1408. // let node = self.nodes[this._editorNode];
  1409. // let currentNode = document.querySelector('#currentNode');
  1410. // var props = {}
  1411. // if (currentNode !== null) {
  1412. // props = currentNode._getNodeComplexProperties();
  1413. // }
  1414. // return props
  1415. // },
  1416. // _listPropertyElement: function (m) {
  1417. // return {
  1418. // $type: "li",
  1419. // class: "mdc-list-item",
  1420. // $components: [{
  1421. // $type: "a",
  1422. // class: "mdc-list-item",
  1423. // $href: "#",
  1424. // $text: m[1].name,
  1425. // onclick: function (e) {
  1426. // this._method = {};
  1427. // this._methodName = m[1].name;
  1428. // this._method.body = m[1].rawValue
  1429. // this._method.type = "complexProperty"
  1430. // }
  1431. // }]
  1432. // }
  1433. // },
  1434. _listElement: function (m) {
  1435. return {
  1436. $type: "li",
  1437. class: "mdc-list-item",
  1438. $components: [{
  1439. $type: "a",
  1440. class: "mdc-list-item",
  1441. $href: "#",
  1442. $text: m[0],
  1443. onclick: function (e) {
  1444. let method = vwf.getMethod(this._editorNode, m[0]);
  1445. //document.querySelector('#aceEditor').
  1446. this._method = method;
  1447. this._methodName = m[0];
  1448. //self.currentNodeID = m.ID;
  1449. //document.querySelector('#currentNode')._setNode(m.ID);
  1450. }
  1451. }]
  1452. }
  1453. },
  1454. $update: function () {
  1455. this.$components = [
  1456. {
  1457. $cell: true,
  1458. $type: "div",
  1459. class: "mdc-layout-grid__inner",
  1460. $components: [
  1461. {
  1462. $cell: true,
  1463. $type: "div",
  1464. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1465. $components: [
  1466. {
  1467. $type: "h3",
  1468. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--subheading1",
  1469. $text: this._editorNode
  1470. }
  1471. ]
  1472. },
  1473. {
  1474. $cell: true,
  1475. $type: "div",
  1476. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1477. $components: [
  1478. {
  1479. $cell: true,
  1480. $type: "button",
  1481. class: "mdc-button mdc-button--raised",
  1482. $text: "Update",
  1483. onclick: function (e) {
  1484. let editor = document.querySelector("#aceEditor").env.editor;
  1485. let evalText = editor.getValue();
  1486. // if (this._method.type == 'complexProperty') {
  1487. // let propValue = evalText;
  1488. // try {
  1489. // //propValue = JSON.parse(propValue);
  1490. // self.kernel.setProperty(this._editorNode, this._methodName, propValue);
  1491. // } catch (e) {
  1492. // // restore the original value on error
  1493. // this.value = propValue;
  1494. // }
  1495. // } else {
  1496. // }
  1497. self.kernel.setMethod(this._editorNode, this._methodName,
  1498. { body: evalText, type: "application/javascript", parameters: this._method.parameters });
  1499. }
  1500. }]
  1501. },
  1502. {
  1503. $cell: true,
  1504. $type: "div",
  1505. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1506. $components: [
  1507. {
  1508. $cell: true,
  1509. $type: "button",
  1510. class: "mdc-button mdc-button--raised",
  1511. $text: "Call",
  1512. onclick: function (e) {
  1513. var params = [];
  1514. if (this._method.parameters) {
  1515. let paramsLength = this._method.parameters.length
  1516. if (paramsLength >= 1) {
  1517. let paramsVal = document.querySelector("#methodParams").value;
  1518. try {
  1519. params = JSON.parse(paramsVal);
  1520. //params.push(prmtr);
  1521. } catch (e) {
  1522. self.logger.error('Invalid Value');
  1523. }
  1524. }
  1525. };
  1526. self.kernel.callMethod(this._editorNode, this._methodName, params);
  1527. }
  1528. }]
  1529. },
  1530. {
  1531. $cell: true,
  1532. $type: "div",
  1533. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1534. $components: [
  1535. {
  1536. $cell: true,
  1537. $type: "button",
  1538. class: "mdc-button mdc-button--raised",
  1539. $text: "Do It",
  1540. onclick: function (e) {
  1541. let editor = document.querySelector("#aceEditor").env.editor;
  1542. codeEditorDoit.call(self, editor, this._editorNode);
  1543. }
  1544. }]
  1545. },
  1546. {
  1547. $cell: true,
  1548. $type: "div",
  1549. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1550. $components: [
  1551. {
  1552. $cell: true,
  1553. $type: "button",
  1554. class: "mdc-button mdc-button--raised",
  1555. $text: "Print It",
  1556. onclick: function (e) {
  1557. let editor = document.querySelector("#aceEditor").env.editor;
  1558. codeEditorPrintit.call(self, editor, this._editorNode);
  1559. }
  1560. }]
  1561. }
  1562. ]
  1563. },
  1564. {
  1565. $cell: true,
  1566. $type: "div",
  1567. class: "mdc-layout-grid__inner",
  1568. $components: [
  1569. {
  1570. $cell: true,
  1571. $type: "div",
  1572. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1573. style: "overflow-y: scroll; max-height: 400px;",
  1574. $components: [
  1575. {
  1576. $cell: true,
  1577. $type: "div",
  1578. class: "mdc-list-group",
  1579. $components: [
  1580. {
  1581. $type: "h3",
  1582. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  1583. $text: "Node methods"
  1584. },
  1585. {
  1586. $cell: true,
  1587. $type: "ul",
  1588. class: "mdc-list",
  1589. $components: Object.entries(this._getNodeMethods()).map(this._listElement)
  1590. }, listDivider,
  1591. {
  1592. $type: "h3",
  1593. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  1594. $text: "Proto methods"
  1595. },
  1596. {
  1597. $cell: true,
  1598. $type: "ul",
  1599. class: "mdc-list",
  1600. $components: Object.entries(this._getProtoNodeMethods()).map(this._listElement)
  1601. }, listDivider,
  1602. {
  1603. $type: "h3",
  1604. class: "mdc-list-group__subheader mdc-list-item__text mdc-typography--button",
  1605. $text: "Events"
  1606. }
  1607. // {
  1608. // $cell: true,
  1609. // $type: "ul",
  1610. // class: "mdc-list",
  1611. // $components: Object.entries(this._getComplexProps()).map(this._listPropertyElement)
  1612. // }
  1613. ]
  1614. }
  1615. ]
  1616. },
  1617. {
  1618. $cell: true,
  1619. $type: "div",
  1620. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-9",
  1621. $components: [
  1622. {
  1623. $cell: true,
  1624. class: "aceEditor",
  1625. id: "aceEditor",
  1626. $type: "div",
  1627. $text: this._method.body,
  1628. $init: function () {
  1629. createAceEditor(self, this._editorNode, "aceEditor");
  1630. }
  1631. }
  1632. ]
  1633. }
  1634. ]
  1635. },
  1636. {
  1637. $cell: true,
  1638. $type: "div",
  1639. class: "mdc-layout-grid__inner",
  1640. $components: [
  1641. {
  1642. $cell: true,
  1643. $type: "div",
  1644. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1645. $components: [
  1646. {
  1647. $type: "span",
  1648. $text: "*"
  1649. }
  1650. ]
  1651. }
  1652. ]
  1653. },
  1654. { //params input
  1655. $cell: true,
  1656. $type: "div",
  1657. class: "mdc-layout-grid__inner",
  1658. $components: [
  1659. {
  1660. $cell: true,
  1661. $type: "div",
  1662. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-3",
  1663. $components: [
  1664. {
  1665. class: "mdc-textfield",
  1666. $cell: true,
  1667. $type: "div",
  1668. $components: [{
  1669. class: "mdc-textfield__input",
  1670. id: "methodName",
  1671. $cell: true,
  1672. $type: "input",
  1673. type: "text",
  1674. value: "newMethodName",
  1675. onchange: function (e) {
  1676. let propValue = this.value;
  1677. try {
  1678. } catch (e) {
  1679. // restore the original value on error
  1680. }
  1681. }
  1682. }]
  1683. }
  1684. ]
  1685. },
  1686. {
  1687. $cell: true,
  1688. $type: "div",
  1689. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-7",
  1690. $components: [
  1691. {
  1692. class: "mdc-textfield params-textfield-input",
  1693. $cell: true,
  1694. $type: "div",
  1695. $components: [{
  1696. class: "mdc-textfield__input",
  1697. id: "methodParams",
  1698. $cell: true,
  1699. $type: "input",
  1700. type: "text",
  1701. value: JSON.stringify(this._method.parameters),
  1702. onchange: function (e) {
  1703. let propValue = this.value;
  1704. try {
  1705. } catch (e) {
  1706. // restore the original value on error
  1707. }
  1708. }
  1709. }]
  1710. }
  1711. ]
  1712. },
  1713. {
  1714. $cell: true,
  1715. $type: "div",
  1716. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2",
  1717. $components: [
  1718. {
  1719. $cell: true,
  1720. $type: "button",
  1721. class: "mdc-button mdc-button--raised",
  1722. $text: "Create",
  1723. onclick: function (e) {
  1724. let methodName = document.querySelector('#methodName').value;
  1725. //let methodParams = document.querySelector('#methodParams');
  1726. var params = [];
  1727. let body = '';
  1728. let paramsVal = document.querySelector("#methodParams").value;
  1729. if (paramsVal !== '') {
  1730. try {
  1731. params = JSON.parse(paramsVal);
  1732. //params.push(prmtr);
  1733. } catch (e) {
  1734. self.logger.error('Invalid Value');
  1735. }
  1736. }
  1737. self.kernel.createMethod(this._editorNode, methodName, params, body);
  1738. this._setNode(this._editorNode);
  1739. // let editor = document.querySelector("#aceEditor").env.editor;
  1740. // codeEditorDoit.call(self, editor, this._editorNode);
  1741. }
  1742. }
  1743. ]
  1744. }
  1745. ]
  1746. }
  1747. ]
  1748. //$components:
  1749. }
  1750. }
  1751. let propWindow = {
  1752. $cell: true,
  1753. $type: "div",
  1754. class: "propGrid mdc-layout-grid max-width mdc-layout-grid--align-left",
  1755. style: "overflow-y: scroll; max-height: 800px;",
  1756. $components: [
  1757. {
  1758. $type: "div",
  1759. class: "mdc-layout-grid__inner",
  1760. $components: [
  1761. {
  1762. $cell: true,
  1763. $type: "div",
  1764. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1765. $components: [
  1766. nodesCell
  1767. ]
  1768. }
  1769. ]
  1770. }
  1771. // <button class="mdc-button">
  1772. // Flat button
  1773. // </button>
  1774. ]
  1775. }
  1776. let clientListCell = {
  1777. $cell: true,
  1778. $type: "div",
  1779. class: "mdc-list",
  1780. id: "clientsList",
  1781. _watchNodes: [],
  1782. _listElement: function (m) {
  1783. return {
  1784. $type: "a",
  1785. class: "mdc-list-item",
  1786. $href: "#",
  1787. $text: m.name,
  1788. onclick: function (e) {
  1789. //self.currentNodeID = m.ID;
  1790. //document.querySelector('#currentNode')._setNode(m.ID);
  1791. }
  1792. }
  1793. },
  1794. $init: function () {
  1795. var t = this;
  1796. setInterval(function () {
  1797. t._updateMe();
  1798. }, 1000);
  1799. },
  1800. _updateMe: function () {
  1801. this._watchNodes = self.nodes["http://vwf.example.com/clients.vwf"].children.slice()
  1802. },
  1803. $update: function () {
  1804. //this._clientNodes
  1805. this.$components = this._watchNodes.map(this._listElement)
  1806. }
  1807. }
  1808. //createCellWindow("clientsWindow", clientListCell, "Clients");
  1809. //createCellWindow("propWindow", propWindow, "Scene");
  1810. createCellWindow("codeEditorWindow", codeEditorWindow, "Code editor");
  1811. createCellWindow("propEditorWindow", propEditorWindow, "Prop editor");
  1812. let viewSceneProps = {
  1813. $cell: true,
  1814. $type: "div",
  1815. class: "propGrid mdc-layout-grid mdc-layout-grid--align-left",
  1816. //style: "overflow-y: scroll; max-height: 500px; overflow-x: hidden;",
  1817. $components: [
  1818. {
  1819. $type: "div",
  1820. class: "mdc-layout-grid__inner",
  1821. $components: [
  1822. {
  1823. $cell: true,
  1824. $type: "div",
  1825. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1826. $components: [
  1827. nodesCell
  1828. ]
  1829. }
  1830. ]
  1831. }
  1832. ]
  1833. }
  1834. let sideBar = {
  1835. $cell: true,
  1836. $type: "div",
  1837. id: 'sideBar',
  1838. class: "sideBar mdc-toolbar-fixed-adjust",
  1839. _sideBarComponent: {},
  1840. _sideCurrentNode: '',
  1841. $init: function () {
  1842. this.style.visibility = 'hidden';
  1843. this._importScript("/" + self.getRoot() + "/appui.js");
  1844. },
  1845. _importScript: function (sSrc, fOnload) {
  1846. var oScript = document.createElement("script");
  1847. oScript.type = "text\/javascript";
  1848. oScript.async = false;
  1849. //oScript.onerror = loadError;
  1850. if (fOnload) { oScript.onload = fOnload; }
  1851. oScript.src = sSrc;
  1852. //let sideBar = document.querySelector('#sideBar');
  1853. this.appendChild(oScript);
  1854. },
  1855. _getAppDef: async function () {
  1856. let response = await fetch("/" + self.getRoot() + "/appui.js");
  1857. let data = await response.text();
  1858. //console.log(data)
  1859. return data
  1860. },
  1861. $update: function () {
  1862. this.$components = [
  1863. {
  1864. $cell: true,
  1865. $type: "button",
  1866. class: "mdc-button mdc-button--compact",
  1867. $text: "X",
  1868. onclick: function (e) {
  1869. document.querySelector('#sideBar').style.visibility = 'hidden';
  1870. }
  1871. },
  1872. this._sideBarComponent
  1873. ]
  1874. }
  1875. //$components: [this._sideComponents]
  1876. }
  1877. document.querySelector('#' + 'sideBar').$cell(sideBar)
  1878. let defaultApp = function () {
  1879. return {
  1880. $cell: true,
  1881. $type: "div",
  1882. class: "propGrid max-width mdc-layout-grid mdc-layout-grid--align-left",
  1883. $components: [
  1884. {
  1885. $cell: true,
  1886. $type: "div",
  1887. class: "mdc-layout-grid__inner",
  1888. $components: [
  1889. {
  1890. $cell: true,
  1891. $type: "div",
  1892. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1893. $components: [
  1894. {
  1895. $cell: true,
  1896. $type: "h3",
  1897. class: "mdc-typography--headline",
  1898. $text: "Application",
  1899. }
  1900. ]
  1901. }
  1902. ]
  1903. }
  1904. ]
  1905. }
  1906. }
  1907. let drawerCell = {
  1908. $cell: true,
  1909. $type: "nav",
  1910. class: "mdc-temporary-drawer__drawer",
  1911. $components: [
  1912. {
  1913. $cell: true,
  1914. $type: "header",
  1915. class: "mdc-temporary-drawer__header",
  1916. $components: [
  1917. {
  1918. $cell: true,
  1919. $type: "div",
  1920. class: "mdc-temporary-drawer__header-content mdc-theme--primary-bg mdc-theme--text-primary-on-primary",
  1921. $text: "Home"
  1922. }
  1923. ]
  1924. },
  1925. {
  1926. $cell: true,
  1927. $type: "nav",
  1928. class: "mdc-temporary-drawer__content mdc-list-group",
  1929. $components: [
  1930. {
  1931. $cell: true,
  1932. $type: "div",
  1933. class: "mdc-list",
  1934. $components: [
  1935. {
  1936. $cell: true,
  1937. $type: "a",
  1938. class: "mdc-list-item",
  1939. $href: "#",
  1940. onclick: function (e) {
  1941. let sideBar = document.querySelector('#sideBar');
  1942. try {
  1943. sideBar._sideBarComponent = createApp.call(self);
  1944. } catch (e) {
  1945. sideBar._sideBarComponent = defaultApp();
  1946. }
  1947. drawer.open = !drawer.open
  1948. document.querySelector('#sideBar').style.visibility = 'visible';
  1949. },
  1950. $components: [{
  1951. $type: "i",
  1952. class: "material-icons mdc-list-item__start-detail",
  1953. 'aria-hidden': "true",
  1954. $text: "play_arrow"
  1955. },
  1956. {
  1957. $text: "App"
  1958. }]
  1959. },
  1960. {
  1961. $cell: true,
  1962. $type: "a",
  1963. class: "mdc-list-item",
  1964. $href: "#",
  1965. onclick: function (e) {
  1966. let sideBar = document.querySelector('#sideBar');
  1967. sideBar._sideBarComponent = viewSceneProps;
  1968. let currentNode = document.querySelector('#sideBar')._sideCurrentNode;
  1969. currentNode == '' ? document.querySelector('#sideBar')._sideCurrentNode = (vwf_view.kernel.find("", "/")[0]) :
  1970. document.querySelector('#sideBar')._sideCurrentNode = currentNode;
  1971. document.querySelector('#sideBar').style.visibility = 'visible';
  1972. drawer.open = !drawer.open
  1973. // let currentNode = document.querySelector('#currentNode')._currentNode;
  1974. // currentNode == '' ? document.querySelector('#currentNode')._setNode(vwf_view.kernel.find("", "/")[0]) :
  1975. // document.querySelector('#currentNode')._setNode(currentNode);
  1976. },
  1977. $components: [{
  1978. $cell: true,
  1979. $type: "i",
  1980. class: "material-icons mdc-list-item__start-detail",
  1981. $text: "description"
  1982. },
  1983. {
  1984. $text: "Scene"
  1985. }
  1986. ]
  1987. },
  1988. {
  1989. $cell: true,
  1990. $type: "a",
  1991. class: "mdc-list-item",
  1992. $href: "#",
  1993. onclick: function (e) {
  1994. // var currentNode = document.querySelector('#currentNode')._currentNode;
  1995. // if (currentNode == '') {
  1996. // currentNode = vwf_view.kernel.find("", "/")[0];
  1997. // }
  1998. document.querySelector('#liveCodeEditor')._setNode(vwf_view.kernel.find("", "/")[0]);
  1999. //createAceEditor(self, currentNode);
  2000. document.querySelector('#codeEditorWindow').style.visibility = 'visible';
  2001. },
  2002. $components: [{
  2003. $type: "i",
  2004. class: "material-icons mdc-list-item__start-detail",
  2005. 'aria-hidden': "true",
  2006. $text: "code"
  2007. },
  2008. {
  2009. $text: "Code editor"
  2010. }]
  2011. },
  2012. {
  2013. $cell: true,
  2014. $type: "a",
  2015. class: "mdc-list-item",
  2016. $href: "#",
  2017. onclick: function (e) {
  2018. //self.currentNodeID = m.ID;
  2019. // document.querySelector('#clientsList')._setClientNodes(self.nodes["http://vwf.example.com/clients.vwf"]);
  2020. // document.querySelector('#clientsWindow').style.visibility = 'visible';
  2021. let sideBar = document.querySelector('#sideBar');
  2022. sideBar._sideBarComponent = avatarSettings;
  2023. drawer.open = !drawer.open
  2024. document.querySelector('#sideBar').style.visibility = 'visible';
  2025. },
  2026. $components: [{
  2027. $type: "i",
  2028. class: "material-icons mdc-list-item__start-detail",
  2029. 'aria-hidden': "true",
  2030. $text: "account_circle"
  2031. },
  2032. {
  2033. $text: "My Avatar"
  2034. }]
  2035. },
  2036. {
  2037. $cell: true,
  2038. $type: "a",
  2039. class: "mdc-list-item",
  2040. $href: "#",
  2041. onclick: function (e) {
  2042. //self.currentNodeID = m.ID;
  2043. // document.querySelector('#clientsList')._setClientNodes(self.nodes["http://vwf.example.com/clients.vwf"]);
  2044. let sideBar = document.querySelector('#sideBar');
  2045. sideBar._sideBarComponent = viewSettings;
  2046. drawer.open = !drawer.open
  2047. document.querySelector('#sideBar').style.visibility = 'visible';
  2048. },
  2049. $components: [{
  2050. $type: "i",
  2051. class: "material-icons mdc-list-item__start-detail",
  2052. 'aria-hidden': "true",
  2053. $text: "settings"
  2054. },
  2055. {
  2056. $text: "Settings"
  2057. }]
  2058. },
  2059. {
  2060. $cell: true,
  2061. $type: "a",
  2062. class: "mdc-list-item",
  2063. $href: "#",
  2064. onclick: function (e) {
  2065. //self.currentNodeID = m.ID;
  2066. // document.querySelector('#clientsList')._setClientNodes(self.nodes["http://vwf.example.com/clients.vwf"]);
  2067. let sideBar = document.querySelector('#sideBar');
  2068. sideBar._sideBarComponent = loadSaveSettings;
  2069. if (document.querySelector('#loadSaveSettings')) {
  2070. document.querySelector('#loadSaveSettings')._getStates();
  2071. }
  2072. //sideBar._sideBarComponent._getStates();
  2073. drawer.open = !drawer.open
  2074. document.querySelector('#sideBar').style.visibility = 'visible';
  2075. },
  2076. $components: [{
  2077. $type: "i",
  2078. class: "material-icons mdc-list-item__start-detail",
  2079. 'aria-hidden': "true",
  2080. $text: "save"
  2081. },
  2082. {
  2083. $text: "Load/Save"
  2084. }]
  2085. }
  2086. ]
  2087. },
  2088. {
  2089. $cell: true,
  2090. $type: "hr",
  2091. class: "mdc-list-divider",
  2092. },
  2093. {
  2094. $cell: true,
  2095. $type: "h3",
  2096. class: "userList mdc-list-group__subheader",
  2097. $text: "Users online"
  2098. },
  2099. clientListCell
  2100. ]
  2101. }
  2102. // {
  2103. // $cell: true,
  2104. // $type: "div",
  2105. // class: "mdc-persistent-drawer__toolbar-spacer",
  2106. // },
  2107. // {
  2108. // $cell: true,
  2109. // $type: "div",
  2110. // class: "mdc-list-group",
  2111. // $components: [{
  2112. // $cell: true,
  2113. // $type: "nav",
  2114. // class: "mdc-list",
  2115. // $components: [
  2116. // ]
  2117. // }]
  2118. // }
  2119. ]
  2120. };
  2121. // <div class="mdc-form-field">
  2122. // <input type="checkbox" id="input">
  2123. // <label for="input">Input Label</label>
  2124. // </div>
  2125. document.querySelector("#drawer").$cell({
  2126. $cell: true,
  2127. $type: "aside",
  2128. class: "mdc-temporary-drawer",
  2129. $components: [drawerCell]
  2130. }
  2131. );
  2132. let toolbar = {
  2133. $cell: true,
  2134. $type: "div",
  2135. class: "mdc-toolbar__row",
  2136. $components: [{
  2137. $type: "section",
  2138. class: "mdc-toolbar__section mdc-toolbar__section--align-start",
  2139. $components: [
  2140. {
  2141. $type: "button",
  2142. class: "demo-menu material-icons mdc-toolbar__icon--menu",
  2143. $text: "menu"
  2144. },
  2145. {
  2146. $type: "span",
  2147. class: "mdc-toolbar__title catalog-title",
  2148. $text: "LiveCoding.space"
  2149. }
  2150. ]
  2151. }]
  2152. };
  2153. document.querySelector("#toolbar").$cell({
  2154. $cell: true,
  2155. $type: "div",
  2156. class: "mdc-toolbar mdc-toolbar--fixed",
  2157. $components: [toolbar]
  2158. }
  2159. );
  2160. // let drawer = new mdc.drawer.MDCTemporaryDrawer(document.querySelector('.mdc-temporary-drawer'));
  2161. // document.querySelector('.menu').addEventListener('click', () => drawer.open = true);
  2162. var drawerEl = document.querySelector('.mdc-temporary-drawer');
  2163. var MDCTemporaryDrawer = mdc.drawer.MDCTemporaryDrawer;
  2164. var drawer = new MDCTemporaryDrawer(drawerEl);
  2165. document.querySelector('.demo-menu').addEventListener('click', function () {
  2166. //self.currentNodeID = (self.currentNodeID == '') ? (vwf_view.kernel.find("", "/")[0]) : self.currentNodeID;
  2167. // let currentNode = document.querySelector('#currentNode')._currentNode;
  2168. // currentNode == '' ? document.querySelector('#currentNode')._setNode(vwf_view.kernel.find("", "/")[0]) :
  2169. // document.querySelector('#currentNode')._setNode(currentNode);
  2170. //document.querySelector('#currentNode')._setNode(self.currentNodeID);
  2171. drawer.open = !drawer.open;
  2172. });
  2173. drawerEl.addEventListener('MDCTemporaryDrawer:open', function () {
  2174. //console.log('Received MDCPersistentDrawer:open');
  2175. });
  2176. drawerEl.addEventListener('MDCTemporaryDrawer:close', function () {
  2177. //console.log('Received MDCPersistentDrawer:close');
  2178. });
  2179. //==============
  2180. },
  2181. createdNode: function (nodeID, childID, childExtendsID, childImplementsIDs,
  2182. childSource, childType, childIndex, childName, callback /* ( ready ) */) {
  2183. var nodeIDAttribute = $.encoder.encodeForHTMLAttribute("id", nodeID, true);
  2184. var childIDAttribute = $.encoder.encodeForHTMLAttribute("id", childID, true);
  2185. var childIDAlpha = $.encoder.encodeForAlphaNumeric(childID);
  2186. var kernel = this.kernel;
  2187. var self = this;
  2188. var parent = this.nodes[nodeID];
  2189. var node = this.nodes[childID] = {
  2190. children: [],
  2191. properties: [],
  2192. events: {},
  2193. methods: {},
  2194. parent: parent,
  2195. parentID: nodeID,
  2196. ID: childID,
  2197. extendsID: childExtendsID,
  2198. implementsIDs: childImplementsIDs,
  2199. source: childSource,
  2200. name: childName,
  2201. };
  2202. if (parent) {
  2203. parent.children.push(node);
  2204. }
  2205. if (childID == vwf_view.kernel.find("", "/")[0] && childExtendsID && this.kernel.test(childExtendsID,
  2206. "self::element(*,'http://vwf.example.com/aframe/ascene.vwf')", childExtendsID)) {
  2207. this.scenes[childID] = node;
  2208. }
  2209. let nodeCell = document.querySelector("#currentNode");
  2210. if (nodeCell !== null) {
  2211. if (nodeCell._currentNode === nodeID) {
  2212. nodeCell._getChildNodes();
  2213. }
  2214. }
  2215. if (nodeID === this.kernel.application()) {
  2216. // document.querySelector('a-scene').classList.add("mdc-toolbar-fixed-adjust");
  2217. document.querySelector('body').classList.add("editor-body");
  2218. }
  2219. },
  2220. createdProperty: function (nodeID, propertyName, propertyValue) {
  2221. return this.initializedProperty(nodeID, propertyName, propertyValue);
  2222. },
  2223. initializedProperty: function (nodeID, propertyName, propertyValue) {
  2224. var node = this.nodes[nodeID];
  2225. if (!node) return; // TODO: patch until full-graph sync is working; drivers should be able to assume that nodeIDs refer to valid objects
  2226. var property = node.properties[propertyName] = createProperty.call(this, node, propertyName, propertyValue);
  2227. node.properties.push(property);
  2228. },
  2229. deletedNode: function (nodeID) {
  2230. var node = this.nodes[nodeID];
  2231. node.parent.children.splice(node.parent.children.indexOf(node), 1);
  2232. delete this.nodes[nodeID];
  2233. let nodeCell = document.querySelector("#currentNode");
  2234. if (nodeCell) {
  2235. if (nodeCell._currentNode !== "") {
  2236. if (nodeCell._currentNode !== nodeID) {
  2237. //&& (this.nodes[nodeID] !== undefined)
  2238. nodeCell._getChildNodes();
  2239. } else {
  2240. nodeCell._setNode(vwf_view.kernel.find("", "/")[0]);
  2241. nodeCell._getChildNodes();
  2242. }
  2243. }
  2244. }
  2245. },
  2246. //addedChild: [ /* nodeID, childID, childName */ ],
  2247. //removedChild: [ /* nodeID, childID */ ],
  2248. satProperty: function (nodeID, propertyName, propertyValue) {
  2249. var node = this.nodes[nodeID];
  2250. if (!node) return; // TODO: patch until full-graph sync is working; drivers should be able to assume that nodeIDs refer to valid objects
  2251. // It is possible for a property to have satProperty called for it without ever getting an
  2252. // initializedProperty (if that property delegated to itself or another on replication)
  2253. // Catch that case here and create the property
  2254. if (!node.properties[propertyName]) {
  2255. var property = node.properties[propertyName] = createProperty.call(this, node, propertyName, propertyValue);
  2256. node.properties.push(property);
  2257. }
  2258. try {
  2259. propertyValue = utility.transform(propertyValue, utility.transforms.transit);
  2260. node.properties[propertyName].value = JSON.stringify(propertyValue);
  2261. node.properties[propertyName].rawValue = propertyValue;
  2262. } catch (e) {
  2263. this.logger.warnx("satProperty", nodeID, propertyName, propertyValue,
  2264. "stringify error:", e.message);
  2265. node.properties[propertyName].value = propertyValue;
  2266. }
  2267. let nodeCell = document.querySelector('#currentNode');
  2268. if (nodeCell !== null) {
  2269. if (nodeCell._currentNode == nodeID && propertyName == 'edit') {
  2270. console.log('EDIT !!!')
  2271. }
  2272. }
  2273. let propCell = document.querySelector("#currentNode #prop-" + propertyName);
  2274. if (propCell !== null) {
  2275. if (propCell._currentNode == nodeID) {
  2276. propCell.value = node.properties[propertyName].getValue();
  2277. }
  2278. }
  2279. },
  2280. //gotProperty: [ /* nodeID, propertyName, propertyValue */ ],
  2281. gotProperty: function (nodeID, propertyName, propertyValue) {
  2282. var node = this.nodes[nodeID];
  2283. if (!node) return; // TODO: patch until full-graph sync is working; drivers should be able to assume that nodeIDs refer to valid objects
  2284. let nodeCell = document.querySelector('#currentNode');
  2285. if (nodeCell !== null) {
  2286. if (nodeCell._currentNode == nodeID && propertyName == 'edit') {
  2287. let editCheckBox = document.querySelector("#currentNode #editnode");
  2288. if (editCheckBox) {
  2289. if (propertyValue) {
  2290. editCheckBox.setAttribute('checked', '');
  2291. } else {
  2292. let checkAttr = editCheckBox.getAttribute('checked');
  2293. if (checkAttr) editCheckBox.removeAttribute('checked');
  2294. }
  2295. }
  2296. console.log('EDIT !!! is ' + propertyValue)
  2297. }
  2298. }
  2299. },
  2300. createdMethod: function (nodeID, methodName, methodParameters, methodBody) {
  2301. var node = this.nodes[nodeID];
  2302. if (node) {
  2303. node.methods[methodName] = methodParameters;
  2304. }
  2305. },
  2306. //calledMethod: function( nodeID, methodName, methodParameters, methodValue ) {
  2307. //},
  2308. createdEvent: function (nodeID, eventName, eventParameters) {
  2309. var node = this.nodes[nodeID];
  2310. if (node) {
  2311. node.events[eventName] = eventParameters;
  2312. }
  2313. },
  2314. firedEvent: function (nodeID, eventName, eventParameters) {
  2315. },
  2316. executed: function (nodeID, scriptText, scriptType) {
  2317. // var nodeScript = {
  2318. // text: scriptText,
  2319. // type: scriptType,
  2320. // };
  2321. // if ( !this.allScripts[ nodeID ] ) {
  2322. // var nodeScripts = new Array();
  2323. // nodeScripts.push(nodeScript);
  2324. // this.allScripts[ nodeID ] = nodeScripts;
  2325. // }
  2326. // else {
  2327. // this.allScripts[ nodeID ].push(nodeScript);
  2328. // }
  2329. },
  2330. //ticked: [ /* time */ ],
  2331. });
  2332. function createCellWindow(elementID, cellNode, title) {
  2333. document.querySelector('#' + elementID).$cell({
  2334. $cell: true,
  2335. $type: "div",
  2336. id: elementID,
  2337. class: 'draggable',
  2338. $init: function () {
  2339. // let draggie = new Draggabilly('.draggable', {
  2340. // handle: '.handle',
  2341. // containment: true
  2342. // });
  2343. // get all draggie elements
  2344. var draggableElems = document.querySelectorAll('.draggable');
  2345. // array of Draggabillies
  2346. var draggies = []
  2347. // init Draggabillies
  2348. for (var i = 0, len = draggableElems.length; i < len; i++) {
  2349. var draggableElem = draggableElems[i];
  2350. var draggie = new Draggabilly(draggableElem, {
  2351. handle: '.handle',
  2352. containment: true
  2353. });
  2354. draggies.push(draggie);
  2355. }
  2356. this.style.visibility = 'hidden';
  2357. },
  2358. $components: [
  2359. {
  2360. $cell: true,
  2361. $type: "div",
  2362. class: "handle",
  2363. $components: [
  2364. {
  2365. $cell: true,
  2366. $type: "button",
  2367. class: "mdc-button mdc-button--compact",
  2368. $text: "X",
  2369. onclick: function (e) {
  2370. //self.currentNodeID = m.ID;
  2371. document.querySelector('#' + elementID).style.visibility = 'hidden';
  2372. }
  2373. },
  2374. {
  2375. $cell: true,
  2376. $type: "span",
  2377. class: "mdc-typography--button",
  2378. $text: title
  2379. }
  2380. ]
  2381. },
  2382. cellNode,
  2383. {
  2384. $cell: true,
  2385. $type: "div",
  2386. class: "handle",
  2387. style: "height: 10px; width: inherit;",
  2388. //$text: "sdfsdf"
  2389. }
  2390. // { $text: "23423"}
  2391. ]
  2392. }
  2393. );
  2394. }
  2395. // -- getChildByName --------------------------------------------------------------------
  2396. function getChildByName(node, childName) {
  2397. var childNode = undefined;
  2398. for (var i = 0; i < node.children.length && childNode === undefined; i++) {
  2399. if (node.children[i].name == childName) {
  2400. childNode = node.children[i];
  2401. }
  2402. }
  2403. return childNode;
  2404. };
  2405. // -- viewScript ------------------------------------------------------------------------
  2406. function createAceEditor(view, nodeID, elID) {
  2407. var editor = view.ace.edit(elID);
  2408. editor.setTheme("ace/theme/monokai");
  2409. editor.setFontSize(16);
  2410. editor.getSession().setMode("ace/mode/javascript");
  2411. editor.commands.addCommand({
  2412. name: "doit",
  2413. bindKey: { win: "Ctrl-e", mac: "Command-e" },
  2414. exec: function () {
  2415. codeEditorDoit(editor, nodeID);
  2416. }
  2417. });
  2418. editor.commands.addCommand({
  2419. name: "printit",
  2420. bindKey: { win: "Ctrl-b", mac: "Command-b" },
  2421. exec: function () {
  2422. codeEditorPrintit(editor, nodeID);
  2423. }
  2424. });
  2425. return editor;
  2426. }
  2427. function getPrototypes(kernel, extendsID) {
  2428. var prototypes = [];
  2429. var id = extendsID;
  2430. while (id !== undefined) {
  2431. prototypes.push(id);
  2432. id = kernel.prototype(id);
  2433. }
  2434. return prototypes;
  2435. }
  2436. function getPrototypes(kernel, extendsID) {
  2437. var prototypes = [];
  2438. var id = extendsID;
  2439. while (id !== undefined) {
  2440. prototypes.push(id);
  2441. id = kernel.prototype(id);
  2442. }
  2443. return prototypes;
  2444. }
  2445. function createProperty(node, propertyName, propertyValue) {
  2446. var property = {
  2447. name: propertyName,
  2448. rawValue: propertyValue,
  2449. value: undefined,
  2450. getValue: function () {
  2451. var propertyValue;
  2452. if (this.value == undefined) {
  2453. try {
  2454. propertyValue = utility.transform(this.rawValue, utility.transforms.transit);
  2455. this.value = JSON.stringify(propertyValue);
  2456. } catch (e) {
  2457. this.logger.warnx("createdProperty", nodeID, this.propertyName, this.rawValue,
  2458. "stringify error:", e.message);
  2459. this.value = this.rawValue;
  2460. }
  2461. }
  2462. return this.value;
  2463. }
  2464. };
  2465. return property;
  2466. }
  2467. function getProperties(kernel, extendsID) {
  2468. var pTypes = getPrototypes(kernel, extendsID);
  2469. var pProperties = {};
  2470. if (pTypes) {
  2471. for (var i = 0; i < pTypes.length; i++) {
  2472. var nd = this.nodes[pTypes[i]];
  2473. if (nd && nd.properties) {
  2474. for (var key in nd.properties) {
  2475. pProperties[key] = { "prop": nd.properties[key], "prototype": pTypes[i] };
  2476. }
  2477. }
  2478. }
  2479. }
  2480. return pProperties;
  2481. }
  2482. function getChildren(kernel, extendsID) {
  2483. var pTypes = getPrototypes(kernel, extendsID);
  2484. var pChildren = {};
  2485. if (pTypes) {
  2486. for (var i = 0; i < pTypes.length; i++) {
  2487. var nd = this.nodes[pTypes[i]];
  2488. if (nd && nd.children) {
  2489. for (var key in nd.children) {
  2490. pChildren[key] = nd.children[key];
  2491. }
  2492. }
  2493. }
  2494. }
  2495. return pChildren;
  2496. }
  2497. function getEvents(kernel, extendsID) {
  2498. var pTypes = getPrototypes(kernel, extendsID);
  2499. var events = {};
  2500. if (pTypes) {
  2501. for (var i = 0; i < pTypes.length; i++) {
  2502. var nd = this.nodes[pTypes[i]];
  2503. if (nd && nd.events) {
  2504. for (var key in nd.events) {
  2505. events[key] = nd.events[key];
  2506. }
  2507. }
  2508. }
  2509. }
  2510. return events;
  2511. }
  2512. function getMethods(kernel, extendsID) {
  2513. var pTypes = getPrototypes(kernel, extendsID);
  2514. var methods = {};
  2515. if (pTypes) {
  2516. for (var i = 0; i < pTypes.length; i++) {
  2517. var nd = this.nodes[pTypes[i]];
  2518. if (nd && nd.methods) {
  2519. for (var key in nd.methods) {
  2520. methods[key] = nd.methods[key];
  2521. }
  2522. }
  2523. }
  2524. }
  2525. return methods;
  2526. }
  2527. // -- Show Code Editor tab
  2528. function codeEditorDoit(editor, nodeID) {
  2529. var selectedText = editor.getSession().doc.getTextRange(editor.selection.getRange());
  2530. if (selectedText == "") {
  2531. var currline = editor.getSelectionRange().start.row;
  2532. var selectedText = editor.session.getLine(currline);
  2533. }
  2534. //console.log(selectedText);
  2535. //var sceneID = self.kernel.application();
  2536. vwf_view.kernel.execute(nodeID, selectedText);
  2537. }
  2538. function codeEditorPrintit(editor, nodeID) {
  2539. var selectedText = editor.getSession().doc.getTextRange(editor.selection.getRange());
  2540. if (selectedText == "") {
  2541. var currline = editor.getSelectionRange().start.row;
  2542. var selectedText = editor.session.getLine(currline);
  2543. }
  2544. //console.log(selectedText);
  2545. //var sceneID = self.kernel.application();
  2546. let scriptText = 'console.log(' + selectedText + ');'
  2547. self.kernel.execute(nodeID, scriptText);
  2548. }
  2549. function saveStateAsFile(filename) // invoke with the view as "this"
  2550. {
  2551. this.logger.info("Saving: " + filename);
  2552. var clients = this.nodes["http://vwf.example.com/clients.vwf"];
  2553. if (supportAjaxUploadWithProgress.call(this)) {
  2554. var xhr = new XMLHttpRequest();
  2555. // Save State Information
  2556. var state = vwf.getState();
  2557. state.nodes[0].children = {};
  2558. var timestamp = state["queue"].time;
  2559. timestamp = Math.round(timestamp * 1000);
  2560. var objectIsTypedArray = function (candidate) {
  2561. var typedArrayTypes = [
  2562. Int8Array,
  2563. Uint8Array,
  2564. // Uint8ClampedArray,
  2565. Int16Array,
  2566. Uint16Array,
  2567. Int32Array,
  2568. Uint32Array,
  2569. Float32Array,
  2570. Float64Array
  2571. ];
  2572. var isTypedArray = false;
  2573. if (typeof candidate == "object" && candidate != null) {
  2574. typedArrayTypes.forEach(function (typedArrayType) {
  2575. isTypedArray = isTypedArray || candidate instanceof typedArrayType;
  2576. });
  2577. }
  2578. return isTypedArray;
  2579. };
  2580. var transitTransformation = function (object) {
  2581. return objectIsTypedArray(object) ?
  2582. Array.prototype.slice.call(object) : object;
  2583. };
  2584. var json = JSON.stringify(
  2585. require("vwf/utility").transform(
  2586. state, transitTransformation
  2587. )
  2588. );
  2589. json = $.encoder.encodeForURL(json);
  2590. var path = window.location.pathname;
  2591. var pathSplit = path.split('/');
  2592. if (pathSplit[0] == "") {
  2593. pathSplit.shift();
  2594. }
  2595. if (pathSplit[pathSplit.length - 1] == "") {
  2596. pathSplit.pop();
  2597. }
  2598. var inst = undefined;
  2599. var instIndex = pathSplit.length - 1;
  2600. if (pathSplit.length > 2) {
  2601. if (pathSplit[pathSplit.length - 2] == "load") {
  2602. instIndex = pathSplit.length - 3;
  2603. }
  2604. }
  2605. if (pathSplit.length > 3) {
  2606. if (pathSplit[pathSplit.length - 3] == "load") {
  2607. instIndex = pathSplit.length - 4;
  2608. }
  2609. }
  2610. inst = pathSplit[instIndex];
  2611. var root = "";
  2612. for (var i = 0; i < instIndex; i++) {
  2613. if (root != "") {
  2614. root = root + "/";
  2615. }
  2616. root = root + pathSplit[i];
  2617. }
  2618. if (filename == '') filename = inst;
  2619. if (root.indexOf('.vwf') != -1) root = root.substring(0, root.lastIndexOf('/'));
  2620. xhr.open("POST", "/" + root + "/save/" + filename, true);
  2621. xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  2622. xhr.send("root=" + root + "/" + filename + "&filename=saveState&inst=" + inst + "&timestamp=" + timestamp + "&extension=.vwf.json" + "&jsonState=" + json);
  2623. // Save Config Information
  2624. var config = { "info": {}, "model": {}, "view": {} };
  2625. // Save browser title
  2626. config["info"]["title"] = document.title//$('title').html();
  2627. // Save model drivers
  2628. Object.keys(vwf_view.kernel.kernel.models).forEach(function (modelDriver) {
  2629. if (modelDriver.indexOf('vwf/model/') != -1) config["model"][modelDriver] = "";
  2630. });
  2631. // If neither glge or threejs model drivers are defined, specify nodriver
  2632. if (config["model"]["vwf/model/glge"] === undefined && config["model"]["vwf/model/threejs"] === undefined) config["model"]["nodriver"] = "";
  2633. // Save view drivers and associated parameters, if any
  2634. Object.keys(vwf_view.kernel.kernel.views).forEach(function (viewDriver) {
  2635. if (viewDriver.indexOf('vwf/view/') != -1) {
  2636. if (vwf_view.kernel.kernel.views[viewDriver].parameters) {
  2637. config["view"][viewDriver] = vwf_view.kernel.kernel.views[viewDriver].parameters;
  2638. }
  2639. else config["view"][viewDriver] = "";
  2640. }
  2641. });
  2642. var jsonConfig = $.encoder.encodeForURL(JSON.stringify(config));
  2643. // Save config file to server
  2644. var xhrConfig = new XMLHttpRequest();
  2645. xhrConfig.open("POST", "/" + root + "/save/" + filename, true);
  2646. xhrConfig.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  2647. xhrConfig.send("root=" + root + "/" + filename + "&filename=saveState&inst=" + inst + "&timestamp=" + timestamp + "&extension=.vwf.config.json" + "&jsonState=" + jsonConfig);
  2648. }
  2649. else {
  2650. console.error("Unable to save state.");
  2651. }
  2652. }
  2653. // -- LoadSavedState --------------------------------------------------------------------------
  2654. function loadSavedState(filename, applicationpath, revision) {
  2655. this.logger.info("Loading: " + filename);
  2656. // Redirect until setState ID conflict is resolved
  2657. var path = window.location.pathname;
  2658. var inst = path.substring(path.length - 17, path.length - 1);
  2659. var pathSplit = path.split('/');
  2660. if (pathSplit[0] == "") {
  2661. pathSplit.shift();
  2662. }
  2663. if (pathSplit[pathSplit.length - 1] == "") {
  2664. pathSplit.pop();
  2665. }
  2666. var inst = undefined;
  2667. var instIndex = pathSplit.length - 1;
  2668. if (pathSplit.length > 2) {
  2669. if (pathSplit[pathSplit.length - 2] == "load") {
  2670. instIndex = pathSplit.length - 3;
  2671. }
  2672. }
  2673. if (pathSplit.length > 3) {
  2674. if (pathSplit[pathSplit.length - 3] == "load") {
  2675. instIndex = pathSplit.length - 4;
  2676. }
  2677. }
  2678. inst = pathSplit[instIndex];
  2679. if (revision) {
  2680. window.location.pathname = applicationpath + "/" + inst + '/load/' + filename + '/' + revision + '/';
  2681. }
  2682. else {
  2683. window.location.pathname = applicationpath + "/" + inst + '/load/' + filename + '/';
  2684. }
  2685. // $.get(filename,function(data,status){
  2686. // vwf.setState(data);
  2687. // });
  2688. }
  2689. // -- SupportAjax -----------------------------------------------------------------------------
  2690. function supportAjaxUploadWithProgress() {
  2691. return supportAjaxUploadProgressEvents();
  2692. function supportAjaxUploadProgressEvents() {
  2693. var xhr = new XMLHttpRequest();
  2694. return !!(xhr && ('upload' in xhr) && ('onprogress' in xhr.upload));
  2695. }
  2696. }
  2697. });