Our pure JavaScript Scheduler component


Post by Aniket »

Team, I want to send params to the sync request of my scheduler from gant

I want to send the childId as a parameter(I fetch it listeners load method) to sync request of crudmanager.

Right nowI send the parameter from the localstorage, but for sync request, I want to replace it with the childid i fetch in load method of listeners.

Any help appreciated

 crudManager = {

listeners: {
  load({ response }) {
    console.log(response);
    const
      start = new Date(response.calendar.startDate);
    const end = new Date(response.calendar.endDate);
    var childId = (response.details.childId);
    var parentId = response.details.parentId;
  
    this.scheduler.setTimeSpan(start, end);      // set calendar startdate and enddate
  },
  beforeResponseApply: ({ response }) => {
    response.resources.rows = response.resources.values;
    response.events.rows = response.events.values;
    response.timeRanges.rows = response.timeRanges.dueDates;
  }
},
autoLoad: true,
autoSync: true,
transport: {
  load: {
    url: 'https://localhost:5000/api/Schedule',
    params: {
      outputScheduleId: JSON.parse(
        localStorage.getItem('CurrentSelectedSchedule')
      ),

    },
 
    method: 'GET',
    credentials: 'omit',
  },
  sync: {
    url: 'https://localhost:5000/api/ReScheduling',
    params: {
      outputScheduleId: JSON.parse(
        localStorage.getItem('CurrentSelectedSchedule')
      )
    },
    headers: {
      'Content-Type': 'application/json'
    },
    method: 'POST',
    credentials: 'omit',

  }

}
  };

Post by saki »

Take a look at our gantt PHP demo which solves same problem as yours. Project there is configured as follows:

const project = window.project = new ProjectModel({
    // Let the Project know we want to use our own Task model with custom fields / methods
    taskModelClass : Task,
    transport      : {
        load : {
            url       : 'php/load.php',
            paramName : 'q'
        },
        sync : {
            url : 'php/sync.php'
        }
    },

    listeners : {
        beforeSend : ({ params }) => {
            // can be used to dynamically add arbitrary parameters to data load/sync requests
            // for example here we add "config" parameter (we use it for testing purposes)
            const queryString = new URLSearchParams(window.location.search);
            params.config = queryString.get('config') || '';
        },
        syncfail : ({ response, responseText }) => {
            if (!response || !response.success) {
                backendTools.serverError('Could not sync the data with the server.', responseText);
            }
        }
    }
});

Post by Aniket »

Saki, I tried to apply beforeSync and send params but no luck.

crudManager = {

listeners: {
  load({ response }) {
    console.log(response);
    const
      start = new Date(response.calendar.startDate);
    const end = new Date(response.calendar.endDate);
    var childId = (response.details.childId);
    var parentId = response.details.parentId;
  
this.scheduler.setTimeSpan(start, end); // set calendar startdate and enddate }, beforeResponseApply: ({ response }) => { response.resources.rows = response.resources.values; response.events.rows = response.events.values; response.timeRanges.rows = response.timeRanges.dueDates; }, beforeSend : ({ params, response }) => { // can be used to dynamically add arbitrary parameters to data load/sync requests // for example here we add "config" parameter (we use it for testing purposes) const queryString = response.details.childId; params.config = queryString; console.log(params.config); // params.config = queryString; } }, autoLoad: true, autoSync: true, transport: { load: { url: 'https://localhost:5000/api/Schedule', params: { outputScheduleId: JSON.parse( localStorage.getItem('CurrentSelectedSchedule') ), }, method: 'GET', credentials: 'omit', }, sync: { url: 'https://localhost:5000/api/ReScheduling',
headers: { 'Content-Type': 'application/json' }, method: 'POST', credentials: 'omit', } } };

Post by saki »

What is output at line 24 above? The URL should then be https://.....?config=[value of queryString]. Is the value correct? Also, how does the network tab request look like? Is the config present in URL?


Post by Aniket »

Hi Saki, I get below error
Even the load request of crudmanager fails as I cant see the schedule.

core.js:6014 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'details' of undefined
TypeError: Cannot read property 'details' of undefined

Post by saki »

Well, you need to debug it. You refer to response.details in your load listener so first you need to find out why it is not present when you rely on it. The server response is wrong?


Post by Aniket »

saki, load listener works fine, I could print response.details in load listener

I think response does not work in beforeSend config

Any thoughts?


Post by Aniket »

saki, let me reiterate what i am trying to achieve so that its clear for you to understand.

  1. I send a schedule id saved in local storage as a parameter to the load request of crudmanager.
  2. For sync request of crudmanager, I want to send the childId I receive in the response of load request of crudmanager as a parameter.

ANy help appreciated


Post by saki »

Well, beforeSend event does not take response as a member of its argument (response exists only during load event), therefore it is always undefined in beforeSend.

If you want to send childId that was previously received from the server then you must save it somewhere in the load listener and then retrieve it and set it as param in beforeSend listener.


Post by Aniket »

saki, how can i save childId in load listener and access it in beforeSend? I tried but had scope issues, beforeSync does not recognise childId stored in load listener .

Any help appreciated


Post Reply