widgets.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  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. $text: obj.label,
  275. onclick: obj.onclick
  276. }
  277. }
  278. sliderDiscrete(obj) {
  279. return {
  280. $cell: true,
  281. $type: "div",
  282. class: "mdc-slider mdc-slider--discrete",
  283. role: "slider",
  284. 'aria-valuemin': obj.min,
  285. 'aria-valuemax': obj.max,
  286. 'aria-label': obj.label,
  287. $init: obj.init,
  288. $components: [
  289. {
  290. $cell: true,
  291. $type: "div",
  292. class: "mdc-slider__track-container",
  293. $components: [
  294. {
  295. $cell: true,
  296. $type: "div",
  297. class: "mdc-slider__track",
  298. }
  299. ]
  300. },
  301. {
  302. $cell: true,
  303. $type: "div",
  304. class: "mdc-slider__thumb-container",
  305. $components: [
  306. {
  307. $cell: true,
  308. $type: "div",
  309. class: "mdc-slider__pin",
  310. $components: [
  311. {
  312. $cell: true,
  313. $type: "span",
  314. class: "mdc-slider__pin-value-marker",
  315. }
  316. ]
  317. },
  318. {
  319. $cell: true,
  320. $type: "svg",
  321. class: "mdc-slider__thumb",
  322. width: 21,
  323. height: 21,
  324. $components: [
  325. {
  326. $cell: true,
  327. $type: "circle",
  328. cx: 10.5,
  329. cy: 10.5,
  330. r: 7.875
  331. }
  332. ]
  333. },
  334. {
  335. $cell: true,
  336. $type: "div",
  337. class: "mdc-slider__focus-ring"
  338. }
  339. ]
  340. }
  341. ]
  342. }
  343. }
  344. sliderContinuous(obj) {
  345. return {
  346. $cell: true,
  347. $type: "div",
  348. class: "mdc-slider",
  349. role: "slider",
  350. tabindex: 0,
  351. 'id': obj.id,
  352. 'aria-valuemin': obj.min,
  353. 'aria-valuemax': obj.max,
  354. 'aria-label': obj.label,
  355. 'aria-valuenow': obj.value,
  356. 'data-step': obj.step,
  357. $init: obj.init,
  358. $components: [
  359. {
  360. $cell: true,
  361. $type: "div",
  362. class: "mdc-slider__track-container",
  363. $components: [
  364. {
  365. $cell: true,
  366. $type: "div",
  367. class: "mdc-slider__track",
  368. }
  369. ]
  370. },
  371. {
  372. $cell: true,
  373. $type: "div",
  374. class: "mdc-slider__thumb-container",
  375. $components: [
  376. {
  377. $cell: true,
  378. $type: "svg",
  379. class: "mdc-slider__thumb",
  380. width: 21,
  381. height: 21,
  382. $components: [
  383. {
  384. $cell: true,
  385. $type: "circle",
  386. cx: 10.5,
  387. cy: 10.5,
  388. r: 7.875
  389. }
  390. ]
  391. },
  392. {
  393. $cell: true,
  394. $type: "div",
  395. class: "mdc-slider__focus-ring"
  396. }
  397. ]
  398. }
  399. ]
  400. }
  401. }
  402. textField(obj) {
  403. return {
  404. class: "mdc-text-field",
  405. style: "width: 100%",
  406. $cell: true,
  407. $type: "div",
  408. $components: [
  409. {
  410. class: "mdc-text-field__input prop-text-field-input",
  411. id: obj.id,
  412. $cell: true,
  413. $type: "input",
  414. type: "text",
  415. value: obj.value,
  416. onchange: obj.funconchange
  417. }
  418. ]
  419. }
  420. }
  421. icontoggle(obj) {
  422. var addClass = "";
  423. if (obj.styleClass){
  424. addClass = obj.styleClass;
  425. }
  426. return {
  427. $type: "i",
  428. class: addClass + " mdc-icon-toggle material-icons",
  429. role: "button",
  430. $text: obj.label,
  431. id: obj.id,
  432. 'data-toggle-on': obj.on,
  433. 'data-toggle-off': obj.off,
  434. 'aria-pressed': obj.state,
  435. 'aria-hidden': true,
  436. $init: obj.init
  437. }
  438. }
  439. floatActionButton(obj) {
  440. var addClass = "";
  441. if (obj.styleClass){
  442. addClass = obj.styleClass;
  443. }
  444. return {
  445. $cell: true,
  446. $type: "button",
  447. class: "mdc-fab material-icons " + addClass,
  448. onclick: obj.onclickfunc,
  449. $components:[
  450. {
  451. $cell: true,
  452. $type: "span",
  453. class: "mdc-fab__icon",
  454. $text: obj.label
  455. }
  456. ]
  457. }
  458. }
  459. iconButton(obj) {
  460. var addClass = "";
  461. if (obj.styleClass){
  462. addClass = obj.styleClass;
  463. }
  464. return {
  465. $cell: true,
  466. $type: "button",
  467. class: "mdc-button " + addClass,
  468. onclick: obj.onclick,
  469. $components:[
  470. {
  471. $cell: true,
  472. $type: "i",
  473. class: "material-icons mdc-button__icon",
  474. $text: obj.label
  475. }
  476. ]
  477. }
  478. }
  479. imageButton(obj){
  480. return {
  481. $cell: true,
  482. $type: "button",
  483. class: "mdc-button mdc-button--compact",
  484. onclick: obj.onclickfunc,
  485. $components:[
  486. {
  487. $cell: true,
  488. class: obj.styleClass,
  489. $type: "img",
  490. src: obj.imgSrc
  491. }
  492. ]
  493. }
  494. }
  495. gridListItem(obj) {
  496. return {
  497. $cell: true,
  498. $type: "li",
  499. class: "mdc-grid-tile " + obj.styleClass,
  500. $components:[
  501. {
  502. $cell: true,
  503. class: "mdc-grid-tile__primary",
  504. $type: "div",
  505. style: "background-color: transparent;",
  506. $components:[
  507. {
  508. $cell: true,
  509. class: "mdc-grid-tile__primary-content tooltip",
  510. $type: "div",
  511. 'aria-label': obj.title,
  512. alt: obj.title,
  513. style: "background-image: url("+ obj.imgSrc + ");",
  514. onclick: obj.onclickfunc,
  515. $components:[
  516. {
  517. $cell: true,
  518. class: "tooltiptext",
  519. $type: "span",
  520. $text: obj.title
  521. }
  522. ]
  523. }
  524. ]
  525. }
  526. ]
  527. }
  528. }
  529. switch(obj) {
  530. return {
  531. $cell: true,
  532. $type: "div",
  533. class: "mdc-switch",
  534. _switch: null,
  535. id: obj.id,
  536. $init: obj.init,
  537. //function(){
  538. // new mdc.switchControl.MDCSwitch(this);
  539. // },
  540. $components: [
  541. {
  542. $type: "div",
  543. class: "mdc-switch__track",
  544. },
  545. {
  546. $type: "div",
  547. class: "mdc-switch__thumb-underlay",
  548. $components:[
  549. {
  550. $type: "div",
  551. class: "mdc-switch__thumb",
  552. $components:[
  553. {
  554. $type: "input",
  555. type: "checkbox",
  556. class: "mdc-switch__native-control",
  557. id: 'input-' + obj.id,
  558. //$init: obj.init,
  559. //id: "basic-switch",
  560. onchange: obj.onchange,
  561. role: "switch"
  562. }
  563. ]
  564. }
  565. ]
  566. }
  567. // {
  568. // $type: "div",
  569. // class: "mdc-switch__background",
  570. // $components: [
  571. // {
  572. // $type: "div",
  573. // class: "mdc-switch__knob"
  574. // }
  575. // ]
  576. // }
  577. ]
  578. }
  579. }
  580. reflectorGUI() {
  581. let reflectorGUI =
  582. {
  583. $type: "div",
  584. id: "reflectorGUI",
  585. //style:"background-color: #efefef",
  586. class: "mdc-layout-grid mdc-layout-grid--align-left",
  587. _reflectorHost: null,
  588. _dbHost: null,
  589. _refHostField: null,
  590. _dbHostField: null,
  591. _initData: function () {
  592. this._reflectorHost = '';
  593. this._dbHost = '';
  594. let config = JSON.parse(localStorage.getItem('lcs_config'));
  595. if (config.reflector) {
  596. this._reflectorHost = config.reflector
  597. }
  598. if (config.dbhost) {
  599. this._dbHost =config.dbhost
  600. }
  601. },
  602. $init: function () {
  603. this._initData();
  604. },
  605. $update: function () {
  606. this.$components = [
  607. {
  608. $type: "div",
  609. class: "mdc-layout-grid__inner",
  610. $components: [
  611. {
  612. $type: "div",
  613. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  614. $components: [
  615. {
  616. $type: "h4",
  617. class: "mdc-typography--headline4",
  618. $text: "Connection settings"
  619. }
  620. ]
  621. },
  622. {
  623. $type: "div",
  624. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  625. $components: [
  626. {
  627. $type: "span",
  628. class: "mdc-typography--headline5",
  629. $text: "Reflector: "
  630. },
  631. window._app.widgets.inputTextFieldOutlined({
  632. "id": 'reflectorInput',
  633. "label": "Reflector",
  634. "value": this._reflectorHost,
  635. "type": "text",
  636. "init": function() {
  637. this._refHostField = new mdc.textField.MDCTextField(this);
  638. },
  639. "style": 'width: 400px;'
  640. }),
  641. ]
  642. },
  643. {
  644. $type: "div",
  645. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  646. $components: [
  647. {
  648. $type: "span",
  649. class: "mdc-typography--headline5",
  650. $text: "DB Host: "
  651. },
  652. window._app.widgets.inputTextFieldOutlined({
  653. "id": 'dbhostInput',
  654. "label": "DB Host",
  655. "value": this._dbHost,
  656. "type": "text",
  657. "init": function() {
  658. this._dbHostField = new mdc.textField.MDCTextField(this);
  659. },
  660. "style": 'width: 400px;'
  661. }),
  662. ]
  663. },
  664. {
  665. $type: "div",
  666. class: "mdc-layout-grid__cell mdc-layout-grid__cell--span-12",
  667. $components: [
  668. window._app.widgets.buttonRaised(
  669. {
  670. "label": 'Update',
  671. "onclick": function (e) {
  672. e.preventDefault();
  673. let config = JSON.parse(localStorage.getItem('lcs_config'));
  674. config.reflector = this._refHostField.value;
  675. config.dbhost = this._dbHostField.value;
  676. localStorage.setItem('lcs_config', JSON.stringify(config));
  677. window.location.reload(true);
  678. }
  679. }),
  680. {
  681. $type: 'span',
  682. $text: " "
  683. },
  684. {
  685. $type: "button",
  686. class: "mdc-button mdc-button--raised",
  687. $text: "Close",
  688. onclick: function (e) {
  689. window.location.pathname = '/'
  690. }
  691. }
  692. ]
  693. }
  694. ]
  695. }
  696. ]
  697. }
  698. }
  699. document.querySelector("#appGUI").$cell({
  700. id: "appGUI",
  701. $cell: true,
  702. $type: "div",
  703. $components: [reflectorGUI]
  704. }
  705. );
  706. }
  707. }
  708. export { Widgets }