widgets.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. /*
  2. * Cell widgets
  3. */
  4. class Widgets {
  5. constructor() {
  6. console.log("widget constructor")
  7. }
  8. get divider(){
  9. return {
  10. $cell: true,
  11. $type: "hr",
  12. class: "mdc-list-divider",
  13. }
  14. }
  15. inputTextFieldOutlined(obj){
  16. function initFunc() {
  17. new mdc.textField.MDCTextField.attachTo(this);
  18. }
  19. let inputType = obj.type ? obj.type: 'text';
  20. let init = obj.init ? obj.init: initFunc;
  21. return {
  22. $cell: true,
  23. $type: "div",
  24. class: "mdc-text-field mdc-text-field--outlined mdc-text-field--dense",
  25. $init: init,
  26. $components:[
  27. {
  28. $type: "input",
  29. type: inputType,
  30. id: obj.id,
  31. class: "mdc-text-field__input",
  32. value: obj.value,
  33. onchange: obj.change
  34. },
  35. {
  36. $type: "label",
  37. class: "mdc-floating-label",
  38. for: obj.id,
  39. $text: obj.label
  40. },
  41. {
  42. $type: "div",
  43. class: "mdc-notched-outline",
  44. $components:[
  45. {
  46. $type: "svg",
  47. $components:[
  48. {
  49. $type: "path",
  50. class: "mdc-notched-outline__path"
  51. }
  52. ]
  53. }
  54. ]
  55. },
  56. {
  57. $type: "div",
  58. class: "mdc-notched-outline__idle"
  59. }
  60. ]
  61. //onclick: obj.onclick
  62. }
  63. }
  64. inputTextFieldStandart(obj){
  65. return {
  66. $cell: true,
  67. $type: "div",
  68. class: "mdc-text-field text-field mdc-ripple-upgraded",
  69. $init: function(){
  70. //new mdc.mdc.notchedOutline.MDCNotchedOutline(document.querySelector('.mdc-notched-outline'));
  71. new mdc.textField.MDCTextField.attachTo(this);
  72. },
  73. $components:[
  74. {
  75. $type: "input",
  76. type: "text",
  77. id: obj.id,
  78. class: "mdc-text-field__input",
  79. value: obj.value,
  80. onchange: obj.change
  81. },
  82. {
  83. $type: "label",
  84. class: "mdc-floating-label",
  85. for: obj.id,
  86. $text: obj.label
  87. },
  88. {
  89. $type: "div",
  90. class: "mdc-line-ripple"
  91. }
  92. ]
  93. //onclick: obj.onclick
  94. }
  95. }
  96. headerH3(headertype, label, cssclass) {
  97. return {
  98. $cell: true,
  99. $type: headertype,
  100. class: cssclass,
  101. $text: label
  102. }
  103. }
  104. simpleCard(obj){
  105. let style = 'background-image: url(' + obj.imgSrc + '); background-size: cover; background-repeat: no-repeat; height:' + obj.imgHeight + ';';
  106. var addonClass = obj.addonClass;
  107. if (!addonClass){
  108. addonClass = ''
  109. }
  110. return {
  111. $cell: true,
  112. $type: "div",
  113. $components:[
  114. {
  115. $cell: true,
  116. $type: "div",
  117. class: "mdc-card" +' '+ addonClass,
  118. onclick: obj.onclickfunc,
  119. $components:[
  120. {
  121. $cell: true,
  122. $type: "section",
  123. class: "mdc-card__media",
  124. style: style
  125. },
  126. {
  127. $cell: true,
  128. $type: "section",
  129. class: "mdc-card__supporting-text",
  130. $text: obj.text
  131. }
  132. ]
  133. }
  134. ]
  135. }
  136. }
  137. listDivider() {
  138. return {
  139. $cell: true,
  140. $type: "hr",
  141. class: "mdc-list-divider mdc-list-divider--inset"
  142. }
  143. }
  144. createListItem(obj) {
  145. return {
  146. $cell: true,
  147. $type: "li",
  148. class: "mdc-list-item",
  149. $components: [
  150. {
  151. $cell: true,
  152. $type: "span",
  153. class: "mdc-list-item__graphic",
  154. $components: [
  155. {
  156. $cell: true,
  157. class: "createItems",
  158. $type: "img",
  159. src: obj.imgSrc,
  160. onclick: obj.onclickfunc
  161. }
  162. ]
  163. },
  164. {
  165. $cell: true,
  166. $type: "span",
  167. class: "mdc-list-item__text",
  168. $text: obj.title
  169. // $components: [
  170. // {
  171. // $text: obj.title
  172. // },
  173. // {
  174. // $cell: true,
  175. // $type: "span",
  176. // class: "mdc-list-item__secondary-text",
  177. // $text: obj.subTitle
  178. // }
  179. // ]
  180. }
  181. ]
  182. }
  183. }
  184. createCard(obj){
  185. return {
  186. $cell: true,
  187. $type: "div",
  188. $components:[
  189. {
  190. $cell: true,
  191. $type: "div",
  192. class: "mdc-card",
  193. $components:[
  194. {
  195. $cell: true,
  196. $type: "div",
  197. class: "mdc-card__horizontal-block",
  198. $components:[
  199. {
  200. $cell: true,
  201. $type: "section",
  202. class: "mdc-card__primary",
  203. $components:[
  204. {
  205. $cell: true,
  206. $type: "h1",
  207. class: "mdc-card__title mdc-card__title--large",
  208. $text: obj.title
  209. },
  210. {
  211. $cell: true,
  212. $type: "h2",
  213. class: "mdc-card__subtitle",
  214. $text: obj.subTitle
  215. }
  216. ]
  217. },
  218. {
  219. $cell: true,
  220. $type: "img",
  221. class: "",
  222. src: obj.imgSrc
  223. }
  224. ]
  225. },
  226. {
  227. $cell: true,
  228. $type: "section",
  229. class: "mdc-card__actions",
  230. $components:[
  231. {
  232. $cell: true,
  233. $type: "button",
  234. class: "mdc-button mdc-button--compact mdc-card__action",
  235. $text: obj.actionLabel
  236. }
  237. ]
  238. }
  239. ]
  240. }
  241. ]
  242. }
  243. }
  244. buttonStroked(obj){
  245. return {
  246. $cell: true,
  247. $type: "button",
  248. class: "mdc-button mdc-button--outlined",
  249. $text: obj.label,
  250. onclick: obj.onclick
  251. }
  252. }
  253. buttonRaised(obj){
  254. return {
  255. $cell: true,
  256. $type: "button",
  257. class: "mdc-button mdc-button--raised mdc-ripple-upgraded",
  258. $text: obj.label,
  259. onclick: obj.onclick
  260. }
  261. }
  262. buttonSimple(obj){
  263. return {
  264. $cell: true,
  265. $type: "button",
  266. class: "mdc-button",
  267. $text: obj.label,
  268. onclick: obj.onclick
  269. }
  270. }
  271. sliderDiscrete(obj) {
  272. return {
  273. $cell: true,
  274. $type: "div",
  275. class: "mdc-slider mdc-slider--discrete",
  276. role: "slider",
  277. 'aria-valuemin': obj.min,
  278. 'aria-valuemax': obj.max,
  279. 'aria-label': obj.label,
  280. $init: obj.init,
  281. $components: [
  282. {
  283. $cell: true,
  284. $type: "div",
  285. class: "mdc-slider__track-container",
  286. $components: [
  287. {
  288. $cell: true,
  289. $type: "div",
  290. class: "mdc-slider__track",
  291. }
  292. ]
  293. },
  294. {
  295. $cell: true,
  296. $type: "div",
  297. class: "mdc-slider__thumb-container",
  298. $components: [
  299. {
  300. $cell: true,
  301. $type: "div",
  302. class: "mdc-slider__pin",
  303. $components: [
  304. {
  305. $cell: true,
  306. $type: "span",
  307. class: "mdc-slider__pin-value-marker",
  308. }
  309. ]
  310. },
  311. {
  312. $cell: true,
  313. $type: "svg",
  314. class: "mdc-slider__thumb",
  315. width: 21,
  316. height: 21,
  317. $components: [
  318. {
  319. $cell: true,
  320. $type: "circle",
  321. cx: 10.5,
  322. cy: 10.5,
  323. r: 7.875
  324. }
  325. ]
  326. },
  327. {
  328. $cell: true,
  329. $type: "div",
  330. class: "mdc-slider__focus-ring"
  331. }
  332. ]
  333. }
  334. ]
  335. }
  336. }
  337. sliderContinuous(obj) {
  338. return {
  339. $cell: true,
  340. $type: "div",
  341. class: "mdc-slider",
  342. role: "slider",
  343. tabindex: 0,
  344. 'id': obj.id,
  345. 'aria-valuemin': obj.min,
  346. 'aria-valuemax': obj.max,
  347. 'aria-label': obj.label,
  348. 'aria-valuenow': obj.value,
  349. 'data-step': obj.step,
  350. $init: obj.init,
  351. $components: [
  352. {
  353. $cell: true,
  354. $type: "div",
  355. class: "mdc-slider__track-container",
  356. $components: [
  357. {
  358. $cell: true,
  359. $type: "div",
  360. class: "mdc-slider__track",
  361. }
  362. ]
  363. },
  364. {
  365. $cell: true,
  366. $type: "div",
  367. class: "mdc-slider__thumb-container",
  368. $components: [
  369. {
  370. $cell: true,
  371. $type: "svg",
  372. class: "mdc-slider__thumb",
  373. width: 21,
  374. height: 21,
  375. $components: [
  376. {
  377. $cell: true,
  378. $type: "circle",
  379. cx: 10.5,
  380. cy: 10.5,
  381. r: 7.875
  382. }
  383. ]
  384. },
  385. {
  386. $cell: true,
  387. $type: "div",
  388. class: "mdc-slider__focus-ring"
  389. }
  390. ]
  391. }
  392. ]
  393. }
  394. }
  395. textField(obj) {
  396. return {
  397. class: "mdc-text-field",
  398. style: "width: 100%",
  399. $cell: true,
  400. $type: "div",
  401. $components: [
  402. {
  403. class: "mdc-text-field__input prop-text-field-input",
  404. id: obj.id,
  405. $cell: true,
  406. $type: "input",
  407. type: "text",
  408. value: obj.value,
  409. onchange: obj.funconchange
  410. }
  411. ]
  412. }
  413. }
  414. icontoggle(obj) {
  415. var addClass = "";
  416. if (obj.styleClass){
  417. addClass = obj.styleClass;
  418. }
  419. return {
  420. $type: "i",
  421. class: addClass + " mdc-icon-toggle material-icons",
  422. role: "button",
  423. $text: obj.label,
  424. id: obj.id,
  425. 'data-toggle-on': obj.on,
  426. 'data-toggle-off': obj.off,
  427. 'aria-pressed': obj.state,
  428. 'aria-hidden': true,
  429. $init: obj.init
  430. }
  431. }
  432. floatActionButton(obj) {
  433. var addClass = "";
  434. if (obj.styleClass){
  435. addClass = obj.styleClass;
  436. }
  437. return {
  438. $cell: true,
  439. $type: "button",
  440. class: "mdc-fab material-icons " + addClass,
  441. onclick: obj.onclickfunc,
  442. $components:[
  443. {
  444. $cell: true,
  445. $type: "span",
  446. class: "mdc-fab__icon",
  447. $text: obj.label
  448. }
  449. ]
  450. }
  451. }
  452. iconButton(obj) {
  453. var addClass = "";
  454. if (obj.styleClass){
  455. addClass = obj.styleClass;
  456. }
  457. return {
  458. $cell: true,
  459. $type: "button",
  460. class: "mdc-button" + addClass,
  461. onclick: obj.onclickfunc,
  462. $components:[
  463. {
  464. $cell: true,
  465. $type: "i",
  466. class: "material-icons mdc-button__icon",
  467. $text: obj.label
  468. }
  469. ]
  470. }
  471. }
  472. imageButton(obj){
  473. return {
  474. $cell: true,
  475. $type: "button",
  476. class: "mdc-button mdc-button--compact",
  477. onclick: obj.onclickfunc,
  478. $components:[
  479. {
  480. $cell: true,
  481. class: obj.styleClass,
  482. $type: "img",
  483. src: obj.imgSrc
  484. }
  485. ]
  486. }
  487. }
  488. gridListItem(obj) {
  489. return {
  490. $cell: true,
  491. $type: "li",
  492. class: "mdc-grid-tile " + obj.styleClass,
  493. $components:[
  494. {
  495. $cell: true,
  496. class: "mdc-grid-tile__primary",
  497. $type: "div",
  498. style: "background-color: transparent;",
  499. $components:[
  500. {
  501. $cell: true,
  502. class: "mdc-grid-tile__primary-content tooltip",
  503. $type: "div",
  504. 'aria-label': obj.title,
  505. alt: obj.title,
  506. style: "background-image: url("+ obj.imgSrc + ");",
  507. onclick: obj.onclickfunc,
  508. $components:[
  509. {
  510. $cell: true,
  511. class: "tooltiptext",
  512. $type: "span",
  513. $text: obj.title
  514. }
  515. ]
  516. }
  517. ]
  518. }
  519. ]
  520. }
  521. }
  522. switch(obj) {
  523. return {
  524. $cell: true,
  525. $type: "div",
  526. class: "mdc-switch",
  527. _switch: null,
  528. id: obj.id,
  529. $init: obj.init,
  530. //function(){
  531. // new mdc.switchControl.MDCSwitch(this);
  532. // },
  533. $components: [
  534. {
  535. $type: "div",
  536. class: "mdc-switch__track",
  537. },
  538. {
  539. $type: "div",
  540. class: "mdc-switch__thumb-underlay",
  541. $components:[
  542. {
  543. $type: "div",
  544. class: "mdc-switch__thumb",
  545. $components:[
  546. {
  547. $type: "input",
  548. type: "checkbox",
  549. class: "mdc-switch__native-control",
  550. //$init: obj.init,
  551. //id: "basic-switch",
  552. onchange: obj.onchange,
  553. role: "switch"
  554. }
  555. ]
  556. }
  557. ]
  558. }
  559. // {
  560. // $type: "div",
  561. // class: "mdc-switch__background",
  562. // $components: [
  563. // {
  564. // $type: "div",
  565. // class: "mdc-switch__knob"
  566. // }
  567. // ]
  568. // }
  569. ]
  570. }
  571. }
  572. }
  573. export { Widgets }