var favoriteListCommand = '/user/add_item_to_wishlist.cmd';
var persistentListCommands = new Array(8);
persistentListCommands[0] = '/user/universal_shopping_list.jsp';
persistentListCommands[1] = '/checkout/add_item_uc.cmd';
persistentListCommands[2] = '/checkout/add_items_uc.cmd';
persistentListCommands[3] = '/checkout/delete_item_in_list.cmd';
persistentListCommands[4] = '/user/move_item_to_shoppinglist.cmd';
persistentListCommands[5] = '/checkout/basket.jsp';
persistentListCommands[6] = '/user/load_shoppinglist.cmd';
persistentListCommands[7] = '/user/create_shoppinglist.cmd';
var persistentListContainerId = "#widget-ulist";
var persistentListCloseButClass = ".widget-close-but";
var hideTimeOuts= new Array();
var ulistLoadingHTML = '
';
var ulistSimpleHTML = '';
/* Function(s) to Show the List Layer */
function showList(action,params,refreshPage,refreshDelayTime, pId) {
var buttonStateChange = false;
if( (action == "show") || (action == "showFromQuickview") )
{ showListLoading(ulistLoadingHTML); requestURL = persistentListCommands[0]; }
else if(action == "addProduct")
{ showListLoading(ulistLoadingHTML, false); requestURL = persistentListCommands[1]; buttonStateChange = true;}
else if(action == "addEnsemble")
{ showListLoading(ulistSimpleHTML, false); requestURL = persistentListCommands[2]; buttonStateChange = true;}
else if(action == "remove")
{ showListLoading(ulistLoadingHTML); requestURL = persistentListCommands[3];}
else if(action == "addVariety")
{ showListLoading(ulistSimpleHTML, false); requestURL = persistentListCommands[1]; buttonStateChange = true;}
else if(action == "moveToList")
{ showListLoading(ulistSimpleHTML); requestURL = persistentListCommands[4];}
else
{ alert("missing action"); }
requestURL = requestURL;
params = "ts=" + timestamp() + "&action=" + action + "&" + params;
$.ajax({
type: "POST",
url: requestURL,
data: params,
dataType: "html",
timeout: 15000,
success: function(data) {
hideListLoading();
$(persistentListContainerId).append(data);
//$(persistentListContainerId).show();
//bganesan 11/13/09 - BUG00068 Fix to display a confirmation msg on basket page reload, once Move to List is done.
var href = location.href;
if(data.indexOf("") != -1){
var productId = data.substring(data.indexOf("")+6,data.indexOf(""));
href = persistentListCommands[5] + "?moveProductId=" + productId;
}
if (refreshPage != undefined && refreshPage) {
setTimeout( function() { window.location = href; }, refreshDelayTime != undefined? refreshDelayTime : 0);
}
if(buttonStateChange == true) {
if(typeof(addToListOrCart) != "undefined") {
addToListOrCart.layer.event.success(pId);
}else {
disable(pId);
// set 3 seconds timer
window.setTimeout(function() {enable(pId)}, 3000);
// Reload shopping list page after selecting list
if ($('body#shoppingList').length ){
window.location.reload();
if ( typeof refreshShoppingHeader == 'function' ) {
refreshShoppingHeader();
}
}
}
}
return true;
},
error: function() {
hideListLoading();
return false;
}
});
};
function showListLoading(htmlToShow, tobeShown) {
$(persistentListContainerId).remove();
//load, position, show new cart
// $("#siteOuterWrapper").append(htmlToShow);
$("#ulistWrapper").append(htmlToShow);
// let the position be handled by the css since we have more than one site to deal with.
// positionUniversalList();
if(tobeShown == "true" || tobeShown == null)
{
$(persistentListContainerId).show();
}
// add an event for close layer.
//$(persistentListCloseButClass).click(function() { hideList(); });
};
function hideListLoading() {
$(persistentListContainerId + " *").remove();
$(persistentListContainerId).html("");
};
//edit this function to position cart.
// let the position be handled by the css since we have more than one site to deal with.
//function positionUniversalList() {
// newLeft = 10 + ($("body").width() / 2) + ( $("#siteOuterWrapper").width() / 2 ) - $(persistentListContainerId).width();
//
// $(persistentListContainerId).css("left", newLeft+"px");
// $(persistentListContainerId).css("top", "120px");
//};
//edit this function to update the setup
function setupPersistentListButtons() {
// draw focus near this
// window.location = "#";
$(persistentListCloseButClass).not('select').off("click").on("click", function() {
hideList();
// Reload shopping list page after selecting list
if ($('body#shoppingList').length ){
window.location.reload();
if ( typeof refreshShoppingHeader == 'function' ) {
refreshShoppingHeader();
}
}
});
$(persistentListCloseButClass).attr("href","javascript:void(0)");
var layerCounter = 0;
var focusTimer;
var selectOpened = false;
// Reload shopping list in layer after new selection
$('select#shoppingLists').on( 'click', function(e) {
selectOpened = !selectOpened; // IE
if( typeof focusTimer != undefined ) { clearTimeout(focusTimer); focusTimer=null; }
layerCounter++;
focusTimer = setTimeout(function(){
selectOpened = !selectOpened;
if(layerCounter > 1){
showList('show','');
} else {
e.stopPropagation();
}
},800); // 800 for IE, 500 FF and Chrome
});
var leaveTimer;
$('#widget-ulist').not('select#shoppingLists').on('mouseleave', function(e) {
if (!selectOpened) {
if( typeof leaveTimer != undefined ) { clearTimeout(leaveTimer); leaveTimer=null; }
leaveTimer = setTimeout(function(){
clearTimeout(ulistTimer);
ulistTimer=null;
hideList();
},2500);
}
});
// close list for iPad upon clicking 'view all'
$(".closelist").on("touchstart click", function(e) {
$linkurl = $(this).attr('href');
hideList(); // keeps list closed when back link is used on ipad
window.location = $linkurl; // continue to link destination on ipad
});
//clearAllTimeouts();
};
//Edit this function if need to do something special on basket close.
function hideList() {
//show select for IE7
$('#shoppingLists').css('visibility','visible');
$(persistentListContainerId).hide();
$(persistentListContainerId).remove();
shoppingBagBut = $("#widget-header-active-link").eq(0);
$(shoppingBagBut).attr("id","")
$(shoppingBagBut).mouseout();
// hide the "added to list" text when the layer closes
hideAddedText();
};
function updateListHeader(amt) {
if(amt == 1)
{ $("#widget-ulist-item-count").text(amt + " item(s)"); }
else
{ $("#widget-ulist-item-count").text(amt + " item(s)");}
};
var msgID;
function addToList(prefix, container, showUList) {
var scope = $(prefix);
if (container) {
scope = $(container).parents(prefix);
}
var productVariantId = $("input[name=productVariantId]", scope).val();
if (productVariantId == null || productVariantId == undefined) {
productVariantId = $("input[name=productVariantId2]", scope).val();
}
var itemNotesTextArea = jQuery("textarea[name='notes']", addToListOrCart.layer.find());
if(itemNotesTextArea.val() == undefined) {
var freeTextNotesId = jQuery("#add-to-list-or-cart-layer-notes");
itemNotesTextArea = jQuery("textarea[name='notes']", freeTextNotesId);
if(itemNotesTextArea.val() == undefined) {
itemNotesTextArea = jQuery("textarea[name='notes']", scope);
}
}
var vItemNotes = itemNotesTextArea.length == 1 ? itemNotesTextArea.val() : "";
var notesDefault = "enter notes (optional)";
if (jQuery.trim(vItemNotes) == notesDefault) {
vItemNotes = "";
}
var unitOfMeasureInputField = $("[name^='unitOfMeasure']", scope);
var vUom = unitOfMeasureInputField.length == 2 ? (unitOfMeasureInputField[0].checked ? unitOfMeasureInputField[0].value :
unitOfMeasureInputField[1].value ) : (unitOfMeasureInputField.length == 1 ? unitOfMeasureInputField.val() : "");
var swapId = $("input[name=swapId]", scope).val();
if (swapId == undefined) {
swapId = "";
}
params = "productName=" + $("input[name=productName]", scope).val() +
"&productId=" + $("input[name=productId]", scope).val() +
"&categoryId=" + $("input[name=categoryId]", scope).val() +
"&parentCategoryId=" + $("input[name=parentCategoryId]", scope).val() +
"&subCategoryId=" + $("input[name=subCategoryId]", scope).val() +
"&quantity=" + $("input[name^=quantity]", scope).val() +
"&productVariantId=" + productVariantId +
"&displayPrice=" + $("input[name=displayPrice]", scope).val() +
"&displayMsrp=" + $("input[name=displayMsrp]", scope).val() +
"&inventoryStatus=" + $("input[name=inventoryStatus]", scope).val() +
"&itemNotes=" + encodeURIComponent(vItemNotes) +
"&unitOfMeasure=" + encodeURIComponent(vUom) +
"&swapId=" + encodeURIComponent(swapId);
//bganesan - 07/30/09 Setting productType ,itemIndex and addvarietiesCoupos for all varieties layer
var productType = $("input[name=productType]", scope).val();
if(productType != null && productType != undefined ){
params = params + "&productType="+productType;
}
var specialInstructions = $("textarea[name=specialInstructions]", scope).val();
if(specialInstructions == null || specialInstructions == undefined ){
specialInstructions = $("input[name=specialInstructions]", scope).val();
}
if(specialInstructions != null && specialInstructions != undefined ){
params = params + "&specialInstructions="+specialInstructions.replace(/&/g, "_AND_");
}
//stran - 08/17/09, adding cake design param
var cakeDesign = $("select[name=cakeDesign]", scope).val();
if(cakeDesign == null || cakeDesign == undefined ){
cakeDesign = $("input[name=cakeDesign]", scope).val();
}
if(cakeDesign != null && cakeDesign != undefined ){
params = params + "&cakeDesign="+cakeDesign.replace(/&/g, "_AND_");
}
//stran - 10/23/09, adding occasion param
var cakeOccasion = $("select[name=cakeOccasion]", scope).val();
if(cakeOccasion == null || cakeOccasion == undefined ){
cakeOccasion = $("input[name=cakeOccasion]", scope).val();
}
if(cakeOccasion != null && cakeOccasion != undefined ){
params = params + "&cakeOccasion="+cakeOccasion.replace(/&/g, "_AND_");
}
//stran - 08/17/09, adding occasion specific param
cakeOccasionSpecific = $("input[name=cakeOccasionSpecific]", scope).val();
if(cakeOccasionSpecific != null && cakeOccasionSpecific != undefined ){
params = params + "&cakeOccasionSpecific="+cakeOccasionSpecific.replace(/&/g, "_AND_");
}
var cakeFlavor = $("select[name=cakeFlavor]", scope).val();
if(cakeFlavor == null || cakeFlavor == undefined ){
cakeFlavor = $("input[name=cakeFlavor]", scope).val();
}
if(cakeFlavor != null && cakeFlavor != undefined ){
params = params + "&cakeFlavor="+cakeFlavor.replace(/&/g, "_AND_");
}
var icingType = $("select[name=icingType]", scope).val();
if(icingType == null || icingType == undefined ){
icingType = $("input[name=icingType]", scope).val();
}
if(icingType != null && icingType != undefined ){
params = params + "&icingType="+icingType.replace(/&/g, "_AND_");
}
var icingFlavor = $("select[name=icingFlavor]", scope).val();
if(icingFlavor == null || icingFlavor == undefined ){
icingFlavor = $("input[name=icingFlavor]", scope).val();
}
if(icingFlavor != null && icingFlavor != undefined ){
params = params + "&icingFlavor="+icingFlavor.replace(/&/g, "_AND_");
}
var icingColor = $("select[name=icingColor]", scope).val();
if(icingColor == null || icingColor == undefined ){
icingColor = $("input[name=icingColor]", scope).val();
}
if(icingColor != null && icingColor != undefined ){
params = params + "&icingColor="+icingColor.replace(/&/g, "_AND_");
}
var icingColorBorder = $("select[name=icingColorBorder]", scope).val();
if(icingColorBorder == null || icingColorBorder == undefined ){
icingColorBorder = $("input[name=icingColorBorder]", scope).val();
}
if(icingColorBorder != null && icingColorBorder != undefined ){
params = params + "&icingColorBorder="+icingColorBorder.replace(/&/g, "_AND_");
}
var cakeInscription = $("textarea[name=cakeInscription]", scope).val();
if(cakeInscription == null || cakeInscription == undefined ){
cakeInscription = $("input[name=cakeInscription]", scope).val();
}
if(cakeInscription != null && cakeInscription != undefined ){
params = params + "&cakeInscription="+cakeInscription.replace(/&/g, "_AND_");
}
var itemIndex = $("input[name=itemIndex]", scope).val();
if(itemIndex != null && itemIndex != undefined ){
params = params + "&itemIndex="+itemIndex;
}
var addVarietiesCoupon = $("input[name=addVarietiesCoupon]", scope).val();
if(addVarietiesCoupon != null && addVarietiesCoupon != undefined ){
params = params + "&addVarietiesCoupon="+addVarietiesCoupon;
}
//see if this is an update.
if( $("input[name=itemGUID]", scope).size() > 0 )
{ params = params + "&itemGUID=" + $("input[name=itemGUID]", scope).val() + "&isUpdate=1"; }
if( $("input[name=onBasketPage]", scope).size() > 0 )
{ params = params + "&onBasketPage=" + $("input[name=onBasketPage]", scope).val(); }
if (prefix != undefined)
params = params + "&prefix=" + prefix;
var pId = $("input[name=productId]", scope).val();
//bganesan - 07/30/09 - create a new action so that universal list does not display
if(showUList == 'true'){
showList('addProduct',params, false, 0, pId);
}else{
showList('addVariety',params, false, 0, pId);
}
// msgID = "#" + pId + "_msg";
// $(".addedMsg").css('display','none');
// showAddedText();
};
function disable(pId) {
// hide "add" button
var buttonAdd = jQuery("#" + pId + "_btn");
buttonAdd.hide();
// show added button
var buttonAddedId = pId + "_btn_disabled";
var buttonAdded = jQuery("#" + buttonAddedId);
if (buttonAdded.length == 0) {
buttonAdded = jQuery("");
buttonAdded.attr("id", buttonAddedId);
buttonAdded.attr("class", "btn-Added");
buttonAdded.hide();
buttonAdded.insertBefore(buttonAdd);
}
buttonAdded.show();
}
function enable(pId) {
// remove added button
jQuery("#" + pId + "_btn_disabled").remove();
// show "add" button
jQuery("#" + pId + "_btn").show();
}
function showAddedText() {
$(msgID).css('display','block');
}
function hideAddedText() {
$(msgID).css('display','none');
}
// Updates the favorites list taking in the same parameters that the shopping list uses for consistency sake.
function addToFavoritesList(prefix, container, productPage) {
var scope = $(prefix);
if (container) {
scope = $(container).parents(prefix);
}
var productVariantId = $("input[name=productVariantId]", scope).val();
if (productVariantId == null || productVariantId == undefined) {
productVariantId = $("input[name=productVariantId2]", scope).val();
}
params = "productName=" + $("input[name=productName]", scope).val() +
"&productId=" + $("input[name=productId]", scope).val() +
"&categoryId=" + $("input[name=categoryId]", scope).val() +
"&parentCategoryId=" + $("input[name=parentCategoryId]", scope).val() +
"&subCategoryId=" + $("input[name=subCategoryId]", scope).val() +
"&subSubCategoryId=" + $("input[name=subSubCategoryId]", scope).val() +
"&quantity=" + $("input[name=quantity]", scope).val() +
"&productVariantId=" + productVariantId +
"&displayPrice=" + $("input[name=displayPrice]", scope).val() +
"&displayMsrp=" + $("input[name=displayMsrp]", scope).val() +
"&inventoryStatus=" + $("input[name=inventoryStatus]", scope).val() +
"&isProductPage=" + $("input[name=isProductPage]", scope).val();
var unitOfMeasure = $("input[name=unitOfMeasure]", scope).val();
if(unitOfMeasure == null || unitOfMeasure == undefined ){
unitOfMeasure = $("select[name=unitOfMeasure]", scope).val();
}
if(unitOfMeasure != null && unitOfMeasure != undefined ){
params = params + "&unitOfMeasure="+unitOfMeasure;
}
if( $("input[name=onBasketPage]", scope).size() > 0 )
{ params = params + "&onBasketPage=" + $("input[name=onBasketPage]", scope).val(); }
var productType = $("input[name=productType]", scope).val();
if(productType != null && productType != undefined ){
params = params + "&productType="+productType;
}
var specialInstructions = $("textarea[name=specialInstructions]", scope).val();
if(specialInstructions != null && specialInstructions != undefined ){
params = params + "&specialInstructions="+specialInstructions;
}
var cakeDesign = $("select[name=cakeDesign]", scope).val();
if(cakeDesign != null && cakeDesign != undefined ){
params = params + "&cakeDesign="+cakeDesign;
}
// stran, 10/23/2009, add cake occasion param
var cakeOccasion = $("select[name=cakeOccasion]", scope).val();
if(cakeOccasion != null && cakeOccasion != undefined ){
params = params + "&cakeOccasion="+cakeOccasion;
}
var cakeOccasionSpecific = $("input[name=cakeOccasionSpecific]", scope).val();
if(cakeOccasionSpecific != null && cakeOccasionSpecific != undefined ){
params = params + "&cakeOccasionSpecific="+cakeOccasionSpecific;
}
var cakeFlavor = $("select[name=cakeFlavor]", scope).val();
if(cakeFlavor != null && cakeFlavor != undefined ){
params = params + "&cakeFlavor="+cakeFlavor;
}
var icingType = $("select[name=icingType]", scope).val();
if(icingType != null && icingType != undefined ){
params = params + "&icingType="+icingType;
}
var icingFlavor = $("select[name=icingFlavor]", scope).val();
if(icingFlavor != null && icingFlavor != undefined ){
params = params + "&icingFlavor="+icingFlavor;
}
var icingColor = $("select[name=icingColor]", scope).val();
if(icingColor != null && icingColor != undefined ){
params = params + "&icingColor="+icingColor;
}
var icingColorBorder = $("select[name=icingColorBorder]", scope).val();
if(icingColorBorder != null && icingColorBorder != undefined ){
params = params + "&icingColorBorder="+icingColorBorder;
}
var cakeInscription = $("textarea[name=cakeInscription]", scope).val();
if(cakeInscription != null && cakeInscription != undefined ){
params = params + "&cakeInscription="+cakeInscription;
}
if (prefix != undefined)
params = params + "&prefix=" + prefix;
if(productPage == undefined){
//bganesan 01/14/10 - If the add to favorites call comes from search or thumbnails page,
//perform an ajax call and do no reload the page. Add a parameter so that the registration_layer_js.jsp knows that the
//favorites ajax call has to be done upon login. This is because other pieces of functionality like Send to Phone share the same method.
params = params + "&addToFavorites=true";
addToFavorites (params,'false');
}
else{
//bganesan 01/14/10 - For the product page though, do a regular command call.
window.location.href = favoriteListCommand + '?'+ params;
}
};
//bganesan 01/11/10 - Add to Favorites Ajax Call
//The params has all the add to favorites parameters and the reload indicates if the page should be reloaded or not.
function addToFavorites (params,reload){
$.ajax({
type: "POST",
url: favoriteListCommand,
data: params,
dataType: "html",
timeout: 15000,
success: function(data) {
$("#widget-addToList").html('');
$("#widget-addToList").append(data);
$("#widget-addToList").show();
if(reload == 'true'){
location.reload(true);
}
return true;
},
error: function() {
return false;
}
});
}
function shoppingListAddAllToList(params,refreshPage,refreshDelayTime) {
params = "addAction=" + $("input[name=addAction]").val();
showList('addAllProductsShoppinglist',params,refreshPage,refreshDelayTime);
};
function addEnsembleToList(type) {
params = "ensembleId=" + $("input[name=ensembleId]").val() +
"&categoryId=" + $("input[name=categoryId]").val() +
"&parentCategoryId=" + $("input[name=parentCategoryId]").val()+
"&checkForDuplicates=" + $("input[name=checkForDuplicates]").val()+
"&reminderItems=" + $("input[name=reminderItems]").val();
// iterate through products in the ensemble for product names
var variantNames = '';
var namesArray = new Array();
$(".the-variant-names").each(function() {
namesArray[namesArray.length] = $(this).val();
});
// iterate through products in the ensemble for variant id
var nameIndex = 0;
$(".the-variant-ids").each(function() {
params = params + "&" + $(this).attr("name") + "=" + $(this).val();
if($(this).val() == '0' || $(this).val() == undefined || $(this).val() == ''){
namesArray[nameIndex] = '';
}
nameIndex = nameIndex + 1;
});
//bganesan 11/09/09 - Adding Product ID for Free Text Reminder Items
$(".the-product-ids").each(function() {
params = params + "&" + $(this).attr("name") + "=" + $(this).val();
});
// iterate through products in the ensemble for product prices
$(".item-price").each(function() {
params = params + "&" + $(this).attr("name") + "=" + $(this).val();
});
$(".item-msrp").each(function() {
params = params + "&" + $(this).attr("name") + "=" + $(this).val();
});
$(".inventory-status").each(function() {
params = params + "&" + $(this).attr("name") + "=" + $(this).val();
});
nameIndex = 0;
// iterate through products for qty
$(".the-variant-qtys").each(function() {
if( type == 'all' )
{
$(this).val("1");
params = params + "&" + $(this).attr("name") + "=1";
//bganesan 11/17/09 - Set all the product names since the user is adding all items.
variantNames = variantNames + ", " + namesArray[nameIndex];
}
else
{ params = params + "&" + $(this).attr("name") + "=" + $(this).val();
//bganesan 11/17/09 - Add the product names for products that have a quantity greater than 0.
//sfarrugia 12/13/2009 - Check that this is a number between 1-99.
if($(this).val() != '0' && $(this).val() != undefined && $(this).val() != '' && !isNaN($(this).val()) && parseInt($(this).val()) > 0 && parseInt($(this).val()) < 100) {
if(variantNames == ''){
variantNames = variantNames + namesArray[nameIndex];
}
else
{
if(namesArray[nameIndex] != ''){
variantNames = variantNames + ", " + namesArray[nameIndex];
}
}
}
}
nameIndex = nameIndex + 1;
});
params = params + "&productName="+variantNames;
// iterate through products variant count
$(".the-variant-count").each(function() {
params = params + "&" + $(this).attr("name") + "=" + $(this).val();
});
//Add a gift card flag if originating from gift cards page
var giftCardFlag = $("input[name=giftCardFlag]").val();
if (giftCardFlag == null || giftCardFlag == undefined) {
giftCardFlag = 'false';
}
params = params + "&giftCardFlag=" + giftCardFlag;
//sfarrugia 12/11/2009 - Messaging for the events and recipes.
// Check if this is ingredients being added or items from events. This is for the messaging.
var itemTypeName = $("input[name=itemTypeName]").val();
if (itemTypeName == null || itemTypeName == undefined) {
itemTypeName = 'item';
}
params = params + "&itemTypeName=" + itemTypeName;
params = params + "&productCount=" + $(".the-variant-ids").length;
var pId = $("input[name=ensembleId]").val();
showList('addEnsemble',params,false,0, pId);
// msgID = "#added_msg";
// $(".addedMsg").css('display','none');
// showAddedText();
};
function loadShoppingListInHeader (params,reload){
$.ajax({
type: "POST",
url: persistentListCommands[6],
data: params,
dataType: "html",
timeout: 15000,
success: function(data) {
if(reload == 'true'){
//Update the item count of the loaded shopping list.
$(".itemCount").html(data);
// Reload shopping list page after selecting list
if ($('body#shoppingList').length ){
window.location.reload();
if ( typeof refreshShoppingHeader == 'function' ) {
refreshShoppingHeader();
}
}
}
return true;
},
error: function() {
return false;
}
});
};
function createShoppingListInHeader (params,reload){
$.ajax({
type: "POST",
url: persistentListCommands[7],
data: params,
dataType: "html",
timeout: 15000,
success: function(data) {
if(reload == 'true'){
//Update the item count of the newly created shopping list, and add an option to the shopping list dropdown.
$(".itemCount",window.opener.document).html(data);
}
return true;
},
error: function() {
return false;
}
});
};