brotherton-erpnext/public/js/website_utils.js

78 lines
2.0 KiB
JavaScript
Raw Normal View History

// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
// 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
erpnext.send_message = function(opts) {
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-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-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) {
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",
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,
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
});