DayBackOnline

Button and Event Action Objects

DayBackOnline.CustomActionObjects History

Hide minor edits - Show changes to output

January 05, 2019, at 12:46 AM by 192.88.134.15 -
Changed line 1 from:
(:title Custom Action Objects:)
to:
(:title Button and Event Action Objects:)
January 05, 2019, at 12:46 AM by 192.88.134.15 -
Added lines 5-7:
Details: https://docs.dayback.com/article/124-action-objects-methods

(:if false:)
Changed lines 197-199 from:
->Useful if a routine/function has updated the event object and those changes also need to reflect in a popover that is still open.
to:
->Useful if a routine/function has updated the event object and those changes also need to reflect in a popover that is still open.

(:ifend:)
January 05, 2019, at 12:43 AM by 192.88.134.15 -
Changed line 3 from:
When working with custom actions, there are a few event-related objects that will be of use depending on whether you are building a custom action or event action.
to:
When working with custom actions, there are a few event-related objects that will be of use depending on whether you are building a button action or an event action.
April 06, 2018, at 11:20 PM by KC Embrey - Removed example code snippets and added links to the full examples
Changed lines 27-45 from:
In this example, we use a custom action to open the email client and compose an email to "[email protected]" with a subject of the event title, and a body filled with the event description and a link to the event. We get the title and description from the editEvent object, because we want to make sure we capture the current state of the popover.

-> emailSupport();

-> function emailSupport() {

-->  //Get the contents of the email
-->  var emailTo = '[email protected]';
-->  var emailSubject = editEvent.titleEdit;
-->  var description = editEvent.description;
-->  var rootURL = location.protocol + '//' + location.hostname;
-->  var linkToEvent = 'Link to event: ' + rootURL + '/#/?id=' + event.eventID;

-->  //Open default email client pre-filling email details
-->  open('mailto:' + emailTo + '?subject=' + emailSubject + '&body=' +
--->    description + '%0A%0A' + linkToEvent);
-> }


