Issue #411
This commit is contained in:
parent
569cea5002
commit
c76c8d5396
@ -46,15 +46,7 @@ App.loadRestaurant = function(id) {
|
|||||||
App.cache('Restaurant', id,function() {
|
App.cache('Restaurant', id,function() {
|
||||||
|
|
||||||
if (!this.open()) {
|
if (!this.open()) {
|
||||||
var hours = '';
|
alert("This restaurant is currently closed. It will be open during the following hours (" + this._tzabbr + "):\n\n" + this.closedMessage());
|
||||||
for (var x in this._hours) {
|
|
||||||
hours += x + ': ';
|
|
||||||
for (var xx in this._hours[x]) {
|
|
||||||
hours += this._hours[x][xx][0] + ' - ' + this._hours[x][xx][1] + (xx == 0 ? ', ' : '');
|
|
||||||
}
|
|
||||||
hours += "\n";
|
|
||||||
}
|
|
||||||
alert("This restaurant is currently closed. It will be open during the following hours (" + this._tzabbr + "):\n\n" + hours);
|
|
||||||
App.busy.unBusy();
|
App.busy.unBusy();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -31,6 +31,10 @@ if (!typeof(App) == 'undefined') {
|
|||||||
App = {};
|
App = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
App.capitalize = function( word ){
|
||||||
|
return word.charAt(0).toUpperCase() + word.slice(1);
|
||||||
|
}
|
||||||
|
|
||||||
App.request = function(url, complete) {
|
App.request = function(url, complete) {
|
||||||
$.getJSON(url,function(json) {
|
$.getJSON(url,function(json) {
|
||||||
complete(json);
|
complete(json);
|
||||||
|
|||||||
@ -202,6 +202,60 @@ var Restaurant = function(id) {
|
|||||||
return ( miles <= this.delivery_radius )
|
return ( miles <= this.delivery_radius )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.closedMessage = function(){
|
||||||
|
|
||||||
|
var isOpenedAt = {};
|
||||||
|
var openTime = this._hours;
|
||||||
|
var weekdayOrder = [ 'Sun','Mon','Tue','Wed','Thu','Fri','Sat' ];
|
||||||
|
for ( var day in openTime ) {
|
||||||
|
var hours = openTime[ day ];
|
||||||
|
var key = '';
|
||||||
|
var openedHoursText = '';
|
||||||
|
var openedHoursTextDivisor = '';
|
||||||
|
for( var hour in hours ){
|
||||||
|
var open = hours[ hour ][ 0 ];
|
||||||
|
var close = hours[ hour ][ 1 ];
|
||||||
|
key += open + close;
|
||||||
|
openedHoursText += openedHoursTextDivisor + App.formatTime( open ).toLowerCase() + ' - ' + App.formatTime( close ).toLowerCase();
|
||||||
|
openedHoursTextDivisor = ', ';
|
||||||
|
}
|
||||||
|
// Remove the : to create an object key
|
||||||
|
key = key.replace( /\:/g, '' );
|
||||||
|
if( !isOpenedAt[ key ] ){
|
||||||
|
isOpenedAt[ key ] = { days : {}, hours : {} };
|
||||||
|
}
|
||||||
|
isOpenedAt[ key ][ 'days' ][ day ] = true;
|
||||||
|
isOpenedAt[ key ][ 'hour' ] = openedHoursText;
|
||||||
|
}
|
||||||
|
|
||||||
|
var _opened = {};
|
||||||
|
for( var hour in isOpenedAt ){
|
||||||
|
var days = isOpenedAt[ hour ][ 'days' ];
|
||||||
|
var commas = '';
|
||||||
|
var keys = '';
|
||||||
|
for( day in days ){
|
||||||
|
keys += commas + App.capitalize( day );
|
||||||
|
commas = ', ';
|
||||||
|
}
|
||||||
|
keys += ': ';
|
||||||
|
hours = isOpenedAt[hour][ 'hour' ];
|
||||||
|
_opened[ keys ] = hours;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort the hours according to the weekdayOrder sequence
|
||||||
|
var ordered = [];
|
||||||
|
for ( var index = 0; index < weekdayOrder.length; ++index) {
|
||||||
|
var weekday = weekdayOrder[ index ];
|
||||||
|
for( var day in _opened ){
|
||||||
|
var regexp = new RegExp( '^' + weekday, 'i' )
|
||||||
|
if( regexp.test( day ) ){
|
||||||
|
ordered.push( day + _opened[ day ] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ordered.join( '\n' );
|
||||||
|
}
|
||||||
|
|
||||||
self.preset = function() {
|
self.preset = function() {
|
||||||
return self['_preset'];
|
return self['_preset'];
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user