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) {
return false;
}
$.ajax({
url: '/ajax/schedule/',
}).done(function (data) {
$('#grid').empty();
$('#grid').html('<div class="row"></div>');
$.each(data.data, function (idx, restaurant) {
function sort_restaurants(restaurants) {
var open = $.grep(restaurants,
function (r, idx) { return (r.open === true) });
var closed = $.grep(restaurants,
function (r, idx) { return (r.open === false) });
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
if ($('#grid .row').last().children().length < 4) {
$('#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 {
$('#grid').append('<div class="row"></div>');
$('#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 date = new Date().setHours(0,0,0,0);
// JavaScript sets 0 to Sunday instead of Monday
......@@ -56,10 +75,12 @@ $.ajax({
if (now >= Date.parse(time.start_time)) {
if (day === end_day) {
if (now <= Date.parse(time.end_time)) {
return open(restaurant.id);
restaurant.open = true;
return false;
}
} else {
return open(restaurant.id);
restaurant.open = true;
return false;
}
}
......@@ -67,21 +88,27 @@ $.ajax({
if (now <= Date.parse(time.end_time)) {
if (day === start_day) {
if (now >= Date.parse(time.start_time)) {
return open(restaurant.id);
restaurant.open = true;
return false;
}
} else {
return open(restaurant.id);
restaurant.open = true;
return false;
}
}
} else if (start_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) {
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