component.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. }).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 ce widget?')) return true;
  82. console.log('Widget has removed', widget);
  83. $.action({
  84. action : data.onRemove,
  85. widget : widget
  86. });
  87. }).on('configure',function(id){
  88. $.action({
  89. action : 'dashboard_widget_by_id',
  90. id : id
  91. },function(response){
  92. var widget = response.item;
  93. $('#dashboard-configure-menu li').off().click(function(){
  94. var li = $(this);
  95. var menu = li.attr('data-menu');
  96. li.addClass('active').parent().find('>li').removeClass('active');
  97. switch(menu){
  98. case "model":
  99. $('#dashboard-configure-content').html($('#configure-model').html());
  100. init_components('#dashboard-configure-content');
  101. var modelList = $('#widget-models');
  102. modelList.fill({
  103. action : 'dashboard_model_search',
  104. },function(response){
  105. $('li',modelList).removeClass('active');
  106. $('li[data-model="'+widget.model+'"]',modelList).addClass('active');
  107. $('li',modelList).click(function(){
  108. $('#widget-models li').removeClass('active');
  109. $(this).addClass('active');
  110. $.action({
  111. action : data.onConfigure,
  112. id : widget.id,
  113. model : $(this).attr('data-model')
  114. },function(response){
  115. });
  116. });
  117. });
  118. break;
  119. case "style":
  120. $('#dashboard-configure-content').html($('#configure-style').html());
  121. $.action({
  122. action : 'dashboard_widget_by_id',
  123. id : widget.id
  124. },function(response){
  125. $('#configure-style-table').fromJson(response.item).change(function(){
  126. var widgetData = {action:data.onConfigure};
  127. widgetData.id = widget.id;
  128. var form = $('#configure-style-table').toJson();
  129. widgetData.headerBackground = form['widget-header-background'];
  130. widgetData.bodyBackground = form['widget-body-background'];
  131. widgetData.bodyColor= form['widget-body-color'];
  132. widgetData.iconColor = form['widget-header-icon-color'];
  133. widgetData.titleColor = form['widget-header-title-color'];
  134. widgetData.icon = form['widget-header-icon'];
  135. var customiser = $('.dashboard-widget-customizer');
  136. $('.dashboard-widget-header',customiser).css('backgroundColor',widgetData.headerBackground+'!important');
  137. $('.widget-header-title',customiser).css('color',widgetData.titleColor+'!important');
  138. $('.dashboard-widget-content',customiser).css({
  139. backgroundColor : widgetData.bodyBackground+'!important',
  140. color : widgetData.bodyColor+'!important'
  141. });
  142. $('.widget-header-icon i',customiser).css('color',widgetData.iconColor+'!important');
  143. $('.widget-header-icon i',customiser).attr('class',widgetData.icon);
  144. component.renderContent(widget.id);
  145. $.action(widgetData);
  146. });
  147. });
  148. init_components('#dashboard-configure-content');
  149. break;
  150. }
  151. });
  152. $('#dashboard-configure-menu li[data-menu="model"]').click();
  153. });
  154. });
  155. }