form.html.twig 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. {% extends 'SonataAdminBundle:CRUD:base_edit.html.twig' %}
  2. {% block javascripts %}
  3. {{ parent() }}
  4. <script type="text/javascript">
  5. $(function () {
  6. // buscar la direccion del cliente y la muestra en el mapa.
  7. $('select[id$="clientId"]').change(function () {
  8. $.ajax({
  9. url: '{{ path('ajax_client_data') }}',
  10. dataType: 'json',
  11. delay: 250,
  12. data: {
  13. q: $(this).val()
  14. }
  15. }).done(function (data) {
  16. googleSearchDirectionAndShowMaps(data.results[0].address);
  17. });
  18. });
  19. });
  20. /**
  21. * funcion que busca una direccion y la muestra en el mapa.
  22. * @param address Contiene la direccion.
  23. */
  24. function googleSearchDirectionAndShowMaps(address) {
  25. $('input[class="search-input"]').val(address + ", Gálvez, Santa Fe, Argentina");
  26. $.ajax({
  27. url: "http://maps.googleapis.com/maps/api/geocode/json?address='" + address + ", Gálvez, Santa Fe, Argentina'",
  28. type: "POST"
  29. }).done(function (res) {
  30. if (res != undefined) {
  31. if (res.status == google.maps.GeocoderStatus.OK) {
  32. loc = new L.latLng(res.results[0].geometry.location.lat, res.results[0].geometry.location.lng);
  33. drawMarker();
  34. setDataValue();
  35. } else {
  36. alert(res.status);
  37. }
  38. } else {
  39. alert("{{ 'error.address_not_found'|trans({}, 'FTTHBundle') }}");
  40. }
  41. }).error(function (res) {
  42. console.log("ERROR: ");
  43. console.log(res);
  44. alert("{{ 'error.address_not_found'|trans({}, 'FTTHBundle') }}");
  45. });
  46. }
  47. /**
  48. * Busca y calcula la distancia a los nap y la cantidad de puertos libres.
  49. */
  50. function calcularDistanciaNap() {
  51. var origin = JSON.parse($("input[id*='_location_extraData']").attr('value'));
  52. $.ajax({
  53. url: '{{ path('ajax_distance_nap_onu') }}',
  54. dataType: 'json',
  55. type: "GET",
  56. data: {
  57. lat: origin.lat,
  58. lng: origin.lng
  59. }
  60. }).done(function (res) {
  61. var select = $("select[id*='_nap']");
  62. select.find("option").remove().end();
  63. $.each(res, function (i, obj) {
  64. obj = JSON.parse(obj);
  65. for (var i = 0; i < obj.length; i++) {
  66. if (obj[i].distance != -1) {
  67. select.append(
  68. '<option value="' + obj[i].id + '">' +
  69. obj[i].name + " ({{ 'Free Port'|trans({}, 'FTTHBundle') }}: " + obj[i].freePort + " - " +
  70. "{{ 'Distance'|trans({}, 'FTTHBundle') }}: " + obj[i].distance + " KM.)" +
  71. '</option>'
  72. );
  73. }
  74. }
  75. for (var i = 0; i < obj.length; i++) {
  76. if (obj[i].distance == -1) {
  77. select.append(
  78. '<option value="' + obj[i].id + '">' +
  79. obj[i].name + " ({{ 'Free Port'|trans({}, 'FTTHBundle') }}: " + obj[i].freePort + ")" +
  80. '</option>'
  81. );
  82. }
  83. }
  84. });
  85. }).error(function (res) {
  86. console.log("ERROR: ");
  87. console.log(res);
  88. });
  89. }
  90. </script>
  91. {% endblock %}