import '@/global/widgets/filebrowser/TImageBrowser';
import '@/global/widgets/filebrowser/TImageAdvBrowser';
import { TTUUID } from '@/global/TTUUID';
export class AboutViewController extends BaseViewController {
constructor( options = {} ) {
_.defaults( options, {
date_api: null,
employeeActive: []
} );
super( options );
}
init( options ) {
//this._super('initialize', options );
this.viewId = 'About';
this.script_name = 'AboutView';
this.context_menu_name = $.i18n._( 'About' );
this.api = TTAPI.APIAbout;
this.date_api = TTAPI.APITTDate;
this.render();
this.initData();
}
getCustomContextMenuModel() {
var context_menu_model = {
exclude: ['default'],
include: [
{
label: $.i18n._( 'Check For Updates' ),
id: 'check_updates',
vue_icon: 'tticon tticon-refresh_black_24dp',
group: 'editor',
},
'cancel',
{
label: '', //Empty label. vue_icon is displayed instead of text.
id: 'diagnostic_header',
action_group: 'diagnostic',
menu_align: 'right',
action_group_header: true,
vue_icon: 'tticon tticon-more_vert_black_24dp'
},
{
label: $.i18n._( 'Diagnostics: Enable' ),
id: 'diagnostics_enable',
action_group: 'diagnostic',
menu_align: 'right',
permission_result: this.diagnosticPermissionValidate()
},
{
label: $.i18n._( 'Diagnostics: Disable' ),
id: 'diagnostics_disable',
action_group: 'diagnostic',
menu_align: 'right',
permission_result: this.diagnosticPermissionValidate()
},
{
label: $.i18n._( 'Diagnostics: Upload' ),
id: 'diagnostics_upload',
action_group: 'diagnostic',
menu_align: 'right',
permission_result: this.diagnosticPermissionValidate()
},
{
label: $.i18n._( 'Diagnostics: Test Connection' ),
id: 'diagnostics_test_connection',
action_group: 'diagnostic',
menu_align: 'right',
permission_result: this.diagnosticPermissionValidate()
}
]
};
return context_menu_model;
}
onCustomContextClick( id ) {
switch ( id ) {
case 'check_updates':
this.onCheckClick();
break;
case 'diagnostics_enable':
this.onToggleDiagnosticClick( true );
break;
case 'diagnostics_disable':
this.onToggleDiagnosticClick( false );
break;
case 'diagnostics_upload':
this.onUploadDiagnosticClick();
break;
case 'diagnostics_test_connection':
this.onTestConnectionDiagnosticClick();
break;
}
}
onCheckClick() {
var $this = this;
this.api['isNewVersionAvailable']( {
onResult: function( result ) {
$this.current_edit_record = result.getResult();
$this.initEditView();
}
} );
}
onToggleDiagnosticClick( toggle ) {
var $this = this;
this.api.setSystemDiagnostic( toggle, {
onResult: function( result ) {
var message = '';
if ( toggle ) {
message = $.i18n._( 'Diagnostic mode is now enabled.' );
} else {
message = $.i18n._( 'Diagnostic mode is now disabled.' );
}
TAlertManager.showAlert( message, $.i18n._( 'Diagnostics Mode' ) );
}
} );
}
onUploadDiagnosticClick() {
this.api.uploadSystemDiagnostic( {
onResult: function( result ) {
}
} );
}
onTestConnectionDiagnosticClick() {
this.api.testConnectionDiagnostic( {
onResult: function( result ) {
var message = '';
if ( result.getResult() === true ) {
message = $.i18n._( 'Connection test successful!' );
} else {
message = result.getResult();
}
TAlertManager.showAlert( message, $.i18n._( 'Diagnostics Connection Test' ) );
}
} );
}
getAboutData( callBack ) {
var $this = this;
$this.api['getAboutData']( {
onResult: function( result ) {
var result_data = result.getResult();
if ( Global.isSet( result_data ) ) {
callBack( result_data );
}
}
} );
}
diagnosticPermissionValidate() {
if ( PermissionManager.validate( 'user', 'edit' ) && APIGlobal.pre_login_data.primary_company_id === LocalCacheData.getLoginUser().company_id ) {
return true;
}
return false;
}
openEditView() {
var $this = this;
if ( $this.edit_only_mode ) {
this.buildContextMenu();
if ( !$this.edit_view ) {
$this.initEditViewUI( 'About', 'AboutEditView.html' );
}
$this.getAboutData( function( result ) {
// Waiting for the TTAPI.API returns data to set the current edit record.
$this.current_edit_record = result;
$this.initEditView();
} );
}
}
setUIWidgetFieldsToCurrentEditRecord() {
}
setCurrentEditRecordData() {
//Set current edit record data to all widgets
if ( !Global.isSet( this.current_edit_record['license_data'] ) ) {
this.current_edit_record['license_data'] = {};
}
for ( var i in this.edit_view_form_item_dic ) {
this.detachElement( i );
}
for ( var key in this.current_edit_record ) {
if ( !this.current_edit_record.hasOwnProperty( key ) ) {
continue;
}
var widget = this.edit_view_ui_dic[key];
switch ( key ) {
case 'new_version':
if ( this.current_edit_record[key] === true ) {
this.attachElement( 'notice' );
var html = '
' + $.i18n._( 'NOTICE' ) + ':' + ' ' + $.i18n._( 'There is a new version of' ) + ' ';
html += '' + $.i18n._( this.current_edit_record['application_name'] ) + ' ' + $.i18n._( 'available' ) + '.';
html += '
' + $.i18n._( 'This version may contain tax table updates necessary for accurate payroll calculation, we recommend that you upgrade as soon as possible.' ) + '
';
html += '' + $.i18n._( 'The latest version can be downloaded from' ) + ':' + ' ';
html += '' + this.current_edit_record['organization_url'] + '
';
$( this.edit_view_form_item_dic['notice'].find( '.tblDataWarning' ) ).html( html );
}
break;
case 'registration_key':
if ( Global.isSet( widget ) ) {
if ( this.current_edit_record[key] === '' || Global.isFalseOrNull( this.current_edit_record[key] ) ) {
widget.setValue( $.i18n._( 'N/A' ) );
} else {
widget.setValue( this.current_edit_record[key] );
}
}
break;
case 'hardware_id':
if ( Global.isSet( widget ) ) {
if ( this.current_edit_record[key] === '' || Global.isFalseOrNull( this.current_edit_record[key] ) ) {
widget.setValue( $.i18n._( 'N/A' ) );
} else {
widget.setValue( this.current_edit_record[key] );
}
}
break;
case 'cron': //popular case
if ( Global.isSet( widget ) ) {
if ( this.current_edit_record[key]['last_run_date'] !== '' ) {
widget.setValue( this.current_edit_record[key]['last_run_date'] );
} else {
widget.setValue( $.i18n._( 'Never' ) );
}
}
break;
case 'license_data':
if ( Global.isSet( this.current_edit_record[key] ) ) {
this.attachElement( 'license_info' );
this.attachElement( 'license_browser' );
var separated_box = $( this.edit_view_form_item_dic['license_info'].find( '.separated-box' ) );
if ( this.current_edit_record[key]['message'] ) {
separated_box.css( {
'font-weight': 'bold',
'background-color': 'red',
'height': 'auto',
'color': '#000000'
} );
separated_box.html( $.i18n._( 'License Information' ) + '
' + $.i18n._( 'WARNING' ) + ': ' + this.current_edit_record[key]['message'] );
$( separated_box.find( 'span' ) ).removeClass( 'label' ).css( {
'font-size': 'normal',
'font-weight': 'bold'
} );
} else {
separated_box.html( '' + $.i18n._( 'License Information' ) + '' );
}
if ( this.current_edit_record[key]['organization_name'] ) {
for ( var k in this.current_edit_record[key] ) {
switch ( k ) {
case 'major_version':
case 'minor_version':
this.attachElement( '_version' );
this.edit_view_ui_dic['_version'].setValue( this.current_edit_record[key]['major_version'] + '.' + this.current_edit_record[key]['minor_version'] + '.X' );
break;
default:
if ( Global.isSet( this.edit_view_ui_dic[k] ) && Global.isSet( this.edit_view_form_item_dic[k] ) ) {
this.attachElement( k );
this.edit_view_ui_dic[k].setValue( this.current_edit_record[key][k] );
}
break;
}
}
}
}
break;
case 'user_counts':
if ( this.current_edit_record[key].length > 0 ) {
this.attachElement( 'user_active_inactive' );
}
break;
case 'schema_version_group_A':
case 'schema_version_group_B':
case 'schema_version_group_C':
case 'schema_version_group_D':
if ( Global.isSet( widget ) && this.current_edit_record[key] ) {
widget.setValue( this.current_edit_record[key] );
}
break;
default:
if ( Global.isSet( widget ) ) {
widget.setValue( this.current_edit_record[key] );
}
break;
}
if ( Global.isSet( widget ) && this.current_edit_record[key] == false ) {
widget.parents( '.edit-view-form-item-div' ).detach();
}
}
this.collectUIDataToCurrentEditRecord();
this.setEditViewDataDone();
}
setEditViewDataDone() {
super.setEditViewDataDone();
this.setActiveEmployees();
}
setActiveEmployees() {
if ( this.employeeActive.length > 0 ) {
for ( var i in this.employeeActive ) {
var field = this.employeeActive[i].getField();
if ( Global.isSet( this.edit_view_form_item_dic[field] ) ) {
this.edit_view_form_item_dic[field].remove();
}
}
this.employeeActive = [];
}
if ( Global.isSet( this.current_edit_record['user_counts'] ) && this.current_edit_record['user_counts'].length > 0 ) {
var tab_about = this.edit_view_tab.find( '#tab_about' );
var tab_about_column1 = tab_about.find( '.first-column' );
for ( var key in this.current_edit_record['user_counts'] ) {
var item = this.current_edit_record['user_counts'][key];
var form_item_input = Global.loadWidgetByName( FormItemType.TEXT );
form_item_input.TText( { field: 'active_' + key } );
form_item_input.setValue( item['max_active_users'] + ' / ' + item['max_inactive_users'] );
this.addEditFieldToColumn( $.i18n._( item['label'] ), form_item_input, tab_about_column1, '', null, true );
this.employeeActive.push( form_item_input );
this.edit_view_ui_dic['active_' + key].css( 'opacity', 1 );
}
this.editFieldResize( 0 );
}
}
buildEditViewUI() {
var $this = this;
super.buildEditViewUI();
var tab_model = {
'tab_about': {
'label': $.i18n._( 'About' )
},
};
this.setTabModel( tab_model );
//Tab 0 start
var tab_about = this.edit_view_tab.find( '#tab_about' );
var tab_about_column1 = tab_about.find( '.first-column' );
this.edit_view_tabs[0] = [];
this.edit_view_tabs[0].push( tab_about_column1 );
var form_item_input = $( '