widgets.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  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. inputTextFieldOutlined(obj){
  20. function initFunc() {
  21. new mdc.textField.MDCTextField.attachTo(this);
  22. }
  23. let inputType = obj.type ? obj.type: 'text';
  24. let init = obj.init ? obj.init: initFunc;
  25. let style = obj.style ? obj.style: "";
  26. return {
  27. $cell: true,
  28. $type: "div",
  29. class: "mdc-text-field mdc-text-field--outlined mdc-text-field--dense",
  30. style: style,
  31. $init: init,
  32. $components:[
  33. {
  34. $type: "input",
  35. type: inputType,
  36. id: obj.id,
  37. class: "mdc-text-field__input",
  38. value: obj.value,
  39. onchange: obj.change
  40. },
  41. {
  42. $type: "label",
  43. class: "mdc-floating-label",
  44. for: obj.id,
  45. $text: obj.label
  46. },
  47. {
  48. $type: "div",
  49. class: "mdc-notched-outline",
  50. $components:[
  51. {
  52. $type: "svg",
  53. $components:[
  54. {
  55. $type: "path",
  56. class: "mdc-notched-outline__path"
  57. }
  58. ]
  59. }
  60. ]
  61. },
  62. {
  63. $type: "div",
  64. class: "mdc-notched-outline__idle"
  65. }
  66. ]
  67. //onclick: obj.onclick
  68. }
  69. }
  70. inputTextFieldStandart(obj){
  71. return {
  72. $cell: true,
  73. $type: "div",
  74. class: "mdc-text-field text-field mdc-ripple-upgraded",
  75. $init: function(){
  76. //new mdc.mdc.notchedOutline.MDCNotchedOutline(document.querySelector('.mdc-notched-outline'));
  77. new mdc.textField.MDCTextField.attachTo(this);
  78. },
  79. $components:[
  80. {
  81. $type: "input",
  82. type: "text",
  83. id: obj.id,
  84. class: "mdc-text-field__input",
  85. value: obj.value,
  86. onchange: obj.change
  87. },
  88. {
  89. $type: "label",
  90. class: "mdc-floating-label",
  91. for: obj.id,
  92. $text: obj.label
  93. },
  94. {
  95. $type: "div",
  96. class: "mdc-line-ripple"
  97. }
  98. ]
  99. //onclick: obj.onclick
  100. }
  101. }
  102. headerH3(headertype, label, cssclass) {
  103. return {
  104. $cell: true,
  105. $type: headertype,
  106. class: cssclass,
  107. $text: label
  108. }
  109. }
  110. simpleCard(obj){
  111. let style = 'background-image: url(' + obj.imgSrc + '); background-size: cover; background-repeat: no-repeat; height:' + obj.imgHeight + ';';
  112. var addonClass = obj.addonClass;
  113. if (!addonClass){
  114. addonClass = ''
  115. }
  116. return {
  117. $cell: true,
  118. $type: "div",
  119. $components:[
  120. {
  121. $cell: true,
  122. $type: "div",
  123. class: "mdc-card" +' '+ addonClass,
  124. onclick: obj.onclickfunc,
  125. $components:[
  126. {
  127. $cell: true,
  128. $type: "section",
  129. class: "mdc-card__media",
  130. style: style
  131. },
  132. {
  133. $cell: true,
  134. $type: "section",
  135. class: "mdc-card__supporting-text",
  136. $text: obj.text
  137. }
  138. ]
  139. }
  140. ]
  141. }
  142. }
  143. listDivider() {
  144. return {
  145. $cell: true,
  146. $type: "hr",
  147. class: "mdc-list-divider mdc-list-divider--inset"
  148. }
  149. }
  150. createListItem(obj) {
  151. return {
  152. $cell: true,
  153. $type: "li",
  154. class: "mdc-list-item",
  155. $components: [
  156. {
  157. $cell: true,
  158. $type: "span",
  159. class: "mdc-list-item__graphic",
  160. $components: [
  161. {
  162. $cell: true,
  163. class: "createItems",
  164. $type: "img",
  165. src: obj.imgSrc,
  166. onclick: obj.onclickfunc
  167. }
  168. ]
  169. },
  170. {
  171. $cell: true,
  172. $type: "span",
  173. class: "mdc-list-item__text",
  174. $text: obj.title
  175. // $components: [
  176. // {
  177. // $text: obj.title
  178. // },
  179. // {
  180. // $cell: true,
  181. // $type: "span",
  182. // class: "mdc-list-item__secondary-text",
  183. // $text: obj.subTitle
  184. // }
  185. // ]
  186. }
  187. ]
  188. }
  189. }
  190. createCard(obj){
  191. return {
  192. $cell: true,
  193. $type: "div",
  194. $components:[
  195. {
  196. $cell: true,
  197. $type: "div",
  198. class: "mdc-card",
  199. $components:[
  200. {
  201. $cell: true,
  202. $type: "div",
  203. class: "mdc-card__horizontal-block",
  204. $components:[
  205. {
  206. $cell: true,
  207. $type: "section",
  208. class: "mdc-card__primary",
  209. $components:[
  210. {
  211. $cell: true,
  212. $type: "h1",
  213. class: "mdc-card__title mdc-card__title--large",
  214. $text: obj.title
  215. },
  216. {
  217. $cell: true,
  218. $type: "h2",
  219. class: "mdc-card__subtitle",
  220. $text: obj.subTitle
  221. }
  222. ]
  223. },
  224. {
  225. $cell: true,
  226. $type: "img",
  227. class: "",
  228. src: obj.imgSrc
  229. }
  230. ]
  231. },
  232. {
  233. $cell: true,
  234. $type: "section",
  235. class: "mdc-card__actions",
  236. $components:[
  237. {
  238. $cell: true,
  239. $type: "button",
  240. class: "mdc-button mdc-button--compact mdc-card__action",
  241. $text: obj.actionLabel
  242. }
  243. ]
  244. }
  245. ]
  246. }
  247. ]
  248. }
  249. }
  250. buttonStroked(obj){
  251. return {
  252. $cell: true,
  253. $type: "button",
  254. class: "mdc-button mdc-button--outlined",
  255. $text: obj.label,
  256. onclick: obj.onclick
  257. }
  258. }
  259. buttonRaised(obj){
  260. return {
  261. $cell: true,
  262. $type: "button",
  263. class: "mdc-button mdc-button--raised mdc-ripple-upgraded",
  264. $text: obj.label,
  265. onclick: obj.onclick
  266. }
  267. }
  268. buttonSimple(obj){
  269. return {
  270. $cell: true,
  271. $type: "button",
  272. class: "mdc-button",
  273. $text: obj.label,
  274. onclick: obj.onclick
  275. }
  276. }
  277. sliderDiscrete(obj) {
  278. return {
  279. $cell: true,
  280. $type: "div",
  281. class: "mdc-slider mdc-slider--discrete",
  282. role: "slider",
  283. 'aria-valuemin': obj.min,
  284. 'aria-valuemax': obj.max,
  285. 'aria-label': obj.label,
  286. $init: obj.init,
  287. $components: [
  288. {
  289. $cell: true,
  290. $type: "div",
  291. class: "mdc-slider__track-container",
  292. $components: [
  293. {
  294. $cell: true,
  295. $type: "div",
  296. class: "mdc-slider__track",
  297. }
  298. ]
  299. },
  300. {
  301. $cell: true,
  302. $type: "div",
  303. class: "mdc-slider__thumb-container",
  304. $components: [
  305. {
  306. $cell: true,
  307. $type: "div",
  308. class: "mdc-slider__pin",
  309. $components: [
  310. {
  311. $cell: true,
  312. $type: "span",
  313. class: "mdc-slider__pin-value-marker",
  314. }
  315. ]
  316. },
  317. {
  318. $cell: true,
  319. $type: "svg",
  320. class: "mdc-slider__thumb",
  321. width: 21,
  322. height: 21,
  323. $components: [
  324. {
  325. $cell: true,
  326. $type: "circle",
  327. cx: 10.5,
  328. cy: 10.5,
  329. r: 7.875
  330. }
  331. ]
  332. },
  333. {
  334. $cell: true,
  335. $type: "div",
  336. class: "mdc-slider__focus-ring"
  337. }
  338. ]
  339. }
  340. ]
  341. }
  342. }
  343. sliderContinuous(obj) {
  344. return {
  345. $cell: true,
  346. $type: "div",
  347. class: "mdc-slider",
  348. role: "slider",
  349. tabindex: 0,
  350. 'id': obj.id,
  351. 'aria-valuemin': obj.min,
  352. 'aria-valuemax': obj.max,
  353. 'aria-label': obj.label,
  354. 'aria-valuenow': obj.value,
  355. 'data-step': obj.step,
  356. $init: obj.init,
  357. $components: [
  358. {
  359. $cell: true,
  360. $type: "div",
  361. class: "mdc-slider__track-container",
  362. $components: [
  363. {
  364. $cell: true,
  365. $type: "div",
  366. class: "mdc-slider__track",
  367. }
  368. ]
  369. },
  370. {
  371. $cell: true,
  372. $type: "div",
  373. class: "mdc-slider__thumb-container",
  374. $components: [
  375. {
  376. $cell: true,
  377. $type: "svg",
  378. class: "mdc-slider__thumb",
  379. width: 21,
  380. height: 21,
  381. $components: [
  382. {
  383. $cell: true,
  384. $type: "circle",
  385. cx: 10.5,
  386. cy: 10.5,
  387. r: 7.875
  388. }
  389. ]
  390. },
  391. {
  392. $cell: true,
  393. $type: "div",
  394. class: "mdc-slider__focus-ring"
  395. }
  396. ]
  397. }
  398. ]
  399. }
  400. }
  401. textField(obj) {
  402. return {
  403. class: "mdc-text-field",
  404. style: "width: 100%",
  405. $cell: true,
  406. $type: "div",
  407. $components: [
  408. {
  409. class: "mdc-text-field__input prop-text-field-input",
  410. id: obj.id,
  411. $cell: true,
  412. $type: "input",
  413. type: "text",
  414. value: obj.value,
  415. onchange: obj.funconchange
  416. }
  417. ]
  418. }
  419. }
  420. icontoggle(obj) {
  421. var addClass = "";
  422. if (obj.styleClass){
  423. addClass = obj.styleClass;
  424. }
  425. return {
  426. $type: "i",
  427. class: addClass + " mdc-icon-toggle material-icons",
  428. role: "button",
  429. $text: obj.label,
  430. id: obj.id,
  431. 'data-toggle-on': obj.on,
  432. 'data-toggle-off': obj.off,
  433. 'aria-pressed': obj.state,
  434. 'aria-hidden': true,
  435. $init: obj.init
  436. }
  437. }
  438. floatActionButton(obj) {
  439. var addClass = "";
  440. if (obj.styleClass){
  441. addClass = obj.styleClass;
  442. }
  443. return {
  444. $cell: true,
  445. $type: "button",
  446. class: "mdc-fab material-icons " + addClass,
  447. onclick: obj.onclickfunc,
  448. $components:[
  449. {
  450. $cell: true,
  451. $type: "span",
  452. class: "mdc-fab__icon",
  453. $text: obj.label
  454. }
  455. ]
  456. }
  457. }
  458. iconButton(obj) {
  459. var addClass = "";
  460. if (obj.styleClass){
  461. addClass = obj.styleClass;
  462. }
  463. return {
  464. $cell: true,
  465. $type: "button",
  466. class: "mdc-button" + addClass,
  467. onclick: obj.onclickfunc,
  468. $components:[
  469. {
  470. $cell: true,
  471. $type: "i",
  472. class: "material-icons mdc-button__icon",
  473. $text: obj.label
  474. }
  475. ]
  476. }
  477. }
  478. imageButton(obj){
  479. return {
  480. $cell: true,
  481. $type: "button",
  482. class: "mdc-button mdc-button--compact",
  483. onclick: obj.onclickfunc,
  484. $components:[
  485. {
  486. $cell: true,
  487. class: obj.styleClass,
  488. $type: "img",
  489. src: obj.imgSrc
  490. }
  491. ]
  492. }
  493. }
  494. gridListItem(obj) {
  495. return {
  496. $cell: true,
  497. $type: "li",
  498. class: "mdc-grid-tile " + obj.styleClass,
  499. $components:[
  500. {
  501. $cell: true,
  502. class: "mdc-grid-tile__primary",
  503. $type: "div",
  504. style: "background-color: transparent;",
  505. $components:[
  506. {
  507. $cell: true,
  508. class: "mdc-grid-tile__primary-content tooltip",
  509. $type: "div",
  510. 'aria-label': obj.title,
  511. alt: obj.title,
  512. style: "background-image: url("+ obj.imgSrc + ");",
  513. onclick: obj.onclickfunc,
  514. $components:[
  515. {
  516. $cell: true,
  517. class: "tooltiptext",
  518. $type: "span",
  519. $text: obj.title
  520. }
  521. ]
  522. }
  523. ]
  524. }
  525. ]
  526. }
  527. }
  528. switch(obj) {
  529. return {
  530. $cell: true,
  531. $type: "div",
  532. class: "mdc-switch",
  533. _switch: null,
  534. id: obj.id,
  535. $init: obj.init,
  536. //function(){
  537. // new mdc.switchControl.MDCSwitch(this);
  538. // },
  539. $components: [
  540. {
  541. $type: "div",
  542. class: "mdc-switch__track",
  543. },
  544. {
  545. $type: "div",
  546. class: "mdc-switch__thumb-underlay",
  547. $components:[
  548. {
  549. $type: "div",
  550. class: "mdc-switch__thumb",
  551. $components:[
  552. {
  553. $type: "input",
  554. type: "checkbox",
  555. class: "mdc-switch__native-control",
  556. id: 'input-' + obj.id,
  557. //$init: obj.init,
  558. //id: "basic-switch",
  559. onchange: obj.onchange,
  560. role: "switch"
  561. }
  562. ]
  563. }
  564. ]
  565. }
  566. // {
  567. // $type: "div",
  568. // class: "mdc-switch__background",
  569. // $components: [
  570. // {
  571. // $type: "div",
  572. // class: "mdc-switch__knob"
  573. // }
  574. // ]
  575. // }
  576. ]
  577. }
  578. }
  579. reflectorGUI() {
  580. let reflectorGUI =
  581. {
  582. $type: "div",
  583. id: "reflectorGUI",
  584. //style:"background-color: #efefef",
  585. class: "mdc-layout-grid mdc-layout-grid--align-left",
  586. _reflectorHost: null,
  587. _dbHost: null,
  588. _refHostField: null,
  589. _dbHostField: null,
  590. _initData: function () {
  591. this._reflectorHost = '';
  592. this._dbHost = '';
  593. let config = JSON.parse(localStorage.getItem('lcs_config'));
  594. if (config.reflector) {
  595. this._reflectorHost = config.reflector
  596. }
  597. if (config.dbhost) {
  598. this._dbHost =config.dbhost
  599. }
  600. },
  601. $init: function () {
  602. this._initData();
  603. },
  604. $update: function () {
  605. this.$components = [
  606. {
  607. $type: "div",
  608. class: "mdc-layout-grid__inner",
  609. $components: [
  610. {
  611. $type: "div",
  612. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  613. $components: [
  614. {
  615. $type: "h4",
  616. class: "mdc-typography--headline4",
  617. $text: "Connection settings"
  618. }
  619. ]
  620. },
  621. {
  622. $type: "div",
  623. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  624. $components: [
  625. {
  626. $type: "span",
  627. class: "mdc-typography--headline5",
  628. $text: "Reflector: "
  629. },
  630. window._app.widgets.inputTextFieldOutlined({
  631. "id": 'reflectorInput',
  632. "label": "Reflector",
  633. "value": this._reflectorHost,
  634. "type": "text",
  635. "init": function() {
  636. this._refHostField = new mdc.textField.MDCTextField(this);
  637. },
  638. "style": 'width: 400px;'
  639. }),
  640. ]
  641. },
  642. {
  643. $type: "div",
  644. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  645. $components: [
  646. {
  647. $type: "span",
  648. class: "mdc-typography--headline5",
  649. $text: "DB Host: "
  650. },
  651. window._app.widgets.inputTextFieldOutlined({
  652. "id": 'dbhostInput',
  653. "label": "DB Host",
  654. "value": this._dbHost,
  655. "type": "text",
  656. "init": function() {
  657. this._dbHostField = new mdc.textField.MDCTextField(this);
  658. },
  659. "style": 'width: 400px;'
  660. }),
  661. ]
  662. },
  663. {
  664. $type: "div",
  665. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  666. $components: [
  667. window._app.widgets.buttonRaised(
  668. {
  669. "label": 'Update',
  670. "onclick": function (e) {
  671. e.preventDefault();
  672. let config = JSON.parse(localStorage.getItem('lcs_config'));
  673. config.reflector = this._refHostField.value;
  674. config.dbhost = this._dbHostField.value;
  675. localStorage.setItem('lcs_config', JSON.stringify(config));
  676. window.location.reload(true);
  677. }
  678. }),
  679. {
  680. $type: 'span',
  681. $text: " "
  682. },
  683. {
  684. $type: "button",
  685. class: "mdc-button mdc-button--raised",
  686. $text: "Close",
  687. onclick: function (e) {
  688. window.location.pathname = '/'
  689. }
  690. }
  691. ]
  692. }
  693. ]
  694. }
  695. ]
  696. }
  697. }
  698. document.querySelector("#appGUI").$cell({
  699. id: "appGUI",
  700. $cell: true,
  701. $type: "div",
  702. $components: [reflectorGUI]
  703. }
  704. );
  705. }
  706. }
  707. export { Widgets }