{I" class:ETI"ProcessedAsset;FI"logical_path;TI"sprangular/models/order.js;FI" pathname;TI"`/home/josh/Projects/Dynamo/sprangular/app/assets/javascripts/sprangular/models/order.coffee;FI"content_type;TI"application/javascript;TI" mtime;Tl+όε%UI" length;TiwI" digest;TI"%2cc8c8df80e717f67ed7a470ed67a554;FI" source;TI"w(function() { 'use strict'; Sprangular.Order = (function() { function Order() { this.creditCard = new Sprangular.CreditCard; this.clear(); } Order.prototype.clear = function() { this.number = ''; this.items = []; this.billingAddress = new Sprangular.Address; this.shippingAddress = new Sprangular.Address; this.billToShipAddress = true; this.itemTotal = 0; this.taxTotal = 0; this.shipTotal = 0; this.adjustmentTotal = 0; this.total = 0; this.state = null; this.shipmentState = null; this.shippingRates = []; this.shippingRate = null; this.token = null; return this.loading = false; }; Order.prototype.load = function(data) { var i, item, j, len, len1, product, products, ref, variant; this.clear(); this.number = data.number; this.state = data.state; this.shipmentState = data.shipment_state; this.itemTotal = Number(data.item_total); this.taxTotal = Number(data.tax_total); this.shipTotal = Number(data.ship_total); this.adjustmentTotal = Number(data.adjustment_total); this.total = Number(data.total); this.token = data.token; this.billToShipAddress = data.use_billing; this.adjustments = Sprangular.extend(data.adjustments, Sprangular.Adjustment); this.shippingRates = []; this.completedAt = data.completed_at; this.shipmentState = data.shipment_state; this.shipments = data.shipments; this.payments = data.payments; this.loadRates(data); if (data.bill_address) { this.billingAddress = Sprangular.extend(data.bill_address, Sprangular.Address); } if (data.ship_address) { this.shippingAddress = Sprangular.extend(data.ship_address, Sprangular.Address); } products = Sprangular.extend(data.products, Sprangular.Product); ref = data.line_items; for (i = 0, len = ref.length; i < len; i++) { item = ref[i]; for (j = 0, len1 = products.length; j < len1; j++) { product = products[j]; variant = product.findVariant(item.variant_id); if (variant) { break; } } this.items.push({ variant: variant, flexi_variants: item.flexi_variants, quantity: item.quantity, price: item.price }); } return this; }; Order.prototype.loadRates = function(data) { this.shipment = _.last(data.shipments); if (this.shipment) { this.shippingRates = Sprangular.extend(this.shipment.shipping_rates, Sprangular.ShippingRate); return this.shippingRate = _.find(this.shippingRates, function(rate) { return rate.selected; }); } else { return this.shippingRate = null; } }; Order.prototype.isEmpty = function() { return this.items.length === 0; }; Order.prototype.isValid = function() { this.shippingAddress.validate(); this.actualBillingAddress().validate(); this.creditCard.validate(); return this.actualBillingAddress().isValid() && this.shippingAddress.isValid() && (this.creditCard.id || this.creditCard.isValid()); }; Order.prototype.isInvalid = function() { return !this.isValid(); }; Order.prototype.totalQuantity = function() { return this.items.reduce((function(total, item) { return total + item.quantity; }), 0); }; Order.prototype.findVariant = function(variantId) { var i, item, len, ref, results; ref = this.items; results = []; for (i = 0, len = ref.length; i < len; i++) { item = ref[i]; if (item.variant.id === variantId) { results.push(item); } } return results; }; Order.prototype.findVariantForProduct = function(product) { var item, variants; variants = (function() { var i, len, ref, results; ref = this.items; results = []; for (i = 0, len = ref.length; i < len; i++) { item = ref[i]; if (item.variant.product.id === product.id) { results.push(item.variant); } } return results; }).call(this); if (variants) { return variants[0]; } }; Order.prototype.hasVariant = function(variant) { return variant && this.findVariant(variant.id).length > 0; }; Order.prototype.updateTotals = function() { debugger; return this.total = this.itemTotal + this.adjustmentTotal + this.taxTotal + this.shipTotal; }; Order.prototype.actualBillingAddress = function() { if (this.billToShipAddress) { return this.shippingAddress; } else { return this.billingAddress; } }; Order.prototype.resetAddresses = function(user) { if (user && user.addresses.length > 0) { if (this.shippingAddress.isEmpty()) { this.shippingAddress = user.shippingAddress; } if (this.billingAddress.isEmpty()) { return this.billingAddress = user.billingAddress; } } }; Order.prototype.resetCreditCard = function(user) { if (user && user.creditCards.length > 0) { return this.creditCard = _.last(user.creditCards); } else { return this.creditCard = new Sprangular.CreditCard; } }; return Order; })(); }).call(this); ;TI"dependency_digest;TI"%0f3deb0e3c56ae87b246a29e73cefe50;FI"required_paths;T[I"`/home/josh/Projects/Dynamo/sprangular/app/assets/javascripts/sprangular/models/order.coffee;FI"dependency_paths;T[{I" path;TI"`/home/josh/Projects/Dynamo/sprangular/app/assets/javascripts/sprangular/models/order.coffee;FI" mtime;TI"2015-04-08T22:37:48-04:00;TI" digest;TI"%6aeba9e769142c84398f1f04fd3be2d1;FI" _version;TI"%64e62ddc273c2f5847f30d698ca14b67;F