' );
setTimeout( function() {
$( 'body' ).append( result );
result.find( '.content' ).html( $.i18n._( 'Previous Session' ) );
var button = result.find( '.close-icon' );
button.bind( 'click', function() {
removePreSession();
} );
result.bind( 'click', function() {
backToPreSession();
} );
}, 100 );
function removePreSession() {
result.remove();
result = null;
deleteCookie( 'AlternateSessionData', LocalCacheData.cookie_path, Global.getHost() );
}
function backToPreSession() {
var host = Global.getHost();
try { //Prevent JS exception if we can't parse alternate_session_data for some reason.
var alternate_session_data = JSON.parse( getCookie( 'AlternateSessionData' ) );
if ( !alternate_session_data ) {
Debug.Text( 'No alternate_session_data exists.', 'TAlertManager.js', 'TAlertManager', 'backToPreSession', 10 );
return;
}
} catch ( e ) {
Debug.Text( e.message, 'TAlertManager.js', 'showPreSessionAlert', 'backToPreSession', 10 );
return;
}
var url = alternate_session_data.previous_session_url;
var previous_cookie_path = alternate_session_data.previous_cookie_path;
alternate_session_data = {
new_session_id: alternate_session_data.previous_session_id,
previous_session_view: alternate_session_data.previous_session_view
};
setCookie( 'AlternateSessionData', JSON.stringify( alternate_session_data ), 1, previous_cookie_path, host );
Global.setURLToBrowser( url + '#!m=Login' );
Global.needReloadBrowser = true;
result.remove();
result = null;
}
};
var showErrorAlert = function( result ) {
var details = result.getDetails();
if ( details.hasOwnProperty( 'error' ) ) {
}
if ( !details ) {
details = result.getDescription(); // If the details is empty, try to get description to show.
}
var error_string = '';
if ( Global.isArray( details ) || typeof details === 'object' ) {
error_string = Global.convertValidationErrorToString( details );
} else {
error_string = details;
}
showAlert( error_string, 'Error' );
};
var showWarningAlert = function( result, callBack ) {
var details = result.getDetails();
var ul_container = $( '' );
if ( Global.isArray( details ) || typeof details === 'object' ) {
$.each( details, function( index, val ) {
if ( val.hasOwnProperty( 'warning' ) ) {
val = val.warning;
}
for ( var key in val ) {
var li = $( '
' );
var child_val = val[key];
var has_child = false;
for ( var child_key in child_val ) {
if ( child_val.hasOwnProperty( child_key ) ) {
has_child = true;
li = $( '
' );
li.append( child_val[child_key] );
ul_container.append( li );
}
}
if ( !has_child ) {
li.append( val[key] );
ul_container.append( li );
}
}
} );
}
var div = $( '
' );
var p = $( '
' );
p.append( $.i18n._( 'Are you sure you wish to save this record without correcting the above warnings?' ) );
div.append( ul_container );
div.append( p );
showConfirmAlert( div[0], 'Warning', callBack, 'Save', 'Cancel' );
};
var showAlert = function( content, title, callBack ) {
if ( !title ) {
title = $.i18n._( 'Message' );
}
var result = $( '
' +
'
' +
'' +
'
' +
'' +
'
' +
'
' );
setTimeout( function() {
if ( view !== null ) {
var cContent = view.find( '.content' ).text();
if ( cContent === content ) {
return;
}
remove();
}
view = result;
$( 'body' ).append( result );
result.find( '.title' ).text( title );
result.find( '.content' ).html( content );
var button = result.find( '.t-button' );
button.bind( 'click', function() {
remove();
if ( callBack ) {
callBack();
}
} );
button.focus();
button.bind( 'keydown', function( e ) {
e.stopPropagation();
if ( e.keyCode === 13 ) {
remove();
if ( callBack ) {
callBack();
}
}
} );
Global.setUIInitComplete();
}, 100 );
};
var showConfirmAlert = function( content, title, callBackFunction, yesLabel, noLabel ) {
if ( !Global.isSet( title ) ) {
title = $.i18n._( 'Message' );
}
if ( !Global.isSet( yesLabel ) ) {
yesLabel = $.i18n._( 'Yes' );
}
if ( !Global.isSet( noLabel ) ) {
noLabel = $.i18n._( 'No' );
}
if ( view !== null ) {
var cContent = view.find( '.content' ).text();
if ( cContent === content ) {
return;
}
remove();
}
var result = $( '
' )
if ( width ) {
result.css( 'width', width );
}
view = result;
$( 'body' ).append( result );
if ( form_type === 'dropdown' ) {
var form_item_input = Global.loadWidgetByName( FormItemType.COMBO_BOX );
form_item_input.TComboBox();
form_item_input.setSourceData( form_data );
result.find( '#yesBtn' ).bind( 'click', function() {
remove();
callBackFunction( result.find( 'select' ).val() );
} );
} else if ( form_type === 'password' ) {
form_item_input = Global.loadWidgetByName( FormItemType.PASSWORD_INPUT );
form_item_input.TPasswordInput();
result.find( '#yesBtn' ).bind( 'click', function() {
remove();
callBackFunction( result.find( '[type=password]' ).val() );
} );
} else if ( form_type === 'text' ) {
form_item_input = Global.loadWidgetByName( FormItemType.TEXT_INPUT );
form_item_input.TTextInput();
form_item_input.setValue( form_data );
if ( width ) {
form_item_input.width( ( width - 20 ) );
}
show_cancel_button = false;
result.find( '#yesBtn' ).bind( 'click', function() {
remove();
} );
} else if ( form_type === 'word_match' ) {
form_item_input = Global.loadWidgetByName( FormItemType.TEXT_INPUT );
form_item_input.TTextInput();
result.find( '#yesBtn' ).bind( 'click', function() {
if ( result.find( '[type=text]' ).val() === form_data ) {
remove();
callBackFunction( true );
} else {
callBackFunction( false );
}
} );
}
result.find( '#form-holder' ).append( form_item_input );
result.find( '#noBtn' ).bind( 'click', function() {
remove();
callBackFunction( false );
} );
result.find( '#yesBtn' ).text( continue_label );
result.find( '#noBtn' ).text( cancel_label );
result.find( '.title' ).text( title );
result.find( '.content' ).html( content );
if ( show_continue_button == false ) {
result.find( '#yesBtn' ).hide();
}
if ( show_cancel_button == false ) {
result.find( '#noBtn' ).hide();
}
Global.setUIInitComplete();
};
var showModalAlert = function( category, step, callBackFunction, img_src ) {
let top_image = '';
let title = '';
let content = '';
let additional_body_style = '';
let button_label = $.i18n._( 'Yes' );
let button_color = '#228b22';
if ( category === 'push_notification' ) {
top_image = '';
title = $.i18n._( 'Turn on Notifications' );
switch ( step ) {
case 'ask':
button_label = $.i18n._( 'Yes, turn on notifications!' );
content = LocalCacheData.getCurrentCompany().name + ' ' + $.i18n._( 'wants permission to notify you of important messages or alerts related to your employment. You can change your notification settings at anytime.' );
break;
case 'wait_for_permission':
button_label = $.i18n._( 'I don\'t see it?' );
button_color = '#AE0000';
// Some browsers by default block push notification permission we need to detect them to show user a different prompt.
if ( NotificationConsumer.detectBrowserNeedsExtraPermission() === true || Notification.permission === 'denied' ) {
// User needs to enable push notifications on the browser.
content = $.i18n._( 'A popup should appear on your screen, click "ALLOW" to enable notifications. If you don\'t see it, you may need to enable notifications in your browser settings.' );
} else {
content = $.i18n._( 'A popup should appear on your screen, click "ALLOW" to enable notifications.' );
}
break;
case 'help_text':
button_label = $.i18n._( 'Ok, done!' );
if ( Global.getBrowserVendor() === 'Edge' ) {
content = $.i18n._( '1. Click the icon to the left of the address (URL) bar to view settings. ' +
'2. Click "Permissions for this Site" ' +
'3. To the right of "Notifications" set the option to "ALLOW".' );
} else if ( Global.getBrowserVendor() === 'Firefox' ) {
content = $.i18n._( '1. Click the icon to the left of the address (URL) bar to view settings. ' +
'2. Click the "X" next Notifications to remove blocked permissions and then refresh the browser. ' );
} else {
content = $.i18n._( '1. Click the icon to the left of the address (URL) bar to view settings. ' +
'2. Click "Site settings" ' +
'3. To the right of "Notifications" set the option to "ALLOW".' );
}
break;
}
} else if ( category === 'multifactor_authentication' ) {
title = $.i18n._( 'Multifactor Authentication Instructions' );
switch ( step ) {
case 'download_instructions':
button_label = $.i18n._( 'Ok' );
button_color = '#426d9d';
additional_body_style = 'style="display: block; padding-left: 2rem; padding-right: 2rem; font-size: 1.1rem;"';
content = ' ';
content += '1.' + $.i18n._( 'Please download the TimeTrex app from the App Store on your device.' ) + '
';
content += '2.' + $.i18n._( ' Once installed, on the first step of the "Setup Wizard", tap the "QR Code" icon at the bottom right to scan the below QR Code.' ) + ' ';
content += '';
break;
}
}
Global.setUINotready();
var result = $( '