Commit 842b0ee3 authored by Daniel Bond's avatar Daniel Bond
Browse files

Merge branch 'master' of github.com:thallada/whats-open

dammit Tyler, changing the same files as me!
parents 581555fc 7de27188
......@@ -26,7 +26,7 @@ div.container{
line-height:1;
}
.open{
.opened{
color:ForestGreen;
font-weight:bold;
font-size:200%;
......
function close(id) {
$('#grid #' + id).removeClass('open');
$('#grid #' + id).addClass('closed');
return false;
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 open(id) {
$('#grid #' + id).removeClass('closed');
$('#grid #' + id).addClass('open');
return false;
}
$.ajax({
url: '/ajax/schedule/',
}).done(function (data) {
$('#grid').empty();
$('#grid').html('<div class="row"></div>');
$.each(data.data, function (idx, restaurant) {
function construct_grid(restaurants) {
restaurants = sort_restaurants(restaurants);
$.each(restaurants, function (idx, restaurant) {
var open_class = 'closed';
if (restaurant.open) {
open_class = 'opened';
}
// 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 +63,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 +76,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