widgets.js 29 KB

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