var checkoutCommands = new Array(2); checkoutCommands[0] = '/checkout/direct_order_pickup.cmd'; checkoutCommands[1] = '/checkout/ispu_order_pickup.cmd'; function populatePickUpTime (pickUpYear,pickUpMonth,pickUpDay){ var params = 'pickUpDay=' + pickUpDay; params = params + '&pickUpMonth=' + pickUpMonth; params = params + '&pickUpYear=' + pickUpYear; $.ajax({ type: "POST", url: checkoutCommands[0], data: params, dataType: "html", success: function(data) { $("#directpickUpTime").append(data); $("#directpickUpTime").show(); return true; }, error: function() { return false; } }); } function populateIspuPickUpTime (pickUpYear,pickUpMonth,pickUpDay){ var params = 'pickUpDay=' + pickUpDay; params = params + '&pickUpMonth=' + pickUpMonth; params = params + '&pickUpYear=' + pickUpYear; $.ajax({ type: "POST", url: checkoutCommands[1], data: params, dataType: "html", success: function(data) { $("#ispuPickUpTime").append(data); $("#ispuPickUpTime").show(); return true; }, error: function() { return false; } }); } var orderDetails = { viewOrder:function(orderNumber) { if (orderNumber === undefined || isNaN(orderNumber)) { return; } jQuery(document).ready(function() { // process hidden form var frmId = "viewOrderForm"; var frm = jQuery("#" + frmId); if (frm.length == 0) { frm = jQuery("
"); frm.attr("id", frmId); frm.attr("method", "post"); frm.appendTo(jQuery("body")); } // process hidden form filed var fldId = "viewOrderFiled"; var fld = jQuery("#" + fldId); if (fld.length == 0) { // build hidden order number field fld = jQuery(""); fld.attr("id", fldId); fld.attr("name", "orderNumber"); fld.appendTo(frm); } // set values and submit form fld.val(orderNumber); frm.attr("action", "/user/order_details.cmd"); frm.submit(); }); }, editToGo:function(orderNumber) { var inEditMode = (SHOPPING_CART_STATUS.inEditMode === undefined) ? false : SHOPPING_CART_STATUS.inEditMode; var cartItemsCount = (SHOPPING_CART_STATUS.cartItemsCount === undefined) ? 0 : SHOPPING_CART_STATUS.cartItemsCount; var editingOrderNumber = (SHOPPING_CART_STATUS.editingOrder.number === undefined) ? 0 : SHOPPING_CART_STATUS.editingOrder.number; // check whether same order is editing if (inEditMode && editingOrderNumber == orderNumber) { orderDetails.process.shoppingCartEmpty(orderNumber); return; } if (cartItemsCount > 0) { orderDetails.showShoppingLists(orderNumber); } else { orderDetails.process.shoppingCartEmpty(orderNumber); } }, buildSubmitterForm:function(orderNumber, shoppingList) { // check whether hidden form exists or not // if not create new one and then submit it var editOrderFormId = "edit-order-form"; var editOrderForm = jQuery("#" + editOrderFormId); if (editOrderForm.length == 0) { editOrderForm = jQuery(""); editOrderForm.attr("id", editOrderFormId); editOrderForm.attr("method", "POST"); editOrderForm.attr("action", "/user/order/edit.cmd"); editOrderForm.appendTo(jQuery("body")); } var editOrderField1Id = "edit-order-field-1"; var editOrderField1 = jQuery("#" + editOrderField1Id); if (editOrderField1.length == 0) { editOrderField1 = jQuery(""); editOrderField1.attr("id", editOrderField1Id); editOrderField1.attr("name", "orderNumber"); editOrderField1.appendTo(editOrderForm); } var editOrderField2Id = "edit-order-field-2"; var editOrderField2 = jQuery("#" + editOrderField2Id); if (editOrderField2.length == 0) { editOrderField2 = jQuery(""); editOrderField2.attr("id", editOrderField2Id); editOrderField2.attr("name", "shoppingList"); editOrderField2.appendTo(editOrderForm); } editOrderField1.val(orderNumber); editOrderField2.val(shoppingList); return editOrderForm; }, showShoppingLists:function(orderNumber) { jQuery(document).ready(function() { jQuery.ajax({ url:"/user/ajax/edit_order_shopping_lists.jsp", type:"GET", cache:false, data:"orderNumber=" + encodeURIComponent(orderNumber), dataType:"html", success:function(response) { jQuery.blockUI({ message: response, css:{ width: "480px", height: "200px", top:"23%", left:"32%", cursor: "default" }, centerX: false, centerY: false }); } }); }); }, process:{ shoppingCartEmpty:function(orderNumber) { jQuery(document).ready(function() { var editOrderForm = orderDetails.buildSubmitterForm(orderNumber, -1); editOrderForm.submit(); }); }, shoppingCartNotEmpty:function(orderNumber, shoppingList) { // validate order number if (orderNumber === undefined) { jQuery.unblockUI(); return; } if (orderNumber <= 0) { jQuery.unblockUI(); return; } // validate shopping cart if (shoppingList === undefined) { jQuery.unblockUI(); return; } if (shoppingList <= 0) { jQuery.unblockUI(); return; } var editOrderForm = orderDetails.buildSubmitterForm(orderNumber, shoppingList); editOrderForm.submit(); } } }; var editOrder = { decision:{ windowClosing:function() { var windowClosing = (window["WINDOW_CLOSING"] !== undefined) ? window["WINDOW_CLOSING"] : false; var editingStatus = (window["EDITING_STATUS"] !== undefined) ? window["EDITING_STATUS"] : false; var editingOrderNumber = (window["EDITING_ORDER_NUMBER"] !== undefined) ? window["EDITING_ORDER_NUMBER"] : -1; return windowClosing && editingStatus && editingOrderNumber > 0 }, windowNotClosing:function() { //alert("windowNotClosing"); window["WINDOW_CLOSING"] = false; }, intercept:function(interceptable) { if (interceptable === undefined) { return; } interceptable.each(function() { if (!this.onclick) { return; } var original = this.onclick; try { this.onclick = function() { editOrder.decision.windowNotClosing(); return original.apply(this, arguments); }; } catch(e) { // do nothing } }); } }, mark:function() { var inEditMode = false; var cartItemsCount = 0; var editingOrderNumber = 0; try{ var o = (SHOPPING_CART_STATUS === undefined) ? null: SHOPPING_CART_STATUS; inEditMode = (o == null || o.inEditMode === undefined) ? false : SHOPPING_CART_STATUS.inEditMode; cartItemsCount = (o == null || o.cartItemsCount === undefined) ? 0 : SHOPPING_CART_STATUS.cartItemsCount; editingOrderNumber = (o == null || o.editingOrder.number === undefined) ? 0 : SHOPPING_CART_STATUS.editingOrder.number; }catch(e){ // do nothing } // set values to global variables window["WINDOW_CLOSING"] = true; window["EDITING_STATUS"] = inEditMode; window["EDITING_ORDER_NUMBER"] = editingOrderNumber; // now set mark any clickable elements such as link, buttons // in order to understand whether user leaving page due to // browser closing or not if (inEditMode && editingOrderNumber > 0) { var clickables = jQuery("a, [onclick], input[type='button'], input[type='submit'], input[type='image']"); editOrder.decision.intercept(clickables); clickables.livequery("click", editOrder.decision.windowNotClosing); // bind event to logout link which will show an alert on user click event jQuery("a[href$='/user/logout.cmd']").livequery("click", function(e) { editOrder.cancel.onLogout(e); }); } }, cancel:{ buildCancelForm:function() { var fid = "cancel-order-form"; var frm = jQuery("#" + fid); if (frm.length == 0) { frm = jQuery(""); frm.attr("id", fid); frm.attr("method", "post"); frm.appendTo(jQuery("body")); } frm.attr("action", "/user/order/edit/cancel.cmd"); return frm; }, process:function(returnToOrder) { if (returnToOrder) { var f = editOrder.cancel.buildCancelForm(); f.submit(); } else { jQuery.ajax({ url:"/ajax/user/order/edit/cancel.cmd", type:"POST", cache:false, dataType:"json", success:function() { // this is a silent command // but if you want you can check response // and its status below if (json === undefined) { return; } if (json.status === undefined) { return; } var status = json.status; if ("CANCELLED" == status) { // here you can show any message } } }); } }, onCancel:function() { if (confirm(editOrder.message.onCancel())) { editOrder.cancel.process(true); } }, onLogout:function(event) { if (!confirm(editOrder.message.onLogout())) { event.preventDefault(); } else { editOrder.cancel.process(false); } }, onWindowClose:function() { alert("onWindowClose"); if (confirm(editOrder.message.onWindowClose())) { editOrder.cancel.process(false); } } }, message:{ onLogout:function () { return "If you logout your editing process will be canceled. Are you sure you want to log out?"; }, onCancel:function () { return "Your editing process will be canceled. Are you sure you want to cancel?"; }, onWindowClose:function () { return "Your editing process will be canceled. Are you sure you want to close window?"; } } }; // we need to put some marks in order to understand that user is closing window or not jQuery(window).bind("load", function() { editOrder.mark(); }); /* jQuery(window).bind("unload", function() { if (editOrder.decision.windowClosing()) { editOrder.cancel.process(false); } }); */ /* // show warning message when user closing window window.onbeforeunload = function (e) { if (editOrder.decision.windowClosing()) { var x = e || window.event; // For IE and Firefox if (x) { x.returnValue = editOrder.message.onWindowClose(); } // For Safari return editOrder.message.onWindowClose(); } }; */ var basketItemQty = { checkInterval:500, typed:function(orderIndex, itemIndex) { // key press time var keyPressedTime = new Date().getTime(); // save key up event time and reset updated flag basketItemQty.param.value.time(orderIndex, itemIndex, keyPressedTime); basketItemQty.param.value.updated(orderIndex, itemIndex, false); // trigger check event basketItemQty.checkChanges(orderIndex, itemIndex); }, checkChanges:function(orderIndex, itemIndex) { // get key pressed time var keyPressedTime = basketItemQty.param.value.time(orderIndex, itemIndex); var nowTime = new Date().getTime(); if (nowTime - keyPressedTime < basketItemQty.checkInterval * 2) { basketItemQty.deferCheck(orderIndex, itemIndex); return; } // update only once if (!basketItemQty.param.value.updated(orderIndex, itemIndex)) { //aduvvuri 01/28/2011 modified the function call as the orderIndex and itemIndex values are UUIDs //updateUserItemQuantity(orderIndex, itemIndex); updateUserItemIDQuantity(orderIndex, itemIndex); basketItemQty.param.value.updated(orderIndex, itemIndex, true); } }, param:{ name:{ time:function(orderIndex, itemIndex) { return "QTY_TYPED_TIME_" + orderIndex + "_" + itemIndex; }, updated:function(orderIndex, itemIndex) { return "QTY_TYPED_UPDATE_" + orderIndex + "_" + itemIndex; } }, value:{ time:function(orderIndex, itemIndex, value) { if (arguments.length == 2) { var key = basketItemQty.param.name.time(orderIndex, itemIndex); return window[key] !== undefined ? window[key] : 0; } else if (arguments.length == 3) { window[basketItemQty.param.name.time(orderIndex, itemIndex)] = value; } }, updated:function(orderIndex, itemIndex, value) { if (arguments.length == 2) { var key = basketItemQty.param.name.updated(orderIndex, itemIndex); return window[key] !== undefined ? window[key] : false; } else if (arguments.length == 3) { window[basketItemQty.param.name.updated(orderIndex, itemIndex)] = value; } } } }, deferCheck:function(orderIndex, itemIndex) { var f = function() { basketItemQty.checkChanges(orderIndex, itemIndex); }; window.setTimeout(f, basketItemQty.checkInterval); window.clearTimeout(f); } };