to:
Take a look at the [[ DayBackOnline.CustomActionExamples#SendEmail | emailSupport.js example here ]] that shows how to use the event and editEvent object to send an email in a custom action

Changed lines 80-103 from:
This example is similar to the example in the Custom Actions section, except we only send an email to support if the status has been changed to "On Hold". Here, we'd set this to an "On Event Save" action and get the details from the event object, since the changes from the popover have already been committed:

-> emailSupportOnHold();

->function emailSupportOnHold() {

-->  //Set the contents of the email
-->  var holdStatus = 'On Hold';
-->  var emailTo = '[email protected]';
-->  var emailSubject = 'The follwing event has been set to On Hold status: '
--->    + event.titleEdit;
--> var description = event.description;
-->  var rootURL = location.protocol + '//' + location.hostname;
-->  var linkToEvent = 'Link to event: ' + rootURL + '/#/?id=' + event.eventID;

-->  //Check if the event status has been set to "On Hold"
-->  if ($.inArray(holdStatus, revertObject.status) === -1 &&
--->  $.inArray(holdStatus, event.status) !== -1) {

-->    //Open default email client pre-filling email details
-->    open('mailto:' + emailTo + '?subject=' + emailSubject + '&body=' +
--->    description + '%0A%0A' + linkToEvent);
-->  }
->}
to:
The [[ DayBackOnline.CustomActionExamples#SendEmail | emailSupportOnHold.js example here ]] shows how you can take advantage of the objects, ''event'' and ''revertObject''
March 18, 2018, at 02:22 AM by 192.88.134.15 -
Changed line 118 from:
->  }
to:
-->  }
March 18, 2018, at 02:21 AM by 192.88.134.15 -
Changed lines 98-119 from:
[@emailSupportOnHold();

function emailSupportOnHold() {

  //Set the contents of the email
  var holdStatus = 'On Hold';
  var emailTo = '[email protected]';
  var emailSubject = 'The follwing event has been set to On Hold status: '
    + event.titleEdit;
  var description = event.description;
  var rootURL = location.protocol + '//' + location.hostname;
  var linkToEvent = 'Link to event: ' + rootURL + '/#/?id=' + event.eventID;

  //Check if the event status has been set to "On Hold"
  if ($.inArray(holdStatus, revertObject.status) === -1 &&
  $.inArray(holdStatus, event.status) !== -1) {

    //Open default email client pre-filling email details
    open('mailto:' + emailTo + '?subject=' + emailSubject + '&body=' +
    description + '%0A%0A' + linkToEvent);
  }
}@]
to:
-> emailSupportOnHold();

->function emailSupportOnHold() {

-->  //Set the contents of the email
-->  var holdStatus = 'On Hold';
-->  var emailTo = '[email protected]';
-->  var emailSubject = 'The follwing event has been set to On Hold status: '
--->    + event.titleEdit;
--> var description = event.description;
-->  var rootURL = location.protocol + '//' + location.hostname;
-->  var linkToEvent = 'Link to event: ' + rootURL + '/#/?id=' + event.eventID;

-->  //Check if the event status has been set to "On Hold"
-->  if ($.inArray(holdStatus, revertObject.status) === -1 &&
--->  $.inArray(holdStatus, event.status) !== -1) {

-->    //Open default email client pre-filling email details
-->    open('mailto:' + emailTo + '?subject=' + emailSubject + '&body=' +
--->    description + '%0A%0A' + linkToEvent);
->  }
->}
March 18, 2018, at 02:20 AM by 192.88.134.15 -
Changed lines 29-43 from:
[@emailSupport();

function emailSupport() {

  //Get the contents of the email
  var emailTo = '[email protected]';
  var emailSubject = editEvent.titleEdit;
  var description = editEvent.description;
  var rootURL = location.protocol + '//' + location.hostname;
  var linkToEvent = 'Link to event: ' + rootURL + '/#/?id=' + event.eventID;

  //Open default email client pre-filling email details
  open('mailto:' + emailTo + '?subject=' + emailSubject + '&body=' +
  description + '%0A%0A' + linkToEvent);
}@]
to:
-> emailSupport();

-> function emailSupport() {

-->   //Get the contents of the email
-->   var emailTo = '[email protected]';
-->   var emailSubject = editEvent.titleEdit;
-->   var description = editEvent.description;
-->   var rootURL = location.protocol + '//' + location.hostname;
-->   var linkToEvent = 'Link to event: ' + rootURL + '/#/?id=' + event.eventID;

-->   //Open default email client pre-filling email details
-->   open('mailto:' + emailTo + '?subject=' + emailSubject + '&body=' +
--->   description + '%0A%0A' + linkToEvent);
-> }
March 14, 2018, at 06:13 PM by KC Embrey - Added seedcodeCalendar.get('config')
Added lines 210-215:

->'''seedcodeCalendar.get'''('config');
-->Returns an object containing the global calendar configuration.

-->'''Config Properties:'''
--->''.defaultTimedEventDuration'' - The default duration for new events
March 04, 2018, at 05:14 PM by 192.88.134.15 -
Changed line 185 from:
->The cancel or confirm function will be performed when the user clicks the corresponding button.
to:
->The cancel or confirm function will be performed when the user clicks the corresponding button. Use utilities.showModal('hide') to hide the modal if you're not calling one of the cancel or confirm callbacks like action.callbacks.cancel().
March 04, 2018, at 04:59 PM by 192.88.134.15 -
Changed line 184 from:
:'''showModal'''''(title, message, cancelButtonText, cancelFunction, confirmButtonText, confirmFunction);'' - method:Displays a popover requesting user input.
to:
:'''utilities.showModal'''''(title, message, cancelButtonText, cancelFunction, confirmButtonText, confirmFunction);'' - method:Displays a popover requesting user input.
February 23, 2018, at 07:46 PM by KC Embrey - Moved useful functions to their own object property sections
Changed lines 1-2 from:
(:title Custom Action Objects and Functions:)
to:
(:title Custom Action Objects:)
Changed lines 121-162 from:
[[#UsefulFunctions]]
!! Useful Functions

The following are useful functions available in custom and event actions.

[[#eventChanged]][[#EventChanged]]
'''eventChanged'''(editEvent, event, endShifted);
->Returns the differences between an editEvent and event object. Will return false if no differences were found.
->endShifted is when the end date in the editEvent object has already been set to exclusive instead of inclusive as it is in the event popover. This would be the case in the On Event Save action, however, the editEvent and event objects have already been merged so end shifted should generally be left blank or set to false.

[[#updateEditEvent]][[#UpdateEditEvent]]
'''updateEditEvent'''(event, editEvent);
->Updates the popover data to match what is currently set in an event object.
->Useful if a routine/function has updated the event object and those changes also need to reflect in a popover that is still open.


[[#showModal]][[#ShowModal]]
'''utilities.showModal'''(title, message, cancelButtonText, cancelFunction, confirmButtonText, confirmFunction);
->Displays a popover requesting user input.
->The cancel or confirm function will be performed when the user clicks the corresponding button.

[[#showMessage]][[#ShowMessage]]
'''utilities.showMessage'''(content, showDelay, hideDelay, type, actionFunction);
->Displays the specified message in an info bar at the bottom of the calendar window.

[[#hideMessages]][[#HideMessages]]
'''utilities.hideMessages'''();
->Hides any messages that have been queued for display in the alert bar.

[[#get]][[#Get]]
'''seedcodeCalendar.get'''(‘resources’);
->Returns an array of loaded resources for the calendar.

'''seedcodeCalendar.get'''(‘statuses’);
->Returns an array of loaded statuses for the calendar.


[[#Properties]]
!! Properties available in custom action objects

Here are the properties that may be found in the custom action objects, their types, and the data they contain. Some properties are source-specific (Google, Basecamp, FileMaker) are object specific (event, editEvent, etc), or are only contained in certain event actions.

to:

[[#eventObject]]
!! event and editEvent Objects

Here are the properties that may be found in the event and editEvent objects, their types, and the data they contain. Some properties are source-specific (Google, Basecamp, FileMaker) are object specific (event, editEvent), or are only contained in certain event actions.

Added lines 175-227:



[[#utilities]]
!!utilities Object

The '''utilities''' object contains useful methods in custom actions.

[[#utilities.showModal]][[#ShowModal]]
:'''showModal'''''(title, message, cancelButtonText, cancelFunction, confirmButtonText, confirmFunction);'' - method:Displays a popover requesting user input.
->The cancel or confirm function will be performed when the user clicks the corresponding button.

[[#utilities.showMessage]][[#ShowMessage]]
:'''utilities.showMessage'''''(content, showDelay, hideDelay, type, actionFunction);'':Displays the specified message in an info bar at the bottom of the calendar window.

[[#utilities.hideMessages]][[#HideMessages]]
:'''utilities.hideMessages'''''();'':Hides any messages that have been queued for display in the alert bar.



[[#seedcodeCalendar]]
!!seedcodeCalendar Object

The '''seedcodeCalendar''' object contains details about the current calendar view.

[[#seedcodeCalendar.get]][[#Get]]
:'''seedcodeCalendar.get'''''([property]);'':Returns the corresponding property of the current calendar view.

->Examples:

->'''seedcodeCalendar.get'''(‘resources’);
-->Returns an array of loaded resources for the calendar.

->'''seedcodeCalendar.get'''(‘statuses’);
-->Returns an array of loaded statuses for the calendar.


[[#UsefulMethods]]
!! Useful Methods

The following are useful methods available in custom and event actions.

[[#eventChanged]][[#EventChanged]]
'''eventChanged'''(editEvent, event, endShifted);
->Returns the differences between an editEvent and event object. Will return false if no differences were found.

->endShifted is when the end date in the editEvent object has already been set to exclusive instead of inclusive as it is in the event popover. This would be the case in the On Event Save action, however, the editEvent and event objects have already been merged so end shifted should generally be left blank or set to false.

[[#updateEditEvent]][[#UpdateEditEvent]]
'''updateEditEvent'''(event, editEvent);
->Updates the popover data to match what is currently set in an event object.

->Useful if a routine/function has updated the event object and those changes also need to reflect in a popover that is still open.
February 23, 2018, at 07:02 PM by KC Embrey - Moved EventObject to CustomActionObjects
Added lines 1-210:
(:title Custom Action Objects and Functions:)

When working with custom actions, there are a few event-related objects that will be of use depending on whether you are building a custom action or event action.

[[#Action]][[#action]]
!!Action Object

The '''action''' object contains the event action definition and is available in all custom and event actions, although you'll likely only use it in event actions. This object includes the type of action, the URL / javascript to be executed and other attributes. For the most part, this object should be left alone except for a few cases listed below.

'''action.preventAction = true;'''
->This will prevent the event action from running the next time it is called. This is useful if you are calling the function that originally executed the event action.

'''action.callbacks.confirm();''' and '''action.callbacks.cancel();'''
->Event actions have built-in callbacks for use in asynchronous processes when “Prevent Default Action” is set to true. Useful when working with external API's where you need to wait for data or when using modal dialogs where a user is required to make a selection before continuing. Confirm will run the remainder of the action that was originally called. For example, if confirm is called in an onClick action the popover will appear. If cancel is called, the popover will not open.

[[#CustomActions]]
!! Custom Actions

In Custom Actions, there are two default objects that will be of use in your code:

->'''event''' - This object contains the properties of the event before it was modified.

->'''editEvent'''  - This object contains the properties of the event, including any changes that were made in the popover.

[+Example+]

In this example, we use a custom action to open the email client and compose an email to "[email protected]" with a subject of the event title, and a body filled with the event description and a link to the event. We get the title and description from the editEvent object, because we want to make sure we capture the current state of the popover.

[@emailSupport();

function emailSupport() {

  //Get the contents of the email
  var emailTo = '[email protected]';
  var emailSubject = editEvent.titleEdit;
  var description = editEvent.description;
  var rootURL = location.protocol + '//' + location.hostname;
  var linkToEvent = 'Link to event: ' + rootURL + '/#/?id=' + event.eventID;

  //Open default email client pre-filling email details
  open('mailto:' + emailTo + '?subject=' + emailSubject + '&body=' +
  description + '%0A%0A' + linkToEvent);
}@]


[[#EventActions]]
!! Event Actions

In event actions, we take advantage of different objects depending on the type of action specified:

[[#OnClick]]
[+On Event Click action+] - runs when an event is clicked on, before the popover is opened

->'''event''' - This object contains the properties of the event that is clicked on.

->'''event''' - This object contains the properties of the event that is clicked on. This object will contain the same contents of the event object as no data has been edited yet when clicking on an event.


[[#OnCreate]]
[+On Event Create Action+] - runs just before a new event is rendered on the calendar

->'''event''' - This object contains the properties of the event that is being created, such as the event source and dates.


[[#BeforeSave]]
[+Before Event Save Action+] - runs before any event changes are written back to the event data source

->'''event''' - This object contains the properties of the event before it was edited.

->'''editEvent''' - This object contains the properties of the event as it has been modified in the popover or via drag and drop. Any changes to this object will get saved to the event once the save action is called.


[[#OnSave]]
[+On Event Save Action+] - runs after event changes are written to the event, but before they are written to the data source, i.e. Google

->'''editEvent''' - This object contains the new properties of the event including changes made either in the popover or by dragging and dropping the event.

->'''event''' - This object has been set to match the editEvent object at this point, so the properties should match the editEvent object properties.

->'''revertObject''' - This object contains the original state of the event properties before the changes were saved. This can be used to compare pre-save data or to revert the event data.

->'''changesObject''' - This object contains only the properties that were changed as part of the save.


[[#OnDelete]]
[+On Event Delete Action+] - runs after the delete button is clicked, but before the event is removed from the view

->'''event''' - This object contains the properties of the event when the popover was opened

->'''editEvent'''  - This object contains the properties of the event, including any changes that were made in the popover before it was deleted.



[+Example+]

This example is similar to the example in the Custom Actions section, except we only send an email to support if the status has been changed to "On Hold". Here, we'd set this to an "On Event Save" action and get the details from the event object, since the changes from the popover have already been committed:

[@emailSupportOnHold();

function emailSupportOnHold() {

  //Set the contents of the email
  var holdStatus = 'On Hold';
  var emailTo = '[email protected]';
  var emailSubject = 'The follwing event has been set to On Hold status: '
    + event.titleEdit;
  var description = event.description;
  var rootURL = location.protocol + '//' + location.hostname;
  var linkToEvent = 'Link to event: ' + rootURL + '/#/?id=' + event.eventID;

  //Check if the event status has been set to "On Hold"
  if ($.inArray(holdStatus, revertObject.status) === -1 &&
  $.inArray(holdStatus, event.status) !== -1) {

    //Open default email client pre-filling email details
    open('mailto:' + emailTo + '?subject=' + emailSubject + '&body=' +
    description + '%0A%0A' + linkToEvent);
  }
}@]

[[#UsefulFunctions]]
!! Useful Functions

The following are useful functions available in custom and event actions.

[[#eventChanged]][[#EventChanged]]
'''eventChanged'''(editEvent, event, endShifted);
->Returns the differences between an editEvent and event object. Will return false if no differences were found.
->endShifted is when the end date in the editEvent object has already been set to exclusive instead of inclusive as it is in the event popover. This would be the case in the On Event Save action, however, the editEvent and event objects have already been merged so end shifted should generally be left blank or set to false.

[[#updateEditEvent]][[#UpdateEditEvent]]
'''updateEditEvent'''(event, editEvent);
->Updates the popover data to match what is currently set in an event object.
->Useful if a routine/function has updated the event object and those changes also need to reflect in a popover that is still open.


[[#showModal]][[#ShowModal]]
'''utilities.showModal'''(title, message, cancelButtonText, cancelFunction, confirmButtonText, confirmFunction);
->Displays a popover requesting user input.
->The cancel or confirm function will be performed when the user clicks the corresponding button.

[[#showMessage]][[#ShowMessage]]
'''utilities.showMessage'''(content, showDelay, hideDelay, type, actionFunction);
->Displays the specified message in an info bar at the bottom of the calendar window.

[[#hideMessages]][[#HideMessages]]
'''utilities.hideMessages'''();
->Hides any messages that have been queued for display in the alert bar.

[[#get]][[#Get]]
'''seedcodeCalendar.get'''(‘resources’);
->Returns an array of loaded resources for the calendar.

'''seedcodeCalendar.get'''(‘statuses’);
->Returns an array of loaded statuses for the calendar.


[[#Properties]]
!! Properties available in custom action objects

Here are the properties that may be found in the custom action objects, their types, and the data they contain. Some properties are source-specific (Google, Basecamp, FileMaker) are object specific (event, editEvent, etc), or are only contained in certain event actions.

:'''allDay''' - boolean:true when event is marked All Day

:'''color''' - string:The rgb value for the source default color

:'''contactDisplay''' - string:Contact display name

:'''contactID''' - array of strings:The Unique ID of the contact

:'''contactName''' - array of strings:

:'''description''' - string:The event description contents

:'''end''' - momentJS object:The event end time

:'''eventID''' - string:The unique ID of the object

:'''eventSource''' - string:The unique calendar source

:'''eventURL''' - string:The URL of the event where the data is stored (Google/Basecamp/SalesForce)

:'''location''' - string:The location of the event

:'''projectDisplay''' - string:Project display name

:'''projectID''' - array of strings:The Unique ID(s) of the project(s)

:'''projectName''' - array of strings:The display name(s) of the project(s)

:'''recordID''' - string:The record ID in FileMaker

:'''resource''' - array of strings:The list of assigned resources

[[#event.schedule]]
:'''schedule''' - object:Contains source information such as name, server connection information, field mappings.

:'''start''' - momentJS object:The event start time

:'''status''' - array of strings:List of assigned statuses

:'''tags''' - string:Event Tag(s)

:'''timeEnd''' - string:The string value of the end time

:'''timeStart''' - string:The string value of the start time

:'''title''' - string:The summary of the event that is displayed in the event block on the calendar

:'''titleEdit''' - string:The event title text
(855) SEEDCODE
[email protected]
Follow us: