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 |
| 3 | |
Anand Doshi | 6c8ef77 | 2013-08-30 18:23:50 +0530 | [diff] [blame] | 4 | if(!window.erpnext) erpnext = {}; |
Rushabh Mehta | 173a0fd | 2012-12-14 16:39:27 +0530 | [diff] [blame] | 5 | |
Rushabh Mehta | a54cb24 | 2013-03-19 11:12:22 +0530 | [diff] [blame] | 6 | // Add / update a new Lead / Communication |
Rushabh Mehta | 173a0fd | 2012-12-14 16:39:27 +0530 | [diff] [blame] | 7 | // subject, sender, description |
Anand Doshi | fb109ad | 2013-09-11 18:58:20 +0530 | [diff] [blame] | 8 | wn.send_message = function(opts, btn) { |
Anand Doshi | 1fac2a9 | 2013-07-29 19:30:39 +0530 | [diff] [blame] | 9 | return wn.call({ |
Rushabh Mehta | a75efa7 | 2013-03-19 17:59:49 +0530 | [diff] [blame] | 10 | type: "POST", |
Anand Doshi | fb109ad | 2013-09-11 18:58:20 +0530 | [diff] [blame] | 11 | method: "portal.utils.send_message", |
| 12 | btn: btn, |
Rushabh Mehta | a75efa7 | 2013-03-19 17:59:49 +0530 | [diff] [blame] | 13 | args: opts, |
| 14 | callback: opts.callback |
Anand Doshi | edbf3e1 | 2013-07-02 11:40:16 +0530 | [diff] [blame] | 15 | }); |
Anand Doshi | fb109ad | 2013-09-11 18:58:20 +0530 | [diff] [blame] | 16 | }; |
| 17 | |
| 18 | // for backward compatibility |
| 19 | erpnext.send_message = wn.send_message; |
Rushabh Mehta | a75efa7 | 2013-03-19 17:59:49 +0530 | [diff] [blame] | 20 | |
Rushabh Mehta | a54cb24 | 2013-03-19 11:12:22 +0530 | [diff] [blame] | 21 | // Setup the user tools |
| 22 | // |
| 23 | $(document).ready(function() { |
| 24 | // update login |
Anand Doshi | 0748cb7 | 2013-09-11 15:31:58 +0530 | [diff] [blame] | 25 | erpnext.cart.set_cart_count(); |
Anand Doshi | 2ac0a83 | 2013-07-10 20:49:44 +0530 | [diff] [blame] | 26 | |
Anand Doshi | 3966c4c | 2013-09-16 19:28:06 +0530 | [diff] [blame] | 27 | // update profile |
| 28 | if(full_name) { |
| 29 | $('.navbar li[data-label="Profile"] a') |
| 30 | .html('<i class="icon-fixed-width icon-user"></i> ' + full_name); |
| 31 | } |
| 32 | |
Anand Doshi | ab69029 | 2013-06-13 11:21:35 +0530 | [diff] [blame] | 33 | }); |
Rushabh Mehta | a54cb24 | 2013-03-19 11:12:22 +0530 | [diff] [blame] | 34 | |
Anand Doshi | ab69029 | 2013-06-13 11:21:35 +0530 | [diff] [blame] | 35 | // shopping cart |
Anand Doshi | 0748cb7 | 2013-09-11 15:31:58 +0530 | [diff] [blame] | 36 | if(!erpnext.cart) erpnext.cart = {}; |
Anand Doshi | 3dceb84 | 2013-06-19 14:57:14 +0530 | [diff] [blame] | 37 | |
Anand Doshi | 0748cb7 | 2013-09-11 15:31:58 +0530 | [diff] [blame] | 38 | $.extend(erpnext.cart, { |
Anand Doshi | 3dceb84 | 2013-06-19 14:57:14 +0530 | [diff] [blame] | 39 | update_cart: function(opts) { |
| 40 | if(!full_name) { |
| 41 | if(localStorage) { |
Anand Doshi | a9c0f5d | 2013-09-05 12:19:00 +0530 | [diff] [blame] | 42 | localStorage.setItem("last_visited", window.location.href.split("/").slice(-1)[0]); |
Anand Doshi | 3dceb84 | 2013-06-19 14:57:14 +0530 | [diff] [blame] | 43 | localStorage.setItem("pending_add_to_cart", opts.item_code); |
| 44 | } |
| 45 | window.location.href = "login"; |
| 46 | } else { |
Anand Doshi | 1fac2a9 | 2013-07-29 19:30:39 +0530 | [diff] [blame] | 47 | return wn.call({ |
Anand Doshi | 3dceb84 | 2013-06-19 14:57:14 +0530 | [diff] [blame] | 48 | type: "POST", |
Rushabh Mehta | c59c4e0 | 2013-09-09 12:17:45 +0530 | [diff] [blame] | 49 | method: "selling.utils.cart.update_cart", |
Anand Doshi | 3dceb84 | 2013-06-19 14:57:14 +0530 | [diff] [blame] | 50 | args: { |
| 51 | item_code: opts.item_code, |
Anand Doshi | c2a3527 | 2013-06-19 17:19:20 +0530 | [diff] [blame] | 52 | qty: opts.qty, |
| 53 | with_doclist: opts.with_doclist |
Anand Doshi | 3dceb84 | 2013-06-19 14:57:14 +0530 | [diff] [blame] | 54 | }, |
| 55 | btn: opts.btn, |
| 56 | callback: function(r) { |
| 57 | if(opts.callback) |
| 58 | opts.callback(r); |
Anand Doshi | 2ac0a83 | 2013-07-10 20:49:44 +0530 | [diff] [blame] | 59 | |
Anand Doshi | 0748cb7 | 2013-09-11 15:31:58 +0530 | [diff] [blame] | 60 | erpnext.cart.set_cart_count(); |
Anand Doshi | 3dceb84 | 2013-06-19 14:57:14 +0530 | [diff] [blame] | 61 | } |
| 62 | }); |
Anand Doshi | ab69029 | 2013-06-13 11:21:35 +0530 | [diff] [blame] | 63 | } |
Anand Doshi | ab69029 | 2013-06-13 11:21:35 +0530 | [diff] [blame] | 64 | }, |
Anand Doshi | 2ac0a83 | 2013-07-10 20:49:44 +0530 | [diff] [blame] | 65 | |
| 66 | set_cart_count: function() { |
| 67 | var cart_count = getCookie("cart_count"); |
Anand Doshi | 0748cb7 | 2013-09-11 15:31:58 +0530 | [diff] [blame] | 68 | var $cart = $("#website-post-login").find('[data-label="Cart"]'); |
| 69 | var $badge = $cart.find(".badge"); |
| 70 | var $cog = $("#website-post-login").find(".dropdown-toggle"); |
| 71 | var $cog_count = $cog.find(".cart-count"); |
| 72 | if(cart_count) { |
| 73 | if($badge.length === 0) { |
| 74 | var $badge = $('<span class="badge pull-right"></span>').appendTo($cart.find("a")); |
| 75 | } |
| 76 | $badge.html(cart_count); |
| 77 | if($cog_count.length === 0) { |
| 78 | var $cog_count = $('<sup class="cart-count"></span>').insertAfter($cog.find(".icon-cog")); |
| 79 | } |
| 80 | $cog_count.html(cart_count); |
| 81 | } else { |
| 82 | $badge.remove(); |
| 83 | $cog_count.remove(); |
Anand Doshi | a9c0f5d | 2013-09-05 12:19:00 +0530 | [diff] [blame] | 84 | } |
Anand Doshi | a9c0f5d | 2013-09-05 12:19:00 +0530 | [diff] [blame] | 85 | } |
Anand Doshi | 0748cb7 | 2013-09-11 15:31:58 +0530 | [diff] [blame] | 86 | }); |