$(function() { // -- Application Variables -------------------------------------------------------------------------------- var ServerAddr = ''; // Required if using Session Data var User = { userID:'', CID:0, FName:'', MI:'', LName:'', Status:'', Groups: '' }; // Sets Default Values in case the user does not have some values - Required if using Session Data // Test data section - Comment out this entire section when installing for FirstClass /* User = { userID:'jschmo', CID:1234, FName:'Jo', MI:'', LName:'Schmo', Status:'I am testing this out', Groups:{0:'First Group', 1:'Second Group'} }; RunApp() */ // End Test data section // Running in test mode with test data, comment out this line which is the starting point getSessionInfo(); // Application Code here when run either offline or installed ------------------------------------------------- function RunApp() { // App now has Session Info so you can run your application. $("#fname").html(User.FName); $("#lname").html(User.LName); $("#userid").html(User.userID); $("#cid").html(User.CID); console.log(User.userID); } // --- Functions used to retrieve User Information do not touch ----------- function getSessionInfo() { var getURL = getParentUrl(); // Get the URL of the FCWS Server, not the iFrame getURL.done(function() { // Now that we know the Server URL, we can retrieve the Session Info var SessionURL = ServerAddr + "/FCP/?KnownObject=-3&ReplyAsJSON" var getSessionInfo = fcwsRequest(SessionURL); $.when(getSessionInfo).done(function(data) { User.userID = data.FORMDATA["7012"]; User.CID = data.FORMDATA["7006"]; if (data.FORMDATA["7001"]) { User.FName = data.FORMDATA["7001"] }; if (data.FORMDATA["7002"]) { User.MI = data.FORMDATA["7002"] }; User.LName = data.FORMDATA["7003"]; if (data.FORMDATA["7020"]) { User.Status = data.FORMDATA["7020"] }; if (data.FORMDATA["7040"]) { User.Groups = data.FORMDATA["7040"] }; // The App is now ready to run RunApp(); }); }); } // Get the URL of the parent window ------------------------------------------------------------------------- function getParentUrl() { var deferred = $.Deferred(); var isInIframe = (parent !== window) var myURL = null; if (isInIframe) { myURL = document.referrer; } var protocol = myURL.substr(0, myURL.indexOf('://') + 3); var remaining_url = myURL.substr(protocol.length, myURL.length) var domain_w_port = remaining_url.substr(0, remaining_url.indexOf('/')); var domain = (domain_w_port.indexOf(':') == -1 ? domain_w_port : domain_w_port.substr(0, domain_w_port.indexOf(':'))); var port = (domain_w_port.indexOf(':') == -1) ? '' : domain_w_port.substr(domain_w_port.indexOf(':')) ServerAddr = protocol + domain + port; deferred.resolve(); return deferred.promise(); } // FCWS API Request -------------------------------------------------------------------------------------- function fcwsRequest(GetURL) { return $.ajax({ url:GetURL, type:"GET", crossDomain: true, dataType: 'jsonp', success: function(data, textStatus, jqXHR) { // data will be returned }, error: function(data, textStatus, jqXHR) { // Let developer know there is an error alert("Error Retrieving JSON\ntextStatus:" + textStatus + "\nqXHR:" + jqXHR); } }); } });