TimeTrex Community Edition v16.2.0
This commit is contained in:
208
interface/html5/views/common/AuthorizationHistoryCommon.js
Normal file
208
interface/html5/views/common/AuthorizationHistoryCommon.js
Normal file
@@ -0,0 +1,208 @@
|
||||
export var AuthorizationHistory = {
|
||||
|
||||
/**
|
||||
* There's only 4 steps for ading auth history to a view file:
|
||||
* 1. Copy the authorization-grid-div from RequestEditView.html
|
||||
* 2. Paste that div into the editview html of the new view
|
||||
* 3. Add AuthorizationHistory.init(this) to setEditViewDataDone() or to the end of onViewClick() if you experience screen flashing with it in setEditViewDataDone()
|
||||
* 4a.If the view only has one hierarchytype id, add this.hierarchy_type_id = [**the correct id**]; to the init function of the view
|
||||
* 4b.Else, ensure that hierarch_type_id is set in the view's current_edit_record
|
||||
*
|
||||
*/
|
||||
|
||||
authorization_api: null,
|
||||
authorization_history_columns: [],
|
||||
authorization_history_default_display_columns: [],
|
||||
|
||||
host_view_controller: null,
|
||||
|
||||
/**
|
||||
* call this to render the auth grid.
|
||||
* assumes this.edit_view exists.
|
||||
* @param $this
|
||||
* @returns {AuthorizationHistory}
|
||||
*/
|
||||
init: function( host ) {
|
||||
$( '.authorization-grid-div' ).hide();
|
||||
if ( host.is_add ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var separate_box = $( '.authorization-grid-div .grid-title' );
|
||||
separate_box.html( '' );
|
||||
|
||||
var form_item_input = Global.loadWidgetByName( FormItemType.SEPARATED_BOX );
|
||||
form_item_input.SeparatedBox( { label: $.i18n._( 'Authorization History' ) } );
|
||||
form_item_input.attr( 'id', 'authorization_history' );
|
||||
host.addEditFieldToColumn( null, form_item_input, separate_box );
|
||||
|
||||
this.host_view_controller = host;
|
||||
this.authorization_api = TTAPI.APIAuthorization;
|
||||
|
||||
var $this = this;
|
||||
this.getAuthorizationHistoryColumns( function() {
|
||||
$this.initAuthorizationHistoryLayout( function() {
|
||||
$this.setAuthorizationGridSize();
|
||||
} );
|
||||
} );
|
||||
|
||||
return $this;
|
||||
},
|
||||
|
||||
initAuthorizationHistoryLayout: function( callback ) {
|
||||
var $this = this;
|
||||
this.getAuthorizationHistoryDefaultDisplayColumns( function() {
|
||||
if ( !$this.host_view_controller.edit_view ) {
|
||||
return;
|
||||
}
|
||||
$this.setAuthorizationHistorySelectLayout();
|
||||
$this.initAuthorizationHistoryData();
|
||||
if ( callback ) {
|
||||
callback();
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets data from the API and puts it into the authorization history grid.
|
||||
*
|
||||
* @param callback
|
||||
*/
|
||||
initAuthorizationHistoryData: function( callback ) {
|
||||
var filter = {};
|
||||
filter.filter_data = {};
|
||||
|
||||
filter.filter_columns = { 'created_by': true, 'created_date': true, 'authorized': true };
|
||||
filter.filter_data.object_id = [this.host_view_controller.current_edit_record.id];
|
||||
filter.filter_data.object_type_id = this.host_view_controller.hierarchy_type_id ? this.host_view_controller.hierarchy_type_id : this.host_view_controller.current_edit_record.hierarchy_type_id;
|
||||
|
||||
var $this = this;
|
||||
this.authorization_api['get' + this.authorization_api.key_name]( filter, {
|
||||
onResult: function( result ) {
|
||||
|
||||
if ( !$this.host_view_controller.edit_view ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var result_data = result.getResult();
|
||||
if ( result.isValid() && Global.isArray( result_data ) && result_data.length >= 1 ) {
|
||||
result_data = Global.formatGridData( result_data, $this.authorization_api.key_name );
|
||||
|
||||
$this.authorization_history_grid.setData( result_data );
|
||||
|
||||
$( $this.host_view_controller.edit_view.find( '.authorization-grid-div' ) ).show();
|
||||
$this.showAuthorizationHistoryGridBorders();
|
||||
$this.setAuthorizationGridSize();
|
||||
} else {
|
||||
$( $this.host_view_controller.edit_view.find( '.authorization-grid-div' ) ).hide();
|
||||
}
|
||||
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
setAuthorizationGridSize: function() {
|
||||
var history_height_unit;
|
||||
if ( ( !this.authorization_history_grid || !this.authorization_history_grid.grid.is( ':visible' ) ) ) {
|
||||
return;
|
||||
}
|
||||
history_height_unit = this.authorization_history_grid.getData().length;
|
||||
history_height_unit > 5 && ( history_height_unit = 5 );
|
||||
this.authorization_history_grid.grid.setGridWidth( $( this.host_view_controller.edit_view.find( '#authorization_history' ) ).width() );
|
||||
this.authorization_history_grid.grid.setGridHeight( history_height_unit * 25 );
|
||||
},
|
||||
|
||||
buildAuthorizationDisplayColumns: function( apiDisplayColumnsArray ) {
|
||||
var len = this.authorization_history_columns.length;
|
||||
var len1 = apiDisplayColumnsArray.length;
|
||||
var display_columns = [];
|
||||
|
||||
for ( var j = 0; j < len1; j++ ) {
|
||||
for ( var i = 0; i < len; i++ ) {
|
||||
if ( apiDisplayColumnsArray[j] === this.authorization_history_columns[i].value ) {
|
||||
display_columns.push( this.authorization_history_columns[i] );
|
||||
}
|
||||
}
|
||||
}
|
||||
return display_columns;
|
||||
},
|
||||
|
||||
showAuthorizationHistoryGridBorders: function() {
|
||||
var top_border = this.host_view_controller.edit_view.find( '.grid-top-border' );
|
||||
var bottom_border = this.host_view_controller.edit_view.find( '.grid-bottom-border' );
|
||||
|
||||
top_border.css( 'display', 'block' );
|
||||
bottom_border.css( 'display', 'block' );
|
||||
},
|
||||
|
||||
getAuthorizationHistoryDefaultDisplayColumns: function( callBack ) {
|
||||
var $this = this;
|
||||
this.authorization_api.getOptions( 'default_display_columns', {
|
||||
onResult: function( columns_result ) {
|
||||
var columns_result_data = columns_result.getResult();
|
||||
|
||||
$this.authorization_history_default_display_columns = columns_result_data;
|
||||
|
||||
if ( callBack ) {
|
||||
callBack();
|
||||
}
|
||||
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
getAuthorizationHistoryColumns: function( callBack ) {
|
||||
var $this = this;
|
||||
this.authorization_api.getOptions( 'columns', {
|
||||
onResult: function( columns_result ) {
|
||||
var columns_result_data = columns_result.getResult();
|
||||
$this.authorization_history_columns = Global.buildColumnArray( columns_result_data );
|
||||
|
||||
if ( callBack ) {
|
||||
callBack();
|
||||
}
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
setAuthorizationHistorySelectLayout: function( column_start_from ) {
|
||||
var $this = this;
|
||||
var grid = this.host_view_controller.edit_view.find( '#grid' );
|
||||
if ( grid ) {
|
||||
grid.attr( 'id', 'authorization_history_grid' ); //Grid's id is ScriptName + _grid
|
||||
}
|
||||
var column_info_array = [];
|
||||
var display_columns = this.buildAuthorizationDisplayColumns( this.authorization_history_default_display_columns );
|
||||
|
||||
//Set Data Grid on List view
|
||||
var len = display_columns.length;
|
||||
|
||||
for ( var i = 0; i < len; i++ ) {
|
||||
var view_column_data = display_columns[i];
|
||||
|
||||
var column_info = {
|
||||
name: view_column_data.value,
|
||||
index: view_column_data.value,
|
||||
label: view_column_data.label,
|
||||
width: 100,
|
||||
sortable: false,
|
||||
title: false
|
||||
};
|
||||
column_info_array.push( column_info );
|
||||
}
|
||||
|
||||
if ( this.authorization_history_grid ) {
|
||||
|
||||
this.authorization_history_grid.grid.jqGrid( 'GridUnload' );
|
||||
this.authorization_history_grid = null;
|
||||
}
|
||||
|
||||
this.authorization_history_grid = new TTGrid( 'authorization_history_grid', {
|
||||
onResizeGrid: false,
|
||||
winMultiselect: false,
|
||||
multiselect: false,
|
||||
width: this.host_view_controller.edit_view.find( '.edit-view-tab' ).width()
|
||||
}, column_info_array );
|
||||
}
|
||||
|
||||
};
|
521
interface/html5/views/common/BaseTreeViewController.js
Normal file
521
interface/html5/views/common/BaseTreeViewController.js
Normal file
@@ -0,0 +1,521 @@
|
||||
export class BaseTreeViewController extends BaseViewController {
|
||||
setSelectLayout( column_start_from ) {
|
||||
var $this = this;
|
||||
|
||||
var grid;
|
||||
if ( !Global.isSet( this.grid ) ) {
|
||||
grid = $( this.el ).find( '#grid' );
|
||||
|
||||
grid.attr( 'id', this.ui_id + '_grid' ); //Grid's id is ScriptName + _grid
|
||||
|
||||
grid = $( this.el ).find( '#' + this.ui_id + '_grid' );
|
||||
}
|
||||
|
||||
var column_info_array = [];
|
||||
|
||||
if ( !this.select_layout ) { //Set to defalt layout if no layout at all
|
||||
this.select_layout = { id: '' };
|
||||
this.select_layout.data = { filter_data: {}, filter_sort: {} };
|
||||
this.select_layout.data.display_columns = this.default_display_columns;
|
||||
}
|
||||
var layout_data = this.select_layout.data;
|
||||
|
||||
if ( layout_data.display_columns.length < 1 ) {
|
||||
layout_data.display_columns = this.default_display_columns;
|
||||
}
|
||||
|
||||
var display_columns = this.buildDisplayColumns( layout_data.display_columns );
|
||||
//Set Data Grid on List view
|
||||
var len = display_columns.length;
|
||||
|
||||
var start_from = 0;
|
||||
|
||||
if ( Global.isSet( column_start_from ) && column_start_from > 0 ) {
|
||||
start_from = column_start_from;
|
||||
}
|
||||
|
||||
var view_column_data = display_columns[0];
|
||||
|
||||
var column_info = {
|
||||
name: view_column_data.value,
|
||||
index: view_column_data.value,
|
||||
label: $this.grid_table_name,
|
||||
width: 100,
|
||||
sortable: false,
|
||||
title: false
|
||||
};
|
||||
|
||||
column_info_array.push( column_info );
|
||||
|
||||
if ( this.grid ) {
|
||||
this.grid.jqGrid( 'GridUnload' );
|
||||
this.grid = null;
|
||||
}
|
||||
|
||||
this.grid = new TTGrid( this.ui_id + '_grid', {
|
||||
multiselect: false,
|
||||
winMultiSelect: false,
|
||||
tree_mode: true,
|
||||
onSelectRow: $.proxy( this.onGridSelectRow, this )
|
||||
}, column_info_array );
|
||||
|
||||
this.bindGridColumnEvents();
|
||||
|
||||
this.setGridHeaderStyle(); //Set Sort Style
|
||||
|
||||
this.filter_data = this.select_layout.data.filter_data;
|
||||
|
||||
this.showGridBorders();
|
||||
|
||||
$this.setGridSize();
|
||||
}
|
||||
|
||||
search( set_default_menu, page_action, page_number ) {
|
||||
var $this = this;
|
||||
|
||||
if ( !Global.isSet( set_default_menu ) ) {
|
||||
set_default_menu = true;
|
||||
}
|
||||
|
||||
var filter = {};
|
||||
filter.filter_data = {};
|
||||
filter.filter_sort = {};
|
||||
filter.filter_columns = this.getFilterColumnsFromDisplayColumns();
|
||||
filter.filter_items_per_page = 0; // Default to 0 to load user preference defined
|
||||
|
||||
if ( this.sub_view_mode && this.parent_key ) {
|
||||
this.select_layout.data.filter_data[this.parent_key] = this.parent_value;
|
||||
|
||||
//If sub view controller set custom filters, get it
|
||||
if ( Global.isSet( this.getSubViewFilter ) ) {
|
||||
|
||||
this.select_layout.data.filter_data = this.getSubViewFilter( this.select_layout.data.filter_data );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
this.last_select_ids = this.getGridSelectIdArray();
|
||||
//select_layout will not be null, it's set in setSelectLayout function
|
||||
filter.filter_data = Global.convertLayoutFilterToAPIFilter( this.select_layout );
|
||||
filter.filter_sort = this.select_layout.data.filter_sort;
|
||||
|
||||
this.api['get' + this.api.key_name]( filter, false, false, {
|
||||
onResult: function( result ) {
|
||||
|
||||
var result_data = result.getResult();
|
||||
|
||||
result_data = Global.buildTreeRecord( result_data );
|
||||
|
||||
$this.grid_current_page_items = result_data; // For tree mode only
|
||||
|
||||
if ( !Global.isArray( result_data ) ) {
|
||||
$this.showNoResultCover();
|
||||
} else {
|
||||
$this.removeNoResultCover();
|
||||
}
|
||||
|
||||
$this.reSetGridTreeData( result_data );
|
||||
|
||||
$this.setGridSize();
|
||||
|
||||
ProgressBar.closeOverlay(); //Add this in initData
|
||||
if ( set_default_menu ) {
|
||||
$this.setDefaultMenu();
|
||||
}
|
||||
|
||||
if ( LocalCacheData.paging_type === 0 ) {
|
||||
if ( !$this.pager_data || $this.pager_data.is_last_page ) {
|
||||
$this.paging_widget.css( 'display', 'none' );
|
||||
} else {
|
||||
$this.paging_widget.css( 'display', 'block' );
|
||||
}
|
||||
}
|
||||
|
||||
$this.reSelectLastSelectItems();
|
||||
$this.autoOpenEditViewIfNecessary();
|
||||
$this.searchDone();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
setDefaultMenu( doNotSetFocus ) {
|
||||
var selected_row = this.getSelectedItem();
|
||||
var context_menu_array = ContextMenuManager.getMenuModelByMenuId( this.determineContextMenuMountAttributes().id );
|
||||
|
||||
//If selected root group, disable all context menu icons other than add. Otherwise blank view opens that might be difficult for user to exit when clicking edit or view.
|
||||
if ( selected_row !== null && selected_row.id == TTUUID.zero_id ) {
|
||||
var len = context_menu_array.length;
|
||||
|
||||
var grid_selected_id_array = this.getGridSelectIdArray();
|
||||
|
||||
var grid_selected_length = grid_selected_id_array.length;
|
||||
|
||||
for ( var i = 0; i < len; i++ ) {
|
||||
let context_btn = context_menu_array[i];
|
||||
let id = context_menu_array[i].id;
|
||||
|
||||
if ( id == 'add' ) {
|
||||
this.setDefaultMenuAddIcon( context_btn, grid_selected_length );
|
||||
} else {
|
||||
ContextMenuManager.disableMenuItem( this.determineContextMenuMountAttributes().id, context_btn.id, false );
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
super.setDefaultMenu( doNotSetFocus );
|
||||
}
|
||||
|
||||
onEditClick( record_id, noRefreshUI ) {
|
||||
if ( record_id === TTUUID.zero_id ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
super.onEditClick( record_id, noRefreshUI );
|
||||
}
|
||||
|
||||
reSetGridTreeData( val ) {
|
||||
var $this = this;
|
||||
|
||||
var col_model = this.grid.getGridParam( 'colModel' );
|
||||
this.grid.grid.jqGrid( 'GridUnload' );
|
||||
this.grid = null;
|
||||
|
||||
this.grid = new TTGrid( this.ui_id + '_grid', {
|
||||
multiselect: false,
|
||||
winMultiSelect: false,
|
||||
datastr: val,
|
||||
datatype: 'jsonstring',
|
||||
sortable: false,
|
||||
onSelectRow: function( id ) {
|
||||
$( '#ribbon_view_container .context-menu:visible a' ).click();
|
||||
$this.grid_select_id_array = [id];
|
||||
$this.setDefaultMenu();
|
||||
|
||||
},
|
||||
ondblClickRow: function() {
|
||||
//Do not open root group item as it cannot be edited and produces weird results if opened.
|
||||
if ( $this.getEditSelectedRecordId() !== TTUUID.zero_id ) {
|
||||
$this.onGridDblClickRow();
|
||||
}
|
||||
},
|
||||
gridview: true,
|
||||
treeGrid: true,
|
||||
treeGridModel: 'adjacency',
|
||||
treedatatype: 'local',
|
||||
ExpandColumn: 'name',
|
||||
}, col_model );
|
||||
}
|
||||
|
||||
getGridSelectIdArray() {
|
||||
var result = [];
|
||||
result = this.grid_select_id_array;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
initLayout() {
|
||||
var $this = this;
|
||||
this.real_this = this.constructor.__super__; // this seems first entry point. needed where view controller is extended twice, Base->Tree-View, used with onViewClick _super
|
||||
|
||||
$this.getDefaultDisplayColumns( function() {
|
||||
$this.setSelectLayout();
|
||||
$this.search();
|
||||
} );
|
||||
}
|
||||
|
||||
getAllColumns( callBack ) {
|
||||
var $this = this;
|
||||
|
||||
this.api.getOptions( 'columns', {
|
||||
onResult: function( columns_result ) {
|
||||
|
||||
var columns_result_data = columns_result.getResult();
|
||||
$this.all_columns = Global.buildColumnArray( columns_result_data );
|
||||
|
||||
if ( callBack ) {
|
||||
callBack();
|
||||
}
|
||||
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
setCurrentEditRecordData() {
|
||||
//Set current edit record data to all widgets
|
||||
for ( var key in this.current_edit_record ) {
|
||||
var widget = this.edit_view_ui_dic[key];
|
||||
if ( Global.isSet( widget ) ) {
|
||||
switch ( key ) {
|
||||
case 'parent_id':
|
||||
widget.setSourceData( this.grid_current_page_items );
|
||||
widget.setValue( this.current_edit_record[key] );
|
||||
break;
|
||||
default:
|
||||
widget.setValue( this.current_edit_record[key] );
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
this.collectUIDataToCurrentEditRecord();
|
||||
this.setEditViewDataDone();
|
||||
}
|
||||
|
||||
setEditViewData() {
|
||||
var $this = this;
|
||||
|
||||
this.is_changed = false;
|
||||
|
||||
if ( !this.edit_only_mode ) {
|
||||
|
||||
var navigation_div = this.edit_view.find( '.navigation-div' );
|
||||
|
||||
if ( Global.isSet( this.current_edit_record.id ) && this.current_edit_record.id ) {
|
||||
navigation_div.css( 'display', 'block' );
|
||||
//Set Navigation Awesomebox
|
||||
|
||||
//init navigation only when open edit view
|
||||
if ( !this.navigation.getSourceData() ) {
|
||||
this.navigation.setSourceData( this.grid_current_page_items.filter( grid_item => grid_item.id !== TTUUID.zero_id ) );
|
||||
|
||||
var default_args = {};
|
||||
default_args.filter_data = Global.convertLayoutFilterToAPIFilter( this.select_layout );
|
||||
default_args.filter_sort = this.select_layout.data.filter_sort;
|
||||
this.navigation.setDefaultArgs( default_args );
|
||||
}
|
||||
|
||||
this.navigation.setValue( this.current_edit_record );
|
||||
|
||||
} else {
|
||||
navigation_div.css( 'display', 'none' );
|
||||
}
|
||||
}
|
||||
|
||||
for ( var key in this.edit_view_ui_dic ) {
|
||||
|
||||
//Set all UI field to current edit reocrd, we need validate all UI fielld when save and validate
|
||||
if ( !Global.isSet( $this.current_edit_record[key] ) && !this.is_mass_editing ) {
|
||||
$this.current_edit_record[key] = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.setNavigationArrowsStatus();
|
||||
this.setNavigationArrowsEnabled();
|
||||
|
||||
// Create this function alone because of the column value of view is different from each other, some columns need to be handle specially. and easily to rewrite this function in sub-class.
|
||||
|
||||
this.setCurrentEditRecordData();
|
||||
|
||||
//Init *Please save this record before modifying any related data* box
|
||||
this.edit_view.find( '.save-and-continue-div' ).SaveAndContinueBox( { related_view_controller: this } );
|
||||
this.edit_view.find( '.save-and-continue-div' ).css( 'display', 'none' );
|
||||
|
||||
if ( this.edit_view_tab.tabs( 'option', 'active' ) === 1 ) {
|
||||
if ( this.current_edit_record.id ) {
|
||||
this.edit_view_tab.find( '#tab_audit' ).find( '.first-column-sub-view' ).css( 'display', 'block' );
|
||||
this.initSubLogView( 'tab_audit' );
|
||||
} else {
|
||||
this.edit_view_tab.find( '#tab_audit' ).find( '.first-column-sub-view' ).css( 'display', 'none' );
|
||||
this.edit_view.find( '.save-and-continue-div' ).css( 'display', 'block' );
|
||||
}
|
||||
}
|
||||
this.switchToProperTab();
|
||||
}
|
||||
|
||||
addIdFieldToNavigation( array ) {
|
||||
$.each( array, function( key, item ) {
|
||||
$( item ).each( function( i_key, i_item ) {
|
||||
i_item.id = i_item._id_;
|
||||
} );
|
||||
} );
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
doViewAPICall( filter ) {
|
||||
return super.doViewAPICall( filter, [filter, false, false] );
|
||||
}
|
||||
|
||||
handleViewAPICallbackResult( result ) {
|
||||
return this.handleAPICallbackResult( result );
|
||||
}
|
||||
|
||||
handleAPICallbackResult( result ) {
|
||||
var result_data = result.getResult();
|
||||
var record_id = this.getCurrentSelectedRecord();
|
||||
result_data = Global.getParentIdByTreeRecord( Global.buildTreeRecord( result_data ), record_id );
|
||||
result_data = result_data[0];
|
||||
result_data.id = record_id;
|
||||
|
||||
super.handleViewAPICallbackResult( result_data );
|
||||
}
|
||||
|
||||
handleEditAPICallbackResult( result ) {
|
||||
return this.handleAPICallbackResult( result );
|
||||
}
|
||||
|
||||
onDeleteDone( result ) {
|
||||
this.grid_select_id_array = [];
|
||||
this.setDefaultMenu();
|
||||
this.removeDeletedRows();
|
||||
}
|
||||
|
||||
onSaveDone( result ) {
|
||||
this.grid_select_id_array = [];
|
||||
}
|
||||
|
||||
doEditAPICall( filter ) {
|
||||
return super.doEditAPICall( filter, [filter, false, false] );
|
||||
}
|
||||
|
||||
_continueDoCopyAsNew() {
|
||||
var $this = this;
|
||||
this.setCurrentEditViewState( 'new' );
|
||||
LocalCacheData.current_doing_context_action = 'copy_as_new';
|
||||
|
||||
if ( Global.isSet( this.edit_view ) ) {
|
||||
|
||||
this.current_edit_record.id = '';
|
||||
var navigation_div = this.edit_view.find( '.navigation-div' );
|
||||
navigation_div.css( 'display', 'none' );
|
||||
this.setEditMenu();
|
||||
this.setTabStatus();
|
||||
this.is_changed = false;
|
||||
ProgressBar.closeOverlay();
|
||||
|
||||
} else {
|
||||
var filter = {};
|
||||
var grid_selected_id_array = this.getGridSelectIdArray();
|
||||
var grid_selected_length = grid_selected_id_array.length;
|
||||
|
||||
if ( grid_selected_length > 0 ) {
|
||||
var selectedId = grid_selected_id_array[0];
|
||||
} else {
|
||||
TAlertManager.showAlert( $.i18n._( 'No selected record' ) );
|
||||
return;
|
||||
}
|
||||
|
||||
filter.filter_data = {};
|
||||
|
||||
this.api['get' + this.api.key_name]( filter, false, false, {
|
||||
onResult: function( result ) {
|
||||
var result_data = result.getResult();
|
||||
result_data = Global.buildTreeRecord( result_data );
|
||||
result_data = Global.getParentIdByTreeRecord( result_data, selectedId );
|
||||
|
||||
if ( !result_data ) {
|
||||
TAlertManager.showAlert( $.i18n._( 'Record does not exist' ) );
|
||||
$this.onCancelClick();
|
||||
return;
|
||||
}
|
||||
|
||||
$this.openEditView(); // Put it here is to avoid if the selected one is not existed in data or have deleted by other pragram. in this case, the edit view should not be opend.
|
||||
|
||||
result_data = result_data[0];
|
||||
if ( $this.sub_view_mode && $this.parent_key ) {
|
||||
result_data[$this.parent_key] = $this.parent_value;
|
||||
}
|
||||
|
||||
$this.current_edit_record = result_data;
|
||||
$this.current_edit_record.id = '';
|
||||
|
||||
$this.initEditView();
|
||||
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
buildEditViewUI() {
|
||||
var $this = this;
|
||||
|
||||
// #VueContextMenu# After we add the edit_view to the page in initEditViewUI(), add the context menu (Vue needs a valid id in dom)
|
||||
if( ContextMenuManager.getMenu( this.determineContextMenuMountAttributes().id ) === undefined ) {
|
||||
this.buildContextMenu();
|
||||
} else {
|
||||
Debug.Warn( 'Context Menu ('+ this.determineContextMenuMountAttributes().id +') already exists for: '+ this.viewId, 'BaseTreeViewController.js', 'BaseTreeViewController', 'buildEditViewUI', 10 );
|
||||
}
|
||||
|
||||
//No navigation when edit only mode
|
||||
if ( !this.edit_only_mode ) {
|
||||
var navigation_div = this.edit_view.find( '.navigation-div' );
|
||||
var label = navigation_div.find( '.navigation-label' );
|
||||
|
||||
var navigation_widget_div = navigation_div.find( '.navigation-widget-div' );
|
||||
|
||||
this.navigation = Global.loadWidgetByName( FormItemType.AWESOME_BOX );
|
||||
|
||||
label.text( this.navigation_label );
|
||||
|
||||
navigation_widget_div.append( this.navigation );
|
||||
}
|
||||
|
||||
this.edit_view_close_icon = this.edit_view.find( '.close-icon' );
|
||||
this.edit_view_close_icon.hide();
|
||||
this.edit_view_close_icon.click( function() {
|
||||
$this.onCloseIconClick();
|
||||
} );
|
||||
|
||||
var tab_model = Array();
|
||||
tab_model[this.primary_tab_key] = { 'label': this.primary_tab_label };
|
||||
tab_model['tab_audit'] = {
|
||||
'label': $.i18n._( 'Audit' ),
|
||||
'init_callback': 'initSubLogView',
|
||||
'display_on_mass_edit': false,
|
||||
'display_on_add': false
|
||||
};
|
||||
this.setTabModel( tab_model );
|
||||
|
||||
this.navigation.AComboBox( {
|
||||
id: this.script_name + '_navigation',
|
||||
tree_mode: true,
|
||||
allow_multiple_selection: false,
|
||||
layout_name: 'global_tree_column',
|
||||
navigation_mode: true,
|
||||
show_search_inputs: false,
|
||||
on_tree_grid_row_select: function( id, tree_mode_collapse ) {
|
||||
$this.onTreeGridNavigationRowSelect( id, tree_mode_collapse );
|
||||
}
|
||||
} );
|
||||
|
||||
var left_click = navigation_div.find( '.left-click' );
|
||||
var right_click = navigation_div.find( '.right-click' );
|
||||
left_click.attr( 'src', Global.getRealImagePath( 'images/left_arrow.svg' ) );
|
||||
right_click.attr( 'src', Global.getRealImagePath( 'images/right_arrow.svg' ) );
|
||||
|
||||
this.setNavigation();
|
||||
|
||||
//Tab 0 start
|
||||
var tab_group = this.edit_view_tab.find( '#' + this.primary_tab_key );
|
||||
|
||||
var tab_group_column1 = tab_group.find( '.first-column' );
|
||||
|
||||
this.edit_view_tabs[0] = [];
|
||||
|
||||
this.edit_view_tabs[0].push( tab_group_column1 );
|
||||
|
||||
//Parent
|
||||
//Group
|
||||
var form_item_input = Global.loadWidgetByName( FormItemType.AWESOME_BOX );
|
||||
|
||||
form_item_input.AComboBox( {
|
||||
tree_mode: true,
|
||||
allow_multiple_selection: false,
|
||||
show_search_inputs: false,
|
||||
layout_name: 'global_tree_column',
|
||||
set_empty: true,
|
||||
field: 'parent_id'
|
||||
} );
|
||||
this.addEditFieldToColumn( $.i18n._( 'Parent' ), form_item_input, tab_group_column1, '' );
|
||||
|
||||
//Name
|
||||
form_item_input = Global.loadWidgetByName( FormItemType.TEXT_INPUT );
|
||||
|
||||
form_item_input.TTextInput( { field: 'name', width: '100%' } );
|
||||
this.addEditFieldToColumn( $.i18n._( 'Name' ), form_item_input, tab_group_column1, '' );
|
||||
|
||||
form_item_input.parent().width( '45%' );
|
||||
}
|
||||
}
|
148
interface/html5/views/common/EmbeddedMessageCommon.js
Normal file
148
interface/html5/views/common/EmbeddedMessageCommon.js
Normal file
@@ -0,0 +1,148 @@
|
||||
import linkifyStr from 'linkifyjs/string';
|
||||
export var EmbeddedMessage = {
|
||||
message_control_api: null,
|
||||
event_bus: new TTEventBus({ view_id: 'embedded_message' }),
|
||||
/**
|
||||
* Initializes embedded messages with a call to EmbeddedMessage.init()
|
||||
* Requires that initUI be called when the editviewui is built
|
||||
*
|
||||
* @param item_id (current_edit_record.id)
|
||||
* @param object_type (50 for requests)
|
||||
*/
|
||||
init: function( item_id, object_type, view_object, edit_view, edit_view_tab, edit_view_ui_dic, callback ) {
|
||||
var args = {};
|
||||
args.filter_data = {};
|
||||
args.filter_data.object_type_id = object_type;
|
||||
args.filter_data.object_id = item_id;
|
||||
var read_ids = [];
|
||||
this.message_control_api = TTAPI.APIMessageControl;
|
||||
|
||||
var $this = this;
|
||||
this.message_control_api['getEmbeddedMessage']( args, {
|
||||
onResult: function( res ) {
|
||||
// Error: Uncaught TypeError: Cannot read property 'setValue' of undefined in interface/html5/#!m=RequestAuthorization&id=1306 line 1547
|
||||
if ( !edit_view || !edit_view_ui_dic['from'] ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var data = res.getResult();
|
||||
if ( Global.isArray( data ) ) {
|
||||
$( edit_view.find( '.separate' ) ).css( 'display', 'block' );
|
||||
|
||||
view_object.messages = data;
|
||||
|
||||
var container = $( '<div></div>' );
|
||||
|
||||
for ( var key in data ) {
|
||||
|
||||
var currentItem = data[key];
|
||||
/* jshint ignore:start */
|
||||
if ( currentItem.status_id == 10 ) {
|
||||
read_ids.push( currentItem.id );
|
||||
}
|
||||
/* jshint ignore:end */
|
||||
/**
|
||||
* This can be a little confusing to look at so here's the process:
|
||||
* 1. Set the hidden fields' values
|
||||
* 2. Clone the message template
|
||||
* 3. Append the message templage to container
|
||||
* 4. Append the contents of the the container variable to the visible form
|
||||
*/
|
||||
var from = currentItem.from_first_name + ' ' + currentItem.from_last_name + ' @ ' + currentItem.updated_date;
|
||||
edit_view_ui_dic['from'].setValue( from );
|
||||
|
||||
edit_view_ui_dic['subject'].setValue( Global.htmlDecode( currentItem.subject ) );
|
||||
// The function setValue is not used on the body to avoid double encoding issues on the content as linkify (parses links in text) already handles that.
|
||||
edit_view_ui_dic['body'].html( Global.htmlDecode( currentItem.body ).linkify( { nl2br: true, className: 'linkified' } ) );
|
||||
edit_view_ui_dic['body'].setResizeEvent();
|
||||
|
||||
var cloneMessageControl = $( edit_view_tab.find( '#tab_request' ).find( '.edit-view-tab' ).find( '.embedded-message-template' ) ).clone();
|
||||
cloneMessageControl.removeClass( 'embedded-message-template' );
|
||||
cloneMessageControl.addClass( 'embedded-message-container' );
|
||||
cloneMessageControl.css( 'display', 'block' );
|
||||
cloneMessageControl.css( 'margin', '0px' );
|
||||
cloneMessageControl.appendTo( container );
|
||||
}
|
||||
|
||||
if ( read_ids.length > 0 ) {
|
||||
$this.message_control_api['markRecipientMessageAsRead']( read_ids, {
|
||||
onResult: function( res ) {
|
||||
//commented out as it is needed on the message screen, but not here and results in a big api call we'd rather avoid.
|
||||
//$this.search( false );
|
||||
//Update message badge counts so we do not have a mismatch in badge counts such as when opening a request.
|
||||
$this.event_bus.emit( 'tt_topbar', 'profile_pending_counts', {
|
||||
object_types: [ 'notification', 'message' ]
|
||||
} );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
$( edit_view_tab.find( '#tab_request' ).find( '.edit-view-tab' ).find( '.embedded-message-column' ) ).hide();
|
||||
edit_view_tab.find( '#tab_request' ).find( '.edit-view-tab' ).find( '.embedded-message-container' ).hide();
|
||||
edit_view_tab.find( '#tab_request' ).find( '.edit-view-tab' ).find( '.embedded-message-container' ).remove();
|
||||
edit_view_tab.find( '#tab_request' ).find( '.edit-view-tab' ).append( container.html() );
|
||||
} else {
|
||||
$( edit_view.find( '.separate' ) ).css( 'display', 'none' );
|
||||
}
|
||||
|
||||
callback();
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Requires a full width column with the class embedded-message-template
|
||||
*
|
||||
* @param view_object
|
||||
* @param tab_object
|
||||
*/
|
||||
initUI: function( view_object, tab_object ) {
|
||||
|
||||
var separate_box = tab_object.find( '.separate' ).css( 'display', 'none' );
|
||||
|
||||
// Messages title bar
|
||||
var form_item_input = Global.loadWidgetByName( FormItemType.SEPARATED_BOX );
|
||||
form_item_input.SeparatedBox( { label: $.i18n._( 'Messages' ) } );
|
||||
view_object.addEditFieldToColumn( null, form_item_input, separate_box );
|
||||
|
||||
var column = tab_object.find( '.embedded-message-template' );
|
||||
|
||||
// From
|
||||
form_item_input = Global.loadWidgetByName( FormItemType.TEXT );
|
||||
form_item_input.TText( { field: 'from', selected_able: true } );
|
||||
view_object.addEditFieldToColumn( $.i18n._( 'From' ), form_item_input, column, '' );
|
||||
|
||||
// Subject
|
||||
form_item_input = Global.loadWidgetByName( FormItemType.TEXT );
|
||||
form_item_input.TText( { field: 'subject', selected_able: true } );
|
||||
view_object.addEditFieldToColumn( $.i18n._( 'Subject' ), form_item_input, column );
|
||||
|
||||
// Body
|
||||
form_item_input = Global.loadWidgetByName( FormItemType.TEXT );
|
||||
form_item_input.TText( { field: 'body', width: 600, height: 400, selected_able: true } );
|
||||
view_object.addEditFieldToColumn( $.i18n._( 'Body' ), form_item_input, column, '', null, null, true );
|
||||
|
||||
// Tab 0 second column end
|
||||
view_object.edit_view_tabs[0].push( column );
|
||||
column.css( 'display', 'none' );
|
||||
return;
|
||||
},
|
||||
|
||||
/**
|
||||
* The record array must be an array containing a single record
|
||||
* The callback function must take the result object as an argument
|
||||
*
|
||||
* @param record_array
|
||||
* @param ignoreWarning
|
||||
* @param callback
|
||||
*/
|
||||
reply: function( record_array, ignoreWarning, callback ) {
|
||||
this.message_control_api['setMessageControl']( record_array, false, ignoreWarning, {
|
||||
onResult: function( result ) {
|
||||
if ( callback ) {
|
||||
callback( result );
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
};
|
1498
interface/html5/views/common/RequestViewCommonController.js
Normal file
1498
interface/html5/views/common/RequestViewCommonController.js
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user