// ==UserScript==
// @name WAZEPT Landmark
// @version 2021.09.20
// @description Facilitates the standardization of landmarks
// @author J0N4S13 ([email protected])
// @include /^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor.*$/
// @exclude https://www.waze.com/user/*editor/*
// @exclude https://www.waze.com/*/user/*editor/*
// @grant none
// @namespace https://greasyfork.org/users/218406
// ==/UserScript==
(function() {
var version = GM_info.script.version;
setTimeout(function() {var myVar = setInterval(myTimer ,500);}, 2000);
//setTimeout(function() {optionsUser();}, 3000);
var validselected = "";
var validcodigo = "";
var validindex = 0;
var indexselected = "";
var funcselected = "";
var data_massive = null;
var array_config_script = {};
var array_config_country = {};
var array_dados_func = {};
var array_emojis = {};
var array_emojis_title = {};
var array_categorias_google = {};
var all_percorrer = [];
function getConfigsScript() {
return new Promise(resolve => {
fetch('https://docs.google.com/spreadsheets/d/1YIokASCZmcCheePyknPU39IlYz1gOfIuu1GwVzaFoic/gviz/tq?tqx=out:json&sheet=Config')
.then(res => res.text())
.then(text => {
const json = JSON.parse(text.substr(47).slice(0, -2))
let first = false;
$(json.table.rows).each(function(){
if(first == false)
{
first = true;
return;
}
array_config_script[verifyNull(this["c"][0])] = verifyNull(this["c"][1]);
});
})
/*var url_data = "https://spreadsheets.google.com/feeds/list/1YIokASCZmcCheePyknPU39IlYz1gOfIuu1GwVzaFoic/1/public/values?alt=json";
$.getJSON(url_data, function(data) {
var entry = data.feed.entry;
$(entry).each(function(){
if (typeof this['gsx$pais'] !== "undefined" || typeof this['gsx$dados'] !== "undefined")
array_config_script[this.gsx$pais.$t] = this.gsx$dados.$t;
});
});*/
var timer = setInterval(check_data, 100);
function check_data() {
if(Object.keys(array_config_script).length > 0 && W.model.getTopCountry() != null)
{
clearInterval(timer);
resolve('true');
}
}
});
}
function getConfigsCountry(link) {
let timeout = 0;
return new Promise(resolve => {
fetch(link)
.then(res => res.text())
.then(text => {
const json = JSON.parse(text.substr(47).slice(0, -2))
$(json.table.rows).each(function(){
if(verifyNull(this["c"][0]))
{
var elem = {funcionalidade: verifyNull(this["c"][1]), excel: verifyNull(this["c"][5]), percorrerlista: verifyNull(this["c"][6]), campolista: verifyNull(this["c"][7]), valorlista: verifyNull(this["c"][8]), validarCategoria: verifyNull(this["c"][9]), nomeCategoria: verifyNull(this["c"][10]), validarFinal: verifyNull(this["c"][11]), campoFinal: verifyNull(this["c"][12]), emojiNome: verifyNull(this["c"][3]), bloqueio: (verifyNull(this["c"][14]) - 1), categoria: verifyNull(this["c"][23]), tipoNotas: verifyNull(this["c"][15]), emoji: verifyNull(this["c"][2]), codigo: verifyNull(this["c"][16]), id: verifyNull(this["c"][17]), nome: verifyNull(this["c"][18]), secundario: verifyNull(this["c"][19]), rua: verifyNull(this["c"][20]), localidade: verifyNull(this["c"][21]), marca: verifyNull(this["c"][22]), notas: verifyNull(this["c"][24]), site: verifyNull(this["c"][25]), telefone: verifyNull(this["c"][26]), servicos: verifyNull(this["c"][27]), estacionamento: verifyNull(this["c"][28]), tomadas: verifyNull(this["c"][29]), segunda: verifyNull(this["c"][30]), terca: verifyNull(this["c"][31]), quarta: verifyNull(this["c"][32]), quinta: verifyNull(this["c"][33]), sexta: verifyNull(this["c"][34]), sabado: verifyNull(this["c"][35]), domingo: verifyNull(this["c"][36]), latitude: verifyNull(this["c"][37]), longitude: verifyNull(this["c"][38]), campo1: verifyNull(this["c"][39]), verificavalidade: verifyNull(this["c"][13])};
array_config_country[ verifyNull(this["c"][1]) ] = elem;
var emoji = verifyNull(this["c"][2]);
var descricao = verifyNull(this["c"][4]);
array_emojis[emoji] = verifyNull(this["c"][1]);
array_emojis_title[emoji] = descricao;
}
});
})
/*$.getJSON(link, function(data) {
var entry = data.feed.entry;
let index = 0;
$(entry).each(function(){
if ((typeof this['gsx$ativo'] === "undefined" || typeof this['gsx$funcionalidade'] === "undefined" || typeof this['gsx$percorrerlista'] === "undefined" || typeof this['gsx$campolista'] === "undefined" || typeof this['gsx$valorlista'] === "undefined" || typeof this['gsx$validarcategoria'] === "undefined" || typeof this['gsx$nomecategoria'] === "undefined" || typeof this['gsx$validarfinal'] === "undefined" || typeof this['gsx$campofinal'] === "undefined" || typeof this['gsx$emojinome'] === "undefined" || typeof this['gsx$emoji'] === "undefined" || typeof this['gsx$descrição'] === "undefined" || typeof this['gsx$excel'] === "undefined" || typeof this['gsx$bloqueio'] === "undefined" || typeof this['gsx$serviços'] === "undefined" || typeof this['gsx$rua'] === "undefined" || typeof this['gsx$localidade'] === "undefined" || typeof this['gsx$código'] === "undefined" ||typeof this['gsx$nome'] === "undefined" || typeof this['gsx$nomessecundários'] === "undefined" || typeof this['gsx$categorias'] === "undefined" || typeof this['gsx$marca'] === "undefined" || typeof this['gsx$notas'] === "undefined" || typeof this['gsx$site'] === "undefined" || typeof this['gsx$telefone'] === "undefined" || typeof this['gsx$tipodenotas'] === "undefined" || typeof this['gsx$id'] === "undefined" || typeof this['gsx$estacionamento'] === "undefined" || typeof this['gsx$tomadas'] === "undefined" || typeof this['gsx$segunda'] === "undefined" || typeof this['gsx$terça'] === "undefined" || typeof this['gsx$quarta'] === "undefined" || typeof this['gsx$quinta'] === "undefined" || typeof this['gsx$sexta'] === "undefined" || typeof this['gsx$sabado'] === "undefined" || typeof this['gsx$domingo'] === "undefined" || typeof this['gsx$latitude'] === "undefined" || typeof this['gsx$longitude'] === "undefined" ||typeof this['gsx$campo1'] === "undefined" || typeof this['gsx$verificavalidade'] === "undefined") || this['gsx$ativo'].$t == "FALSE")
return true;
else
{
var elem = {funcionalidade:this.gsx$funcionalidade.$t, excel:this.gsx$excel.$t, percorrerlista:this.gsx$percorrerlista.$t, campolista:this.gsx$campolista.$t, valorlista:this.gsx$valorlista.$t, validarCategoria:this.gsx$validarcategoria.$t, nomeCategoria:this.gsx$nomecategoria.$t, validarFinal:this.gsx$validarfinal.$t, campoFinal:this.gsx$campofinal.$t, emojiNome:this.gsx$emojinome.$t, bloqueio:(this.gsx$bloqueio.$t - 1), categoria:this.gsx$categorias.$t, tipoNotas:this.gsx$tipodenotas.$t, emoji:this.gsx$emoji.$t, codigo:this.gsx$código.$t, id:this.gsx$id.$t, nome:this.gsx$nome.$t, secundario:this.gsx$nomessecundários.$t, rua:this.gsx$rua.$t, localidade:this.gsx$localidade.$t, marca:this.gsx$marca.$t, notas:this.gsx$notas.$t, site:this.gsx$site.$t, telefone:this.gsx$telefone.$t, servicos:this.gsx$serviços.$t, estacionamento:this.gsx$estacionamento.$t, tomadas:this.gsx$tomadas.$t, segunda:this.gsx$segunda.$t, terca:this.gsx$terça.$t, quarta:this.gsx$quarta.$t, quinta:this.gsx$quinta.$t, sexta:this.gsx$sexta.$t, sabado:this.gsx$sabado.$t, domingo:this.gsx$domingo.$t, latitude:this.gsx$latitude.$t, longitude:this.gsx$longitude.$t, campo1:this.gsx$campo1.$t, verificavalidade:this.gsx$verificavalidade.$t};
array_config_country[ this.gsx$funcionalidade.$t ] = elem;
var emoji = this.gsx$emoji.$t;
var descricao = this.gsx$descrição.$t;
array_emojis[emoji] = this.gsx$funcionalidade.$t;
array_emojis_title[emoji] = descricao;
index = index + 1;
}
});
});*/
var timer = setInterval(check_data, 100);
function check_data() {
if(Object.keys(array_config_country).length > 0 || timeout >= 50)
{
clearInterval(timer);
resolve('true');
}
timeout = timeout + 1;
}
});
}
function getDataFunc(func, link) {
return new Promise(resolve => {
fetch(link)
.then(res => res.text())
.then(text => {
const json = JSON.parse(text.substr(47).slice(0, -2))
var aux = {};
$(json.table.rows).each(function(){
let horarios = [func.segunda!=""?verifyNull(this["c"][func.segunda]):"",func.terca!=""?verifyNull(this["c"][func.terca]):"",func.quarta!=""?verifyNull(this["c"][func.quarta]):"",func.quinta!=""?verifyNull(this["c"][func.quinta]):"",func.sexta!=""?verifyNull(this["c"][func.sexta]):"",func.sabado!=""?verifyNull(this["c"][func.sabado]):"",func.domingo!=""?verifyNull(this["c"][func.domingo]):""];
var elem = {id:func.id!=""?verifyNull(this["c"][func.id]):"", nome:func.nome!=""?verifyNull(this["c"][func.nome]):"",secundario:func.secundario!=""?verifyNull(this["c"][func.secundario]):"", rua:func.rua!=""?verifyNull(this["c"][func.rua]):"", localidade:func.localidade!=""?verifyNull(this["c"][func.localidade]):"", marca:func.marca!=""?verifyNull(this["c"][func.marca]):"", notas:func.notas!=""?verifyNull(this["c"][func.notas]):"", site:func.site!=""?verifyNull(this["c"][func.site]):"", telefone:func.telefone!=""?verifyNull(this["c"][func.telefone]):"", servicos:func.servicos!=""?(isNumeric(func.servicos)?verifyNull(this["c"][func.servicos]):func.servicos):"", tomadas:func.tomadas!=""?verifyNull(this["c"][func.tomadas]):"", categoria:func.categoria!=""?(isNumeric(func.categoria)?verifyNull(this["c"][func.categoria]):func.categoria):"",horario:horarios, latitude:func.latitude!=""?verifyNull(this["c"][func.latitude]):"", longitude:func.longitude!=""?verifyNull(this["c"][func.longitude]):""};
if(verifyNull(this["c"][func.codigo]) != "")
aux[verifyNull(this["c"][func.codigo])] = elem;
});
array_dados_func[func.funcionalidade] = aux;
})
/*$.getJSON(link, function(data) {
var aux = {};
var entry = data.feed.entry;
$(entry).each(function(){
let horarios = [func.segunda!=""&&typeof this[func.segunda]!=="undefined"?this[func.segunda].$t:"",func.terca!=""&&typeof this[func.terca]!=="undefined"?this[func.terca].$t:"",func.quarta!=""&&typeof this[func.quarta]!=="undefined"?this[func.quarta].$t:"",func.quinta!=""&&typeof this[func.quinta]!=="undefined"?this[func.quinta].$t:"",func.sexta!=""&&typeof this[func.sexta]!=="undefined"?this[func.sexta].$t:"",func.sabado!=""&&typeof this[func.sabado]!=="undefined"?this[func.sabado].$t:"",func.domingo!=""&&typeof this[func.domingo]!=="undefined"?this[func.domingo].$t:""];
var elem = {id:func.id!=""&&typeof this[func.id]!=="undefined"?this[func.id].$t:"", nome:func.nome!=""&&typeof this[func.nome]!=="undefined"?this[func.nome].$t:"",secundario:func.secundario!=""&&typeof this[func.secundario]!=="undefined"?this[func.secundario].$t:"", rua:func.rua!=""&&typeof this[func.rua]!=="undefined"?this[func.rua].$t:"", localidade:func.localidade!=""&&typeof this[func.localidade]!=="undefined"?this[func.localidade].$t:"", marca:func.marca!=""&&typeof this[func.marca]!=="undefined"?this[func.marca].$t:"", notas:func.notas!=""&&typeof this[func.notas]!=="undefined"?this[func.notas].$t:"", site:func.site!=""&&typeof this[func.site]!=="undefined"?this[func.site].$t:"", telefone:func.telefone!=""&&typeof this[func.telefone]!=="undefined"?this[func.telefone].$t:"", servicos:func.servicos!=""?(func.servicos.indexOf("gsx$")!=-1?(typeof this[func.servicos]!=="undefined"?this[func.servicos].$t:""):func.servicos):"", tomadas:func.tomadas!=""&&typeof this[func.tomadas]!=="undefined"?this[func.tomadas].$t:"", categoria:func.categoria!=""?(func.categoria.indexOf("gsx$")!=-1?(typeof this[func.categoria]!=="undefined"?this[func.categoria].$t:""):func.categoria):"",horario:horarios, latitude:func.latitude!=""&&typeof this[func.latitude]!=="undefined"?this[func.latitude].$t:"", longitude:func.longitude!=""&&typeof this[func.longitude]!=="undefined"?this[func.longitude].$t:""};
if(this[func.codigo].$t != "")
aux[this[func.codigo].$t] = elem;
});
array_dados_func[func.funcionalidade] = aux;
});*/
resolve('true');
});
}
function receiveCategorias() {
return new Promise(resolve => {
fetch('https://docs.google.com/spreadsheets/d/1YIokASCZmcCheePyknPU39IlYz1gOfIuu1GwVzaFoic/gviz/tq?tqx=out:json&sheet=Categorias')
.then(res => res.text())
.then(text => {
const json = JSON.parse(text.substr(47).slice(0, -2))
let first = false;
$(json.table.rows).each(function(){
if(first == false)
{
first = true;
return;
}
array_categorias_google[verifyNull(this["c"][0])] = verifyNull(this["c"][1]);
});
})
/*$.getJSON("https://spreadsheets.google.com/feeds/list/16F6tdn5lQRemFAFP9iFvJL8rU6GzT_XmCLA41JwOGBA/3/public/values?alt=json", function(data) {
var entry = data.feed.entry;
$(entry).each(function(){
array_categorias_google[ this.gsx$waze.$t ] = this.gsx$google.$t;
});
});*/
resolve('true');
});
}
async function dataCall() {
var result = await getConfigsScript();
result = await getConfigsCountry(array_config_script[W.model.getTopCountry().abbr]);
for(var key in array_config_country)
{
if(array_config_country[key]["excel"] != "")
result = await getDataFunc(array_config_country[key],array_config_country[key]["excel"]);
}
receiveCategorias();
if (!$("#LANDMARKS").length) {
optionsUser();
}
}
function optionsUser() {
var $settings = $('<li><a href="#sidepanel-LANDMARKS" data-toggle="tab" aria-expanded="true">LANDMARKS</a></li>');
$("#user-tabs ul").append($settings);
var div_sidepnale = document.createElement("div");
div_sidepnale.id = "sidepanel-LANDMARKS";
div_sidepnale.className = "tab-pane";
var atualizar = document.createElement("button");
atualizar.innerHTML = 'Atualizar Dados';
atualizar.id = 'btnAtualizar';
atualizar.style.cssText = 'height: 25px;font-size: 11px;margin-bottom: 20px;width: 100%;background-color: greenyellow;font-weight: bold;';
atualizar.onclick = function() {
dataCall();
};
div_sidepnale.appendChild(atualizar);
var label_por_validar = document.createElement("label");
label_por_validar.innerHTML = "Landmarks por validar";
label_por_validar.style.cssText = 'font-size:13px;color:blue;';
div_sidepnale.appendChild(label_por_validar);
var nav = document.createElement("ul");
nav.className = "nav nav-tabs";
nav.style.cssText = 'margin-bottom:15px;';
$.each(array_emojis, function(emoji , func) {
if(array_config_country[func]["percorrerlista"] == 'TRUE')
{
all_percorrer.push(func);
var percorrer_emoji = document.createElement("li");
percorrer_emoji.id = func;
percorrer_emoji.innerHTML = '<a href="" data-toggle="tab" aria-expanded="true">' + emoji + '</a>';
percorrer_emoji.onclick = function() {
$("#LANDMARKS").show();
$('label[id="DATA_ID"]').text("");
$('label[id="DATA_NAME"]').text("");
$('label[id="DATA_LINE"]').text("");
validcodigo = "";
validindex = 0;
validselected = func;
open_tab(func);
};
nav.appendChild(percorrer_emoji);
}
});
div_sidepnale.appendChild(nav);
var div_landmarks = document.createElement("div");
div_landmarks.id = "LANDMARKS";
div_landmarks.style.display = "block";
var div_info = document.createElement("div");
div_info.style.display = "block";
var div_line = document.createElement("div");
div_line.style.display = "block";
var label_line = document.createElement("label");
label_line.innerHTML = "LINHA:";
label_line.style.cssText = 'font-size:15px;color:blue;';
div_line.append(label_line);
var data_line = document.createElement("label");
data_line.id = 'DATA_LINE';
data_line.innerHTML = "";
data_line.style.cssText = 'margin-left:5px;font-size:12px;color:black;';
div_line.append(data_line);
var div_id = document.createElement("div");
div_id.style.display = "block";
var label_id = document.createElement("label");
label_id.innerHTML = "CÓDIGO:";
label_id.style.cssText = 'font-size:15px;color:blue;';
div_id.append(label_id);
var data_id = document.createElement("label");
data_id.id = 'DATA_ID';
data_id.innerHTML = "";
data_id.style.cssText = 'margin-left:5px;font-size:12px;color:black;';
div_id.append(data_id);
var div_name = document.createElement("div");
div_name.style.display = "block";
var label_name = document.createElement("label");
label_name.innerHTML = "NOME:";
label_name.style.cssText = 'font-size:15px;color:blue;';
div_name.append(label_name);
var data_name = document.createElement("label");
data_name.id = 'DATA_NAME';
data_name.innerHTML = "";
data_name.style.cssText = 'margin-left:5px;font-size:12px;color:black;';
div_name.append(data_name);
div_info.append(div_line);
div_info.append(div_id);
div_info.append(div_name);
div_landmarks.prepend(div_info);
var adicionar = document.createElement("button");
adicionar.innerHTML = 'Adicionar';
adicionar.id = 'btnAdicionar';
adicionar.style.cssText = 'height: 25px;font-size:12px';
adicionar.onclick = function() {
var aux = null;
$.each(array_dados_func[validselected], function(codigo , dados) {
if(codigo == validcodigo)
{
aux = dados;
return true;
}
});
if(aux != null)
addNewLandmark(aux);
};
var seguinte = document.createElement("button");
seguinte.innerHTML = 'Seguinte';
seguinte.id = 'btnSeguinte';
seguinte.style.cssText = 'height:25px;font-size:12px;float:right;';
seguinte.onclick = function() {
let count = 1;
let existe = 0;
$.each(array_dados_func[validselected], function(codigo , dados) {
if(dados[array_config_country[validselected]["campoFinal"]] == "0" && count > validindex)
{
let newCenter = new OpenLayers.LonLat(dados.longitude, dados.latitude)
.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));
W.map.setCenter(newCenter,9);
validindex = count;
data_massive = dados;
$('label[id="DATA_ID"]').text(codigo);
$('label[id="DATA_NAME"]').text(dados.nome);
$('label[id="DATA_LINE"]').text(count + 1);
validcodigo = codigo;
existe = 1;
return false;
}
count++;
});
if(existe == 0)
alert("Já não existem landmarks para validar nesta categoria.");
};
div_landmarks.append(adicionar);
div_landmarks.append(seguinte);
div_sidepnale.appendChild(div_landmarks);
$("div.tab-content")[0].prepend(div_sidepnale);
$("#LANDMARKS").hide();
}
function getPermalink() {
let PL = "";
let center = new OpenLayers.LonLat(W.map.getCenter().lon, W.map.getCenter().lat)
.transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
PL += window.location.origin;
PL += window.location.pathname;
PL += '?env=';
PL += W.app.getAppRegionCode();
PL += '&lat=';
PL += center.lat;
PL += '&lon=';
PL += center.lon;
PL += '&zoom=';
PL += W.map.getZoom();
PL += '&venues=';
PL += W.selectionManager.getSelectedFeatures()[0]["model"]["attributes"]["id"];
return PL;
}
function open_tab(tab)
{
$.each(all_percorrer, function(index , func) {
$('div[id="' + func + '"]').removeClass("active");
});
$('div[id="' + tab + '"]').addClass("active");
$('div[id="LANDMARKS"]').show();
}
dataCall();
var error = {'nome' : 0, 'secundario' : 0, 'marca' : 0, 'categoria' : 0, 'bloqueio' : 0, 'notas' : 0, 'site' : 0, 'telefone' : 0, 'servicos' : 0, 'tomadas' : 0, 'horario' : 0, 'dados' : []};
function myTimer() {
error = {'nome' : 0, 'secundario' : 0, 'marca' : 0, 'categoria' : 0, 'bloqueio' : 0, 'notas' : 0, 'site' : 0, 'telefone' : 0, 'servicos' : 0, 'tomadas' : 0, 'horario' : 0, 'dados' : []};
var typeData = null;
if(typeof W.selectionManager.getSelectedFeatures()[0]!=="undefined")
if(W.selectionManager.getSelectedFeatures()[0].model.type == "venue")
{
if($('label[id="DATA_LINE"]').text() != "")
$("#divassociar").show();
var landmark = W.selectionManager.getSelectedFeatures()[0].model.attributes;
var final = [];
var funcionalidade = "";
$.each(array_config_country, function(func , data) {
let auxCat = [];
if(data.validarCategoria == "Sim")
{
if(landmark["categories"].includes(data.nomeCategoria))
{
if(data.validarFinal == "ID")
{
$.each(array_dados_func[func], function(codigo , dados) {
if(landmark["id"] == dados[data.campoFinal])
{
final.push(dados);
funcionalidade = func;
}
});
}
else if(data.validarFinal == "Nome")
{
$.each(array_dados_func[func], function(codigo , dados) {
if(landmark["name"].indexOf(dados[data.campoFinal]) > 0)
{
final.push(dados);
funcionalidade = func;
}
});
}
}
}
else if(data.validarFinal == "Nome")
{
$.each(array_dados_func[func], function(codigo , dados) {
if(landmark["name"].indexOf(dados[data.campoFinal]) > 0)
{
final.push(dados);
funcionalidade = func;
}
});
}
else if(data.validarFinal == "ID")
{
$.each(array_dados_func[func], function(codigo , dados) {
if(landmark["id"] == dados[data.campoFinal])
{
final.push(dados);
funcionalidade = func;
}
});
}
});
if(final.length == 1)
{
let invalido = 0;
if(array_config_country[funcionalidade]["verificavalidade"] != "")
if(final[0][array_config_country[funcionalidade]["verificavalidade"]] != "")
$("#divinvalido").hide();
else
{
$("#divinvalido").show();
invalido = 1;
}
if(array_config_country[funcionalidade]["verificavalidade"] == "")
$("#divinvalido").hide();
if(invalido == 0)
{
var aux;
if(array_config_country[funcionalidade]["nome"] != "")
{
if(array_config_country[funcionalidade]["emojiNome"] != "")
aux = array_config_country[funcionalidade]["emojiNome"] + " " + final[0]["nome"];
else
aux = final[0]["nome"];
if(aux != landmark["name"])
error["nome"] = 1;
}
if(array_config_country[funcionalidade]["secundario"] != "")
{
aux = final[0]["secundario"].split(";");
if(aux[0] != "")
{
$.each(aux, function(index , nome) {
if(!landmark["aliases"].includes(nome))
error["secundario"] = 1;
});
}
}
if(array_config_country[funcionalidade]["marca"] != "")
{
aux = final[0]["marca"];
let marcasPostos = W.model.categoryBrands.GAS_STATION;
if(marcasPostos.includes(aux))
{
if(aux != landmark["brand"])
error["marca"] = 1;
}
else
{
if(landmark["brand"] != null && landmark["brand"] != "")
error["marca"] = 1;
}
}
if(array_config_country[funcionalidade]["categoria"] != "")
{
aux = final[0]["categoria"].split(";");
$.each(aux, function(index , category) {
if(!landmark["categories"].includes(category))
error["categoria"] = 1;
});
}
if(array_config_country[funcionalidade]["notas"] != "")
{
aux = final[0]["notas"];
if(aux != "")
{
if(array_config_country[funcionalidade]["tipoNotas"] == "ALL")
{
if(landmark["description"] != aux)
error["notas"] = 1;
}
else if(landmark["description"].indexOf(aux) == -1)
error["notas"] = 1;
}
}
if(array_config_country[funcionalidade]["bloqueio"] != "")
{
aux = array_config_country[funcionalidade]["bloqueio"];
if(landmark["lockRank"] < aux && landmark["lockRank"] < W.loginManager.getUserRank())
error["bloqueio"] = 1;
}
if(array_config_country[funcionalidade]["site"] != "")
{
aux = final[0]["site"];
if(aux != "" && aux != landmark["url"])
error["site"] = 1;
else
if(aux == "" && landmark["url"] != "" && landmark["url"] != null)
error["site"] = 1;
}
if(array_config_country[funcionalidade]["telefone"] != "")
{
aux = final[0]["telefone"];
if(aux != "" && aux != landmark["phone"])
error["telefone"] = 1;
else
if(aux == "" && landmark["phone"] != "" && landmark["phone"] != null)
error["telefone"] = 1;
}
if(array_config_country[funcionalidade]["servicos"] != "")
{
aux = final[0]["servicos"].split(";");
if(aux[0] != "")
{
$.each(aux, function(index , service) {
if(!landmark["services"].includes(service))
error["servicos"] = 1;
});
}
}
if(array_config_country[funcionalidade]["tomadas"] != "" && final[0]["categoria"].indexOf("CHARGING_STATION") != -1)
{
let portsSplit = final[0]["tomadas"].split(";");
$.each(portsSplit, function(index , port) {
let aux = port.split(":");
if(aux[1] > 0)
{
if(aux[0] in landmark["evChargingPorts"])
{
if(landmark["evChargingPorts"][aux[0]] != aux[1])
error["tomadas"] = 1;
}
else
error["tomadas"] = 1;
}
});
}
error["funcionalidade"] = funcionalidade;
error["dados"] = final[0];
}
if(error["nome"] == 1 || error["secundario"] == 1 || error["marca"] == 1 || error["categoria"] == 1 || error["bloqueio"] == 1 || error["notas"] == 1 || error["site"] == 1 || error["telefone"] == 1 || error["servicos"] == 1 || error["tomadas"] == 1 || error["horario"] == 1)
$("#divuniformizar").show();
else
$("#divuniformizar").hide();
}
}
if (!$("#landmarkemoji").length) {
var landmarkemoji = document.createElement("div");
landmarkemoji.id = 'landmarkemoji';
landmarkemoji.style.cssText = 'display: inline-block;';
$.each(array_emojis, function(emoji , func) {
var addsign = document.createElement("div");
addsign.id = 'sign_' + emoji;
addsign.style.cssText = 'cursor:pointer;float:left;width:34px;height:34px;';
addsign.onclick = function() {
indexselected = emoji;
funcselected = func;
if(array_config_country[funcselected]["excel"] == "")
{
var campo1;
if(array_config_country[funcselected]["campo1"] != "")
campo1 = prompt(array_config_country[funcselected]["campo1"]);
else
campo1 = "";
if(campo1 != null)
{
if(array_config_country[funcselected]["categoria"] != "")
definecategories(array_config_country[funcselected]["categoria"].split(";"));
if(array_config_country[funcselected]["emojiNome"] != "" || array_config_country[funcselected]["nome"] != "")
{
var emoji = array_config_country[funcselected]["emojiNome"];
var nome = array_config_country[funcselected]["nome"];
if(array_config_country[funcselected]["emojiNome"].indexOf("{1}") != -1)
emoji = array_config_country[funcselected]["emojiNome"].replace("{1}", campo1)
if(array_config_country[funcselected]["nome"].indexOf("{1}") != -1)
nome = array_config_country[funcselected]["nome"].replace("{1}", campo1)
if(emoji != "" && nome != "NULL")
defineName(emoji + " " + nome);
else
if(emoji != "" && nome == "NULL")
defineName(emoji);
else
defineName(nome);
}
if(array_config_country[funcselected]["secundario"] != "")
{
if(array_config_country[funcselected]["secundario"] == "")
definealiases(new Array());
else
definealiases(array_config_country[funcselected]["secundario"].split(";"));
}
if(array_config_country[funcselected]["notas"] != "")
{
var notas = array_config_country[funcselected]["notas"];
if(array_config_country[funcselected]["notas"].indexOf("{1}") != -1)
notas = array_config_country[funcselected]["notas"].replace("{1}", campo1)
defineDescription(array_config_country[funcselected]["tipoNotas"], notas);
}
if(array_config_country[funcselected]["servicos"] != "")
defineServices(false, array_config_country[funcselected]["servicos"].split(";"));
if(array_config_country[funcselected]["bloqueio"] != "")
defineLockRank(array_config_country[funcselected]["bloqueio"]);
if(array_config_country[funcselected]["rua"] == "NONE" || array_config_country[funcselected]["localidade"] == "NONE")
defineStreetLandmark("", "", "");
if(array_config_country[funcselected]["estacionamento"] != "")
defineAttributesParking(array_config_country[funcselected]["estacionamento"]);
}
}
else
{
var code = prompt("Código");
var aux = [];
$.each(array_dados_func[funcselected], function(codigo , dados) {
if(codigo == code)
{
aux = dados;
return true;
}
});
let passa = 0;
if(array_config_country[funcselected]["verificavalidade"] != "")
if(aux[array_config_country[funcselected]["verificavalidade"]] != "")
passa = 1;
if(array_config_country[funcselected]["verificavalidade"] == "")
passa = 1;
if(passa == 1)
addDataLandmark(aux);
};
}
var title = "";
$.each(array_emojis_title, function(emoji_title , tooltip) {
if(emoji == emoji_title)
title = tooltip;
});
var emojivalue = document.createElement("div");
emojivalue.id = 'emoji_' + emoji;
emojivalue.style.cssText = 'text-align:center;font-size:14px;visibility:visible;';
emojivalue.innerHTML = emoji;
emojivalue.title = title;
addsign.appendChild(emojivalue);
landmarkemoji.appendChild(addsign);
});
$("div #venue-edit-general").prepend(landmarkemoji);
}
/*if (!$("#divassociar").length) {
var labelassociar = document.createElement("label");
labelassociar.id = 'labelassociar';
labelassociar.innerHTML = 'Deseja associar este POI á linha ' + $('label[id="DATA_LINE"]').text() + '?';
labelassociar.style.cssText = 'width:85%;font-size:11px;color:red;';
var btnassociar = document.createElement("button");
btnassociar.innerHTML = 'Sim';
btnassociar.id = 'btnassociar';
btnassociar.style.cssText = 'float:right;font-size:12px;height:21px;';
btnassociar.onclick = function() {
var form = new FormData();
form.append("line", $('label[id="DATA_LINE"]').text());
form.append("pl", getPermalink());
var settings = {
"url": "https://api.wazept.com/pois/index.php",
"method": "POST",
"timeout": 0,
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
};
$.ajax(settings).done(function (response) {
console.log(response);
});
};
var divassociar = document.createElement("div");
divassociar.id = 'divassociar';
divassociar.style.cssText = 'padding-bottom: 10px;';
divassociar.appendChild(labelassociar);
divassociar.appendChild(btnassociar);
$("div #venue-edit-general").prepend(divassociar);
$("#divassociar").hide();
}*/
if (!$("#divuniformizar").length) {
var labeluniform = document.createElement("label");
labeluniform.id = 'labeluniform';
labeluniform.innerHTML = 'Dados da landmark errados. Deseja corrigir?';
labeluniform.style.cssText = 'width:85%;font-size:11px;color:red;';
var btnuniformizar = document.createElement("button");
btnuniformizar.innerHTML = 'Sim';
btnuniformizar.id = 'btnuniformizar';
btnuniformizar.style.cssText = 'float:right;font-size:12px;height:21px;';
btnuniformizar.onclick = function() {
var funcionalidade = error["funcionalidade"];
if(error["nome"] == 1)
{
if(array_config_country[funcionalidade]["emojiNome"] != "")
defineName(array_config_country[funcionalidade]["emojiNome"] + " " + error.dados.nome);
else
defineName(error.dados.nome);
}
if(error["secundario"] == 1)
{
if(array_config_country[funcionalidade]["secundario"] != "")
{
if(error.dados.secundario == "")
definealiases(new Array());
else
definealiases(error.dados.secundario.split(";"));
}
}
if(error["categoria"] == 1)
{
definecategories(error.dados.categoria.split(";"));
}
if(error["bloqueio"] == 1)
{
defineLockRank(array_config_country[funcionalidade]["bloqueio"]);
}
if(error["marca"] == 1)
{
defineBrand(error.dados.marca);
}
if(error["notas"] == 1)
{
defineDescription(array_config_country[error.funcionalidade]["tipoNotas"], error.dados.notas);
}
if(error["telefone"] == 1)
{
definePhone(error.dados.telefone);
}
if(error["site"] == 1)
{
defineUrl(error.dados.site);
}
if(error["servicos"] == 1 || error["categoria"] == 1)
{
defineServices(error["categoria"]==1?true:false, error.dados.servicos.split(";"));
}
if(error["tomadas"] == 1)
{
definePortsEV(error.dados.tomadas);
}
};
var divuniformizar = document.createElement("div");
divuniformizar.id = 'divuniformizar';
divuniformizar.style.cssText = 'padding-bottom: 10px;';
divuniformizar.appendChild(labeluniform);
divuniformizar.appendChild(btnuniformizar);
$("div #venue-edit-general").prepend(divuniformizar);
$("#divuniformizar").hide();
}
if (!$("#divinvalido").length) {
var labelinvalido = document.createElement("label");
labelinvalido.id = 'labelinvalido';
labelinvalido.innerHTML = 'Este landmark não está validado no excel.';
labelinvalido.style.cssText = 'width:85%;font-size:11px;color:red;';
var divinvalido = document.createElement("div");
divinvalido.id = 'divinvalido';
divinvalido.style.cssText = 'padding-bottom: 10px;';
divinvalido.appendChild(labelinvalido);
$("div #venue-edit-general").prepend(divinvalido);
$("#divinvalido").hide();
}
if (!$("#nearbyGooglePlace").length && W.selectionManager.getSelectedFeatures().length > 0 && W.selectionManager.getSelectedFeatures()[0].model.type == "venue") {
var click = [];
var c, r, t;
var cont = 0;
var lat, lon;
var coord = W.selectionManager.getSelectedFeatures()[0].model.attributes.geometry.getCentroid();
var geoXY;
geoXY=new OL.LonLat(coord.x, coord.y).transform('EPSG:3857', 'EPSG:4326').transform(W.map.projection, W.map.displayProjection);
t = document.createElement('table');
t.style.cssText = 'font-size: 12px; border: 1px solid black;width:100%;';
var header = t.createTHead();
header.style.cssText = 'border: 1px solid black; background: #D3D3D3;';
var row = header.insertRow(0);
row.innerHTML = "<b>Name</b>";
var cell = row.insertCell(0);
cell.innerHTML = "<b>Dist(m)</b>";
var cell1 = row.insertCell(1);
var body = t.createTBody();
var type = "all";
if(typeof array_categorias_google[W.selectionManager.getSelectedFeatures()[0].model.attributes.categories[0]] !== 'undefined')
type= array_categorias_google[W.selectionManager.getSelectedFeatures()[0].model.attributes.categories[0]];
$.getJSON("https://api.wazept.com/places/near.php?lat=" + geoXY.lat + "&lon=" + geoXY.lon + "&type=" + type, function(data) {
$(data).each(function(){
if(typeof this['place_id'] == "undefined" || cont >= 5)
return true;
else
{
r = body.insertRow(cont);
c = r.insertCell(0);
c.innerHTML = this['name'];
c = r.insertCell(1);
c.innerHTML = "<b><u>" + this['distancia'] + "</u></b>";
c.style.cssText = 'text-align: center;';
c = r.insertCell(2);
var b = document.createElement("button");
b.innerHTML = "+";
b.style.cssText = 'width: 23px;height: 18px;font-size: 10px;';
b.id = 'putplace' + cont;
b.onclick = function() {
if(this.id == "putplace0")
definePlaceGoogle(click[0]);
if(this.id == "putplace1")
definePlaceGoogle(click[1]);
if(this.id == "putplace2")
definePlaceGoogle(click[2]);
if(this.id == "putplace3")
definePlaceGoogle(click[3]);
if(this.id == "putplace4")
definePlaceGoogle(click[4]);
}
c.appendChild(b);
click.push(this['name']);
cont = cont + 1;
}
});
});
var nearbyGooglePlace = document.createElement("div");
nearbyGooglePlace.id = 'nearbyGooglePlace';
nearbyGooglePlace.style.cssText = 'margin-top:5px;';
nearbyGooglePlace.appendChild(t);
$("div .external-providers").append(nearbyGooglePlace);
}
}
function addNewLandmark (aux) {
let AddLandmark= require("Waze/Action/AddLandmark");
var wazefeatureVectorLandmark = require("Waze/Feature/Vector/Landmark");
var poi = new wazefeatureVectorLandmark();
var geometry = new OpenLayers.Geometry.Point();
let newLocal = new OpenLayers.LonLat(aux.longitude, aux.latitude)
.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));
geometry.y = newLocal.lat;
geometry.x = newLocal.lon;
poi.geometry = geometry;
poi.attributes.categories = aux.categoria.split(";");
if(aux.nome != "")
if(array_config_country[validselected]["emojiNome"] != "")
poi.attributes.name = array_config_country[validselected]["emojiNome"] + " " + aux.nome;
else
poi.attributes.name = aux.nome;
if(array_config_country[validselected]["secundario"] != "")
{
if(aux.secundario != "")
poi.attributes.aliases = aux.secundario.split(";");
}
if(array_config_country[validselected]["bloqueio"] != "")
{
var bloquear;
if(W.loginManager.user.rank >= array_config_country[validselected]["bloqueio"])
bloquear = array_config_country[validselected]["bloqueio"];
else
bloquear = W.loginManager.user.rank;
poi.attributes.lockRank = bloquear;
}
if(aux.marca != "")
poi.attributes.brand = aux.marca;
if(aux.notas != "")
poi.attributes.description = aux.notas;
if(aux.servicos != "")
poi.attributes.services = aux.servicos.split(";");
if(aux.site != "")
poi.attributes.url = aux.site;
if(aux.telefone != "")
poi.attributes.phone = aux.telefone;
if(aux.tomadas != "" && aux.categoria.indexOf("CHARGING_STATION") != -1)
{
let finalPorts = {};
let portsSplit = aux.tomadas.split(";");
$.each(portsSplit, function(index , port) {
let aux = port.split(":");
if(aux[1] > 0)
finalPorts[aux[0]] = aux[1];
});
poi.attributes.evChargingPorts = finalPorts;
}
W.model.actionManager.add(new AddLandmark(poi));
}
function addDataLandmark (aux) {
if(aux.categoria != "")
definecategories(aux.categoria.split(";"));
if(aux.nome != "")
if(array_config_country[funcselected]["emojiNome"] != "")
defineName(array_config_country[funcselected]["emojiNome"] + " " + aux.nome);
else
defineName(aux.nome);
if(array_config_country[funcselected]["secundario"] != "")
{
if(aux.secundario == "")
definealiases(new Array());
else
definealiases(aux.secundario.split(";"));
}
if(aux.rua != "" || aux.localidade != "")
defineStreetLandmark("", aux.rua, aux.localidade);
if(array_config_country[funcselected]["bloqueio"] != "")
defineLockRank(array_config_country[funcselected]["bloqueio"]);
if(aux.marca != "")
defineBrand(aux.marca);
if(aux.notas != "")
defineDescription(array_config_country[funcselected]["tipoNotas"], aux.notas);
if(aux.servicos != "" || (typeof landmark !== 'undefined' && landmark["services"].length > 0))
defineServices(false, aux.servicos.split(";"));
if(aux.site != "")
defineUrl(aux.site);
if(aux.telefone != "")
definePhone(aux.telefone);
if(aux.tomadas != "" && aux.categoria.indexOf("CHARGING_STATION") != -1)
definePortsEV(aux.tomadas);
add_horarios(aux.horario)
}
function definePlaceGoogle (name) {
$('div.external-providers-view .add').focus().click();
setTimeout(() => {
$('a[href="#venue-edit-general"]').click();
$('.external-providers-view a.add').focus().mousedown();
$('div.external-providers-view > div > ul > div > div > li > div > a').last().mousedown();
setTimeout(() => $('.select2-input').last().focus().val(name).trigger('input'), 100);
}, 100);
}
function definecategories (categories) {
let UpdateObject= require("Waze/Action/UpdateObject");
let myPlace = W.selectionManager.getSelectedFeatures()[0].model;
W.model.actionManager.add(new UpdateObject(myPlace, {'categories': categories}));
}
function definealiases (aliases) {
let UpdateObject= require("Waze/Action/UpdateObject");
let myPlace = W.selectionManager.getSelectedFeatures()[0].model;
W.model.actionManager.add(new UpdateObject(myPlace, {'aliases': aliases}));
}
function defineBrand (brand) {
let marcasPostos = W.model.categoryBrands.GAS_STATION;
let marca = "";
if(marcasPostos.includes(brand))
marca = brand;
let UpdateObject= require("Waze/Action/UpdateObject");
let myPlace = W.selectionManager.getSelectedFeatures()[0].model;
W.model.actionManager.add(new UpdateObject(myPlace, {'brand': marca}));
}
function defineLockRank (rank) {
let UpdateObject= require("Waze/Action/UpdateObject");
var bloquear;
if(W.loginManager.user.rank >= rank)
bloquear = rank;
else
bloquear = W.loginManager.user.rank;
let myPlace = W.selectionManager.getSelectedFeatures()[0].model;
let lock = myPlace.attributes.lockRank;
if(lock < bloquear)
W.model.actionManager.add(new UpdateObject(myPlace, {'lockRank': bloquear}));
}
function defineName (name) {
let UpdateObject= require("Waze/Action/UpdateObject");
let myPlace = W.selectionManager.getSelectedFeatures()[0].model;
W.model.actionManager.add(new UpdateObject(myPlace, {'name': name}));
}
function defineServices (categoryChange, services) {
let aux = [];
if(!categoryChange)
{
let servicos = W.selectionManager.getSelectedFeatures()[0].model.attributes.services;
servicos.forEach(function(element) {
if(!aux.includes(element))
aux.push(element);
});
}
if(services[0] != "")
services.forEach(function(element) {
if(!aux.includes(element))
aux.push(element);
});
let UpdateObject= require("Waze/Action/UpdateObject");
let myPlace = W.selectionManager.getSelectedFeatures()[0].model;
W.model.actionManager.add(new UpdateObject(myPlace, {'services': aux}));
}
function defineUrl (url) {
let UpdateObject= require("Waze/Action/UpdateObject");
let myPlace = W.selectionManager.getSelectedFeatures()[0].model;
W.model.actionManager.add(new UpdateObject(myPlace, {'url': url}));
}
function definePhone (numberPhone) {
let UpdateObject= require("Waze/Action/UpdateObject");
let myPlace = W.selectionManager.getSelectedFeatures()[0].model;
W.model.actionManager.add(new UpdateObject(myPlace, {'phone': numberPhone}));
}
function defineAttributesParking (type) {
let UpdateObject= require("Waze/Action/UpdateObject");
let myPlace = W.selectionManager.getSelectedFeatures()[0].model;
let categoryAttributes = myPlace.attributes.categoryAttributes;
if(categoryAttributes.PARKING_LOT === undefined)
categoryAttributes.PARKING_LOT = {canExitWhileClosed: false, costType: "UNKNOWN", estimatedNumberOfSpots: null, hasTBR: false, lotType: [], numberOfSpots: null, parkingType: "PUBLIC", paymentType: []};
if(type == "FREE")
categoryAttributes.PARKING_LOT.costType = "FREE";
categoryAttributes.PARKING_LOT.parkingType = "PUBLIC";
W.model.actionManager.add(new UpdateObject(myPlace, {'categoryAttributes': categoryAttributes}));
}
function definePortsEV (ports) {
let finalPorts = {};
let portsSplit = ports.split(";");
$.each(portsSplit, function(index , port) {
let aux = port.split(":");
if(aux[1] > 0)
finalPorts[aux[0]] = aux[1];
});
let UpdateObject= require("Waze/Action/UpdateObject");
let myPlace = W.selectionManager.getSelectedFeatures()[0].model;
W.model.actionManager.add(new UpdateObject(myPlace, {'evChargingPorts': finalPorts}));
}
function defineDescription (type, description) {
let notas = W.selectionManager.getSelectedFeatures()[0].model.attributes.description;
if(type == "AFTER")
{
if(notas.indexOf(description) < 0)
notas = notas + description;
}
else if(type == "BEFORE")
{
if(notas.indexOf(description) < 0)
notas = description + notas;
}
else if(type == "ALL")
notas = description;
let UpdateObject= require("Waze/Action/UpdateObject");
let myPlace = W.selectionManager.getSelectedFeatures()[0].model;
W.model.actionManager.add(new UpdateObject(myPlace, {'description': notas}));
}
function defineOpenning (horarios) {
let UpdateObject= require("Waze/Action/UpdateObject");
let OpeningHours = require('Waze/Model/Objects/OpeningHour');
const hoursObjectArray = [];
horarios.forEach(function(element) {
hoursObjectArray.push(new OpeningHours(element));
});
let myPlace = W.selectionManager.getSelectedFeatures()[0].model;
W.model.actionManager.add(new UpdateObject(myPlace, {'openingHours': hoursObjectArray}));
}
function defineStreetLandmark(house, street, city) {
var wazeActionUpdateFeatureAddress = require("Waze/Action/UpdateFeatureAddress");
let UpdateObject= require("Waze/Action/UpdateObject");
var poi = W.selectionManager.getSelectedFeatures()[0].model;
var poiAddress = poi.getAddress().attributes;
var newAddressAtts = {
streetName: street,
emptyStreet: street==""?true:null,
cityName: city,
emptyCity: city==""?true:null,
stateID: poiAddress.country == null?W.model.getTopState().id:poiAddress.state.id,
countryID: poiAddress.country == null?W.model.getTopCountry().id:poiAddress.country.id
};
W.model.actionManager.add(new wazeActionUpdateFeatureAddress(poi, newAddressAtts));
//W.model.actionManager.add(new UpdateObject(poi,{houseNumber: poiobject.houseNumber.toUpperCase(),residential: isRH}));
}
function add_horarios(horarios)
{
var varios_horarios = [];
$.each(horarios, function(dia , horario) {
let aux = horario.split(";")
$.each(aux, function(index , auxhorario) {
if(auxhorario != "" && varios_horarios.length < 1)
{
varios_horarios.push(auxhorario);
return true;
}
var existe = 0;
$.each(varios_horarios, function(index , dif_horario) {
if(auxhorario == "" || dif_horario == auxhorario)
{
existe = 1;
return true;
}
});
if(auxhorario != "" && existe == 0)
varios_horarios.push(auxhorario);
});
});
if(varios_horarios.length > 0)
{
var arrayhorarios = [];
var i;
$.each(varios_horarios, function(index , dif_horario) {
let hoursObjectAdd;
hoursObjectAdd = {};
hoursObjectAdd.days = [];
$.each(horarios, function(dia , horario) {
if(horario.indexOf(dif_horario) != -1)
{
var horas = dif_horario.split("-");
hoursObjectAdd.fromHour = horas[0];
hoursObjectAdd.toHour = horas[1];
if(dia == 0)
hoursObjectAdd.days.push(1);
else if(dia == 1)
hoursObjectAdd.days.push(2);
else if(dia == 2)
hoursObjectAdd.days.push(3);
else if(dia == 3)
hoursObjectAdd.days.push(4);
else if(dia == 4)
hoursObjectAdd.days.push(5);
else if(dia == 5)
hoursObjectAdd.days.push(6);
else if(dia == 6)
hoursObjectAdd.days.push(0);
}
});
arrayhorarios.push(hoursObjectAdd);
});
defineOpenning(arrayhorarios);
}
}
function verifyNull(variable)
{
if(variable === null)
return "";
if(variable["v"] === null)
return "";
return variable["v"];
}
function isNumeric(value) {
return /^\d+$/.test(value);
}
})();