We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

HOW to control with code Datasource responses (success & errors) when binded to Scheduler

I'm  trying to do a control for Rooms reservations for Meetings  and  here are my scenarios 

I have 3 users   "Admin" , "Secretary" , "Assistant"
# 1:

1.- User Admin Creates an appointment/Event  For room #1  from  12:30  to  14:30
2.- User Assistant Wants to create also an appointment/Event  For room #1   but the time  is from  14:00 to  15:30  (this part i need to generate error on serverside and get it with JS in order to alert users about the error)

# 2:
1.- User Admin Creates an appointment/Event  For room #1  from  12:30  to  14:30
2.- User Assistant Wants to create also an appointment/Event  For room #1   but the time  is from  14:30 to  15:30
3.- User Admin notice he made a mistake and tries to EDIT his event  so now the time is going to be  12:30  to  15:30    (this part i need to generate error on serverside and get it with JS in order to alert users about the error)

#3  (After scenario 1 & 2)
1.- User secretary want to create a recurrent event from 11:30 to 13:30 every 2 days for Room # 1     but it collides with appointments created with scenario#1 and #2  so i need to generate an error alert

First of all i dont want to control everything on JS i want to get the errors from the serverside.  I am generating JSON responses for the scheduler. NOW Obviously for this issue the server must return an error in the response  but no luck finding on docs how to create an error response for the data manager.   So my problem is  HOW CAN I:   intercept errors  in all operations ??? 

I have tried to make according the documentation   https://help.syncfusion.com/js/datamanager/how-to#how-do-i-control-communication-errors-with-the-web-service
but for me this works only the first time the DataManager makes a request

Also another problem i see its that for promises i need to execute the query before create the Scheduler so that leads me to that the URL is called before scheduler its created and then its called again after its created.  Looking At detail it seems that Scheduler always expects a success response but how can i interact with Users when there is an error about  data conflicts which is the case of the Scenarios. Also documentation for Datamanager of Scheduler examples really doesnt help at all in this case.

This is so far an example CODE i have made to check how to solve this.

              var myOtherAdaptorBase = new ej.UrlAdaptor().extend({
                         beforeSend: function (request, settings){
                                 console.log('myAdaptor-beforeSend');   
                         }
                 });
              var myOtherAdaptor  = new myOtherAdaptorBase();

              var dataManager = new ej.DataManager({
                      url:"/data/calendar_sample.php",
                      batchUrl:"/data/calendar_sample.php?batch=1",
                      insertUrl:"/data/calendar_sample.php?add=1",
                      updateUrl:"/data/calendar_sample.php?edit=1",                 
                      removeUrl:"/data/calendar_sample.php?remove=1",                                             
                      adaptor: myOtherAdaptor
              });

              var myquery = ej.Query().from("events");

              var dataSource = dataManager.executeQuery(myquery).done(
                  function(args){
                          console.log('myquery-done');   
                  }
              ).fail(
                  function(args){
                      console.log('myquery-fail');   
                  }
              ).always(
                  function(args){
                      console.log('myquery-always');   
                  }
              );

              var calx= $("#schedule").ejSchedule({
                locale: "es-ES",                
                    views:['Day','Week','Month','Agenda'],                   
                    currentView: ej.Schedule.CurrentView.Week,
                    isDST:false,
                    allowDragAndDrop: false,
                    showWeekend: true,
                    showQuickWindow: false,
                    showDeleteConfirmationDialog: false,
                    enableRecurrenceValidation: false,
                    enableLoadOnDemand: true,                   
                    startHour:7,
                    endHour:21,
                    timeZone:"UTC -06:00",
                    timeMode: ej.Schedule.TimeMode.Hour24,
                    currentDate: new Date(),                                      
                    appointmentSettings: {
                        dataSource: dataManager,
                        query: myquery,
                        id: "Id",
                        subject: "Subject",
                        startTime: "StartTime",
                        endTime: "EndTime",
                        allDay: "AllDay",
                        recurrence: "Recurrence",
                        recurrenceRule: "RecurrenceRule",
                        editFutureEventsOnly: true
                    },
                    create:"doOnCreate",
                    actionBegin:'doActionBegin',
                    //cellClick: "cellClickx",
                    //cellDoubleClick:'cellDobleclickx',
                    //cellHover:"mycellHover",
                    overflowButtonHover:"MyoverflowButtonHover",
                    overflowButtonClick:"myoverflowButtonClick",
                    appointmentHover: "myAppointmentHover",
                    appointmentClick: "OnAppointmentClick",
                    appointmentWindowOpen:'onAppointmentWindowOpen',
                    beforeAppointmentCreate: "onAppointmentSave",
                    beforeAppointmentChange: "onAppointmentEdit",
                    beforeAppointmentRemove: "onAppointmentDelete"                           
            });

