component.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. onConfigure: 'dashboard_widget_configure',
  9. onAdd: 'dashboard_widget_add'
  10. },{
  11. column: input.attr('data-column'),
  12. line: input.attr('data-line'),
  13. scope: input.attr('data-scope'),
  14. uid: input.attr('data-uid'),
  15. id: input.attr('data-id'),
  16. });
  17. component = input.data('component');
  18. if(!component){
  19. component = new Dashboard({
  20. element : input,
  21. columnNumber : data.column,
  22. lineNumber : data.line
  23. });
  24. input.data('component',component);
  25. }
  26. if(data.scope){
  27. $.action({
  28. action: 'dashboard_widget_search',
  29. scope: data.scope,
  30. uid: data.uid
  31. },function(response){
  32. component.addWidgets(response.widgets);
  33. });
  34. }
  35. /*component.addWidgets([{
  36. width : 1,
  37. height: 1,
  38. row: 3,
  39. column: 5,
  40. id: 1,
  41. icon : 'far fa-user',
  42. headerBackground : 'rgb(0, 123, 255)',
  43. label : 'Hello monde',
  44. content : '<p>Wazup ?</p>'
  45. },
  46. {
  47. width : 3,
  48. height: 3,
  49. row: 0,
  50. column: 1,
  51. id: 2,
  52. removable : false,
  53. resizeable : false,
  54. draggable : false,
  55. label : 'ByBy',
  56. content : '<p>Wazup 2 ?</p>'
  57. }]);*/
  58. component.on('placeholder-click',function(placeholder){
  59. $.action({
  60. action : data.onAdd,
  61. scope : data.scope,
  62. uid : data.uid,
  63. row : placeholder.row,
  64. column : placeholder.column
  65. },function(widget){
  66. component.addWidgets([widget]);
  67. });
  68. });
  69. component.on('move',function(widget){
  70. console.log('Widget has moved', widget);
  71. $.action({
  72. action : data.onMove,
  73. widget : widget
  74. });
  75. }).on('resize',function(widget){
  76. console.log('Widget has resized', widget);
  77. $.action({
  78. action: data.onResize,
  79. widget: widget
  80. });
  81. }).on('delete',function(widget){
  82. if(!confirm('Êtes-vous sûr de vouloir supprimer ce widget?')) return true;
  83. console.log('Widget has removed', widget);
  84. $.action({
  85. action : data.onRemove,
  86. widget : widget
  87. });
  88. }).on('configure',function(id){
  89. $('#dashboard-configure-menu li').click(function(){
  90. var li = $(this);
  91. var menu = li.attr('data-menu');
  92. li.parent().find('>li').removeClass('active');
  93. li.addClass('active');
  94. $('#widget-types').fill({
  95. action : data.onConfigure,
  96. id : id,
  97. menu : menu
  98. },function(response){
  99. });
  100. });
  101. });
  102. }