//var to hold requestURL
var requestURL = "";
// Commands
// All commands need to be registered here.
var commands = new Map();
commands.put("showCloset", "/outfitter/jsp/closet.jsp");
commands.put("showOutfits", "/outfitter/jsp/outfits.jsp");
commands.put("updateOutfitLayer","/outfitter/jsp/save_update_layer.jsp");
commands.put("saveOutfit","/outfitter/save_outfit.cmd");
commands.put("publishOutfit","/outfitter/publish_outfit.cmd");
commands.put("updateOutfit","/outfitter/rename_outfit.cmd");
commands.put("loadOutfitStage","/outfitter/jsp/stage.jsp");
commands.put("loadOutfitTags","/outfitter/jsp/tags.jsp");
commands.put("loadOutfitInfo","/outfitter/jsp/your_outfit.jsp");
commands.put("manageOutfits","/outfitter/jsp/manage_outfits.jsp");
commands.put("manageItems","/outfitter/jsp/manage_items.jsp");
commands.put("removeItemFromCloset","/outfitter/delete_product_from_closet.cmd");
commands.put("removeOutfitFromCloset","/outfitter/delete_outfit.cmd");
commands.put("manageTable","/outfitter/jsp/manage_table_include.jsp");
commands.put("removeItemManage","/outfitter/delete_product_from_manage.cmd");
commands.put("removeOutfitManage","/outfitter/delete_outfit_from_manage.cmd");
commands.put("addOutfitItemsToCart","/outfitter/add_outfit_items_to_order.cmd");
commands.put("iLikeIt","/outfitter/ilikeit.cmd");
commands.put("iLikeThis","/outfitter/ilikethisoutfit.cmd");
commands.put("showMessages", "/outfitter/jsp/messages.jsp");
commands.put("showMessagesFromNav", "/outfitter/jsp/messages_main_pages.jsp");
commands.put("updateMessagesPagable", "/outfitter/jsp/messages_pagable_pages.jsp");
commands.put("messageAction", "/outfitter/jsp/message_action.jsp");
commands.put("sendMessage", "/outfitter/jsp/send_message.cmd");
commands.put("deleteMessage", "/outfitter/jsp/delete_message.cmd");
commands.put("deleteMultipleMessages", "/outfitter/jsp/delete_messages.cmd");
commands.put("friendRequest", "/outfitter/accept_friend_request.cmd");
commands.put("blockUser", "/outfitter/block_user.cmd");
commands.put("messageLeftnav", "/outfitter/jsp/message_leftnav.jsp");
commands.put("deleteRelationship", "/outfitter/delete_relationships.cmd");
commands.put("updateMessageleftnav", "/outfitter/jsp/message_leftnav.jsp");
// showloader
// 0 == don't show loading, and just append, 1 == show loading, clear layer, then append
// Any HTML update needs to set loaderInfo
var loaderInfo = new Map();
loaderInfo.put("showCloset",1);
loaderInfo.put("showOutfits",1);
loaderInfo.put("showMessages",1);
loaderInfo.put("updateOutfitLayer",1);
loaderInfo.put("saveOutfit",0);
loaderInfo.put("publishOutfit",0);
loaderInfo.put("updateOutfit",0);
loaderInfo.put("loadOutfitStage",1);
loaderInfo.put("loadOutfitTags",1);
loaderInfo.put("loadOutfitInfo",1);
loaderInfo.put("manageOutfits",1);
loaderInfo.put("manageItems",1);
loaderInfo.put("removeItemFromCloset",1);
loaderInfo.put("removeOutfitFromCloset",0);
loaderInfo.put("manageTable",1);
loaderInfo.put("removeItemManage",1);
loaderInfo.put("removeOutfitManage",1);
loaderInfo.put("iLikeIt",0);
loaderInfo.put("iLikeThis",0);
loaderInfo.put("showMessagesFromNav", 1);
loaderInfo.put("updateMessagesPagable", 1);
loaderInfo.put("messageAction", 1);
loaderInfo.put("sendMessage", 1);
loaderInfo.put("deleteMessage", 1);
loaderInfo.put("deleteMultipleMessages", 1);
loaderInfo.put("friendRequest", 1);
loaderInfo.put("blockUser", 1);
loaderInfo.put("messageLeftnav", 0);
loaderInfo.put("deleteRelationship", 1);
loaderInfo.put("updateMessageleftnav", 0);
/* Function(s) to show layer/state (HTML) */
function updateHTML(action,params,type,area) {
if(loaderInfo.get(action) == 1)
{ loading(action,area); }
// add random number to request.
params = "rId=" + uniqueID() + "&" + params;
requestURL = commands.get(action);
$.ajax({
type: type,
url: requestURL,
data: params,
dataType: "html",
timeout: 15000,
success: function(data) {
handleHTML(action,data,area);
return true;
},
error: function() {
if(loaderInfo.get(action) == 1)
{ ajaxErrorHandler(action,area); }
}
});
};
/* ------------------------------------- */
/* Function(s) to get data (XML) */
function updateXML(action,params,type) {
requestURL = commands.get(action);
params = "rId=" + uniqueID() + "&" + params;
$.ajax({
type: type,
url: requestURL,
data: params,
dataType: "xml",
success: function(data) {
handleXML(action,data);
return true; },
error: function() { alert("ERROR"); return false; }
});
};
/* -------------------------------------- */
/* Helper Functions */
/* Error Handling Function */
function ajaxErrorHandler(action,area) {
if( (action == "showCloset") || (action == "showOutfits") || (action == "showMessages") || (action == "removeItemFromCloset") )
{ $("#o-closet-loading-msg").hide(); }
else if( (action == "loadOutfitStage") || (action == "removeOutfitFromCloset") )
{ $("#o-the-stage-loading").hide(); }
else if( (action == "manageOutfits") || (action == "manageItems") )
{
$(area +" *").remove();
$(area).html("");
removeManagelayer();
unShrinkPage();
outfitterTabs.showTab( outfitterTabs.getCurrentTab() );
}
else if( (action == "manageTable") || (action == "removeItemManage") || (action == "removeOutfitManage") )
{
$(area +" *").remove();
$(area).html("");
$("#o-manage-loading").hide();
}
else
{
if( action == "updateOutfitLayer" )
{ overlayHide(); }
$(area +" *").remove();
$(area).hide();
}
};
/* ----------------------------------------- */
/* Loading function (HTML) */
function loading(action,area) {
if( (action == "showCloset") || (action == "showOutfits") || (action == "showMessages") || (action == "removeItemFromCloset") )
{ $("#o-closet-loading-msg").show(); }
else if( (action == "loadOutfitStage") || (action == "removeOutfitFromCloset") )
{ $("#o-the-stage-loading").show(); }
else if( (action == "manageOutfits") || (action == "manageItems") )
{
$(area +" *").remove();
$(area).html("");
$("#o-manage-loading2").show();
}
else if( (action == "manageTable") || (action == "removeItemManage") || (action == "removeOutfitManage") )
{
$(area +" *").remove();
$(area).html("");
$("#o-manage-loading").show();
}
else
{
//default loading
if (action == "loadOutfitTags")
{ html = '
'; }
else if( action == "loadOutfitInfo" )
{ html = '
'; }
else if( action == "updateOutfitLayer" )
{ html = '
';}
else if ( (action == "sendMessage") || (action == "deleteRelationship") || (action == "friendRequest") || (action == "blockUser") || (action == "messageAction") || (action == "deleteMultipleMessages") || (action == "deleteMessage") || (action == "showMessagesFromNav") || (action == "updateMessagesPagable") )
{ html = '
'; }
else
{ html = 'Loading...'; }
$(area +" *").remove();
$(area).append(html);
$(area).show();
}
};
/* --------------------------- */
/* HTML HANDLER (HTML)*/
function handleHTML(action,data,area) {
// if need to do something special for a action set that up here.
if( (action == "removeOutfitFromCloset") || (action == "removeItemFromCloset") || (action == "showCloset") || (action == "showOutfits") || (action == "showMessages") )
{
//remove old areas if needed
if( (action == "showCloset") || (action == "removeItemFromCloset") )
{ $("#o-my-closet-items").parent().remove(); }
else if( (action == "showOutfits") || (action == "removeOutfitFromCloset") )
{ $("#o-my-closet-outfits").parent().remove(); }
data = '