From fbf20ff2eb318b65c62576b51b4256b5de53f766 Mon Sep 17 00:00:00 2001 From: Daniel Camargo Date: Fri, 2 Aug 2013 11:16:52 -0300 Subject: [PATCH] partial #1503 --- www/assets/js/pages.js | 52 +++++++++++++++++++++++++--- www/assets/js/restaurant.js | 8 ++--- www/assets/js/services.cart.js | 48 ++++++++++++------------- www/assets/js/services.restaurant.js | 42 ++-------------------- 4 files changed, 76 insertions(+), 74 deletions(-) diff --git a/www/assets/js/pages.js b/www/assets/js/pages.js index 871164afb..f53516686 100644 --- a/www/assets/js/pages.js +++ b/www/assets/js/pages.js @@ -200,23 +200,67 @@ NGApp.controller('restaurant', function ($scope, $http, $routeParams, Restaurant $scope.service = RestaurantService; + + // Alias to ServiceAccount.user + $scope.user = $scope.service.account.user; + $scope.service.init(); $scope.cart = CartService; + // Credit card years + var date = new Date().getFullYear(); + var years = []; + for (var x = date; x <= date + 20; x++) { + years[years.length] = x; + } + + $scope.form = { + tip: App.order.tip, + name: $scope.user.name, + phone: App.phone.format( $scope.user.phone ), + address: $scope.user.address, + notes: ( $scope.user && $scope.user.presets && $scope.user.presets[$routeParams.id]) ? $scope.user.presets[$routeParams.id].notes : '', + card: { + number: $scope.user.card, + month: $scope.user.card_exp_month, + year: $scope.user.card_exp_year + }, + months: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], + years: years + }; + + $scope.AB = { + dollar: (App.config.ab && App.config.ab.dollarSign == 'show') ? '$' : '', + changeablePrice: function (dish) { + return (App.config.ab && App.config.ab.changeablePrice == 'show' && dish.changeable_price) ? '+' : '' + }, + restaurantPage: (App.config.ab && App.config.ab.restaurantPage == 'restaurant-page-noimage') ? ' restaurant-pic-wrapper-hidden' : '' + }; + $scope.$watch( 'service.loaded', function( newValue, oldValue, scope ) { if( newValue ){ + $scope.restaurant = $scope.service.restaurant; - $scope.user = $scope.service.account.user; + $scope.cart.restaurant = $scope.restaurant; + $scope.cart.updateTotal(); $scope.lastOrderDelivery = $scope.service.lastOrderDelivery; $scope.community = $scope.service.community; $scope.showRestaurantDeliv = $scope.service.showRestaurantDeliv; - $scope.AB = $scope.service.AB; - $scope.form = $scope.service.form; - // $scope.cart = $scope.service.cart; } }); + /* + // Validate gift card at the notes field + service.$watch( 'form.notes', function( newValue, oldValue, scope ) { + service.giftcard.text.content = service.form.notes; + service.giftcard.text.start(); + }); +*/ + // service.cart = { + // totalFixed: parseFloat(service.restaurant.delivery_min - service.cartService.total()).toFixed(2) + // } + $('.config-icon').addClass('config-icon-mobile-hide'); $('.nav-back').addClass('nav-back-show'); diff --git a/www/assets/js/restaurant.js b/www/assets/js/restaurant.js index 8cbaf538c..df347e326 100644 --- a/www/assets/js/restaurant.js +++ b/www/assets/js/restaurant.js @@ -163,15 +163,13 @@ var Restaurant = function(id) { } } - self.deliveryDiff = function() { - var total = self.delivery_min_amt == 'subtotal' ? App.cart.subtotal() : App.cart.total(); - var diff = parseFloat(App.restaurant.delivery_min - total).toFixed(2); + self.deliveryDiff = function(total) { + var diff = parseFloat(self.delivery_min - total).toFixed(2); /* console.log(App.cart.subtotal(), App.cart.total(),self.delivery_min_amt, total, diff); */ return diff; } - self.meetDeliveryMin = function() { - var total = self.delivery_min_amt == 'subtotal' ? App.cart.subtotal() : App.cart.total(); + self.meetDeliveryMin = function(total) { return total < parseFloat(self.delivery_min) ? true : false; } diff --git a/www/assets/js/services.cart.js b/www/assets/js/services.cart.js index c2c93f69a..6e791af1b 100644 --- a/www/assets/js/services.cart.js +++ b/www/assets/js/services.cart.js @@ -113,19 +113,16 @@ NGApp.factory( 'CartService', function ( RestaurantService ) { * @return void */ updateTotal: function () { - ///TODO: REMOVE THIS RETURN - - return; 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; + hasFees = ((service.restaurant.delivery_fee && App.order.delivery_type == 'delivery') || service.restaurant.fee_customer) ? true : false; - if (App.credit.restaurant[App.restaurant.id]) { - credit = parseFloat(App.credit.restaurant[App.restaurant.id]); + if (App.credit.restaurant[service.restaurant.id]) { + credit = parseFloat(App.credit.restaurant[service.restaurant.id]); } for (var x in service.items) { @@ -158,9 +155,10 @@ NGApp.factory( 'CartService', function ( RestaurantService ) { totalText = (App.config.ab && App.config.ab.dollarSign == 'show' ? '$' : '') + this.charged(); } - if (App.restaurant.meetDeliveryMin() && App.order.delivery_type == 'delivery') { + var _total = service.restaurant.delivery_min_amt == 'subtotal' ? service.subtotal() : service.total(); + if (service.restaurant.meetDeliveryMin(_total) && App.order.delivery_type == 'delivery') { $('.delivery-minimum-error').show(); - $('.delivery-min-diff').html(App.restaurant.deliveryDiff()); + $('.delivery-min-diff').html(service.restaurant.deliveryDiff(_total)); } else { $('.delivery-minimum-error').hide(); @@ -223,7 +221,7 @@ NGApp.factory( 'CartService', function ( RestaurantService ) { $('.cart-paymentType').html(''); } - if (serviceHighlightEnabled && $('.cart-summary').css('display') != 'none') { + 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'); @@ -354,7 +352,7 @@ NGApp.factory( 'CartService', function ( RestaurantService ) { cart: service.getCart(), pay_type: App.order['pay_type'], delivery_type: App.order['delivery_type'], - restaurant: App.restaurant.id, + restaurant: service.restaurant.id, make_default: $('#default-order-check').is(':checked'), notes: $('[name="notes"]').val(), lat: (App.loc.pos()) ? App.loc.pos().lat : null, @@ -435,7 +433,7 @@ NGApp.factory( 'CartService', function ( RestaurantService ) { 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) { + if (App.config.user.last_order.communities.indexOf(service.restaurant.id_community) > -1) { // Get the last address the user used at this community var lastAddress = App.config.user.last_order.address; @@ -448,7 +446,7 @@ NGApp.factory( 'CartService', function ( RestaurantService ) { // Log the legacy address App.log.order({ 'address': lastAddress, - 'restaurant': App.restaurant.name + 'restaurant': service.restaurant.name }, 'legacy address'); } } @@ -464,7 +462,7 @@ NGApp.factory( 'CartService', function ( RestaurantService ) { // 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 ); + var latLong = new google.maps.LatLng( service.restaurant.loc_lat, service.restaurant.loc_long ); } if( !latLong ){ @@ -490,7 +488,7 @@ NGApp.factory( 'CartService', function ( RestaurantService ) { $( '[name=pay-address]' ).val( App.loc.formatedAddress( theClosestAddress ) ); } - if (!App.restaurant.deliveryHere({ lat: lat, lon: lon})) { + if (!service.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.' ); @@ -498,7 +496,7 @@ NGApp.factory( 'CartService', function ( RestaurantService ) { $( '[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.log.order( { 'address' : $( '[name=pay-address]' ).val(), 'restaurant' : service.restaurant.name } , 'address out of delivery range' ); App.busy.unBusy(); return; @@ -532,7 +530,7 @@ NGApp.factory( 'CartService', function ( RestaurantService ) { $('.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' ); + App.log.order( { 'address' : $( '[name=pay-address]' ).val(), 'restaurant' : service.restaurant.name } , 'address not found or invalid' ); } } @@ -541,7 +539,7 @@ NGApp.factory( 'CartService', function ( RestaurantService ) { 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' ); + App.log.order( { 'address' : $( '[name=pay-address]' ).val(), 'restaurant' : service.restaurant.name } , 'address not found' ); }; // Call the geo method @@ -618,7 +616,7 @@ NGApp.factory( 'CartService', function ( RestaurantService ) { 'total': this.final_price, 'subtotal': this.price, 'tip': this.tip, - 'restaurant': App.restaurant.name, + 'restaurant': service.restaurant.name, 'paytype': this.pay_type, 'ordertype': this.order_type, 'user': this.user, @@ -666,8 +664,8 @@ NGApp.factory( 'CartService', function ( RestaurantService ) { */ _breackDownDelivery: function () { var delivery = 0; - if (App.restaurant.delivery_fee && App.order.delivery_type == 'delivery') { - delivery = parseFloat(App.restaurant.delivery_fee); + if (service.restaurant.delivery_fee && App.order.delivery_type == 'delivery') { + delivery = parseFloat(service.restaurant.delivery_fee); } delivery = App.ceil(delivery); return delivery; @@ -680,15 +678,15 @@ NGApp.factory( 'CartService', function ( RestaurantService ) { */ _breackDownFee: function (feeTotal) { var fee = 0; - if (App.restaurant.fee_customer) { - fee = (feeTotal * (parseFloat(App.restaurant.fee_customer) / 100)); + if (service.restaurant.fee_customer) { + fee = (feeTotal * (parseFloat(service.restaurant.fee_customer) / 100)); } fee = App.ceil(fee); return fee; }, _breackDownTaxes: function (feeTotal) { - var taxes = (feeTotal * (App.restaurant.tax / 100)); + var taxes = (feeTotal * (service.restaurant.tax / 100)); taxes = App.ceil(taxes); return taxes; }, @@ -728,8 +726,8 @@ NGApp.factory( 'CartService', function ( RestaurantService ) { 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 (App.order.pay_type == 'card' && App.credit.restaurant[service.restaurant.id]) { + finalAmount = finalAmount - App.ceil(App.credit.restaurant[service.restaurant.id]).toFixed(2); if (finalAmount < 0) { finalAmount = 0; } diff --git a/www/assets/js/services.restaurant.js b/www/assets/js/services.restaurant.js index 36dc2954c..803f793e2 100644 --- a/www/assets/js/services.restaurant.js +++ b/www/assets/js/services.restaurant.js @@ -114,9 +114,9 @@ NGApp.factory('RestaurantService', function ($http, $routeParams, $rootScope, Ac service.load(); } -service.load = function(){ +service.account = AccountService; - service.account = AccountService; +service.load = function(){ App.cache('Restaurant', $routeParams.id, function () { @@ -144,50 +144,12 @@ service.load = function(){ var complete = function () { - var date = new Date().getFullYear(); - var years = []; - for (var x = date; x <= date + 20; x++) { - years[years.length] = x; - } - service.loaded = true; service.lastOrderDelivery = lastOrderDelivery; service.showRestaurantDeliv = ((lastOrderDelivery == 'delivery' || service.restaurant.delivery == '1' || service.restaurant.takeout == '0') && lastOrderDelivery != 'takeout'); - service.AB = { - dollar: (App.config.ab && App.config.ab.dollarSign == 'show') ? '$' : '', - changeablePrice: function (dish) { - return (App.config.ab && App.config.ab.changeablePrice == 'show' && dish.changeable_price) ? '+' : '' - }, - restaurantPage: (App.config.ab && App.config.ab.restaurantPage == 'restaurant-page-noimage') ? ' restaurant-pic-wrapper-hidden' : '' - }; - - service.form = { - tip: App.order.tip, - name: service.account.user.name, - phone: App.phone.format(service.account.user.phone), - address: service.account.user.address, - notes: ( service.account.user && service.account.user.presets && service.account.user.presets[service.restaurant.id_restaurant]) ? service.account.user.presets[service.restaurant.id_restaurant].notes : '', - card: { - number: service.account.user.card, - month: service.account.user.card_exp_month, - year: service.account.user.card_exp_year - }, - months: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], - years: years - }; - /* - // Validate gift card at the notes field - service.$watch( 'form.notes', function( newValue, oldValue, scope ) { - service.giftcard.text.content = service.form.notes; - service.giftcard.text.start(); - }); -*/ - // service.cart = { - // totalFixed: parseFloat(service.restaurant.delivery_min - service.cartService.total()).toFixed(2) - // } }; // double check what phase we are in