123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- {% extends 'SonataAdminBundle:CRUD:base_edit.html.twig' %}
- {% block formactions %}
- {{ parent() }}
- <script type="text/javascript">
- var modificacion = false;
- $(function () {
- // buscar la direccion del cliente y la muestra en el mapa.
- var objSelectClient = $('input:hidden[id$="clientId"]');
- if (objSelectClient.val() != "" && parseInt(objSelectClient.val()) > 0) {
- modificacion = true;
- callbackClientId(objSelectClient.val());
- } else {
- if (_MAP_LATITUDE == 0 && _MAP_LONGITUDE == 0) {
- setCoordinatesFromConfig(true);
- } else {
- drawMap(_MAP_LATITUDE, _MAP_LONGITUDE);
- }
- $("div[id*='_nap']").find(".select2-chosen").html("");
- $("select[id*='_nap']").val(0);
- }
- });
- function callbackClientId(clientId) {
- $.ajax({
- url: '{{ path('ajax_client_data') }}',
- dataType: 'json',
- delay: 250,
- data: {
- q: clientId
- }
- }).done(function (data) {
- var extradata = null;
- if (data.results[0].location) {
- try {
- extradata = JSON.parse(data.results[0].location.extraData);
- if (extradata.lat == undefined || extradata.lng == undefined) {
- extradata = null;
- }
- } catch (ignore) {
- }
- }
- if (extradata === null) {
- googleSearchDirectionAndShowMaps(data.results[0].address);
- } else {
- $('input[class="search-input"]').val(data.results[0].address);
- drawMap(extradata.lat, extradata.lng);
- }
- //calcularDistanciaNap();
- });
- }
- /**
- * funcion que busca una direccion y la muestra en el mapa.
- * @param address Contiene la direccion.
- */
- function googleSearchDirectionAndShowMaps(address) {
- $('input[class="search-input"]').val(address);
- $.ajax({
- url: "http://maps.googleapis.com/maps/api/geocode/json?address='" + address + "'",
- type: "POST"
- }).done(function (res) {
- if (res != undefined && res.status == google.maps.GeocoderStatus.OK) {
- drawMap(res.results[0].geometry.location.lat, res.results[0].geometry.location.lng);
- } else {
- // direccion no encontrada por google
- var msg = "{{ 'error.address_not_found'|trans({}, 'FTTHBundle') }}";
- showError(msg.replace('%client_address%', address));
- }
- }).error(function (res) {
- // direccion no encontrada por google, esto se puede deber a la cantidad de consultas que se
- // realizan al webservice de google
- });
- }
- /**
- * Funcion que dibuja el mapa.
- * @param lat
- * @param lng
- */
- function drawMap(lat, lng) {
- loc = new L.latLng(lat, lng);
- drawMarker();
- setDataValue();
- }
- /**
- * Busca y calcula la distancia a los nap y la cantidad de puertos libres.
- */
- function calcularDistanciaNap() {
- var origin = null;
- try {
- origin = JSON.parse($("input[id*='_location_extraData']").attr('value'));
- } catch (ignore) {
- }
- if (origin != null) {
- $.ajax({
- url: '{{ path('ajax_distance_nap_onu') }}',
- dataType: 'json',
- type: "GET",
- data: {
- lat: origin.lat,
- lng: origin.lng,
- napId: modificacion ? $("select[id*='_nap']").val() : 0
- }
- }).done(function (res) {
- var select = $("select[id*='_nap']");
- var span = $("div[id*='_nap']").find(".select2-chosen");
- var codigoNap = select.val(), nap = "";
- span.html("");
- select.find("option").remove().end();
- $.each(res, function (i, obj) {
- obj = JSON.parse(obj);
- for (var i = 0; i < obj.length; i++) {
- if (obj[i].distance != -1) {
- var tmp = obj[i].name +
- " ({{ 'Free Port'|trans({}, 'FTTHBundle') }}: " + obj[i].freePort + " - " +
- "OLT: " + obj[i].olt + " - " +
- "Slot: " + obj[i].slot + " - " +
- "Link: " + obj[i].link + " - " +
- "{{ 'Distance'|trans({}, 'FTTHBundle') }}: " + obj[i].distance + " KM. - " +
- "{{ 'Address'|trans({}, 'FTTHBundle') }}: " + obj[i].address + " )";
- select.append(
- '<option value="' + obj[i].id + '" >' + tmp +
- '</option>'
- );
- if (codigoNap == obj[i].id) {
- nap = tmp;
- }
- }
- }
- for (var i = 0; i < obj.length; i++) {
- if (obj[i].distance == -1) {
- var tmp = obj[i].name + " ({{ 'Free Port'|trans({}, 'FTTHBundle') }}: " + obj[i].freePort + " - ";
- tmp +=
- "OLT: " + obj[i].olt + " - " +
- "Slot: " + obj[i].slot + " - " +
- "Link: " + obj[i].link + " - ";
- tmp += "{{ 'Distance'|trans({}, 'FTTHBundle') }}: " + obj[i].distanceMessage;
- if (obj[i].address != null && obj[i].address.length > 0) {
- tmp += " - {{ 'Address'|trans({}, 'FTTHBundle') }}: " + obj[i].address;
- }
- tmp += ")";
- select.append(
- '<option value="' + obj[i].id + '" >' + tmp +
- '</option>'
- );
- if (codigoNap == obj[i].id) {
- nap = tmp;
- }
- }
- }
- });
- span.html(nap);
- select.val(codigoNap);
- });
- }
- }
- </script>
- {% endblock %}
|