var finesse = finesse || {}; finesse.gadget = finesse.gadget || {}; finesse.container = finesse.container || {}; var clientLogs = finesse.cslogger.ClientLogger || {}; // for logging /** @namespace */ finesse.modules = finesse.modules || {}; finesse.modules.SPAFinesse = (function ($) { var user, dialogs, clientlogs, _util, alternatingUrlNumber, ipNum, buttonAllowedByCalltype = false, buttonAllowedByUserState = false; /** @scope finesse.modules.SPAFinesse */ return { init : function (ip) { ipNum = ip; var cfg = finesse.gadget.Config; _util = finesse.utilities.Utilities; clientLogs = finesse.cslogger.ClientLogger; // declare clientLogs // Initiate the ClientServices and load the user object. ClientServices are // initialized with a reference to the current configuration. finesse.clientservices.ClientServices.init(cfg, false); // Initiate the ClientLogs. The gadget id will be logged as a part of the message clientLogs.init(gadgets.Hub, "SPAFinesse"); // Create a user object for this user (Call GET User) user = new finesse.restservices.User({ id: cfg.id, onLoad : handleUserLoad, onChange : handleUserChange }); //states = finesse.restservices.User.States; //need this? containerServices = finesse.containerservices.ContainerServices.init(); containerServices.addHandler(finesse.containerservices.ContainerServices.Topics.ACTIVE_TAB, function() { gadgets.window.adjustHeight(); }); containerServices.makeActiveTabReq(); } }; function handleUserChange(user) { addMsgToCallLog(new Date($.now()) + " entered handleUserChange"); }; function handleUserLoad(user) { addMsgToCallLog(new Date($.now()) + " entered handleUserLoad"); dialogs = user.getDialogs( { onCollectionAdd : handleNewDialog, onCollectionDelete : handleEndDialog, onChange : handleDialogAdd, //only gets called on finesse page load }); $("#responseBody").text("Please wait for a call."); gadgets.window.adjustHeight(); }; function handleDialogAdd(dialog) { addMsgToCallLog(new Date($.now()) + " entered handleDialogAdd"); // add change handler to detect participant list change //dialog.addHandler("change", handleDialogChange); //never gets called }; function handleDialogChange(dialog) { addMsgToCallLog(new Date($.now()) + " entered handleDialogChange!"); var plist = dialog.getParticipants(); // process list futher here addMsgToCallLog(new Date($.now()) + " particiLen= " + plist.length); }; function handleNewDialog(dialog) { addMsgToCallLog(new Date($.now()) + " handleNewDialog.callType=" + dialog.getMediaProperties().callType); dialog.addHandler("change", handleDialogChange); //works }; function handleEndDialog(dialog) { addMsgToCallLog(new Date($.now()) + " handleEndDialog.callType=" + dialog.getMediaProperties().callType); // Update the gadget accordingly after the call completes $("#responseBody").text("Please wait for the next call."); gadgets.window.adjustHeight(); }; function addMsgToCallLog(msg) { var newline = " "; $("#callProgress").append(newline).append(msg); //scroll to the bottom of the call log box $("#callProgress").scrollTop($("#callProgress")[0].scrollHeight); }; }(jQuery));