site.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. "use strict";
  2. $(function () {
  3. $('.fieldlist').each(function() {
  4. var $this=$(this);
  5. var lis=$this.children('li');
  6. lis.first().children(':first').after(' <button class="btn btn-mini" type="button"><i class="icon-plus"></i></button>');
  7. lis.first().children('button').click(function() {
  8. clone_fieldlist($this.children('li:last'));
  9. });
  10. lis=lis.slice(1);
  11. lis.each(function() {
  12. append_remove_button($(this));
  13. });
  14. });
  15. $('.selectpicker').selectpicker();
  16. $("[rel=tooltip]").tooltip();
  17. init_map();
  18. });
  19. function init_map() {
  20. var mapquest=L.tileLayer('http://otile{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpg', {
  21. attribution: '&copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, '+
  22. 'Tiles courtesy of <a href="http://www.mapquest.com/" target="_blank">MapQuest</a>',
  23. subdomains: '1234'
  24. });
  25. var mapquestsat=L.tileLayer('http://otile{s}.mqcdn.com/tiles/1.0.0/sat/{z}/{x}/{y}.jpg', {
  26. attribution: '&copy; Tiles courtesy of <a href="http://www.mapquest.com/" target="_blank">MapQuest</a>, '+
  27. 'Portions Courtesy NASA/JPL-Caltech and U.S. Depart. of Agriculture, Farm Service Agency',
  28. subdomains: '1234',
  29. maxZoom: 11
  30. });
  31. var osm=L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  32. attribution: '&copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors',
  33. subdomains: 'ab'
  34. });
  35. var hyb=L.tileLayer('http://otile{s}.mqcdn.com/tiles/1.0.0/hyb/{z}/{x}/{y}.jpg', {
  36. subdomains: '1234',
  37. maxZoom: 11
  38. });
  39. if(!$('#map').length)
  40. return;
  41. var map = L.map('map', {
  42. center: new L.LatLng(46.603354, 10),
  43. zoom: 4,
  44. layers: [mapquest]
  45. });
  46. map.attributionControl.setPrefix('');
  47. L.control.layers({'MapQuest': mapquest, 'OSM Mapnik': osm, 'MapQuest Aerial': mapquestsat}).addTo(map);
  48. map.on('baselayerchange', function(a) {
  49. if(a.name == 'MapQuest Aerial') {
  50. map.addLayer(hyb);
  51. hyb.bringToFront();
  52. } else {
  53. map.removeLayer(hyb);
  54. }
  55. });
  56. }
  57. function change_input_num(li, new_num, reset=false) {
  58. li.find('input,select').each(function() {
  59. var id = $(this).attr('id').replace(/^(.*)-\d{1,4}/, '$1-'+new_num);
  60. $(this).attr({'name': id, 'id': id});
  61. if(reset)
  62. $(this).val('').removeAttr('checked');
  63. });
  64. }
  65. function append_remove_button(li) {
  66. li.children(':first').after(' <button class="btn btn-mini" type="button"><i class="icon-minus"></i></button>');
  67. li.children('button').click(function() {
  68. var ul=li.parent();
  69. li.remove();
  70. var i=0;
  71. ul.children('li').each(function() {
  72. change_input_num($(this), i);
  73. i++;
  74. });
  75. });
  76. };
  77. function clone_fieldlist(el) {
  78. var new_element = el.clone(true);
  79. var elem_id = new_element.find(':input')[0].id;
  80. var elem_num = parseInt(elem_id.replace(/^.*-(\d{1,4})/, '$1')) + 1;
  81. change_input_num(new_element, elem_num, true);
  82. new_element.children('button').remove();
  83. new_element.children('.help-inline.error-list').remove();
  84. new_element.find('.bootstrap-select').remove();
  85. append_remove_button(new_element);
  86. new_element.find('.selectpicker').data('selectpicker', null).selectpicker();
  87. el.after(new_element);
  88. }