Skip to content
Permalink
Browse files

refactor 5: logically group functionality

  • Loading branch information
bbraithwaite committed Apr 9, 2015
1 parent bf37619 commit 78067d0e50b8a8588d7dbad14420e7ac6a86a0d7
Showing with 85 additions and 73 deletions.
  1. +85 −73 app/index.html
@@ -39,7 +39,17 @@

google.maps.event.addDomListener(window, 'load', initialize);

/*
* Search Panel
*/
function SearchControl(controlDiv, map) {
var movieClicked = function(item) {
map.clearMarkers();
map.setOptions({ streetViewControl: false, zoomControl: true });
document.getElementById('films_results').innerHTML = '';
document.getElementById('q').value = item.title;
showMovieDetail(item);
};

var searchInput = document.createElement('input');
searchInput.type = 'search';
@@ -54,7 +64,7 @@
label: 'title',
value: 'releaseYear',
select: function(item) {
clicked(item);
movieClicked(item);
}
});

@@ -63,78 +73,10 @@
controlDiv.appendChild(resultsUI);
}

function clicked(item) {

map.clearMarkers();
map.setOptions({ streetViewControl: false, zoomControl: true });

document.getElementById('films_results').innerHTML = '';

detailPanel(item.title);

document.getElementById('q').value = item.title;

setMoveDetail(item.title, item.director);

var xhr = new XMLHttpRequest();
xhr.onload = function() {
var response = this.response;
for (var i = 0; i < response.locations.length; i++) {
map.plotLocation(
response.locations[i].geo.lat,
response.locations[i].geo.lng,
zoom(response, response.locations[i]));
};
}
xhr.open("GET", "/movies/locations?title=" + encodeURIComponent(item.title) + '&director=' + encodeURIComponent(item.director));
xhr.responseType = "json";
xhr.send();
}

function detailPanel(response) {
var locationDiv = document.getElementById('location_detail');
if (locationDiv) {
locationDiv.style.display = 'none';
}

var dashboard = document.getElementById('dashboard');
if (dashboard) {
dashboard.style.display = 'none';
}

if (!document.getElementById('film_detail')) {

// Set CSS for the control interior.
var controlText = document.createElement('div');
controlText.id = 'film_detail';
controlText.className = 'film_detail';
controlText.innerHTML = templates.loading(response);

document.getElementById('bottom_panel').appendChild(controlText);

} else {

var controlText = document.getElementById('film_detail');
controlText.innerHTML = templates.loading(response);;
controlText.style.display = '';

}
}

function setMoveDetail(title, director) {

var xhr = new XMLHttpRequest();
xhr.onload = function() {
var detail = this.response;

document.getElementById('film_detail').innerHTML = templates.movie(detail);
}
xhr.open("GET", "/movies/content?title=" + encodeURIComponent(title) + '&director=' + encodeURIComponent(director));
xhr.responseType = "json";
xhr.send();
}

function zoom(detail, location) {
/*
* Movie Detail
*/
function showLocation(detail, location) {
return function() {
map.zoomView(location.geo.lat, location.geo.lng);

@@ -201,6 +143,76 @@
}
}

/*
* Movie Detail
*/
function showMovieDetail(item) {
displayLoadingPanel(item.title);
getMoveDetail(item.title, item.director);
plotLocations(item);
}

function plotLocations(item) {
var xhr = new XMLHttpRequest();
xhr.onload = function() {
var response = this.response;
for (var i = 0; i < response.locations.length; i++) {
map.plotLocation(
response.locations[i].geo.lat,
response.locations[i].geo.lng,
showLocation(response, response.locations[i]));
};
}
xhr.open("GET", "/movies/locations?title=" + encodeURIComponent(item.title) + '&director=' + encodeURIComponent(item.director));
xhr.responseType = "json";
xhr.send();
}

function displayLoadingPanel(response) {
var locationDiv = document.getElementById('location_detail');
if (locationDiv) {
locationDiv.style.display = 'none';
}

var dashboard = document.getElementById('dashboard');
if (dashboard) {
dashboard.style.display = 'none';
}

if (!document.getElementById('film_detail')) {

// Set CSS for the control interior.
var controlText = document.createElement('div');
controlText.id = 'film_detail';
controlText.className = 'film_detail';
controlText.innerHTML = templates.loading(response);

document.getElementById('bottom_panel').appendChild(controlText);

} else {

var controlText = document.getElementById('film_detail');
controlText.innerHTML = templates.loading(response);;
controlText.style.display = '';

}
}

function getMoveDetail(title, director) {
var xhr = new XMLHttpRequest();
xhr.onload = function() {
var detail = this.response;

document.getElementById('film_detail').innerHTML = templates.movie(detail);
}
xhr.open("GET", "/movies/content?title=" + encodeURIComponent(title) + '&director=' + encodeURIComponent(director));
xhr.responseType = "json";
xhr.send();
}

/*
* Homepage Panel
*/
function HomeControl(controlDiv, map) {
var dashBoard = document.createElement('div');
dashBoard.innerHTML = templates.home();

0 comments on commit 78067d0

Please sign in to comment.