/** * timezone.js - change time based on user's timezone selection */ var TIMEZONE_INFORMATION_ACTION = 'get_information'; var TIMEZONE_SAVE_ACTION = 'save'; var tzLoadedSetValues = ''; // The global object for timezoneGeneral var timezoneGeneral = timezoneGeneral || {}; /** * Convert date string in UTC into GMT (with format MM/dd/yyyy HH:mm:ss am) */ function convertFromUTC2GMT(utcString, timezoneInMillis) { var resultDate = new Date(utcString); return resultDate.format("mm/dd/yyyy HH:MM:ss"); } function initCurrentDateTimeFormat(){ // --- time format curTimeFormat = dateTimeFormatObj['TimeFormat'] .replace('mm','MM') .replace('aa','TT'); if(dateTimeFormatObj['Military']){ // replace with 24h curTimeFormat = (curTimeFormat.split(" ")[0]).replace("hh", "HH"); } // --- date format curDateFormat = dateTimeFormatObj['DateFormat'].toLowerCase(); curDateFormat2 = curDateFormat.replace('yyyy','yy'); // --- date time format curDateTimeFormat = curDateFormat + " " + curTimeFormat; // --- device time curDeviceTime = dateTimeFormatObj['DeviceTime']; } function convertNewDateTimeFormat(_dateTimeString, _type, _zoneParam, displayOnlyFlg, editMode){ try { if(_dateTimeString == '') return ''; // === 19104 var _curAction = ''; try { if(_type.indexOf('&') == 0){ _type = _type.substring(1, _type.length); _curAction = 'edit'; } } catch (e) { } // --- get current zone var _zone = ''; var notDSTDate = _dateTimeString.replace(' DST', ''); if (notDSTDate.indexOf('UTC') > 0) { _zone = ' ' + notDSTDate.substring(notDSTDate.indexOf('UTC'), notDSTDate.length); } else if (notDSTDate.indexOf('GMT') > 0) { _zone = ' ' + notDSTDate.substring(notDSTDate.indexOf('GMT'), notDSTDate.length); } if('' != _zoneParam && '0' != _zoneParam){ // add case _zone = _zoneParam; // --- 19104 if('5' == curDeviceTime) _zone = curClientTZName; } // --- Calculation cases if(CONST_CTRL_TYPE_INPUTCALCULATE == _type){ _type = CONST_VALUE_DATE_SPACE_TIME; // default if(notDSTDate.indexOf('/') < 0){ // time case _type = CONST_VALUE_TIME; } } // --- time format var __timeFormat = dateTimeFormatObj['TimeFormat'] .replace('mm','MM') .replace('aa','TT'); if(dateTimeFormatObj['Military']){ // replace with 24h __timeFormat = (__timeFormat.split(" ")[0]).replace("hh", "HH"); } // --- date format var __dateFormat = dateTimeFormatObj['DateFormat'].toLowerCase(); if(__dateFormat.indexOf('dd') == 0 // dd/mm/yyyy && undefined != editMode){ // === convert to mm/dd/yyyy for edit mode only var _datePart = notDSTDate; var _timePart = ''; if(CONST_VALUE_DATE_SPACE_TIME == _type){ var spaceIndex = notDSTDate.indexOf(' '); _datePart = notDSTDate.substring(0, spaceIndex); _timePart = notDSTDate.substring(spaceIndex, notDSTDate.length); } if(_datePart.indexOf('/') > 0 && '0' != _zoneParam){ var _info = _datePart.split('/'); _datePart = _info[1] + '/' + _info[0] + '/' + _info[2]; // mm/dd/yyyy } if(CONST_VALUE_TIME == _type){ _datePart = '01/01/1900 ' + _datePart; } notDSTDate = _datePart + _timePart; __dateFormat = 'mm/dd/yyyy'; } else if(CONST_VALUE_TIME == _type){ // fix bug 18289 notDSTDate = '01/01/1900 ' + notDSTDate; } // --- result format var __dateTimeFormat = ""; if(CONST_VALUE_DATE == _type){ __dateTimeFormat = __dateFormat; } else if(CONST_VALUE_TIME == _type){ __dateTimeFormat = __timeFormat; } else if(CONST_VALUE_DATE_SPACE_TIME == _type){ __dateTimeFormat = __dateFormat + " " + __timeFormat; } // --- init date object from string value var dateObj = new Date(validateDateTimeFormatIE(notDSTDate)); // ======================= 19463: convert to record GMT try { if(_curAction == 'edit'){ // edit mode + save mode with edit action var _millis = glbHashObject['timezoneInMillis']; if(undefined != editMode){ // edit => get record TZ if('5' == curDeviceTime) _millis = curRecordTZMillis; if(CONST_VALUE_DATE_SPACE_TIME == _type && true == dateTimeFormatObj.TimeZoneFlg){ // 24040: do display TZ label dateObj = new Date(dateObj.getTime() - curClientTZMillis + parseFloat(_millis)); } } else if('5' == curDeviceTime){ // save => get Client TZ _millis = curClientTZMillis; } _zone = getClientZoneName(_millis); } } catch (e) { } // ======================= // --- check DST option var dst = ""; if (isDaylightSavingTime) { if(undefined != editMode){ // edit mode => not display DST & date time minus 1 hour dateObj = new Date(dateObj.getTime() - 3600000); // 1 hour } else{ // display mode => plush 1 hour for the original value dst = " DST"; dateObj = new Date(dateObj.getTime() + 3600000); // 1 hour } } // for display purpose only (after edit/add successfully) if(false == displayOnlyFlg // fix bug 14894 || (undefined != displayOnlyFlg && !dateTimeFormatObj['TimeZoneFlg'])){ _zone = ''; } return dateObj.format(__dateTimeFormat) + _zone + dst; } catch (e) { return _dateTimeString; } } /** * Convert date string in UTC into GMT DST (with format MM/dd/yyyy HH:mm:ss am) DST */ function convertFromUTC2GMTDST(utcString, kind, zone){ try { if('' == utcString){ return utcString; } var dstSuffix = ''; var dtPattern = 'mm/dd/yyyy HH:MM:ss'; // default value if(kind == CONST_VALUE_TIME || (utcString.indexOf('/') < 0 // not date time && utcString.indexOf('GMT') < 0 // not gmt value formated && utcString.indexOf('UTC') < 0 // not utc value formated && utcString.split(':').length > 2)){ // not showAsHM case dtPattern = 'HH:MM:ss'; var tmpDatePrefix = ''; if(utcString.indexOf('/')>=0){ }else{ tmpDatePrefix = '01/01/2011 '; } utcString = tmpDatePrefix + utcString; } var resultDate = new Date(utcString); if(isDaylightSavingTime){ dstSuffix = ' DST'; resultDate.setHours(resultDate.getHours()+1); } return resultDate.format(dtPattern) + zone + dstSuffix; } catch (e) { return utcString; } } /** * Convert date string from GMT into UTC (with format MM/dd/yyyy HH:mm:ss am) */ function convertFromGMT2UTC(gmtString, timezoneInMillis) { try { var formatDateValue = gmtString; // Delete tail (UTC or GMT) if (formatDateValue.indexOf('UTC') > 0) { formatDateValue = formatDateValue.substring(0, formatDateValue.indexOf('UTC') - 1); } if (formatDateValue.indexOf('GMT') > 0) { formatDateValue = formatDateValue.substring(0, formatDateValue.indexOf('GMT') - 1); } var resultDate = new Date(formatDateValue); if (gmtString.indexOf('DST') > 0) { // check for DST case resultDate.setHours(resultDate.getHours()-1); } return resultDate.format("mm/dd/yyyy hh:MM:ss TT"); } catch (e) { return gmtString; } } function getClientTimeZoneMillis() { var rightNow = new Date(); var jan1 = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0, 0); // jan 1st var june1 = new Date(rightNow.getFullYear(), 6, 1, 0, 0, 0, 0); // june 1st var temp = jan1.toGMTString(); var jan2 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1)); temp = june1.toGMTString(); var june2 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1)); var std_time_offset = (jan1 - jan2) / (1000 * 60 * 60); var daylight_time_offset = (june1 - june2) / (1000 * 60 * 60); var dst; if (std_time_offset == daylight_time_offset) { dst = "0"; // daylight savings time is NOT observed } else { // positive is southern, negative is northern hemisphere var hemisphere = std_time_offset - daylight_time_offset; if (hemisphere >= 0) std_time_offset = daylight_time_offset; dst = "1"; // daylight savings time is observed } return (std_time_offset * 60 * 60 * 1000); } function getClientTimeZoneMillis2() { return -(new Date()).getTimezoneOffset()*60*1000; } function getClientZoneName(_tzMillis){ var _zoneResult = ' UTC'; // default value try { if(_tzMillis == undefined || _tzMillis == 0){ return _zoneResult; } var operand = "+"; if(_tzMillis < 0) // negative num operand = "-"; var tzMinute = '0'; var hourDiff = parseFloat(Math.abs(_tzMillis)/3600000 + "").toFixed(1).split("."); if(hourDiff.length > 1) tzMinute = Math.round(parseFloat("0." + hourDiff[1])*60) + ""; _zoneResult = " GMT" + operand + (hourDiff[0].length > 1 ? hourDiff[0] : "0"+hourDiff[0]) + ":" + (tzMinute.length > 1 ? tzMinute : "0"+tzMinute); } catch (e) { } return _zoneResult; } function setRadioChecked(radioObj, selectedVal){ for ( var ra = 0; ra < radioObj.length; ra++) { if(radioObj[ra].value == selectedVal){ radioObj[ra].setAttribute('checked', 'checked') } else{ radioObj[ra].removeAttribute('checked'); } } } function initTimezoneSetting() { // Init the global variable for using in cross-functions $('#accTimezoneSettingRegion, .accTimezoneSetting').show(); $.live('.accTimezoneSetting', 'click', function(event) { event.preventDefault(); currentSubTabName = 'accTimezoneSetting'; if(isVersion3_5()) $('.dst_contain').css(CONST_CSS_KEY_DISPLAY, 'inline-block'); else $('.dst_contain').css(CONST_CSS_KEY_DISPLAY, CONST_VALUE_NONE); if(isVersion5_0()){ $('.time_setting_new').css(CONST_CSS_KEY_DISPLAY, 'inline-block'); //$('.dst_contain').css(CONST_CSS_KEY_DISPLAY, CONST_VALUE_NONE); $.live('.time_setting_new input:radio[name=setting_rad_others]', 'change', function() { if(this.value == '5'){ // device time $('.container_tz_edit').css('margin-top', '10px'); $('#setting_timezone_edit').prop('disabled', false); $('.choose_timezone').fadeOut('slow'); $('.time_settings_contain .dst_contain').fadeOut('slow'); } else{ // unified time $('.container_tz_edit').css('margin-top', ''); $('#setting_timezone_edit').prop('disabled', true); $('.choose_timezone').fadeIn('slow'); $('.time_settings_contain .dst_contain').fadeIn('slow'); } }); } else{ $('.time_setting_new').css(CONST_CSS_KEY_DISPLAY, CONST_VALUE_NONE); if(isVersion3_5()){ $('.dst_contain').css(CONST_CSS_KEY_DISPLAY, 'inline-block'); } } tzLoadedSetValues = ''; var userTimezone = null; var trackingSpeed = ''; // Init the list of available Timezones (only once) if (glbHashObject['has_init_timezonelist'] == undefined || glbHashObject['has_init_timezonelist'] == false) { waitForDataLoading(true); // Get list of timezone on server $.ajax({ url: '/timezone', dataType: 'json', type: 'POST', async:false, data: { action : TIMEZONE_INFORMATION_ACTION ,get_list : true }, cache: false, complete: function() { waitForDataLoading(false); }, success: function(data, status) { // Get data from server and fill into the timezone region var listTimezones = new Array(); var serverTimezones = data['list_timezone']; var idStart = new Number(serverTimezones['id_start']); var idEnd = new Number(serverTimezones['id_end']); var templateTz = ''; for (var i = idStart; i <= idEnd; i++) { var curTimezone = serverTimezones[i + '']; listTimezones.push(templateTz .replace('#value#', i) .replace('#location#', curTimezone['location'])); } $('#cboTimezoneSetting').html(listTimezones.join('')); // Update the current user's timezone selection userTimezone = data['user_timezone']; trackingSpeed = data.GpsSpeed; if(trackingSpeed == undefined || trackingSpeed == ''){ trackingSpeed = 'miles'; } // modified by NVHung if(data['dst']){ document.getElementById('chkDST').setAttribute('checked','check'); //document.getElementById('setting_chk_dst').setAttribute('checked','check'); } else{ document.getElementById('chkDST').removeAttribute('checked'); //document.getElementById('setting_chk_dst').removeAttribute('checked','check'); } // update new date:time options try { if(isVersion5_0()){ // --- date format var dateFormat = 1; // 'MM/dd/yyyy' if(data.dateFormat != undefined && data.dateFormat.indexOf('dd') == 0){ // dd/MM/yyyy dateFormat = 2; } setRadioChecked($('.time_setting_new input:radio[name=setting_rad_date]'), dateFormat); // --- time format var timeFormat = 4; // 'HH:mm:ss' if(data.timeFormat != undefined && data.timeFormat.split(':').length == 2){ // HH:mm timeFormat = 3; } setRadioChecked($('.time_setting_new input:radio[name=setting_rad_time]'), timeFormat) // --- device time setRadioChecked($('.time_setting_new input:radio[name=setting_rad_others]'), data.deviceTime); if('6' == data.deviceTime){ // unified time $('.container_tz_edit').css('margin-top', ''); $('#setting_timezone_edit').prop('disabled', true); $('.choose_timezone').css(CONST_CSS_KEY_DISPLAY, 'block'); $('.time_settings_contain .dst_contain').css(CONST_CSS_KEY_DISPLAY, 'inline-block'); } else{ // device time $('.container_tz_edit').css('margin-top', '10px'); $('#setting_timezone_edit').prop('disabled', false); $('.choose_timezone').css(CONST_CSS_KEY_DISPLAY, CONST_VALUE_NONE); $('.time_settings_contain .dst_contain').css(CONST_CSS_KEY_DISPLAY, CONST_VALUE_NONE); } // --- military if(data.military){ document.getElementById('setting_chk_military').setAttribute('checked', true); } else{ document.getElementById('setting_chk_military').removeAttribute('checked'); } // --- time zone flag if(data.tz){ document.getElementById('setting_chk_tz').setAttribute('checked', true); } else{ document.getElementById('setting_chk_tz').removeAttribute('checked'); } // CO-550 if(data.tzEdit){ document.getElementById('setting_timezone_edit').setAttribute('checked', true); } else{ document.getElementById('setting_timezone_edit').removeAttribute('checked'); } tzLoadedSetValues = dateFormat + '_' + timeFormat + '_' + data.military + '_' + data.tz + '_' + data.deviceTime + '_' + userTimezone + '_' + data['dst'] + '_' + trackingSpeed + '_' + data.tzEdit; } } catch (e) { writeToLogInfo('initTimezoneSetting : ' + e.message); } } }); glbHashObject['has_init_timezonelist'] = true; } else { // In the second, we only request the current user's timezone selection $.ajax({ url: '/timezone', dataType: 'json', type: 'POST', async:false, data: { action : TIMEZONE_INFORMATION_ACTION ,get_list : false }, cache: false, success: function(data, status) { userTimezone = data['user_timezone']; trackingSpeed = data.GpsSpeed; if(trackingSpeed == undefined || trackingSpeed == ''){ trackingSpeed = 'miles'; } // modified by NVHung if(data['dst']){ document.getElementById('chkDST').setAttribute('checked','check'); //document.getElementById('setting_chk_dst').setAttribute('checked','check'); } else{ document.getElementById('chkDST').removeAttribute('checked'); //document.getElementById('setting_chk_dst').removeAttribute('checked','check'); } // update new date:time options try { if(isVersion5_0()){ // --- date format var dateFormat = 1; // 'mm/dd/yyyy' if(data.dateFormat != undefined && data.dateFormat.indexOf('dd') == 0){ // dd/mm/yyyy dateFormat = 2; } setRadioChecked($('.time_setting_new input:radio[name=setting_rad_date]'), dateFormat); // --- time format var timeFormat = 4; // 'hh:mm:ss' if(data.timeFormat != undefined && data.timeFormat.split(':').length == 2){ // hh:mm timeFormat = 3; } setRadioChecked($('.time_setting_new input:radio[name=setting_rad_time]'), timeFormat) // --- device time setRadioChecked($('.time_setting_new input:radio[name=setting_rad_others]'), data.deviceTime); if('6' == data.deviceTime){ // unified time $('.container_tz_edit').css('margin-top', ''); $('#setting_timezone_edit').prop('disabled', true); $('.choose_timezone').css(CONST_CSS_KEY_DISPLAY, 'block'); $('.time_settings_contain .dst_contain').css(CONST_CSS_KEY_DISPLAY, 'inline-block'); } else{ // device time $('.container_tz_edit').css('margin-top', '10px'); $('#setting_timezone_edit').prop('disabled', false); $('.choose_timezone').css(CONST_CSS_KEY_DISPLAY, CONST_VALUE_NONE); $('.time_settings_contain .dst_contain').css(CONST_CSS_KEY_DISPLAY, CONST_VALUE_NONE); } // --- military if(data.military){ document.getElementById('setting_chk_military').setAttribute('checked', true); } else{ document.getElementById('setting_chk_military').removeAttribute('checked'); } // --- time zone flag if(data.tz){ document.getElementById('setting_chk_tz').setAttribute('checked', true); } else{ document.getElementById('setting_chk_tz').removeAttribute('checked'); } // CO-550 if(data.tzEdit){ document.getElementById('setting_timezone_edit').setAttribute('checked', true); } else{ document.getElementById('setting_timezone_edit').removeAttribute('checked'); } tzLoadedSetValues = dateFormat + '_' + timeFormat + '_' + data.military + '_' + data.tz + '_' + data.deviceTime + '_' + userTimezone + '_' + data['dst'] + '_' + trackingSpeed + '_' + data.tzEdit; } } catch (e) { writeToLogInfo('initTimezoneSetting : ' + e.message); } } }); } // Update information $('.main_content') .empty() .append(document.getElementById('acc_setup_5').innerHTML) .slideDown(); // Update the selected timezone for current user if (userTimezone != null && userTimezone != '0') { $('#cboTimezoneSetting').val(userTimezone); } $('#cboGpsSpeed').val(trackingSpeed); $('#accTimezoneSettingButtonSave,#accTimezoneSettingButtonCancel').off('click'); if(isUserPriAddEdit()) { $('#accTimezoneSettingButtonSave').click(function(){ // Submit data to server by ajax waitForDataLoading(true); var dstVal = $('#chkDST').prop('checked'); if(dstVal == 'checked') { dstVal = true; } else if(dstVal == undefined) { dstVal = false; } if(!isVersion3_5()) dstVal = false; // ----------------------------------------------- new date:time options var dateFormat = 'MM/dd/yyyy'; // old version var timeFormat = 'HH:mm:ss'; // old version - military 24h var timezoneEdit = true; // CO-550 var militaryFlg = false; var tzFlg = true; var deviceTimeFlgVal = 5; var trackingSpeedVal = ''; if(isVersion5_0()){ if($('.time_setting_new input:radio[name=setting_rad_date]:checked').val() == '2'){ dateFormat = 'dd/MM/yyyy'; } timeFormat = 'hh:mm aa'; // default 3 - AM | PM if($('.time_setting_new input:radio[name=setting_rad_time]:checked').val() == '4'){ timeFormat = 'hh:mm:ss aa'; } militaryFlg = $('.time_setting_new #setting_chk_military').prop('checked'); if(militaryFlg == 'checked') { militaryFlg = true; } else if(militaryFlg == undefined) { militaryFlg = false; } tzFlg = $('.time_setting_new #setting_chk_tz').prop('checked'); if(tzFlg == 'checked') { tzFlg = true; } else if(tzFlg == undefined) { tzFlg = false; } deviceTimeFlgVal = $('.time_setting_new input:radio[name=setting_rad_others]:checked').val(); if(5 == deviceTimeFlgVal){ // device time => not apply DST //$('.time_setting_new #setting_chk_dst').prop('checked', false); $('#chkDST').prop('checked', false); } dstVal = $('#chkDST').prop('checked'); if(dstVal == 'checked') { dstVal = true; } else if(dstVal == undefined) { dstVal = false; } trackingSpeedVal = $('#cboGpsSpeed').val(); timezoneEdit = $('#setting_timezone_edit').prop('checked'); } // ------------------------------------------------------------------ $.ajax({ url: '/timezone', dataType: 'json', type: 'POST', async:false, data: { action : TIMEZONE_SAVE_ACTION , choose_timezone : $('#cboTimezoneSetting').val() , date_format : dateFormat , time_format : timeFormat , military : militaryFlg , time_zone : tzFlg , dst : dstVal , deviceTime : deviceTimeFlgVal , trackingGpsSpeed : trackingSpeedVal , timezoneEdit : timezoneEdit }, cache: false, complete: function() { tzLoadedSetValues = ''; waitForDataLoading(false); }, success: function(data, status) { waitForDataLoading(false); if (data.result == false) { jAlert(msg_unknown_error); } else { if(authNS && authNS.currentUser){ authNS.currentUser.TimeZone = data.timezoneInMillis; authNS.currentUser.dayligthSavingsTime = dstVal; authNS.currentUser.CustomerTimeZoneID = $('#cboTimezoneSetting').val(); } jAlert(msg_save_success); // Put timezone information into global variable glbHashObject['timezoneInMillis'] = data.timezoneInMillis; } }, error : function() { jAlert(msg_unknown_error); } }); }); } else { $('#accTimezoneSettingButtonSave').off('click').prop('disabled', true); } $('#accTimezoneSettingButtonCancel').click(function(){ tzLoadedSetValues = ''; // Return the Account tab changeAccountTab('.accountLink'); }); }); }; /*************************************************************************** * Change into the Account Tab **************************************************************************/ var changeAccountTab = function(tabActive){ // Load the current account waitForDataLoading(true); $.ajax({ url: '/account/AccountSelectServlet', dataType: 'json', type: 'GET', data: '{}', cache: false, complete: function() { waitForDataLoading(false); }, success: function(response, status) { $('.main_content') .empty() .append(document.getElementById('accountManage').innerHTML) .slideDown(); if(undefined != authNS.currentUser && !authNS.currentUser.advanced_security) { $('#accAdvanceSecurityPageRegion').remove(); } $('.main_content .accChangeLogo1').off('mouseover').qtip({ content: lbl_avlbl_for_paid, show: 'mouseover', hide: 'mouseout', position: { corner: { tooltip: 'bottomLeft', // Use the corner... target: 'topMiddle' // ...and opposite corner } }, style: { width: 280, name: 'dark', background: '#000000', border: { radius: 1, width: 1 }, tip: true } }); // timezoneGeneral.initComplexPasswordAndULockout(); // CO-1752 - remove this code }, error: function(request, status, error) { if(getStatus(request) == 401){ jAlert(msg_read_permission_required); }else{ jAlert(msg_error_try); } } }); }; /** * Convert date string in UTC into GMT for Time (with format MM/dd/yyyy HH:mm:ss am) */ function convertFromUTC2GMTForTime(utcString) { var tmpDatePrefix = ''; if(utcString.indexOf('/')>=0){ }else{ tmpDatePrefix = '01/01/2011 '; } var resultDate = new Date(tmpDatePrefix + utcString); return resultDate.format("HH:MM:ss"); } /** * Convert date string from GMT into UTC for Time (with format MM/dd/yyyy HH:mm:ss am) */ function convertFromGMT2UTCForTime(gmtString) { try { // Delete tail (UTC or GMT) var formatDateValue = gmtString.replace(' DST', ''); // comment this code fof fixing bug 18494 /*if (formatDateValue.indexOf('UTC') > 0) { formatDateValue = formatDateValue.substring(0, formatDateValue.indexOf('UTC') - 1); } if (formatDateValue.indexOf('GMT') > 0) { formatDateValue = formatDateValue.substring(0, formatDateValue.indexOf('GMT') - 1); }*/ var resultDate = initDateFromTimeValue(formatDateValue); if (gmtString.indexOf('DST') > 0) { // check for DST case resultDate.setHours(resultDate.getHours()-1); } return resultDate.format('hh:MM:ss TT'); } catch (e) { return gmtString; } } function initDateFromTimeValue(timeValue){ var dateResult = null; try { var timePart = timeValue.split(' ')[0]; // get hh:MM:ss part only try { // 26828: firefox var timePart2 = timePart.split(':'); if(timePart2.length > 3){ // 01:01:01:000 timeValue = timeValue.replace(':'+timePart2[3],''); } } catch (e) { } // === init default value dateResult = new Date( validateDateTimeFormatIE('01/01/1900 ' + timeValue)); var _hour = timePart.split(':')[0]; if(timeValue.indexOf('AM') > 0 || timeValue.indexOf('PM') > 0){ // mui gio AM PM // === check hour val var pmFlg = false; if(timeValue.indexOf('PM') > 0) pmFlg = true; if('12' == _hour && pmFlg){ // 12 at lunch // do nothing } else if('12' == _hour && !pmFlg){ // 12 at morning _hour = '0'; } else if(pmFlg){ _hour = 12 + parseInt(_hour); } } // set hours exactly from timeValue // (avoiding system DST case) dateResult.setHours(_hour); } catch (e) { dateResult = null; } return dateResult; } /** * Convert current time based on selected timzone * @param currentTime The current time (example 10:20:30 PM) * @returns The time string */ function convertTimeBasedOnTimezone(currentTime, addingMillis, __action) { try { if('' == currentTime || undefined == currentTime){ return ''; } // fix bug 23794 - 03:05 PM try { if(currentTime.split(':').length == 2){ var arrFull = currentTime.split(' '); currentTime = arrFull[0] + ':00'; if(arrFull.length > 1){ currentTime += ' ' + arrFull[1]; } } } catch (e) { } var curDate = new Date('01/01/1900 ' + currentTime); if((''+curDate) == 'Invalid Date' || currentTime.split(':').length == 2){ // calculation HM case - 66:12 return currentTime; } try { // === 19463: convert to UTC var persistTZ = glbHashObject['timezoneInMillis']; if('5' == curDeviceTime) persistTZ = curClientTZMillis; var dstMillis = 0; if(isDaylightSavingTime){ dstMillis = 3600000; } curDate = new Date(curDate.getTime() - persistTZ - dstMillis); } catch (e) { // Bulk dispatch tab curDate = new Date(curDate.getTime() - addingMillis); } var currentHour = curDate.getHours(); if (currentHour >= 12 && curDate.format(":MM:ss TT").indexOf('PM') > 0) { currentHour = currentHour - 12; } if (currentHour < 10) { currentHour = '0' + currentHour; } return currentHour + curDate.format(":MM:ss TT"); } catch (e) { return currentTime; } } /** * Get standard date time/time based on inputDateTime * * @param {} inputDateTime the different date time value, examples : * + 01:02:03 * + 01:02:03 UTC * + 01:02:03 GMT+07 * + 01:02:03 GMT+07:00 * + 2012/10/10 01:02:03 GMT+07 * + 2012/10/10 01:02:03 GMT+07:00 * * => All will be result in pattern [01:02:03] or [2012/10/10 01:02:03] * * @returns {} */ function getStandardDateTimeString(inputDateTime) { if (inputDateTime === undefined || inputDateTime === null || inputDateTime === '') { return null; } if (inputDateTime.indexOf(' UTC') > 0) { inputDateTime = inputDateTime.replace(/ UTC.*/ig, ''); } if (inputDateTime.indexOf(' GMT') > 0) { inputDateTime = inputDateTime.replace(/ GMT.*/ig, ''); } return inputDateTime; } /** * Check the current time/date time is inside of range[from, to] * (when the from/to is empty, we will ignore checking from/to) * @param {} from * @param {} to * @param {} current * @param {} isCheckTime The flag about checking time (true/false) * @returns {} * The result of checking (true/false) */ function isInsideRangeDateTime(from, to, current, isCheckTime) { var tmpDatePrefix = ''; if (isCheckTime === true) { tmpDatePrefix = '01/01/2011 '; } var strCurrent = getStandardDateTimeString(current); if(strCurrent.indexOf('/')>=0){ }else{ tmpDatePrefix = ''; } var currentVal = new Date(tmpDatePrefix + strCurrent).getTime(); //writeToLogInfo('strCurrent : ' + strCurrent + ' --- currentVal : ' + currentVal); // Check from (if not empty) if (from !== '') { var dtFrom = new Date(tmpDatePrefix + from); //writeToLogInfo('dtFrom : ' + dtFrom.getTime()); if (currentVal < dtFrom.getTime()) { //writeToLogInfo('current Val <<<< FROM '); return false; } } if (to !== '') { var dtTo = new Date(tmpDatePrefix + to); //writeToLogInfo('dtTo : ' + dtTo.getTime()); if (currentVal > dtTo.getTime()) { //writeToLogInfo('current Val >>>> TO '); return false; } } return true; } /** * Global function for initializing Complex Password nad User Lockout * CO-15 : Add Complex Passwords and User Lockout to the account settings */ /* CO-1752 Show menu for all user, no more hidden timezoneGeneral.initComplexPasswordAndULockout = function() { // Check version of complex password and User Lockout $('.accComplexPasswordsRegion').hide(); if (isVersion(VERSION_COMPLEX_PASSWORD_AND_USER_LOCKOUT)) { // Show region .accComplexPasswordsRegion //$('.accComplexPasswordsRegion').show(); // Check if the current account is using this feature waitForDataLoading(true); $.ajax({ url: '/EmailAliasServlet', dataType: 'json', type: 'POST', data: { action : 'check_using_complex_pwd_feature' }, cache: false, complete: function() { waitForDataLoading(false); }, success: function(response, status) { // Get data from server and fill into the email alias region if (response['status'] === false || response['is_using_feature_cpl_pwd'] === undefined ) { jAlert(msg_unknown_error); return; } // Use feature if (response['is_using_feature_cpl_pwd']) { $('.accComplexPasswordsRegion').show(); } } }); } else { return; } * / if (!isVersion(VERSION_COMPLEX_PASSWORD_AND_USER_LOCKOUT)) { $('.accComplexPasswordsRegion').hide(); } // Init event click of [Complex Password] /* $(document).off('click', '.accComplexPasswords'); $(document).on('click', '.accComplexPasswords', function(event) { event.preventDefault(); waitForDataLoading(true); // Get data from server $.ajax({ url: '/EmailAliasServlet', dataType: 'json', type: 'POST', data: { action : 'get_information4_complex_pass' }, cache: false, complete: function() { waitForDataLoading(false); }, success: function(response, status) { // Get data from server and fill into the email alias region if (response['status'] === false || response['useComplexPass'] === undefined || response['useUserLockout'] === undefined ) { jAlert(msg_unknown_error); return; } // Update information $('.main_content') .empty() .append(document.getElementById('acc_setup_4ComplexPassword').innerHTML) .slideDown(); var regionObj = $('.main_content').find('.complex_password_user_lockout_region'); regionObj.find('#chkAddComplexPassword2Acc')[0].checked = response['useComplexPass']; regionObj.find('#chkAddUserLockout2Acc')[0].checked = response['useUserLockout']; regionObj.find('#userLockMaxFailCount').val(response['userLockMaxFailCount']); regionObj.find('#userLockRemoveLockAfter').val(response['userLockRemoveLockAfter']); regionObj.find('#userLockActivityTimeoutAfterMinute').val(response['userLockActivityTimeoutAfterMinute']); regionObj.find('#userLockActivityTimeoutAfterHour').val(response['userLockActivityTimeoutAfterHour']); regionObj.find('#userLockATAUnit').val(response['userLockATAUnit']); onlyNumber(regionObj.find('#userLockMaxFailCount')); if(response['userLockATAUnit'] == 'hours') { regionObj.find('#userLockActivityTimeoutAfterMinute').addClass('hideItem'); regionObj.find('#userLockActivityTimeoutAfterHour').removeClass('hideItem'); } else if(response['userLockATAUnit'] == 'minutes') { regionObj.find('#userLockActivityTimeoutAfterMinute').removeClass('hideItem'); regionObj.find('#userLockActivityTimeoutAfterHour').addClass('hideItem'); } regionObj.find('#userLockATAUnit').off('change').change(function() { var regionObj = $('.main_content').find('.complex_password_user_lockout_region'); if($(this).val() == 'hours') { regionObj.find('#userLockActivityTimeoutAfterMinute').addClass('hideItem'); regionObj.find('#userLockActivityTimeoutAfterHour').removeClass('hideItem'); } else if($(this).val() == 'minutes') { regionObj.find('#userLockActivityTimeoutAfterMinute').removeClass('hideItem'); regionObj.find('#userLockActivityTimeoutAfterHour').addClass('hideItem'); } }); // The button Save if(isUserPriAddEdit()) { regionObj.find('#accBtnChangeCmplxPL').off('click').click(function() { var regionObj = $('.main_content').find('.complex_password_user_lockout_region'); var useComplexPass = regionObj.find('#chkAddComplexPassword2Acc')[0].checked; var useUserLockout = regionObj.find('#chkAddUserLockout2Acc')[0].checked; var userLockMaxFailCount = regionObj.find('#userLockMaxFailCount')[0].value; var userLockRemoveLockAfter = regionObj.find('#userLockRemoveLockAfter')[0].value; var userLockActivityTimeoutAfterMinute = regionObj.find('#userLockActivityTimeoutAfterMinute')[0].value; var userLockActivityTimeoutAfterHour = regionObj.find('#userLockActivityTimeoutAfterHour')[0].value; var userLockATAUnit = regionObj.find('#userLockATAUnit')[0].value; $.ajax({ url: '/EmailAliasServlet', dataType: 'json', type: 'POST', data: { action : 'save_complex_pass' ,useComplexPass : useComplexPass ,useUserLockout : useUserLockout ,userLockMaxFailCount : userLockMaxFailCount ,userLockRemoveLockAfter : userLockRemoveLockAfter ,userLockActivityTimeoutAfterMinute : userLockActivityTimeoutAfterMinute ,userLockActivityTimeoutAfterHour : userLockActivityTimeoutAfterHour ,userLockATAUnit : userLockATAUnit }, cache: false, complete: function() { waitForDataLoading(false); }, success: function(response, status) { // Get data from server and fill into the email alias region if (response['status'] === false) { jAlert(msg_unknown_error); return; } // Return the Account tab // changeAccountTab('.accountLink'); $('.manageLink').trigger('click'); } ,error : function() { jAlert(msg_unknown_error); } }); }); } else { regionObj.find('#accBtnChangeCmplxPL').off('click').prop('disabled',true); } // The button Cancel / * regionObj.find('#accBtnCancelCmplxPL').off('click').click(function() { // Return the Account tab changeAccountTab('.accountLink'); }); * / } ,error : function() { jAlert(msg_unknown_error); } }); }); } */ // The global value storing useComplexPassword flag, getting from server timezoneGeneral.isUsingComplexPassword = false; /** * Validate Complex Password * @return Object { * + status : true/false * + error_code : The predefined error code * + error_message : The predefined error message * } */ timezoneGeneral.validateComplexPassword = function(currentPwd) { console.log('>> Check Complex Password : ' + currentPwd); var result = { status : true ,error_code : '' ,error_message : '' }; if (currentPwd === '') { return result; } // CO16 :: Apply Complex Passwords when adding/updating web users // (https://doforms.atlassian.net/browse/CO-16) var countUpper = 0; var countLower = 0; var countSpChars = 0; var listSpecialChars = '!,@,#,$,%,&'.split(','); for (var i = 0; i < currentPwd.length; i++) { var pwdChar = currentPwd[i]; if (pwdChar >= 'A' && pwdChar <= 'Z') { countUpper++; } if (pwdChar >= 'a' && pwdChar <= 'z') { countLower++; } if (listSpecialChars.indexOf(pwdChar) >= 0) { countSpChars++; } } console.log('UPPER/lower/special : ' + countUpper + '/' + countLower + '/' + countSpChars); result.countUpper = countUpper; result.countLower = countLower; result.countSpChars = countSpChars; // Minimum Length: 8 characters var minimumPasswordLength = 8; if(authNS.currentUser.complexPassword) { minimumPasswordLength = authNS.currentUser.minimumPasswordLength; } var error_message = msg_complex_password_minmax_required.replace('$1', minimumPasswordLength); if (currentPwd.length < minimumPasswordLength || currentPwd.length > 40) { result.error_code = 'MIN_MAX'; result.error_message = error_message; result.status = false; } // Case Sensitive: at least 1 UPPER case and 1 lower case character else if (countUpper <= 0 || countLower <= 0) { result.error_code = 'UPPER_LOWER'; result.error_message = error_message; result.status = false; } // Special Character: at least 1 special character (!,@,#,$,%,&) else if (countSpChars <= 0) { result.error_code = 'SPECIAL'; result.error_message = error_message; result.status = false; return result; } console.log(' >> Result check : ' + JSON.stringify(result)); return result; }