Reverted changes

This commit is contained in:
Kanchan Chauhan 2016-06-22 15:51:42 +05:30
parent c8d47da6bc
commit a756e3f765
4 changed files with 83 additions and 83 deletions

View File

@ -10,25 +10,29 @@ frappe.ready(function() {
$('.navbar li[data-label="User"] a') $('.navbar li[data-label="User"] a')
.html('<i class="icon-fixed-width icon-user"></i> ' + full_name); .html('<i class="icon-fixed-width icon-user"></i> ' + full_name);
} }
// update login
shopping_cart.set_cart_count();
$(".shopping-cart").on('shown.bs.dropdown', function() { // update login
if (!$('.shopping-cart-menu .cart-container').length) { shopping_cart.show_shoppingcart_dropdown();
return frappe.call({ shopping_cart.set_cart_count();
method: 'erpnext.shopping_cart.cart.get_shopping_cart_menu', shopping_cart.bind_dropdown_cart_buttons();
callback: function(r) {
if (r.message) {
$('.shopping-cart-menu').html(r.message);
$('#cart-overlay').addClass('show');
}
}
});
}
});
}); });
$.extend(shopping_cart, { $.extend(shopping_cart, {
show_shoppingcart_dropdown: function() {
$(".shopping-cart").on('shown.bs.dropdown', function() {
if (!$('.shopping-cart-menu .cart-container').length) {
return frappe.call({
method: 'erpnext.shopping_cart.cart.get_shopping_cart_menu',
callback: function(r) {
if (r.message) {
$('.shopping-cart-menu').html(r.message);
}
}
});
}
});
},
update_cart: function(opts) { update_cart: function(opts) {
if(!full_name || full_name==="Guest") { if(!full_name || full_name==="Guest") {
if(localStorage) { if(localStorage) {
@ -83,5 +87,49 @@ $.extend(shopping_cart, {
} else { } else {
$badge.remove(); $badge.remove();
} }
} },
shopping_cart_update: function(item_code, newVal, cart_dropdown) {
frappe.freeze();
shopping_cart.update_cart({
item_code: item_code,
qty: newVal,
with_items: 1,
btn: this,
callback: function(r) {
frappe.unfreeze();
if(!r.exc) {
$(".cart-items").html(r.message.items);
$(".cart-tax-items").html(r.message.taxes);
if (cart_dropdown != true) {
$(".cart-icon").hide();
}
}
},
});
},
bind_dropdown_cart_buttons: function() {
$(".cart-icon").on('click', '.number-spinner button', function () {
var btn = $(this),
input = btn.closest('.number-spinner').find('input'),
oldValue = input.val().trim(),
newVal = 0;
if (btn.attr('data-dir') == 'up') {
newVal = parseInt(oldValue) + 1;
} else {
if (oldValue > 1) {
newVal = parseInt(oldValue) - 1;
}
}
input.val(newVal);
var item_code = input.attr("data-item-code");
shopping_cart.shopping_cart_update(item_code, newVal, true);
return false;
});
},
}); });

View File

@ -13,7 +13,7 @@ class ItemPrice(Document):
def validate(self): def validate(self):
self.validate_item() self.validate_item()
self.validate_price_list() self.validate_price_list()
# self.check_duplicate_item() self.check_duplicate_item()
self.update_price_list_details() self.update_price_list_details()
self.update_item_details() self.update_item_details()
@ -25,13 +25,13 @@ class ItemPrice(Document):
enabled = frappe.db.get_value("Price List", self.price_list, "enabled") enabled = frappe.db.get_value("Price List", self.price_list, "enabled")
if not enabled: if not enabled:
throw(_("Price List {0} is disabled").format(self.price_list)) throw(_("Price List {0} is disabled").format(self.price_list))
#
# def check_duplicate_item(self): def check_duplicate_item(self):
# if frappe.db.sql("""select name from `tabItem Price` if frappe.db.sql("""select name from `tabItem Price`
# where item_code=%s and price_list=%s and name!=%s""", (self.item_code, self.price_list, self.name)): where item_code=%s and price_list=%s and name!=%s""", (self.item_code, self.price_list, self.name)):
#
# frappe.throw(_("Item {0} appears multiple times in Price List {1}").format(self.item_code, self.price_list), frappe.throw(_("Item {0} appears multiple times in Price List {1}").format(self.item_code, self.price_list),
# ItemPriceDuplicateItem) ItemPriceDuplicateItem)
def update_price_list_details(self): def update_price_list_details(self):
self.buying, self.selling, self.currency = \ self.buying, self.selling, self.currency = \

View File

@ -16,9 +16,9 @@ $.extend(shopping_cart, {
shopping_cart.bind_address_select(); shopping_cart.bind_address_select();
shopping_cart.bind_place_order(); shopping_cart.bind_place_order();
shopping_cart.bind_change_qty(); shopping_cart.bind_change_qty();
shopping_cart.bind_dropdown_cart_buttons();
}, },
bind_address_select: function() { bind_address_select: function() {
$(".cart-addresses").find('input[data-address-name]').on("click", function() { $(".cart-addresses").find('input[data-address-name]').on("click", function() {
if($(this).prop("checked")) { if($(this).prop("checked")) {
@ -54,53 +54,26 @@ $.extend(shopping_cart, {
// bind update button // bind update button
$(".cart-items").on("change", ".cart-qty", function() { $(".cart-items").on("change", ".cart-qty", function() {
var item_code = $(this).attr("data-item-code"); var item_code = $(this).attr("data-item-code");
frappe.freeze(); var newVal = $(this).val();
shopping_cart.update_cart({ shopping_cart.shopping_cart_update(item_code, newVal);
item_code: item_code,
qty: $(this).val(),
with_items: 1,
btn: this,
callback: function(r) {
frappe.unfreeze();
if(!r.exc) {
$(".cart-items").html(r.message.items);
$(".cart-tax-items").html(r.message.taxes);
$(".cart-icon").hide();
}
},
});
}); });
$(".cart-items").on('click', '.number-spinner button', function () { $(".cart-items").on('click', '.number-spinner button', function () {
var btn = $(this), var btn = $(this),
oldValue = btn.closest('.number-spinner').find('input').val().trim(), input = btn.closest('.number-spinner').find('input'),
oldValue = input.val().trim(),
newVal = 0; newVal = 0;
if (btn.attr('data-dir') == 'up') { if (btn.attr('data-dir') == 'up') {
console.log(oldValue);
newVal = parseInt(oldValue) + 1; newVal = parseInt(oldValue) + 1;
} else { } else {
if (oldValue > 1) { if (oldValue > 1) {
newVal = parseInt(oldValue) - 1; newVal = parseInt(oldValue) - 1;
} }
} }
btn.closest('.number-spinner').find('input').val(newVal); input.val(newVal);
var item_code = btn.closest('.number-spinner').find('input').attr("data-item-code"); var item_code = input.attr("data-item-code");
frappe.freeze(); shopping_cart.shopping_cart_update(item_code, newVal);
shopping_cart.update_cart({
item_code: item_code,
qty: newVal,
with_items: 1,
btn: this,
callback: function(r) {
frappe.unfreeze();
if(!r.exc) {
$(".cart-items").html(r.message.items);
$(".cart-tax-items").html(r.message.taxes);
$(".cart-icon").hide();
}
},
});
}); });
}, },
@ -175,7 +148,7 @@ $.extend(shopping_cart, {
} }
}); });
$(document).ready(function() { frappe.ready(function() {
$(".cart-icon").hide(); $(".cart-icon").hide();
shopping_cart.bind_events(); shopping_cart.bind_events();
}); });

View File

@ -37,25 +37,4 @@
</div> </div>
</div> </div>
</div> </div>
{% endmacro %} {% endmacro %}
<script>
frappe.ready(function() {
$(".cart-items-dropdown").on('click', '.number-spinner button', function () {
var btn = $(this),
oldValue = btn.closest('.number-spinner').find('input').val().trim(),
newVal = 0;
if (btn.attr('data-dir') == 'up') {
newVal = parseInt(oldValue) + 1;
} else {
if (oldValue > 1) {
newVal = parseInt(oldValue) - 1;
} else {
newVal = 1;
}
}
btn.closest('.number-spinner').find('input').val(newVal);
});
}
</script>