I think I found a bug in the scheduler._mouse_coords function in dhtmlscheduler_units.js (2.3)
The Method crashes on me, when I drop an event into the unit_tab and it tries to determine the mouse position.
It seems the _drag_event is undefined.
I fixed it for me by changing
scheduler._mouse_coords = function () {
var K = scheduler._props[this._mode];
var J = E.apply(this, arguments);
if (K) {
var H = this._drag_event;
if (this._drag_id) {
H = this.getEvent(this._drag_id);
this._drag_event._dhx_changed = true
}
var I = Math.min(J.x + K.position, K.options.length - 1);
H[K.map_to] = K.options[I].key;
J.x = I / 10000000
}
return J
};
to
scheduler._mouse_coords = function () {
var K = scheduler._props[this._mode];
var J = E.apply(this, arguments);
if (K) {
var H = this._drag_event;
if (this._drag_id) {
H = this.getEvent(this._drag_id);
this._drag_event._dhx_changed = true
}
var I = Math.min(J.x + K.position, K.options.length - 1);
if (H) {H[K.map_to] = K.options[I].key;} // <------------------------- CHANGE IS HERE
J.x = I / 10000000
}
return J
};
I currently have no time to investigate further, but if you need additional information I would be glad to help.
Can you please specify exact steps to reproduce this issue?
I have tried creating and moving existing events out of the scheduler’s div, on the sections yet everything seems to be working correctly.
Sorry, I mean when I use some own drag&drop procedure to handle external links dragged into the area.
when the ondrop-event is fired, the following is executed:
function doDrop(e) {
e = e || window.event;
var pos=scheduler._mouse_coords(e); // <----------- problem occurs here
scheduler.mousepos = pos;
... and so on...
I’m afraid the try-catch is not working for me.
I need the coordinates to assign some data (that I drag into the units view from the outside) to the correct section. Without the coordinates its all assigned to section 0.
Do I need to use some parts of “External Drag & Drop”-Module to archive this?
I’m afraid my original solution is not fully functional either.
Apart from the need to modify the source code (makes updates more difficult), there are some problems because the parameter is not getting set.
Firstly the good news: I started from scratch (discarding all the mind numbing stuff my predecessor was putting into the application) and most problems are resolved.
However, I am still unable to find a solution for this external dragging.
For some obscure reason the y-value is set, but the x-value (the appropriate unit) is either false or 1e-7.
function doDrop(e) {
e = e || window.event;
scheduler._drag_event = {};
var pos = scheduler._mouse_coords(e);
scheduler._drag_event=null;
alert(pos.x+' # '+pos.y);
The alert states something like “0 # 112” for a drop into the first of two units/sections in unit view and “1e-7 # 123” if dropping into the second unit/section column.
The y seems valid, but why can’t I get a valid x?
I am expecting a “0” for the first column and “1” for the second. Is that right?
How else could I get the section_id of the column I’m dropping into?
I am expecting a "0" for the first column and "1" for the second. Is that right?
Absolutely. This is a problem and it should be fixed in the upcoming version.
As a temporary solution you can do the following:
var true_x = pos.x*10000000;
var section = scheduler._props.unit.options[true_x];
/*
unit -- name of the your units tab,
section.key, section.label are available as well as other properties (if were set)
*/
In reality pos.x means different things depending on the current view. In units view it could be sections, in week view — date. That’s why for custom views we most likely will leave pos.x = 0.
Now for the whole Drag and drop thing — we have an extension for this. Check out samples\06_timeline\05_drag.html sample, maybe this will help you better.
var temp = scheduler.attachEvent("onEventCreated", function(id,e){
if (!scheduler.callEvent("onExternalDragIn", [id, e])){
this._drag_mode = this._drag_id = null;
this.deleteEvent(id);
}
});
if (scheduler.matrix[scheduler._mode])
scheduler.dblclick_dhx_matrix_cell(last_event);
else
scheduler._on_dbl_click(last_event);
scheduler.detachEvent(temp);
where last_event - HTML event object, related to mouse actions
As result scheduler will simulate double-click at target position , which will create new event and trigger onExternalDragIn event - which can be used for further customization.
Above code doesn’t relay on any properties of scheduler so will work for all modes of existing scheduler and must not have problems in future.
I can’t use the on_dbl_click-event, for I disabled it in config.
Now somehow
var pos = scheduler._mouse_coords(e);
doesn’t return anything else for pos.x than 0 anymore in unit view.
Not sure why…
So the situation is as following now:
In calendar-view scheduler._mouse_coords(e) works fine.
For y I get number of 5min-intervals since midnight, so y=120 means 10 o’clock
For x I get column-index, so in week view x==0 means monday, x==1 means tuesday and so on.
In Timeline view I can handle the result
For y I get the number of 5min-intervals since the first displayed time. So, lowest hour displayed is 7 o’clock, so when I drop something at 10 o’clock I get 36 (365 min + 760 = 600 = 10 o’clock)
For x I get 1/10000000 of the row-index, so multiplying with 10000000 gives me the desired result
In Unit view I have most trouble
y is handled as in calendar, so thats ok
x is always 0 now, so I have no way to determine the section i drop in. It used to be as in timeline view, but not anymore, propably due to new dhtmlxscheduler_units.js send by support.
Apart from the inconsistency, I have no idea how to determine the section now.
I can get the event coordinates with my own functions but they are relative to screen and/or document.
How can I determine the current section from these absolute position?
e = e || window.event;
var pos = scheduler._mouse_coords(e);
var sec_id = scheduler._drag_event.section_id;
var start = new Date(scheduler._min_date.valueOf() + (pos.y * scheduler.config.time_step) * 60000);
So: hooray!
The x-coordinates is actually set to 0 in my (custom) dhtmlxscheduler_units.js:
scheduler._mouse_coords=function(){
var pr = scheduler._props[this._mode];
var pos=p.apply(this,arguments);
if (pr){
if(!this._drag_event) this._drag_event = {};
var ev = this._drag_event;
if (this._drag_id){
ev = this.getEvent(this._drag_id);
this._drag_event._dhx_changed = true;
}
var unit_ind = Math.min(pos.x+pr.position,pr.options.length-1);
ev[pr.map_to]=pr.options[unit_ind].key;
pos.x = 0;
pos.custom = true;
}
return pos;
}