Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Globe.global.Util = {
- TRANSACTION_REDIRECTIONOTHER: "Page Redirection to other page/application",
- shortMonth: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
- getCookie: function (name) {
- var nameEQ = name + "=";
- var ca = document.cookie.split(';');
- for (var i = 0; i < ca.length; i++) {
- var c = ca[i];
- while (c.charAt(0) == ' ') c = c.substring(1, c.length);
- if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
- }
- return null;
- },
- setCookie: function (c_name, value, days) {
- if (!this.is_int(days)) {
- days = 365;
- }
- var exdate = new Date();
- exdate.setDate(exdate.getDate() + days);
- var c_value = value + "; expires=" + exdate.toUTCString() + "; path=/";
- document.cookie = c_name + "=" + c_value;
- },
- setCookieByHour: function (c_name, value, hours) {
- if (!this.is_int(hours)) {
- hours = 24;
- }
- var exdate = new Date();
- exdate.setHours(exdate.getHours() + hours);
- var c_value = value + "; expires=" + exdate.toUTCString() + "; path=/";
- document.cookie = c_name + "=" + c_value;
- },
- deleteCookie: function (name) {
- document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/;';
- },
- is_int: function (value) {
- if ((parseFloat(value) == parseInt(value)) && !isNaN(value)) {
- return true;
- } else {
- return false;
- }
- },
- parseDate: function (date) {
- var dateOut = '';
- if (date) {
- // fix for non-chrome browsers
- var dateString = date.replace(/-/g, "/");
- dateOut = new Date(dateString);
- }
- return dateOut;
- },
- parseFloat: function (value) {
- if (!isNaN(parseFloat(value))) {
- return parseFloat(value);
- }
- return 0;
- },
- getParameterByName: function (name) {
- name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
- var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
- results = regex.exec(location.search);
- return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
- },
- animateToId: function (id) {
- $('html, body').animate({scrollTop: $('#' + id).offset().top}, 'fast');
- },
- animateToTop: function () {
- $('html, body').animate({scrollTop: 0}, 'fast');
- },
- clickElem: function (id) {
- $('#' + id).click();
- },
- // http://stackoverflow.com/questions/1184624/convert-form-data-to-javascript-object-with-jquery
- serializeObject: function (form) {
- // form = $('#formId');
- var a = form.serializeArray();
- var o = {};
- $.each(a, function () {
- if (o[this.name] !== undefined) {
- if (!o[this.name].push) {
- o[this.name] = [o[this.name]];
- }
- o[this.name].push(this.value || '');
- } else {
- o[this.name] = this.value || '';
- }
- });
- return o;
- },
- setCacheFlag: function (name) {
- var _this = Globe.global.Util;
- // 1 day cache
- _this.setCookie(name, "usecache", 1);
- },
- useCache: function (name) {
- var _this = Globe.global.Util;
- // get value from cookie
- var cacheVal = _this.getCookie(name);
- if (cacheVal && cacheVal == "usecache") {
- return true;
- }
- return false;
- },
- /*
- * detect ie version
- * returns version of ie or false, if browser is not ie
- */
- detectIE: function () {
- var ua = window.navigator.userAgent,
- msie = ua.indexOf('MSIE ');
- if (msie > 0) {
- // IE 10 or older => return version number
- return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
- }
- var trident = ua.indexOf('Trident/');
- if (trident > 0) {
- // IE 11 => return version number
- var rv = ua.indexOf('rv:');
- return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
- }
- var edge = ua.indexOf('Edge/');
- if (edge > 0) {
- // IE 12 => return version number
- return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);
- }
- // other browser
- return false;
- },
- getErrorCode: function (errorList) {
- if (errorList) {
- // get first error's code
- var errorCode = errorList[0].code;
- return errorCode;
- }
- return "";
- },
- convertToCSV: function (objArray) {
- var array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray;
- var str = '';
- for (var i = 0; i < array.length; i++) {
- var line = '';
- for (var index in array[i]) {
- if (line != '') line += ','
- line += array[i][index];
- }
- str += line + '\r\n';
- }
- return str;
- },
- downloadCSV: function (formatJsonArr, fileName) {
- var _util = Globe.global.Util;
- var jsonObject = JSON.stringify(formatJsonArr);
- var a = document.createElement('a');
- a.href = 'data:application/csv,' + encodeURIComponent(Globe.global.Util.convertToCSV(jsonObject));
- a.target = '_jsonObject';
- a.download = fileName + '.csv';
- //a.click();
- _util.fireClick(a);
- //add to audit trail
- try {
- var auditTrailObj = Globe.webtools.AuditTrail;
- var tType = auditTrailObj.TRANSACTION_TYPE_REPORTS;
- var tDetails = auditTrailObj.getTransactionDetails(tType, 'transactions'); //key should be transactionName's page name
- var tAction = auditTrailObj.getTransactionAction(tDetails.action, {"fileName": a.download});
- var addTransactionParams = {
- "userId": "N/A",
- "transactionType": tType,
- "transactionName": tDetails.name,
- "action": tAction,
- }
- auditTrailObj.addTransaction(auditTrailObj.setWTTransactionUrl, addTransactionParams);
- } catch (e) {
- console.log("Add transaction to audit trail failed " + e);
- }
- },
- /**
- * Add MouseEvent handler to cater for scenario where browser does not support a.click()
- * i.e. Safari earlier versions
- */
- fireClick: function (node) {
- var isChrome = /Chrome/.test(navigator.userAgent);
- var isSafari = /Safari/.test(navigator.userAgent);
- var isFirefox = /Firefox/.test(navigator.userAgent);
- var isIE = /MSIE/.test(navigator.userAgent); //valid IE before IE11
- var isIE11Plus = /Trident.*rv[ :]*(\d+\.\d+)/.test(navigator.userAgent);
- var evt = document.createEvent('MouseEvents');
- evt.initEvent('click', true, false, window);
- if (isChrome) {
- node.click();
- } else if (isSafari) {
- if (/Windows/.test(navigator.userAgent)) {
- console.info("Detected Windows Safari.");
- if (document.createEvent) {
- node.dispatchEvent(evt);
- }
- } else {
- console.info("Detected Safari.");
- try {
- node.click();
- } catch (e) {
- if (document.createEvent) {
- node.dispatchEvent(evt);
- }
- }
- }
- } else if (isFirefox) {
- if (document.createEvent) {
- node.dispatchEvent(evt);
- }
- } else if (isIE || isIE11Plus) {
- console.info("Detected IE version less than 11.");
- var blob = new Blob([decodeURIComponent(node.href)], {
- type: "text/csv;charset=utf-8;"
- });
- navigator.msSaveBlob(blob, node.download);
- } else {
- console.info("Detected other browser");
- node.click();
- }
- },
- /**
- * Change Date format of Datepicker to ISO format
- *
- */
- changeDateFormat: function (dateElementName) {
- try {
- var evalStr = "$('input[name=\"" + dateElementName + "\"]').getDateIso();";
- var date = eval(evalStr);
- var evalStr2 = "document.getElementById(\'" + dateElementName + "\').value = date;";
- eval(evalStr2);
- //console.log("final date: " + date);
- } catch (e) {
- console.log("Cannot convert datepicker date format " + e);
- }
- },
- /**
- * Get Selected value from dropdown
- *
- */
- getSelectedDropdownValue: function (ulClass, elementId) {
- var a = ulClass + " li";
- var id = elementId;
- try {
- $(a).click(function () {
- var selectedOption = $(this).attr('value');
- document.getElementById(id).value = selectedOption;
- console.log(selectedOption);
- });
- } catch (e) {
- console.log("Error on getting selected dropdown value " + e);
- }
- },
- /**
- *
- * Author: Kyle Ohagan
- *
- * Method name: appendSuffixToDate
- *
- * Parameter: monthDayInt
- *
- * Description:
- * Accepts an integer which represents a Date's day.
- * Returns a string (the initial integer and the suffix) that can be displayed on the front end
- *
- */
- appendSuffixToDate: function (monthDayInt) {
- if (monthDayInt >= 11 && monthDayInt <= 13) {
- monthDayInt = monthDayInt + "th";
- } else {
- var temp = monthDayInt % 10;
- if (temp == 1) {
- monthDayInt = monthDayInt + "st";
- } else if (temp == 2) {
- monthDayInt = monthDayInt + "nd";
- } else if (temp == 3) {
- monthDayInt = monthDayInt + "rd";
- } else {
- monthDayInt = monthDayInt + "th";
- }
- }
- return monthDayInt;
- },
- /**
- * Redirect to the page with the Url passed in and add a transaction record for the redirection.
- *
- */
- pageRedirection: function (pageUrl, pageName, openNewWindow, transactionName) {
- var _this = Globe.global.Util;
- var _transaction = Globe.global.Transaction;
- if (pageUrl) {
- var actionParam = {};
- /* If no transaction name is specified or
- redirected to a page which is not listed in Transaction Type */
- if (!transactionName || transactionName == _this.TRANSACTION_REDIRECTIONOTHER) {
- transactionName = _this.TRANSACTION_REDIRECTIONOTHER;
- if (pageName) {
- actionParam.pageName = pageName;
- }
- else {
- actionParam.pageName = pageUrl;
- }
- }
- var transaction = _transaction.getTransactionDetails(transactionName, actionParam);
- transaction.referenceId = "";
- transaction.processType = "";
- _transaction.addTransaction(transaction);
- window.open(pageUrl, openNewWindow ? '_blank' : '_top');
- }
- },
- recontractRedirect: function (pageUrl, pageName, openNewWindow, transactionName, getOmniTokenURL) {
- var _ccUtil = Globe.global.ClientContextUtil;
- var accountInfoStoreMgr = _ccUtil.getAccountInfoStoreMgr();
- var profileInfoStoreMgr = _ccUtil.getProfileInfoStoreMgr();
- var userId = profileInfoStoreMgr.get("userId");
- var activeAccount = accountInfoStoreMgr.getActiveAccount();
- var serviceNumber = activeAccount.serviceNumber;
- console.log("pageUrl - " + pageUrl);
- if (pageUrl) {
- var actionParam = {};
- /* If no transaction name is specified or
- redirected to a page which is not listed in Transaction Type */
- if (!transactionName || transactionName == _this.TRANSACTION_REDIRECTIONOTHER) {
- transactionName = _this.TRANSACTION_REDIRECTIONOTHER;
- if (pageName) {
- actionParam.pageName = pageName;
- }
- else {
- actionParam.pageName = pageUrl;
- }
- }
- var transaction = _transaction.getTransactionDetails(transactionName, actionParam);
- transaction.referenceId = "";
- transaction.processType = "";
- _transaction.addTransaction(transaction);
- }
- },
- addTransactionHist: function (transactionName, actionParam) {
- var _transaction = Globe.global.Transaction;
- var transaction = _transaction.getTransactionDetails(transactionName, actionParam);
- transaction.referenceId = "";
- transaction.processType = "";
- _transaction.addTransaction(transaction);
- },
- // Checking for null value for different browsers ( different browsers shows different null values
- // Author : Davin Jaya
- isNull: function (arg) {
- if (arg == 'NaN' || arg == 'undefined' || arg == undefined || arg == '' || arg == null) {
- return "";
- }
- else {
- return arg;
- }
- },
- //replace all svgs with a temp canvas
- convertSvgToCanvas: function (svgElements) {
- svgElements.each(function (index) {
- var canvas, xml;
- // canvg doesn't cope very well with em font sizes so find the calculated size in pixels and replace it in the element.
- $.each($(this).find('[style*=em]'), function (index, el) {
- $(this).css('font-size', getStyle(el, 'font-size'));
- });
- canvas = document.createElement("canvas");
- canvas.className = "screenShotTempCanvas";
- //convert SVG into a XML string
- xml = (new XMLSerializer()).serializeToString(this);
- // Removing the name space as IE throws an error
- xml = xml.replace(/xmlns=\"http:\/\/www\.w3\.org\/2000\/svg\"/, '');
- //draw the SVG onto a canvas
- canvg(canvas, xml);
- $(canvas).insertAfter(this);
- //hide the SVG element
- $(this).attr('class', 'tempHide');
- $(this).hide();
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement