var HoGoUtils = (function ($) { var country = new Array("United States", "Canada"); var state = new Array(); state["Canada"] = "Alberta|British Columbia|Manitoba|New Brunswick|Newfoundland|Northwest Territories|Nova Scotia|Nunavut|Ontario|Prince Edward Island|Quebec|Saskatchewan|Yukon Territory"; state["United States"] = "Alabama|Alaska|Arizona|Arkansas|California|Colorado|Connecticut|Delaware|District of Columbia|Florida|Georgia|Hawaii|Idaho|Illinois|Indiana|Iowa|Kansas|Kentucky|Louisiana|Maine|Maryland|Massachusetts|Michigan|Minnesota|Mississippi|Missouri|Montana|Nebraska|Nevada|New Hampshire|New Jersey|New Mexico|New York|North Carolina|North Dakota|Ohio|Oklahoma|Oregon|Pennsylvania|Rhode Island|South Carolina|South Dakota|Tennessee|Texas|Utah|Vermont|Virginia|Washington|West Virginia|Wisconsin|Wyoming"; /** * Make buttons * @param {type} type : {1 : Enable | 2: Disable} * @param {type} selector * @param {type} opts : {colorClass: class will be change, isArrow : button is arrow or not, isSubmitForm : this is submit or not, handler: function will be execute or nor, textInsde : text will be changed} * @returns {undefined} */ function makeButton(type, selector, opts) { var _this = $(selector); switch (type) { case 1: // Enable // Remove grey class _this.removeClass('grey'); // Arrow button or not if (typeof opts.isArrow !== 'undefined' && opts.isArrow === true) { _this.removeClass('grey-fw'); } if (typeof opts.colorClass !== 'undefined' && opts.colorClass !== null) { _this.addClass(opts.colorClass); if (typeof opts.isArrow !== 'undefined' && opts.isArrow === true) { _this.addClass(opts.colorClass + '-fw'); } } else { // Default color _this.addClass('orange'); } _this.unbind('click', false); // Remove handler if (typeof opts.isSubmitForm !== 'undefined' && opts.isSubmitForm === true) { // Unbind all then bind _this.addClass('submit_form').unbind('click').bind('click', function () { var fID = opts.formID; if (typeof fID !== 'undefined' && fID !== '' && fID !== null) { $("#" + fID).submit(); } else { fID = $(this).parents('form').attr('id'); $("#" + fID).submit(); } }); } //else { var handler = opts.handler; if (typeof handler !== 'undefined' && handler !== '' && handler !== null) { //Remove all bind click first _this.unbind('click').bind('click', handler); } //} //Set text inside the button var textInside = opts.textInside; if (typeof textInside !== 'undefined' && textInside !== null) { _this.html(textInside); } break; case 2: // Disable // Remove current color var colorClass = opts.colorClass; _this.addClass('grey'); if (typeof colorClass !== 'undefined' && colorClass !== null) { _this.removeClass(colorClass); if (typeof opts.isArrow !== 'undefined' && opts.isArrow === true) { _this.removeClass(colorClass + '-fw'); _this.addClass('grey-fw'); } } else { // Default color be removed if (_this.hasClass('orange')) _this.removeClass('orange'); if (_this.hasClass('green')) _this.removeClass('green'); } //Remove hanlder if (_this.hasClass('submit_form')) { _this.removeClass('submit_form'); } var handler = opts.handler; if (typeof handler !== 'undefined' && handler !== '' && handler !== null) { _this.unbind('click', handler).unbind('click'); } else { // Remove all handler _this.unbind('click'); } _this.bind('click', false); // Set text inside the button var textInside = opts.textInside; if (typeof textInside !== 'undefined' && textInside !== null) { _this.text(textInside); } break; default: break; } } return { // Pattern match email patternEmail: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/, /** * Check valid email base on regrex in validationEngine * @param {type} email * @returns {Boolean} */ isValidEmail: function (email) { return this.patternEmail.test(email); }, /** * Check valid list email string which is separated by comma (,) * @param {type} gEmail concated string email * @returns {Boolean} */ isValidGroupEmail: function (gEmail) { var array = gEmail.split(','); for (var i = 0; i < array.length; i++) { if (this.patternEmail.test($.trim(array[i])) === false) { return false; } } return true; }, /** * Message-Digest algorithm 5 (MD5) * @param {type} string * @returns {unresolved} */ MD5: function (string) { function RotateLeft(lValue, iShiftBits) { return (lValue << iShiftBits) | (lValue >>> (32 - iShiftBits)); } function AddUnsigned(lX, lY) { var lX4, lY4, lX8, lY8, lResult; lX8 = (lX & 0x80000000); lY8 = (lY & 0x80000000); lX4 = (lX & 0x40000000); lY4 = (lY & 0x40000000); lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF); if (lX4 & lY4) { return (lResult ^ 0x80000000 ^ lX8 ^ lY8); } if (lX4 | lY4) { if (lResult & 0x40000000) { return (lResult ^ 0xC0000000 ^ lX8 ^ lY8); } else { return (lResult ^ 0x40000000 ^ lX8 ^ lY8); } } else { return (lResult ^ lX8 ^ lY8); } } function F(x, y, z) { return (x & y) | ((~x) & z); } function G(x, y, z) { return (x & z) | (y & (~z)); } function H(x, y, z) { return (x ^ y ^ z); } function I(x, y, z) { return (y ^ (x | (~z))); } function FF(a, b, c, d, x, s, ac) { a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac)); return AddUnsigned(RotateLeft(a, s), b); } ; function GG(a, b, c, d, x, s, ac) { a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac)); return AddUnsigned(RotateLeft(a, s), b); } ; function HH(a, b, c, d, x, s, ac) { a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac)); return AddUnsigned(RotateLeft(a, s), b); } ; function II(a, b, c, d, x, s, ac) { a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac)); return AddUnsigned(RotateLeft(a, s), b); } ; function ConvertToWordArray(string) { var lWordCount; var lMessageLength = string.length; var lNumberOfWords_temp1 = lMessageLength + 8; var lNumberOfWords_temp2 = (lNumberOfWords_temp1 - (lNumberOfWords_temp1 % 64)) / 64; var lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16; var lWordArray = Array(lNumberOfWords - 1); var lBytePosition = 0; var lByteCount = 0; while (lByteCount < lMessageLength) { lWordCount = (lByteCount - (lByteCount % 4)) / 4; lBytePosition = (lByteCount % 4) * 8; lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount) << lBytePosition)); lByteCount++; } lWordCount = (lByteCount - (lByteCount % 4)) / 4; lBytePosition = (lByteCount % 4) * 8; lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80 << lBytePosition); lWordArray[lNumberOfWords - 2] = lMessageLength << 3; lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29; return lWordArray; } ; function WordToHex(lValue) { var WordToHexValue = "", WordToHexValue_temp = "", lByte, lCount; for (lCount = 0; lCount <= 3; lCount++) { lByte = (lValue >>> (lCount * 8)) & 255; WordToHexValue_temp = "0" + lByte.toString(16); WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length - 2, 2); } return WordToHexValue; } ; function Utf8Encode(string) { string = string.replace(/\r\n/g, "\n"); var utftext = ""; for (var n = 0; n < string.length; n++) { var c = string.charCodeAt(n); if (c < 128) { utftext += String.fromCharCode(c); } else if ((c > 127) && (c < 2048)) { utftext += String.fromCharCode((c >> 6) | 192); utftext += String.fromCharCode((c & 63) | 128); } else { utftext += String.fromCharCode((c >> 12) | 224); utftext += String.fromCharCode(((c >> 6) & 63) | 128); utftext += String.fromCharCode((c & 63) | 128); } } return utftext; } ; var x = Array(); var k, AA, BB, CC, DD, a, b, c, d; var S11 = 7, S12 = 12, S13 = 17, S14 = 22; var S21 = 5, S22 = 9, S23 = 14, S24 = 20; var S31 = 4, S32 = 11, S33 = 16, S34 = 23; var S41 = 6, S42 = 10, S43 = 15, S44 = 21; string = Utf8Encode(string); x = ConvertToWordArray(string); a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476; for (k = 0; k < x.length; k += 16) { AA = a; BB = b; CC = c; DD = d; a = FF(a, b, c, d, x[k + 0], S11, 0xD76AA478); d = FF(d, a, b, c, x[k + 1], S12, 0xE8C7B756); c = FF(c, d, a, b, x[k + 2], S13, 0x242070DB); b = FF(b, c, d, a, x[k + 3], S14, 0xC1BDCEEE); a = FF(a, b, c, d, x[k + 4], S11, 0xF57C0FAF); d = FF(d, a, b, c, x[k + 5], S12, 0x4787C62A); c = FF(c, d, a, b, x[k + 6], S13, 0xA8304613); b = FF(b, c, d, a, x[k + 7], S14, 0xFD469501); a = FF(a, b, c, d, x[k + 8], S11, 0x698098D8); d = FF(d, a, b, c, x[k + 9], S12, 0x8B44F7AF); c = FF(c, d, a, b, x[k + 10], S13, 0xFFFF5BB1); b = FF(b, c, d, a, x[k + 11], S14, 0x895CD7BE); a = FF(a, b, c, d, x[k + 12], S11, 0x6B901122); d = FF(d, a, b, c, x[k + 13], S12, 0xFD987193); c = FF(c, d, a, b, x[k + 14], S13, 0xA679438E); b = FF(b, c, d, a, x[k + 15], S14, 0x49B40821); a = GG(a, b, c, d, x[k + 1], S21, 0xF61E2562); d = GG(d, a, b, c, x[k + 6], S22, 0xC040B340); c = GG(c, d, a, b, x[k + 11], S23, 0x265E5A51); b = GG(b, c, d, a, x[k + 0], S24, 0xE9B6C7AA); a = GG(a, b, c, d, x[k + 5], S21, 0xD62F105D); d = GG(d, a, b, c, x[k + 10], S22, 0x2441453); c = GG(c, d, a, b, x[k + 15], S23, 0xD8A1E681); b = GG(b, c, d, a, x[k + 4], S24, 0xE7D3FBC8); a = GG(a, b, c, d, x[k + 9], S21, 0x21E1CDE6); d = GG(d, a, b, c, x[k + 14], S22, 0xC33707D6); c = GG(c, d, a, b, x[k + 3], S23, 0xF4D50D87); b = GG(b, c, d, a, x[k + 8], S24, 0x455A14ED); a = GG(a, b, c, d, x[k + 13], S21, 0xA9E3E905); d = GG(d, a, b, c, x[k + 2], S22, 0xFCEFA3F8); c = GG(c, d, a, b, x[k + 7], S23, 0x676F02D9); b = GG(b, c, d, a, x[k + 12], S24, 0x8D2A4C8A); a = HH(a, b, c, d, x[k + 5], S31, 0xFFFA3942); d = HH(d, a, b, c, x[k + 8], S32, 0x8771F681); c = HH(c, d, a, b, x[k + 11], S33, 0x6D9D6122); b = HH(b, c, d, a, x[k + 14], S34, 0xFDE5380C); a = HH(a, b, c, d, x[k + 1], S31, 0xA4BEEA44); d = HH(d, a, b, c, x[k + 4], S32, 0x4BDECFA9); c = HH(c, d, a, b, x[k + 7], S33, 0xF6BB4B60); b = HH(b, c, d, a, x[k + 10], S34, 0xBEBFBC70); a = HH(a, b, c, d, x[k + 13], S31, 0x289B7EC6); d = HH(d, a, b, c, x[k + 0], S32, 0xEAA127FA); c = HH(c, d, a, b, x[k + 3], S33, 0xD4EF3085); b = HH(b, c, d, a, x[k + 6], S34, 0x4881D05); a = HH(a, b, c, d, x[k + 9], S31, 0xD9D4D039); d = HH(d, a, b, c, x[k + 12], S32, 0xE6DB99E5); c = HH(c, d, a, b, x[k + 15], S33, 0x1FA27CF8); b = HH(b, c, d, a, x[k + 2], S34, 0xC4AC5665); a = II(a, b, c, d, x[k + 0], S41, 0xF4292244); d = II(d, a, b, c, x[k + 7], S42, 0x432AFF97); c = II(c, d, a, b, x[k + 14], S43, 0xAB9423A7); b = II(b, c, d, a, x[k + 5], S44, 0xFC93A039); a = II(a, b, c, d, x[k + 12], S41, 0x655B59C3); d = II(d, a, b, c, x[k + 3], S42, 0x8F0CCC92); c = II(c, d, a, b, x[k + 10], S43, 0xFFEFF47D); b = II(b, c, d, a, x[k + 1], S44, 0x85845DD1); a = II(a, b, c, d, x[k + 8], S41, 0x6FA87E4F); d = II(d, a, b, c, x[k + 15], S42, 0xFE2CE6E0); c = II(c, d, a, b, x[k + 6], S43, 0xA3014314); b = II(b, c, d, a, x[k + 13], S44, 0x4E0811A1); a = II(a, b, c, d, x[k + 4], S41, 0xF7537E82); d = II(d, a, b, c, x[k + 11], S42, 0xBD3AF235); c = II(c, d, a, b, x[k + 2], S43, 0x2AD7D2BB); b = II(b, c, d, a, x[k + 9], S44, 0xEB86D391); a = AddUnsigned(a, AA); b = AddUnsigned(b, BB); c = AddUnsigned(c, CC); d = AddUnsigned(d, DD); } var temp = WordToHex(a) + WordToHex(b) + WordToHex(c) + WordToHex(d); return temp.toLowerCase(); }, /** * Generate ID * @returns {String} ID */ createUUID: function () { return "xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g, function (d) { var b = Math.random() * 16 | 0, a = d === "x" ? b : (b & 3 | 8); return a.toString(16); }); }, /** * Detect browser language. Now we just support two language so that if finding a language which isn't two that language, it'll return language default (en) * @returns {string} */ detectBrowserLang: function () { var lang = window.navigator.browserLanguage || window.navigator.language; // Language code: http://4umi.com/web/html/languagecodes.php || http://msdn.microsoft.com/en-us/library/ie/ms533052.aspx var language = lang.substr(0, 2); switch (language) { case 'en': case 'ja': return language; break; default: return HoGoConst.LANG_DEFAULT; break; } }, /** * Format string number to number format. For example: 2000 => 2,000 * @param {type} nStr : string number * @returns {String} */ formatNumber: function (nStr) { nStr += ''; var x = nStr.split('.'); var x1 = x[0]; var x2 = x.length > 1 ? '.' + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2'); } return x1 + x2; }, /* Convert cent to $ or free and format number * @param {number} cent The cent number * @return {string} $ */ convertMoneyFomat: function (cent, currency) { if (cent !== undefined) { if (cent === 0) return "0"; else { if (currency === 'YEN') { return "¥" + this.formatNumber(cent); } else { var usd = "$" + this.formatNumber(cent / 100); return usd; } } } else return ""; }, /** * Make a notify for user after server change somthing * @param {type} msg * @returns {undefined} */ makeNotifyServer: function (opt) { var setting = opt || {}, action; // Content var bar = $('#notify-wrapper'); if (typeof opt !== 'object') { action = opt.trim(); if (action === 'hide') { bar.fadeOut(); } } else { // Default options var defaults = {autoClose: true, msg: "", time: 3000}; var option = $.extend(defaults, setting); if (bar.length === 0) { var html = '
' + '' + '' + option.msg + '' + '
'; $(html).insertBefore('#container'); } else { bar.find('#notify-msg').text(option.msg); bar.show(); } if (option.autoClose) { //Hide after timeout setTimeout("$('#notify-wrapper').fadeOut();", option.time); // 3s } else { // Do something here } } }, /** * Get current page name * @returns {String} */ getPageName: function () { var aParts = window.location.pathname.split('/'), sNameEQ = aParts[aParts.length - 1].replace(/[\/:]/g, "").toLowerCase(); var pageName = ""; if (window.location.pathname.indexOf("admin") !== -1){ // Admin login page pageName = "administrator.html"; }else{ if (sNameEQ.indexOf(".html") !== -1) pageName = sNameEQ; else { if (sNameEQ.indexOf(".htm") !== -1) { pageName = sNameEQ + "l"; // .htm => .html } else pageName = sNameEQ + ".html"; } } return pageName; }, /** * Get value of specific param. Example: /pagename?name=tmhao#/child => return * @returns {Array} */ getParameter: function () { var vars = [], hash; var path = window.location.href.slice(window.location.href.indexOf('?') + 1); var rPath = path; // Remove hash if have if (path.indexOf(location.hash)) { rPath = path.substring(0, path.indexOf(location.hash)); } var hashes = rPath.split('&'); for (var i = 0; i < hashes.length; i++) { hash = hashes[i].split('='); vars.push(hash[0]); vars[hash[0]] = hash[1]; } return vars; }, /** * Enable button * @param {type} selector * @param {type} opts : {colorClass (required), isSubmitForm (optional), handler (required if isSubmitForm is false or not specify), isArrow (optional - default: none) textInside (optional)} * @returns {undefined} */ enableButton: function (selector, opts) { makeButton(1, selector, opts); }, /** * Disable buttons * @param {type} selector * @param {type} opts {colorClass (required), isArrow (optional - default: none), textInside (optional)} * @returns {undefined} */ disableButton: function (selector, opts) { makeButton(2, selector, opts); }, /** * Validate form ID and set status to status param * @param {type} formID * @param {object} obj : This object contains a variable name 'fStatus' * @returns {undefined} */ validateForm: function (formID, obj, opts) { // Some opts var position = "topRight"; // Default if (typeof opts === 'object') { position = (opts.position) ? opts.position : position; } $('form#' + formID).validationEngine({ scroll: false, validationEventTrigger: "", promptPosition: position, onValidationComplete: function (form, status) { if (typeof obj !== 'undefined') { obj.fStatus = status; } else { formStatus = status; } } }); }, /** * Show our custom scrollbar * @param {type} selector * @returns {undefined} */ showScrollBar: function (selector) { if ($(selector)) { var e = $(selector); e.mCustomScrollbar({ //autoHideScrollbar: true, advanced: { updateOnContentResize: true } }); } }, /** * Show calendar and call action callback * @param {type} json * @returns {undefined} */ showDatePicker: function (json) { $('#' + json.input_id).datepicker({ autoSize: true, //appendText: '(mm/dd/yyyy)', dateFormat: 'mm/dd/yy', beforeShow: function () { if (typeof json.radio_id !== 'undefined') { $('#' + json.radio_id).prop('checked', true).trigger('click'); } }, onSelect: function () { // Hide placeholder IE9 if (typeof json.radio_id !== 'undefined') { $('label[for=' + json.input_id + ']').hide(); } // Callback after on select if (typeof json.callback !== 'undefined') { // Execute function json.callback(); } } // onClose: function() { // $(this).trigger('blur'); // } }); }, /** * Cheking flash install on user's browser or not * @returns {Boolean} */ checkFlashInstall: function () { var support = false; //IE only if (navigator.appVersion.indexOf("MSIE") !== -1) { try { var flashObj = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"); if (flashObj !== null) support = true; } catch (e) { support = false; } //W3C, better support in legacy browser } else { if (navigator.mimeTypes ["application/x-shockwave-flash"] !== 'undefined') support = true; } return support; }, /** * Redirect to buy point * @returns {undefined} */ goBuyPoint: function () { //Get url var loc = window.location; var lpath = loc.pathname.split('/'); var pagename = lpath[lpath.length - 1].replace(/[\/:]/g, ""); var path = pagename + loc.search + loc.hash; //Redirect window.location.href = "BuyPoint?returnPath=" + path; }, /** * Determine action when user's session timeout * @param {string} data : Data return from API * @param {string} textError : Error text will be shown in case of showing popup * @param {string} pageRedirect : Page name will be redirected to if there's not case of timeout */ fnSessionTimeout: function (data, textError, pageRedirect) { if (data.status === APIConst.sessionIdNotFound || data.status === APIConst.adminSessionRequired) { // Remove before unload handler window.onbeforeunload = null; window.location.href = 'login'; } else { if (typeof pageRedirect !== 'undefined') { window.location.href = pageRedirect; } else { if (typeof textError === 'undefined' || textError === null || textError === "") { Modal.showAlert({content: i18n.t('error.unknown')}); } else { Modal.showAlert({content: textError}); } } } }, disableCalendar: function (idInputCalendar, classCheckValidate) { if (typeof idInputCalendar !== 'undefined' && typeof classCheckValidate !== 'undefined') { $('#' + idInputCalendar).removeClass(classCheckValidate).val(''); // Disable placeholder $('label[for=' + idInputCalendar + ']').css('display', 'block'); // Clear error is displaying $('.' + idInputCalendar + 'formError').remove(); } }, enableCalendar: function (idInputCalendar, classCheckValidate) { if (typeof idInputCalendar !== 'undefined' && typeof classCheckValidate !== 'undefined') { $('#' + idInputCalendar).val('').addClass(classCheckValidate); $('label[for=' + idInputCalendar + ']').hide(); } }, /** * Create list options for select tag with set of countries * @param {type} countryID The select ID tag * @returns {undefined} */ getListCountry: function (countryID) { var option = $('#' + countryID)[0]; option.length = 0; option.selectedIndex = 0; for (var i = 0; i < country.length; i++) { option.options[option.length] = new Option(country[i], country[i]); } }, /** * Create list state for select tag with set of state * @param {type} stateID The select ID tag * @param {type} stateName State will be indexed * @returns {undefined} */ getListState: function (stateID, stateName) { var option = $('#' + stateID)[0]; option.length = 0; option.selectedIndex = 0; var state_arr = state[stateName].split("|"); for (var i = 0; i < state_arr.length; i++) { option.options[option.length] = new Option(state_arr[i], state_arr[i]); } }, /** * Center an elemenet * @param {type} e : jQuery object * @returns {undefined} */ centerElemlent: function (e) { var $self = e; //get the dimensions using dimensions plugin var width = $self.width(); var height = $self.height(); //get the paddings var paddingTop = parseInt($self.css("padding-top")); var paddingBottom = parseInt($self.css("padding-bottom")); //get the borders var borderTop = parseInt($self.css("border-top-width")); var borderBottom = parseInt($self.css("border-bottom-width")); //get the media of padding and borders var mediaBorder = (borderTop + borderBottom) / 2; var mediaPadding = (paddingTop + paddingBottom) / 2; //get the type of positioning // var positionType = $self.parent().css("position"); // get the half minus of width and height var halfWidth = (width / 2) * (-1); var halfHeight = ((height / 2) * (-1)) - mediaPadding - mediaBorder; // initializing the css properties var cssProp = { position: 'fixed' }; //Set display in font any element cssProp["z-index"] = 100; // cssProp.height = height; cssProp.top = '50%'; cssProp.marginTop = halfHeight; // cssProp.width = width; cssProp.left = '50%'; cssProp.marginLeft = halfWidth; //check the current position // if (positionType === 'static') { // $self.parent().css("position", "relative"); // } //aplying the css $self.css(cssProp); }, /** * Create a loading bar center of a page * @returns {$} */ createLoadingBar: function () { $('
LOADING...
').appendTo('body'); var p = $('.hg-processing'); this.centerElemlent(p); return p; }, /** * Copy to clipboard action * @param {type} btnSelector : Button copy * @returns {undefined} */ copyLink: function (btnSelector) { // Check flash install or not if (ClientInfo.checkFlashPlayerInstall()) { //Checking flash var client = new ZeroClipboard($(btnSelector), { moviePath: "Images/ZeroClipboard.swf" }); // Loaded client.on("load", function (client) { client.on("complete", function (client, args) { if (args.text !== "") { // Make a notify HoGoUtils.makeNotifyServer({ "msg": i18n.t('notification.link_copied.content'), "autoClose": true, "time": 400 }) } }); }); } else { //Notify the flash not installed Modal.showAlert({ title: i18n.t('notification.flash_not_installed.title'), content: i18n.t('notification.flash_not_installed.content') }); } }, /** * Manage actions on whole page * @param {type} pName * @returns {undefined} */ manageActionsOnPage: function (pName) { switch (pName) { // SendWizard context case 'sendwizard.html': var sMenu = $("#sendWinzardMenuDiv"); var step = HoGoUtils.getParameter()["step"]; sMenu.find('i.header-sprites').removeClass('icon-menu-send').addClass('icon-menu-send-active'); sMenu.find('span').css('color', '#077194'); if (step !== '4Link' && step !== '5') { // step = 1, 2, 3 sMenu.find('a').removeAttr('href').css('cursor', 'default'); } break; // Addressbook context case 'addressbooklist.html': case 'addrecipient.html': case 'recipientdetail.html': var rMenu = $("#addressbookMenuDiv"); rMenu.find('.header-sprites').removeClass('icon-menu-addressbook').addClass('icon-menu-addressbook-active'); rMenu.find('span').css('color', '#077194'); if (pName === 'addressbooklist.html') { rMenu.find('a').removeAttr('href'); // Refresh list rMenu.find('a').bind('click', function () { AddressBook.getTableList().fnDraw(); }); } break; // Document context case 'mydocumentlist.html': case 'adddocument.html': case 'mydocumentdetail.html': // Document page var dMenu = $("#mydocumentMenuDiv"); dMenu.find('i.header-sprites').removeClass('icon-menu-documents').addClass('icon-menu-documents-active'); dMenu.find('span').css('color', '#077194'); // Remove only this page if (pName === 'mydocumentlist.html') { dMenu.find('a').removeAttr('href'); // Refresh list dMenu.find('a').bind('click', function () { MyDocument.getTable().fnDraw(); }); } break; // History context case 'history.html': case 'packagedetaildownload.html': case 'packagedetaillink.html': var hMenu = $("#historyMenuDiv"); hMenu.find('i.header-sprites').removeClass('icon-menu-history').addClass('icon-menu-history-active'); hMenu.find('span').css('color', '#077194'); if (pName === 'history.html') { hMenu.find('a').removeAttr('href'); // Refresh list hMenu.find('a').bind('click', function () { History.getTableList().fnDraw(); }); } break; } }, /** * Make an IP request * @returns {jqXHR} */ makeIPRequset: function () { return $.ajax({ type: 'GET', url: 'api/v1/GetCountryCode', //-- We use this api as a free service dataType: 'json', timeout: HoGoConst.EXTERNAL_TIMEOUT // 1 min }); }, /** * * @param {type} page * @param {type} lang * @returns {undefined} */ renderNameBaseLang: function (page, lang) { console.log(page); switch (page) { case 'myaccount.html': { // Render view depend user's country var tblAccount = $('table#tbAccountInfo'); var accountForm = $('div#accountInfo'); switch (lang) { case 'ja': case 'vi': // First Name tblAccount.find('tr:eq(0)').replaceWith('' + '
' + i18n.t('myaccount.account_info.info.last_name') + '
' + '' + ''); // Middle Name tblAccount.find('tr:eq(1)').hide(); // Last Name tblAccount.find('tr:eq(2)').replaceWith('' + '
' + i18n.t('myaccount.account_info.info.first_name') + '
' + '' + ''); accountForm.find('div#cFirstName').insertAfter(accountForm.find('div#cLastName')); accountForm.find('div#cMiddleName').hide(); break; default: // First Name tblAccount.find('tr:eq(0)').replaceWith('' + '
' + i18n.t('myaccount.account_info.info.first_name') + '
' + '' + ''); // Middle Name tblAccount.find('tr:eq(1)').show(); // Last Name tblAccount.find('tr:eq(2)').replaceWith('' + '
' + i18n.t('myaccount.account_info.info.last_name') + '
' + '' + ''); accountForm.find('div#cMiddleName').show(); accountForm.find('div#cFirstName').insertBefore(accountForm.find('div#cMiddleName')); accountForm.find('div#cLastName').insertAfter(accountForm.find('div#cMiddleName')); break; } break; } case 'signup.html': { // Render view depend user's country var signupForm = $('div.form-signup form'); switch (lang) { case 'ja': case 'vi': // First Name signupForm.find('div:eq(0)').replaceWith('
' + '
' + '
' + '
'); // Last Name signupForm.find('div:eq(3)').replaceWith('
' + '
' + '
' + '
'); break; default: // First Name signupForm.find('div:eq(0)').replaceWith('
' + '' + '
' + '
' + '
'); // console.log(signupForm.find('div:eq(1)'), " cai quan que"); // Last Name signupForm.find('div:eq(3)').replaceWith('
' + '
' + '
' + '
'); break; } break; } case 'recipientdetail.html': case 'addrecipient.html': { // Render view depend user's country var tblAccount = $('table.info'); switch (lang) { case 'ja': case 'vi': $('#contents').find('div#dvMiddleName').hide(); $('#contents').find('div#dvFirstName').insertAfter($('#contents').find('div#dvLastName')); break; default: $('#contents').find('div#dvMiddleName').show(); $('#contents').find('div#dvFirstName').insertBefore($('#contents').find('div#dvMiddleName')); $('#contents').find('div#dvLastName').insertAfter($('#contents').find('div#cMiddleName')); break; } break; } case 'admininformation.html': case 'companydetail.html': case 'distributoradmininformation.html': case 'adddistributor.html': case 'userdetail.html': case 'adduser.html': case 'distributordetail.html': { // Render view depend user's country var accountForm = $('div#accountInfo'); switch (lang) { case 'ja': case 'vi': accountForm.find('div#cFirstName').insertAfter(accountForm.find('div#cLastName')); accountForm.find('div#cMiddleName').hide(); if (page === 'distributoradmininformation.html') { var compNum = accountForm.find('div#numberComps'); compNum.find('.key').removeClass('col-md-4').addClass('col-md-3'); compNum.insertAfter(accountForm.find('div#compName')); } break; default: accountForm.find('div#cMiddleName').show(); accountForm.find('div#cFirstName').insertBefore(accountForm.find('div#cMiddleName')); accountForm.find('div#cLastName').insertAfter(accountForm.find('div#cMiddleName')); if (page === 'distributoradmininformation.html') { var compNum = accountForm.find('div#numberComps'); compNum.find('.key').removeClass('col-md-3').addClass('col-md-4'); compNum.insertAfter(accountForm.find('div#dvCreateDate')); } break; } // rerender dropdown multi select $('#ddBillingCycles').multipleSelect('refresh', { selectAllText: i18n.t('myaccount.billing_cycle.select_all_text'), allSelected: i18n.t('myaccount.billing_cycle.all_selected'), countSelected: i18n.t('myaccount.billing_cycle.count_selected'), noMatchesFound: i18n.t('myaccount.billing_cycle.no_matches_found') }); break; } //check case 'signupcom.html': { var accountForm = $('div#accountInfo'); switch (lang) { case 'ja': case 'vi': accountForm.find('div#cFirstName').insertAfter(accountForm.find('div#cLastName')); break; default: accountForm.find('div#cFirstName').insertBefore(accountForm.find('div#cLastName')); break; } break; } case 'addservice.html': { var accountForm = $('div#accountInfo'); switch (lang) { case 'ja': case 'vi': // First Name accountForm.find('div#cFirstName').replaceWith('
' + '' + '
'); //middle name accountForm.find('div#cMiddleName').hide(); // Last Name accountForm.find('div#cLastName').replaceWith('
' + '' + '
'); break; default: // Last Name accountForm.find('div#cLastName').replaceWith('
' + '' + '
'); //middle name accountForm.find('div#cMiddleName').hide(); // First Name accountForm.find('div#cFirstName').replaceWith('
' + '' + '
'); break; } break; } } }, /** * Write log message if user's browser supports console * @param {type} message * @returns {undefined} */ writeLog: function (message) { if (typeof console !== 'undefined') { // console.log(message); } }, /** * Parse history code to meaningfultext * @param {type} historyType * @returns {String} */ parseHistoryTypeToText: function (historyType) { switch (historyType) { //405 case HoGoConst.DIRECT_SEND_TYPE: return i18n.t('history.event.send_direct_type'); //406 case HoGoConst.CREATE_LINK_NONDOWNLOAD_TYPE: return i18n.t('history.event.create_link_nondownload_type'); //407 case HoGoConst.CREATE_LINK_DOWNLOAD_TYPE: return i18n.t('history.event.create_link_download_type'); //411 case HoGoConst.LINK_SPECIFY_CREATED_TYPE: return i18n.t('history.event.create_link_specify_recipient'); //412 case HoGoConst.LINK_ANONYMOUS_CREATED_TYPE: return i18n.t('history.event.create_link_anonymous'); //408 case HoGoConst.PURCHASE_POINTS_TYPE: return i18n.t('history.event.package_purchase_type'); //504 case HoGoConst.ADMIN_REFUND_TYPE: return i18n.t('history.event.admin_refund_type'); //505 case HoGoConst.ADMIN_ADD_POINTS: return i18n.t('history.event.package_recieve_type'); //403 -- Login case HoGoConst.LOGIN_TYPE: return i18n.t('history.event.user_login_type'); //404 -- Logout case HoGoConst.LOGOUT_TYPE: return i18n.t('history.event.user_logout_type'); //604 -- Link expired case HoGoConst.LINK_EXPIRED_TYPE: return i18n.t('history.event.link_expired_type'); //603 -- Document expired case HoGoConst.DOCUMENT_EXPIRED_TYPE: return i18n.t('history.event.document_expired_type'); //200 -- Document added case HoGoConst.DOCUMENT_ADDED_TYPE: return i18n.t('history.event.add_document_type'); //202 -- Document deleted case HoGoConst.DOCUMENT_DELETED_TYPE: return i18n.t('history.event.delete_document_type'); //102 -- Package deleted case HoGoConst.PACKAGE_DELETED_TYPE: return i18n.t('history.event.delete_package_type'); // 601 case HoGoConst.DOCUMENT_VIEWED_TYPE: return i18n.t('history.event.document_viewed'); // 602 case HoGoConst.DOCUMENT_DOWNLOADED_TYPE: return i18n.t('history.event.document_downloaded'); // 606 case HoGoConst.DOCUMENT_OPENED_TYPE: return i18n.t('history.event.document_opened'); //201 case HoGoConst.DOCUMENT_UPDATED_TYPE: return i18n.t('history.event.document_edited'); // 300 case HoGoConst.RECIPIENT_ADDED_TYPE: return i18n.t('history.event.recipient_added'); // 301 case HoGoConst.RECIPIENT_UPDATED_TYPE: return i18n.t('history.event.recipient_edited'); default: return historyType;//"N/A"; } }, /** * Get file extension based on its name * @param {type} fileName * @returns {unresolved} */ getFileExtension: function (fileName) { var extension = fileName.substr((fileName.lastIndexOf('.') + 1)); return extension.toLowerCase(); }, /** * Show document icon from document type * @param {type} element jQuery object * @param {type} type type {1, 2, 3, 4}. Refer to HoGoConst to know exactly what it is */ drawDocumentIconFromType: function (element, type) { switch (parseInt(type)) { case HoGoConst.FILE_PDF_TYPE: element.addClass('pdf-icon').attr('title', i18n.t('mydocument.type_document.pdf')); break; case HoGoConst.FILE_WORD_TYPE: element.addClass('word-icon').attr('title', i18n.t('mydocument.type_document.word')); break; case HoGoConst.FILE_EXCEL_TYPE: case HoGoConst.FILE_XLSM_TYPE: element.addClass('excel-icon').attr('title', i18n.t('mydocument.type_document.excel')); break; case HoGoConst.FILE_POWERPOINT_TYPE: element.addClass('powerpoint-icon').attr('title', i18n.t('mydocument.type_document.powerpoint')); break; case HoGoConst.FILE_ORTHER_TYPE: element.addClass('other-document-icon').attr('title', "Other document"); break; } }, /** * Get file extension from file type * @param {type} type {1, 2, 3, 4}. Refer to HoGoConst to know exactly what it is * @returns {String} */ getExtFromFileType: function (type) { var ext = null; switch (parseInt(type)) { case HoGoConst.FILE_PDF_TYPE: ext = 'pdf'; break; case HoGoConst.FILE_WORD_TYPE: ext = 'docx'; break; case HoGoConst.FILE_EXCEL_TYPE: ext = 'xlsx'; break; case HoGoConst.FILE_POWERPOINT_TYPE: ext = 'pptx'; break; case HoGoConst.FILE_XLSM_TYPE: ext = 'xlsm'; break; case HoGoConst.FILE_ORTHER_TYPE: ext = "other"; break; } return ext; }, /** * Get user's local timezone. It supports from IE6 + * @returns {Number} */ getLocalTimeZone: function () { return (new Date().getTimezoneOffset( ) / 60) * (-1); }, /** * Check new node is existed on the list node * @param {type} listNode * @param {type} newNode * @returns {Boolean} */ checkNodeExisted: function (listNode, newNode) { var check = false; $.each(listNode, function (index, v) { if (v === newNode) { check = true; return check; } }); return check; }, /** * remove node on list node * @param {type} listNode * @param {type} node * @returns {undefined} */ removeNode: function (listNode, node, attr) { var index = -1; if (!attr) { index = $.inArray(node, listNode); } else { for (var i in listNode) { var n = listNode[i]; // Check exist attr if (attr in node && attr in n) { // Compare if (n[attr] == node[attr]) { index = i; } } } } // Push if (index != -1) { listNode.splice(index, 1); } }, /** * add node into list node * @param {type} listNode * @param {type} node * @param {type} attr * @returns {undefined} */ addNode: function (listNode, node, attr) { var index = -1; if (!attr) { index = $.inArray(node, listNode); } else { for (var i in listNode) { var n = listNode[i]; // Check exist attr if (node.hasOwnProperty(attr) && attr in n) { // Compare if (n[attr] == node[attr]) { index = i; } } } } // Push if (index == -1) { listNode.push(node); } }, loadPaymentPackage: function (currency) { return $.ajax({ type: "POST", url: "api/v1/GetPaymentPackage", beforeSend: function () { Modal.closeModal(); }, success: function (data) { if (data.status === 'OK') { var payPackages = data.list_package; HoGoUtils.makePaymentPakageList(payPackages, currency); } else { Modal.showAlert({content: "Can not get payment package"}); } } }); }, makePaymentPakageList: function (packages, currency) { // sort package by ID _.sortBy(packages, 'paymentId'); var contentList = ""; $.each(packages, function (i, value) { switch (parseInt(value.paymentId)) { case 1: var content = (currency === "yen") ? i18n.t('payment_package.package1_ja') : i18n.t('payment_package.package1'); contentList += ''; break; case 2: var content = (currency === "yen") ? i18n.t('payment_package.package2_ja') : i18n.t('payment_package.package2'); contentList += ''; break; case 3: var content = (currency === "yen") ? i18n.t('payment_package.package3_ja') : i18n.t('payment_package.package3'); contentList += ''; break; case 4: var content = (currency === "yen") ? i18n.t('payment_package.package4_ja') : i18n.t('payment_package.package4'); contentList += ''; break; } $('#listPayPackage').html(contentList); }); $("form#validationPay input[name=plan]").on("change", function () { // console.log("check", $('input[name=plan]:checked').val()); if ($(this).is(':checked')) { $(this).parent().parent().parent().parent().parent().find('.active').removeClass('active'); $(this).parent().parent().parent().addClass('active'); } }); }, makeLeftMenuAdmin: function ( ) { var admin = UserSession.getAdminObject(); if (admin){ switch (parseInt(admin.service_level)) { case HoGoConst.SYSTEM_ADMIN: $("#userListMenu").remove(); $("#affListMenu").remove(); $("#comListMenu").remove(); $("#disDashboard").remove(); $("#disReports").remove(); $("#comDashboard").remove(); $("#companyReport").remove(); $("#companyRecipientListMenu").remove(); $("#comHistory").remove(); break; case HoGoConst.DISTRIBUTOR: $("#userListMenu").remove(); $("#affListMenu").remove(); $("#disListMenu").remove(); $("#comDashboard").remove(); $("#companyReport").remove(); $("#comHistory").remove(); $("#companyRecipientListMenu").remove(); break; case HoGoConst.COMPANY_ADMIN: $("#disListMenu").remove(); $("#comListMenu").remove(); $("#disDashboard").remove(); $("#disReports").remove(); break; default: break; } }else{ window.location.href = 'admin/login'; } }, makeHrefHeaderAdmin: function ( ) { var admin = UserSession.getAdminObject(); switch (parseInt(admin.service_level)) { case HoGoConst.SYSTEM_ADMIN: $("#hrefAdminInformation").prop("href", "SystemAdminInformation"); break; case HoGoConst.DISTRIBUTOR: $("#hrefAdminInformation").prop("href", "DistributorAdminInformation"); break; case HoGoConst.COMPANY_ADMIN: $("#hrefAdminInformation").prop("href", "AdminInformation"); break; default: break; } }, detectBrowserAutoLang: function (userLang) { var lang; if (typeof userLang === 'undefined' || userLang === "" || userLang.indexOf('auto') !== -1) { lang = 'auto-' + HoGoUtils.detectBrowserLang(); } else { lang = userLang; } return lang; } }; }(jQuery));