main.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. //CHARGEMENT DE LA PAGE
  2. function init_plugin_employee(){
  3. switch($.urlParam('page')){
  4. case 'sheet.employee':
  5. employee_employee_contract_search();
  6. break;
  7. default:
  8. break;
  9. }
  10. $('#employees').sortable_table({
  11. onSort : employee_search
  12. });
  13. }
  14. function init_setting_global_employee(){
  15. employee_employee_work_time_search()
  16. }
  17. //Enregistrement des configurations
  18. function employee_setting_save(){
  19. $.action({
  20. action: 'employee_setting_save',
  21. fields: $('#employee-setting-form').toJson()
  22. },function(){
  23. $.message('success','Enregistré');
  24. });
  25. }
  26. /** FICHE EMPLOYé **/
  27. //Récuperation d'une liste fiche employé dans le tableau #employees
  28. function employee_search(callback,exportMode){
  29. var box = new FilterBox('#filters');
  30. if(exportMode) $('.btn-export').addClass('btn-preloader');
  31. $('#employees').fill({
  32. action:'employee_search',
  33. filters: box.filters(),
  34. sort: $('#employees').sortable_table('get'),
  35. export: !exportMode ? false : exportMode
  36. },function(response){
  37. $('.results-count span').text(response.pagination.total);
  38. if(callback!=null) callback();
  39. });
  40. }
  41. //Ajout ou modification fiche employé
  42. function employee_save(callback,noMessage){
  43. var data = $('#employee-form').toJson();
  44. data.hardware = [];
  45. $('.btn-save').addClass('btn-preloader');
  46. $('.hardware:checked').each(function(){
  47. data.hardware.push($(this).attr('data-id'));
  48. });
  49. $.action(data,function(r){
  50. $('#employee-form').attr('data-id',r.id);
  51. $.urlParam('id',r.id);
  52. if(noMessage===false || !noMessage) $.message('success','Enregistré');
  53. if(callback) callback();
  54. });
  55. }
  56. //Suppression fiche employé
  57. function employee_delete(element){
  58. if(!confirm('Êtes vous sûr de vouloir supprimer cet item ?')) return;
  59. var line = $(element).closest('.item-line');
  60. $.action({
  61. action: 'employee_delete',
  62. id: line.attr('data-id')
  63. },function(r){
  64. line.remove();
  65. $.message('info','Item supprimé');
  66. });
  67. }
  68. /** TEMPS DE TRAVAIL EMPLOYé **/
  69. //Récuperation d'une liste temps de travail employé dans le tableau #employeeworktimes
  70. function employee_employee_work_time_search(callback){
  71. $('#employee-work-times').fill({
  72. action:'employee_employee_work_time_search'
  73. },function(response){
  74. if(callback!=null) callback();
  75. });
  76. }
  77. //Ajout ou modification temps de travail employé
  78. function employee_employee_work_time_save(){
  79. var data = $('#employee-work-time-form').toJson();
  80. $.action(data,function(r){
  81. $('#employee-work-time-form').attr('data-id','');
  82. employee_employee_work_time_search();
  83. $('#employee-work-time-form').attr('data-id',r.id);
  84. $.urlParam('id',r.id);
  85. $.message('success','Enregistré');
  86. });
  87. }
  88. //Récuperation ou edition temps de travail employé
  89. function employee_employee_work_time_edit(element){
  90. var line = $(element).closest('.item-line');
  91. $.action({
  92. action: 'employee_employee_work_time_edit',
  93. id: line.attr('data-id')
  94. },function(r){
  95. $('#employee-work-time-form').fromJson(r);
  96. init_components('#employee-work-time-form');
  97. $('#employee-work-time-form').attr('data-id',r.id);
  98. });
  99. }
  100. //Suppression temps de travail employé
  101. function employee_employee_work_time_delete(element){
  102. if(!confirm('Êtes vous sûr de vouloir supprimer cet item ?')) return;
  103. var line = $(element).closest('.item-line');
  104. $.action({
  105. action: 'employee_employee_work_time_delete',
  106. id: line.attr('data-id')
  107. },function(r){
  108. line.remove();
  109. $.message('info','Item supprimé');
  110. });
  111. }
  112. /** CONTRAT EMPLOYé **/
  113. //Récuperation d'une liste contrat employé dans le tableau #employeecontracts
  114. function employee_employee_contract_search(callback){
  115. var id = $.urlParam('id');
  116. if(!id) return;
  117. $('#employee-contracts').fill({
  118. action:'employee_employee_contract_search',
  119. employee : id
  120. },function(response){
  121. if(callback!=null) callback();
  122. });
  123. }
  124. function employee_employee_contract_edit(element){
  125. $('#contractModal').clear().modal('show');
  126. var data = {action : 'employee_employee_contract_edit'};
  127. if(element) data.id = $(element).closest('tr').attr('data-id');
  128. $.action(data,function(r){
  129. $('#contractModal').fromJson(r);
  130. $('#contractModal').attr('data-id',r.id);
  131. });
  132. }
  133. //Ajout ou modification contrat employé
  134. function employee_employee_contract_save(){
  135. var saveContract = function(){
  136. var data = $('#contractModal').toJson();
  137. data.action='employee_employee_contract_save';
  138. data.employee = $.urlParam('id');
  139. data.id = $('#contractModal').attr('data-id');
  140. $.action(data,function(r){
  141. employee_employee_contract_search();
  142. $('#contractModal').modal('hide');
  143. $.message('success','Enregistré');
  144. });
  145. }
  146. if(!$.urlParam('id')){
  147. employee_save(function(){saveContract()},true);
  148. }else{
  149. saveContract();
  150. }
  151. }
  152. //Suppression contrat employé
  153. function employee_employee_contract_delete(element){
  154. if(!confirm('Êtes vous sûr de vouloir supprimer cet item ?')) return;
  155. var line = $(element).closest('.item-line');
  156. $.action({
  157. action: 'employee_employee_contract_delete',
  158. id: line.attr('data-id')
  159. },function(r){
  160. line.remove();
  161. $.message('info','Item supprimé');
  162. });
  163. }