").dxList( {
// dataSource is set later
displayExpr : "fullName",
keyExpr : "fspro_userId",
selectionMode : "multiple",
searchEnabled : true,
searchExpr : "fullName",
searchMode : "contains",
showSelectionControls : true,
pageLoadMode : "scrollBottom",
onOptionChanged : function( e ) {
if( e.name == "selectedItems" ) {
if( e.value && e.value.length ) {
selectionCountElement.text( `${e.value.length} users selected` );
instance.addButton.option( "disabled", false );
} else {
selectionCountElement.empty();
instance.addButton.option( "disabled", true );
}
}
}
}).dxList( "instance" );
popup = $("
").dxPopup( {
title : "Add Staff",
hideOnOutsideClick : true,
width : 400,
height : 400,
contentTemplate : function() {
let box = $("
").dxBox( {
height : "100%",
direction : "col",
items : [
{
baseSize : 35,
template : function() {
return instance.groupFilter.element();
}
},
{
ratio : 1,
template : function() {
return instance.userList.element();
}
}
]
})
return box;
},
toolbarItems : [
{
toolbar : "bottom",
location : "before",
template : function() {
return selectionCountElement;
}
},
{
toolbar : "bottom",
location : "after",
template : function() {
return instance.addButton.element();
}
}
],
onHidden : function( e ) {
e.component.element().remove();
e.component.dispose();
},
onShown : function( e ) {
instance._setStaffListDataSource();
}
}).dxPopup( "instance" );
popup.element().appendTo( $("body"));
popup.show();
return pickPromise;
}
ObjectiveStaffPicker.prototype._setStaffListDataSource = function( groupId ) {
let instance = this;
let existingStaffStore = new DevExpress.data.ArrayStore( { data : instance.existingStaff, key : "fspro_userId" } );
let objectParams = {};
if( groupId ) {
objectParams.groupId = groupId
}
let territoryFilter = [];
instance.territories.forEach( function( territory ) {
if( territoryFilter.length ) territoryFilter.push( "or" );
territoryFilter.push( [ "territoryIdList", "contains", `#${territory.territoryId};` ] );
})
if( territoryFilter.length == 0 ) territoryFilter = null;
let salesRepDataSource = Fse.Data.newDataSource( { object : "CRM.salesRepList", key : "fspro_userId", paginate : false, filter : territoryFilter,
objectParams : objectParams,
map : function( item ) {
existingStaffStore.byKey( item.fspro_userId ).done( function() {
item.disabled = true;
}).fail( function() {
item.disabled = false;
})
return item;
}
} );
instance.userList.option( "dataSource", salesRepDataSource );
}