PageSourceSearch

https://consultapopular.rs.gov.br/matriz_common/versions/2.1.5/the…/js/demandalai.local.js?2.1.5.161.6+4

js consultapopular.rs.gov.br collected 2026-09-26 17:40:38 UTC 9,647 bytes, 203 lines download raw bytes

1
2$(function () {
3    var geoID = $(".modal-body #geoID");
4
5    MatrizDemandalaiLocal = function (options) {
6        var self = this;
7        
8        this.containers = {
9            $form: function () {
10                return $("#formDemandaLai");
11            },
12            $drawMarkerButton: function () {
13                return $("[data-matriz-action='draw-marker']");
14            },
15            $clearMapButton: function () {
16                return $("[data-matriz-action='clear-map']");
17            },
18            $findInMapButton: function () {
19                return $('[data-matriz-action="find-in-map"]');
20            },
21            $mapa: function () {
22                return $(".matriz-mapa");
23            }
24        };
25 
26        this.setLocalData = function (local) {
27            var demanda = '';
28
29            if (geoID.val() === 'sTxtGeorreferenciamentoDemanda') {
30                demanda = 'Demanda';
31            }
32
33            this.containers.$form().find("#sLogradouro" + demanda).val(local.logradouro);
34            this.containers.$form().find("#sNumEndereco" + demanda).val(local.numero);
35            this.containers.$form().find("#sComplemento" + demanda).val(local.complemento);
36            this.containers.$form().find("input[id^=sBairro" + demanda + "_]").val(local.bairro);
37            this.containers.$form().find("#sCep" + demanda).val(local.cep);
38            this.containers.$form().find("#sTxtGeorreferenciamento" + demanda).val(local.pontos);
39            this.containers.$form().find("#sIdPais" + demanda + " option:contains('" + local.pais.toUpperCase() + "')").prop("selected", true);
40
41            var $pais = this.containers.$form().find("#sIdPais" + demanda);
42            var idFormulario = this.containers.$form().find("[name='idformulario']").val();
43            var reqLai = idFormulario ? "&idformulario=" + idFormulario : "";
44            
45            matriz.ui.loading.modal.show();
46            $.ajax({
47                "url": "/_service/demandalai/estados?id_pais=" + $pais.val() + reqLai
48            }).then(function (dataEstados) {
49                var $uf = self.containers.$form().find("#sIdUf" + demanda);
50                $uf.find('option').remove();
51                $uf.append('<option value="">Selecione...</option>');
52                var $data = $(dataEstados);
53                $data.each(function(index, item) {
54                    $uf.append('<option value="'+item.id_uf+'">'+item.nome_uf+'</option>');
55                });
56                self.containers.$form().find("#sIdUf" + demanda + " option:contains('" + getNomeUf(local.uf) + "')").prop("selected", true);
57                return $.ajax({
58                    url: "/_service/demandalai/municipios?id_uf=" + $uf.val() + reqLai
59                }).then(function (dataMunicipios) {
60                    var $inputValueSelector = self.containers.$form().find("#sIdMunicipio" + demanda);
61                    var $inputListSelector = self.containers.$form().find("#sIdMunicipio" + demanda + "AutoComplete");
62                    $inputValueSelector[0].value = "";
63                    $inputListSelector[0].value = "";
64                    form.demandaLai.municipios = dataMunicipios;
65                    self.containers.$form().find("#sIdMunicipio" + demanda + "AutoComplete").val(local.municipio);
66                    initAutoComplete(null, $inputValueSelector);
67                    var item = getSelectedItem(dataMunicipios, $inputListSelector);
68                    if (item) {
69                        $inputValueSelector.val(item.id_municipio);
70                    } else {
71                        $inputValueSelector.val("");
72                    }
73                    matriz.ui.loading.modal.hide();
74                });
75            });
76        };
77
78        this.getLocalData = function () {
79            var demanda = '';
80
81            if (geoID.val() === 'sTxtGeorreferenciamentoDemanda') {
82                demanda = 'Demanda';
83            }
84
85            var local = {
86                "logradouro": this.containers.$form().find("#sLogradouro" + demanda).val() + " " + this.containers.$form().find("#sNumEndereco" + demanda).val(),
87                "complemento": this.containers.$form().find("#sComplemento" + demanda).val(),
88                "municipio": this.containers.$form().find("#sIdMunicipio" + demanda + "AutoComplete").val(),
89                "uf": this.containers.$form().find("#sIdUf" + demanda + " option:selected").text(),
90                "pais": this.containers.$form().find("#sIdPais" + demanda + " option:selected").text(),
91                "cep": this.containers.$form().find("#sCep" + demanda).val(),
92                "pontos": this.containers.$form().find("#sTxtGeorreferenciamento" + demanda).val()
93            };
94
95            $('button[data-matriz-action="update-local"]').removeAttr("disabled");
96            return local;
97        };
98
99        function createLocalEditor(local) {
100             function createEditor() {
101                var localEditor = new matriz.utils.maps.LocalEditor(local, self);
102
103                var gmap = localEditor.getGmap();
104
105                 localEditor.findInMap = function () {
106                    gmap.searchByAddress(self.getLocalData(), (function (locals) {
107                        if (locals.length > 0) {
108                            matriz.ui.scrollTo("#bibliotecaLocalMapa");
109                            localEditor.adicionaLocal(locals[0]);
110                            $('button[data-matriz-action="update-local"]').attr("data-matriz-local", JSON.stringify(locals[0]));
111                            localEditor.changeState(this.states.MARKER_VISIBLE);
112                        } else {
113                            localEditor.displayMessage("Sua busca não retornou resultados.");
114                        }
115                    }).bind(localEditor));
116                };
117
118                localEditor.updateLocalDataByMap = function () {
119                   var localData = self.getLocalData();
120
121                   gmap.searchByLocation(localData, (function(locals) {
122                        if (locals.length > 0) {
123                            localEditor.adicionaLocal(locals[0]);
124                            $('button[data-matriz-action="update-local"]').attr("data-matriz-local", JSON.stringify(locals[0]));
125                        }
126                   }).bind(localEditor));
127                };
128
129                localEditor.updateLocalPontos = function(pontos) {
130                    if (geoID.length && geoID.val()) {
131                        $pontos = self.containers.$form().find("#" + geoID.val());
132                        if ($pontos.length) {
133                            $pontos.val(pontos);
134                        }
135                    } else {
136                        $pontos = self.containers.$form().find(".geo-reference-coordinates");
137                        if ($pontos.length) {
138                            $pontos.val(pontos);
139                        }
140                    }
141                };
142
143                var __superClearMap = localEditor.clearMap;
144                localEditor.clearMap = function () {
145                    $('button[data-matriz-action="update-local"]').attr("disabled", true).removeAttr("data-matriz-local");
146                    __superClearMap.call(this);
147                };
148
149                $('button[data-matriz-action="update-local"]').on("click", localEditor.updateLocal.bind(this));
150
151                $('button[data-matriz-action="cancel"]').on("click", function () {
152                    self.containers.$clearMapButton().trigger("click");
153                });
154
155                localEditor.initEvents();
156                localEditor.renderMap([local]);
157                 navigator.geolocation.getCurrentPosition(function (location) {
158                     gmap.centerMapOnLatLong(location.coords.latitude, location.coords.longitude);
159                 });
160            }
161            if (typeof matriz.externalapis !== "undefined") {
162                if (matriz.externalapis.google.maps.loaded) {
163                    createEditor();
164                } else {
165                    matriz.externalapis.google.maps.load();
166                    matriz.common.events.on("matriz.externalapis.google.maps.ready", createEditor);
167                }
168            }
169        }
170
171        this.init = function () {
172            createLocalEditor();
173        };
174
175        return this;
176    };
177
178    if ($("#bibliotecaLocalMapa").length) {
179        var matrizDemandalaiLocal = new MatrizDemandalaiLocal();
180        matrizDemandalaiLocal.init();
181    }
182
183    $(".open-geo-reference").on("click", function () {
184        geoID.val($(this).data('matriz-id'));
185
186        var inputs = $('#sIdMunicipioAutoComplete, #sCep, #sLogradouro, #sNumEndereco, input[name^=sBairro]').filter(function() {
187            return this.value !== ''
188        });
189
190        var inputsDemanda = $("#sIdMunicipioAutoCompleteDemanda, #sCepDemanda, #sLogradouroDemanda, #sNumEnderecoDemanda, input[name^=sBairroDemanda]").filter(function() {
191            return this.value !== ''
192        });
193
194        if ((geoID.val() === "sTxtGeorreferenciamento" && inputs.length > 0 && inputs.val().length > 0) ||
195            (geoID.val() === "sTxtGeorreferenciamentoDemanda" && inputsDemanda.length > 0 && inputsDemanda.val().length > 0)) {
196            matrizDemandalaiLocal.containers.$findInMapButton().trigger("click");
197        } else {
198            matrizDemandalaiLocal.containers.$clearMapButton().trigger("click");
199        }
200    });
201
202});
203

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.