2013-08-05 09:29:54 +00:00
|
|
|
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
|
|
|
|
// License: GNU General Public License v3. See license.txt
|
|
|
|
|
2013-08-30 12:53:50 +00:00
|
|
|
if(!window.erpnext) erpnext = {};
|
2012-12-14 11:09:27 +00:00
|
|
|
|
2013-03-19 05:42:22 +00:00
|
|
|
// Add / update a new Lead / Communication
|
2012-12-14 11:09:27 +00:00
|
|
|
// subject, sender, description
|
|
|
|
erpnext.send_message = function(opts) {
|
2013-07-29 14:00:39 +00:00
|
|
|
return wn.call({
|
2013-03-19 12:29:49 +00:00
|
|
|
type: "POST",
|
2013-09-09 06:47:45 +00:00
|
|
|
method: "selling.utils.contact.send_message",
|
2013-03-19 12:29:49 +00:00
|
|
|
args: opts,
|
|
|
|
callback: opts.callback
|
2013-07-02 06:10:16 +00:00
|
|
|
});
|
2013-03-19 12:29:49 +00:00
|
|
|
}
|
|
|
|
|
2013-03-19 05:42:22 +00:00
|
|
|
// Setup the user tools
|
|
|
|
//
|
|
|
|
$(document).ready(function() {
|
|
|
|
// update login
|
2013-09-11 10:01:58 +00:00
|
|
|
erpnext.cart.set_cart_count();
|
2013-07-10 15:19:44 +00:00
|
|
|
|
2013-06-13 05:51:35 +00:00
|
|
|
$("#user-tools a").tooltip({"placement":"bottom"});
|
|
|
|
$("#user-tools-post-login a").tooltip({"placement":"bottom"});
|
|
|
|
});
|
2013-03-19 05:42:22 +00:00
|
|
|
|
2013-06-13 05:51:35 +00:00
|
|
|
// shopping cart
|
2013-09-11 10:01:58 +00:00
|
|
|
if(!erpnext.cart) erpnext.cart = {};
|
2013-06-19 09:27:14 +00:00
|
|
|
|
2013-09-11 10:01:58 +00:00
|
|
|
$.extend(erpnext.cart, {
|
2013-06-19 09:27:14 +00:00
|
|
|
update_cart: function(opts) {
|
|
|
|
if(!full_name) {
|
|
|
|
if(localStorage) {
|
2013-09-05 06:49:00 +00:00
|
|
|
localStorage.setItem("last_visited", window.location.href.split("/").slice(-1)[0]);
|
2013-06-19 09:27:14 +00:00
|
|
|
localStorage.setItem("pending_add_to_cart", opts.item_code);
|
|
|
|
}
|
|
|
|
window.location.href = "login";
|
|
|
|
} else {
|
2013-07-29 14:00:39 +00:00
|
|
|
return wn.call({
|
2013-06-19 09:27:14 +00:00
|
|
|
type: "POST",
|
2013-09-09 06:47:45 +00:00
|
|
|
method: "selling.utils.cart.update_cart",
|
2013-06-19 09:27:14 +00:00
|
|
|
args: {
|
|
|
|
item_code: opts.item_code,
|
2013-06-19 11:49:20 +00:00
|
|
|
qty: opts.qty,
|
|
|
|
with_doclist: opts.with_doclist
|
2013-06-19 09:27:14 +00:00
|
|
|
},
|
|
|
|
btn: opts.btn,
|
|
|
|
callback: function(r) {
|
|
|
|
if(opts.callback)
|
|
|
|
opts.callback(r);
|
2013-07-10 15:19:44 +00:00
|
|
|
|
2013-09-11 10:01:58 +00:00
|
|
|
erpnext.cart.set_cart_count();
|
2013-06-19 09:27:14 +00:00
|
|
|
}
|
|
|
|
});
|
2013-06-13 05:51:35 +00:00
|
|
|
}
|
|
|
|
},
|
2013-07-10 15:19:44 +00:00
|
|
|
|
|
|
|
set_cart_count: function() {
|
|
|
|
var cart_count = getCookie("cart_count");
|
2013-09-11 10:01:58 +00:00
|
|
|
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 06:49:00 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-11 10:01:58 +00:00
|
|
|
});
|