From 7c1a5b9b7520da0d042aafe7d78df7c106fd699e Mon Sep 17 00:00:00 2001 From: Daniel Camargo Date: Wed, 2 Oct 2013 16:37:49 -0300 Subject: [PATCH] partial #1592 --- www/assets/js/app.js | 6 +++--- www/assets/js/controllers.js | 10 ++++++++++ www/assets/js/services.account.js | 2 +- www/assets/js/services.order.js | 33 ++++++++++++++++++++++++++++++- 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/www/assets/js/app.js b/www/assets/js/app.js index 3ccc8b08d..93e7348de 100644 --- a/www/assets/js/app.js +++ b/www/assets/js/app.js @@ -477,9 +477,9 @@ App.test = { App.alert(JSON.stringify(App.cart.items)); }, clearloc: function() { - $.totalstorage('community',null); - $.totalstorage('location_lat',null); - $.totalstorage('location_lon',null); + $.totalStorage('community',null); + $.totalStorage('location_lat',null); + $.totalStorage('location_lon',null); location.href = '/'; }, reload: function() { diff --git a/www/assets/js/controllers.js b/www/assets/js/controllers.js index e44b15f5b..417641edc 100644 --- a/www/assets/js/controllers.js +++ b/www/assets/js/controllers.js @@ -522,6 +522,16 @@ NGApp.controller('RestaurantCtrl', function ($scope, $http, $routeParams, $rootS $scope.$on( 'orderLoaded', function(e, data) { $scope.order.loaded = order.loaded; $scope.order.showForm = order.showForm; + + // watch form changes and stores it + $scope.$watch( 'order.form', function( newValue, oldValue, scope ) { + if( order.startStoreEntederInfo && !order.account.user.id_user ){ + var userEntered = angular.copy( order.form ); + userEntered.cardNumber = ''; + $.totalStorage( 'userEntered', userEntered ); + } + }, true); + }); // Alias to CartService 'public' methods diff --git a/www/assets/js/services.account.js b/www/assets/js/services.account.js index 82a5f1abf..bab4608ce 100644 --- a/www/assets/js/services.account.js +++ b/www/assets/js/services.account.js @@ -331,7 +331,7 @@ NGApp.factory( 'AccountSignOut', function( $http, $rootScope, $location, Account return; } // Force to remove the cookies - $.each(['token', 'location', 'PHPSESSID', 'fbtoken'], function(index, value) { + $.each(['token', 'location', 'PHPSESSID', 'fbtoken', 'userEntered'], function(index, value) { $.totalStorage(value, null); }); var signout = function() { diff --git a/www/assets/js/services.order.js b/www/assets/js/services.order.js index f29319059..6bd84ce45 100644 --- a/www/assets/js/services.order.js +++ b/www/assets/js/services.order.js @@ -8,6 +8,7 @@ NGApp.factory('OrderService', function ($http, $location, $rootScope, $filter, A service.giftcard = GiftCardService; service.credit = CreditService; service.restaurant = {}; + service.startStoreEntederInfo = false; // Listener to user signin/signout $rootScope.$on( 'userAuth', function(e, data) { @@ -121,6 +122,31 @@ NGApp.factory('OrderService', function ($http, $location, $rootScope, $filter, A service.form.cardYear = ( service.account.user.card_exp_year ) ? service.account.user.card_exp_year : ''; service.updateTotal(); + if( !service.account.user.id_user ){ + var userEntered = $.totalStorage( 'userEntered' ); + if( userEntered ){ + service.form.name = ( userEntered.name && userEntered.name != '' ? userEntered.name : service.form.name ); + service.form.phone = $filter( 'formatPhone' )( ( userEntered.phone && userEntered.phone != '' ? userEntered.phone : service.form.phone ) ); + service.form.address = ( userEntered.address && userEntered.address != '' ? userEntered.address : service.form.address ); + service.form.notes = ( userEntered.notes && userEntered.notes != '' ? userEntered.notes : service.form.notes ); + service.form.delivery_type = ( userEntered.delivery_type && userEntered.delivery_type != '' ? userEntered.delivery_type : service.form.delivery_type ); + service.form.pay_type = ( userEntered.pay_type && userEntered.pay_type != '' ? userEntered.pay_type : service.form.pay_type ); + service.form.cardMonth = ( userEntered.cardMonth && userEntered.cardMonth != '' ? userEntered.cardMonth : service.form.cardMonth ); + service.form.cardYear = ( userEntered.cardYear && userEntered.cardYear != '' ? userEntered.cardYear : service.form.cardYear ); + if( userEntered.tip && userEntered.tip != '' ){ + var _tip = userEntered.tip; + setTimeout(function() { + service.form.tip = _tip; + service.tipChanged(); + service.updateTotal(); + }, 10 ); + } else { + service.updateTotal(); + } + } + service.startStoreEntederInfo = true; + } + // If the user has presets at other's restaurants but he did not typed his address yet // and the actual restaurant is a delivery only #875 if ( service.account.user && ( service.form.delivery_type == 'takeout' || ( service.form.delivery_type == 'delivery' && service.account.user.address ) ) ) { @@ -618,7 +644,11 @@ NGApp.factory('OrderService', function ($http, $location, $rootScope, $filter, A if (json.token) { $.cookie( 'token', json.token ); } - + + // Clean the user entered info + $.totalStorage( 'userEntered', null ); + service.startStoreEntederInfo = false; + service.account.updateInfo(); App.cache('Order', json.uuid, function () { App.track('Ordered', { @@ -633,6 +663,7 @@ NGApp.factory('OrderService', function ($http, $location, $rootScope, $filter, A }); // Clean the cart service.cart.clean(); + // Resets the gift card notes field service.giftcard.notes_field.reset(); $rootScope.$safeApply( function(){