123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- /*******************************************************************************
- * IBM Confidential
- *
- * OCO Source Materials
- *
- * A and PM: PD
- *
- * (c) Copyright IBM Corp. 2014, 2015
- *
- * The source code for this program is not published or otherwise divested of
- * its trade secrets, irrespective of what has been deposited with the U.S.
- * Copyright Office.
- ******************************************************************************/
- define([
- "dojo/dom",
- "dojo/dom-construct",
- "pd/widgets/MessageDialog",
- "dojo/_base/connect",
- "dojo/dom-attr",
- "dojox/html/entities",
- "bux/dialogs/IFrameDialog"
- ], function(dom, domConstruct, MessageDialog, connect, domAttr, entities){
-
- if (typeof pd == "undefined") {
- this.pd = {};
- }
-
- pd.connect = connect;
-
- pd.supplementId = {
- PUBLISH_DIALOG: "pd_import_publish",
- PUBLISH_DIALOG_PUBLIC_FOLDERS: "pd_import_publish_publicFoldersBtn",
- PUBLISH_DIALOG_MY_FOLDERS: "pd_import_publish_myFoldersBtn",
- PUBLISH_DIALOG_NEW_FOLDER: "pd_import_publish_newFolder",
- PUBLISH_DIALOG_NEW_FOLDER_NAME_INPUT: "pd_import_publish_newFolder_folderNameTxt",
- PUBLISH_DIALOG_NEW_FOLDER_OK_BUTTON: "pd_import_publish_newFolder_okBtn",
- PUBLISH_DIALOG_NEW_FOLDER_CANCEL_BUTTON: "pd_import_publish_newFolder_cancelBtn",
- PUBLISH_DIALOG_PUBLISH_BUTTON: "pd_import_publish_publishBtn",
- PUBLISH_DIALOG_CANCEL_BUTTON: "pd_import_publish_cancelBtn",
- PUBLISH_DIALOG_NAME_INPUT: "pd_import_publish_packageNameTxt",
-
- IMPORT_DIALOG_PUBLISH_BUTTON: "pd_import_publishBtn",
- IMPORT_DIALOG_CANCEL_BUTTON: "pd_import_cancelBtn"
- };
-
- //To provide a more reliable mean to locate the critical elements/dojo widgets in selenium testing.
- pd.setSupplementId = function (element, id) {
- domAttr.set(element, "supplementid", pd.supplementId[id]);
- };
-
- pd.statics = {
- STATUS_INIT : "init",
- STATUS_UPLOAD : "upload",
- STATUS_PROCESS : "process",
- STATUS_FINISH : "finish",
- STATUS_DISABLED : "disabled",
- STATUS_ENABLED: "enabled",
- MODE_EDIT : "edit",
- MODE_REFRESH : "refresh",
- MODE_NORMAL : "normal",
- MB_ERROR : 1,
- MB_WARNING : 2,
- MB_INFO : 3
- };
-
-
- /**
- * Display a generic message box.
- * @param {enum} type is one of MB_ERROR, MB_WARNING or MB_INFO.
- * @param {String} msg the message
- * @param {String} desc optional description
- * @param {String} details optional details
- * @return {dojo.Deferred} deferred object for additional control
- */
- pd.messageBox = function(type, msg, desc, details) {
- var dfd = new dojo.Deferred();
- function dispose() {
- this.destroy();
- dfd.resolve(true);
- }
- var dlg = null;
- switch (type) {
- case pd.statics.MB_ERROR:
- dlg = new MessageDialog.Error(msg, desc, details, dispose);
- break;
- case pd.statics.MB_WARNING:
- dlg = new MessageDialog.Warning(msg, desc, details, dispose);
- break;
- default:
- dlg = new MessageDialog.Info(msg, desc, dispose);
- break;
- }
- dlg.startup();
- dlg.show();
- return dfd; // dojo.Deferred
- };
-
- pd.workingDialog = function(msg) {
- dlg = new MessageDialog.Working(msg);
- dlg.startup();
- dlg.show();
- return dlg;
- };
-
- pd.placeDiv = function(id, node){
- if (!dom.byId(id)){
- domConstruct.place("<div id='"+id+"'></div>", node);
- }
- };
-
- pd.convertToInnerHtml = function(str){
- if (str == null || str == undefined) {
- return null;
- }
-
- var elt = document.createElement("div");
- elt.innerHTML = str;
- return entities.decode(elt.innerHTML);
- };
-
- pd.showLogonDialog = function(){
- var pdLogonDialog = new bux.dialogs.LogonDialog({
- okHandler: function() {
- pdLogonDialog = null;
- },
- cancelHandler: function() {
- pdLogonDialog = null;
- }
- });
- pdLogonDialog.startup();
- pdLogonDialog.show();
- };
-
- pd.CAM_PASSPORT_ERROR = "camPassportError";
- pd.SERVER_NOT_AVAILABLE = "serverNotAvailable";
- pd.GENERAL_LOB_ERROR = "generalLobError";
-
- pd.parseResponse = function(/*Document|String*/response) {
- //Summary
- // this parser is expecting either a html/xml document or a html/xml markup generated from xts engine
- // It will retrieve the error code and error message, and use the errorPanel element if any as the details.
- if (!response) {
- throw new Error();
- }
- var markup = "";
- var errorPanel = null;
-
- if (dojo.isSafari){
- markup = response;
- var responseNode = domConstruct.toDom(response);
- if (responseNode.querySelector) {
- errorPanel = responseNode.querySelector("#errorPanel");
- }
- } else {
- if (typeof response == "string"){
- markup = response;
- var responseNode = domConstruct.toDom(response);
- if (responseNode.getElementById) {
- errorPanel = dom.byId("errorPanel", responseNode);
- }
- } else if (response.documentElement) {
- markup = response.documentElement.innerHTML;
- errorPanel = dom.byId("errorPanel", response);
- } else if (response.xml) {
- markup = response.xml;
- }
- }
-
- if (markup){
- function extractContent(content){
- var regExp = new RegExp("<.*?>", "i");
- var res = regExp.exec(content);
- if (res){
- var extractor = res[0];
- return content.substring(extractor.length, (content.length - extractor.length - 1));
- } else {
- return "";
- }
- }
-
- var errorList = [{
- errorCode: "<ERROR_CODE>SERVER_NOT_AVAILABLE</ERROR_CODE>",
- errorName: pd.SERVER_NOT_AVAILABLE,
- errorMessage: "<ERROR_MSG>.*?</ERROR_MSG>"
- },{
- errorCode: "<ERROR_CODE>CAM_PASSPORT_ERROR</ERROR_CODE>",
- errorName: pd.CAM_PASSPORT_ERROR
- },{
- errorCode: "<ERROR_CODE>CM-REQ-4159</ERROR_CODE>.*?CM-CAM-4005",
- errorName: pd.CAM_PASSPORT_ERROR
- },{
- errorCode: "<ERROR_CODE>.*?</ERROR_CODE>",
- errorName: pd.GENERAL_LOB_ERROR,
- errorMessage: "<ERROR_MSG>.*?</ERROR_MSG>"
- },{
- //bibus error handler
- errorCode: "<errorCode>.*?</errorCode>",
- errorName: pd.GENERAL_LOB_ERROR,
- errorMessage: "<messageString>.*?</messageString>"
- }];
-
- for (var i=0; i<errorList.length; i++){
- var pattCode = new RegExp(errorList[i].errorCode, "i");
- var resCode = pattCode.exec(markup);
- var pattMsg = new RegExp(errorList[i].errorMessage, "i");
- var resMsg = pattMsg.exec(markup);
- if (resCode){
- throw({
- name: errorList[i].errorName,
- message: extractContent(resCode[0]) +" "+ (resMsg?extractContent(resMsg[0]):""),
- detail: errorPanel?errorPanel.innerHTML:null
- });
- return;
- }
- }
- }
- };
- });
|