component.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. $('.btn-widget-add').click(function(){
  58. $.action({
  59. action : data.onAdd,
  60. scope : data.scope,
  61. uid : data.uid
  62. },function(widget){
  63. component.addWidgets([widget]);
  64. });
  65. });
  66. component.on('move',function(widget){
  67. console.log('Widget has moved',widget);
  68. $.action({
  69. action : data.onMove,
  70. widget : widget
  71. });
  72. }).on('resize',function(widget){
  73. console.log('Widget has resized',widget);
  74. $.action({
  75. action : data.onResize,
  76. widget : widget
  77. });
  78. }).on('delete',function(widget){
  79. console.log('Widget has removed',widget);
  80. $.action({
  81. action : data.onRemove,
  82. widget : widget
  83. });
  84. });
  85. }