main.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //CHARGEMENT DE LA PAGE
  2. function init_plugin_example(){
  3. switch($.urlParam('page')){
  4. default:
  5. break;
  6. }
  7. $('#contacts').sortable_table({
  8. onSort : example_contact_search
  9. });
  10. }
  11. //Enregistrement des configurations
  12. function example_setting_save(){
  13. $.action({
  14. action: 'example_setting_save',
  15. fields: $('#example-setting-form').toJson()
  16. },function(){
  17. $.message('success','Enregistré');
  18. });
  19. }
  20. /** CONTACT **/
  21. //Récuperation d'une liste contact dans le tableau #contacts
  22. function example_contact_search(callback,exportMode){
  23. var box = new FilterBox('#example_contact-filters');
  24. if(exportMode) $('.btn-export').addClass('btn-preloader');
  25. $('#contacts').fill({
  26. action:'example_contact_search',
  27. filters: box.filters(),
  28. //Gestion du tri par colonnes de tableau (optionnel)
  29. sort: $('#contacts').sortable_table('get'),
  30. //Activation de l'export excel (optionnel)
  31. export: !exportMode ? false : exportMode,
  32. //exemple d'affichage de ligne personnalisé (optionnel)
  33. showing : function(item,i){
  34. item.css({
  35. transform:'translateX(-200px)',
  36. transition:'all 0.2s ease-in-out',
  37. opacity : 0
  38. }).removeClass('hidden');
  39. setTimeout(function(){
  40. item.css({
  41. transform:'translateX(0px)',
  42. opacity : 1
  43. })
  44. },(i+1)*5);
  45. }
  46. },function(response){
  47. if(!exportMode) $('.results-count > span').text(response.pagination.total);
  48. if(callback!=null) callback();
  49. });
  50. }
  51. //Ajout ou modification contact
  52. function example_contact_save(){
  53. var data = $('#contact-form').toJson();
  54. $('input[data-type="radio"]:checked', '#contact-form').each(function(){
  55. data[$(this).attr('name')] = $(this).val();
  56. });
  57. $.action(data,function(r){
  58. $('#contact-form').attr('data-id',r.id);
  59. $.urlParam('id',r.id);
  60. $.message('success','Enregistré');
  61. });
  62. }
  63. //Suppression contact
  64. function example_contact_delete(element){
  65. if(!confirm('Êtes vous sûr de vouloir supprimer cet item ?')) return;
  66. var line = $(element).closest('.item-line');
  67. $.action({
  68. action: 'example_contact_delete',
  69. id: line.attr('data-id')
  70. },function(r){
  71. line.remove();
  72. $.message('info','Item supprimé');
  73. });
  74. }
  75. /* QUICKFORM */
  76. function example_quickform_buttons(){
  77. $('.quickform-modal .modal-footer').append('<div class="btn btn-success" onclick="contact_save(contact_submit_quickform);"><i class="fas fa-check"></i> Ajouter</div>');
  78. }
  79. // Callback du quickform on save
  80. function contact_submit_quickform(){
  81. $('#quickform-modal').modal('hide');
  82. }
  83. /* EXPORT MODELE */
  84. function contact_export_pre_callback(){
  85. console.log('Callback custom après chargement du modal');
  86. setTimeout(function(){
  87. $('#export-modal .cb-custom-btn').remove();
  88. $('#export-modal .modal-footer').prepend('<div class="btn btn-primary mr-auto cb-custom-btn"><i class="fas fa-check"></i> Bouton ajouté avec le callback custom</div>');
  89. },0);
  90. }
  91. function contact_export_post_callback(){
  92. alert('Callback custom après export');
  93. }
  94. /* LOCATION CALLBACK */
  95. function example_location_select(location){
  96. var attributes = {};
  97. for(var key in location){
  98. attributes['data-'+key] = location[key];
  99. if($('#'+key)!='') $('#'+key).val(location[key]).text(location[key]);
  100. }
  101. }
  102. function example_location_geocode(infos){
  103. alert("Latitude: "+infos.Response.View[0].Result[0].Location.DisplayPosition.Latitude+"\nLongitude: "+infos.Response.View[0].Result[0].Location.DisplayPosition.Longitude);
  104. }
  105. function example_map_click(args){
  106. console.log('click on map with args',args);
  107. }