Skip to content

Commit

Permalink
Correções de erros JavaScript e melhorias
Browse files Browse the repository at this point in the history
Permite exportar CSV incluindo apenas as linhas selecionadas. Grava
corretamente os campos digitados da pesquisa. Corrige erro na pesquisa
ao digitar caracteres acentuados.
  • Loading branch information
gavlinski committed Feb 7, 2014
1 parent a973dbe commit f2c26dd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
18 changes: 15 additions & 3 deletions js/4sq.js
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,18 @@ dojo.addOnLoad(function inicializar() {
if (csv[i] != undefined)
arq[j++] = csv[i].join(";");
}
if (totalSelecionadas > 0) {
var j = 1;
var l = arq.length;
linhasSelecionadas = [];
dojo.query("input[name=selecao]:checked").forEach("linhasSelecionadas.push(dijit.byId(item.id).value)");
for (i = 0; i < l; i++) {
if (linhasSelecionadas.indexOf(i.toString()) == -1)
arq.splice(j, 1);
else
j++;
}
}
window.location.href = "data:text/csv;charset=iso-8859-1," + escape(arq.join("\r\n"));
}
});
Expand All @@ -1028,10 +1040,10 @@ dojo.addOnLoad(function inicializar() {
id: "menuItemExportarTXT",
onClick: function() {
var arq = txt.slice(0);
var j = 0;
var l = arq.length;
linhasSelecionadas = [];
if (totalSelecionadas > 0) {
var j = 0;
var l = arq.length;
linhasSelecionadas = [];
dojo.query("input[name=selecao]:checked").forEach("linhasSelecionadas.push(dijit.byId(item.id).value)");
for (i = 0; i < l; i++) {
if (linhasSelecionadas.indexOf(i.toString()) == -1)
Expand Down
22 changes: 11 additions & 11 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ dojo.addOnLoad(function() {
var ll_src = dijit.byId("ll");
dojo.connect(form_src, "onSubmit", function(e) {
if (form_src.validate()) {
if (radius.value == "") {
dijit.byId("radius").attr("value", "10000");
}
if (ll_src.value == "") {
e.preventDefault();
alert("Informe as coordenadas ou o endere&ccedil;o");
Expand All @@ -158,16 +155,20 @@ dojo.addOnLoad(function() {
var campos4 = dijit.byId("nome4").checked + "." + dijit.byId("endereco4").checked + "." + dijit.byId("ruacross4").checked + "." + dijit.byId("cidade4").checked + "." + dijit.byId("estado4").checked + "." + dijit.byId("cep4").checked + "." + dijit.byId("twitter4").checked + "." + dijit.byId("telefone4").checked + "." + dijit.byId("website4").checked + ".";
(dijit.byId("descricao4").disabled) ? campos4 += "false." : campos4 += dijit.byId("descricao4").checked + ".";
campos4 += dijit.byId("latlong4").checked;
var search = [dijit.byId("ll").value, "near", "categoryId", dijit.byId("query").value, dijit.byId("limit").value, "intent", "radius"];
var search = [dijit.byId("query").value, dijit.byId("ll").value, dijit.byId("categoryId").value, dijit.byId("radius").value, dijit.byId("intent").value, dijit.byId("limit").value];
dojo.cookie("search", JSON.stringify(search), { expires: 15 });
dojo.cookie("campos", campos4, { expires: 15 });
dojo.cookie("accordion", dijit.byId("accordion").selectedChildWidget.id, { expires: 15 });
if (radius.value == "") {
dijit.byId("radius").attr("value", "5000");
}

});
});

dojo.ready(function() {
setTimeout(function() {
if (dojo.cookie("name") != "undefined")
if ((dojo.cookie("name") != null) && (dojo.cookie("name") != "undefined"))
dojo.byId("name").innerText = dojo.cookie("name");
if (dojo.cookie("pagina") != "undefined")
dijit.byId("pagina").attr("value", dojo.cookie("pagina"));
Expand Down Expand Up @@ -208,13 +209,12 @@ dojo.ready(function() {
}
if (dojo.cookie("search") != undefined) {
var search = JSON.parse(dojo.cookie("search"));
dijit.byId("ll").attr("value", search[0]);
dijit.byId("near").attr("value", search[1]);
dijit.byId("query").attr("value", search[0]);
dijit.byId("ll").attr("value", search[1]);
dijit.byId("categoryId").attr("value", search[2]);
dijit.byId("query").attr("value", search[3]);
dijit.byId("limit").attr("value", search[4]);
dijit.byId("intent").attr("value", search[5]);
dijit.byId("radius").attr("value", search[6]);
dijit.byId("radius").attr("value", search[3]);
dijit.byId("intent").attr("value", search[4]);
dijit.byId("limit").attr("value", search[5]);
} else {
dijit.byId("ll").attr("value", dojo.cookie("coordinates"));
}
Expand Down
4 changes: 2 additions & 2 deletions main.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function carregarListaCategorias() {
}

function setLocalCache($key, $data) {
print('<script type="text/javascript">localStorage.setItem(\''.$key.'\', \''.$data.'\');</script>');
print('<script type="text/javascript">localStorage.setItem(\''.$key.'\', \''.str_replace("'", "\'", $data).'\');</script>');
print str_pad('', intval(ini_get('output_buffering')));
flush();
}
Expand Down Expand Up @@ -443,7 +443,7 @@ function setLocalCache($key, $data) {
<span class="labelIntent"><label for="intent"><a href="https://developer.foursquare.com/docs/venues/search" target="_blank">Inten&ccedil;&atilde;o</a>:</label></span>
<span class="formw">
<span class="comboboxes">
<select data-dojo-id="intent" name="intent" data-dojo-type="dijit/form/Select">
<select data-dojo-id="intent" name="intent" id="intent" data-dojo-type="dijit/form/Select">
<option value="checkin">checkin</option>
<option value="browse">browse</option>
<option value="global">global</option>
Expand Down
6 changes: 5 additions & 1 deletion search.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
</script>;');

if (isset($_POST["ll"]))
$params["ll"] = utf8_encode($_POST["ll"]);
$params["ll"] = stripAccents($_POST["ll"]);
if (isset($_POST["categoryId"]))
$params["categoryId"] = $_POST["categoryId"];
if ((isset($_POST["query"])) && ($_POST["query"] != ""))
Expand All @@ -86,6 +86,10 @@
setLocalCache("venues", addslashes($data));
echo EDIT;

function stripAccents($str) {
return strtr($str, utf8_decode('àáâãäçèéêëìíîïñòóôõöùúûüýÿÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ'), 'aaaaaceeeeiiiinooooouuuuyyAAAAACEEEEIIIINOOOOOUUUUY');
}

function filtrarArray($array) {
return array_values(array_unique($array));
}
Expand Down

0 comments on commit f2c26dd

Please sign in to comment.