Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
GeoInt_SIDT
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mario Chirinos Colunga
GeoInt_SIDT
Commits
94bd0ac2
Commit
94bd0ac2
authored
May 24, 2018
by
Renán Sosa Guillen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
option list updated
parent
8a9af8f3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
118 additions
and
79 deletions
+118
-79
dataRetrieval.js
catalog/static/js/dataRetrieval.js
+101
-45
views.py
catalog/views.py
+17
-34
No files found.
catalog/static/js/dataRetrieval.js
View file @
94bd0ac2
...
@@ -40,24 +40,10 @@
...
@@ -40,24 +40,10 @@
// request.send({
// request.send({
// value: value
// value: value
// });
// });
var
OPT_LIST_IS_HIDDEN
=
true
;
$
(
document
).
ready
(
function
()
{
var
makeRequest
=
function
(
value
)
{
var
input
=
document
.
getElementById
(
'ajax-input'
);
var
pol_element
=
document
.
getElementById
(
'polygon-list'
);
var
dataList
=
document
.
getElementById
(
'polygon-list'
);
$
(
'#ajax-input'
).
on
(
'input'
,
function
(
e
)
{
var
value
=
$
(
this
).
val
();
if
(
value
===
''
)
{
$
(
'#option-list'
).
hide
();
var
nodeList
=
document
.
getElementById
(
'polygon-list'
)
while
(
nodeList
.
firstChild
)
{
nodeList
.
removeChild
(
nodeList
.
firstChild
);
}
return
}
console
.
log
(
value
);
// console.log("TOKEN: ", document.getElementsByName('csrfmiddlewaretoken')[0].value);
$
.
ajax
({
$
.
ajax
({
type
:
"POST"
,
type
:
"POST"
,
...
@@ -69,28 +55,98 @@ $(document).ready(function () {
...
@@ -69,28 +55,98 @@ $(document).ready(function () {
dataType
:
'json'
,
dataType
:
'json'
,
success
:
function
(
data
)
{
success
:
function
(
data
)
{
console
.
log
(
"DATA: "
,
data
.
polygonList
);
console
.
log
(
"DATA: "
,
data
.
polygonList
);
// data.forEach(function(polygon) {
// console.log(polygon);
while
(
pol_element
.
firstChild
)
{
// // Create a new <option> element
pol_element
.
removeChild
(
pol_element
.
firstChild
);
// var option = document.createElement('option');
}
// // Set the value using the item in the JSON array
// option.value = polygon.city + " " + polygon.state;
// // Add the <option> element to the <datalist>.
// dataList.appendChild(option);
// });
data
.
polygonList
.
forEach
(
function
(
polygon
)
{
data
.
polygonList
.
forEach
(
function
(
polygon
)
{
$
(
'#polygon-list'
).
append
(
'<li class="pol">'
+
polygon
.
city
+
" "
+
polygon
.
state
+
'</li
>'
);
$
(
'#polygon-list'
).
append
(
'<a href="#"><li class="pol">'
+
polygon
.
city
+
", "
+
polygon
.
state
+
'</li></a
>'
);
});
});
if
(
OPT_LIST_IS_HIDDEN
)
{
$
(
'#option-list'
).
show
();
$
(
'#option-list'
).
show
();
// $('#ajax-input').autocomplete({
OPT_LIST_IS_HIDDEN
=
false
;
// source: data.polygonList,
}
// minLength: 3
// });
}
}
});
});
});
}
$
(
'#ajax-input'
).
focus
(
function
()
{
console
.
log
(
'in'
);
if
(
OPT_LIST_IS_HIDDEN
&&
$
(
this
).
val
()
!=
''
)
{
// console.log('makeRequest');
makeRequest
(
$
(
this
).
val
());
}
});
$
(
document
).
click
(
function
(
event
)
{
if
(
!
OPT_LIST_IS_HIDDEN
)
{
//if click is triggered outside '#option-list' element remove the list
if
(
!
$
(
event
.
target
).
closest
(
'#option-list'
).
length
>
0
)
{
$
(
'#option-list'
).
hide
();
var
pol_element
=
document
.
getElementById
(
'polygon-list'
);
while
(
pol_element
.
firstChild
)
{
pol_element
.
removeChild
(
pol_element
.
firstChild
);
}
OPT_LIST_IS_HIDDEN
=
true
;
}
}
});
$
(
document
).
ready
(
function
()
{
// var input = document.getElementById('ajax-input');
// var dataList = document.getElementById('polygon-list');
var
pol_element
=
document
.
getElementById
(
'polygon-list'
);
$
(
'#option-list'
).
focusout
(
function
()
{
$
(
'#ajax-input'
).
on
(
'input'
,
function
(
e
)
{
$
(
this
).
hide
();
var
value
=
$
(
this
).
val
();
if
(
value
===
''
)
{
$
(
'#option-list'
).
hide
();
while
(
pol_element
.
firstChild
)
{
pol_element
.
removeChild
(
pol_element
.
firstChild
);
}
OPT_LIST_IS_HIDDEN
=
true
;
return
}
console
.
log
(
value
);
// console.log("TOKEN: ", document.getElementsByName('csrfmiddlewaretoken')[0].value);
makeRequest
(
value
);
// $.ajax({
// type: "POST",
// url: "http://localhost:8080/catalog/searchsubmit/",
// data: {
// 'csrfmiddlewaretoken': document.getElementsByName('csrfmiddlewaretoken')[0].value,
// 'value': value
// },
// dataType: 'json',
// success: function(data) {
// console.log("DATA: ", data.polygonList);
// while (pol_element.firstChild) {
// pol_element.removeChild(pol_element.firstChild);
// }
// data.polygonList.forEach(function (polygon) {
// $('#polygon-list').append('<a href="#"><li class="pol">' + polygon.city + ", " + polygon.state + '</li></a>');
// });
// if (OPT_LIST_IS_HIDDEN) {
// $('#option-list').show();
// OPT_LIST_IS_HIDDEN = false;
// }
// }
// });
});
});
// $('#option-list').focusout(function () {
// $(this).hide();
// });
});
});
\ No newline at end of file
catalog/views.py
View file @
94bd0ac2
...
@@ -9,7 +9,7 @@ from django.urls import reverse
...
@@ -9,7 +9,7 @@ from django.urls import reverse
from
django.views.generic.base
import
View
from
django.views.generic.base
import
View
from
django.template
import
loader
from
django.template
import
loader
from
urllib
import
urlencode
from
urllib
import
urlencode
import
requests
,
json
import
requests
,
json
,
unicodedata
# Create your views here.
# Create your views here.
...
@@ -54,46 +54,29 @@ class SearchSubmitView(View):
...
@@ -54,46 +54,29 @@ class SearchSubmitView(View):
template
=
'map.html'
template
=
'map.html'
# template = 'search_submit.html'
# template = 'search_submit.html'
state_parser
=
{
state_parser
=
{
'01'
:
"Aguascalientes"
,
'01'
:
"Aguascalientes"
,
'02'
:
"Baja California"
,
'03'
:
"Baja California Sur"
,
'04'
:
"Campeche"
,
'02'
:
"Baja California"
,
'05'
:
"Chiapas"
,
'06'
:
"Chihuahua"
,
'07'
:
"Ciudad de México"
,
'08'
:
"Coahuila"
,
'03'
:
"Baja California Sur"
,
'09'
:
"Colima"
,
'10'
:
"Durango"
,
'11'
:
"Guanajuato"
,
'12'
:
"Guerrero"
,
'04'
:
"Campeche"
,
'13'
:
"Hidalgo"
,
'14'
:
"Jalisco"
,
'15'
:
"México"
,
'16'
:
"Michoacán"
,
'05'
:
"Chiapas"
,
'17'
:
"Morelos"
,
'18'
:
"Nayarit"
,
'19'
:
"Nuevo León"
,
'20'
:
"Oaxaca"
,
'06'
:
"Chihuahua"
,
'21'
:
"Puebla"
,
'22'
:
"Querétaro"
,
'23'
:
"Quintana Roo"
,
'24'
:
"San Luis Potosí"
,
'07'
:
"Ciudad de México"
,
'25'
:
"Sinaloa"
,
'26'
:
"Sonora"
,
'27'
:
"Tabasco"
,
'28'
:
"Tamaulipas"
,
'08'
:
"Coahuila"
,
'29'
:
"Tlaxcala"
,
'30'
:
"Veracruz"
,
'31'
:
"Yucatán"
,
'32'
:
"Zacatecas"
'09'
:
"Colima"
,
'10'
:
"Durango"
,
'11'
:
"Guanajuato"
,
'12'
:
"Guerrero"
,
'13'
:
"Hidalgo"
,
'14'
:
"Jalisco"
,
'15'
:
"México"
,
'16'
:
"Michoacán"
,
'17'
:
"Morelos"
,
'18'
:
"Nayarit"
,
'19'
:
"Nuevo León"
,
'20'
:
"Oaxaca"
,
'21'
:
"Puebla"
,
'22'
:
"Querétaro"
,
'23'
:
"Quintana Roo"
,
'24'
:
"San Luis Potosí"
,
'25'
:
"Sinaloa"
,
'26'
:
"Sonora"
,
'27'
:
"Tabasco"
,
'28'
:
"Tamaulipas"
,
'29'
:
"Tlaxcala"
,
'30'
:
"Veracruz"
,
'31'
:
"Yucatán"
,
'32'
:
"Zacatecas"
}
}
def
strip_accents
(
self
,
s
):
return
''
.
join
((
c
for
c
in
unicodedata
.
normalize
(
'NFD'
,
s
)
if
unicodedata
.
category
(
c
)
!=
'Mn'
))
def
post
(
self
,
request
):
def
post
(
self
,
request
):
template
=
loader
.
get_template
(
self
.
template
)
template
=
loader
.
get_template
(
self
.
template
)
searchValue
=
request
.
POST
.
get
(
'value'
,
''
)
searchValue
=
request
.
POST
.
get
(
'value'
,
''
)
searchValue
=
self
.
strip_accents
(
searchValue
)
.
lower
()
## A simple query for Polygon objects whose name is 'searchValue'
## A simple query for Polygon objects whose name is 'searchValue'
polygonList
=
Polygon
.
objects
.
filter
(
name
=
searchValue
)
# polygonList = Polygon.objects.filter(name=searchValue)
polygonList
=
Polygon
.
objects
.
filter
(
name__startswith
=
searchValue
)
# data = []
# data = []
list
=
[]
list
=
[]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment