1(function () { 2 'use strict'; 3 4 // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors 5 // License: GNU General Public License v3. See license.txt 6 7 if(!window.erpnext) { window.erpnext = {}; } 8 9 // Add / update a new Lead / Communication 10 // subject, sender, description 11 frappe.send_message = function(opts, btn) { 12 return frappe.call({ 13 type: "POST", 14 method: "erpnext.templates.utils.send_message", 15 btn: btn, 16 args: opts, 17 callback: opts.callback 18 }); 19 }; 20 21 erpnext.subscribe_to_newsletter = function(opts, btn) { 22 return frappe.call({ 23 type: "POST", 24 method: "frappe.email.doctype.newsletter.newsletter.subscribe", 25 btn: btn, 26 args: {"email": opts.email}, 27 callback: opts.callback 28 }); 29 }; 30 31 // for backward compatibility 32 erpnext.send_message = frappe.send_message; 33 34 // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors 35 // License: GNU General Public License v3. See license.txt 36 37 // shopping cart 38 frappe.provide("erpnext.e_commerce.shopping_cart"); 39 var shopping_cart = erpnext.e_commerce.shopping_cart; 40 41 var getParams = function (url) { 42 var params = []; 43 var parser = document.createElement('a'); 44 parser.href = url; 45 var query = parser.search.substring(1); 46 var vars = query.split('&'); 47 for (var i = 0; i < vars.length; i++) { 48 var pair = vars[i].split('='); 49 params[pair[0]] = decodeURIComponent(pair[1]); 50 } 51 return params; 52 }; 53 54 frappe.ready(function() { 55 var full_name = frappe.session && frappe.session.user_fullname; 56 // update user 57 if(full_name) { 58 $('.navbar li[data-label="User"] a') 59 .html('<i class="fa fa-fixed-width fa fa-user"></i> ' + full_name); 60 } 61 // set coupon code and sales partner code 62 63 var url_args = getParams(window.location.href); 64 65 var referral_coupon_code = url_args['cc']; 66 var referral_sales_partner = url_args['sp']; 67 68 var d = new Date(); 69 // expires within 30 minutes 70 d.setTime(d.getTime() + (0.02 * 24 * 60 * 60 * 1000)); 71 var expires = "expires="+d.toUTCString(); 72 if (referral_coupon_code) { 73 document.cookie = "referral_coupon_code=" + referral_coupon_code + ";" + expires + ";path=/"; 74 } 75 if (referral_sales_partner) { 76 document.cookie = "referral_sales_partner=" + referral_sales_partner + ";" + expires + ";path=/"; 77 } 78 referral_coupon_code=frappe.get_cookie("referral_coupon_code"); 79 referral_sales_partner=frappe.get_cookie("referral_sales_partner"); 80 81 if (referral_coupon_code && $(".tot_quotation_discount").val()==undefined ) { 82 $(".txtcoupon").val(referral_coupon_code); 83 } 84 if (referral_sales_partner) { 85 $(".txtreferral_sales_partner").val(referral_sales_partner); 86 } 87 88 // update login 89 shopping_cart.show_shoppingcart_dropdown(); 90 shopping_cart.set_cart_count(); 91 shopping_cart.show_cart_navbar(); 92 }); 93 94 $.extend(shopping_cart, { 95 show_shoppingcart_dropdown: function() { 96 $(".shopping-cart").on('shown.bs.dropdown', function() { 97 if (!$('.shopping-cart-menu .cart-container').length) { 98 return frappe.call({ 99 method: 'erpnext.e_commerce.shopping_cart.cart.get_shopping_cart_menu', 100 callback: function(r) { 101 if (r.message) { 102 $('.shopping-cart-menu').html(r.message); 103 } 104 } 105 }); 106 } 107 }); 108 }, 109 110 update_cart: function(opts) { 111 if (frappe.session.user==="Guest") { 112 if (localStorage) { 113 localStorage.setItem("last_visited", window.location.pathname); 114 } 115 frappe.call('erpnext.e_commerce.api.get_guest_redirect_on_action').then(function (res) { 116 window.location.href = res.message || "/login"; 117 }); 118 } else { 119 shopping_cart.freeze(); 120 return frappe.call({ 121 type: "POST", 122 method: "erpnext.e_commerce.shopping_cart.cart.update_cart", 123 args: { 124 item_code: opts.item_code, 125 qty: opts.qty, 126 additional_notes: opts.additional_notes !== undefined ? opts.additional_notes : undefined, 127 with_items: opts.with_items || 0 128 }, 129 btn: opts.btn, 130 callback: function(r) { 131 shopping_cart.unfreeze(); 132 shopping_cart.set_cart_count(true); 133 if(opts.callback) 134 { opts.callback(r); } 135 } 136 }); 137 } 138 }, 139 140 set_cart_count: function(animate) { 141 if ( animate === void 0 ) animate=false; 142 143 $(".intermediate-empty-cart").remove(); 144
145 var cart_count = frappe.get_cookie("cart_count"); 146 if(frappe.session.user==="Guest") { 147 cart_count = 0; 148 } 149 150 if(cart_count) { 151 $(".shopping-cart").toggleClass('hidden', false); 152 } 153 154 var $cart = $('.cart-icon'); 155 var $badge = $cart.find("#cart-count"); 156 157 if(parseInt(cart_count) === 0 || cart_count === undefined) { 158 $cart.css("display", "none"); 159 $(".cart-tax-items").hide(); 160 $(".btn-place-order").hide(); 161 $(".cart-payment-addresses").hide(); 162 163 var intermediate_empty_cart_msg = "\n\t\t\t\t<div class=\"text-center w-100 intermediate-empty-cart mt-4 mb-4 text-muted\">\n\t\t\t\t\t" + (__("Cart is Empty")) + "\n\t\t\t\t</div>\n\t\t\t"; 164 $(".cart-table").after(intermediate_empty_cart_msg); 165 } 166 else { 167 $cart.css("display", "inline"); 168 $("#cart-count").text(cart_count); 169 } 170 171 if(cart_count) { 172 $badge.html(cart_count); 173 174 if (animate) { 175 $cart.addClass("cart-animate"); 176 setTimeout(function () { 177 $cart.removeClass("cart-animate"); 178 }, 500); 179 } 180 } else { 181 $badge.remove(); 182 } 183 }, 184 185 shopping_cart_update: function(ref) { 186 var item_code = ref.item_code; 187 var qty = ref.qty; 188 var cart_dropdown = ref.cart_dropdown; 189 var additional_notes = ref.additional_notes; 190 191 shopping_cart.update_cart({ 192 item_code: item_code, 193 qty: qty, 194 additional_notes: additional_notes, 195 with_items: 1, 196 btn: this, 197 callback: function(r) { 198 if(!r.exc) { 199 $(".cart-items").html(r.message.items); 200 $(".cart-tax-items").html(r.message.total); 201 $(".payment-summary").html(r.message.taxes_and_totals); 202 shopping_cart.set_cart_count(); 203 204 if (cart_dropdown != true) { 205 $(".cart-icon").hide(); 206 } 207 } 208 }, 209 }); 210 }, 211 212 show_cart_navbar: function () { 213 frappe.call({ 214 method: "erpnext.e_commerce.doctype.e_commerce_settings.e_commerce_settings.is_cart_enabled", 215 callback: function(r) { 216 $(".shopping-cart").toggleClass('hidden', r.message ? false : true); 217 } 218 }); 219 }, 220 221 toggle_button_class: function toggle_button_class(button, remove, add) { 222 button.removeClass(remove); 223 button.addClass(add); 224 }, 225 226 bind_add_to_cart_action: function bind_add_to_cart_action() { 227 $('.page_content').on('click', '.btn-add-to-cart-list', function (e) { 228 var $btn = $(e.currentTarget); 229 $btn.prop('disabled', true); 230 231 if (frappe.session.user==="Guest") { 232 if (localStorage) { 233 localStorage.setItem("last_visited", window.location.pathname); 234 } 235 frappe.call('erpnext.e_commerce.api.get_guest_redirect_on_action').then(function (res) { 236 window.location.href = res.message || "/login"; 237 }); 238 return; 239 } 240 241 $btn.addClass('hidden'); 242 $btn.closest('.cart-action-container').addClass('d-flex'); 243 $btn.parent().find('.go-to-cart').removeClass('hidden'); 244 $btn.parent().find('.go-to-cart-grid').removeClass('hidden'); 245 $btn.parent().find('.cart-indicator').removeClass('hidden'); 246 247 var item_code = $btn.data('item-code'); 248 erpnext.e_commerce.shopping_cart.update_cart({ 249 item_code: item_code, 250 qty: 1 251 }); 252 253 }); 254 }, 255 256 freeze: function freeze() { 257 if (window.location.pathname !== "/cart") { return; } 258 259 if (!$('#freeze').length) { 260 var freeze = $('<div id="freeze" class="modal-backdrop fade"></div>') 261 .appendTo("body"); 262 263 setTimeout(function() { 264 freeze.addClass("show"); 265 }, 1); 266 } else { 267 $("#freeze").addClass("show"); 268 } 269 }, 270 271 unfreeze: function unfreeze() { 272 if ($('#freeze').length) { 273 var freeze = $('#freeze').removeClass("show"); 274 setTimeout(function() { 275 freeze.remove(); 276 }, 1); 277 } 278 } 279 }); 280 281 frappe.provide("erpnext.e_commerce.wishlist"); 282 var wishlist = erpnext.e_commerce.wishlist; 283 284 frappe.provide("erpnext.e_commerce.shopping_cart"); 285 var shopping_cart$1 = erpnext.e_commerce.shopping_cart; 286 287 $.extend(wishlist, { 288 set_wishlist_count: function(animate) { 289 if ( animate === void 0 ) animate=false; 290 291 // set badge count for wishlist icon 292 var wish_count = frappe.get_cookie("wish_count"); 293 if (frappe.session.user==="Guest") { 294 wish_count = 0; 295 } 296 297 if (wish_count) { 298 $(".wishlist").toggleClass('hidden', false); 299 } 300 301 var $wishlist = $('.wishlist-icon'); 302 var $badge = $wishlist.find("#wish-count"); 303 304 if (parseInt(wish_count) === 0 || wish_count === undefined) { 305 $wishlist.css("display", "none"); 306 } else { 307 $wishlist.css("display", "inline"); 308 } 309 if (wish_count) { 310 $badge.html(wish_count); 311 if (animate) { 312 $wishlist.addClass('cart-animate'); 313 setTimeout(function () { 314 $wishlist.removeClass('cart-animate'); 315 }, 500); 316 } 317 } else { 318 $badge.remove(); 319 } 320 }, 321 322 bind_move_to_cart_action: function() { 323 var this$1 = this; 324 325 // move item to cart from wishlist 326 $('.page_content').on("click", ".btn-add-to-cart", function (e) { 327 var $move_to_cart_btn = $(e.currentTarget); 328 var item_code = $move_to_cart_btn.data("item-code"); 329 330 shopping_cart$1.shopping_cart_update({ 331 item_code: item_code, 332 qty: 1, 333 cart_dropdown: true 334 }); 335 336 var success_action = function() { 337 var $card_wrapper = $move_to_cart_btn.closest(".wishlist-card"); 338 $card_wrapper.addClass("wish-removed"); 339 }; 340 var args = { item_code: item_code }; 341 this$1.add_remove_from_wishlist("remove", args, success_action, null, true); 342 }); 343 }, 344 345 bind_remove_action: function() { 346 var this$1 = this; 347 348 // remove item from wishlist 349 var me = this; 350 351 $('.page_content').on("click", ".remove-wish", function (e) { 352 var $remove_wish_btn = $(e.currentTarget); 353 var item_code = $remove_wish_btn.data("item-code"); 354 355 var success_action = function() { 356 var $card_wrapper = $remove_wish_btn.closest(".wishlist-card"); 357 $card_wrapper.addClass("wish-removed"); 358 if (frappe.get_cookie("wish_count") == 0) { 359 $(".page_content").empty(); 360 me.render_empty_state(); 361 } 362 }; 363 var args = { item_code: item_code }; 364 this$1.add_remove_from_wishlist("remove", args, success_action); 365 }); 366 }, 367 368 bind_wishlist_action: function bind_wishlist_action() { 369 var this$1 = this; 370 371 // 'wish'('like') or 'unwish' item in product listing 372 $('.page_content').on('click', '.like-action, .like-action-list', function (e) { 373 var $btn = $(e.currentTarget); 374 this$1.wishlist_action($btn); 375 }); 376 }, 377
378 wishlist_action: function wishlist_action(btn) { 379 var $wish_icon = btn.find('.wish-icon'); 380 var me = this; 381 382 if (frappe.session.user==="Guest") { 383 if (localStorage) { 384 localStorage.setItem("last_visited", window.location.pathname); 385 } 386 this.redirect_guest(); 387 return; 388 } 389 390 var success_action = function() { 391 erpnext.e_commerce.wishlist.set_wishlist_count(true); 392 }; 393 394 if ($wish_icon.hasClass('wished')) { 395 // un-wish item 396 btn.removeClass("like-animate"); 397 btn.addClass("like-action-wished"); 398 this.toggle_button_class($wish_icon, 'wished', 'not-wished'); 399 400 var args = { item_code: btn.data('item-code') }; 401 var failure_action = function() { 402 me.toggle_button_class($wish_icon, 'not-wished', 'wished'); 403 }; 404 this.add_remove_from_wishlist("remove", args, success_action, failure_action); 405 } else { 406 // wish item 407 btn.addClass("like-animate"); 408 btn.addClass("like-action-wished"); 409 this.toggle_button_class($wish_icon, 'not-wished', 'wished'); 410 411 var args$1 = {item_code: btn.data('item-code')}; 412 var failure_action$1 = function() { 413 me.toggle_button_class($wish_icon, 'wished', 'not-wished'); 414 }; 415 this.add_remove_from_wishlist("add", args$1, success_action, failure_action$1); 416 } 417 }, 418 419 toggle_button_class: function toggle_button_class(button, remove, add) { 420 button.removeClass(remove); 421 button.addClass(add); 422 }, 423 424 add_remove_from_wishlist: function add_remove_from_wishlist(action, args, success_action, failure_action, async) { 425 if ( async === void 0 ) async=false; 426 427 /* AJAX call to add or remove Item from Wishlist 428 action: "add" or "remove" 429 args: args for method (item_code, price, formatted_price), 430 success_action: method to execute on successs, 431 failure_action: method to execute on failure, 432 async: make call asynchronously (true/false). */ 433 if (frappe.session.user==="Guest") { 434 if (localStorage) { 435 localStorage.setItem("last_visited", window.location.pathname); 436 } 437 this.redirect_guest(); 438 } else { 439 var method = "erpnext.e_commerce.doctype.wishlist.wishlist.add_to_wishlist"; 440 if (action === "remove") { 441 method = "erpnext.e_commerce.doctype.wishlist.wishlist.remove_from_wishlist"; 442 } 443 444 frappe.call({ 445 async: async, 446 type: "POST", 447 method: method, 448 args: args, 449 callback: function (r) { 450 if (r.exc) { 451 if (failure_action && (typeof failure_action === 'function')) { 452 failure_action(); 453 } 454 frappe.msgprint({ 455 message: __("Sorry, something went wrong. Please refresh."), 456 indicator: "red", title: __("Note") 457 }); 458 } else if (success_action && (typeof success_action === 'function')) { 459 success_action(); 460 } 461 } 462 }); 463 } 464 }, 465 466 redirect_guest: function redirect_guest() { 467 frappe.call('erpnext.e_commerce.api.get_guest_redirect_on_action').then(function (res) { 468 window.location.href = res.message || "/login"; 469 }); 470 }, 471 472 render_empty_state: function render_empty_state() { 473 $(".page_content").append(("\n\t\t\t<div class=\"cart-empty frappe-card\">\n\t\t\t\t<div class=\"cart-empty-state\">\n\t\t\t\t\t<img src=\"/assets/erpnext/images/ui-states/cart-empty-state.png\" alt=\"Empty Cart\">\n\t\t\t\t</div>\n\t\t\t\t<div class=\"cart-empty-message mt-4\">" + (__('Wishlist is empty !')) + "</p>\n\t\t\t</div>\n\t\t")); 474 } 475 476 }); 477 478 frappe.ready(function() { 479 if (window.location.pathname !== "/wishlist") { 480 $(".wishlist").toggleClass('hidden', true); 481 wishlist.set_wishlist_count(); 482 } else { 483 wishlist.bind_move_to_cart_action(); 484 wishlist.bind_remove_action(); 485 } 486 487 }); 488 489}()); 490//# sourceMappingURL=erpnext-web.min.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.