blob: fceb8f655aa394c9ad771fc071d49fe95d936c1c [file] [log] [blame]
Rushabh Mehtae67d1fb2013-08-05 14:59:54 +05301// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
2// License: GNU General Public License v3. See license.txt
3
Anand Doshi6c8ef772013-08-30 18:23:50 +05304if(!window.erpnext) erpnext = {};
Rushabh Mehta173a0fd2012-12-14 16:39:27 +05305
Rushabh Mehtaa54cb242013-03-19 11:12:22 +05306// Add / update a new Lead / Communication
Rushabh Mehta173a0fd2012-12-14 16:39:27 +05307// subject, sender, description
Anand Doshifb109ad2013-09-11 18:58:20 +05308wn.send_message = function(opts, btn) {
Anand Doshi1fac2a92013-07-29 19:30:39 +05309 return wn.call({
Rushabh Mehtaa75efa72013-03-19 17:59:49 +053010 type: "POST",
Anand Doshifb109ad2013-09-11 18:58:20 +053011 method: "portal.utils.send_message",
12 btn: btn,
Rushabh Mehtaa75efa72013-03-19 17:59:49 +053013 args: opts,
14 callback: opts.callback
Anand Doshiedbf3e12013-07-02 11:40:16 +053015 });
Anand Doshifb109ad2013-09-11 18:58:20 +053016};
17
18// for backward compatibility
19erpnext.send_message = wn.send_message;
Rushabh Mehtaa75efa72013-03-19 17:59:49 +053020
Rushabh Mehtaa54cb242013-03-19 11:12:22 +053021// Setup the user tools
22//
23$(document).ready(function() {
24 // update login
Anand Doshi0748cb72013-09-11 15:31:58 +053025 erpnext.cart.set_cart_count();
Anand Doshi2ac0a832013-07-10 20:49:44 +053026
Anand Doshiab690292013-06-13 11:21:35 +053027 $("#user-tools a").tooltip({"placement":"bottom"});
28 $("#user-tools-post-login a").tooltip({"placement":"bottom"});
Anand Doshiab690292013-06-13 11:21:35 +053029});
Rushabh Mehtaa54cb242013-03-19 11:12:22 +053030
Anand Doshiab690292013-06-13 11:21:35 +053031// shopping cart
Anand Doshi0748cb72013-09-11 15:31:58 +053032if(!erpnext.cart) erpnext.cart = {};
Anand Doshi3dceb842013-06-19 14:57:14 +053033
Anand Doshi0748cb72013-09-11 15:31:58 +053034$.extend(erpnext.cart, {
Anand Doshi3dceb842013-06-19 14:57:14 +053035 update_cart: function(opts) {
36 if(!full_name) {
37 if(localStorage) {
Anand Doshia9c0f5d2013-09-05 12:19:00 +053038 localStorage.setItem("last_visited", window.location.href.split("/").slice(-1)[0]);
Anand Doshi3dceb842013-06-19 14:57:14 +053039 localStorage.setItem("pending_add_to_cart", opts.item_code);
40 }
41 window.location.href = "login";
42 } else {
Anand Doshi1fac2a92013-07-29 19:30:39 +053043 return wn.call({
Anand Doshi3dceb842013-06-19 14:57:14 +053044 type: "POST",
Rushabh Mehtac59c4e02013-09-09 12:17:45 +053045 method: "selling.utils.cart.update_cart",
Anand Doshi3dceb842013-06-19 14:57:14 +053046 args: {
47 item_code: opts.item_code,
Anand Doshic2a35272013-06-19 17:19:20 +053048 qty: opts.qty,
49 with_doclist: opts.with_doclist
Anand Doshi3dceb842013-06-19 14:57:14 +053050 },
51 btn: opts.btn,
52 callback: function(r) {
53 if(opts.callback)
54 opts.callback(r);
Anand Doshi2ac0a832013-07-10 20:49:44 +053055
Anand Doshi0748cb72013-09-11 15:31:58 +053056 erpnext.cart.set_cart_count();
Anand Doshi3dceb842013-06-19 14:57:14 +053057 }
58 });
Anand Doshiab690292013-06-13 11:21:35 +053059 }
Anand Doshiab690292013-06-13 11:21:35 +053060 },
Anand Doshi2ac0a832013-07-10 20:49:44 +053061
62 set_cart_count: function() {
63 var cart_count = getCookie("cart_count");
Anand Doshi0748cb72013-09-11 15:31:58 +053064 var $cart = $("#website-post-login").find('[data-label="Cart"]');
65 var $badge = $cart.find(".badge");
66 var $cog = $("#website-post-login").find(".dropdown-toggle");
67 var $cog_count = $cog.find(".cart-count");
68 if(cart_count) {
69 if($badge.length === 0) {
70 var $badge = $('<span class="badge pull-right"></span>').appendTo($cart.find("a"));
71 }
72 $badge.html(cart_count);
73 if($cog_count.length === 0) {
74 var $cog_count = $('<sup class="cart-count"></span>').insertAfter($cog.find(".icon-cog"));
75 }
76 $cog_count.html(cart_count);
77 } else {
78 $badge.remove();
79 $cog_count.remove();
Anand Doshia9c0f5d2013-09-05 12:19:00 +053080 }
Anand Doshia9c0f5d2013-09-05 12:19:00 +053081 }
Anand Doshi0748cb72013-09-11 15:31:58 +053082});