Howto open the lightbox with a textlink?

Hi Ilya,
Thank you so much for your excellent help. I figured out why my event was not being created correctly when passing in all the data. This was because I was mapping the UserId field too the event, and when I mapped the UserId field, start_date and end_date too the new event, it would cause the collision to be detected and the event to fail being created (which makes complete sense). Too resolve this, I coded my method as follows:

        scheduler.form_blocks["approved_fields"].button_click=function(index, src, sec, data){

            var event_data = scheduler._lightbox_out({}); // now event_data is an object with all information entered in the lightbox's fields
       
            scheduler.cancel_lightbox(); // closing current lightbox

            scheduler._drag_mode = "create";
            
            scheduler.addEventNow({
               start_date: new Date(event_data.start_date),
               end_date: new Date(event_data.end_date)
            });

            scheduler._select_id = scheduler._drag_id;
            
            scheduler._select_id1 = scheduler._drag_id;

            var new_event = scheduler.getEvent(scheduler._lightbox_id); // scheduler._lighbox_id (or scheduler.getState().lightbox_id holds id of an event displayed in the lightbox)
            
            new_event.rec_type = 'true';
            
            new_event.UserId = event_data.UserId;
            
            document.getElementById('schedUser').value = new_event.UserId;
        }

My next issue was that the collision script was coded in a way that counted the collisions incorrectly when an event was created in this manner. To resolve this, I modified the onEventSave event handler (within the collission script) too the following code:

scheduler.attachEvent("onEventSave",function(id, edited_ev){
	//var ev = scheduler.getEvent(id);
	if(edited_ev.rec_type){
		scheduler._roll_back_dates(edited_ev);
		return scheduler.collision_check(edited_ev);
	}
	else
	{
	    return scheduler.collision_check(edited_ev);
	}
});

My next issue was that the script was incrementing the count and doing a comparison in a bad way within scheduler.collision_check. To resolve this, I modified the following code within it

		for (var i = 0; i < evs.length; i++) 
			if (evs[i][map_to] == ev[map_to]) 
				count++;

was changed too

		for (var i = 0; i < evs.length; i++) 
			if (evs[i][map_to] == ev[map_to] & evs[i].id != ev.id) 
				count++;

and the following code within the same collision_check method was changed from

		if (count > scheduler.config.collision_limit) {
			scheduler._drag_event.start_date = temp_time;
			ev[map_to] = temp_section;
			single = false;
		}

to

		if (count >= scheduler.config.collision_limit) {
			scheduler._drag_event.start_date = temp_time;
			ev[map_to] = temp_section;
			single = false;
		}

Hope this helps with anyone else in the future who has similar issues. Thanks heaps for all your excellent help Ilya, it was greatly appreciated, and my issue is now resolved.

Kind regards
Greg Goldberg

:ugeek:

Hello, Greg Goldberg.

I am glad you issue is resolved. I haven’t asked this before but what were you trying to do? You select button in the lightbox form and want to create another event happening at the same time for the same user and don’t want collision extension to prevent it? :slight_smile:

With this changes to the button handler you are adding userId property after event was actually created and collision extension should sleep still.

What exactly was working incorrectly?

I don’t see any difference. In our case were weren’t doing check for id and had at least 1 match (event compared with itself) but later on our comparison was
count > scheduler.config.collision_limit
So for collision to occur it had to be 2 > 1, there 2 = 1 (event itself) + 1 (another event which was actually causing collision).
In your case it seems you are filtering event itself but later on make >= comparison (so 1>=1 — collision has occured).

Best regards,
Ilya

Hi Ilya,
I just wanted too populate the lightbox form with the same details as the previous event, but force the Scheduler user to change either the date of the event before saving it, or changing the section it is assigned too (The UserId).

So for collision to occur it had to be 2 > 1, there 2 = 1 (event itself) + 1 (another event which was actually causing collision).
In your case it seems you are filtering event itself but later on make >= comparison (so 1>=1 — collision has occured).

The collision was not hitting itself against the new event, so the colission count was only 1 when it should have been 2.

The logic I built in was so that it did not have to collide with itself at all to regonize that there was a collision, but relied on colliding with other events (It would not count itself as a colission). As the scheduler could not detect that the event was colliding with itself, this was causing an issue with the colission script when using the addEventNow() syntax, when initially adding the event, as well as when I attempted too save it (It would allow me too save this event in a timeslot where another event was saved already, or collide when I passed in the UserId variable).

Hope this clarifies why I made the change too the code.

Thanks greatly for all your help again Ilya, you have been great.
Kind regards
Greg Goldberg

I.E. In other words when saving the event after using addEventNow(), the collision count was only 1, not 2 like it should have been.

Dear dHTMLx Support,
I had my duplicate button working perfectly using the scheduler.addEventNow code, however since then I have attempted to customize my scheduler further, by implementing a custom lightbox. Within my custom Lightbox I have implemented the same button, and created a function for it to duplicate the event as follows:

