Rushabh Mehta | ad45e31 | 2013-11-20 12:59:58 +0530 | [diff] [blame] | 1 | // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors |
Rushabh Mehta | e67d1fb | 2013-08-05 14:59:54 +0530 | [diff] [blame] | 2 | // License: GNU General Public License v3. See license.txt |
Anand Doshi | ab69029 | 2013-06-13 11:21:35 +0530 | [diff] [blame] | 3 | |
| 4 | // js inside blog page |
| 5 | |
| 6 | $(document).ready(function() { |
Anand Doshi | 0748cb7 | 2013-09-11 15:31:58 +0530 | [diff] [blame] | 7 | erpnext.cart.bind_events(); |
Anand Doshi | 1fac2a9 | 2013-07-29 19:30:39 +0530 | [diff] [blame] | 8 | return wn.call({ |
Anand Doshi | c2a3527 | 2013-06-19 17:19:20 +0530 | [diff] [blame] | 9 | type: "POST", |
Rushabh Mehta | c59c4e0 | 2013-09-09 12:17:45 +0530 | [diff] [blame] | 10 | method: "selling.utils.cart.get_cart_quotation", |
Anand Doshi | 3dceb84 | 2013-06-19 14:57:14 +0530 | [diff] [blame] | 11 | callback: function(r) { |
Anand Doshi | 3dceb84 | 2013-06-19 14:57:14 +0530 | [diff] [blame] | 12 | $("#cart-container").removeClass("hide"); |
| 13 | $(".progress").remove(); |
| 14 | if(r.exc) { |
| 15 | if(r.exc.indexOf("WebsitePriceListMissingError")!==-1) { |
Bárbara Perretti | 187ea33 | 2013-10-09 14:53:44 -0300 | [diff] [blame] | 16 | erpnext.cart.show_error("Oops!", wn._("Price List not configured.")); |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 17 | } else if(r["403"]) { |
Bárbara Perretti | 187ea33 | 2013-10-09 14:53:44 -0300 | [diff] [blame] | 18 | erpnext.cart.show_error("Hey!", wn._("You need to be logged in to view your cart.")); |
Anand Doshi | 3dceb84 | 2013-06-19 14:57:14 +0530 | [diff] [blame] | 19 | } else { |
Bárbara Perretti | 187ea33 | 2013-10-09 14:53:44 -0300 | [diff] [blame] | 20 | erpnext.cart.show_error("Oops!", wn._("Something went wrong.")); |
Anand Doshi | 3dceb84 | 2013-06-19 14:57:14 +0530 | [diff] [blame] | 21 | } |
| 22 | } else { |
Anand Doshi | 0748cb7 | 2013-09-11 15:31:58 +0530 | [diff] [blame] | 23 | erpnext.cart.set_cart_count(); |
| 24 | erpnext.cart.render(r.message); |
Anand Doshi | 3dceb84 | 2013-06-19 14:57:14 +0530 | [diff] [blame] | 25 | } |
Anand Doshi | 3dceb84 | 2013-06-19 14:57:14 +0530 | [diff] [blame] | 26 | } |
| 27 | }); |
Anand Doshi | ab69029 | 2013-06-13 11:21:35 +0530 | [diff] [blame] | 28 | }); |
| 29 | |
| 30 | // shopping cart |
Anand Doshi | 0748cb7 | 2013-09-11 15:31:58 +0530 | [diff] [blame] | 31 | if(!erpnext.cart) erpnext.cart = {}; |
| 32 | $.extend(erpnext.cart, { |
Anand Doshi | 3dceb84 | 2013-06-19 14:57:14 +0530 | [diff] [blame] | 33 | show_error: function(title, text) { |
| 34 | $("#cart-container").html('<div class="well"><h4>' + title + '</h4> ' + text + '</div>'); |
| 35 | }, |
| 36 | |
Anand Doshi | c2a3527 | 2013-06-19 17:19:20 +0530 | [diff] [blame] | 37 | bind_events: function() { |
| 38 | // bind update button |
| 39 | $(document).on("click", ".item-update-cart button", function() { |
Anand Doshi | c2a3527 | 2013-06-19 17:19:20 +0530 | [diff] [blame] | 40 | var item_code = $(this).attr("data-item-code"); |
Anand Doshi | 0748cb7 | 2013-09-11 15:31:58 +0530 | [diff] [blame] | 41 | erpnext.cart.update_cart({ |
Anand Doshi | c2a3527 | 2013-06-19 17:19:20 +0530 | [diff] [blame] | 42 | item_code: item_code, |
| 43 | qty: $('input[data-item-code="'+item_code+'"]').val(), |
| 44 | with_doclist: 1, |
| 45 | btn: this, |
| 46 | callback: function(r) { |
| 47 | if(!r.exc) { |
Anand Doshi | 0748cb7 | 2013-09-11 15:31:58 +0530 | [diff] [blame] | 48 | erpnext.cart.render(r.message); |
Anand Doshi | c2a3527 | 2013-06-19 17:19:20 +0530 | [diff] [blame] | 49 | var $button = $('button[data-item-code="'+item_code+'"]').addClass("btn-success"); |
| 50 | setTimeout(function() { $button.removeClass("btn-success"); }, 1000); |
| 51 | } |
| 52 | }, |
| 53 | }); |
| 54 | }); |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 55 | |
| 56 | $("#cart-add-shipping-address").on("click", function() { |
| 57 | window.location.href = "address?address_fieldname=shipping_address_name"; |
| 58 | }); |
| 59 | |
| 60 | $("#cart-add-billing-address").on("click", function() { |
| 61 | window.location.href = "address?address_fieldname=customer_address"; |
| 62 | }); |
Anand Doshi | 2ac0a83 | 2013-07-10 20:49:44 +0530 | [diff] [blame] | 63 | |
| 64 | $(".btn-place-order").on("click", function() { |
Anand Doshi | 0748cb7 | 2013-09-11 15:31:58 +0530 | [diff] [blame] | 65 | erpnext.cart.place_order(this); |
Anand Doshi | 2ac0a83 | 2013-07-10 20:49:44 +0530 | [diff] [blame] | 66 | }); |
Anand Doshi | c2a3527 | 2013-06-19 17:19:20 +0530 | [diff] [blame] | 67 | }, |
| 68 | |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 69 | render: function(out) { |
| 70 | var doclist = out.doclist; |
| 71 | var addresses = out.addresses; |
Anand Doshi | 0b4943c | 2013-07-04 23:45:22 +0530 | [diff] [blame] | 72 | |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 73 | var $cart_items = $("#cart-items").empty(); |
| 74 | var $cart_taxes = $("#cart-taxes").empty(); |
Anand Doshi | 0b4943c | 2013-07-04 23:45:22 +0530 | [diff] [blame] | 75 | var $cart_totals = $("#cart-totals").empty(); |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 76 | var $cart_billing_address = $("#cart-billing-address").empty(); |
| 77 | var $cart_shipping_address = $("#cart-shipping-address").empty(); |
Anand Doshi | c2a3527 | 2013-06-19 17:19:20 +0530 | [diff] [blame] | 78 | |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 79 | var no_items = $.map(doclist, function(d) { return d.item_code || null;}).length===0; |
| 80 | if(no_items) { |
Bárbara Perretti | 187ea33 | 2013-10-09 14:53:44 -0300 | [diff] [blame] | 81 | erpnext.cart.show_error("Empty :-(", wn._("Go ahead and add something to your cart.")); |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 82 | $("#cart-addresses").toggle(false); |
Anand Doshi | c2a3527 | 2013-06-19 17:19:20 +0530 | [diff] [blame] | 83 | return; |
| 84 | } |
| 85 | |
Anand Doshi | 0b4943c | 2013-07-04 23:45:22 +0530 | [diff] [blame] | 86 | var shipping_rule_added = false; |
| 87 | var taxes_exist = false; |
Anand Doshi | 2862c9e | 2013-07-08 18:50:33 +0530 | [diff] [blame] | 88 | var shipping_rule_labels = $.map(out.shipping_rules || [], function(rule) { return rule[1]; }); |
Anand Doshi | c2a3527 | 2013-06-19 17:19:20 +0530 | [diff] [blame] | 89 | $.each(doclist, function(i, doc) { |
| 90 | if(doc.doctype === "Quotation Item") { |
Anand Doshi | 0748cb7 | 2013-09-11 15:31:58 +0530 | [diff] [blame] | 91 | erpnext.cart.render_item_row($cart_items, doc); |
Anand Doshi | 0b4943c | 2013-07-04 23:45:22 +0530 | [diff] [blame] | 92 | } else if (doc.doctype === "Sales Taxes and Charges") { |
| 93 | if(out.shipping_rules && out.shipping_rules.length && |
| 94 | shipping_rule_labels.indexOf(doc.description)!==-1) { |
| 95 | shipping_rule_added = true; |
Anand Doshi | 0748cb7 | 2013-09-11 15:31:58 +0530 | [diff] [blame] | 96 | erpnext.cart.render_tax_row($cart_taxes, doc, out.shipping_rules); |
Anand Doshi | 0b4943c | 2013-07-04 23:45:22 +0530 | [diff] [blame] | 97 | } else { |
Anand Doshi | 0748cb7 | 2013-09-11 15:31:58 +0530 | [diff] [blame] | 98 | erpnext.cart.render_tax_row($cart_taxes, doc); |
Anand Doshi | 0b4943c | 2013-07-04 23:45:22 +0530 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | taxes_exist = true; |
Anand Doshi | c2a3527 | 2013-06-19 17:19:20 +0530 | [diff] [blame] | 102 | } |
| 103 | }); |
| 104 | |
Anand Doshi | 0b4943c | 2013-07-04 23:45:22 +0530 | [diff] [blame] | 105 | if(out.shipping_rules && out.shipping_rules.length && !shipping_rule_added) { |
Anand Doshi | 0748cb7 | 2013-09-11 15:31:58 +0530 | [diff] [blame] | 106 | erpnext.cart.render_tax_row($cart_taxes, {description: "", formatted_tax_amount: ""}, |
Anand Doshi | 0b4943c | 2013-07-04 23:45:22 +0530 | [diff] [blame] | 107 | out.shipping_rules); |
| 108 | taxes_exist = true; |
| 109 | } |
| 110 | |
| 111 | if(taxes_exist) |
| 112 | $('<hr>').appendTo($cart_taxes); |
| 113 | |
Anand Doshi | 0748cb7 | 2013-09-11 15:31:58 +0530 | [diff] [blame] | 114 | erpnext.cart.render_tax_row($cart_totals, { |
Anand Doshi | 0b4943c | 2013-07-04 23:45:22 +0530 | [diff] [blame] | 115 | description: "<strong>Total</strong>", |
| 116 | formatted_tax_amount: "<strong>" + doclist[0].formatted_grand_total_export + "</strong>" |
| 117 | }); |
| 118 | |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 119 | if(!(addresses && addresses.length)) { |
Bárbara Perretti | 187ea33 | 2013-10-09 14:53:44 -0300 | [diff] [blame] | 120 | $cart_shipping_address.html('<div class="well">'+wn._("Hey! Go ahead and add an address")+'</div>'); |
Anand Doshi | ab69029 | 2013-06-13 11:21:35 +0530 | [diff] [blame] | 121 | } else { |
Anand Doshi | 0748cb7 | 2013-09-11 15:31:58 +0530 | [diff] [blame] | 122 | erpnext.cart.render_address($cart_shipping_address, addresses, doclist[0].shipping_address_name); |
| 123 | erpnext.cart.render_address($cart_billing_address, addresses, doclist[0].customer_address); |
Anand Doshi | ab69029 | 2013-06-13 11:21:35 +0530 | [diff] [blame] | 124 | } |
Anand Doshi | abc1003 | 2013-06-14 17:44:03 +0530 | [diff] [blame] | 125 | }, |
| 126 | |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 127 | render_item_row: function($cart_items, doc) { |
Nabin Hait | 6ec4b0c | 2013-09-26 15:45:44 +0530 | [diff] [blame] | 128 | doc.image_html = doc.website_image ? |
| 129 | '<div style="height: 120px; overflow: hidden;"><img src="' + doc.website_image + '" /></div>' : |
Anand Doshi | b0d996f | 2013-09-10 18:29:39 +0530 | [diff] [blame] | 130 | '{% include "app/stock/doctype/item/templates/includes/product_missing_image.html" %}'; |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 131 | |
Anand Doshi | cefccb9 | 2013-07-15 18:28:14 +0530 | [diff] [blame] | 132 | if(doc.description === doc.item_name) doc.description = ""; |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 133 | |
| 134 | $(repl('<div class="row">\ |
Rushabh Mehta | cce21d1 | 2013-08-21 17:48:08 +0530 | [diff] [blame] | 135 | <div class="col-md-9 col-sm-9">\ |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 136 | <div class="row">\ |
Rushabh Mehta | cce21d1 | 2013-08-21 17:48:08 +0530 | [diff] [blame] | 137 | <div class="col-md-3">%(image_html)s</div>\ |
| 138 | <div class="col-md-9">\ |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 139 | <h4><a href="%(page_name)s">%(item_name)s</a></h4>\ |
Anand Doshi | cefccb9 | 2013-07-15 18:28:14 +0530 | [diff] [blame] | 140 | <p>%(description)s</p>\ |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 141 | </div>\ |
| 142 | </div>\ |
| 143 | </div>\ |
Rushabh Mehta | cce21d1 | 2013-08-21 17:48:08 +0530 | [diff] [blame] | 144 | <div class="col-md-3 col-sm-3 text-right">\ |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 145 | <div class="input-group item-update-cart">\ |
| 146 | <input type="text" placeholder="Qty" value="%(qty)s" \ |
Anand Doshi | 65f5c58 | 2013-08-21 19:36:23 +0530 | [diff] [blame] | 147 | data-item-code="%(item_code)s" class="text-right form-control">\ |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 148 | <div class="input-group-btn">\ |
| 149 | <button class="btn btn-primary" data-item-code="%(item_code)s">\ |
| 150 | <i class="icon-ok"></i></button>\ |
| 151 | </div>\ |
| 152 | </div>\ |
| 153 | <p style="margin-top: 10px;">at %(formatted_rate)s</p>\ |
| 154 | <small class="text-muted" style="margin-top: 10px;">= %(formatted_amount)s</small>\ |
| 155 | </div>\ |
| 156 | </div><hr>', doc)).appendTo($cart_items); |
| 157 | }, |
| 158 | |
Anand Doshi | 0b4943c | 2013-07-04 23:45:22 +0530 | [diff] [blame] | 159 | render_tax_row: function($cart_taxes, doc, shipping_rules) { |
| 160 | var shipping_selector; |
| 161 | if(shipping_rules) { |
Anand Doshi | 65f5c58 | 2013-08-21 19:36:23 +0530 | [diff] [blame] | 162 | shipping_selector = '<select class="form-control">' + $.map(shipping_rules, function(rule) { |
Anand Doshi | 0b4943c | 2013-07-04 23:45:22 +0530 | [diff] [blame] | 163 | return '<option value="' + rule[0] + '">' + rule[1] + '</option>' }).join("\n") + |
| 164 | '</select>'; |
| 165 | } |
| 166 | |
| 167 | var $tax_row = $(repl('<div class="row">\ |
Rushabh Mehta | cce21d1 | 2013-08-21 17:48:08 +0530 | [diff] [blame] | 168 | <div class="col-md-9 col-sm-9">\ |
Anand Doshi | 0b4943c | 2013-07-04 23:45:22 +0530 | [diff] [blame] | 169 | <div class="row">\ |
Rushabh Mehta | cce21d1 | 2013-08-21 17:48:08 +0530 | [diff] [blame] | 170 | <div class="col-md-9 col-md-offset-3">' + |
Anand Doshi | 0b4943c | 2013-07-04 23:45:22 +0530 | [diff] [blame] | 171 | (shipping_selector || '<p>%(description)s</p>') + |
| 172 | '</div>\ |
| 173 | </div>\ |
| 174 | </div>\ |
Rushabh Mehta | cce21d1 | 2013-08-21 17:48:08 +0530 | [diff] [blame] | 175 | <div class="col-md-3 col-sm-3 text-right">\ |
Anand Doshi | 0b4943c | 2013-07-04 23:45:22 +0530 | [diff] [blame] | 176 | <p' + (shipping_selector ? ' style="margin-top: 5px;"' : "") + '>%(formatted_tax_amount)s</p>\ |
| 177 | </div>\ |
| 178 | </div>', doc)).appendTo($cart_taxes); |
| 179 | |
| 180 | if(shipping_selector) { |
| 181 | $tax_row.find('select option').each(function(i, opt) { |
| 182 | if($(opt).html() == doc.description) { |
| 183 | $(opt).attr("selected", "selected"); |
| 184 | } |
| 185 | }); |
| 186 | $tax_row.find('select').on("change", function() { |
Anand Doshi | 0748cb7 | 2013-09-11 15:31:58 +0530 | [diff] [blame] | 187 | erpnext.cart.apply_shipping_rule($(this).val(), this); |
Anand Doshi | 0b4943c | 2013-07-04 23:45:22 +0530 | [diff] [blame] | 188 | }); |
| 189 | } |
| 190 | }, |
| 191 | |
| 192 | apply_shipping_rule: function(rule, btn) { |
Anand Doshi | 1fac2a9 | 2013-07-29 19:30:39 +0530 | [diff] [blame] | 193 | return wn.call({ |
Anand Doshi | 0b4943c | 2013-07-04 23:45:22 +0530 | [diff] [blame] | 194 | btn: btn, |
| 195 | type: "POST", |
Rushabh Mehta | c59c4e0 | 2013-09-09 12:17:45 +0530 | [diff] [blame] | 196 | method: "selling.utils.cart.apply_shipping_rule", |
Anand Doshi | 0b4943c | 2013-07-04 23:45:22 +0530 | [diff] [blame] | 197 | args: { shipping_rule: rule }, |
| 198 | callback: function(r) { |
| 199 | if(!r.exc) { |
Anand Doshi | 0748cb7 | 2013-09-11 15:31:58 +0530 | [diff] [blame] | 200 | erpnext.cart.render(r.message); |
Anand Doshi | 0b4943c | 2013-07-04 23:45:22 +0530 | [diff] [blame] | 201 | } |
| 202 | } |
| 203 | }); |
| 204 | }, |
| 205 | |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 206 | render_address: function($address_wrapper, addresses, address_name) { |
| 207 | $.each(addresses, function(i, address) { |
Anand Doshi | 65f5c58 | 2013-08-21 19:36:23 +0530 | [diff] [blame] | 208 | $(repl('<div class="panel panel-default"> \ |
| 209 | <div class="panel-heading"> \ |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 210 | <div class="row"> \ |
Rushabh Mehta | cce21d1 | 2013-08-21 17:48:08 +0530 | [diff] [blame] | 211 | <div class="col-md-10 address-title" \ |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 212 | data-address-name="%(name)s"><strong>%(name)s</strong></div> \ |
Rushabh Mehta | cce21d1 | 2013-08-21 17:48:08 +0530 | [diff] [blame] | 213 | <div class="col-md-2"><input type="checkbox" \ |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 214 | data-address-name="%(name)s"></div> \ |
| 215 | </div> \ |
| 216 | </div> \ |
Anand Doshi | 65f5c58 | 2013-08-21 19:36:23 +0530 | [diff] [blame] | 217 | <div class="panel-collapse collapse" data-address-name="%(name)s"> \ |
| 218 | <div class="panel-body">%(display)s</div> \ |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 219 | </div> \ |
| 220 | </div>', address)) |
| 221 | .css({"margin": "10px auto"}) |
| 222 | .appendTo($address_wrapper); |
| 223 | }); |
| 224 | |
Anand Doshi | 65f5c58 | 2013-08-21 19:36:23 +0530 | [diff] [blame] | 225 | $address_wrapper.find(".panel-heading") |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 226 | .find(".address-title") |
| 227 | .css({"cursor": "pointer"}) |
| 228 | .on("click", function() { |
Anand Doshi | 65f5c58 | 2013-08-21 19:36:23 +0530 | [diff] [blame] | 229 | $address_wrapper.find('.panel-collapse[data-address-name="' |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 230 | +$(this).attr("data-address-name")+'"]').collapse("toggle"); |
| 231 | }); |
| 232 | |
| 233 | $address_wrapper.find('input[type="checkbox"]').on("click", function() { |
Anand Doshi | 1672fd8 | 2013-07-24 13:07:23 +0530 | [diff] [blame] | 234 | if($(this).prop("checked")) { |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 235 | var me = this; |
| 236 | $address_wrapper.find('input[type="checkbox"]').each(function(i, chk) { |
| 237 | if($(chk).attr("data-address-name")!=$(me).attr("data-address-name")) { |
Anand Doshi | 1672fd8 | 2013-07-24 13:07:23 +0530 | [diff] [blame] | 238 | $(chk).prop("checked", false); |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 239 | } |
| 240 | }); |
| 241 | |
Anand Doshi | 1fac2a9 | 2013-07-29 19:30:39 +0530 | [diff] [blame] | 242 | return wn.call({ |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 243 | type: "POST", |
Rushabh Mehta | c59c4e0 | 2013-09-09 12:17:45 +0530 | [diff] [blame] | 244 | method: "selling.utils.cart.update_cart_address", |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 245 | args: { |
| 246 | address_fieldname: $address_wrapper.attr("data-fieldname"), |
| 247 | address_name: $(this).attr("data-address-name") |
| 248 | }, |
| 249 | callback: function(r) { |
| 250 | if(!r.exc) { |
Anand Doshi | 0748cb7 | 2013-09-11 15:31:58 +0530 | [diff] [blame] | 251 | erpnext.cart.render(r.message); |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | }); |
| 255 | } else { |
| 256 | return false; |
| 257 | } |
| 258 | }); |
| 259 | |
| 260 | $address_wrapper.find('input[type="checkbox"][data-address-name="'+ address_name +'"]') |
Anand Doshi | 1672fd8 | 2013-07-24 13:07:23 +0530 | [diff] [blame] | 261 | .prop("checked", true); |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 262 | |
Anand Doshi | 65f5c58 | 2013-08-21 19:36:23 +0530 | [diff] [blame] | 263 | $address_wrapper.find(".panel-collapse").collapse({ |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 264 | parent: $address_wrapper, |
| 265 | toggle: false |
| 266 | }); |
| 267 | |
Anand Doshi | 65f5c58 | 2013-08-21 19:36:23 +0530 | [diff] [blame] | 268 | $address_wrapper.find('.panel-collapse[data-address-name="'+ address_name +'"]') |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 269 | .collapse("show"); |
Anand Doshi | 2ac0a83 | 2013-07-10 20:49:44 +0530 | [diff] [blame] | 270 | }, |
| 271 | |
Anand Doshi | 0748cb7 | 2013-09-11 15:31:58 +0530 | [diff] [blame] | 272 | place_order: function(btn) { |
Anand Doshi | 1fac2a9 | 2013-07-29 19:30:39 +0530 | [diff] [blame] | 273 | return wn.call({ |
Anand Doshi | 2ac0a83 | 2013-07-10 20:49:44 +0530 | [diff] [blame] | 274 | type: "POST", |
Rushabh Mehta | c59c4e0 | 2013-09-09 12:17:45 +0530 | [diff] [blame] | 275 | method: "selling.utils.cart.place_order", |
Anand Doshi | 0748cb7 | 2013-09-11 15:31:58 +0530 | [diff] [blame] | 276 | btn: btn, |
Anand Doshi | 2ac0a83 | 2013-07-10 20:49:44 +0530 | [diff] [blame] | 277 | callback: function(r) { |
| 278 | if(r.exc) { |
| 279 | var msg = ""; |
| 280 | if(r._server_messages) { |
| 281 | msg = JSON.parse(r._server_messages || []).join("<br>"); |
| 282 | } |
| 283 | |
| 284 | $("#cart-error") |
| 285 | .empty() |
Bárbara Perretti | 187ea33 | 2013-10-09 14:53:44 -0300 | [diff] [blame] | 286 | .html(msg || wn._("Something went wrong!")) |
Anand Doshi | 2ac0a83 | 2013-07-10 20:49:44 +0530 | [diff] [blame] | 287 | .toggle(true); |
| 288 | } else { |
| 289 | window.location.href = "order?name=" + encodeURIComponent(r.message); |
| 290 | } |
| 291 | } |
| 292 | }); |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 293 | } |
Anand Doshi | ab69029 | 2013-06-13 11:21:35 +0530 | [diff] [blame] | 294 | }); |