TimeTrex/interface/html5/views/hr/qualification/UserMembershipViewController.js

457 lines
12 KiB
JavaScript

export class UserMembershipViewController extends BaseViewController {
constructor( options = {} ) {
_.defaults( options, {
el: '#user_membership_view_container',
document_object_type_id: null,
qualification_group_array: null,
source_type_array: null,
ownership_array: null,
qualification_group_api: null,
qualification_api: null,
sub_view_grid_autosize: true
} );
super( options );
}
init( options ) {
//this._super('initialize', options );
this.edit_view_tpl = 'UserMembershipEditView.html';
this.permission_id = 'user_membership';
this.viewId = 'UserMembership';
this.script_name = 'UserMembershipView';
this.table_name_key = 'user_membership';
this.context_menu_name = $.i18n._( 'Memberships' );
this.navigation_label = $.i18n._( 'Membership' );
this.api = TTAPI.APIUserMembership;
this.qualification_api = TTAPI.APIQualification;
this.qualification_group_api = TTAPI.APIQualificationGroup;
this.document_object_type_id = 130;
this.render();
//call init data in parent view
if ( !this.sub_view_mode ) {
this.buildContextMenu();
this.initData();
}
}
initOptions() {
var $this = this;
this.initDropDownOption( 'ownership' );
this.initDropDownOption( 'source_type' );
this.qualification_group_api.getQualificationGroup( '', false, false, {
onResult: function( res ) {
res = res.getResult();
res = Global.buildTreeRecord( res );
$this.qualification_group_array = res;
if ( !$this.sub_view_mode && $this.basic_search_field_ui_dic['group_id'] ) {
$this.basic_search_field_ui_dic['group_id'].setSourceData( res );
$this.adv_search_field_ui_dic['group_id'].setSourceData( res );
}
}
} );
var args = {};
var filter_data = {};
filter_data.type_id = [50];
filter_data.visibility_type_id = [10, 100]; //10=Internal Only, 100=Both
args.filter_data = filter_data;
this.qualification_api.getQualification( args, {
onResult: function( res ) {
res = res.getResult();
if ( !$this.sub_view_mode && $this.basic_search_field_ui_dic['qualification_id'] ) {
$this.basic_search_field_ui_dic['qualification_id'].setSourceData( res );
$this.adv_search_field_ui_dic['qualification_id'].setSourceData( res );
}
}
} );
}
showNoResultCover( show_new_btn ) {
super.showNoResultCover( ( this.sub_view_mode ) ? true : false );
}
onGridSelectRow() {
if ( this.sub_view_mode ) {
this.buildContextMenu( true );
this.cancelOtherSubViewSelectedStatus();
} else {
this.buildContextMenu();
}
this.setDefaultMenu();
}
onGridSelectAll() {
if ( this.sub_view_mode ) {
this.buildContextMenu( true );
this.cancelOtherSubViewSelectedStatus();
}
this.setDefaultMenu();
}
cancelOtherSubViewSelectedStatus() {
switch ( true ) {
case typeof ( this.parent_view_controller.sub_user_skill_view_controller ) !== 'undefined':
this.parent_view_controller.sub_user_skill_view_controller.unSelectAll();
case typeof ( this.parent_view_controller.sub_user_license_view_controller ) !== 'undefined':
this.parent_view_controller.sub_user_license_view_controller.unSelectAll();
case typeof ( this.parent_view_controller.sub_user_education_view_controller ) !== 'undefined':
this.parent_view_controller.sub_user_education_view_controller.unSelectAll();
case typeof ( this.parent_view_controller.sub_user_language_view_controller ) !== 'undefined':
this.parent_view_controller.sub_user_language_view_controller.unSelectAll();
break;
}
}
onAddClick() {
if ( this.sub_view_mode ) {
this.buildContextMenu( true );
}
super.onAddClick();
}
onMassEditClick() {
var $this = this;
$this.is_add = false;
$this.is_viewing = false;
$this.is_mass_editing = true;
LocalCacheData.current_doing_context_action = 'mass_edit';
$this.openEditView();
var filter = {};
var grid_selected_id_array = this.getGridSelectIdArray();
var grid_selected_length = grid_selected_id_array.length;
this.mass_edit_record_ids = [];
$.each( grid_selected_id_array, function( index, value ) {
$this.mass_edit_record_ids.push( value );
} );
filter.filter_data = {};
filter.filter_data.id = this.mass_edit_record_ids;
this.api['getCommon' + this.api.key_name + 'Data']( filter, {
onResult: function( result ) {
var result_data = result.getResult();
$this.unique_columns = {};
$this.linked_columns = {};
if ( !result_data ) {
result_data = [];
}
if ( $this.sub_view_mode && $this.parent_key ) {
result_data[$this.parent_key] = $this.parent_value;
}
$this.current_edit_record = result_data;
$this.initEditView();
}
} );
}
buildEditViewUI() {
super.buildEditViewUI();
var $this = this;
var tab_model = {
'tab_membership': {
'label': $.i18n._( 'Membership' )
},
'tab_attachment': true,
'tab_audit': true,
};
this.setTabModel( tab_model );
this.navigation.AComboBox( {
api_class: TTAPI.APIUserMembership,
id: this.script_name + '_navigation',
allow_multiple_selection: false,
layout_name: 'global_user_membership',
navigation_mode: true,
show_search_inputs: true
} );
this.setNavigation();
//Tab 0 start
var tab_membership = this.edit_view_tab.find( '#tab_membership' );
var tab_membership_column1 = tab_membership.find( '.first-column' );
this.edit_view_tabs[0] = [];
this.edit_view_tabs[0].push( tab_membership_column1 );
// Employee
var form_item_input = Global.loadWidgetByName( FormItemType.AWESOME_BOX );
form_item_input.AComboBox( {
api_class: TTAPI.APIUser,
allow_multiple_selection: true,
layout_name: 'global_user',
field: 'user_id',
set_empty: true,
show_search_inputs: true
} );
var default_args = {};
default_args.permission_section = 'user_membership';
form_item_input.setDefaultArgs( default_args );
this.addEditFieldToColumn( $.i18n._( 'Employee' ), form_item_input, tab_membership_column1, '' );
// Membership
var args = {};
var filter_data = {};
filter_data.type_id = [50];
filter_data.visibility_type_id = [10, 100]; //10=Internal Only, 100=Both
args.filter_data = filter_data;
form_item_input = Global.loadWidgetByName( FormItemType.AWESOME_BOX );
form_item_input.AComboBox( {
api_class: TTAPI.APIQualification,
allow_multiple_selection: false,
layout_name: 'global_qualification',
show_search_inputs: true,
set_empty: true,
field: 'qualification_id'
} );
form_item_input.setDefaultArgs( args );
this.addEditFieldToColumn( $.i18n._( 'Membership' ), form_item_input, tab_membership_column1 );
form_item_input = Global.loadWidgetByName( FormItemType.SEPARATED_BOX );
form_item_input.SeparatedBox( { label: $.i18n._( 'Membership Subscription' ) } );
this.addEditFieldToColumn( null, form_item_input, tab_membership_column1 );
// Ownership
form_item_input = Global.loadWidgetByName( FormItemType.COMBO_BOX );
form_item_input.TComboBox( { field: 'ownership_id' } );
form_item_input.setSourceData( $this.ownership_array );
this.addEditFieldToColumn( $.i18n._( 'Ownership' ), form_item_input, tab_membership_column1 );
// Currency
form_item_input = Global.loadWidgetByName( FormItemType.AWESOME_BOX );
form_item_input.AComboBox( {
api_class: TTAPI.APICurrency,
allow_multiple_selection: false,
layout_name: 'global_currency',
field: 'currency_id',
set_empty: true,
show_search_inputs: true
} );
this.addEditFieldToColumn( $.i18n._( 'Currency' ), form_item_input, tab_membership_column1 );
//Amount
form_item_input = Global.loadWidgetByName( FormItemType.TEXT_INPUT );
form_item_input.TTextInput( { field: 'amount', width: 50 } );
this.addEditFieldToColumn( $.i18n._( 'Amount' ), form_item_input, tab_membership_column1 );
// Start Date
form_item_input = Global.loadWidgetByName( FormItemType.DATE_PICKER );
form_item_input.TDatePicker( { field: 'start_date' } );
this.addEditFieldToColumn( $.i18n._( 'Start Date' ), form_item_input, tab_membership_column1, '', null );
// Renewal Date
form_item_input = Global.loadWidgetByName( FormItemType.DATE_PICKER );
form_item_input.TDatePicker( { field: 'renewal_date' } );
this.addEditFieldToColumn( $.i18n._( 'Renewal Date' ), form_item_input, tab_membership_column1, '', null );
//Tags
form_item_input = Global.loadWidgetByName( FormItemType.TAG_INPUT );
form_item_input.TTagInput( { field: 'tag', object_type_id: 255 } );
this.addEditFieldToColumn( $.i18n._( 'Tags' ), form_item_input, tab_membership_column1, '', null, null, true );
}
buildSearchFields() {
super.buildSearchFields();
var default_args = {};
default_args.permission_section = 'user_membership';
this.search_fields = [
new SearchField( {
label: $.i18n._( 'Employee' ),
in_column: 1,
field: 'user_id',
default_args: default_args,
layout_name: 'global_user',
api_class: TTAPI.APIUser,
multiple: true,
basic_search: true,
adv_search: true,
form_item_type: FormItemType.AWESOME_BOX
} ),
new SearchField( {
label: $.i18n._( 'Currency' ),
in_column: 1,
field: 'currency_id',
layout_name: 'global_currency',
api_class: TTAPI.APICurrency,
multiple: true,
basic_search: false,
adv_search: true,
form_item_type: FormItemType.AWESOME_BOX
} ),
new SearchField( {
label: $.i18n._( 'Membership' ),
in_column: 1,
field: 'qualification_id',
layout_name: 'global_qualification',
api_class: TTAPI.APIQualification,
multiple: true,
basic_search: true,
adv_search: true,
form_item_type: FormItemType.AWESOME_BOX
} ),
new SearchField( {
label: $.i18n._( 'Ownership' ),
in_column: 1,
field: 'ownership_id',
multiple: true,
basic_search: true,
adv_search: true,
layout_name: 'global_option_column',
form_item_type: FormItemType.AWESOME_BOX
} ),
new SearchField( {
label: $.i18n._( 'Tags' ),
field: 'tag',
basic_search: true,
adv_search: true,
in_column: 1,
object_type_id: 255,
form_item_type: FormItemType.TAG_INPUT
} ),
new SearchField( {
label: $.i18n._( 'Group' ),
in_column: 2,
multiple: true,
field: 'group_id',
layout_name: 'global_tree_column',
tree_mode: true,
basic_search: true,
adv_search: true,
form_item_type: FormItemType.AWESOME_BOX
} ),
new SearchField( {
label: $.i18n._( 'Source' ),
in_column: 2,
multiple: true,
field: 'source_type_id',
basic_search: true,
adv_search: true,
layout_name: 'global_option_column',
form_item_type: FormItemType.AWESOME_BOX
} ),
new SearchField( {
label: $.i18n._( 'Start Date' ),
in_column: 2,
field: 'start_date',
tree_mode: true,
basic_search: false,
adv_search: true,
form_item_type: FormItemType.DATE_PICKER
} ),
new SearchField( {
label: $.i18n._( 'Renwal Date' ),
in_column: 2,
field: 'renewal_date',
tree_mode: true,
basic_search: false,
adv_search: true,
form_item_type: FormItemType.DATE_PICKER
} ),
new SearchField( {
label: $.i18n._( 'Created By' ),
in_column: 2,
field: 'created_by',
layout_name: 'global_user',
api_class: TTAPI.APIUser,
multiple: true,
basic_search: false,
adv_search: true,
form_item_type: FormItemType.AWESOME_BOX
} ),
new SearchField( {
label: $.i18n._( 'Updated By' ),
in_column: 2,
field: 'updated_by',
layout_name: 'global_user',
api_class: TTAPI.APIUser,
multiple: true,
basic_search: false,
adv_search: true,
form_item_type: FormItemType.AWESOME_BOX
} )
];
}
searchDone() {
super.searchDone();
TTPromise.resolve( 'Employee_Qualifications_Tab', 'UserMembershipViewController' );
}
uniformVariable( records ) {
if ( Global.isArray( records.user_id ) && records.user_id.length > 0 ) {
let new_records = [];
for ( let key in records.user_id ) {
new_records.push( Object.assign( {}, records, { user_id: records.user_id[key] } ) );
}
return new_records;
}
return records;
}
}
UserMembershipViewController.loadSubView = function( container, beforeViewLoadedFun, afterViewLoadedFun ) {
Global.loadViewSource( 'UserMembership', 'SubUserMembershipView.html', function( result ) {
var args = {};
var template = _.template( result );
if ( Global.isSet( beforeViewLoadedFun ) ) {
beforeViewLoadedFun();
}
if ( Global.isSet( container ) ) {
container.html( template( args ) );
if ( Global.isSet( afterViewLoadedFun ) ) {
afterViewLoadedFun( sub_user_membership_view_controller );
}
}
} );
};