Commit abd60801 authored by Tyler Hallada's avatar Tyler Hallada
Browse files

Sort grid by open status after alphabetical sort

parent 024a9ebb
...@@ -10,23 +10,42 @@ function open(id) { ...@@ -10,23 +10,42 @@ function open(id) {
return false; return false;
} }
$.ajax({ function sort_restaurants(restaurants) {
url: '/ajax/schedule/', var open = $.grep(restaurants,
}).done(function (data) { function (r, idx) { return (r.open === true) });
$('#grid').empty(); var closed = $.grep(restaurants,
$('#grid').html('<div class="row"></div>'); function (r, idx) { return (r.open === false) });
$.each(data.data, function (idx, restaurant) { return $.merge(open, closed);
}
function construct_grid(restaurants) {
restaurants = sort_restaurants(restaurants);
$.each(restaurants, function (idx, restaurant) {
var open_class = 'closed';
if (restaurant.open) {
open_class = 'open';
}
// Append the data into the Bootstrap scaffolding // Append the data into the Bootstrap scaffolding
if ($('#grid .row').last().children().length < 4) { if ($('#grid .row').last().children().length < 4) {
$('#grid .row').last().append( $('#grid .row').last().append(
'<div class="span3 closed" id="' + restaurant.id + '">' + restaurant.name + '</div>' '<div class="span3 ' + open_class + '" id="' + restaurant.id + '">' + restaurant.name + '</div>'
); );
} else { } else {
$('#grid').append('<div class="row"></div>'); $('#grid').append('<div class="row"></div>');
$('#grid .row').last().append( $('#grid .row').last().append(
'<div class="span3 closed" id="' + restaurant.id + '">' + restaurant.name + '</div>' '<div class="span3 ' + open_class + '" id="' + restaurant.id + '">' + restaurant.name + '</div>'
); );
} }
});
}
$.ajax({
url: '/ajax/schedule/',
}).done(function (data) {
$('#grid').empty();
$('#grid').html('<div class="row"></div>');
var restaurants = data.data;
$.each(restaurants, function (idx, restaurant) {
var now = new Date(); var now = new Date();
var date = new Date().setHours(0,0,0,0); var date = new Date().setHours(0,0,0,0);
// JavaScript sets 0 to Sunday instead of Monday // JavaScript sets 0 to Sunday instead of Monday
...@@ -56,10 +75,12 @@ $.ajax({ ...@@ -56,10 +75,12 @@ $.ajax({
if (now >= Date.parse(time.start_time)) { if (now >= Date.parse(time.start_time)) {
if (day === end_day) { if (day === end_day) {
if (now <= Date.parse(time.end_time)) { if (now <= Date.parse(time.end_time)) {
return open(restaurant.id); restaurant.open = true;
return false;
} }
} else { } else {
return open(restaurant.id); restaurant.open = true;
return false;
} }
} }
...@@ -67,21 +88,27 @@ $.ajax({ ...@@ -67,21 +88,27 @@ $.ajax({
if (now <= Date.parse(time.end_time)) { if (now <= Date.parse(time.end_time)) {
if (day === start_day) { if (day === start_day) {
if (now >= Date.parse(time.start_time)) { if (now >= Date.parse(time.start_time)) {
return open(restaurant.id); restaurant.open = true;
return false;
} }
} else { } else {
return open(restaurant.id); restaurant.open = true;
return false;
} }
} }
} else if (start_day < end_day) { } else if (start_day < end_day) {
if (day > start_day && day < end_day) { if (day > start_day && day < end_day) {
return open(restaurant.id); restaurant.open = true;
return false;
} }
} else if (start_day > end_day) { } else if (start_day > end_day) {
if (day < start_day || day > end_day) { if (day < start_day || day > end_day) {
return open(restaurant.id); restaurant.open = true;
return false;
} }
} }
restaurant.open = false;
}); });
}); });
construct_grid(restaurants);
}); });
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment