component.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 = $.extend(component.widgets[response.item.id],response.item);
  93. $('#dashboard-configure-menu li').off('click').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).off('change').change(function(){
  126. var form = $('#configure-style-table').toJson();
  127. widget.headerBackground = form['widget-header-background'];
  128. widget.bodyBackground = form['widget-body-background'];
  129. widget.bodyColor= form['widget-body-color'];
  130. widget.iconColor = form['widget-header-icon-color'];
  131. widget.titleColor = form['widget-header-title-color'];
  132. widget.icon = form['widget-header-icon'];
  133. var customiser = $('.dashboard-widget-customizer');
  134. $('.dashboard-widget-header',customiser).css('backgroundColor',widget.headerBackground+'!important');
  135. $('.widget-header-title',customiser).css('color',widget.titleColor+'!important');
  136. $('.dashboard-widget-content',customiser).css({
  137. backgroundColor : widget.bodyBackground+'!important',
  138. color : widget.bodyColor+'!important'
  139. });
  140. $('.widget-header-icon i',customiser).css('color',widget.iconColor+'!important');
  141. $('.widget-header-icon i',customiser).attr('class',widget.icon);
  142. component.widgets[widget.id] = widget;
  143. component.renderContent(widget.id);
  144. $.action({
  145. action : data.onConfigure,
  146. id : widget.id,
  147. headerBackground : widget.headerBackground,
  148. bodyBackground : widget.bodyBackground,
  149. bodyColor : widget.bodyColor,
  150. iconColor : widget.iconColor,
  151. titleColor : widget.titleColor,
  152. icon : widget.icon
  153. });
  154. });
  155. });
  156. init_components('#dashboard-configure-content');
  157. break;
  158. }
  159. });
  160. $('#dashboard-configure-menu li[data-menu="model"]').click();
  161. });
  162. });
  163. }