_base.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*******************************************************************************
  2. * IBM Confidential
  3. *
  4. * OCO Source Materials
  5. *
  6. * A and PM: PD
  7. *
  8. * (c) Copyright IBM Corp. 2014, 2015
  9. *
  10. * The source code for this program is not published or otherwise divested of
  11. * its trade secrets, irrespective of what has been deposited with the U.S.
  12. * Copyright Office.
  13. ******************************************************************************/
  14. define([
  15. "dojo/dom",
  16. "dojo/dom-construct",
  17. "pd/widgets/MessageDialog",
  18. "dojo/_base/connect",
  19. "dojo/dom-attr",
  20. "dojox/html/entities",
  21. "bux/dialogs/IFrameDialog"
  22. ], function(dom, domConstruct, MessageDialog, connect, domAttr, entities){
  23. if (typeof pd == "undefined") {
  24. this.pd = {};
  25. }
  26. pd.connect = connect;
  27. pd.supplementId = {
  28. PUBLISH_DIALOG: "pd_import_publish",
  29. PUBLISH_DIALOG_PUBLIC_FOLDERS: "pd_import_publish_publicFoldersBtn",
  30. PUBLISH_DIALOG_MY_FOLDERS: "pd_import_publish_myFoldersBtn",
  31. PUBLISH_DIALOG_NEW_FOLDER: "pd_import_publish_newFolder",
  32. PUBLISH_DIALOG_NEW_FOLDER_NAME_INPUT: "pd_import_publish_newFolder_folderNameTxt",
  33. PUBLISH_DIALOG_NEW_FOLDER_OK_BUTTON: "pd_import_publish_newFolder_okBtn",
  34. PUBLISH_DIALOG_NEW_FOLDER_CANCEL_BUTTON: "pd_import_publish_newFolder_cancelBtn",
  35. PUBLISH_DIALOG_PUBLISH_BUTTON: "pd_import_publish_publishBtn",
  36. PUBLISH_DIALOG_CANCEL_BUTTON: "pd_import_publish_cancelBtn",
  37. PUBLISH_DIALOG_NAME_INPUT: "pd_import_publish_packageNameTxt",
  38. IMPORT_DIALOG_PUBLISH_BUTTON: "pd_import_publishBtn",
  39. IMPORT_DIALOG_CANCEL_BUTTON: "pd_import_cancelBtn"
  40. };
  41. //To provide a more reliable mean to locate the critical elements/dojo widgets in selenium testing.
  42. pd.setSupplementId = function (element, id) {
  43. domAttr.set(element, "supplementid", pd.supplementId[id]);
  44. };
  45. pd.statics = {
  46. STATUS_INIT : "init",
  47. STATUS_UPLOAD : "upload",
  48. STATUS_PROCESS : "process",
  49. STATUS_FINISH : "finish",
  50. STATUS_DISABLED : "disabled",
  51. STATUS_ENABLED: "enabled",
  52. MODE_EDIT : "edit",
  53. MODE_REFRESH : "refresh",
  54. MODE_NORMAL : "normal",
  55. MB_ERROR : 1,
  56. MB_WARNING : 2,
  57. MB_INFO : 3
  58. };
  59. /**
  60. * Display a generic message box.
  61. * @param {enum} type is one of MB_ERROR, MB_WARNING or MB_INFO.
  62. * @param {String} msg the message
  63. * @param {String} desc optional description
  64. * @param {String} details optional details
  65. * @return {dojo.Deferred} deferred object for additional control
  66. */
  67. pd.messageBox = function(type, msg, desc, details) {
  68. var dfd = new dojo.Deferred();
  69. function dispose() {
  70. this.destroy();
  71. dfd.resolve(true);
  72. }
  73. var dlg = null;
  74. switch (type) {
  75. case pd.statics.MB_ERROR:
  76. dlg = new MessageDialog.Error(msg, desc, details, dispose);
  77. break;
  78. case pd.statics.MB_WARNING:
  79. dlg = new MessageDialog.Warning(msg, desc, details, dispose);
  80. break;
  81. default:
  82. dlg = new MessageDialog.Info(msg, desc, dispose);
  83. break;
  84. }
  85. dlg.startup();
  86. dlg.show();
  87. return dfd; // dojo.Deferred
  88. };
  89. pd.workingDialog = function(msg) {
  90. dlg = new MessageDialog.Working(msg);
  91. dlg.startup();
  92. dlg.show();
  93. return dlg;
  94. };
  95. pd.placeDiv = function(id, node){
  96. if (!dom.byId(id)){
  97. domConstruct.place("<div id='"+id+"'></div>", node);
  98. }
  99. };
  100. pd.convertToInnerHtml = function(str){
  101. if (str == null || str == undefined) {
  102. return null;
  103. }
  104. var elt = document.createElement("div");
  105. elt.innerHTML = str;
  106. return entities.decode(elt.innerHTML);
  107. };
  108. pd.showLogonDialog = function(){
  109. var pdLogonDialog = new bux.dialogs.LogonDialog({
  110. okHandler: function() {
  111. pdLogonDialog = null;
  112. },
  113. cancelHandler: function() {
  114. pdLogonDialog = null;
  115. }
  116. });
  117. pdLogonDialog.startup();
  118. pdLogonDialog.show();
  119. };
  120. pd.CAM_PASSPORT_ERROR = "camPassportError";
  121. pd.SERVER_NOT_AVAILABLE = "serverNotAvailable";
  122. pd.GENERAL_LOB_ERROR = "generalLobError";
  123. pd.parseResponse = function(/*Document|String*/response) {
  124. //Summary
  125. // this parser is expecting either a html/xml document or a html/xml markup generated from xts engine
  126. // It will retrieve the error code and error message, and use the errorPanel element if any as the details.
  127. if (!response) {
  128. throw new Error();
  129. }
  130. var markup = "";
  131. var errorPanel = null;
  132. if (dojo.isSafari){
  133. markup = response;
  134. var responseNode = domConstruct.toDom(response);
  135. if (responseNode.querySelector) {
  136. errorPanel = responseNode.querySelector("#errorPanel");
  137. }
  138. } else {
  139. if (typeof response == "string"){
  140. markup = response;
  141. var responseNode = domConstruct.toDom(response);
  142. if (responseNode.getElementById) {
  143. errorPanel = dom.byId("errorPanel", responseNode);
  144. }
  145. } else if (response.documentElement) {
  146. markup = response.documentElement.innerHTML;
  147. errorPanel = dom.byId("errorPanel", response);
  148. } else if (response.xml) {
  149. markup = response.xml;
  150. }
  151. }
  152. if (markup){
  153. function extractContent(content){
  154. var regExp = new RegExp("<.*?>", "i");
  155. var res = regExp.exec(content);
  156. if (res){
  157. var extractor = res[0];
  158. return content.substring(extractor.length, (content.length - extractor.length - 1));
  159. } else {
  160. return "";
  161. }
  162. }
  163. var errorList = [{
  164. errorCode: "<ERROR_CODE>SERVER_NOT_AVAILABLE</ERROR_CODE>",
  165. errorName: pd.SERVER_NOT_AVAILABLE,
  166. errorMessage: "<ERROR_MSG>.*?</ERROR_MSG>"
  167. },{
  168. errorCode: "<ERROR_CODE>CAM_PASSPORT_ERROR</ERROR_CODE>",
  169. errorName: pd.CAM_PASSPORT_ERROR
  170. },{
  171. errorCode: "<ERROR_CODE>CM-REQ-4159</ERROR_CODE>.*?CM-CAM-4005",
  172. errorName: pd.CAM_PASSPORT_ERROR
  173. },{
  174. errorCode: "<ERROR_CODE>.*?</ERROR_CODE>",
  175. errorName: pd.GENERAL_LOB_ERROR,
  176. errorMessage: "<ERROR_MSG>.*?</ERROR_MSG>"
  177. },{
  178. //bibus error handler
  179. errorCode: "<errorCode>.*?</errorCode>",
  180. errorName: pd.GENERAL_LOB_ERROR,
  181. errorMessage: "<messageString>.*?</messageString>"
  182. }];
  183. for (var i=0; i<errorList.length; i++){
  184. var pattCode = new RegExp(errorList[i].errorCode, "i");
  185. var resCode = pattCode.exec(markup);
  186. var pattMsg = new RegExp(errorList[i].errorMessage, "i");
  187. var resMsg = pattMsg.exec(markup);
  188. if (resCode){
  189. throw({
  190. name: errorList[i].errorName,
  191. message: extractContent(resCode[0]) +" "+ (resMsg?extractContent(resMsg[0]):""),
  192. detail: errorPanel?errorPanel.innerHTML:null
  193. });
  194. return;
  195. }
  196. }
  197. }
  198. };
  199. });