main.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //CHARGEMENT DE LA PAGE
  2. function init_plugin_clientmap(){
  3. switch($.urlParam('page')){
  4. default:
  5. break;
  6. }
  7. }
  8. /** CLIENT **/
  9. //Enregistrement des configurations
  10. function client_map_setting_save(){
  11. $.action({
  12. action: 'client_map_setting_save',
  13. fields: $('#client-map-setting-form').toJson()
  14. },function(){
  15. $.message('success','Enregistré');
  16. });
  17. }
  18. function client_map_search(options){
  19. options = !options ? {} : options;
  20. var box = new FilterBox('#filters');
  21. if(options && options.exportMode) $('.btn-export').addClass('btn-preloader');
  22. var searchTable = $('#clients').data('searchTable');
  23. searchTable.resetGlobalCheckbox();
  24. if(!options.keepChecked) searchTable.resetCheckbox();
  25. var data = {
  26. action:'client_client_search',
  27. filters: box.filters(),
  28. sort: $('#clients').sortable_table('get'),
  29. firm: $.urlParam('firm'),
  30. export: !options.exportMode ? false : options.exportMode,
  31. selected : searchTable.checkboxes()
  32. };
  33. var customFields = $('#customFields').text().split("\n").filter(n => n);
  34. console.log(customFields);
  35. if(customFields.length!=0){
  36. data.columns = {
  37. added : customFields,
  38. deleted : []
  39. }
  40. }
  41. $('#clients').fill(data,function(response){
  42. if(!options.exportMode) $('.results-count > span').text(response.pagination.total);
  43. searchTable.fillCheckbox();
  44. var tooltipTpl = $('#map-tooltip').html();
  45. var jsonPoints = [];
  46. for (var k in response.rows) {
  47. var client = response.rows[k];
  48. if(!client.meta) continue;
  49. if(!client.meta.longitude || !client.meta.latitude) continue;
  50. var clientPoint = {};
  51. clientPoint.latitude = client.meta.latitude;
  52. clientPoint.longitude = client.meta.longitude;
  53. clientPoint.id = client.id;
  54. clientPoint.label = Mustache.render(tooltipTpl,{client:client});
  55. jsonPoints.push(clientPoint);
  56. }
  57. $('.map-container').html('<div data-type="map" data-zoom-position="topright" id="client-map" style="height:100%;width:80%;"></div>');
  58. $('#client-map').get(0).innerHtml = JSON.stringify(jsonPoints);
  59. if(jsonPoints.length==0){
  60. $('#client-map-no-points').removeClass('hidden');
  61. }else{
  62. $('#client-map-no-points').addClass('hidden');
  63. }
  64. init_components();
  65. });
  66. }
  67. function client_map_edit(element){
  68. var li;
  69. if($(element).hasClass('client-item')) {
  70. li = $(element)
  71. } else {
  72. var id = $(element).attr('data-id');
  73. li = $('.plugin-clientmap .map-panel #clients').find('li[data-id="'+id+'"]');
  74. }
  75. $('.plugin-clientmap .map-panel #clients li').addClass('hidden');
  76. li.removeClass('hidden').addClass('selected');
  77. $('.plugin-clientmap .map-panel .btn-return').removeClass('hidden');
  78. var points = $('#client-map').data('points');
  79. var id = li.attr('data-id');
  80. var marker = points[id];
  81. if(marker) marker.fire('click');
  82. }
  83. function client_map_edit_cancel(){
  84. $('.plugin-clientmap .map-panel #clients li:not(:eq(0))').removeClass('hidden selected');
  85. $('.plugin-clientmap .map-panel .btn-return').addClass('hidden');
  86. }
  87. function collapseMapPanel(){
  88. $('.map-panel').toggleClass('visible');
  89. $('#map-panel-button').toggleClass('visible');
  90. }