Our pure JavaScript Scheduler component


Post by eugenem »

I don't see anything relevant there.

Basically, I get taskRecord at beforeTaskEditShow event, but where do I get its assignments?


Post by mats »

They exist on the taskRecord as

taskRecord.assignments

Docs: https://bryntum.com/docs/scheduler-pro/#SchedulerPro/model/EventModel#property-assignments


Post by eugenem »

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.


Post by alex.l »

Hi eugenem,

Did you figure out with it?

    listeners : {
        beforeTaskEditShow({ taskRecord }) {
            const assignments = taskRecord.assignments;
        }
    },

All the best,
Alex


Post by eugenem »

    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.


Post by alex.l »

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


Post by eugenem »

I’m not sure how it’s related. And anyway, facilities and staff aren’t in my model.


Post by alex.l »

Please, try to use show event to set values for now:

features : {
       taskEdit : {
            editorConfig : {
                listeners : {
                    show() {
                        const taskRecord = this.record; // an example how to get taskRecord here
                        this.editor.widgetMap.facilities.value = [1, 2, 3];
                    }
                }
            }
        }
    },

All the best,
Alex


Post by eugenem »

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.


Post by eugenem »

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?


Post Reply