main.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //CHARGEMENT DE LA PAGE
  2. function init_plugin_organizational(){
  3. // var datasource = JSON.parse($('#chart-container').attr('data-source'));
  4. $.action({
  5. action : 'organizational_employee_search'
  6. },function(response){
  7. $('#chart-container-number').raiseNumber(0, parseInt(response.count));
  8. var oc = $('#chart-container').orgchart({
  9. data : response.json,
  10. nodeContent: 'title',
  11. pan: true,
  12. zoom: true,
  13. toggleSiblingsResp : false,
  14. // verticalLevel : 10,
  15. nodeTemplate : function(data){
  16. var sstHtml = data.sst? '<i class="fas fa-plus fa-2x icon-sst-bg"></i><i class="fas fa-plus-circle icon-sst"title="Titulaire SST (Services de Santé au Travail)" data-tooltip data-placement="top"></i>': '' ;
  17. return '<div class="title">'+data.name +'</div>'+
  18. '<div class="content media">'+ '<div class="img-container align-self-center">' +
  19. '<img src="'+ data.avatar +'" class="avatar-rounded pr-0">'+
  20. sstHtml + '</div>' +
  21. '<div class="media-body">'+data.title+'</div>'+
  22. '</div>';
  23. },
  24. createNode : function(element,data){
  25. var managerColors = [
  26. '#ff9800',
  27. '#9c27b0',
  28. '#009688',
  29. '#0078d7',
  30. '#192a56',
  31. '#e84118',
  32. '#44bd32',
  33. '#353b48',
  34. '#8c7ae6',
  35. '#718093'
  36. ];
  37. if(data.children && data.children.length > 0){
  38. var color = managerColors[data.level];
  39. $('.title',element).css('background-color',color);
  40. }
  41. $(element).attr('data-service',data.service);
  42. },
  43. initCompleted : function(){
  44. init_tooltips();
  45. $('.orgchart').addClass('noncollapsable');
  46. var panel = $('.organizational-detail-panel');
  47. var tpl = panel.find('.organizational-detail-template').html();
  48. $(document).click(function(){
  49. panel.removeClass('show');
  50. });
  51. panel.click(function(event){
  52. event.stopPropagation();
  53. });
  54. //Ouvertur des détails lors du click sur un employé
  55. $('#chart-container .node').click(function(event){
  56. var data = $(this).data();
  57. data = $.extend(data,data.nodeData);
  58. delete data.nodeData;
  59. panel.find('.organizational-detail').html(Mustache.render(tpl,data));
  60. panel.addClass('show');
  61. event.stopPropagation();
  62. });
  63. //attribution des services sur les tables
  64. $('#chart-container table:eq(0) table').each(function(i,table){
  65. table = $(table);
  66. table.attr('data-service',table.find('.node').eq(0).attr('data-service'));
  67. });
  68. //On groupe toutes les lignes ayant le même service en une seule table
  69. $('#chart-container table:eq(0) table[data-service]').each(function(i,table){
  70. table = $(table);
  71. $('table[data-service="'+table.attr('data-service')+'"]:not(:eq(0)) tr').each(function(i,tr){
  72. if($(tr).parent()==table) return;
  73. $(tr).detach().appendTo(table);
  74. });
  75. });
  76. //Si un service est vide on supprime sa colonne
  77. $('#chart-container table:eq(0) table[data-service]').each(function(i,table){
  78. if($('tr',table).length==0){
  79. var column = $(this).parent();
  80. column.remove();
  81. }
  82. });
  83. //Pour chaque table de service, on ajoute une en-tête avec le libellé du service
  84. $('#chart-container table:eq(0) table').each(function(i,table){
  85. table = $(table);
  86. var service = table.attr('data-service');
  87. if(service == table.parents('table').attr('data-service')) return;
  88. table.addClass('organizational-service');
  89. table.prepend('<caption class="organizational-service-label" >'+service+'</caption>');
  90. });
  91. $('#chart-preloader').remove();
  92. $('.topLine').each(function(){
  93. if($(this).width()<10) $(this).remove();
  94. });
  95. $('.lines').each(function(i, container){
  96. $("td.leftLine:last", container).prev('.leftLine.topLine').remove();
  97. })
  98. }
  99. });
  100. oc.$chartContainer.on('touchmove', function(event) {
  101. event.preventDefault();
  102. });
  103. });
  104. }
  105. //Enregistrement des configurations
  106. function organizational_setting_save(){
  107. $.action({
  108. action: 'organizational_setting_save',
  109. fields: $('#organizational-setting-form').toJson()
  110. },function(r){
  111. $.message('success',r.message);
  112. });
  113. }