widgets.js 17 KB

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