main.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //CHARGEMENT DE LA PAGE
  2. function init_plugin_contact(){
  3. switch($.urlParam('page')){
  4. case 'sheet.contact.person':
  5. contact_contact_search();
  6. break;
  7. default:
  8. break;
  9. }
  10. $('#contact-persons').sortable_table({
  11. onSort : contact_contact_person_search
  12. });
  13. }
  14. //Enregistrement des configurations
  15. function contact_setting_save(){
  16. $.action({
  17. action: 'contact_setting_save',
  18. fields: $('#contact-setting-form').toJson()
  19. },function(){
  20. $.message('success','Enregistré');
  21. });
  22. }
  23. /** CONTACT **/
  24. //Récuperation d'une liste contact dans le tableau #contactpersons
  25. function contact_contact_person_search(callback,exportMode){
  26. var box = new FilterBox('#filters');
  27. $('#contact-persons').fill({
  28. action:'contact_contact_person_search',
  29. filters: box.filters(),
  30. sort: $('#contact-persons').sortable_table('get'),
  31. export: !exportMode ? false : exportMode
  32. },function(response){
  33. $('.results-count span').text(response.pagination.total);
  34. if(callback!=null) callback();
  35. });
  36. }
  37. //Ajout ou modification contact
  38. function contact_contact_person_save(){
  39. var data = $('#contact-person-form').toJson();
  40. $.action(data,function(r){
  41. $('#contact-person-form').attr('data-id',r.id);
  42. $.urlParam('id',r.id);
  43. $.message('success','Enregistré');
  44. });
  45. }
  46. //Suppression contact
  47. function contact_contact_person_delete(element){
  48. if(!confirm('Êtes vous sûr de vouloir supprimer cet item ?')) return;
  49. var line = $(element).closest('.item-line');
  50. $.action({
  51. action: 'contact_contact_person_delete',
  52. id: line.attr('data-id')
  53. },function(r){
  54. line.remove();
  55. $.message('info','Contact supprimé');
  56. });
  57. }
  58. /* CONTACT info*/
  59. function contact_contact_add(element,data){
  60. if(element){
  61. var line = $(element).closest('li');
  62. }else{
  63. var line = $('#contact-list li:eq(0)');
  64. }
  65. var newline = line.clone().clear();
  66. line.after(newline);
  67. if($('#contact-list li:eq(0) .value').val()=='') $('#contact-list li:eq(0)').remove();
  68. if(data){
  69. newline.find('.type').val(data.type);
  70. newline.find('.value').val(data.value);
  71. }
  72. contact_contact_save();
  73. }
  74. function contact_contact_remove(element){
  75. var line = $(element).closest('li');
  76. if($('#contact-list li').length==1){
  77. line.clear();
  78. }else{
  79. line.remove();
  80. }
  81. contact_contact_save();
  82. }
  83. function contact_contact_search(){
  84. var contacts = JSON.parse(atob($('#contacts').val()));
  85. for(var k in contacts){
  86. contact_contact_add(null,contacts[k]);
  87. }
  88. }
  89. function contact_contact_save(){
  90. var contacts = [];
  91. $('#contact-list li').each(function(){
  92. var line = $(this);
  93. contacts.push({
  94. type : line.find('.type').val(),
  95. value : line.find('.value').val()
  96. });
  97. });
  98. $('#contacts').val(btoa(JSON.stringify(contacts)));
  99. }