Right-click menu - paste goes to wrong location

I have been struggling with getting a context menu working in the same way that using the keyboard shortcuts does. Ideally, I’d like to trigger the shortcuts from the menu but, failing that - no-one seems able to tell me how to do that - what I now have is soooooooooooo close to working.

Pasting to a date with an existing event works. However, pasting to a date that doesn’t have an existing event results in the event that was copied being “cloned” to that event’s date, along with the message that an event already exists.

I have lifted code from ‘dhtmlxscheduler_key_nav.js’, such as that which attaches the ‘onEmptyClick’ event and am sure that what I need to do is somehow use ‘getActiveNode’ to tell the paste operation where it’s supposed to operate on. How I do that is what I’m struggling with.

As I say, if there is a way to simply call the existing cut/copy/paste functionality, I’d much rather do that (to save duplicate code/maintenance effort) but if I can get this route working, it’ll do for now.

Here’s my page:[code]<!doctype html>

Timesheet html, body{ margin:0px; padding:0px; height:100%; overflow:hidden; } .copied_event div { color: white !important; background-color: #f08080 !important; }
 
 
 
[/code]

Hello,
I don’t think copying library code would be the simplest solution, since that may be written the way it is for backward and browser compatibility reasons and this particular code may have been not the ideal in the first place. Knowing your requirements you could write it simpler and add more logic as you need it.
E.g. simple copy/paste using context menu:
docs.dhtmlx.com/scheduler/snippet/eb2f15a4

regarding the built-in methods, if you don’t mind using internal methods for copy/paste functionality you can try this one:
github.com/DHTMLX/scheduler/blo … av.js#L859

  • you’ll probably have to emulate DOM event (‘e’ parameter which goes into _key_nav_copy_paste), most likely it can be done via creating a small object with properties that method expects, i.e.
    scheduler._key_nav_copy_paste({ ctrlKey:true, keyCode: 86});// invoke ctrl+v handler

Well, that seems a most odd thing to say! It’s known working code! Anyway, I got it working using that code. The one thing that doesn’t work yet is the ‘Clone to tomorrow’ option that I’ve set up. I would like the simplest, most robust means to add a day to the event date and then paste that new event data. I honestly have tried, using all manner of date-adding code but, when debugging, I see “Invalid date” at the variable’s value. I have surrounded the 2 places where this addition needs to happen with multiple hash symbols (#) to make it easier to find:[code]<!doctype html>

Timesheet html, body{ margin:0px; padding:0px; height:100%; overflow:hidden; } .copied_event div { color: white !important; background-color: #f08080 !important; }
 
 
 
[/code]

Also, from a code POV (you have, by now, surely guessed that I am a Javascript newbie!), I presume I can reduce much of the duplication around that area by defining a new variable, copying ‘new_ev’ or ‘copy_event’ to it and then using that new variable?

Hi,
regarding date operations, please look into scheduler.date helper
docs.dhtmlx.com/scheduler/api__ … other.html

It provides helpers for common date operations thus making it more difficult to make a mistake.

For cloning event to tomorrow, the function may look like this:

[code]function cloneToTomorrow(id){
var clone = Object.assign({}, scheduler.getEvent(id));// Object.assing won’t work in any IE, probably need to replace it with other deep-copy mehtod

clone.start_date = scheduler.date.add(clone.start_date, 1, “day”);
clone.end_date = scheduler.date.add(clone.end_date, 1, “day”);

clone.id = scheduler.uid();

return clone;
}[/code]

and usage:

scheduler.addEvent(cloneToTomorrow(eventId));

I presume I can reduce much of the duplication around that area by defining a new variable, copying ‘new_ev’ or ‘copy_event’ to it and then using that new variable?

Probably so, however what I think would work better is splitting copy and paste logic into a separate functions/object/module and reuse them in wherever you need.

as for reusing components code for copy and paste - it’s really up to you. In this particular case I’d probably tried reimplementing it in more readable way rather than reusing as it is, since it may save time for bugfixing in future, e.g.
docs.dhtmlx.com/scheduler/snippet/711dc54b

Many thanks, Aliaksandr, for the pointer on the date functions and for patiently answering my questions. Thanks to you, my clipboard stuff, including cloning, now works!

I’m going to go with what I have and tidy up at my leisure. Not my usual style - I like to get things right from the beginning - but my (personal) deadline for getting the entire project finished is waaaaaaay past.

Now on to ‘DHTMLx Forms’! :slight_smile: Meanwhile, here’s what I’m going with:[code]<!doctype html>

Timesheet html, body{ margin:0px; padding:0px; height:100%; overflow:hidden; } .copied_event div { color: white !important; background-color: #f08080 !important; }
 
 
 
[/code] The context menu is very simple:[code]<?xml version="1.0"?> [/code]