Get Section ID

Hi Stanislav,

I need help with this one as I am at a lose end. How would I get the section ID from an external drop event?

var old = scheduler._on_mouse_up; scheduler._on_mouse_up = function(e){ if (is_dnd_active()){ debugger; var pos = this._mouse_coords(e); var start = this._min_date.valueOf()+(pos.y*this.config.time_step+(this._table_view?0:pos.x)*24*60)*60000; start = this._correct_shift(start); window.setTimeout(function(){ //timeout is necessary to prevent infinity loop scheduler.addEventNow(start); alert(e.section_id); },1) } else { old.apply(this,arguments); } }

How do I assign/alert out the section ID from my new event, to the correct unit (see image) - I drag into the secont column from external

outside of scheduler
?

This is what I use also:

[code]
//instead of this code you can use any other lib
//the scheduler will react on mouseup event, it doesn’t specif to the used dnd engine
var node = document.getElementById(‘drag_me’);
(new dhtmlDragAndDropObject()).addDraggableItem(node,{
_createDragNode:function(node){
var dragSpan=node.cloneNode(true);
dragSpan.style.position=“absolute”;
dragSpan.style.zIndex=12;
return dragSpan;
},
});
node.dragLanding=false;

	//this method returns true while dnd active, it necessary to separate dnd-mouseup, from normal mouseup
	function is_dnd_active(){
		return !!window.dhtmlDragAndDrop.dragStartNode;
	}
</script>[/code]

Many thanks :slight_smile:

Hi Stanislav,

Do you have any idea how I can get the section id here? I was playing around with Scheduler and your code last night and I just couldn’t figure out how to get the section ID.

Can I get the column key of the first row, which would be the section id?

Many thanks,

Blueevo.

In unit view, pos.x will contain index of column, which can be converted to key of related unit as

scheduler._props[scheduler._mode].options[pos.x].key;

Existing version of addEventNow doesn’t allow to provide custom parameters ( fixed in dev. version ), you can use onEventCreated handler but it will be a bit messy code.

so you can add the next lines to the end of dhtmlxscheduler.js, which will patch addEventNow

[code]scheduler.addEventNow=function(start,end,e){
var base = {};
if (typeof start == “object”){
base = start;
start = null;
}

var d = (this.config.event_length||this.config.time_step)*60000;
if (!start) start = Math.round((new Date()).valueOf()/d)*d;
var start_date = new Date(start);
if (!end){
	var start_hour = this.config.first_hour;
	if (start_hour > start_date.getHours()){
		start_date.setHours(start_hour);
		start = start_date.valueOf();
	}
	end = start+d;
}


base.start_date = base.start_date||start_date;
base.end_date =  base.end_date||new Date(end);
base.text = base.text||this.locale.labels.new_event;
base.id = this._drag_id = this.uid();
this._drag_mode="new-size";

this._loading=true;
this.addEvent(base);
this.callEvent("onEventCreated",[this._drag_id,e]);
this._loading=false;

this._drag_event={}; //dummy , to trigger correct event updating logic
this._on_mouse_up(e);	

}[/code]

and use

scheduler.addEventNow({ section_id:some, start_date:new Date(start) })

Excellent, absolutely fantastic. Thanks for this Stanislav, I’ll give that a try this morning.

Have a great day.

Thanks Stanislav, however I do have a few issues with this:

In unit view, I get H is undefined in dhtmlxscheudler_units.js.

It breaks at: var old = scheduler._on_mouse_up; scheduler._on_mouse_up = function(e){ if (is_dnd_active()){ debugger; var pos = this._mouse_coords(e); // Breaks here (in units view) as I think Scheduler expects and event, but it isn't atcually created yet??

Also, in the year, month and matrix view, I need to grab the date I have “dropped” on. Is this possible?

Many thanks.

Also, in the year, month and matrix view
in month view existing logic of “start” calculation will work
but in year and matrix view there is no way to get position from mouse event ( it possible to check event.target and calculate which cell is under cursor - but there is no build in helpers )

as I think Scheduler expects and event, but it isn’t atcually created yet??
Yep, in unit view scheduler attempts to modify dragged event, which cause problems in your case
try to add

scheduler._drag_event = {}; var pos = this._mouse .... scheduler._drag_event=null;

Here is my new code:

[code]var old = scheduler._on_mouse_up;
scheduler._on_mouse_up = function(e){
if (is_dnd_active()){ debugger;
var pos = this._mouse_coords(e);
var start = this._min_date.valueOf()+(pos.y*this.config.time_step+(this._table_view?0:pos.x)2460)*60000;
start = this._correct_shift(start);

          scheduler._props[scheduler._mode].options[pos.x].key;
                

				window.setTimeout(function(){	//timeout is necessary to prevent infinity loop
				
				    scheduler.addEventNow({
                        section_id:1236,
                        start_date:new Date(start),
                        id:123456789,
                        text:"New Event"
                    })
				},1)
			} else {
				old.apply(this,arguments);
			}
        }[/code]

Thanks, I’ll try what you have just said.

The thing now is I get :

this._drag_event is null

File: dhtmlxshceudler_units.js

This is what I have so far:

[code]var old = scheduler._on_mouse_up;
scheduler._on_mouse_up = function(e){
if (is_dnd_active()){ debugger;
alert(“Pos issue”);
scheduler._drag_event = {};

				var pos         = this._mouse_coords(e);
				
				
				
				scheduler._drag_event=null;
				
				
				var start       = this._min_date.valueOf()+(pos.y*this.config.time_step+(this._table_view?0:pos.x)*24*60)*60000;
				start           = this._correct_shift(start);
				
                var my_section_id = scheduler._props[scheduler._mode].options[pos.x].key;
                alert(my_section_id);

				window.setTimeout(function(){	//timeout is necessary to prevent infinity loop
				//	scheduler.addEventNow(start,start,gDraggingGroupID);
				    //scheduler.addEvent(new Date(start),new Date(end),"New Schedule",gDraggingGroupID);
				    scheduler.addEventNow({
                        section_id:my_section_id,
                        start_date:new Date(start),
                        id:my_section_id,
                        text:"New event"
                    })
				},1)
			} else {
				old.apply(this,arguments);
			}
        }[/code]

It does seem to work, in that the event is added to the required resource, but I don’t know how this works, and also it adds an event to the first unit in view.

I also get “this._drag_event is null” error after my new event is created.

Thanks.