Hope some other users have face similar issues or needs and may share solution.
Thanks in advance.










3 Replies

NR Nevitha Ravi Syncfusion Team September 18, 2017 12:18 PM UTC

Hi Carlos, 

Thank you for contacting Syncfusion Support. 

In Schedule, client side event can be used to achieve your scenario. But in Datamanager, there is no option to achieve your scenario. In General, Datamanager is used to exchange data between client and server. The server returns the response in success method. In order to throw some exception, the server returns response in fail method. We cannot perform our client side error response in Datamanager fail method. We have prepared a workaround sample to achieve your scenarios using client side events which can be viewed from the below location:  


<Code> 
$("#Schedule1").ejSchedule({ 
   beforeAppointmentCreate: "appointmentValidation", 
   beforeAppointmentChange: "appointmentValidation", 
   dragStop: "appointmentValidation", 
   resizeStop: "appointmentValidation" 
}); 
  function appointmentValidation(args) { 
         if (args.type == "beforeAppointmentCreate" || args.type == "resizeStop" || args.type == "dragStop") 
             var app = (ej.isNullOrUndefined(args.appointment[0])) ? args.appointment : args.appointment[0]; 
         else if (args.type == "beforeAppointmentChange") 
             var app = args.appointment.changed[0]; 
         var predicate2 = ej.Predicate(this._appointmentSettings["endTime"], ej.FilterOperators.greaterThan, new Date(app.StartTime)).and(this._appointmentSettings["startTime"], ej.FilterOperators.lessThan, new Date(new Date(app.EndTime))); 
         var predicate3 = ej.Predicate(this._appointmentSettings["startTime"], ej.FilterOperators.greaterThan, new Date(app.StartTime)).and(this._appointmentSettings["startTime"], ej.FilterOperators.lessThan, new Date(new Date(app.EndTime))); 
         var predicate1 = predicate2["or"](predicate3); 
         var predicate = predicate1["and"](this._appointmentSettings.resourceFields.toString().split(',')[this.model.resources.length - 2].trim(), ej.FilterOperators.equal, app[this._appointmentSettings.resourceFields.split(",")[0]]);  // to check for the same owner 
         var result = new ej.DataManager(this._processed).executeLocal(new ej.Query().where(predicate)); //checks whether already any appointment is in scheduler for the same time and resource. 
         if(result.length > 0 && app.AppTaskId == result[0].AppTaskId) result =[];           
         if (result.length >= 1) { 
            args.cancel = true;   //prevents appointment creation 
            alert("error"); 
         } 
    } 
</Code> 

Regards, 
Nevitha. 
 



CM carlos mendez September 18, 2017 05:54 PM UTC

Hi  Nevitha,  this means that if the back-end server  (for responses) is gone or crash then the calendar will request but will not receive nothing SO it will always show empty/blank scheduler ?

So far I tested on the playground and works but on client side, but however this is what i was trying to avoid. Gonna try to find other workarounds  cause my last alternative which also i don't want to is to make read only and suppress all interactivity and make custom dialogs and Ajax requests separate from the scheduler in order to achieve what i want.  

As a feature request it would be nice to have "events" on the Data Manager class also improve it more,  cause if this is the case for scheduler then i suspect Grid and many other components that need data-manager will have the same issue , Its only to be expected nice and good responses but its not capable of handling reject or error responses.

Thanks for the sample code !




NR Nevitha Ravi Syncfusion Team September 20, 2017 04:16 PM UTC

Hi Carlos, 
  
Thanks for your update. 
  
We have analyzed the possibility of implementing your requirement and would like to inform that it is not possible using Syncfusion Data Manager. 
  
Regards, 
Nevitha. 


Loader.
Live Chat Icon For mobile
Up arrow icon