Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| myapps:agent-callback [2022/02/03 14:37] – [JQuery - JSON / HTML Tables] gerardorourke | myapps:agent-callback [2022/02/21 18:25] (current) – [XML Code for createCallback] gerardorourke | ||
|---|---|---|---|
| Line 215: | Line 215: | ||
| </ | </ | ||
| + | ==== JS Code for createCallback==== | ||
| <code JavaScript> | <code JavaScript> | ||
| // Author: Gerry O' | // Author: Gerry O' | ||
| // Agent Callback Gadget | // Agent Callback Gadget | ||
| // Date 02/ | // Date 02/ | ||
| + | |||
| var finesse = finesse || {}; | var finesse = finesse || {}; | ||
| finesse.gadget = finesse.gadget || {}; | finesse.gadget = finesse.gadget || {}; | ||
| finesse.container = finesse.container || {}; | finesse.container = finesse.container || {}; | ||
| _clientLogger = finesse.cslogger.ClientLogger || {}; // for logging | _clientLogger = finesse.cslogger.ClientLogger || {}; // for logging | ||
| - | + | ||
| + | |||
| /** @namespace */ | /** @namespace */ | ||
| finesse.modules = finesse.modules || {}; | finesse.modules = finesse.modules || {}; | ||
| finesse.modules.AgentCallbackGadget = (function ($) { | finesse.modules.AgentCallbackGadget = (function ($) { | ||
| + | |||
| var _user; | var _user; | ||
| var _host = ' | var _host = ' | ||
| Line 237: | Line 238: | ||
| var _callbackText = 'To speak directly to this agent, please call 01 5551234 and enter the 6 digit PIN:'; | var _callbackText = 'To speak directly to this agent, please call 01 5551234 and enter the 6 digit PIN:'; | ||
| var _version = ' | var _version = ' | ||
| + | |||
| /** | /** | ||
| * Populates the fields in the gadget with data | * Populates the fields in the gadget with data | ||
| Line 245: | Line 246: | ||
| gadgets.window.adjustHeight(); | gadgets.window.adjustHeight(); | ||
| }, | }, | ||
| - | | + | |
| - | + | ||
| /* This function uses the gadgets.io.makeRequest - to do the REST GET, POST or PUT requests and returns success / error | /* This function uses the gadgets.io.makeRequest - to do the REST GET, POST or PUT requests and returns success / error | ||
| * Reference: https:// | * Reference: https:// | ||
| Line 258: | Line 259: | ||
| var params, uuid; | var params, uuid; | ||
| _clientLogger.log(" | _clientLogger.log(" | ||
| + | |||
| // Protect against null dereferencing of options & handlers allowing its (nonexistant) keys to be read as undefined | // Protect against null dereferencing of options & handlers allowing its (nonexistant) keys to be read as undefined | ||
| params = {}; | params = {}; | ||
| Line 264: | Line 265: | ||
| handlers.success = _util.validateHandler(handlers.success); | handlers.success = _util.validateHandler(handlers.success); | ||
| handlers.error = _util.validateHandler(handlers.error); | handlers.error = _util.validateHandler(handlers.error); | ||
| + | |||
| // Request Headers | // Request Headers | ||
| params[gadgets.io.RequestParameters.HEADERS] = {}; | params[gadgets.io.RequestParameters.HEADERS] = {}; | ||
| + | |||
| // HTTP method is a passthrough to gadgets.io.makeRequest | // HTTP method is a passthrough to gadgets.io.makeRequest | ||
| params[gadgets.io.RequestParameters.METHOD] = options.method; | params[gadgets.io.RequestParameters.METHOD] = options.method; | ||
| + | |||
| if (options.method === " | if (options.method === " | ||
| // Disable caching for GETs | // Disable caching for GETs | ||
| Line 282: | Line 283: | ||
| params[gadgets.io.RequestParameters.HEADERS].requestId = uuid; | params[gadgets.io.RequestParameters.HEADERS].requestId = uuid; | ||
| params[gadgets.io.RequestParameters.GET_FULL_HEADERS] = " | params[gadgets.io.RequestParameters.GET_FULL_HEADERS] = " | ||
| - | + | ||
| } else { | } else { | ||
| // Generate a requestID and add it to the headers | // Generate a requestID and add it to the headers | ||
| Line 289: | Line 290: | ||
| params[gadgets.io.RequestParameters.GET_FULL_HEADERS] = " | params[gadgets.io.RequestParameters.GET_FULL_HEADERS] = " | ||
| } | } | ||
| - | | + | |
| + | |||
| // Add content type & body if content body is provided | // Add content type & body if content body is provided | ||
| if (options.content) { | if (options.content) { | ||
| Line 298: | Line 299: | ||
| params[gadgets.io.RequestParameters.POST_DATA] = options.content; | params[gadgets.io.RequestParameters.POST_DATA] = options.content; | ||
| } | } | ||
| + | |||
| // Call the gadgets.io.makereqest function with the encoded url | // Call the gadgets.io.makereqest function with the encoded url | ||
| _clientLogger.log(" | _clientLogger.log(" | ||
| gadgets.io.makeRequest(encodeURI(url), | gadgets.io.makeRequest(encodeURI(url), | ||
| }, | }, | ||
| - | | + | |
| /** | /** | ||
| * Handler for the response of the REST API request. This function determines if | * Handler for the response of the REST API request. This function determines if | ||
| Line 319: | Line 320: | ||
| return function (response) { | return function (response) { | ||
| _clientLogger.log(" | _clientLogger.log(" | ||
| + | |||
| // Send the response to the success handler if the http status | // Send the response to the success handler if the http status | ||
| // code is 200 - 299. Send the response to the error handler | // code is 200 - 299. Send the response to the error handler | ||
| Line 334: | Line 335: | ||
| }; | }; | ||
| }, | }, | ||
| - | | + | |
| + | |||
| /** | /** | ||
| * Handler for getCallbacks when successful. | * Handler for getCallbacks when successful. | ||
| Line 341: | Line 342: | ||
| _getCallbacksSuccess = function(response) { | _getCallbacksSuccess = function(response) { | ||
| _clientLogger.log (" | _clientLogger.log (" | ||
| + | |||
| var _getCallbacksSuccessJSON = JSON.parse(response.text); | var _getCallbacksSuccessJSON = JSON.parse(response.text); | ||
| _clientLogger.log (" | _clientLogger.log (" | ||
| callbackTableValues = _getCallbacksSuccessJSON; | callbackTableValues = _getCallbacksSuccessJSON; | ||
| + | |||
| $("# | $("# | ||
| _clientLogger.log (" | _clientLogger.log (" | ||
| - | + | ||
| + | |||
| function generateTableHead(table, | function generateTableHead(table, | ||
| let thead = table.createTHead(); | let thead = table.createTHead(); | ||
| Line 360: | Line 361: | ||
| } | } | ||
| } | } | ||
| + | |||
| function generateTable(table, | function generateTable(table, | ||
| for (let element of data) { | for (let element of data) { | ||
| Line 371: | Line 372: | ||
| } | } | ||
| } | } | ||
| + | |||
| let table = document.querySelector("# | let table = document.querySelector("# | ||
| let data = Object.keys(callbackTableValues[0]); | let data = Object.keys(callbackTableValues[0]); | ||
| + | |||
| _clientLogger.log (" | _clientLogger.log (" | ||
| generateTableHead(table, | generateTableHead(table, | ||
| generateTable(table, | generateTable(table, | ||
| + | |||
| gadgets.window.adjustHeight(); | gadgets.window.adjustHeight(); | ||
| + | |||
| }, | }, | ||
| + | |||
| /** | /** | ||
| * Handler for getCallback Errors | * Handler for getCallback Errors | ||
| Line 390: | Line 391: | ||
| var statusCode = response.rc; | var statusCode = response.rc; | ||
| var errorMessage = ' | var errorMessage = ' | ||
| + | |||
| // Checking if we got any HTTP Headers in response (maybe not if there was a Timeout etc.) | // Checking if we got any HTTP Headers in response (maybe not if there was a Timeout etc.) | ||
| if (typeof response.headers != " | if (typeof response.headers != " | ||
| var myContentType = response.headers[" | var myContentType = response.headers[" | ||
| console.log(" | console.log(" | ||
| + | |||
| //Checking if Content is JSON and so use the error value returned by the server | //Checking if Content is JSON and so use the error value returned by the server | ||
| if (myContentType == " | if (myContentType == " | ||
| Line 405: | Line 406: | ||
| } | } | ||
| } | } | ||
| + | |||
| _clientLogger.log (" | _clientLogger.log (" | ||
| _clientLogger.log (" | _clientLogger.log (" | ||
| - | + | ||
| + | |||
| $('# | $('# | ||
| $('# | $('# | ||
| $('# | $('# | ||
| $('# | $('# | ||
| + | |||
| gadgets.window.adjustHeight(); | gadgets.window.adjustHeight(); | ||
| }, | }, | ||
| + | |||
| /** | /** | ||
| * Handler for getCallbacks when successful. | * Handler for getCallbacks when successful. | ||
| Line 423: | Line 424: | ||
| _createCallbackSuccess = function(response) { | _createCallbackSuccess = function(response) { | ||
| _clientLogger.log (" | _clientLogger.log (" | ||
| + | |||
| var _getCallbacksSuccessJSON = JSON.parse(response.text); | var _getCallbacksSuccessJSON = JSON.parse(response.text); | ||
| _clientLogger.log (" | _clientLogger.log (" | ||
| callbackTableValues = _getCallbacksSuccessJSON; | callbackTableValues = _getCallbacksSuccessJSON; | ||
| + | |||
| $("# | $("# | ||
| _clientLogger.log (" | _clientLogger.log (" | ||
| - | + | ||
| + | |||
| function generateTableHead(table, | function generateTableHead(table, | ||
| let thead = table.createTHead(); | let thead = table.createTHead(); | ||
| Line 442: | Line 443: | ||
| } | } | ||
| } | } | ||
| + | |||
| function generateTable(table, | function generateTable(table, | ||
| for (let element of data) { | for (let element of data) { | ||
| Line 453: | Line 454: | ||
| } | } | ||
| } | } | ||
| + | |||
| let table = document.querySelector("# | let table = document.querySelector("# | ||
| let data = Object.keys(callbackTableValues[0]); | let data = Object.keys(callbackTableValues[0]); | ||
| + | |||
| _clientLogger.log (" | _clientLogger.log (" | ||
| generateTableHead(table, | generateTableHead(table, | ||
| generateTable(table, | generateTable(table, | ||
| + | |||
| + | //Clear Name and Description Fields after successful Callback Creation. | ||
| + | document.getElementById(' | ||
| + | document.getElementById(' | ||
| + | |||
| gadgets.window.adjustHeight(); | gadgets.window.adjustHeight(); | ||
| + | |||
| }, | }, | ||
| + | |||
| /** | /** | ||
| * Handler for getCallback Errors | * Handler for getCallback Errors | ||
| Line 472: | Line 477: | ||
| var statusCode = response.rc; | var statusCode = response.rc; | ||
| var errorMessage = ' | var errorMessage = ' | ||
| + | |||
| // Checking if we got any HTTP Headers in response (maybe not if there was a Timeout etc.) | // Checking if we got any HTTP Headers in response (maybe not if there was a Timeout etc.) | ||
| if (typeof response.headers != " | if (typeof response.headers != " | ||
| var myContentType = response.headers[" | var myContentType = response.headers[" | ||
| console.log(" | console.log(" | ||
| + | |||
| //Checking if Content is JSON and so use the error value returned by the server | //Checking if Content is JSON and so use the error value returned by the server | ||
| if (myContentType == " | if (myContentType == " | ||
| Line 487: | Line 492: | ||
| } | } | ||
| } | } | ||
| + | |||
| _clientLogger.log (" | _clientLogger.log (" | ||
| _clientLogger.log (" | _clientLogger.log (" | ||
| - | + | ||
| + | |||
| $('# | $('# | ||
| $('# | $('# | ||
| $('# | $('# | ||
| $('# | $('# | ||
| + | |||
| gadgets.window.adjustHeight(); | gadgets.window.adjustHeight(); | ||
| }, | }, | ||
| + | |||
| /** | /** | ||
| * Handler for the onLoad of a User object. | * Handler for the onLoad of a User object. | ||
| * from the Finesse server. | * from the Finesse server. | ||
| */ | */ | ||
| - | | + | |
| | | ||
| _clientLogger.log(" | _clientLogger.log(" | ||
| + | |||
| _myAgentId = _user.getId(); | _myAgentId = _user.getId(); | ||
| _clientLogger.log(" | _clientLogger.log(" | ||
| _getCallbacks(); | _getCallbacks(); | ||
| }, | }, | ||
| - | + | ||
| _getCallbacks = function() { | _getCallbacks = function() { | ||
| _clientLogger.log (" | _clientLogger.log (" | ||
| + | |||
| var url = _baseURL + _getCallbackPath + '? | var url = _baseURL + _getCallbackPath + '? | ||
| _clientLogger.log (" | _clientLogger.log (" | ||
| + | |||
| makeRequest(url, | makeRequest(url, | ||
| method: ' | method: ' | ||
| Line 526: | Line 531: | ||
| }); | }); | ||
| }; | }; | ||
| + | |||
| _createCallback = function() { | _createCallback = function() { | ||
| _clientLogger.log (" | _clientLogger.log (" | ||
| + | |||
| + | const RadioCallbackExpiryButtons = document.querySelectorAll(' | ||
| + | for (const RadioCallbackExpiryButton of RadioCallbackExpiryButtons) { | ||
| + | if (RadioCallbackExpiryButton.checked) { | ||
| + | ExpiryHours = RadioCallbackExpiryButton.value; | ||
| + | _clientLogger.log (" | ||
| + | break; | ||
| + | } | ||
| + | } | ||
| + | |||
| var name = document.getElementById(' | var name = document.getElementById(' | ||
| - | if (name==="" | + | if (name==="" |
| var description = document.getElementById(' | var description = document.getElementById(' | ||
| - | if (description==="" | + | if (description==="" |
| _clientLogger.log (" | _clientLogger.log (" | ||
| - | + | ||
| - | document.getElementById(' | + | var url = _baseURL + _createCallbackPath + '? |
| - | document.getElementById(' | + | |
| - | + | ||
| - | var url = _baseURL + _createCallbackPath + '? | + | |
| _clientLogger.log (" | _clientLogger.log (" | ||
| + | |||
| makeRequest(url, | makeRequest(url, | ||
| method: ' | method: ' | ||
| Line 549: | Line 560: | ||
| }); | }); | ||
| }; | }; | ||
| + | |||
| /** @scope finesse.modules.AgentCallbackGadget */ | /** @scope finesse.modules.AgentCallbackGadget */ | ||
| return { | return { | ||
| Line 557: | Line 568: | ||
| */ | */ | ||
| refreshCallbacks : function () { | refreshCallbacks : function () { | ||
| + | // Clear Name and Description Fields | ||
| + | document.getElementById(' | ||
| + | document.getElementById(' | ||
| + | |||
| _getCallbacks(); | _getCallbacks(); | ||
| }, | }, | ||
| + | |||
| /** | /** | ||
| * Create Callback | * Create Callback | ||
| Line 567: | Line 582: | ||
| _createCallback(); | _createCallback(); | ||
| }, | }, | ||
| - | + | ||
| /** | /** | ||
| * Create Callback | * Create Callback | ||
| Line 580: | Line 595: | ||
| _clientLogger.log (' | _clientLogger.log (' | ||
| _clientLogger.log (' | _clientLogger.log (' | ||
| + | |||
| /* Copy the text inside the text field */ | /* Copy the text inside the text field */ | ||
| navigator.clipboard.writeText(_callbackText + ' ' + copyCallbackId + '. This callback will expire on ' + copyExpiryTime); | navigator.clipboard.writeText(_callbackText + ' ' + copyCallbackId + '. This callback will expire on ' + copyExpiryTime); | ||
| + | |||
| /* Alert the copied text */ | /* Alert the copied text */ | ||
| alert(' | alert(' | ||
| }, | }, | ||
| + | |||
| /** | /** | ||
| * Performs all initialization for this gadget | * Performs all initialization for this gadget | ||
| Line 593: | Line 608: | ||
| init : function () { | init : function () { | ||
| var _clientLogger = finesse.cslogger.ClientLogger; | var _clientLogger = finesse.cslogger.ClientLogger; | ||
| + | |||
| // Initiate the ClientLogs. The gadget id will be logged as a part of the message | // Initiate the ClientLogs. The gadget id will be logged as a part of the message | ||
| _clientLogger.init(gadgets.Hub, | _clientLogger.init(gadgets.Hub, | ||
| _clientLogger.log (" | _clientLogger.log (" | ||
| - | | + | |
| var cfg = finesse.gadget.Config; | var cfg = finesse.gadget.Config; | ||
| _util = finesse.utilities.Utilities; | _util = finesse.utilities.Utilities; | ||
| + | |||
| // Initiate the ClientServices and load the user object. ClientServices are | // Initiate the ClientServices and load the user object. ClientServices are | ||
| // initialized with a reference to the current configuration. | // initialized with a reference to the current configuration. | ||
| finesse.clientservices.ClientServices.init(cfg, | finesse.clientservices.ClientServices.init(cfg, | ||
| - | + | ||
| gadgets.window.adjustHeight(); | gadgets.window.adjustHeight(); | ||
| - | | + | |
| - | + | ||
| _user = new finesse.restservices.User({ | _user = new finesse.restservices.User({ | ||
| id: finesse.gadget.Config.id, | id: finesse.gadget.Config.id, | ||
| Line 614: | Line 629: | ||
| _clientLogger.log (" | _clientLogger.log (" | ||
| _clientLogger.log (" | _clientLogger.log (" | ||
| + | |||
| // Initiate the ContainerServices and add a handler for when the tab is visible | // Initiate the ContainerServices and add a handler for when the tab is visible | ||
| // to adjust the height of this gadget in case the tab was not visible | // to adjust the height of this gadget in case the tab was not visible | ||
| Line 629: | Line 644: | ||
| }; | }; | ||
| }(jQuery)); | }(jQuery)); | ||
| + | </ | ||
| + | |||
| + | ==== XML Code for createCallback==== | ||
| + | <code xml> | ||
| + | <?xml version=" | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | < | ||
| + | < | ||
| + | display_name=" | ||
| + | default_value=""/> | ||
| + | < | ||
| + | display_name=" | ||
| + | default_value=""/> | ||
| + | < | ||
| + | display_name=" | ||
| + | default_value=""/> | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | <!-- Styling --> | ||
| + | <link rel=" | ||
| + | <link rel=" | ||
| + | |||
| + | <!-- jQuery - uncomment if NOT hosting on Finesse server --> | ||
| + | < | ||
| + | |||
| + | <!-- Finesse Library - uncomment if NOT hosting on Finesse server --> | ||
| + | < | ||
| + | |||
| + | <!-- Bootstrap - Must appear After jQuery JS--> | ||
| + | <script type=" | ||
| + | |||
| + | | ||
| + | <!-- Gadget Business Logic --> | ||
| + | <script type=" | ||
| + | </ | ||
| + | |||
| + | <body class=" | ||
| + | |||
| + | <div class=" | ||
| + | |||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | <button type=" | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | < | ||
| + | |||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | |||
| + | < | ||
| + | < | ||
| + | < | ||
| + | 1 hour | ||
| + | </ | ||
| + | </ | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | 1 day | ||
| + | </ | ||
| + | </ | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | 1 week | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | </ | ||
| + | |||
| + | < | ||
| + | |||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | <script type=" | ||
| + | ]]></ | ||
| + | </ | ||
| </ | </ | ||