search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

COPY PASTE

Asked by Anonymous
4 years ago.

Hello

using sample code for copy paste, i would like add a argument lieu.

// COPY  Event  ADD ARGUMENT :  lieu: "lieu " + args.e.lieu(),
dp.onEventMove = function(args) {
  if (args.ctrl) {
    var newEvent = new DayPilot.Event({
      start: args.newStart,
      end: args.newEnd,
      text: "text " + args.e.text(),
      lieu: "lieu " + args.e.lieu(),
      status: "A confirmer" ,
      paid: "0" ,
      resource: args.newResource,
      id: DayPilot.guid()  // generate random id DayPilot.guid()
    });
    dp.events.add(newEvent);

    // notify the server about the action here

    args.preventDefault(); // prevent the default action - moving event to the new location
  }
};

// PASTE CODE  lieu: "Lieu" + copied.lieu(), doesn't work

dp.contextMenuSelection = new DayPilot.Menu({items: [
  {text:"Paste", onclick: function() {
    if (!copied) { alert('You need to copy an event first.'); return; } 
    var selection = this.source;
    var duration = copied.end().getTime() - copied.start().getTime(); // milliseconds
    var newEvent = new DayPilot.Event({
      start: selection.start,
      end: selection.start.addMilliseconds(duration),
      text: "Text " + copied.text(),
      lieu: "Lieu" + copied.lieu(),
      status: "A confirmer" ,
      paid=: "0" ,
      resource: selection.resource,
      id: DayPilot.guid()  // generate random id DayPilot.guid()
    });
    dp.events.add(newEvent);

    // notify the server about the action here

    args.preventDefault(); // prevent the default action - moving event to the new location
  }
};

copied.lieu() return an error.

Uncaught TypeError: copied.lieu is not a function

Could you help me ?

Answer posted by Dan Letecky [DayPilot]
4 years ago.

You can access the original data object as "e.data".

Example:

var newEvent = new DayPilot.Event({
  start: args.newStart,
  end: args.newEnd,
  text: "text " + args.e.text(),
  lieu: "lieu " + args.e.data.lieu,
  status: "A confirmer" ,
  paid: "0" ,
  resource: args.newResource,
  id: DayPilot.guid()  // generate random id DayPilot.guid()
});

See also:
https://api.daypilot.org/daypilot-event-data/

Comment posted by Anonymous
4 years ago.

Hello,

thanks for help.

why "args.e.lieu" doesn't work ?

i have to replace

lieu: "lieu " + args.e.lieu(),

by

var lieu = newEvent.data.lieu;

what is the good way to get var lieu with Paste function ?

Best regard

Comment posted by Dan Letecky [DayPilot]
4 years ago.

Here, "args.e" is the DayPilot.Event object. In order to access the source data, you need to use "args.e.data". To access "lieu" property of the source data object, use "args.e.data.lieu".

The DayPilot.Event class doesn't have lieu() method, that's why you can't use args.e.lieu().

To read more about the DayPilot.Event class please see the API docs:
https://api.daypilot.org/daypilot-event-class/

A list of all DayPilot.Event methods:
https://api.daypilot.org/daypilot-event-methods/

Comment posted by Anonymous
4 years ago.

Sorry Dan,

i am beginner, and i have to choose one framework.

so Copy fonction

var newEvent = new DayPilot.Event({
  start: args.newStart,
  end: args.newEnd,
  text: "text " + args.e.text(),
 // lieu: "lieu " + args.e.lieu(),
  status: "A confirmer" ,
  paid: "0" ,
  resource: args.newResource,
  id: DayPilot.guid()  // generate random id DayPilot.guid()
});

var lieu = newEvent.data.lieu;
And Paste Funtion
 dp.contextMenuSelection = new DayPilot.Menu({items: [
    {text:"Paste", onclick: function() {
      if (!copied) { alert('You need to copy an event first.'); return; } 
      var selection = this.source;
      var duration = copied.end().getTime() - copied.start().getTime(); // milliseconds
      var newEvent = new DayPilot.Event({
        start: selection.start,
        end: selection.start.addMilliseconds(duration),
        text: "Text " + copied.text(),
	lieu: args.e.data.lieu,
	status: "A confirmer" ,
	paid: "0" ,
        resource: selection.resource,
        id: DayPilot.guid()  // generate random id DayPilot.guid()
      });

      dp.events.add(newEvent);

i have just testing this., but doesn't work.

Comment posted by Dan Letecky [DayPilot]
4 years ago.

Sorry, my first example was a bit confusing. I've updated it to make it clear:

var newEvent = new DayPilot.Event({
  start: args.newStart,
  end: args.newEnd,
  text: "text " + args.e.text(),
  lieu: "lieu " + args.e.data.lieu,
  status: "A confirmer" ,
  paid: "0" ,
  resource: args.newResource,
  id: DayPilot.guid()  // generate random id DayPilot.guid()
});

This assumes you have "lieu" property in the data source (you load it from the server side).

Your paste logic in the last example is fine.

Let me know if it still doesn't work.

Comment posted by Anonymous
4 years ago.

With last example paste logic doesn't work.

message on console :
Uncaught ReferenceError: args is not defined

sample code

dp.contextMenuSelection = new DayPilot.Menu({items: [
    {text:"Paste", onclick: function() {
      if (!copied) { alert('You need to copy an event first.'); return; } 
      var selection = this.source;
      var duration = copied.end().getTime() - copied.start().getTime(); // milliseconds
	//  var lieu = newEvent.data.lieu;
      var newEvent = new DayPilot.Event({
        start: selection.start,
        end: selection.start.addMilliseconds(duration),
        text: "Text " + copied.text(),
	lieu: args.e.data.lieu,
	status: "A confirmer" ,
	paid: "0" ,
        resource: selection.resource,
        id: DayPilot.guid()  // generate random id DayPilot.guid()
      });

      dp.events.add(newEvent);

      // notify the server about the action here
Comment posted by Dan Letecky [DayPilot]
4 years ago.

OK, replace

lieu: args.e.data.lieu,

with

lieu: copied.data.lieu,

The "copied" variable holds the DayPilot.Event object that you stored in the context menu "Copy" action:

dp.contextMenu = new DayPilot.Menu({
  items: [
    {
      text: "Copy", onclick: function () {
        copied = this.source;
      }
    }
  ],
  cssClassPrefix: "menu_default"
});
Comment posted by Anonymous
4 years ago.

Nice it works.

thank a lot

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.