component.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. function init_components_dashboard(input){
  2. var data = $.extend({
  3. column : 8,
  4. line : 8,
  5. onMove : 'dashboard_widget_move',
  6. onRemove : 'dashboard_widget_delete',
  7. onResize : 'dashboard_widget_resize',
  8. onAdd : 'dashboard_widget_add'
  9. },{
  10. column : input.attr('data-column'),
  11. line : input.attr('data-line'),
  12. scope : input.attr('data-scope'),
  13. uid : input.attr('data-uid'),
  14. id : input.attr('data-id'),
  15. });
  16. component = input.data('component');
  17. if(!component){
  18. component = new Dashboard({
  19. element : input,
  20. columnNumber : data.column,
  21. lineNumber : data.line
  22. });
  23. input.data('component',component);
  24. }
  25. if(data.scope){
  26. $.action({
  27. action : 'dashboard_widget_search',
  28. scope : data.scope,
  29. uid : data.uid
  30. },function(response){
  31. component.addWidgets(response.widgets);
  32. });
  33. }
  34. /*component.addWidgets([{
  35. width : 1,
  36. height: 1,
  37. row: 3,
  38. column: 5,
  39. id: 1,
  40. icon : 'far fa-user',
  41. headerBackground : 'rgb(0, 123, 255)',
  42. label : 'Hello monde',
  43. content : '<p>Wazup ?</p>'
  44. },
  45. {
  46. width : 3,
  47. height: 3,
  48. row: 0,
  49. column: 1,
  50. id: 2,
  51. removable : false,
  52. resizeable : false,
  53. draggable : false,
  54. label : 'ByBy',
  55. content : '<p>Wazup 2 ?</p>'
  56. }]);*/
  57. component.on('placeholder-click',function(placeholder){
  58. $.action({
  59. action : data.onAdd,
  60. scope : data.scope,
  61. uid : data.uid,
  62. row : placeholder.row,
  63. column : placeholder.column
  64. },function(widget){
  65. component.addWidgets([widget]);
  66. });
  67. });
  68. component.on('move',function(widget){
  69. console.log('Widget has moved',widget);
  70. $.action({
  71. action : data.onMove,
  72. widget : widget
  73. });
  74. }).on('resize',function(widget){
  75. console.log('Widget has resized',widget);
  76. $.action({
  77. action : data.onResize,
  78. widget : widget
  79. });
  80. }).on('delete',function(widget){
  81. if(!confirm('Êtes-vous sûr de vouloir supprimer cet item?')) return true;
  82. console.log('Widget has removed',widget);
  83. $.action({
  84. action : data.onRemove,
  85. widget : widget
  86. });
  87. });
  88. }