diff --git a/shrine-webclient/src/main/html/js-i2b2/cells/SHRINE/EnhancedError.js b/shrine-webclient/src/main/html/js-i2b2/cells/SHRINE/EnhancedError.js index ae567cc62..f245cb9d2 100644 --- a/shrine-webclient/src/main/html/js-i2b2/cells/SHRINE/EnhancedError.js +++ b/shrine-webclient/src/main/html/js-i2b2/cells/SHRINE/EnhancedError.js @@ -1,311 +1,310 @@ /** * Created by ben on 10/13/15. */ var $hrine = window.$hrine = {}; $hrine.EnhancedError = (function(){ var EnhancedError = {}, config = config || { //@TODO: }; /** * * @returns {{}} */ function simulateI2b2Obj() { var self = {}, errorObject = { summary: "SHRINE Failed to Start", description: "The SHRINE software is not running at the queried" + " site. This error must be corrected at the queried site.Check network status or contact your local SHRINE administrator. For faster assistance, expand this window and provide all text below this line to your local SHRINE administrator.", details: "There is a fatal syntax error in the remote site's" + " shrine.conf or another .conf file. The remote site admin should check to make sure that there are no stray/missing quotes or brackets, and that URLs are entered correctly.", codec: "" }; self.errorObject = errorObject; self.dispDIV = document.getElementById('infoQueryStatusText'); self.dispDIV.innerHTML = '
SHRINE Critical Error
'; //which hospital self.dispDIV.innerHTML += '

Error Summary:
'; self.dispDIV.innerHTML += "" + "" + errorObject.summary + ""; return self; } /** * Scope for error dialog. */ EnhancedError.createErrorDialogue = function (container, errorObjects) { var anchors, btnExpand, btnContract, errorData, i2b2Obj; //default error. if(!container || !errorObjects) { i2b2Obj = simulateI2b2Obj(); container = i2b2Obj.dispDIV; errorObjects = [i2b2Obj.errorObject]; } //this sets up the events. anchors = container.getElementsByClassName('query-error-anchor'); //something's wrong captain, abandon ship! if(!anchors.length|| !errorObjects.length) { return; } addAnchorEvents(); function expandErrorDetailDiv (ev) { var errorDetailDiv = $('errorDetailDiv'); btnExpand.style.display = 'none'; btnContract.style.display = 'inline'; errorDetailDiv.innerHTML = getExpandedHtml(); } function retractErrorDetailDiv (ev) { var errorDetailDiv = $('errorDetailDiv'); btnExpand.style.display = 'inline'; btnContract.style.display = 'none'; errorDetailDiv.innerHTML = getRetractedHtml(); } function onClick(event) { event.preventDefault(); errorData = event.currentTarget.__errorData__; btnExpand = document.getElementById('btnExpandErrorDetail'); btnContract = document.getElementById('btnContractErrorDetail'); // -- add event listeners for expand and contract as well --// btnExpand.addEventListener('click', expandErrorDetailDiv, false); btnContract.addEventListener('click', retractErrorDetailDiv, false); showErrorDetail(errorData); } /** * * @param errorData * @returns {string} */ function getRetractedHtml () { var wikiBaseUrl = (i2b2.hive.cfg.wikiBaseUrl || 'https://open.med.harvard.edu/wiki/display/SHRINE/'); if(wikiBaseUrl.lastIndexOf('/') !== wikiBaseUrl.length -1){ wikiBaseUrl += '/'; } var retractedHtml = '
Summary:
'+ '
' + errorData.summary + '

' + '
Description:
'+ '
' + errorData.description + '

' + '
For information on troubleshooting and resolution, check' + ' the SHRINE Error' + ' Codex.
'; return retractedHtml; } /** * * @param errorData * @returns {string} */ function getExpandedHtml () { var expandedHtml = getRetractedHtml() + '
' + '
Copy the text below and paste it in an email to your site administrator for a faster response.
' + '
' + '
Technical Details:
' + errorData.details + '

' + '
Codec:
' + errorData.codec + '

' + '
Stamp:
' + errorData.stamp + '

' + '
Stack Trace Name:
' + errorData.exception.name + '

' + '
Stack Trace Message:
' + errorData.exception.message + '

' + '
Stack Trace Details:
' + errorData.exception.stackTrace + '

'; return expandedHtml; } /** * * @param detailObj */ function showErrorDetail(detailObj) { var handleCancel = function() { this.cancel(); removeAllEvents(); retractErrorDetailDiv(); } var dialogErrorDetail = new YAHOO.widget.SimpleDialog("dialogErrorDetail", { width: "820px", fixedcenter: true, constraintoviewport: true, modal: true, zindex: 700, buttons: [ { text: "Done", handler: handleCancel, isDefault: true }] }); dialogErrorDetail._doClose = function (e) { e.preventDefault(); this.cancel(); removeAllEvents(); retractErrorDetailDiv(); } $('dialogErrorDetail').show(); dialogErrorDetail.validate = function(){ return true; }; dialogErrorDetail.render(document.body); // / display the dialoge dialogErrorDetail.center(); dialogErrorDetail.show(); $('errorDetailDiv').innerHTML = getRetractedHtml(); } function addAnchorEvents () { var el, length = anchors.length; // -- will need to iterate over these once they are created and add event listeners. for(var i = 0; i < length; i ++) { var el = anchors[i]; el.__errorData__ = errorObjects[i]; el.addEventListener('click', onClick, false); } } function removeAllEvents () { btnExpand.removeEventListener('click', expandErrorDetailDiv); btnContract.removeEventListener('click', retractErrorDetailDiv); } } /** * Parse problem node. * @param qriNode * @returns {{exception: {}}} */ EnhancedError.parseProblem = function (qriNode) { var details, problem = { exception: {} - }, - innerHTML; + }; problem.codec = grabXmlNodeData(qriNode, 'descendant-or-self::query_status_type/problem/codec'); problem.summary = grabXmlNodeData(qriNode, 'descendant-or-self::query_status_type/problem/summary'); problem.description = grabXmlNodeData(qriNode, 'descendant-or-self::query_status_type/problem/description'); problem.stamp = grabXmlNodeData(qriNode, 'descendant-or-self::query_status_type/problem/stamp'); //unescape embedded html. details = i2b2.h.XPath(qriNode, 'descendant-or-self::query_status_type/problem/details') //funky stuff goin' on...get outta here! if(!details.length) { problem.exception.name = problem.exception.message = problem.stackTrace = problem.codec = problem.summary = 'An unexpected error has occurred.'; } //error format as expected. else{ var innerHTML = (details[0].xml !== undefined)? details[0].xml : details[0].innerHTML; problem.details = innerHTML.unescapeHTML().replace(/(<([^>]+)>)/ig,""); problem.exception.name = grabXmlNodeData(qriNode, 'descendant-or-self::query_status_type/problem/details/exception/name'); problem.exception.message = grabXmlNodeData(qriNode, 'descendant-or-self::query_status_type/problem/details/exception/message'); problem.exception.stackTrace = parseErrorException(qriNode); } return problem; } /** * Replace all and with
tags. * @param node * @returns {*} */ function parseErrorException(node) { //no exception, abandon ship! if(node.innerHTML.indexOf('') == -1){ return ''; } var content, startIdx, endIdx; //fish out the problem section. content = node.innerHTML.split('') .join() .split('') .join(); //fish out the first stack trace. startIdx = content.indexOf('') + 12; endIdx = content.indexOf(''); content = content.substring(startIdx, endIdx); //remove all line tags and replace with line break. content = content.split('') .join('
') .split('
') .join() //remove all exception tags .split('') .join('
') .split('
') .join() //remove all stacktrace tags .split('') .join('
') .split('
') .join() //remove all message tags. .split('') .join('
') .split('
') .join(); return content; } /** * Grab data for node, return empty string if none. * @param node * @param xPathString * @returns {string} */ function grabXmlNodeData(node, xPathString){ var nodeVal = i2b2.h.XPath(node, xPathString); return (nodeVal.length)? nodeVal[0].firstChild.nodeValue : ''; } return EnhancedError; })(); \ No newline at end of file