site.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. var icon = L.icon({
  57. iconUrl: 'static/img/marker.png',
  58. iconSize: [14, 20], // size of the icon
  59. shadowSize: [14, 20], // size of the shadow
  60. iconAnchor: [7, 20], // point of the icon which will correspond to marker's location
  61. popupAnchor: [0, -20] // point from which the popup should open relative to the iconAnchor
  62. });
  63. var icon_ffdn = $.extend(true, {}, icon);
  64. icon_ffdn['options']['iconUrl'] = 'static/img/marker_ffdn.png';
  65. $.getJSON('/isp/map_data.json', function(data) {
  66. $.each(data, function(k, isp) {
  67. var marker = L.marker([isp['coordinates']['latitude'], isp['coordinates']['longitude']],
  68. {'icon': isp.ffdn_member ? icon_ffdn : icon});
  69. marker./*on('click', function() {
  70. $.getJSON('/isp/'+isp.id+'/covered_areas.json', function(data) {
  71. alert(data);
  72. });
  73. }).*/bindPopup(isp.popup).addTo(map);
  74. });
  75. });
  76. }
  77. function change_input_num(li, new_num, reset=false) {
  78. li.find('input,select').each(function() {
  79. var id = $(this).attr('id').replace(/^(.*)-\d{1,4}/, '$1-'+new_num);
  80. $(this).attr({'name': id, 'id': id});
  81. if(reset)
  82. $(this).val('').removeAttr('checked');
  83. });
  84. }
  85. function append_remove_button(li) {
  86. li.children(':first').after(' <button class="btn btn-mini" type="button"><i class="icon-minus"></i></button>');
  87. li.children('button').click(function() {
  88. var ul=li.parent();
  89. li.remove();
  90. var i=0;
  91. ul.children('li').each(function() {
  92. change_input_num($(this), i);
  93. i++;
  94. });
  95. });
  96. };
  97. function clone_fieldlist(el) {
  98. var new_element = el.clone(true);
  99. var elem_id = new_element.find(':input')[0].id;
  100. var elem_num = parseInt(elem_id.replace(/^.*-(\d{1,4})/, '$1')) + 1;
  101. change_input_num(new_element, elem_num, true);
  102. new_element.children('button').remove();
  103. new_element.children('.help-inline.error-list').remove();
  104. new_element.find('.bootstrap-select').remove();
  105. append_remove_button(new_element);
  106. new_element.find('.selectpicker').data('selectpicker', null).selectpicker();
  107. el.after(new_element);
  108. }