This commit is contained in:
Daniel Camargo 2013-10-02 16:37:49 -03:00
parent 2eb7631530
commit 7c1a5b9b75
4 changed files with 46 additions and 5 deletions

View File

@ -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() {

View File

@ -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

View File

@ -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() {

View File

@ -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(){