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;
}
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);
}
}
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