copy and paste an event

Hi,

still trying this add-on out on the following site:
113.20.7.57/~nalum/index.php?opt … ,mode=week
definitely looks like it will be the one to buy over other calendars.

I need to find out if I can copy and paste an event in the calendar from the front end.

Also still have one other query from a previous post that I will need to confirm as well.

thanks for you time.

anthony.

I need to find out if I can copy and paste an event
Can you provide some more info, how do you plan to use such functionality?
There is no such possibility for now, but it sounds as interesting addition.

Hi Stanislav,

thanks for your replies to my posts…

For instance in the calendar that I am creating now. its a weekly one for a dance school. Each class may run on say, a wednesday, friday and sunday. they all have the same info in them. ie. price, class description, instructor biography. The client that runs the school will have to be updating fairly often for the new classes when the school puts them on. It would be great for her to be able to click on “Beginners 1” and then paste it some where else, rather than having to re enter all the info.

Does that make sense? Hope so.

Cheers again for your help.

regards,

anthony.

to be able to click on “Beginners 1” and then paste it some where else, rather than having to re enter all the info

Does support for ctrl-c, ctrl-v will be enough? ( it will produce a sibling event , which can be dragged to different date after that ) or do you have some other scenario in mind?

that would be fantastic!
It would really make it easy and quick to add same / similar events…

thanks,

anthony.

Sample is attached. You can select any event , ( in week and day mode only ) , and use ctrl-c and ctrl-v to make copies of it.

To add the same functionality for joomla’s plugin

a) copy
sample.zip\codebase\dhtmlxscheduler_key_nav.js
to
{joomla_dir}/com_scheduler/codebase/ext

b) in
{joomla_dir}\com_scheduler\codebase\dhtmlxSchedulerConfigurator.php
locate

$scheduler .= "<script src=\"".$url."ext/dhtmlxscheduler_url.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";

and replace with

$scheduler .= "<script src=\"".$url."ext/dhtmlxscheduler_url.js\" type=\"text/javascript\" charset=\"utf-8\"></script>"; $scheduler .= "<script src=\"".$url."ext/dhtmlxscheduler_key_nav.js\" type=\"text/javascript\" charset=\"utf-8\"></script>";
sample.zip (48.3 KB)

Awesome.

Few niggles, I have clash management so that I do not allow events to clash.

It would be good that CTRL+V would paste the event at a starting time of where you clicked the mouse - If there was no other mouse click, it would then default to side-by-side.

Wow!! I thought you meant that you might bring something out in a few months… not a few minutes!!! cool!

Okay,
having a few dramas. I have replaced the line of code (line 353 to be exact) as you said.
I have uploaded the php file back up onto the remote server and cut and paste still does not work.

I am using a MAC is this an issue?? You use the command button instead of the cntrl button on macs.
But definitely not working for me at the moment.
I have cleared the cache and refreshed as well.

any ideas?

thanks,

anthony.

Try to update js file, it must work with both ctrl-key and command-key combinations now

But definitely not working for me at the moment.
Try to use the rigth and left cursor key, if PHP file was updated correctly, they will change active day|week. If it doesn’t works as well - it means js file was not copied to the correct location.
dhtmlxscheduler_key_nav.zip (1.13 KB)

It would be good that CTRL+V would paste the event at a starting time of where you clicked the mouse 

Yep, it will be more useful, but will require a bit more complex handling.
Most probably will be added as part of scheduler 2.3

Hi Stanislav,
I was wondering if this has been included in Scheduler 2.3, and how I would go about implementing it?

Also, I have tried implementing the dhtmlxscheduler_key_nav.js file, and scheduler._select_id was always undefined. On the following section of code in dhtmlxScheduler.js

scheduler.select=function(A)
{
    if(this._table_view||!this.getEvent(A)._timed)
    {
        return;
    }
    if(this._select_id==A)
    {
        return;
    }
    this.editStop(false);
    this.unselect();
    this._select_id=A;
    this.updateEvent(A);
};

