-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented minimal router for updating map view detail pannel.
- moved default views and urls to async folders - refactored everything to play nicely with django-leaflet
- Loading branch information
Showing
55 changed files
with
2,614 additions
and
2,551 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
/* eslint-env jquery */ | ||
|
||
$('button#add-party').click(function() { | ||
$('div#select-party').toggleClass('hidden'); | ||
$('div#new-item').toggleClass('hidden'); | ||
}); | ||
// $('button#add-party').click(function() { | ||
// $('div#select-party').toggleClass('hidden'); | ||
// $('div#new-item').toggleClass('hidden'); | ||
// }); | ||
|
||
$('table#select-list tr').click(function(event) { | ||
const target = $(event.target).closest('tr'); | ||
const relId = target.attr('data-id'); | ||
target.closest('tbody').find('tr.info').removeClass('info'); | ||
target.addClass('info'); | ||
$('input[name="id"]').val(relId); | ||
}); | ||
// $('table#select-list tr').click(function(event) { | ||
// const target = $(event.target).closest('tr'); | ||
// const relId = target.attr('data-id'); | ||
// target.closest('tbody').find('tr.info').removeClass('info'); | ||
// target.addClass('info'); | ||
// $('input[name="id"]').val(relId); | ||
// }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
$(window).load(function () { | ||
var js_files = [ | ||
'lazytiles.js', | ||
'L.TileLayer.GeoJSON.js', | ||
'map.js' | ||
]; | ||
var body = $('body') | ||
for (i in js_files) { | ||
body.append($('<script src="/static/js/smap/' + js_files[i] + '"></script>')); | ||
} | ||
}); | ||
// $(window).load(function () { | ||
// var js_files = [ | ||
// 'lazytiles.js', | ||
// // 'L.TileLayer.GeoJSON.js', | ||
// // 'map.js', | ||
// 'routes.js', | ||
// 'router.js' | ||
// ]; | ||
// var body = $('body'); | ||
// for (var i in js_files) { | ||
// body.append($('<script src="/static/js/smap/' + js_files[i] + '"></script>')); | ||
// } | ||
// // var sr = new SimpleRouter(); | ||
// // sr.router(); | ||
// }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet-geocoder-mapzen/1.4.0/leaflet-geocoder-mapzen.js"></script> | ||
<script src="{% static 'js/leaflet.markercluster.js' %}"></script> | ||
<script src="{% static 'js/L.Map.Deflate.js' %}"></script> | ||
<script src="{% static 'js/jquery-ui.min.js' %}"></script> | ||
{% if get_current_language != "en-us" %} | ||
{% get_current_language as LANGUAGE_CODE %} | ||
<script src="https://cdn.rawgit.com/jquery/jquery-ui/1.12.1/ui/i18n/datepicker-{{ LANGUAGE_CODE }}.js"></script> | ||
{% endif %} | ||
<script src="{% static 'js/map_utils.js' %}"></script> --> | ||
<script> | ||
$(document).ready(function () { | ||
$(window).on('map:init', function(e) { | ||
if (e.detail) { | ||
var detail = e.detail; | ||
} else { | ||
var detail = e.originalEvent.detail; | ||
} | ||
var map = detail.map; | ||
var options = detail.options; | ||
switch_layer_controls(map, options); | ||
|
||
var orgSlug = '{{ object.organization.slug }}'; | ||
var projectSlug = '{{ object.slug }}'; | ||
var url = '/api/v1/organizations/' | ||
+ orgSlug + '/projects/' + projectSlug + '/spatialresources/'; | ||
add_spatial_resources(map, url); | ||
|
||
add_map_controls(map); | ||
renderFeatures(detail.map, | ||
'{% url "async:spatial:list" object.organization.slug object.slug %}?exclude={{location.id}}'); | ||
|
||
// Enable edit mode on map load and save the geometry on page save | ||
setTimeout(enableMapEditMode, 500); | ||
$('input.btn-primary')[0].addEventListener('click', saveOnMapEditMode); | ||
}); | ||
|
||
$('.datepicker').datepicker({ | ||
yearRange: "c-200:c+200", | ||
changeMonth: true, | ||
changeYear: true, | ||
}); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Based on http://joakim.beng.se/blog/posts/a-javascript-router-in-20-lines.html | ||
var SimpleRouter = function(map){ | ||
routes = new CreateRoutes(map); | ||
|
||
var el = null; | ||
function router() { | ||
var hash_path = location.hash.slice(1) || '/'; | ||
var view_url = '/async' + location.pathname; | ||
|
||
if (hash_path !== '/') { | ||
view_url = view_url + hash_path.substr(1) + '/'; | ||
} | ||
|
||
var route = routes[hash_path] ? routes[hash_path] : null; | ||
|
||
// Removes record id from hash_path to match key in routes. | ||
if (!route) { | ||
var records = ['/records/location', '/records/relationship'] | ||
var actions = ['/edit', '/delete', '/resources/add', '/resources/new', '/relationships/new'] | ||
var new_hash_path; | ||
|
||
for (var i in records) { | ||
if (hash_path.includes(records[i])) { | ||
new_hash_path = records[i]; | ||
} | ||
} | ||
|
||
for (var i in actions) { | ||
if (hash_path.includes(actions[i])) { | ||
new_hash_path = new_hash_path + actions[i] | ||
} | ||
} | ||
route = routes[new_hash_path]; | ||
console.log(new_hash_path); | ||
console.log(view_url); | ||
} | ||
|
||
|
||
el = route.controller() || document.getElementById('project-detail'); | ||
|
||
$.get(view_url, function(response){ | ||
el.innerHTML = response; | ||
if (route.eventHook) { | ||
route.eventHook(view_url); | ||
} | ||
}); | ||
} | ||
|
||
return { | ||
router: router, | ||
}; | ||
}; | ||
|
||
$(window).on('map:init', function (e) { | ||
var detail = e.originalEvent ? | ||
e.originalEvent.detail : e.detail; | ||
console.log(detail.map); | ||
var sr = new SimpleRouter(detail.map); | ||
window.addEventListener('hashchange', sr.router); | ||
window.addEventListener('load', sr.router); | ||
}); | ||
|
Oops, something went wrong.