2013-11-20 12:59:58 +05:30
|
|
|
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
2013-08-05 14:59:54 +05:30
|
|
|
// License: GNU General Public License v3. See license.txt
|
|
|
|
|
2013-08-30 18:23:50 +05:30
|
|
|
if(!window.erpnext) erpnext = {};
|
2012-12-14 16:39:27 +05:30
|
|
|
|
2013-03-19 11:12:22 +05:30
|
|
|
// Add / update a new Lead / Communication
|
2012-12-14 16:39:27 +05:30
|
|
|
// subject, sender, description
|
2013-09-11 18:58:20 +05:30
|
|
|
wn.send_message = function(opts, btn) {
|
2013-07-29 19:30:39 +05:30
|
|
|
return wn.call({
|
2013-03-19 17:59:49 +05:30
|
|
|
type: "POST",
|
2013-09-11 18:58:20 +05:30
|
|
|
method: "portal.utils.send_message",
|
|
|
|
btn: btn,
|
2013-03-19 17:59:49 +05:30
|
|
|
args: opts,
|
|
|
|
callback: opts.callback
|
2013-07-02 11:40:16 +05:30
|
|
|
});
|
2013-09-11 18:58:20 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
// for backward compatibility
|
|
|
|
erpnext.send_message = wn.send_message;
|
2013-03-19 17:59:49 +05:30
|
|
|
|
2013-03-19 11:12:22 +05:30
|
|
|
// Setup the user tools
|
|
|
|
//
|
|
|
|
$(document).ready(function() {
|
|
|
|
// update login
|
2013-09-11 15:31:58 +05:30
|
|
|
erpnext.cart.set_cart_count();
|
2013-07-10 20:49:44 +05:30
|
|
|
|
2013-09-16 19:28:06 +05:30
|
|
|
// update profile
|
|
|
|
if(full_name) {
|
|
|
|
$('.navbar li[data-label="Profile"] a')
|
|
|
|
.html('<i class="icon-fixed-width icon-user"></i> ' + full_name);
|
|
|
|
}
|
|
|
|
|
2013-06-13 11:21:35 +05:30
|
|
|
});
|
2013-03-19 11:12:22 +05:30
|
|
|
|
2013-06-13 11:21:35 +05:30
|
|
|
// shopping cart
|
2013-09-11 15:31:58 +05:30
|
|
|
if(!erpnext.cart) erpnext.cart = {};
|
2013-06-19 14:57:14 +05:30
|
|
|
|
2013-09-11 15:31:58 +05:30
|
|
|
$.extend(erpnext.cart, {
|
2013-06-19 14:57:14 +05:30
|
|
|
update_cart: function(opts) {
|
|
|
|
if(!full_name) {
|
|
|
|
if(localStorage) {
|
2013-09-05 12:19:00 +05:30
|
|
|
localStorage.setItem("last_visited", window.location.href.split("/").slice(-1)[0]);
|
2013-06-19 14:57:14 +05:30
|
|
|
localStorage.setItem("pending_add_to_cart", opts.item_code);
|
|
|
|
}
|
|
|
|
window.location.href = "login";
|
|
|
|
} else {
|
2013-07-29 19:30:39 +05:30
|
|
|
return wn.call({
|
2013-06-19 14:57:14 +05:30
|
|
|
type: "POST",
|
2013-09-09 12:17:45 +05:30
|
|
|
method: "selling.utils.cart.update_cart",
|
2013-06-19 14:57:14 +05:30
|
|
|
args: {
|
|
|
|
item_code: opts.item_code,
|
2013-06-19 17:19:20 +05:30
|
|
|
qty: opts.qty,
|
|
|
|
with_doclist: opts.with_doclist
|
2013-06-19 14:57:14 +05:30
|
|
|
},
|
|
|
|
btn: opts.btn,
|
|
|
|
callback: function(r) {
|
|
|
|
if(opts.callback)
|
|
|
|
opts.callback(r);
|
2013-07-10 20:49:44 +05:30
|
|
|
|
2013-09-11 15:31:58 +05:30
|
|
|
erpnext.cart.set_cart_count();
|
2013-06-19 14:57:14 +05:30
|
|
|
}
|
|
|
|
});
|
2013-06-13 11:21:35 +05:30
|
|
|
}
|
|
|
|
},
|
2013-07-10 20:49:44 +05:30
|
|
|
|
|
|
|
set_cart_count: function() {
|
|
|
|
var cart_count = getCookie("cart_count");
|
2013-09-11 15:31:58 +05:30
|
|
|
var $cart = $("#website-post-login").find('[data-label="Cart"]');
|
|
|
|
var $badge = $cart.find(".badge");
|
|
|
|
var $cog = $("#website-post-login").find(".dropdown-toggle");
|
|
|
|
var $cog_count = $cog.find(".cart-count");
|
|
|
|
if(cart_count) {
|
|
|
|
if($badge.length === 0) {
|
|
|
|
var $badge = $('<span class="badge pull-right"></span>').appendTo($cart.find("a"));
|
|
|
|
}
|
|
|
|
$badge.html(cart_count);
|
|
|
|
if($cog_count.length === 0) {
|
|
|
|
var $cog_count = $('<sup class="cart-count"></span>').insertAfter($cog.find(".icon-cog"));
|
|
|
|
}
|
|
|
|
$cog_count.html(cart_count);
|
|
|
|
} else {
|
|
|
|
$badge.remove();
|
|
|
|
$cog_count.remove();
|
2013-09-05 12:19:00 +05:30
|
|
|
}
|
|
|
|
}
|
2013-09-11 15:31:58 +05:30
|
|
|
});
|