partial angular implimentation
This commit is contained in:
parent
767a4a0200
commit
86241000de
@ -105,6 +105,7 @@ $(function() {
|
||||
<script src="/assets/js/suggestions.js?v=<?=Cana_Util::gitVersion()?>"></script>
|
||||
<? endif ; ?>
|
||||
|
||||
<script src="/assets/js/cart.js?v=<?=Cana_Util::gitVersion()?>"></script>
|
||||
<script src="/assets/js/orm.js?v=<?=Cana_Util::gitVersion()?>"></script>
|
||||
<script src="/assets/js/community.js?v=<?=Cana_Util::gitVersion()?>"></script>
|
||||
<script src="/assets/js/restaurant.js?v=<?=Cana_Util::gitVersion()?>"></script>
|
||||
|
||||
@ -1,85 +1 @@
|
||||
<div class="main-content-readable home-greeting">
|
||||
<div class="home-welcome home-welcome-click">
|
||||
<h1>Push a button. Get Food.</h1>
|
||||
<h2>
|
||||
Order the top food in your area.
|
||||
<br />
|
||||
After you order, everything is saved for future 1 click ordering.
|
||||
<br />
|
||||
<strong>Enter your Address:</strong>
|
||||
</h2>
|
||||
</div>
|
||||
<div class="home-welcome home-welcome-touch">
|
||||
<h1>Push a button. Get Food.</h1>
|
||||
<h2>
|
||||
Order the top food in your area.
|
||||
<br />
|
||||
After you order, everything is saved for future 1 click ordering.
|
||||
<br />
|
||||
<strong>Enter your Address:</strong>
|
||||
</h2>
|
||||
</div>
|
||||
</div>
|
||||
<div class="enter-location">
|
||||
<form class="button-letseat-formform" onsubmit="return false;">
|
||||
<table class="button-letseat-table" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td style="width: 100%;">
|
||||
<input type="text" class="location-address" placeholder="Enter your zip code or full address"<%= autofocus %>>
|
||||
</td>
|
||||
<td><div class="location-detect">
|
||||
<div class="location-detect-icon"></div>
|
||||
<div class="location-detect-loader"></div>
|
||||
</div></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
<div class="divider"></div>
|
||||
<button class="button-letseat-form button-bottom"><div>Let's Eat!</div></button>
|
||||
<div class="error-location" style="display: none;">
|
||||
<div class="content-item-locations">
|
||||
<h1>Crunchbutton by city:</h1>
|
||||
<div class="content-item-locations-cities">
|
||||
<% _.each(topCommunities, function(alias) { %>
|
||||
<span class="content-item-locations-city" permalink="<%= alias.alias %>"><%= alias.name %></span>
|
||||
<% }); %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="main-content-readable">
|
||||
<div class="home-welcome home-welcom-error">
|
||||
<h1>Sorry!</h1>
|
||||
<h2>
|
||||
We don't serve <span class="loc-your-area change-location-inline"><%= yourArea %></span> yet. Please click <span class="change-location-inline">here</span> to enter a different address, or recommend your favorite restaurant and we'll add it to the site!
|
||||
</h2>
|
||||
</div>
|
||||
<div class="divider"></div>
|
||||
<div class="home-recommend">
|
||||
<div class="home-recommend-form">
|
||||
<div class="home-recommend-title">
|
||||
<h1><strong>Recommend a restaurant:</strong></h1>
|
||||
</div>
|
||||
<input type="text" class="home-recommend-text">
|
||||
<button class="home-recommend-button"><div>Recommend!</div></button>
|
||||
<div class="divider"></div>
|
||||
<div class="home-recommend-message">
|
||||
What's your absolute favorite? What should be on Crunchbutton? Tell us, and we'll actually add it and get back to you.
|
||||
</div>
|
||||
<div class="divider"></div>
|
||||
</div>
|
||||
<div class="home-recommend-thank-you">
|
||||
<div class="home-recommend-title">
|
||||
<h1>Awesome, thanks!</h1>
|
||||
</div>
|
||||
<div class="divider"></div>
|
||||
<div class="home-recommend-message-thank-you">
|
||||
<% if( App.config.user.has_auth ) { %>
|
||||
We'll let you know if they make it to Crunchbutton.
|
||||
<% } else { %>
|
||||
<a href="#" class="home-recommend-message-create-account"><span>Create an account</span></a> and when we'll let you know when we launch in your area!
|
||||
<% } %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
1
include/views/default/crunchbutton/frontend/legal.phtml
Normal file
1
include/views/default/crunchbutton/frontend/legal.phtml
Normal file
@ -0,0 +1 @@
|
||||
{{legal}}
|
||||
78
include/views/default/crunchbutton/frontend/location.phtml
Normal file
78
include/views/default/crunchbutton/frontend/location.phtml
Normal file
@ -0,0 +1,78 @@
|
||||
<div class="main-content-readable home-greeting">
|
||||
<div class="home-welcome">
|
||||
<h1>Push a button. Get Food.</h1>
|
||||
<h2>
|
||||
Order the top food in your area.
|
||||
<br />
|
||||
After you order, everything is saved for future 1 click ordering.
|
||||
<br />
|
||||
<strong>Enter your Address:</strong>
|
||||
</h2>
|
||||
</div>
|
||||
</div>
|
||||
<div class="enter-location">
|
||||
<form class="button-letseat-formform" onsubmit="return false;">
|
||||
<table class="button-letseat-table" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td style="width: 100%;">
|
||||
<input type="text" class="location-address" placeholder="Enter your zip code or full address"{{autofocus}}>
|
||||
</td>
|
||||
<td>
|
||||
<div class="location-detect">
|
||||
<div class="location-detect-icon"></div>
|
||||
<div class="location-detect-loader"></div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
<div class="divider"></div>
|
||||
<button class="button-letseat-form button-bottom"><div>Let's Eat!</div></button>
|
||||
<div class="error-location" style="display: none;">
|
||||
<div class="content-item-locations">
|
||||
<h1>Crunchbutton by city:</h1>
|
||||
<div class="content-item-locations-cities">
|
||||
<span class="content-item-locations-city" ng-repeat="alias in topCommunities">
|
||||
<span permalink="{{alias.alias}}">{{alias.name}}</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="main-content-readable">
|
||||
<div class="home-welcome home-welcom-error">
|
||||
<h1>Sorry!</h1>
|
||||
<h2>
|
||||
We don't serve <span class="loc-your-area change-location-inline">{{yourArea}}</span> yet. Please click <span class="change-location-inline">here</span> to enter a different address, or recommend your favorite restaurant and we'll add it to the site!
|
||||
</h2>
|
||||
</div>
|
||||
<div class="divider"></div>
|
||||
<div class="home-recommend">
|
||||
<div class="home-recommend-form">
|
||||
<div class="home-recommend-title">
|
||||
<h1><strong>Recommend a restaurant:</strong></h1>
|
||||
</div>
|
||||
<input type="text" class="home-recommend-text">
|
||||
<button class="home-recommend-button"><div>Recommend!</div></button>
|
||||
<div class="divider"></div>
|
||||
<div class="home-recommend-message">
|
||||
What's your absolute favorite? What should be on Crunchbutton? Tell us, and we'll actually add it and get back to you.
|
||||
</div>
|
||||
<div class="divider"></div>
|
||||
</div>
|
||||
<div class="home-recommend-thank-you">
|
||||
<div class="home-recommend-title">
|
||||
<h1>Awesome, thanks!</h1>
|
||||
</div>
|
||||
<div class="divider"></div>
|
||||
<div class="home-recommend-message-thank-you">
|
||||
<div ng-if="{{isUser}}">
|
||||
We'll let you know if they make it to Crunchbutton.
|
||||
</div>
|
||||
<div ng-if="{{notUser}}">
|
||||
<a href="#" class="home-recommend-message-create-account"><span>Create an account</span></a> and when we'll let you know when we launch in your area!
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -1,6 +1,6 @@
|
||||
<div class="home-welcome home-tagline main-content-readable">
|
||||
<h1><%= slogan %></h1>
|
||||
<h2><%= tagline %></h2>
|
||||
<h1>{{slogan}}</h1>
|
||||
<h2>{{tagline}}</h2>
|
||||
</div>
|
||||
<div class="content-padder-before"></div>
|
||||
<div class="content-padder">
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
|
||||
<? /*
|
||||
<? if ($this->restaurant->id_restaurant) : ?>
|
||||
<?
|
||||
$this->title = $this->restaurant->name.' | '.$this->community->name.' Food Delivery | Order from '.($this->community->name_alt() ? $this->community->name_alt() : 'Local').' Restaurants | Crunchbutton';
|
||||
@ -168,4 +170,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<? endif ; ?>
|
||||
<? endif ; ?>
|
||||
|
||||
*/ ?>
|
||||
@ -1,5 +1,5 @@
|
||||
<script type="text/javascript">
|
||||
if( App ){
|
||||
if (App){
|
||||
App.config = <?=json_encode(c::appConfig())?>;
|
||||
} else {
|
||||
$(function() {
|
||||
@ -8,7 +8,7 @@ if( App ){
|
||||
}
|
||||
</script>
|
||||
|
||||
<? if ((Cana::env() != 'live' ) && (isset($this->restaurant)) && (!$this->restaurant->open()) ) :?>
|
||||
<? if ((Cana::env() != 'live' ) && (isset($this->restaurant)) && (!$this->restaurant->open()) ) : ?>
|
||||
<style> .wrapper { background: lightgray;} </style>
|
||||
<? endif?>
|
||||
</head>
|
||||
@ -39,7 +39,7 @@ if( App ){
|
||||
<div class="body">
|
||||
<div class="content<?=$e?>">
|
||||
<div class="main-content pages">
|
||||
<?=$this->content?>
|
||||
<div ng-view><?=$this->content?></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -62,54 +62,58 @@ if( App ){
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="fb-root"></div>
|
||||
|
||||
<audio id="get-food-audio">
|
||||
<source src="/assets/audio/crunch.mp3"></source>
|
||||
<source src="/assets/audio/crunch.ogg"></source>
|
||||
</audio>
|
||||
</audio>
|
||||
</body>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
window.fbAsyncInit = function() {
|
||||
FB.init({
|
||||
appId: '<?php echo Cana::config()->facebook->app; ?>',
|
||||
cookie: true,
|
||||
xfbml: true,
|
||||
oauth: true
|
||||
$(function() {
|
||||
window.fbAsyncInit = function() {
|
||||
FB.init({
|
||||
appId: '<?=Cana::config()->facebook->app?>',
|
||||
cookie: true,
|
||||
xfbml: true,
|
||||
oauth: true
|
||||
});
|
||||
FB.getLoginStatus(App.signin.facebook.processStatus);
|
||||
FB.Event.subscribe('auth.statusChange', App.signin.facebook.processStatus);
|
||||
};
|
||||
});
|
||||
FB.getLoginStatus( App.signin.facebook.processStatus );
|
||||
FB.Event.subscribe('auth.statusChange', App.signin.facebook.processStatus );
|
||||
};
|
||||
});
|
||||
(function(d, s, id) {
|
||||
var js, fjs = d.getElementsByTagName(s)[0];
|
||||
if (d.getElementById(id)) return;
|
||||
js = d.createElement(s); js.id = id;
|
||||
js.src = "//connect.facebook.net/en_US/all.js";
|
||||
fjs.parentNode.insertBefore(js, fjs);
|
||||
}(document, 'script', 'facebook-jssdk'));
|
||||
(function(d, s, id) {
|
||||
var js, fjs = d.getElementsByTagName(s)[0];
|
||||
if (d.getElementById(id)) return;
|
||||
js = d.createElement(s); js.id = id;
|
||||
js.src = "//connect.facebook.net/en_US/all.js";
|
||||
fjs.parentNode.insertBefore(js, fjs);
|
||||
}(document, 'script', 'facebook-jssdk'));
|
||||
</script>
|
||||
|
||||
<? if ($_SERVER['__HTTP_HOST'] == 'crunchbutton.com') : ?>
|
||||
<script type="text/javascript">
|
||||
var _gaq = _gaq || [];
|
||||
_gaq.push(['_setAccount', 'UA-36135548-1']);
|
||||
_gaq.push(['_setDomainName', 'crunchbutton.com']);
|
||||
_gaq.push(['_setAllowLinker', true]);
|
||||
_gaq.push(['_trackPageview']);
|
||||
(function() {
|
||||
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
||||
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
||||
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
||||
})();
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
var _gaq = _gaq || [];
|
||||
_gaq.push(['_setAccount', 'UA-36135548-1']);
|
||||
_gaq.push(['_setDomainName', 'crunchbutton.com']);
|
||||
_gaq.push(['_setAllowLinker', true]);
|
||||
_gaq.push(['_trackPageview']);
|
||||
(function() {
|
||||
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
||||
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
||||
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
||||
})();
|
||||
</script>
|
||||
<? endif ; ?>
|
||||
|
||||
<? if (!c::isMobile()) : ?>
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
App.support.init();
|
||||
});
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
App.support.init();
|
||||
});
|
||||
</script>
|
||||
<? endif; ?>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
@ -3,10 +3,11 @@
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/jquery-ui.min.js"></script>
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"></script>
|
||||
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
|
||||
|
||||
<?php
|
||||
<?
|
||||
/* Issue #1221 - QuoJs does not support IE - this is a workaround */
|
||||
if( c::Browser()->browser == 'MSIE' ) { ?>
|
||||
if (c::Browser()->browser == 'MSIE' ) : ?>
|
||||
<script type="text/javascript">
|
||||
var $$ = $;
|
||||
$$.fn.tap = function( func ){
|
||||
@ -16,7 +17,7 @@ if( c::Browser()->browser == 'MSIE' ) { ?>
|
||||
$(document).on( 'click', $( this ).selector , func );
|
||||
};
|
||||
</script>
|
||||
<?php } ?>
|
||||
<? endif ; ?>
|
||||
|
||||
<? if (c::config()->bundle) : ?>
|
||||
<script src="/assets/js/bundle.js?v=<?=Cana_Util::gitVersion()?>&s=app"></script>
|
||||
@ -24,9 +25,9 @@ if( c::Browser()->browser == 'MSIE' ) { ?>
|
||||
<?=$this->display('bundle/js', ['set' => ['scripts' => ['app']]])?>
|
||||
<? endif ; ?>
|
||||
|
||||
<?php
|
||||
<?
|
||||
/* Issue #1221 - QuoJs does not support IE - if is IE not use QuoJs (workaround html.phtml:8) */
|
||||
if( c::Browser()->browser != 'MSIE' ) : ?>
|
||||
if (c::Browser()->browser != 'MSIE') : ?>
|
||||
<script src="/assets/js/quo.js?v=<?=Cana_Util::gitVersion()?>"></script>
|
||||
<? endif ; ?>
|
||||
|
||||
|
||||
@ -42,7 +42,7 @@ var _gmtServer = '<?php echo $utc_str;?>';
|
||||
|
||||
<? foreach (new DirectoryIterator(c::config()->dirs->view.'default/crunchbutton/frontend') as $fileInfo) : ?>
|
||||
<? if (!$fileInfo->isDot()) : ?>
|
||||
<script type="text/template" class="template-<?=$fileInfo->getBasename('.phtml')?>">
|
||||
<script type="text/ng-template" id="view/<?=$fileInfo->getBasename('.phtml')?>.html">
|
||||
<?=file_get_contents($fileInfo->getPathname())?>
|
||||
</script>
|
||||
<? endif ; ?>
|
||||
|
||||
@ -255,7 +255,7 @@ body {
|
||||
text-shadow: 1px 1px 0 rgba(255,255,255,1);
|
||||
margin-bottom: 90px;
|
||||
}
|
||||
.error-location, .enter-location, .button-letseat-form{
|
||||
.error-location {
|
||||
display: none;
|
||||
}
|
||||
.copyright {
|
||||
@ -1201,15 +1201,12 @@ html[xmlns] .clearfix {
|
||||
.content-item-locations{
|
||||
margin-top: 70px !important;
|
||||
}
|
||||
.content-item-locations h1 {
|
||||
font-size: 15px;
|
||||
text-align: center;
|
||||
margin-bototm: 5px;
|
||||
}
|
||||
|
||||
.home-welcome-click {
|
||||
display: none;
|
||||
.content-item-locations h1 {
|
||||
font-size: 15px;
|
||||
text-align: center;
|
||||
margin-bototm: 5px;
|
||||
}
|
||||
|
||||
.home-welcome h1 {
|
||||
font-size: 20px;
|
||||
}
|
||||
@ -1923,9 +1920,6 @@ html[xmlns] .clearfix {
|
||||
background-size: contain;
|
||||
cursor: pointer;
|
||||
}
|
||||
.home-welcome-touch {
|
||||
display: none;
|
||||
}
|
||||
.ui-footer-fixed {
|
||||
left: auto;
|
||||
right: auto;
|
||||
|
||||
1114
www/assets/js/app.js
1114
www/assets/js/app.js
File diff suppressed because it is too large
Load Diff
915
www/assets/js/cart.js
Normal file
915
www/assets/js/cart.js
Normal file
@ -0,0 +1,915 @@
|
||||
|
||||
App.cart = {
|
||||
uuidInc: 0,
|
||||
|
||||
items: {},
|
||||
|
||||
uuid: function() {
|
||||
var id = 'c-' + App.cart.uuidInc;
|
||||
App.cart.uuidInc++;
|
||||
return id;
|
||||
},
|
||||
|
||||
add: function(item) {
|
||||
var
|
||||
id = App.cart.uuid(),
|
||||
opt = App.cached['Dish'][item].options(),
|
||||
options = [];
|
||||
|
||||
if (arguments[1]) {
|
||||
options = arguments[1].options;
|
||||
} else {
|
||||
for (var x in opt) {
|
||||
if (opt[x]['default'] == 1) {
|
||||
options[options.length] = opt[x].id_option;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
App.cart.items[id] = {
|
||||
id: item,
|
||||
options: options
|
||||
};
|
||||
|
||||
var el = $('<div class="cart-item cart-item-dish" data-cart_id="' + id + '"></div>');
|
||||
el.append('<div class="cart-button cart-button-remove"><span></span></div>');
|
||||
|
||||
el.append('<div class="cart-item-name">' + App.cache('Dish',item).name + ' <span class="cart-item-description">' + (App.cache('Dish',item).description != null ? App.cache('Dish',item).description : '') + '</span></div>');
|
||||
|
||||
if (App.cached['Dish'][item].options().length) {
|
||||
el.append('<div class="cart-item-config"><a href="javascript:;">Customize</a></div>');
|
||||
}
|
||||
|
||||
el.hide();
|
||||
|
||||
// If it is a mobile add the items at the top #1035
|
||||
if( $( window ).width() > 769 ){
|
||||
$('.cart-items-content').append(el);
|
||||
} else {
|
||||
$('.cart-items-content').prepend(el);
|
||||
}
|
||||
|
||||
//el.fadeIn();
|
||||
el.show();
|
||||
|
||||
if( parseInt( App.cache( 'Dish', item ).expand_view ) > 0 ){
|
||||
App.cart.customize( el );
|
||||
}
|
||||
|
||||
App.cart.updateTotal();
|
||||
|
||||
App.track('Dish added', {
|
||||
id_dish: App.cache('Dish',item).id_dish,
|
||||
name: App.cache('Dish',item).name
|
||||
});
|
||||
},
|
||||
|
||||
clone: function(item) {
|
||||
var
|
||||
cartid = item.attr('data-cart_id'),
|
||||
cart = App.cart.items[cartid],
|
||||
newoptions = [];
|
||||
|
||||
for (var x in cart.options) {
|
||||
newoptions[newoptions.length] = cart.options[x];
|
||||
}
|
||||
App.cart.add(cart.id, {
|
||||
options: newoptions
|
||||
});
|
||||
|
||||
App.track('Dish cloned');
|
||||
},
|
||||
|
||||
remove: function(item) {
|
||||
var
|
||||
cart = item.attr('data-cart_id');
|
||||
|
||||
App.track('Dish removed');
|
||||
|
||||
delete App.cart.items[cart];
|
||||
|
||||
item.remove();
|
||||
$('.cart-item-customize[data-id_cart_item="' + cart + '"]').remove();
|
||||
|
||||
App.cart.updateTotal();
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets called after the cart is updarted to refresh the total
|
||||
*
|
||||
* @todo Gets called many times before the cart is updated, on load, and shouldn't
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
updateTotal: function() {
|
||||
var
|
||||
totalText = ( App.config.ab && App.config.ab.dollarSign == 'show' ? '$' : '' ) + this.charged(),
|
||||
tipText = '',
|
||||
feesText = '',
|
||||
totalItems = 0,
|
||||
credit = 0,
|
||||
hasFees = ((App.restaurant.delivery_fee && App.order.delivery_type == 'delivery') || App.restaurant.fee_customer) ? true : false;
|
||||
|
||||
if( App.credit.restaurant[ App.restaurant.id ] ){
|
||||
credit = parseFloat( App.credit.restaurant[ App.restaurant.id ] );
|
||||
}
|
||||
|
||||
for (var x in App.cart.items) {
|
||||
totalItems++;
|
||||
}
|
||||
App.updateAutotipValue();
|
||||
|
||||
/* If the user changed the delivery method to takeout and the payment is card
|
||||
* the default tip will be 0%. If the delivery method is delivery and the payment is
|
||||
* card the default tip will be autotip.
|
||||
* If the user had changed the tip value the default value will be the chosen one.
|
||||
*/
|
||||
var wasTipChanged = false;
|
||||
if( App.order.delivery_type == 'takeout' && App.order['pay_type'] == 'card' ){
|
||||
if( typeof App.order.tipHasChanged == 'undefined' ){
|
||||
App.order.tip = 0;
|
||||
wasTipChanged = true;
|
||||
}
|
||||
} else if( App.order.delivery_type == 'delivery' && App.order['pay_type'] == 'card' ){
|
||||
if( typeof App.order.tipHasChanged == 'undefined' ){
|
||||
App.order.tip = ( App.config.user.last_tip ) ? App.config.user.last_tip : 'autotip';
|
||||
App.order.tip = App.lastTipNormalize( App.order.tip );
|
||||
wasTipChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
if( wasTipChanged ){
|
||||
$('[name="pay-tip"]').val( App.order.tip );
|
||||
// Forces the recalculation of total because the tip was changed.
|
||||
totalText = ( App.config.ab && App.config.ab.dollarSign == 'show' ? '$' : '' ) + this.charged();
|
||||
}
|
||||
|
||||
if (App.restaurant.meetDeliveryMin() && App.order.delivery_type == 'delivery') {
|
||||
$('.delivery-minimum-error').show();
|
||||
$('.delivery-min-diff').html(App.restaurant.deliveryDiff());
|
||||
|
||||
} else {
|
||||
$('.delivery-minimum-error').hide();
|
||||
}
|
||||
|
||||
$('.cart-summary-item-count span').html(totalItems);
|
||||
|
||||
/* If no items, hide payment line
|
||||
* .payment-total line for new customers
|
||||
* .dp-display-payment is for stored customers
|
||||
*/
|
||||
if (!this.subtotal()) {
|
||||
$('.payment-total, .dp-display-payment').hide();
|
||||
} else {
|
||||
$('.payment-total, .dp-display-payment').show();
|
||||
}
|
||||
|
||||
var breakdown = App.cart.totalbreakdown();
|
||||
|
||||
var extraCharges = App.cart.extraChargesText(breakdown);
|
||||
if (extraCharges) {
|
||||
$('.cart-breakdownDescription').html( ( App.config.ab && App.config.ab.dollarSign == 'show' ? '$' : '' ) + this.subtotal().toFixed(2) + ' (+'+ extraCharges +')' );
|
||||
} else {
|
||||
$('.cart-breakdownDescription').html( ( App.config.ab && App.config.ab.dollarSign == 'show' ? '$' : '' ) + this.subtotal().toFixed(2));
|
||||
}
|
||||
|
||||
if( App.order.pay_type == 'card' && credit > 0 ){
|
||||
var creditLeft = '';
|
||||
if( this.total() < credit ){
|
||||
var creditLeft = '<span class="gift-left"> - You\'ll still have ' + ( App.config.ab && App.config.ab.dollarSign == 'show' ? '$' : '' ) + App.ceil( ( credit - this.total() ) ).toFixed( 2 ) + ' gift card left </span>';
|
||||
credit = this.total();
|
||||
}
|
||||
$('.cart-gift').html( ' (- ' + ( App.config.ab && App.config.ab.dollarSign == 'show' ? '$' : '' ) + App.ceil( credit ).toFixed( 2 ) + ' credit ' + creditLeft + ') ' );
|
||||
} else {
|
||||
$('.cart-gift').html( '' );
|
||||
}
|
||||
|
||||
setTimeout( function(){
|
||||
if( App.order.pay_type == 'cash' && credit > 0 && App.giftcard.showGiftCardCashMessage ){
|
||||
$( '.cart-giftcard-message' ).html( '<span class="giftcard-payment-message">Pay with a card, NOT CASH, to use your ' + ( App.config.ab && App.config.ab.dollarSign == 'show' ? '$' : '' ) + App.ceil( credit ).toFixed( 2 ) + ' gift card!</span>' );
|
||||
} else {
|
||||
$( '.cart-giftcard-message' ).html( '' );
|
||||
}
|
||||
}, 1000 );
|
||||
|
||||
$('.cart-total').html( totalText );
|
||||
|
||||
/**
|
||||
* Crunchbutton doesnt collect the cash, the restaurant will ring up
|
||||
* the order in their register, which may have different prices. The
|
||||
* restaurant collects the cash, so its posible things may be
|
||||
* different. This differs from when its card, crunchbutton collects
|
||||
* the money directly so the price cant vary
|
||||
*/
|
||||
if (App.order['pay_type'] == 'card') {
|
||||
$('.cash-order-aprox').html('');
|
||||
$('.cart-paymentType').html('by card');
|
||||
} else {
|
||||
$('.cash-order-aprox').html('approximately');
|
||||
$('.cart-paymentType').html('');
|
||||
}
|
||||
|
||||
if (App.cartHighlightEnabled && $('.cart-summary').css('display') != 'none') {
|
||||
$('.cart-summary').removeClass('cart-summary-detail');
|
||||
$('.cart-summary').effect('highlight', {}, 500, function() {
|
||||
$('.cart-summary').addClass('cart-summary-detail');
|
||||
});
|
||||
}
|
||||
|
||||
if ($('.cart-total').html() == totalText) {
|
||||
//return;
|
||||
}
|
||||
|
||||
if (!totalItems) {
|
||||
$('.default-order-check').hide();
|
||||
} else {
|
||||
$('.default-order-check').show();
|
||||
}
|
||||
|
||||
var
|
||||
totalItems = {},
|
||||
name,
|
||||
text = '';
|
||||
$('.cart-summary-items').html('');
|
||||
|
||||
for (var x in App.cart.items) {
|
||||
name = App.cached['Dish'][App.cart.items[x].id].name;
|
||||
if (totalItems[name]) {
|
||||
totalItems[name]++;
|
||||
} else {
|
||||
totalItems[name] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (x in totalItems) {
|
||||
text = ', ' + text;
|
||||
if (totalItems[x] > 1) {
|
||||
text = x + ' (' + totalItems[x] + ')' + text;
|
||||
} else {
|
||||
text = x + text;
|
||||
}
|
||||
}
|
||||
|
||||
$('.cart-summary-items').html(text.substr(0,text.length-13));
|
||||
|
||||
$('.cart-item-customize-price').each(function() {
|
||||
var dish = $(this).closest('.cart-item-customize').attr('data-id_cart_item'),
|
||||
option = $(this).closest('.cart-item-customize-item').attr('data-id_option'),
|
||||
cartitem = App.cart.items[dish],
|
||||
opt = App.cached['Option'][option],
|
||||
price = opt.optionPrice(cartitem.options);
|
||||
|
||||
$(this).html(App.cart.customizeItemPrice(price));
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
customizeItemPrice: function(price, force) {
|
||||
var priceText = '';
|
||||
if( price != '0.00' || force ){
|
||||
priceText = ' (';
|
||||
priceText += ( price < 0 ) ? 'minus $' : '+ $';
|
||||
priceText += parseFloat( Math.abs( price ) ).toFixed(2);
|
||||
priceText += ')';
|
||||
}
|
||||
return priceText;
|
||||
},
|
||||
|
||||
customize: function(item) {
|
||||
var
|
||||
cart = item.attr('data-cart_id'),
|
||||
old = $('.cart-item-customize[data-id_cart_item="' + cart + '"]');
|
||||
|
||||
if (old.length) {
|
||||
old.remove();
|
||||
} else {
|
||||
var
|
||||
el = $('<div class="cart-item-customize" data-id_cart_item="' + cart + '"></div>').insertAfter(item),
|
||||
cartitem = App.cart.items[cart],
|
||||
obj = App.cached['Dish'][cartitem.id],
|
||||
opt = obj.options();
|
||||
|
||||
// First the basic options
|
||||
for (var x in opt) {
|
||||
if (opt[x].id_option_parent) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (opt[x].type == 'check') {
|
||||
|
||||
var price = opt[x].optionPrice(cartitem.options);
|
||||
var check = $('<input type="checkbox" class="cart-customize-check">');
|
||||
|
||||
if ($.inArray(opt[x].id_option, cartitem.options) !== -1) {
|
||||
check.attr('checked','checked');
|
||||
}
|
||||
|
||||
var option = $('<div class="cart-item-customize-item" data-id_option="' + opt[x].id_option + '"></div>')
|
||||
.append(check)
|
||||
.append('<label class="cart-item-customize-name">' +
|
||||
opt[x].name + (opt[x].description || '') +
|
||||
'</label><label class="cart-item-customize-price">' +
|
||||
App.cart.customizeItemPrice( price ) + '</label>'
|
||||
);
|
||||
el.append(option);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Second the customizable options
|
||||
for (var x in opt) {
|
||||
if (opt[x].id_option_parent) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (opt[x].type == 'select') {
|
||||
|
||||
var select = $('<select class="cart-customize-select">');
|
||||
for (var i in opt) {
|
||||
|
||||
if (opt[i].id_option_parent == opt[x].id_option) {
|
||||
var price = opt[i].price;
|
||||
var option = $('<option value="' + opt[i].id_option + '">' + opt[i].name + (opt[i].description || '') + App.cart.customizeItemPrice( price, ( opt[x].price_linked == '1' ) ) + '</option>');
|
||||
if ($.inArray(opt[i].id_option, cartitem.options) !== -1) {
|
||||
option.attr('selected','selected');
|
||||
}
|
||||
select.append(option);
|
||||
}
|
||||
}
|
||||
var option = $('<div class="cart-item-customize-item" data-id_option="' + opt[x].id_option + '"></div>')
|
||||
.append('<label class="cart-item-customize-select-name">' + opt[x].name + (opt[x].description || '') + '</label>')
|
||||
.append(select);
|
||||
|
||||
el.append(option);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
App.track('Dish customized');
|
||||
},
|
||||
|
||||
customizeItem: function(item) {
|
||||
|
||||
var
|
||||
cart = item.closest('.cart-item-customize').attr('data-id_cart_item'),
|
||||
cartitem = App.cart.items[cart],
|
||||
customitem = item.closest('.cart-item-customize-item'),
|
||||
opt = customitem.attr('data-id_option');
|
||||
|
||||
if (opt) {
|
||||
if (item.hasClass('cart-customize-select')) {
|
||||
|
||||
var obj = App.cached['Dish'][cartitem.id],
|
||||
opts = obj.options();
|
||||
|
||||
for (var i in opts) {
|
||||
if (opts[i].id_option_parent != opt) {
|
||||
continue;
|
||||
}
|
||||
for (var x in cartitem.options) {
|
||||
if (cartitem.options[x] == opts[i].id) {
|
||||
cartitem.options.splice(x, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cartitem.options[cartitem.options.length] = item.val();
|
||||
|
||||
} else if(item.hasClass('cart-customize-check')) {
|
||||
if (item.is(':checked')) {
|
||||
cartitem.options[cartitem.options.length] = opt;
|
||||
} else {
|
||||
for (var x in cartitem.options) {
|
||||
if (cartitem.options[x] == opt) {
|
||||
cartitem.options.splice(x, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
App.cart.updateTotal();
|
||||
},
|
||||
|
||||
/**
|
||||
* subtotal, delivery, fee, taxes and tip
|
||||
*
|
||||
* @category view
|
||||
*/
|
||||
extraChargesText: function(breakdown) {
|
||||
var elements = [];
|
||||
var text = '';
|
||||
if (breakdown.delivery) {
|
||||
elements.push(( App.config.ab && App.config.ab.dollarSign == 'show' ? '$' : '' ) + breakdown.delivery.toFixed(2) + ' delivery');
|
||||
}
|
||||
|
||||
if (breakdown.fee) {
|
||||
elements.push(( App.config.ab && App.config.ab.dollarSign == 'show' ? '$' : '' ) + breakdown.fee.toFixed(2) + ' fee');
|
||||
}
|
||||
if (breakdown.taxes) {
|
||||
elements.push(( App.config.ab && App.config.ab.dollarSign == 'show' ? '$' : '' ) + breakdown.taxes.toFixed(2) + ' taxes');
|
||||
}
|
||||
if (breakdown.tip && breakdown.tip > 0) {
|
||||
elements.push(( App.config.ab && App.config.ab.dollarSign == 'show' ? '$' : '' ) + breakdown.tip + ' tip');
|
||||
}
|
||||
|
||||
if (elements.length) {
|
||||
if (elements.length > 2) {
|
||||
var lastOne = elements.pop();
|
||||
var elements = [elements.join(', ')];
|
||||
elements.push(lastOne);
|
||||
}
|
||||
var text = elements.join(' & ');
|
||||
}
|
||||
return text;
|
||||
},
|
||||
|
||||
getCart: function() {
|
||||
var cart = [];
|
||||
for (x in App.cart.items) {
|
||||
cart[cart.length] = App.cart.items[x];
|
||||
}
|
||||
return cart;
|
||||
},
|
||||
|
||||
/**
|
||||
* Submits the cart order
|
||||
*
|
||||
* @returns void
|
||||
*/
|
||||
submit: function() {
|
||||
|
||||
if (App.busy.isBusy()) {
|
||||
return;
|
||||
}
|
||||
|
||||
App.busy.makeBusy();
|
||||
|
||||
var read = $('.payment-form').length ? true : false;
|
||||
|
||||
if (read) {
|
||||
App.config.user.name = $('[name="pay-name"]').val();
|
||||
App.config.user.phone = $('[name="pay-phone"]').val().replace(/[^\d]*/gi,'');
|
||||
if (App.order['delivery_type'] == 'delivery') {
|
||||
App.config.user.address = $('[name="pay-address"]').val();
|
||||
}
|
||||
App.order.tip = $('[name="pay-tip"]').val();
|
||||
}
|
||||
|
||||
var order = {
|
||||
cart: App.cart.getCart(),
|
||||
pay_type: App.order['pay_type'],
|
||||
delivery_type: App.order['delivery_type'],
|
||||
restaurant: App.restaurant.id,
|
||||
make_default: $('#default-order-check').is(':checked'),
|
||||
notes: $('[name="notes"]').val(),
|
||||
lat: ( App.loc.pos() ) ? App.loc.pos().lat : null,
|
||||
lon: ( App.loc.pos() ) ? App.loc.pos().lon : null
|
||||
};
|
||||
|
||||
if (order.pay_type == 'card') {
|
||||
order.tip = App.order.tip || '3';
|
||||
order.autotip_value = $('[name=pay-autotip-value]').val();
|
||||
}
|
||||
|
||||
if (read) {
|
||||
order.address = App.config.user.address;
|
||||
order.phone = App.config.user.phone;
|
||||
order.name = App.config.user.name;
|
||||
if (App.order.cardChanged) {
|
||||
order.card = {
|
||||
number: $('[name="pay-card-number"]').val(),
|
||||
month: $('[name="pay-card-month"]').val(),
|
||||
year: $('[name="pay-card-year"]').val()
|
||||
};
|
||||
} else {
|
||||
order.card = {};
|
||||
}
|
||||
}
|
||||
|
||||
console.log('ORDER:',order);
|
||||
|
||||
var errors = {};
|
||||
|
||||
if (!order.name) {
|
||||
errors['name'] = 'Please enter your name.';
|
||||
}
|
||||
|
||||
if (!App.phone.validate(order.phone)) {
|
||||
errors['phone'] = 'Please enter a valid phone #.';
|
||||
}
|
||||
|
||||
if (order.delivery_type == 'delivery' && !order.address) {
|
||||
errors['address'] = 'Please enter an address.';
|
||||
}
|
||||
|
||||
if (order.pay_type == 'card' && ((App.order.cardChanged && !order.card.number) || (!App.config.user.id_user && !order.card.number))) {
|
||||
errors['card'] = 'Please enter a valid card #.';
|
||||
}
|
||||
|
||||
if (!App.cart.hasItems()) {
|
||||
errors['noorder'] = 'Please add something to your order.';
|
||||
}
|
||||
|
||||
if (!$.isEmptyObject(errors)) {
|
||||
var error = '';
|
||||
for (var x in errors) {
|
||||
error += errors[x] + "\n";
|
||||
}
|
||||
$('body').scrollTop($('.payment-form').position().top-80);
|
||||
App.alert(error);
|
||||
App.busy.unBusy();
|
||||
App.track('OrderError', errors);
|
||||
// Log the error
|
||||
App.log.order( { 'errors' : errors } , 'validation error' );
|
||||
return;
|
||||
}
|
||||
|
||||
// Play the crunch audio just once, when the user clicks at the Get Food button
|
||||
if( App.iOS() && !App.crunchSoundAlreadyPlayed ){
|
||||
App.playAudio( 'get-food-audio' );
|
||||
App.crunchSoundAlreadyPlayed = true;
|
||||
}
|
||||
|
||||
// if it is a delivery order we need to check the address
|
||||
if( order.delivery_type == 'delivery' ){
|
||||
|
||||
// Correct Legacy Addresses in Database to Avoid Screwing Users #1284
|
||||
// If the user has already ordered food
|
||||
if( App.config && App.config.user && App.config.user.last_order ){
|
||||
|
||||
// Check if the order was made at this community
|
||||
if( App.config.user.last_order.communities.indexOf( App.restaurant.id_community ) > -1 ){
|
||||
|
||||
// Get the last address the user used at this community
|
||||
var lastAddress = App.config.user.last_order.address;
|
||||
var currentAdress = $( '[name=pay-address]' ).val();
|
||||
|
||||
// Make sure the the user address is the same of his last order
|
||||
if( $.trim( lastAddress ) != '' && $.trim( lastAddress ) == $.trim( currentAdress ) ){
|
||||
App.isDeliveryAddressOk = true;
|
||||
|
||||
// Log the legacy address
|
||||
App.log.order( { 'address' : lastAddress, 'restaurant' : App.restaurant.name } , 'legacy address' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the user address was already validated
|
||||
if ( !App.isDeliveryAddressOk ) {
|
||||
|
||||
// Use the aproxLoc to create the bounding box
|
||||
if( App.loc.aproxLoc ){
|
||||
var latLong = new google.maps.LatLng( App.loc.aproxLoc ? App.loc.aproxLoc.lat : App.loc.pos().lat, App.loc.aproxLoc ? App.loc.aproxLoc.lon : App.loc.pos().lon);
|
||||
}
|
||||
|
||||
// Use the restautant's position to create the bounding box - just for tests
|
||||
if( App.useRestaurantBoundingBox ){
|
||||
var latLong = new google.maps.LatLng( App.restaurant.loc_lat, App.restaurant.loc_long );
|
||||
}
|
||||
|
||||
if( !latLong ){
|
||||
App.alert( 'Could not locate you!' );
|
||||
App.busy.unBusy();
|
||||
return;
|
||||
}
|
||||
|
||||
var success = function( results ) {
|
||||
|
||||
// Get the closest address from that lat/lng
|
||||
var theClosestAddress = App.loc.theClosestAddress( results, latLong );
|
||||
|
||||
var isTheAddressOk = App.loc.validateAddressType( theClosestAddress );
|
||||
|
||||
if( isTheAddressOk ){
|
||||
// Now lets check if the restaurant deliveries at the given address
|
||||
var lat = theClosestAddress.geometry.location.lat();
|
||||
var lon = theClosestAddress.geometry.location.lng();
|
||||
|
||||
|
||||
if( App.useCompleteAddress ){
|
||||
$( '[name=pay-address]' ).val( App.loc.formatedAddress( theClosestAddress ) );
|
||||
}
|
||||
|
||||
if (!App.restaurant.deliveryHere({ lat: lat, lon: lon})) {
|
||||
App.alert( 'Sorry, you are out of delivery range or have an invalid address. \nPlease check your address, or order takeout.' );
|
||||
|
||||
|
||||
// Write the found address at the address field, so the user can check it.
|
||||
$( '[name=pay-address]' ).val( App.loc.formatedAddress( theClosestAddress ) );
|
||||
|
||||
// Log the error
|
||||
App.log.order( { 'address' : $( '[name=pay-address]' ).val(), 'restaurant' : App.restaurant.name } , 'address out of delivery range' );
|
||||
|
||||
App.busy.unBusy();
|
||||
return;
|
||||
|
||||
} else {
|
||||
|
||||
if( App.completeAddressWithZipCode ){
|
||||
|
||||
// Get the address zip code
|
||||
var zipCode = App.loc.zipCode( theClosestAddress );
|
||||
var typed_address = $( '[name=pay-address]' ).val();
|
||||
|
||||
// Check if the typed address already has the zip code
|
||||
if( typed_address.indexOf( zipCode ) < 0 ){
|
||||
var addressWithZip = typed_address + ' - ' + zipCode;
|
||||
$( '[name=pay-address]' ).val( addressWithZip );
|
||||
}
|
||||
}
|
||||
|
||||
App.busy.unBusy();
|
||||
App.isDeliveryAddressOk = true;
|
||||
App.cart.submit();
|
||||
}
|
||||
|
||||
} else {
|
||||
// Address was found but it is not valid (for example it could be a city name)
|
||||
App.alert( 'Oops, it looks like your address is incomplete. \nPlease enter a street name, number and zip code.' );
|
||||
App.busy.unBusy();
|
||||
// Make sure that the form will be visible
|
||||
$('.payment-form').show();
|
||||
$('.delivery-payment-info, .content-padder-before').hide();
|
||||
$( '[name="pay-address"]' ).focus();
|
||||
// Log the error
|
||||
App.log.order( { 'address' : $( '[name=pay-address]' ).val(), 'restaurant' : App.restaurant.name } , 'address not found or invalid' );
|
||||
}
|
||||
}
|
||||
|
||||
// Address not found!
|
||||
var error = function() {
|
||||
App.alert( 'Oops, it looks like your address is incomplete. \nPlease enter a street name, number and zip code.' );
|
||||
App.busy.unBusy();
|
||||
// Log the error
|
||||
App.log.order( { 'address' : $( '[name=pay-address]' ).val(), 'restaurant' : App.restaurant.name } , 'address not found' );
|
||||
};
|
||||
|
||||
// Call the geo method
|
||||
App.loc.doGeocodeWithBound( order.address, latLong, success, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if( order.delivery_type == 'takeout' ){
|
||||
App.isDeliveryAddressOk = true;
|
||||
}
|
||||
|
||||
if( !App.isDeliveryAddressOk ){
|
||||
return;
|
||||
}
|
||||
|
||||
// Play the crunch audio just once, when the user clicks at the Get Food button
|
||||
if( !App.crunchSoundAlreadyPlayed ){
|
||||
App.playAudio( 'get-food-audio' );
|
||||
App.crunchSoundAlreadyPlayed = true;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: App.service + 'order',
|
||||
data: order,
|
||||
dataType: 'html',
|
||||
type: 'POST',
|
||||
complete: function(json) {
|
||||
try {
|
||||
json = $.parseJSON(json.responseText);
|
||||
} catch (e) {
|
||||
// Log the error
|
||||
App.log.order( json.responseText, 'processing error' );
|
||||
json = {
|
||||
status: 'false',
|
||||
errors: ['Sorry! Something went horribly wrong trying to place your order!']
|
||||
};
|
||||
}
|
||||
|
||||
if (json.status == 'false') {
|
||||
var error = '';
|
||||
for (x in json.errors) {
|
||||
error += json.errors[x] + "\n";
|
||||
}
|
||||
App.track('OrderError', json.errors);
|
||||
App.alert(error);
|
||||
// Log the error
|
||||
App.log.order( { 'errors' : json.errors } , 'validation error - php' );
|
||||
} else {
|
||||
|
||||
if (json.token) {
|
||||
$.cookie('token', json.token, { expires: new Date(3000,01,01), path: '/'});
|
||||
}
|
||||
|
||||
$('.link-orders').show();
|
||||
|
||||
order.cardChanged = false;
|
||||
App.justCompleted = true;
|
||||
App.giftcard.notesCode = false;
|
||||
|
||||
var totalItems = 0;
|
||||
|
||||
for (var x in App.cart.items) {
|
||||
totalItems++;
|
||||
}
|
||||
|
||||
$.getJSON('/api/config', App.processConfig);
|
||||
|
||||
App.cache('Order',json.uuid, function() {
|
||||
App.track('Ordered', {
|
||||
'total':this.final_price,
|
||||
'subtotal':this.price,
|
||||
'tip':this.tip,
|
||||
'restaurant': App.restaurant.name,
|
||||
'paytype': this.pay_type,
|
||||
'ordertype': this.order_type,
|
||||
'user': this.user,
|
||||
'items': totalItems
|
||||
});
|
||||
|
||||
App.order.cardChanged = false;
|
||||
App.loc.changeLocationAddressHasChanged = false;
|
||||
delete App.order.tipHasChanged;
|
||||
var loc = '/order/' + this.uuid;
|
||||
History.pushState({},loc,loc);
|
||||
|
||||
});
|
||||
}
|
||||
setTimeout( function(){
|
||||
App.busy.unBusy();
|
||||
}, 400 );
|
||||
}
|
||||
});
|
||||
|
||||
}, // end App.cart.submit()
|
||||
|
||||
subtotal: function() {
|
||||
var
|
||||
total = 0,
|
||||
options;
|
||||
|
||||
for (var x in App.cart.items) {
|
||||
total += parseFloat(App.cached['Dish'][App.cart.items[x].id].price);
|
||||
options = App.cart.items[x].options;
|
||||
|
||||
for (var xx in options) {
|
||||
var option = App.cached['Option'][options[xx]];
|
||||
if (option === undefined) continue; // option does not exist anymore
|
||||
total += parseFloat(option.optionPrice(options));
|
||||
}
|
||||
}
|
||||
total = App.ceil(total);
|
||||
return total;
|
||||
},
|
||||
|
||||
/**
|
||||
* delivery cost
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
_breackDownDelivery: function() {
|
||||
var delivery = 0;
|
||||
if (App.restaurant.delivery_fee && App.order.delivery_type == 'delivery') {
|
||||
delivery = parseFloat(App.restaurant.delivery_fee);
|
||||
}
|
||||
delivery = App.ceil(delivery);
|
||||
return delivery;
|
||||
},
|
||||
|
||||
/**
|
||||
* Crunchbutton service
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
_breackDownFee: function(feeTotal) {
|
||||
var fee = 0;
|
||||
if (App.restaurant.fee_customer) {
|
||||
fee = (feeTotal * (parseFloat(App.restaurant.fee_customer)/100));
|
||||
}
|
||||
fee = App.ceil(fee);
|
||||
return fee;
|
||||
},
|
||||
|
||||
_breackDownTaxes: function(feeTotal) {
|
||||
var taxes = (feeTotal * (App.restaurant.tax/100));
|
||||
taxes = App.ceil(taxes);
|
||||
return taxes;
|
||||
},
|
||||
|
||||
_breakdownTip: function(total) {
|
||||
var tip = 0;
|
||||
if (App.order['pay_type'] == 'card') {
|
||||
if (App.order.tip === 'autotip') {
|
||||
return parseFloat($('[name=pay-autotip-value]').val());
|
||||
}
|
||||
tip = (total * (App.order.tip/100));
|
||||
}
|
||||
tip = App.ceil(tip);
|
||||
return tip;
|
||||
},
|
||||
|
||||
total: function() {
|
||||
var
|
||||
total = 0,
|
||||
dish,
|
||||
options,
|
||||
feeTotal = 0,
|
||||
totalItems = 0,
|
||||
finalAmount = 0
|
||||
;
|
||||
|
||||
var breakdown = this.totalbreakdown();
|
||||
total = breakdown.subtotal;
|
||||
feeTotal = total;
|
||||
feeTotal += breakdown.delivery;
|
||||
feeTotal += breakdown.fee;
|
||||
finalAmount = feeTotal + breakdown.taxes;
|
||||
finalAmount += this._breakdownTip(total);
|
||||
return App.ceil(finalAmount).toFixed(2);
|
||||
},
|
||||
|
||||
charged : function(){
|
||||
|
||||
var finalAmount = this.total();
|
||||
|
||||
if( App.order.pay_type == 'card' && App.credit.restaurant[ App.restaurant.id ] ){
|
||||
finalAmount = finalAmount - App.ceil( App.credit.restaurant[ App.restaurant.id ] ).toFixed(2);
|
||||
if( finalAmount < 0 ){
|
||||
finalAmount = 0;
|
||||
}
|
||||
}
|
||||
return App.ceil(finalAmount).toFixed(2);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the elements that calculates the total
|
||||
*
|
||||
* breakdown elements are: subtotal, delivery, fee, taxes and tip
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
totalbreakdown: function() {
|
||||
var elements = {};
|
||||
var total = this.subtotal();
|
||||
var feeTotal = total;
|
||||
|
||||
elements['subtotal'] = this.subtotal();
|
||||
elements['delivery'] = this._breackDownDelivery();
|
||||
feeTotal += elements['delivery'];
|
||||
elements['fee'] = this._breackDownFee(feeTotal);
|
||||
feeTotal += elements['fee'];
|
||||
elements['taxes'] = this._breackDownTaxes(feeTotal);
|
||||
elements['tip'] = this._breakdownTip( total );
|
||||
return elements;
|
||||
},
|
||||
|
||||
resetOrder: function() {
|
||||
App.cart.items = {};
|
||||
$('.cart-items-content, .cart-total').html('');
|
||||
},
|
||||
|
||||
reloadOrder: function() {
|
||||
var cart = App.cart.items;
|
||||
App.cart.resetOrder();
|
||||
App.cart.loadFlatOrder(cart);
|
||||
},
|
||||
|
||||
loadFlatOrder: function(cart) {
|
||||
for (var x in cart) {
|
||||
App.cart.add(cart[x].id,{
|
||||
options: cart[x].options ? cart[x].options : []
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
loadOrder: function(order) {
|
||||
// @todo: convert this to preset object
|
||||
try {
|
||||
if (order) {
|
||||
var dishes = order['_dishes'];
|
||||
for (var x in dishes) {
|
||||
var options = [];
|
||||
for (var xx in dishes[x]['_options']) {
|
||||
options[options.length] = dishes[x]['_options'][xx].id_option;
|
||||
}
|
||||
if (App.cached.Dish[dishes[x].id_dish] != undefined) {
|
||||
App.cart.add(dishes[x].id_dish,{
|
||||
options: options
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e.stack);
|
||||
// throw e;
|
||||
}
|
||||
App.cart.updateTotal();
|
||||
},
|
||||
|
||||
hasItems: function() {
|
||||
if (!$.isEmptyObject(App.cart.items)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,3 +1,134 @@
|
||||
/**
|
||||
* legal page
|
||||
*/
|
||||
NGApp.controller('legal', function ($scope, $http) {
|
||||
$http.get(App.service + 'legal').success(function(data) {
|
||||
console.log(data.data);
|
||||
$scope.content = data.data;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Default controller
|
||||
*/
|
||||
NGApp.controller('default', function ($scope, $http) {
|
||||
if (App.loc.address() && App.restaurants.list) {
|
||||
History.pushState({}, 'Crunchbutton', '/food-delivery');
|
||||
} else {
|
||||
// we dont have a location. let the user enter it
|
||||
History.pushState({}, 'Crunchbutton', '/location');
|
||||
}
|
||||
/*
|
||||
$http.get(App.server + 'user/devin').success(function(data) {
|
||||
$scope.penis = data;
|
||||
});
|
||||
*/
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Show the restaurants
|
||||
*/
|
||||
NGApp.controller('restaurants', function ($scope, $http) {
|
||||
if (App.loc.address()) {
|
||||
|
||||
// sort the restaurants
|
||||
var sortRestaurants = function() {
|
||||
App.restaurants.list.sort(sort_by(
|
||||
{
|
||||
name: '_open',
|
||||
reverse: true
|
||||
},
|
||||
{
|
||||
name: 'delivery',
|
||||
reverse: true
|
||||
},
|
||||
{
|
||||
name: '_weight',
|
||||
primer: parseInt,
|
||||
reverse: true
|
||||
}
|
||||
));
|
||||
};
|
||||
|
||||
var displayRestaurants = function($scope) {
|
||||
|
||||
sortRestaurants();
|
||||
|
||||
var titles = App.foodDelivery.localizedContent();
|
||||
|
||||
$scope.restaurants = App.restaurants.list;
|
||||
$scope.slogan = titles.slogan;
|
||||
$scope.tagline = titles.tagline;
|
||||
|
||||
if (App.restaurants.list.length == 4) {
|
||||
$('.content').addClass('short-meal-list');
|
||||
} else {
|
||||
$('.content').removeClass('short-meal-list');
|
||||
}
|
||||
$('.content').removeClass('smaller-width');
|
||||
|
||||
$('.nav-back').removeClass('nav-back-show');
|
||||
};
|
||||
|
||||
|
||||
// get the list of restaurants
|
||||
if (App.restaurants.list === false) {
|
||||
var url = App.service + 'restaurants?lat=' + App.loc.pos().lat + '&lon=' + App.loc.pos().lon + '&range=' + ( App.loc.range || App.defaultRange );
|
||||
App.restaurants.list = false;
|
||||
|
||||
$http.get(url).success(function(data) {
|
||||
App.restaurants.list = [];
|
||||
|
||||
// There is no restaurant near to the user. Go home and show the error.
|
||||
if (typeof data.restaurants == 'undefined' || data.restaurants.length == 0) {
|
||||
error();
|
||||
|
||||
} else {
|
||||
for (var x in data.restaurants) {
|
||||
var res = new Restaurant(data.restaurants[x]);
|
||||
res.open();
|
||||
App.restaurants.list[App.restaurants.list.length] = res;
|
||||
};
|
||||
success();
|
||||
}
|
||||
|
||||
displayRestaurants($scope);
|
||||
});
|
||||
|
||||
} else {
|
||||
displayRestaurants($scope);
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
// we dont have a location. let the user enter it
|
||||
History.pushState({}, 'Crunchbutton', '/location');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* show cities
|
||||
*/
|
||||
NGApp.controller('cities', function ($scope, $http) {
|
||||
$scope.topCommunities = App.topCommunities;
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Change location
|
||||
*/
|
||||
NGApp.controller('location', function ($scope, $http) {
|
||||
return;
|
||||
$scope.isUser = App.config.user.has_auth;
|
||||
$scope.notUser = !App.config.user.has_auth;
|
||||
$scope.topCommunities = App.topCommunities;
|
||||
$scope.yourArea = App.loc.city() || 'your area';
|
||||
$scope.autofocus = $(window).width() >= 768 ? ' autofocus="autofocus"' : '';
|
||||
});
|
||||
|
||||
|
||||
App.page.home = function(force) {
|
||||
|
||||
@ -14,17 +145,18 @@ App.page.home = function(force) {
|
||||
}
|
||||
|
||||
var homeSuccess = function() {
|
||||
|
||||
App.showPage({
|
||||
page: 'home',
|
||||
title: 'Crunchbutton',
|
||||
data: {
|
||||
isUser: App.config.user.has_auth,
|
||||
notUser: !App.config.user.has_auth,
|
||||
topCommunities: App.topCommunities,
|
||||
yourArea: App.loc.city() || 'your area',
|
||||
autofocus: $(window).width() >= 768 ? ' autofocus="autofocus"' : ''
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$('.nav-back').removeClass('nav-back-show');
|
||||
$('.config-icon').addClass('config-icon-mobile-hide, config-icon-desktop-hide');
|
||||
$('.content').addClass('short-meal-list');
|
||||
@ -83,22 +215,8 @@ App.page.home = function(force) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
App.page.bycity = function(){
|
||||
|
||||
App.currentPage = 'bycity';
|
||||
App.showPage({
|
||||
page: 'bycity',
|
||||
title: 'Crunchbutton',
|
||||
data: {
|
||||
topCommunities: App.topCommunities
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
App.page.restaurant = function(id) {
|
||||
|
||||
$('.config-icon').addClass('config-icon-mobile-hide');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user