I am trying to determine in what user’s column has someone clicked resulting in the onBeforeDrag event. For all other modes its fine but for create mode how can I find the information on which user column is being clicked in?
Hello,
Update dhtmlxscheduler_units.js file.
Now you can use following code:
scheduler.attachEvent("onBeforeDrag", function(event_id, mode, native_event) {
var pos = scheduler._mouse_coords(native_event); // getting mouse coords
var mode = scheduler.getState().mode; // saving current mode
if(scheduler._props && scheduler._props[mode]){ // if we are in the units view..
view = scheduler._props[mode]; // save object with units view properties
var unit = view.options[pos[view.map_to]]; // got unit object, e.g. { key: 1, label: "test" }
}
return false;
});
Best regards,
Ilya
dhtmlxscheduler_units.zip (1.76 KB)
The code below is giving me problems.
scheduler._mouse_coords=function(){
var a=scheduler._props[this._mode],d=m.apply(this,arguments);
if(a){
if(!this._drag_event)
this._drag_event={};
var c=this._drag_event;
if(this._drag_id&&this._drag_mode)
c=this.getEvent(this._drag_id),this._drag_event._dhx_changed=!0;
var e=Math.min(d.x+a.position,a.options.length-1);
c[a.map_to]=a.options[e].key;
d[a.map_to] = a.options[e].key;
d.x=0;
d.custom=!0
}
return d;
};
What happens is that when i try to do create an event the onBeforeDrag event is triggered and
and it calls the above method as
var pos = scheduler._mouse_coords(native_event_object);
The first time I try to create an event everything works as it should. I cancel the event and dont save it. Now i try to create the event again, the above method fails and says the ‘c’ is undefined.
Below I am giving you the values of all the variables involved for both 1st and 2nd runs
1st run.
this._mode = “unit”
a = Object { map_to=“ProviderID”, options=[4], step=1, more…}
this._drag_event = undefined
this._drag_event = Object {}
c = Object {}
this._drag_id = undefined
this._drag_mode = “create”
a.position = 0
a.options.length = 4
d.x = 1
e = 1
c = Object { ProviderID=“bc4fd768-a18d-4fe7-8d08-fc6be46f2d36”}
d = Object { x=1, y=119, ev=Event mousedown, more…}
// below elements are part of d object
ProviderID = “bc4fd768-a18d-4fe7-8d08-fc6be46f2d36”
ev = mousedown clientX=753, clientY=188
x = 1
y = 119
//
d.x = 0
d.custom = true
2nd run
the control goes in the if statement as the drag_id is the same as the new light box and then c becomes undefined. and then the onBeforeDrag stops working.
Hello,
Thank for the feedback.
I’ve attached updated version, now it should work correctly and even a bit more easy to write
scheduler.attachEvent("onBeforeDrag", function(event_id, mode, native_event) {
var unit_id = scheduler._getUnitByEvent(native_event);
var scheduler_mode = scheduler.getState().mode; // saving current mode
if(scheduler._props && scheduler._props[scheduler_mode]){ // if we are in the units view..
var view = scheduler._props[scheduler_mode]; // save object with units view properties
var unit = view.options[unit_id]; // got unit object, e.g. { key: 1, label: "test" }
}
return true;
});
Kind regards,
Ilya
dhtmlxscheduler_units.zip (4.12 KB)