When I click on an event, It will always stop at the following return:

    if(this._table_view||!this.getEvent(A)._timed)
    {
        return;

I verified by changing the dhtmlxEvent function in dhtmlxscheduler_key_nav.js to the following (I just added alerts to let me know what the _select_id is because I couldn’t copy and paste…)

            else
            {
                if(D.ctrlKey&&D.keyCode==67)
                {
                    scheduler._copy_id=scheduler._select_id
                    alert(scheduler._select_id);
                }
                else
                {
                    if(D.ctrlKey&&D.keyCode==86)
                    {
                        alert(scheduler._select_id);
                        var C=scheduler.getEvent(scheduler._copy_id);

Also, this script does not work in conjunction with the collisions javascript functionality. Any help would be greatly appreciated.

Kind regards
Greg Goldberg

cheduler._select_id was always undefined
This one set when you are clicking on some event in day|week view ( onClick must not be blocked by event handler )

There is no selection in other views. ( as there is no visual marking of selected item - ctrl-c|ctrl-v functionality will be confusing for such views )

Hi Stanislav,
I understand that there is no currently no visual marking showing which event has been selected, and therefore the user will not be able to visually see that the event they want to generate is selected to be copied, however I can perform visual marking on the element to show that it has been selected/deselected, and set the scheduler._select_id property during another event provided to the scheduler, and then the paste functionality seems fine, with the exception that the event is being pasted within the same time slot in the same section as the event I am copying, and the collision detection fails.

Is there any code I can call in the paste function of the dhtmlxscheduler_key_nav.js file too detect if collisions has been enabled in the scheduler, and detect collisions on the newly created event?

Kind regards
Greg

You can set ._select_id from onClick event, but it may trigger some unwanted behavior in the scheduler.
The safest soluiton

a) use onClick event to save id of last clicked event in some var
b) alter code in key_nav extension to use such global var

Hi Stanislav,
Thanks for your prompt and valuable response, I had noticed some unwanted behaviour but didn’t realize it was caused from that. I have ensured that key_nav uses scheduler._select_id1 and I set that variable onMouseClick using the following method:

scheduler.attachEvent("onClick", function (event_id, native_event_object){
     //any custom logic here
     scheduler._select_id1 = event_id;
});

And the copy and paste functionality is working correctly. Is there any way too resolve the issues I am having with the colissions when I copy and paste?

Kind regards
Greg Goldberg

Currently, paste logic creates the copy of event at the same time as original.
As far as I can see , logic of collision extension will not check events which are added in such way - so you will be able to copy paste event, which will result in violation of collisions rules.

Do you have some ideas how both extensions can work in the same way ( ability to create copy of event at last clicked position was not implemented, because it is not intuitive and rather confusing )

Hi Stanislav,
Thanks for the fast response, I would expect the event to be pasted as it originally was, and then repositioned to a future time slot which is large enough to cater for it in the same section (I believe that this code may be part of the 2.2 collisions script, and may just need a small tweak for sections?).
Kind regards
Greg

Existing logic of collision extension is more simple - it just move event to original position or prevent new event creation if time slot already has event. So there is no logic , which can find “empty timeslot”

Technically it possible to get all events for the day, and loop through them, searching an opening. But it seems for me as quite a lot of custom code.

Hi Stanislav,
If there is a scheduler.getEvents function which was over-ridden to accept a section id as well, the statement would be as follows:

while(scheduler.getEvents(event.start_date, event.end_date, event.section_id).length > 0)
{
   event.start_date.addMinutes(1);
   event.end_date.addMinutes(1);
}
scheduler._date = new Date(event.start_date);

EDIT.
The addition of minutes would only be required to be days in my use case, but other users may have an hour/minute view so I have bought it down to minutes rather than days.

That would push it forward into an open timeslot prior to saving it.
Kind regards
Greg

A much less intensive script

// Haven't researched if this is possible too generate an array of events
// however I can generate the events in the section if required, using my own code.
var myEvents = connector.getEvents('select *RequiredFields* FROM *TableName* where sectionId=' + event.section_id + ' order by start_date);

// a variable to let us know if we have slotted in the event to an available timeslot
var hasInserted = false;

// a variable too hold the length of an event in seconds
var eventLength = dateDiff(event.start_date, event.end_date);

for(i; i<myEvents.length; i++)
{
   // A variable to hold the difference between the end date of the current 
   // event and the start date of the next event in seconds from the myEvents array
   var timeSlot = dateDiff(myEvents[i].end_date, myEvents[i +].start_date);
   if(timeSlot >= eventLength)
   {
      hasInserted = true;
      event.start_date = myEvents[i].end_date;
      event.end_date = event.start_date.addSeconds(eventLength); 
   }
}
if(hasInserted == false)
{
   event.start_date = myEvents[myEvents.length].end_date;
   event.end_date = event.start_date.addSeconds(eventLength); 
}
scheduler._date = new Date(event.start_date);

Kind regards
Greg Goldberg

P.S. haven’t tested it yet.