Advertisement
KoctrX

Untitled

Jul 13th, 2021
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. editor.DomComponents.addType('table_clone', {
  2. model: tableType.model.extend({
  3. defaults: {
  4. ...tableType.model.prototype.defaults,
  5. },
  6.  
  7. init() {
  8. this.renderTable(this.get('payload'));
  9. },
  10.  
  11. renderTable(payload = false) {
  12. //console.log('QQ: ', payload);
  13. const start = new Date().getTime();
  14. if (!payload) payload = this.get('payload');
  15. const components = [];
  16.  
  17. for (const data of payload.data) {
  18. const column = {
  19. tagName: 'tr',
  20. draggable: false,
  21. removable: false,
  22. copyable: false,
  23. selectable: false,
  24. components: []
  25. };
  26.  
  27. for (const item of data) {
  28. column.components.push({
  29. tagName: 'td',
  30. type: 'text',
  31. content: utils.replaceTextVariables(item.text),
  32. attributes: { column_id: item.id },
  33. style: {
  34. 'padding-left': '3px',
  35. 'padding-right': '3px',
  36. 'padding-top': '3px',
  37. 'padding-bottom': '3px',
  38. 'border-style': 'solid',
  39. 'border-color': 'black',
  40. 'border-width': '1px',
  41. ...(item.style ? item.style : {})
  42. },
  43. draggable: false,
  44. removable: false,
  45. copyable: false,
  46. editable: true,
  47. resizable: true
  48. });
  49. }
  50.  
  51. components.push(column);
  52. }
  53.  
  54. //console.log('Press F: ', JSON.parse(JSON.stringify(components)));
  55.  
  56. //this.set('components', components);
  57. // console.log('RENDER: ', Date.now() - start);
  58. // // return;
  59. //this.components().set(components);
  60.  
  61. window.lastComps = components;
  62.  
  63. //this.component().replaceWith(components);
  64. //this.component().add(components);
  65. this.set({ components, payload: { ...payload, date: Date.now() }});
  66. }
  67. }, {
  68. isComponent: el => {
  69. if (el.getAttribute &&
  70. el.getAttribute('data-gjs-type') == 'table_clone') {
  71. return { type: 'table_clone' };
  72. }
  73. },
  74. }),
  75.  
  76. view: tableType.view
  77. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement