ObjectiveRestrictions = function( data, options ) {
let instance = this;
instance.data = $.extend( true, {}, data );
instance.options = $.extend( true, { readOnly : false }, options ? options : {});
instance.data.restrictions = $.extend( true, {
oprSegmentRestrict : null,
oprParentDistributorRestrict : null,
oprDistributorRestrict : null,
oprTypeRestrict : null,
mfrOprTypeRestrict : null,
oprPriorityRestrict : null,
oprAffiliationRestrict : null,
oprAssignedOnlyRestrict : false
}, instance.data.restrictions );
instance.form = null;
instance.updatedPromise = $.Deferred();
}
ObjectiveRestrictions.prototype.construtor = ObjectiveRestrictions;
ObjectiveRestrictions.prototype.element = function() {
let instance = this;
if( instance.rootElement ) return instance.rootElement;
instance.rootElement = $("
").addClass( "ObjectiveRestrictions" );
let priorityTypes = [
{"prioritycode":"*","desc":"A+"},
{"prioritycode":"A","desc":"A"},
{"prioritycode":"B","desc":"B"},
{"prioritycode":"C","desc":"C"},
{"prioritycode":"D","desc":"D"}
];
let formData = {
oprSegmentRestrict : instance.data.restrictions.oprSegmentRestrict,
oprParentDistributorRestrict : instance.data.restrictions.oprParentDistributorRestrict,
oprDistributorRestrict : instance.data.restrictions.oprDistributorRestrict,
oprTypeRestrict : instance.data.restrictions.oprTypeRestrict,
mfrOprTypeRestrict : instance.data.restrictions.mfrOprTypeRestrict,
oprPriorityRestrict : instance.data.restrictions.oprPriorityRestrict,
oprAffiliationRestrict : instance.data.restrictions.oprAffiliationRestrict,
oprAssignedOnlyRestrict : instance.data.restrictions.oprAssignedOnlyRestrict
}
instance.form = $("
").dxForm( {
formData : formData,
items : [
{ dataField : "oprSegmentRestrict", label : { text : "Segment" }, editorType : "dxDropDownBox",
editorOptions : Fse.UI.multiSelectDropDownBoxEditorOptions( {
multiSelectReadOnly : instance.options.readOnly ? true : false,
dataSource : Fse.Data.newDataSource( { object : "OPR.segments", key : "clientSegId" } ),
searchExpr : "segmentPath",
searchMode : "contains",
displayExpr : "segmentPath",
multipleSelectedDisplay : "Multiple Selected",
keyExpr : "clientSegId",
title : "Select Segments..."
})
},
{ dataField : "oprParentDistributorRestrict", label : { text : "Parent Distributor" }, editorType : "dxDropDownBox",
editorOptions : Fse.UI.multiSelectDropDownBoxEditorOptions({
multiSelectReadOnly : instance.options.readOnly ? true : false,
dataSource : Fse.Data.newDataSource( { object : "CDR.distributorsLight", key : "cdr_recordId", filter : [ "dstCompanyType", "=", "P" ] } ),
searchExpr : "cdr_dstPath",
searchMode : "contains",
searchEnabled : true,
displayExpr : "cdr_dstPath",
multipleSelectedDisplay : "Multiple Selected",
title : "Select Parent Distributors...",
keyExpr : "cdr_recordId"
})
},
{ dataField : "oprDistributorRestrict", label : { text : "Distributor" }, editorType : "dxSelectBox",
editorOptions : {
dataSource : Fse.Data.newDataSource( { object : "CDR.distributorsLight", key : "cdr_recordId", filter : [ "dstCompanyType", "=", "B" ] } ),
readOnly : instance.options.readOnly ? true : false,
searchExpr : "cdr_dstPath",
searchMode : "contains",
searchEnabled : true,
displayExpr : "cdr_dstPath",
placeholder : "Select Distributor...",
valueExpr : "cdr_recordId",
showClearButton : true
}
},
{ dataField : "oprTypeRestrict", label : { text : "Priority" }, editorType : "dxSelectBox",
editorOptions : {
placeholder : "Select Priority...",
readOnly : instance.options.readOnly ? true : false,
dataSource : new DevExpress.data.ArrayStore({
data: priorityTypes,
key: "prioritycode"
}),
valueExpr : "prioritycode", displayExpr : "desc", showClearButton : true
}
},
{ dataField : "mfrOprTypeRestrict", label : { text : "Mfr Priority" }, editorType : "dxSelectBox",
editorOptions : {
readOnly : instance.options.readOnly ? true : false,
placeholder : "Select Priority...",
dataSource : new DevExpress.data.ArrayStore({
data: priorityTypes,
key: "prioritycode"
}),
valueExpr : "prioritycode", displayExpr : "desc", showClearButton : true
}
},
{ dataField : "oprPriorityRestrict", label : { text : "Classification" }, editorType : "dxDropDownBox",
editorOptions : Fse.UI.multiSelectDropDownBoxEditorOptions( {
multiSelectReadOnly : instance.options.readOnly ? true : false,
dataSource : Fse.Data.newDataSource( { dataURL : instance.dataURL, object : "OPR.classifications", keyField : "classificationId" } ),
searchExpr : "name",
searchMode : "contains",
displayExpr : "name",
multipleSelectedDisplay : "Multiple Selected",
keyExpr : "classificationId",
title : "Select Classifications..."
})
},
{ dataField : "oprAffiliationRestrict", label : { text : "GPO/CMC" }, editorType : "dxSelectBox", editorOptions : {
readOnly : instance.options.readOnly ? true : false,
dataSource : Fse.Data.newDataSource( { object : "OPR.memberGroups", key : "operatorId" } ),
displayExpr : "companyName",
valueExpr: "operatorId",
placeholder : "Select GPO/CMC...",
showClearButton : true,
searchExpr : "companyName",
searchEnabled : true,
searchMode : "contains"
} },
{ dataField : "oprAssignedOnlyRestrict", label : { text : "Assigned Accounts Only" }, editorType : "dxSwitch", editorOptions : {
readOnly : instance.options.readOnly ? true : false
} }
]
}).dxForm( "instance" );
instance.rootElement.append( instance.form.element() );
return instance.rootElement;
}
ObjectiveRestrictions.prototype.update = function() {
let instance = this;
let objectiveRestrictions = instance.form.option( "formData" );
instance.updatedPromise.resolve( objectiveRestrictions );
}
ObjectiveRestrictions.prototype.updated = function() {
return this.updatedPromise;
}