Our pure JavaScript Scheduler component


Post by Highnoon »

Hi,
i try to do a nice Drag and Drop in scheduler.
                          
//Fired on the owning Scheduler when event dragging starts
eventDragStart: function onDragStart(param1) {
         var source = param1.source
         var eventRecords = param1.eventRecords;
         var context = param1.context;

          // Prevent tooltips from showing while dragging
          this.eventEdit.scheduler.schedulerEvents.element.classList.add('b-dragging-event');

},
//Fired on the owning Scheduler when an event is dropped
eventDrop: function onDrop(param2) {
          var source = param2.source
          var eventRecords = param2.eventRecords;
          var isCopy = param2.isCopy;
          var context = param2.context;
          var targetEventRecord = param2.context.record;
          var targetResourceRecord = param2.targetResourceRecord;

          if (context.validPosition) {
              changeEvent(targetEventRecord.GUID, targetEventRecord.REFOBJECT,  targetResourceRecord.id, context.startDate, context.endDate);
              context.finalize();
           } else {
               //abort();
               context.finalize(false);
          }

          this.eventEdit.scheduler.schedulerEvents.element.classList.remove('b-dragging-event');
 },
 //Fired on the owning Scheduler when event is dragged
 eventDrag: function onDrag(param3) {
           var newResource = param3.newResource;
           var context = param3.context;

           if (newResource.isParent)
                 context.validPosition = false;
           else
                context.validPosition = true;
}
It works nearly perfect but it seems to me that there is something missing. This is the changeEvent method:
function changeEvent(guid, refobject, resourceId, startDate, endDate) {
      try {
         var result = P2Service.get("plan").changePositionAsJson(guid, refobject, resourceId, formatDate(startDate), formatDate(endDate));
         var jres = JSON.parse(result);
         updateEvents(jres);
      } catch (e) {
      }
}

function updateEvents(records) {
      for (i = 0; i < records.length; i++) {
            findMe = function (r) {
                 return r.GUID == records[i].GUID;
            }
           obj = scheduler.eventStore.find(findMe);
           scheduler.eventStore.remove(obj);
            // transfer new values
            for (var key in records[i]) {
                  var value = records[i][key];
                  if (key === 'endDate' || key === 'startDate') {
                       obj[key] = makeDate(value); 
                   } else if (key === 'resourceId') {
                       obj.assign(value); 
                   } else {
                        obj[key] = value;
                    }
            }
            scheduler.eventStore.add(obj);
      }
}
A WebService is called to apply changes to data. The returning value contains the effects to the event and to other events. This can be color, start, end ...

Somethimes the events which have changed in this way disappear or move back to old position. Whats wrong? If i resize the browser window they appear again in the desired position.

And second i get very often the no sign when i start to drag. So i think adding and removing the css b-dragging-event is not correct. Can you please check this. Maybe you can offer a code snippet for drag and drop. In case the WebService failed i think i need a beforeeventdropfinalize method.

Thanks

Post by mats »

Please provide info about which version of our product you are using (if not on the latest, please test on the latest version).

Post by Highnoon »

I'm using the newest Scheduler 1.21.

Post by mats »

Ok, then we'll need a test case to debug - please zip up a sample that we can inspect.

Post by Highnoon »

ok, this needs time. I have to replace the WebService calls.

Post by mats »

Yes, please just use dummy data as in our examples

Post by Highnoon »

Hi,

sorry for delay. Unpack it and place it in a WebServer. Add scheduler includes. I need this for IE11. The behavior is different to mine, because the slow WebService calls are missing. But in some cases you get still the no sign. Maybe you can offer some code snippets. I am thinking of moving the whole thing to event store update. Is there a safe way to catch exceptions from the WebService and move the event to old position?

Many thanks
BryntumTest.zip
(747.68 KiB) Downloaded 161 times

Post by mats »

And can you please describe exactly what is wrong? And how do we reproduce what you are seeing?

Post by Highnoon »

Yes, shure sorry. Just drag the events. It's not allowed to drop them on the parents. If everything is ok the event appears on new position a star is added to name and they change their color. In some cases the no sign appears but you can move the event. I think it has to do with the time/date tooltip. Just try it a few times.

Post by pmiklashevich »

Your test case is based on .NET. Could you please provide a runnable sample based on pure JS/HTML. You can take any of our simple examples as a base. Thanks

Pavlo Miklashevych
Sr. Frontend Developer


Post Reply