site.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. var map = L.map('map', {
  40. center: new L.LatLng(46.603354, 10),
  41. zoom: 4,
  42. layers: [mapquest]
  43. });
  44. map.attributionControl.setPrefix('');
  45. L.control.layers({'MapQuest': mapquest, 'OSM Mapnik': osm, 'MapQuest Aerial': mapquestsat}).addTo(map);
  46. map.on('baselayerchange', function(a) {
  47. if(a.name == 'MapQuest Aerial') {
  48. map.addLayer(hyb);
  49. hyb.bringToFront();
  50. } else {
  51. map.removeLayer(hyb);
  52. }
  53. });
  54. }
  55. function change_input_num(li, new_num, reset=false) {
  56. li.find('input,select').each(function() {
  57. var id = $(this).attr('id').replace(/^(.*)-\d{1,4}/, '$1-'+new_num);
  58. $(this).attr({'name': id, 'id': id});
  59. if(reset)
  60. $(this).val('').removeAttr('checked');
  61. });
  62. }
  63. function append_remove_button(li) {
  64. li.children(':first').after(' <button class="btn btn-mini" type="button"><i class="icon-minus"></i></button>');
  65. li.children('button').click(function() {
  66. var ul=li.parent();
  67. li.remove();
  68. var i=0;
  69. ul.children('li').each(function() {
  70. change_input_num($(this), i);
  71. i++;
  72. });
  73. });
  74. };
  75. function clone_fieldlist(el) {
  76. var new_element = el.clone(true);
  77. var elem_id = new_element.find(':input')[0].id;
  78. var elem_num = parseInt(elem_id.replace(/^.*-(\d{1,4})/, '$1')) + 1;
  79. change_input_num(new_element, elem_num, true);
  80. new_element.children('button').remove();
  81. new_element.children('.help-inline.error-list').remove();
  82. new_element.find('.bootstrap-select').remove();
  83. append_remove_button(new_element);
  84. new_element.find('.selectpicker').data('selectpicker', null).selectpicker();
  85. el.after(new_element);
  86. }