brotherton-erpnext/erpnext/public/js/website_utils.js

86 lines
2.1 KiB
JavaScript
Raw Normal View History

2013-11-20 07:29:58 +00:00
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt
if(!window.erpnext) erpnext = {};
2013-03-19 05:42:22 +00:00
// Add / update a new Lead / Communication
// subject, sender, description
2013-09-11 13:28:20 +00:00
wn.send_message = function(opts, btn) {
return wn.call({
2013-03-19 12:29:49 +00:00
type: "POST",
method: "erpnext.portal.utils.send_message",
2013-09-11 13:28:20 +00:00
btn: btn,
2013-03-19 12:29:49 +00:00
args: opts,
callback: opts.callback
});
2013-09-11 13:28:20 +00:00
};
// for backward compatibility
erpnext.send_message = wn.send_message;
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-09-16 13:58:06 +00:00
// 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 05:51:35 +00:00
});
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) {
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 {
return wn.call({
2013-06-19 09:27:14 +00:00
type: "POST",
method: "erpnext.selling.utils.cart.update_cart",
2013-06-19 09:27:14 +00:00
args: {
item_code: opts.item_code,
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-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
}
},
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-11 10:01:58 +00:00
});