{I" class:ETI"ProcessedAsset;FI"logical_path;TI" sprangular/services/cart.js;FI" pathname;TI"a/home/josh/Projects/Dynamo/sprangular/app/assets/javascripts/sprangular/services/cart.coffee;FI"content_type;TI"application/javascript;TI" mtime;Tl+%UI" length;TiI" digest;TI"%c5b8a68738428dbddd528badba987096;FI" source;TI"(function() { Sprangular.service("Cart", function($http) { var service, startupData; service = { current: null, init: function() { return this.current = new Sprangular.Order; }, reload: function() { return $http.get('/api/cart.json').success(this.load); }, errors: function(errors) { var attr, attrErrors, key, object, order, parts, results; order = service.current; order.errors = {}; order.billingAddress.errors = {}; order.shippingAddress.errors = {}; order.creditCard.errors = {}; results = []; for (key in errors) { attrErrors = errors[key]; parts = key.split('.'); object = parts[0]; attr = parts[1]; switch (object) { case 'ship_address': results.push(order.shippingAddress.errors[attr] = attrErrors); break; case 'bill_address': results.push(order.billingAddress.errors[attr] = attrErrors); break; case 'payments': results.push(order.errors.base = attrErrors[0]); break; default: results.push(order.errors[key] = attrErrors); } } return results; }, load: function(data) { if (data) { return service.current.load(data); } else { return service.current.clear(); } }, empty: function() { return $http["delete"]('/api/cart').success(this.load); }, addVariant: function(variant, quantity, flexi) { var foundProducts, params; if (flexi == null) { flexi = null; } foundProducts = this.findVariant(variant.id); if (foundProducts.length > 0) { return this.changeItemQuantity(foundProducts[0], quantity, flexi); } else { params = $.param({ variant_id: variant.id, quantity: quantity, flexi: flexi }); return $http.post('/api/cart/add_variant', params, { ignoreLoadingIndicator: true }).success(function(response) { return service.load(response); }); } }, removeItem: function(item) { var i, order; order = service.current; i = order.items.indexOf(item); if (i !== -1) { order.items.splice(i, 1); } return this.updateItemQuantity(item.variant.id, 0); }, changeItemQuantity: function(item, delta, flexi) { if (flexi == null) { flexi = null; } if (delta !== 0) { return this.updateItemQuantity(item.variant.id, item.quantity + delta, flexi); } }, updateItemQuantity: function(id, quantity, flexi) { var params; if (flexi == null) { flexi = null; } params = $.param({ variant_id: id, quantity: quantity, flexi: flexi }); return $http.put('/api/cart/update_variant', params, { ignoreLoadingIndicator: true }).success(this.load); }, changeVariant: function(oldVariant, newVariant) { var params; params = $.param({ old_variant_id: oldVariant.id, new_variant_id: newVariant.id }); return $http.put('/api/cart/change_variant', params).success(this.load); }, removeAdjustment: function(adjustment) { var params; this.current.adjustmentTotal -= adjustment.amount; this.current.total -= adjustment.amount; this.current.adjustments = _.without(this.current.adjustments, adjustment); params = $.param({ adjustment_id: adjustment.id }); return $http.put('/api/cart/remove_adjustment', params).success(this.load); }, shippingRates: function(options) { var order, params; order = this.current; params = { country_id: options.countryId, state_id: options.stateId, zipcode: options.zipcode, use_billing: this.current.shipToBillAddress }; return $http.get('/api/shipping_rates', { params: params, ignoreLoadingIndicator: true }).success(function(data) { return order.loadRates(data); }); }, clear: function() { return this.current.clear(); }, totalQuantity: function() { return this.current.totalQuantity(); }, findVariant: function(variantId) { return this.current.findVariant(variantId); }, hasVariant: function(variant) { return this.current.hasVariant(variant); }, isEmpty: function() { return this.current.isEmpty(); } }; service.init(); startupData = Sprangular.startupData; if (startupData.Order) { service.load(startupData.Order); } else { service.reload(); } return service; }); }).call(this); ;TI"dependency_digest;TI"%b83f78f664922fe42ff188b1708c2bb4;FI"required_paths;T[I"a/home/josh/Projects/Dynamo/sprangular/app/assets/javascripts/sprangular/services/cart.coffee;FI"dependency_paths;T[{I" path;TI"a/home/josh/Projects/Dynamo/sprangular/app/assets/javascripts/sprangular/services/cart.coffee;FI" mtime;TI"2015-04-08T16:20:51-04:00;TI" digest;TI"%9909e658d72ae09d5a1bd94d91adbc02;FI" _version;TI"%64e62ddc273c2f5847f30d698ca14b67;F