blob: 06bbe590cd55040e4e258c459a862492f1dba44b [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 Doshi3966c4c2013-09-16 19:28:06 +053027 // 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 Doshiab690292013-06-13 11:21:35 +053033});
Rushabh Mehtaa54cb242013-03-19 11:12:22 +053034
Anand Doshiab690292013-06-13 11:21:35 +053035// shopping cart
Anand Doshi0748cb72013-09-11 15:31:58 +053036if(!erpnext.cart) erpnext.cart = {};
Anand Doshi3dceb842013-06-19 14:57:14 +053037
Anand Doshi0748cb72013-09-11 15:31:58 +053038$.extend(erpnext.cart, {
Anand Doshi3dceb842013-06-19 14:57:14 +053039 update_cart: function(opts) {
40 if(!full_name) {
41 if(localStorage) {
Anand Doshia9c0f5d2013-09-05 12:19:00 +053042 localStorage.setItem("last_visited", window.location.href.split("/").slice(-1)[0]);
Anand Doshi3dceb842013-06-19 14:57:14 +053043 localStorage.setItem("pending_add_to_cart", opts.item_code);
44 }
45 window.location.href = "login";
46 } else {
Anand Doshi1fac2a92013-07-29 19:30:39 +053047 return wn.call({
Anand Doshi3dceb842013-06-19 14:57:14 +053048 type: "POST",
Rushabh Mehtac59c4e02013-09-09 12:17:45 +053049 method: "selling.utils.cart.update_cart",
Anand Doshi3dceb842013-06-19 14:57:14 +053050 args: {
51 item_code: opts.item_code,
Anand Doshic2a35272013-06-19 17:19:20 +053052 qty: opts.qty,
53 with_doclist: opts.with_doclist
Anand Doshi3dceb842013-06-19 14:57:14 +053054 },
55 btn: opts.btn,
56 callback: function(r) {
57 if(opts.callback)
58 opts.callback(r);
Anand Doshi2ac0a832013-07-10 20:49:44 +053059
Anand Doshi0748cb72013-09-11 15:31:58 +053060 erpnext.cart.set_cart_count();
Anand Doshi3dceb842013-06-19 14:57:14 +053061 }
62 });
Anand Doshiab690292013-06-13 11:21:35 +053063 }
Anand Doshiab690292013-06-13 11:21:35 +053064 },
Anand Doshi2ac0a832013-07-10 20:49:44 +053065
66 set_cart_count: function() {
67 var cart_count = getCookie("cart_count");
Anand Doshi0748cb72013-09-11 15:31:58 +053068 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 Doshia9c0f5d2013-09-05 12:19:00 +053084 }
Anand Doshia9c0f5d2013-09-05 12:19:00 +053085 }
Anand Doshi0748cb72013-09-11 15:31:58 +053086});