I don't see anything relevant there.
Basically, I get taskRecord at beforeTaskEditShow event, but where do I get its assignments?
They exist on the taskRecord as
taskRecord.assignments
Docs: https://bryntum.com/docs/scheduler-pro/#SchedulerPro/model/EventModel#property-assignments
https://www.dropbox.com/s/8ij3h7iro3s1cma/annotation%202021-03-30%20192424.jpg?dl=0
This is how it looks now. I just need to split resources into facilities and staff editors.
this.schedulerPro.schedulerInstance.addListener('beforeTaskEditShow', ({ taskRecord, editor }) => {
console.log(taskRecord, taskRecord.assignments);
const { facilities, staff } = editor.widgetMap;
//const resources = taskRecord.resources?.length ? taskRecord.resources : (resourceRecord ? [resourceRecord] : []);
facilities.value = taskRecord.assignments.filter(x => x.id.startsWith("EF_")).map(x => x.originalData.resource);
staff.value = taskRecord.assignments.filter(x => x.id.startsWith("ES_")).map(x => x.originalData.resource);
//facilities.value = resources.filter(r => r.type === 'facilities');
//staff.value = resources.filter(r => r.type === 'staff');
});
I see that control values are assigned properly with values like "S_123", which corresponds to store values. But at popup both controls are empty.
Hi eugenem,
This is a known bug, we have a ticket for it here: https://github.com/bryntum/support/issues/674
As a workaround, try to use names for those fields which are different from field names in your task model.
All the best,
Alex
All the best,
Alex
wow, this seems to work!
editorConfig: {
autoClose: false,
listeners: {
show() {
const taskRecord = this.record;
const { facilities, staff } = this.editor.widgetMap;
facilities.value = taskRecord.assignments.filter(x => x.id.startsWith("EF_")).map(x => x.originalData.resource);
staff.value = taskRecord.assignments.filter(x => x.id.startsWith("ES_")).map(x => x.originalData.resource);
}
}
},
Now, how do I do the opposite on save? I couldn't find any references to show() event btw.
The code above splits resources into staff and facility:
https://www.dropbox.com/s/4bebeqotgnx31kt/screenshot%202021-04-20%20111800.jpg?dl=0
and I have this code that runs before task is saved:
this.schedulerPro.instance.addListener('beforeTaskSave', ({ source: scheduler, taskRecord, editor }) => {
const selectedFacilities = [editor.widgetMap.facilities.value]; // single select
const selectedStaff = editor.widgetMap.staff.value; // multi select
const selectedResourceIds = [...selectedFacilities, ...selectedStaff];
// Assigning resources to event does not work here, because event editor reassigns the resources internally.
// Therefore mutate the resourceRecords param which is used internally.
const selectedResources = scheduler.resourceStore.query(record => selectedResourceIds.includes(record.id), true);
console.log(selectedResources);
console.log(taskRecord.assignments);
//taskRecord.assignments.splice(0, resourceRecords.length, ...selectedResources);
});
how do I set taskRecord.assignments properly?