function DuplicateEvent()
{
    save_form();
    
    var event_data = scheduler.getEvent(scheduler._drag_id);

    scheduler._drag_mode = "create";

    scheduler.addEventNow({
        start_date: addDays(event_data.start_date),
        end_date: addDays(event_data.end_date),
        text: event_data.text.toString(),
        EventDescription: event_data.EventDescription.toString(),
        IsBillable: event_data.IsBillable.toString(),
        IsTentative: event_data.IsTentative.toString(),
        JobId: event_data.JobId.toString(),
        SchedulerTypeId: event_data.SchedulerTypeId.toString()
    });

    scheduler._select_id = scheduler._drag_id;

    scheduler._select_id1 = scheduler._drag_id;

    var new_event = scheduler.getEvent(scheduler._lightbox_id); // scheduler._lighbox_id (or scheduler.getState().lightbox_id holds id of an event displayed in the lightbox)

    new_event.ResourceId = event_data.ResourceId;

    Get('ctl00_cphMainContent_ucResourceScheduler_ddlResources').value = new_event.ResourceId;
}

I have also re-coded the save_form() function as follows:

function Get(s)
{ 
    return document.getElementById(s);
}

function save_form() 
{
    // Get the event from the Scheduler.    
    var ev = scheduler.getEvent(scheduler.getState().lightbox_id);

    // Set the Controls with the Database values from the Scheduler
    ev.text = Get("ctl00_cphMainContent_ucResourceScheduler_txtEventName").value;
    ev.EventDescription = Get("ctl00_cphMainContent_ucResourceScheduler_txtDescription").value;
    ev.start_date = new Date(Get("ctl00_cphMainContent_ucResourceScheduler_txtStartDate").value);
    
    // Set the Resources drop down list.
    var ddlResources = Get("ctl00_cphMainContent_ucResourceScheduler_ddlResources");
    ev.ResourceId = ddlResources.value;

    // Set the IsBillable Flag.    	
	var isBillable = Get("ctl00_cphMainContent_ucResourceScheduler_chkBillable").checked.toString();
    if(isBillable == "true")
    {
        ev.IsBillable = 1;
    }
    else
    {
        ev.IsBillable = 0;
    }
	
	// Set the IsTentative Flag.
    var isTentative = Get("ctl00_cphMainContent_ucResourceScheduler_chkTentative").checked.toString(); 
    if(isTentative == "true")
    {
        ev.IsTentative = 1;
    }
    else
    {
        ev.IsTentative = 0;
    }
	
	// Set the Date Values
    var newEndDate = new Date(Get("ctl00_cphMainContent_ucResourceScheduler_txtEndDate").value);
    newEndDate.addDays(1);
    ev.end_date = newEndDate;
	
	// Set the Job Drop Drop Value.
    var ddlJob = Get("ctl00_cphMainContent_ucResourceScheduler_ddlJob");
    ev.JobId = ddlJob.value;
	
	// End the Lightbox
    scheduler.endLightbox(true, Get("MPELightbox"));
}

Now with that code implemented, it attempts to save the event when pressing the duplicate button, then once it has been saved, it retrieves the event data and uses it to create an event using the addEventNow method as can be seen above. Everything works perfectly, but then I attempt to save this newly created event, and everything seems to bomb out. Specifically the first line of code within my save_form:

    // Get the event from the Scheduler.    
    var ev = scheduler.getEvent(scheduler.getState().lightbox_id);

I attempted to remedy that, by using the following syntax instead:

    var ev = scheduler._drag_event;

Which then lets me get as far as the following block of code within dhtmxlscheduler.js:

scheduler._edit_stop_event=function(A,B)
{
    if(this._new_event)
    {
        if(!B)
        {
            this.deleteEvent(A.id,true);
        }
        else
        {
            this.callEvent("onEventAdded",[A.id,A]);
        }
        this._new_event=null;
    }
    else
    {
        if(B)
        {
            this.callEvent("onEventChanged",[A.id,A]);
        }
    }
};

Where it fails within the else statement of the following block of code:

        if(!B)
        {
            this.deleteEvent(A.id,true);
        }
        else
        {
            this.callEvent("onEventAdded",[A.id,A]);
        }

As the variable “A” is undefined at this point. Additionally, the event will only make the initial save after this change has been made, and any future changes to the event do not effect it within the scheduler.

Any help would be greatly appreciated.

Kind regards
Greg Goldberg

Hello,

Is it possible to access your scheduler on the internet so I could check it myself?

Best regards,
Ilya

Hi Ilya,
I do not have a copy of it running on the Internet, it is only running locally on my network. I will package it and send it to your support email later today, so that you can review my codebase. I am currently having another issue with complex SQL and a date field not being encapsulated by the following apostrophe character ’

So the Date appears as ApprovedDate = 1 July 2011 12:43
Instead of ApprovedDate = ‘1 July 2011 12:43’

As soon as I resolve that issue and have the scheduler working as it was previously, I will package it together with an SQL script to create the database required for it, and email it to support@dhtmlx.com from the same email address as my account is registered with on the forum.

EDIT. I managed to fix my issue, I was calling scheduler.clearAll() when the event was being updated, and removing that has resolved the issue. If you still want a look at my codebase, please let me know and I will send off a sample.

Kind regards
Greg Goldberg

Hello,

No, it’s all good if it’s working for you :slight_smile:

Best regards,
Ilya