component.js 2.8 KB

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