widgets.js 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786
  1. /*
  2. The MIT License (MIT)
  3. Copyright (c) 2014-2018 Nikolai Suslov and the Krestianstvo.org project contributors. (https://github.com/NikolaySuslov/livecodingspace/blob/master/LICENSE.md)
  4. */
  5. /*
  6. * Cell widgets
  7. */
  8. class Widgets {
  9. constructor() {
  10. console.log("widget constructor")
  11. }
  12. get divider() {
  13. return {
  14. $cell: true,
  15. $type: "hr",
  16. class: "mdc-list-divider"
  17. }
  18. }
  19. get emptyDiv() {
  20. return {
  21. $type: "div",
  22. style: "padding-bottom: 30px;"
  23. }
  24. }
  25. get break() {
  26. return {
  27. $type: "br"
  28. }
  29. }
  30. get space() {
  31. return {
  32. $type: "span",
  33. $text: " "
  34. }
  35. }
  36. get p() {
  37. return {
  38. $type: "p"
  39. }
  40. }
  41. inputTextFieldOutlined(obj) {
  42. function initFunc() {
  43. new mdc.textField.MDCTextField.attachTo(this);
  44. }
  45. let inputType = obj.type ? obj.type : 'text';
  46. let init = obj.init ? obj.init : initFunc;
  47. let style = obj.style ? obj.style : "";
  48. let fieldStyle = obj.fieldStyle ? obj.fieldStyle : "";
  49. return {
  50. $cell: true,
  51. $type: "div",
  52. class: "mdc-text-field mdc-text-field--outlined mdc-text-field--dense",
  53. style: style,
  54. $init: init,
  55. $components: [
  56. {
  57. $type: "input",
  58. type: inputType,
  59. id: obj.id,
  60. class: "mdc-text-field__input",
  61. value: obj.value,
  62. onchange: obj.change,
  63. style: obj.fieldStyle
  64. },
  65. {
  66. $type: "span",
  67. class: "mdc-notched-outline",
  68. $components: [
  69. {
  70. $type: "span",
  71. class: "mdc-notched-outline__leading"
  72. },
  73. {
  74. $type: "span",
  75. class: "mdc-notched-outline__notch",
  76. $components: [
  77. {
  78. $type: "span",
  79. class: "mdc-floating-label",
  80. for: obj.id,
  81. $text: obj.label
  82. }
  83. ]
  84. },
  85. {
  86. $type: "span",
  87. class: "mdc-notched-outline__trailing"
  88. }
  89. ]
  90. }
  91. ]
  92. //onclick: obj.onclick
  93. }
  94. }
  95. inputTextFieldStandart(obj) {
  96. var propValue = obj.value;
  97. if (_app.helpers.testJSON(obj.value)) {
  98. propValue = JSON.parse(obj.value);
  99. } else {
  100. propValue = obj.value;
  101. }
  102. return {
  103. $cell: true,
  104. $type: "div",
  105. class: "mdc-text-field mdc-text-field--filled",
  106. _mdc: null,
  107. $init: function () {
  108. //new mdc.mdc.notchedOutline.MDCNotchedOutline(document.querySelector('.mdc-notched-outline'));
  109. this._mdc = new mdc.textField.MDCTextField.attachTo(this);
  110. },
  111. $components: [
  112. {
  113. $type: "span",
  114. class: "mdc-text-field__ripple",
  115. },
  116. {
  117. $type: "input",
  118. type: "text",
  119. id: obj.id,
  120. class: "mdc-text-field__input",
  121. value: propValue,
  122. onchange: obj.change
  123. },
  124. {
  125. $type: "span",
  126. class: "mdc-floating-label",
  127. for: obj.id,
  128. $text: obj.label
  129. },
  130. {
  131. $type: "span",
  132. class: "mdc-line-ripple"
  133. }
  134. ]
  135. //onclick: obj.onclick
  136. }
  137. }
  138. headerH3(headertype, label, cssclass) {
  139. return {
  140. $cell: true,
  141. $type: headertype,
  142. class: cssclass,
  143. $text: label
  144. }
  145. }
  146. simpleCard(obj) {
  147. let style = 'background-image: url(' + obj.imgSrc + '); background-size: cover; background-repeat: no-repeat; height:' + obj.imgHeight + ';';
  148. var addonClass = obj.addonClass;
  149. if (!addonClass) {
  150. addonClass = ''
  151. }
  152. return {
  153. $cell: true,
  154. $type: "div",
  155. $components: [
  156. {
  157. $cell: true,
  158. $type: "div",
  159. class: "mdc-card" + ' ' + addonClass,
  160. onclick: obj.onclickfunc,
  161. $components: [
  162. {
  163. $cell: true,
  164. $type: "section",
  165. class: "mdc-card__media",
  166. style: style
  167. },
  168. {
  169. $cell: true,
  170. $type: "section",
  171. class: "mdc-card__supporting-text",
  172. $text: obj.text
  173. }
  174. ]
  175. }
  176. ]
  177. }
  178. }
  179. listDivider() {
  180. return {
  181. $cell: true,
  182. $type: "hr",
  183. class: "mdc-list-divider mdc-list-divider--inset"
  184. }
  185. }
  186. createListItem(obj) {
  187. return {
  188. $cell: true,
  189. $type: "li",
  190. class: "mdc-list-item",
  191. $components: [
  192. {
  193. $cell: true,
  194. $type: "span",
  195. class: "mdc-list-item__graphic",
  196. $components: [
  197. {
  198. $cell: true,
  199. class: "createItems",
  200. $type: "img",
  201. src: obj.imgSrc,
  202. onclick: obj.onclickfunc
  203. }
  204. ]
  205. },
  206. {
  207. $cell: true,
  208. $type: "span",
  209. class: "mdc-list-item__text",
  210. $text: obj.title
  211. // $components: [
  212. // {
  213. // $text: obj.title
  214. // },
  215. // {
  216. // $cell: true,
  217. // $type: "span",
  218. // class: "mdc-list-item__secondary-text",
  219. // $text: obj.subTitle
  220. // }
  221. // ]
  222. }
  223. ]
  224. }
  225. }
  226. createCard(obj) {
  227. return {
  228. $cell: true,
  229. $type: "div",
  230. $components: [
  231. {
  232. $cell: true,
  233. $type: "div",
  234. class: "mdc-card",
  235. $components: [
  236. {
  237. $cell: true,
  238. $type: "div",
  239. class: "mdc-card__horizontal-block",
  240. $components: [
  241. {
  242. $cell: true,
  243. $type: "section",
  244. class: "mdc-card__primary",
  245. $components: [
  246. {
  247. $cell: true,
  248. $type: "h1",
  249. class: "mdc-card__title mdc-card__title--large",
  250. $text: obj.title
  251. },
  252. {
  253. $cell: true,
  254. $type: "h2",
  255. class: "mdc-card__subtitle",
  256. $text: obj.subTitle
  257. }
  258. ]
  259. },
  260. {
  261. $cell: true,
  262. $type: "img",
  263. class: "",
  264. src: obj.imgSrc
  265. }
  266. ]
  267. },
  268. {
  269. $cell: true,
  270. $type: "section",
  271. class: "mdc-card__actions",
  272. $components: [
  273. {
  274. $cell: true,
  275. $type: "button",
  276. class: "mdc-button mdc-button--compact mdc-card__action",
  277. $text: obj.actionLabel
  278. }
  279. ]
  280. }
  281. ]
  282. }
  283. ]
  284. }
  285. }
  286. buttonStroked(obj) {
  287. let initFun = obj.init ? obj.init : function () { }
  288. return {
  289. $cell: true,
  290. $type: "button",
  291. class: "mdc-button mdc-button--outlined",
  292. $text: obj.label,
  293. onclick: obj.onclick,
  294. $init: initFun
  295. }
  296. }
  297. buttonRaised(obj) {
  298. let initFun = obj.init ? obj.init : function () { }
  299. return {
  300. $cell: true,
  301. $type: "button",
  302. class: "mdc-button mdc-button--raised mdc-ripple-upgraded",
  303. $text: obj.label,
  304. onclick: obj.onclick,
  305. $init: initFun
  306. }
  307. }
  308. buttonSimple(obj) {
  309. return {
  310. $cell: true,
  311. $type: "button",
  312. class: "mdc-button",
  313. $components: [
  314. {
  315. $type: "span",
  316. class: "mdc-button__label",
  317. $text: obj.label
  318. }
  319. ],
  320. onclick: obj.onclick
  321. }
  322. }
  323. sliderDiscrete(obj) {
  324. return {
  325. $cell: true,
  326. $type: "div",
  327. class: "mdc-slider mdc-slider--discrete",
  328. role: "slider",
  329. 'aria-valuemin': obj.min,
  330. 'aria-valuemax': obj.max,
  331. 'aria-label': obj.label,
  332. $init: obj.init,
  333. $components: [
  334. {
  335. $cell: true,
  336. $type: "div",
  337. class: "mdc-slider__track-container",
  338. $components: [
  339. {
  340. $cell: true,
  341. $type: "div",
  342. class: "mdc-slider__track",
  343. }
  344. ]
  345. },
  346. {
  347. $cell: true,
  348. $type: "div",
  349. class: "mdc-slider__thumb-container",
  350. $components: [
  351. {
  352. $cell: true,
  353. $type: "div",
  354. class: "mdc-slider__pin",
  355. $components: [
  356. {
  357. $cell: true,
  358. $type: "span",
  359. class: "mdc-slider__pin-value-marker",
  360. }
  361. ]
  362. },
  363. {
  364. $cell: true,
  365. $type: "svg",
  366. class: "mdc-slider__thumb",
  367. width: 21,
  368. height: 21,
  369. $components: [
  370. {
  371. $cell: true,
  372. $type: "circle",
  373. cx: 10.5,
  374. cy: 10.5,
  375. r: 7.875
  376. }
  377. ]
  378. },
  379. {
  380. $cell: true,
  381. $type: "div",
  382. class: "mdc-slider__focus-ring"
  383. }
  384. ]
  385. }
  386. ]
  387. }
  388. }
  389. sliderContinuous(obj) {
  390. return {
  391. $cell: true,
  392. $type: "div",
  393. 'id': obj.id,
  394. class: "mdc-slider",
  395. //tabindex: 0,
  396. $init: obj.init,
  397. $components: [
  398. {
  399. $cell: true,
  400. $type: "input",
  401. class: "mdc-slider__input",
  402. 'value': obj.value,
  403. 'type': "range",
  404. 'step': obj.step,
  405. 'min': obj.min,
  406. 'max': obj.max,
  407. 'aria-label': obj.label
  408. },
  409. {
  410. // $cell: true,
  411. $type: "div",
  412. class: "mdc-slider__track",
  413. $components: [
  414. {
  415. //$cell: true,
  416. $type: "div",
  417. class: "mdc-slider__track--active",
  418. $components: [
  419. {
  420. //$cell: true,
  421. $type: "div",
  422. class: "mdc-slider__track--active_fill"
  423. }
  424. ]
  425. },
  426. {
  427. //$cell: true,
  428. $type: "div",
  429. class: "mdc-slider__track--inactive"
  430. }
  431. ]
  432. },
  433. {
  434. //$cell: true,
  435. $type: "div",
  436. class: "mdc-slider__thumb",
  437. $components: [
  438. {
  439. //$cell: true,
  440. $type: "div",
  441. class: "mdc-slider__thumb-knob"
  442. }
  443. ]
  444. }
  445. // {
  446. // $cell: true,
  447. // $type: "div",
  448. // class: "mdc-slider__thumb-container",
  449. // $components: [
  450. // {
  451. // $cell: true,
  452. // $type: "svg",
  453. // class: "mdc-slider__thumb",
  454. // width: 21,
  455. // height: 21,
  456. // $components: [
  457. // {
  458. // $cell: true,
  459. // $type: "circle",
  460. // cx: 10.5,
  461. // cy: 10.5,
  462. // r: 7.875
  463. // }
  464. // ]
  465. // },
  466. // {
  467. // $cell: true,
  468. // $type: "div",
  469. // class: "mdc-slider__focus-ring"
  470. // }
  471. // ]
  472. // }
  473. ]
  474. }
  475. }
  476. textField(obj) {
  477. return {
  478. class: "mdc-text-field",
  479. style: "width: 100%",
  480. $cell: true,
  481. $type: "div",
  482. $components: [
  483. {
  484. class: "mdc-text-field__input prop-text-field-input",
  485. id: obj.id,
  486. $cell: true,
  487. $type: "input",
  488. type: "text",
  489. value: obj.value,
  490. onchange: obj.funconchange
  491. }
  492. ]
  493. }
  494. }
  495. icontoggle(obj) {
  496. var addClass = "";
  497. if (obj.styleClass) {
  498. addClass = obj.styleClass;
  499. }
  500. return {
  501. $type: "button",
  502. class: addClass + " mdc-icon-button",
  503. //$text: obj.label,
  504. id: obj.id,
  505. //'data-toggle-on': obj.on,
  506. // 'data-toggle-off': obj.off,
  507. 'aria-pressed': obj.state,
  508. 'aria-hidden': true,
  509. $init: obj.init,
  510. $components: [
  511. {
  512. $type: "i",
  513. class: "material-icons mdc-icon-button__icon mdc-icon-button__icon--on",
  514. $text: JSON.parse(obj.on).content
  515. },
  516. {
  517. $type: "i",
  518. class: "material-icons mdc-icon-button__icon",
  519. $text: JSON.parse(obj.off).content
  520. },
  521. ]
  522. }
  523. }
  524. floatActionButton(obj) {
  525. var addClass = "";
  526. if (obj.styleClass) {
  527. addClass = obj.styleClass;
  528. }
  529. if(obj.tooltip){
  530. obj.init = function(){
  531. let el = document.querySelector('#'+obj.id);
  532. if(el)
  533. tippy('#'+obj.id, {
  534. content: obj.tooltip,
  535. appendTo: document.body,
  536. });
  537. }
  538. } else {
  539. obj.init = function(){}
  540. }
  541. return {
  542. $cell: true,
  543. id: obj.id,
  544. $type: "button",
  545. class: "mdc-fab material-icons " + addClass,
  546. //"aria-describedby": obj.tooltip ? obj.tooltip: null,
  547. onclick: obj.onclickfunc,
  548. $init: obj.init,
  549. $components: [
  550. {
  551. $cell: true,
  552. $type: "span",
  553. class: "mdc-fab__icon",
  554. $text: obj.label
  555. }
  556. ]
  557. }
  558. }
  559. iconButton(obj) {
  560. var addClass = "";
  561. if (obj.styleClass) {
  562. addClass = obj.styleClass;
  563. }
  564. return {
  565. $cell: true,
  566. $type: "button",
  567. class: "mdc-button " + addClass,
  568. onclick: obj.onclick,
  569. $components: [
  570. {
  571. $cell: true,
  572. $type: "i",
  573. class: "material-icons mdc-button__icon",
  574. $text: obj.label
  575. }
  576. ]
  577. }
  578. }
  579. imageButton(obj) {
  580. return {
  581. $cell: true,
  582. $type: "button",
  583. class: "mdc-button mdc-button--compact",
  584. onclick: obj.onclickfunc,
  585. $components: [
  586. {
  587. $cell: true,
  588. class: obj.styleClass,
  589. $type: "img",
  590. src: obj.imgSrc
  591. }
  592. ]
  593. }
  594. }
  595. listTitle(obj) {
  596. return {
  597. $type: "div",
  598. class: "mdc-layout-grid__inner",
  599. $components: [
  600. {
  601. $type: "div",
  602. class: "mdc-layout-grid__cell",
  603. $components: [
  604. {
  605. $type: "h3",
  606. class: "",
  607. $text: obj.text
  608. }
  609. ]
  610. }
  611. ]
  612. }
  613. }
  614. gridListItemWithIco(obj) {
  615. let objID = obj.title.toLowerCase();
  616. let init = function(){
  617. let el = document.querySelector('#'+ objID);
  618. if(el)
  619. tippy('#'+obj.id, {
  620. content: obj.title,
  621. appendTo: document.body,
  622. });
  623. }
  624. return {
  625. $type: "div",
  626. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2 " + obj.styleClass, // tooltip
  627. $components: [
  628. // {
  629. // class: "tooltiptext",
  630. // $type: "span",
  631. // $text: obj.title
  632. // },
  633. // {
  634. // $type: "button",
  635. // class: "mdc-button",
  636. // onclick: obj.onclickfunc,
  637. // $components:[
  638. // {
  639. // $type: "i",
  640. // class: "material-icons mdc-button__icon",
  641. // $text: obj.imgSrc
  642. // }
  643. // ]
  644. // }
  645. {
  646. $type: "div",
  647. style: "background-color: transparent;",
  648. $components: [
  649. {
  650. id: objID,
  651. $init: init,
  652. $type: "i",
  653. class: "material-icons mdc-list-item__graphic",
  654. 'aria-hidden': "true",
  655. $text: obj.imgSrc,
  656. onclick: obj.onclickfunc
  657. }
  658. ]
  659. }
  660. ]
  661. }
  662. }
  663. tooltip(obj){
  664. return {
  665. $cell: true,
  666. id: obj.id,
  667. $type: "div",
  668. class: "mdc-tooltip",
  669. role: "tooltip",
  670. "aria-hidden": true,
  671. $init: function(){
  672. this._tooltip = mdc.tooltip.MDCTooltip(this);
  673. },
  674. $components: [
  675. {
  676. $type: "div",
  677. class: "mdc-tooltip__surface",
  678. $text: obj.text
  679. }
  680. ]
  681. }
  682. // <div id="tooltip-id" class="mdc-tooltip" role="tooltip" aria-hidden="true">
  683. // <div class="mdc-tooltip__surface">
  684. // lorem ipsum dolor
  685. // </div>
  686. // </div>
  687. }
  688. gridListItem(obj) {
  689. let objID = obj.title.toLowerCase().replace(/\s+/g, '');
  690. let init = function(){
  691. let el = document.querySelector('#'+ objID);
  692. if(el)
  693. tippy('#'+objID, {
  694. content: obj.title,
  695. appendTo: document.body,
  696. });
  697. }
  698. return {
  699. $type: "div",
  700. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-2 " + obj.styleClass, // tooltip
  701. $components: [
  702. // {
  703. // class: "tooltiptext",
  704. // $type: "span",
  705. // $text: obj.title
  706. // },
  707. {
  708. $type: "div",
  709. style: "background-color: transparent;",
  710. $components: [
  711. {
  712. $cell: true,
  713. id: objID,
  714. $init: init,
  715. class: "",
  716. $type: "div",
  717. 'aria-label': obj.title,
  718. alt: obj.title,
  719. style: "background-image: url(" + obj.imgSrc + "); background-size: cover; background-repeat: no-repeat; height: " + obj.imgSize + "; width: " + obj.imgSize + ";",
  720. onclick: obj.onclickfunc,
  721. }
  722. ]
  723. }
  724. ]
  725. }
  726. }
  727. switch(obj) {
  728. return {
  729. $cell: true,
  730. $type: "div",
  731. class: "mdc-switch",
  732. _switch: null,
  733. id: obj.id,
  734. //change: obj.onchange,
  735. $init: obj.init,
  736. //function(){
  737. // new mdc.switchControl.MDCSwitch(this);
  738. // },
  739. $components: [
  740. {
  741. $type: "div",
  742. class: "mdc-switch__track",
  743. },
  744. {
  745. $type: "div",
  746. class: "mdc-switch__thumb-underlay",
  747. $components: [
  748. {
  749. $type: "div",
  750. class: "mdc-switch__thumb",
  751. $components: [
  752. {
  753. $type: "input",
  754. "type": "checkbox",
  755. class: "mdc-switch__native-control",
  756. id: 'input-' + obj.id,
  757. //$init: obj.init,
  758. //id: "basic-switch",
  759. "aria-checked": false,
  760. role: "switch"
  761. }
  762. ]
  763. }
  764. ]
  765. }
  766. // {
  767. // $type: "div",
  768. // class: "mdc-switch__background",
  769. // $components: [
  770. // {
  771. // $type: "div",
  772. // class: "mdc-switch__knob"
  773. // }
  774. // ]
  775. // }
  776. ]
  777. }
  778. }
  779. connectionSettingsGUI() {
  780. let connectionSettings = {
  781. id: 'connectionSettings',
  782. $type: 'div',
  783. $components: [
  784. _app.widgets.emptyDiv,
  785. window._app.widgets.buttonRaised(
  786. {
  787. "label": 'Settings',
  788. "onclick": function (e) {
  789. e.preventDefault();
  790. window.location.pathname = '/settings';
  791. }
  792. }), _app.widgets.emptyDiv
  793. ]
  794. }
  795. return connectionSettings
  796. }
  797. debugGUI() {
  798. let self = this;
  799. let debug6DoF = {
  800. $cell: true,
  801. $components: [
  802. {
  803. $type: "p",
  804. class: "mdc-typography--headline5",
  805. $text: "Debug 6DoF mode (for using with WebXR emulator)"
  806. },
  807. {
  808. $type: 'p'
  809. },
  810. _app.widgets.switch({
  811. 'id': 'forceDebug6DoF',
  812. 'init': function () {
  813. let config = localStorage.getItem('lcs_config');
  814. this._switch = new mdc.switchControl.MDCSwitch(this);
  815. this._switch.checked = JSON.parse(config).d6DoF;
  816. this.addEventListener('change',
  817. function (e) {
  818. if (this._switch) {
  819. let chkAttr = this._switch.checked;//this.getAttribute('checked');
  820. if (chkAttr) {
  821. let config = JSON.parse(localStorage.getItem('lcs_config'));
  822. config.d6DoF = true;
  823. localStorage.setItem('lcs_config', JSON.stringify(config));
  824. //this._switch.checked = false;
  825. } else {
  826. let config = JSON.parse(localStorage.getItem('lcs_config'));
  827. config.d6DoF = false;
  828. localStorage.setItem('lcs_config', JSON.stringify(config));
  829. }
  830. }
  831. }
  832. )
  833. // this._replaceSwitch = this._switch;
  834. }
  835. }
  836. ),
  837. {
  838. $type: 'label',
  839. for: 'input-forceDebug6DoF',
  840. $text: 'On / Off'
  841. }
  842. ]
  843. }
  844. let debug3DoF = {
  845. $cell: true,
  846. $components: [
  847. {
  848. $type: "p",
  849. class: "mdc-typography--headline5",
  850. $text: "Debug 3DoF mode (for using with WebXR emulator)"
  851. },
  852. {
  853. $type: 'p'
  854. },
  855. _app.widgets.switch({
  856. 'id': 'forceDebug3DoF',
  857. 'init': function () {
  858. let config = localStorage.getItem('lcs_config');
  859. this._switch = new mdc.switchControl.MDCSwitch(this);
  860. this._switch.checked = JSON.parse(config).d3DoF;
  861. // this._replaceSwitch = this._switch;
  862. this.addEventListener('change',
  863. function (e) {
  864. if (this._switch) {
  865. let chkAttr = this._switch.checked;//this.getAttribute('checked');
  866. if (chkAttr) {
  867. let config = JSON.parse(localStorage.getItem('lcs_config'));
  868. config.d3DoF = true;
  869. localStorage.setItem('lcs_config', JSON.stringify(config));
  870. //this._switch.checked = false;
  871. } else {
  872. let config = JSON.parse(localStorage.getItem('lcs_config'));
  873. config.d3DoF = false;
  874. localStorage.setItem('lcs_config', JSON.stringify(config));
  875. }
  876. }
  877. }
  878. )
  879. }
  880. }
  881. ),
  882. {
  883. $type: 'label',
  884. for: 'input-forceDebug3DoF',
  885. $text: 'On / Off'
  886. }
  887. ]
  888. }
  889. let allGUI =
  890. {
  891. $type: "div",
  892. id: "allGUI",
  893. //style:"background-color: #efefef",
  894. class: "mdc-layout-grid mdc-layout-grid--align-left",
  895. _d3DoF: null,
  896. _d6DoF: null,
  897. _initData: function () {
  898. let config = JSON.parse(localStorage.getItem('lcs_config'));
  899. if (config.d3DoF) {
  900. this._d3DoF = config.d3DoF
  901. }
  902. if (config.d6DoF) {
  903. this._d6DoF = config.d6DoF
  904. }
  905. this._refresh();
  906. },
  907. $init: function () {
  908. this._initData();
  909. },
  910. _refresh: function () {
  911. this.$components = [
  912. {
  913. $type: "div",
  914. class: "mdc-layout-grid__inner",
  915. $components: [
  916. {
  917. $type: "div",
  918. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  919. $components: [
  920. {
  921. $type: "h4",
  922. class: "mdc-typography--headline4",
  923. $text: "Debug settings"
  924. }
  925. ]
  926. },
  927. {
  928. $type: "div",
  929. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  930. $components: [debug6DoF]
  931. },
  932. {
  933. $type: "div",
  934. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  935. $components: [_app.widgets.divider]
  936. },
  937. {
  938. $type: "div",
  939. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  940. $components: [debug3DoF]
  941. },
  942. {
  943. $type: "div",
  944. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  945. $components: [
  946. // window._app.widgets.buttonRaised(
  947. // {
  948. // "label": 'Update',
  949. // "onclick": function (e) {
  950. // e.preventDefault();
  951. // let config = JSON.parse(localStorage.getItem('lcs_config'));
  952. // config.reflector = this._refHostField.value;
  953. // config.dbhost = this._dbHostField.value;
  954. // config.luminaryPath = this._lpathField.value;
  955. // config.luminaryGlobalHBPath = this._hbpathField.value;
  956. // localStorage.setItem('lcs_config', JSON.stringify(config));
  957. // window.location.reload(true);
  958. // }
  959. // }),
  960. {
  961. $type: 'span',
  962. $text: " "
  963. },
  964. {
  965. $type: "button",
  966. class: "mdc-button mdc-button--raised",
  967. $text: "Close",
  968. onclick: function (e) {
  969. window.history.back();
  970. //window.location.pathname = '/'
  971. }
  972. }
  973. ]
  974. }
  975. ]
  976. }
  977. ]
  978. }
  979. }
  980. document.querySelector("#appGUI").$cell({
  981. id: "appGUI",
  982. $cell: true,
  983. $type: "div",
  984. $components: [allGUI]
  985. }
  986. );
  987. }
  988. streamMsgConfig() {
  989. return {
  990. $cell: true,
  991. _streamMsgConfig: null,
  992. $components: [
  993. {
  994. $type: "p",
  995. class: "mdc-typography--headline5",
  996. $text: "Use Stream of Messages"
  997. },
  998. {
  999. $type: 'p'
  1000. },
  1001. _app.widgets.switch({
  1002. 'id': 'streamMsgConfig',
  1003. 'init': function () {
  1004. this._switch = new mdc.switchControl.MDCSwitch(this);
  1005. this._switch.checked = _app.streamMsg;//JSON.parse(config).streamMsg;
  1006. this.addEventListener('change',
  1007. function (e) {
  1008. if (this._switch) {
  1009. let chkAttr = this._switch.checked;//this.getAttribute('checked');
  1010. _app.streamMsg = chkAttr;
  1011. }
  1012. }
  1013. )
  1014. }
  1015. }
  1016. ),
  1017. {
  1018. $type: 'label',
  1019. for: 'input-streamMsgConfig',
  1020. $text: 'On / Off'
  1021. }
  1022. ]
  1023. }
  1024. }
  1025. reflectorGUI() {
  1026. let self = this;
  1027. let webrtcConnection = {
  1028. $cell: true,
  1029. $components: [
  1030. {
  1031. $type: "p",
  1032. class: "mdc-typography--headline5",
  1033. $text: "Use WebRTC for connection"
  1034. },
  1035. {
  1036. $type: 'p'
  1037. },
  1038. _app.widgets.switch({
  1039. 'id': 'forceWebRTC',
  1040. 'init': function () {
  1041. this._switch = new mdc.switchControl.MDCSwitch(this);
  1042. let config = localStorage.getItem('lcs_config');
  1043. this._switch.checked = JSON.parse(config).webrtc;
  1044. // this._replaceSwitch = this._switch;
  1045. this.addEventListener('change',
  1046. function (e) {
  1047. if (this._switch) {
  1048. let chkAttr = this._switch.checked;//this.getAttribute('checked');
  1049. if (chkAttr) {
  1050. let config = JSON.parse(localStorage.getItem('lcs_config'));
  1051. config.webrtc = true;
  1052. localStorage.setItem('lcs_config', JSON.stringify(config));
  1053. //this._switch.checked = false;
  1054. } else {
  1055. let config = JSON.parse(localStorage.getItem('lcs_config'));
  1056. config.webrtc = false;
  1057. localStorage.setItem('lcs_config', JSON.stringify(config));
  1058. }
  1059. }
  1060. }
  1061. )
  1062. },
  1063. 'onchange': ""
  1064. }
  1065. ),
  1066. {
  1067. $type: 'label',
  1068. for: 'input-forceWebRTC',
  1069. $text: 'On / Off'
  1070. }
  1071. ]
  1072. }
  1073. let multiSocket = {
  1074. $cell: true,
  1075. $components: [
  1076. {
  1077. $type: "p",
  1078. class: "mdc-typography--headline5",
  1079. $text: "Use Rooms & Gun DB MultiSocket (no mem)"
  1080. },
  1081. {
  1082. $type: 'p'
  1083. },
  1084. _app.widgets.switch({
  1085. 'id': 'multisocket',
  1086. 'init': function () {
  1087. this._switch = new mdc.switchControl.MDCSwitch(this);
  1088. let config = localStorage.getItem('lcs_config');
  1089. this._switch.checked = JSON.parse(config).multisocket;
  1090. this.addEventListener('change',
  1091. function (e) {
  1092. if (this._switch) {
  1093. let chkAttr = this._switch.checked;//this.getAttribute('checked');
  1094. if (chkAttr) {
  1095. let config = JSON.parse(localStorage.getItem('lcs_config'));
  1096. config.multisocket = true;
  1097. localStorage.setItem('lcs_config', JSON.stringify(config));
  1098. //this._switch.checked = false;
  1099. } else {
  1100. let config = JSON.parse(localStorage.getItem('lcs_config'));
  1101. config.multisocket = false;
  1102. localStorage.setItem('lcs_config', JSON.stringify(config));
  1103. }
  1104. }
  1105. }
  1106. )
  1107. // this._replaceSwitch = this._switch;
  1108. },
  1109. 'onchange': ""
  1110. }
  1111. ),
  1112. {
  1113. $type: 'label',
  1114. for: 'input-multisocket',
  1115. $text: 'On / Off'
  1116. }
  1117. ]
  1118. }
  1119. // let luminaryGlobalHB = {
  1120. // $cell: true,
  1121. // $components: [
  1122. // {
  1123. // $type: "p",
  1124. // class: "mdc-typography--headline5",
  1125. // $text: "Use Global Heartbeat"
  1126. // },
  1127. // {
  1128. // $type: 'p'
  1129. // },
  1130. // _app.widgets.switch({
  1131. // 'id': 'forceLuminary',
  1132. // 'init': function () {
  1133. // this._switch = new mdc.switchControl.MDCSwitch(this);
  1134. // let config = localStorage.getItem('lcs_config');
  1135. // this._switch.checked = JSON.parse(config).luminaryGlobalHB;
  1136. // // this._replaceSwitch = this._switch;
  1137. // },
  1138. // 'onchange': function (e) {
  1139. // if (this._switch) {
  1140. // let chkAttr = this._switch.checked;//this.getAttribute('checked');
  1141. // if (chkAttr) {
  1142. // let config = JSON.parse(localStorage.getItem('lcs_config'));
  1143. // config.luminaryGlobalHB = true;
  1144. // localStorage.setItem('lcs_config', JSON.stringify(config));
  1145. // //this._switch.checked = false;
  1146. // } else {
  1147. // let config = JSON.parse(localStorage.getItem('lcs_config'));
  1148. // config.luminaryGlobalHB = false;
  1149. // localStorage.setItem('lcs_config', JSON.stringify(config));
  1150. // }
  1151. // }
  1152. // }
  1153. // }
  1154. // ),
  1155. // {
  1156. // $type: 'label',
  1157. // for: 'input-forceLuminary',
  1158. // $text: 'On / Off'
  1159. // }
  1160. // ]
  1161. // }
  1162. let luminaryFeature = {
  1163. $type: 'div',
  1164. $components: [
  1165. {
  1166. $type: "p",
  1167. class: "mdc-typography--headline4",
  1168. $text: "Use Krestianstvo Luminary (experimental)"
  1169. },
  1170. {
  1171. $type: 'p'
  1172. },
  1173. _app.widgets.switch({
  1174. 'id': 'forceLuminary',
  1175. 'init': function () {
  1176. this._switch = new mdc.switchControl.MDCSwitch(this);
  1177. let config = localStorage.getItem('lcs_config');
  1178. this._switch.checked = JSON.parse(config).luminary;
  1179. // this._replaceSwitch = this._switch;
  1180. this.addEventListener('change',
  1181. function (e) {
  1182. if (this._switch) {
  1183. let chkAttr = this._switch.checked;//this.getAttribute('checked');
  1184. if (chkAttr) {
  1185. let config = JSON.parse(localStorage.getItem('lcs_config'));
  1186. config.luminary = true;
  1187. localStorage.setItem('lcs_config', JSON.stringify(config));
  1188. window.location.reload(true);
  1189. //this._switch.checked = false;
  1190. } else {
  1191. let config = JSON.parse(localStorage.getItem('lcs_config'));
  1192. config.luminary = false;
  1193. localStorage.setItem('lcs_config', JSON.stringify(config));
  1194. window.location.reload(true);
  1195. }
  1196. }
  1197. }
  1198. )
  1199. },
  1200. 'onchange': ""
  1201. }
  1202. ),
  1203. {
  1204. $type: 'label',
  1205. for: 'input-forceLuminary',
  1206. $text: 'Off / On'
  1207. },
  1208. _app.widgets.p
  1209. ]
  1210. }
  1211. let reflectorGUI =
  1212. {
  1213. $type: "div",
  1214. id: "reflectorGUI",
  1215. //style:"background-color: #efefef",
  1216. class: "mdc-layout-grid mdc-layout-grid--align-left",
  1217. _reflectorHost: null,
  1218. _dbHost: null,
  1219. _refHostField: null,
  1220. _dbHostField: null,
  1221. _lpath: null,
  1222. _lpathField: null,
  1223. _hbpath: null,
  1224. _hbpathField: null,
  1225. //_debug: null,
  1226. _initData: function () {
  1227. this._reflectorHost = '';
  1228. this._dbHost = '';
  1229. let config = JSON.parse(localStorage.getItem('lcs_config'));
  1230. if (config.reflector) {
  1231. this._reflectorHost = config.reflector
  1232. }
  1233. if (config.dbhost) {
  1234. this._dbHost = config.dbhost
  1235. }
  1236. if (config.luminaryPath) {
  1237. this._lpath = config.luminaryPath
  1238. }
  1239. // if (config.luminaryGlobalHBPath) {
  1240. // this._hbpath = config.luminaryGlobalHBPath
  1241. // }
  1242. // if (config.debug) {
  1243. // this._debug = config.debug
  1244. // }
  1245. },
  1246. $init: function () {
  1247. this._initData();
  1248. },
  1249. $update: function () {
  1250. this.$components = [
  1251. {
  1252. $type: "div",
  1253. class: "mdc-layout-grid__inner",
  1254. $components: [
  1255. {
  1256. $type: "div",
  1257. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1258. $components: [
  1259. {
  1260. $type: "h4",
  1261. class: "mdc-typography--headline4",
  1262. $text: "Gun DB settings"
  1263. }
  1264. ]
  1265. },
  1266. {
  1267. $type: "div",
  1268. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1269. $components: [
  1270. {
  1271. $type: "span",
  1272. class: "mdc-typography--headline5",
  1273. $text: "DB Host: "
  1274. },
  1275. window._app.widgets.inputTextFieldOutlined({
  1276. "id": 'dbhostInput',
  1277. "label": "DB Host",
  1278. "value": this._dbHost,
  1279. "type": "text",
  1280. "init": function () {
  1281. this._dbHostField = new mdc.textField.MDCTextField(this);
  1282. },
  1283. "style": 'width: 400px;'
  1284. }),
  1285. ]
  1286. },
  1287. {
  1288. $type: "div",
  1289. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1290. $components: [
  1291. {
  1292. $type: "h4",
  1293. class: "mdc-typography--headline4",
  1294. $text: "Reflector settings"
  1295. }
  1296. ]
  1297. },
  1298. {
  1299. $type: "div",
  1300. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1301. $components: [
  1302. {
  1303. $type: "span",
  1304. class: "mdc-typography--headline5",
  1305. $text: "Reflector: "
  1306. },
  1307. window._app.widgets.inputTextFieldOutlined({
  1308. "id": 'reflectorInput',
  1309. "label": "Reflector",
  1310. "value": this._reflectorHost,
  1311. "type": "text",
  1312. "init": function () {
  1313. this._refHostField = new mdc.textField.MDCTextField(this);
  1314. },
  1315. "style": 'width: 400px;'
  1316. }),
  1317. ]
  1318. },
  1319. {
  1320. $type: "div",
  1321. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1322. $components: [webrtcConnection]
  1323. },
  1324. {
  1325. $type: "div",
  1326. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1327. $components: [_app.widgets.divider]
  1328. },
  1329. // {
  1330. // $type: "div",
  1331. // class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1332. // $components: [
  1333. // {
  1334. // $type: "h4",
  1335. // class: "mdc-typography--headline4",
  1336. // $text: "Krestianstvo Luminary settings (experimental)"
  1337. // }
  1338. // ]
  1339. // },
  1340. {
  1341. $type: "div",
  1342. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1343. $components: [
  1344. luminaryFeature
  1345. ]
  1346. },
  1347. {
  1348. $type: "div",
  1349. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1350. $components: [multiSocket]
  1351. },
  1352. {
  1353. $type: "div",
  1354. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1355. $components: [
  1356. {
  1357. $type: "span",
  1358. class: "mdc-typography--headline5",
  1359. $text: "Multisocket Rooms Host: "
  1360. },
  1361. window._app.widgets.inputTextFieldOutlined({
  1362. "id": 'lpathInput',
  1363. "label": "Multisocket Rooms Host",
  1364. "value": this._lpath,
  1365. "type": "text",
  1366. "init": function () {
  1367. this._lpathField = new mdc.textField.MDCTextField(this);
  1368. },
  1369. "style": 'width: 400px;'
  1370. }),
  1371. ]
  1372. },
  1373. // {
  1374. // $type: "div",
  1375. // class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1376. // $components: [
  1377. // {
  1378. // $type: "span",
  1379. // class: "mdc-typography--headline5",
  1380. // $text: "Global Heartbeat Path: "
  1381. // },
  1382. // window._app.widgets.inputTextFieldOutlined({
  1383. // "id": 'hbpathInput',
  1384. // "label": "Global Heartbeat Path",
  1385. // "value": this._hbpath,
  1386. // "type": "text",
  1387. // "init": function() {
  1388. // this._hbpathField = new mdc.textField.MDCTextField(this);
  1389. // },
  1390. // "style": 'width: 400px;'
  1391. // }),
  1392. // ]
  1393. // },
  1394. // {
  1395. // $type: "div",
  1396. // class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1397. // $components: [luminaryGlobalHB ]
  1398. // },
  1399. {
  1400. $type: "div",
  1401. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1402. $components: [_app.widgets.divider]
  1403. },
  1404. // {
  1405. // $type: "div",
  1406. // class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1407. // $components: [self.streamMsgConfig()]
  1408. // },
  1409. // {
  1410. // $type: "div",
  1411. // class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1412. // $components: [debugGUI]
  1413. // },
  1414. {
  1415. $type: "div",
  1416. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1417. $components: [
  1418. window._app.widgets.buttonRaised(
  1419. {
  1420. "label": 'Update',
  1421. "onclick": function (e) {
  1422. e.preventDefault();
  1423. let config = JSON.parse(localStorage.getItem('lcs_config'));
  1424. config.reflector = this._refHostField.value;
  1425. config.dbhost = this._dbHostField.value;
  1426. config.luminaryPath = this._lpathField.value;
  1427. //config.luminaryGlobalHBPath = this._hbpathField.value;
  1428. localStorage.setItem('lcs_config', JSON.stringify(config));
  1429. window.location.reload(true);
  1430. }
  1431. }),
  1432. {
  1433. $type: 'span',
  1434. $text: " "
  1435. },
  1436. {
  1437. $type: "button",
  1438. class: "mdc-button mdc-button--raised",
  1439. $text: "Close",
  1440. onclick: function (e) {
  1441. window.history.back();
  1442. //window.location.pathname = '/'
  1443. }
  1444. }
  1445. ]
  1446. }
  1447. ]
  1448. }
  1449. ]
  1450. }
  1451. }
  1452. document.querySelector("#appGUI").$cell({
  1453. id: "appGUI",
  1454. $cell: true,
  1455. $type: "div",
  1456. $components: [reflectorGUI]
  1457. }
  1458. );
  1459. }
  1460. getLoginGUI() {
  1461. let loginGUI =
  1462. {
  1463. $type: "div",
  1464. id: "loginGUI",
  1465. //style:"background-color: #efefef",
  1466. class: "mdc-layout-grid mdc-layout-grid--align-left",
  1467. _alias: null,
  1468. _pass: null,
  1469. _passField: null,
  1470. _aliasField: null,
  1471. _initData: function () {
  1472. this._alias = '';
  1473. this._pass = '';
  1474. // if (window.sessionStorage.getItem('alias')) {
  1475. // this._alias = window.sessionStorage.getItem('alias')
  1476. // }
  1477. // if (window.sessionStorage.getItem('tmp')) {
  1478. // this._pass = window.sessionStorage.getItem('tmp')
  1479. // }
  1480. },
  1481. $init: function () {
  1482. this._initData();
  1483. },
  1484. $update: function () {
  1485. this.$components = [
  1486. {
  1487. $type: "div",
  1488. class: "mdc-layout-grid__inner",
  1489. $components: [
  1490. {
  1491. $type: "div",
  1492. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1493. $components: [
  1494. {
  1495. $type: "span",
  1496. class: "mdc-typography--headline5",
  1497. $text: _l.t("login") + ": "
  1498. },
  1499. window._app.widgets.inputTextFieldOutlined({
  1500. "id": 'aliasInput',
  1501. "label": _l.t("login"),
  1502. "value": this._alias,
  1503. "type": "text",
  1504. "init": function () {
  1505. this._aliasField = new mdc.textField.MDCTextField(this);
  1506. }
  1507. }),
  1508. ]
  1509. },
  1510. {
  1511. $type: "div",
  1512. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1513. $components: [
  1514. {
  1515. $type: "span",
  1516. class: "mdc-typography--headline5",
  1517. $text: _l.t("password") + ": "
  1518. },
  1519. window._app.widgets.inputTextFieldOutlined({
  1520. "id": 'passwordInput',
  1521. "label": _l.t("password"),
  1522. "value": this._pass,
  1523. "type": "password",
  1524. "init": function () {
  1525. this._passField = new mdc.textField.MDCTextField(this);
  1526. }
  1527. }),
  1528. ]
  1529. },
  1530. {
  1531. $type: "div",
  1532. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  1533. $components: [
  1534. window._app.widgets.buttonRaised(
  1535. {
  1536. "label": _l.t("sign up"),
  1537. "onclick": function (e) {
  1538. e.preventDefault();
  1539. let alias = this._aliasField.value;
  1540. let pass = this._passField.value
  1541. if (pass.length < 7) {
  1542. new Noty({
  1543. text: "Your passphrase needs to be longer than 7 letters",
  1544. timeout: 2000,
  1545. theme: 'mint',
  1546. layout: 'bottomRight',
  1547. type: 'error'
  1548. }).show();
  1549. } else {
  1550. //
  1551. _LCSDB.user().create(alias, pass,
  1552. function (ack) {
  1553. if (!ack.wait) { }
  1554. if (ack.err) {
  1555. console.log(ack.err)
  1556. return ack.err
  1557. };
  1558. if (ack.pub) {
  1559. let userObj = {
  1560. 'alias': alias,
  1561. 'pub': ack.pub
  1562. };
  1563. _LCSDB.get('users').get(alias).put(userObj);
  1564. }
  1565. _LCSDB.user().auth(alias, pass);
  1566. });
  1567. }
  1568. }
  1569. }),
  1570. _app.widgets.space,
  1571. window._app.widgets.buttonRaised(
  1572. {
  1573. "label": _l.t("sign in"),
  1574. "onclick": function (e) {
  1575. e.preventDefault();
  1576. let alias = this._aliasField.value;
  1577. let pass = this._passField.value
  1578. _app.helpers.authUser(alias, pass);
  1579. // _LCSDB.user().auth.call(_LCSDB, alias, pass
  1580. // // , function(ack) {
  1581. // // if (ack.err) {
  1582. // // new Noty({
  1583. // // text: ack.err,
  1584. // // timeout: 2000,
  1585. // // theme: 'mint',
  1586. // // layout: 'bottomRight',
  1587. // // type: 'error'
  1588. // // }).show();
  1589. // // }
  1590. // //}
  1591. // );
  1592. }
  1593. })
  1594. ]
  1595. }
  1596. ]
  1597. }
  1598. ]
  1599. }
  1600. }
  1601. return loginGUI
  1602. }
  1603. }
  1604. export { Widgets }