var retMsg = ""; var retHTML = ""; var errMsg = ""; var eventCopyResultFooterJS = ""; var lbFormURL = ""; var newCalEventID = ""; var copyEventDetails = StructNew(); var copyEventDatesTimes = StructNew(); var newDateTimeIDlist = ""; var copyEventRecurrence = StructNew(); var newRecurrenceIDlist = ""; var updateNewEvent = StructNew(); var newDataStruct = StructNew(); var newEventDataPageID = ""; var dtCopyErrCnt = 0; var recurCopyErrCnt = 0; var key = ""; var appConfig = getAppConfig(); var actionApp = getAppBeanName(); var lightBoxURL = application.ADF.lightboxProxy; var uiTheme = getUItheme(); var formBean = "calEventsForms"; var formMethod = "renderEventEditForm"; var editTitle = "Edit Copied Event"; var callbackAction = "updateEventCache_cbFunct"; var callbackActionID = ""; var useVerboseOutput = getVerboseOutputStatus(); //if ( useVerboseOutput ) // causes an issue with the copy process // arguments.appdebug = true; // STEP 1: Do the copy of the event record to get the NewEventID copyEventDetails = application.ptCalendar.calEventDetailsService.copyCalEventDetails(srcEventID=arguments.srcEventID); // Set the NewCalEventID value from the newly created event if ( StructKeyExists(copyEventDetails,"CONTENTUPDATED") AND copyEventDetails.CONTENTUPDATED EQ true ) { retMsg = retMsg & 'The Event was Copied.' & '
'; if ( StructKeyExists(copyEventDetails,"newEventID") AND LEN(TRIM(copyEventDetails.newEventID)) ) newCalEventID = copyEventDetails.newEventID; // STEP 2: (OPTIONAL) if we have dateTimeIDs copy the dateTime records for this event... using the NewEventID as the calEventID // - return a list of the NewDateTime IDs if ( arguments.datetimeCopy AND LEN(TRIM(arguments.srcDateTimeIDList)) AND LEN(TRIM(newCalEventID)) ) { copyEventDatesTimes = application.ptCalendar.calEventDateTimeService.copyCalEventDatesTimes( srcUUIDlist=arguments.srcDateTimeIDList ,calEventID=newCalEventID ); // Loop over the results struct and create a list of new datetime IDs for ( key in copyEventDatesTimes ) { if ( StructKeyExists(copyEventDatesTimes[key],"CONTENTUPDATED") AND copyEventDatesTimes[key].CONTENTUPDATED EQ true ) { newDateTimeIDlist = ListAppend(newDateTimeIDlist,key); } else { // Output Date/Time Copy Error if ( dtCopyErrCnt EQ 0 ) errMsg = errMsg & 'Error: The Event Date/Time failed to Copy! See Logs...' & '
'; if ( StructKeyExists(copyEventDatesTimes[key],"msg") ) { application.ADF.log.addLogEntry(message='Error: The Event Date/Time failed to Copy!: #copyEventDatesTimes[key].MSG# - DateTimeID: #key# - newEventID: #copyEventDatesTimes[key].calEventID#', useDatePrefix=true); } dtCopyErrCnt++; } } // If records were created if ( ListLen(newDateTimeIDlist) GT 0 ) retMsg = retMsg & 'The Date Time Records were Copied.' & '
'; } // STEP 3: (OPTIONAL) if we have recurrenceIDs copy the recurrence records for this event... using the NewEventID as the calEventID // - return a list of NewRecurrenceIDs if ( arguments.recurrenceCopy AND LEN(TRIM(arguments.srcRecurrenceIDList)) AND LEN(TRIM(newCalEventID)) ) { copyEventRecurrence = application.ptCalendar.calEventRecurrenceService.copyCalEventRecurrence( srcUUIDlist=arguments.srcRecurrenceIDList ,calEventID=newCalEventID ); // Loop over the results struct and create a list of new datetime IDs for ( key in copyEventRecurrence ) { if ( StructKeyExists(copyEventRecurrence[key],"CONTENTUPDATED") AND copyEventRecurrence[key].CONTENTUPDATED EQ true ) { newRecurrenceIDlist = ListAppend(newRecurrenceIDlist,key); } else { // Output Recurrence Copy Error if ( recurCopyErrCnt EQ 0 ) errMsg = errMsg & 'Error: The Event Recurrence failed to Copy! See Logs...' & '
'; if ( StructKeyExists(copyEventRecurrence[key],"msg") ) { application.ADF.log.addLogEntry(message='Error: The Event Recurrence failed to Copy!: #copyEventRecurrence[key].MSG# - RecurrenceID: #key# - newEventID: #copyEventRecurrence[key].calEventID#', useDatePrefix=true); } recurCopyErrCnt++; } } // If records were created if ( ListLen(newRecurrenceIDlist) GT 0 ) retMsg = retMsg & 'The Recurrence Record was Copied.' & '
'; } // STEP 4: Update the "New Event" with the NewdateTimeIDs and NewRecurrenceIDs if ( LEN(TRIM(newCalEventID)) AND ( LEN(TRIM(newDateTimeIDlist)) OR LEN(TRIM(newRecurrenceIDlist)) ) ) { updateNewEvent = application.ptCalendar.calEventDetailsService.updateCalEventDetailsDateTimeRecurrence( uniqueID=newCalEventID ,dateTimeIDlist=newDateTimeIDlist ,recurrenceIDlist=newRecurrenceIDlist ); if ( StructKeyExists(updateNewEvent,"CONTENTUPDATED") AND updateNewEvent.CONTENTUPDATED EQ true ) { retMsg = retMsg & 'The New Event was updated.' & '
'; } else { // Output New Event Copy Error errMsg = errMsg & 'Error: The New Event failed to Update! See Logs...' & '
'; if ( StructKeyExists(updateNewEvent,"msg") ) { application.ADF.log.addLogEntry(message='Error: The New Event failed to Update!: #updateNewEvent.MSG# - srcEventID: #copyEventDetails.srcEventID#', useDatePrefix=true); } } } // STEP 5: Get the pageID of the "New Event" to be able to open the new event in a form if ( LEN(TRIM(newCalEventID)) ) { newDataStruct = application.ptCalendar.calEventDetailsDAO.getEventDetailsDataByUniqueID(uniqueID=TRIM(newCalEventID)); if ( StructKeyExists(newDataStruct,"pageID") AND IsNumeric(newDataStruct.pageid) AND newDataStruct.pageid GT 0 ) newEventDataPageID = newDataStruct.pageid; } } else { errMsg = errMsg & 'Error: The Event failed to Copy! See Logs...' & '
'; if ( StructKeyExists(copyEventDetails,"msg") ) { application.ADF.log.addLogEntry(message='Error: The Event failed to Copy!: #copyEventDetails.MSG# - srcEventID: #copyEventDetails.srcEventID#', useDatePrefix=true); } } // STEP 6: Build the "New Copied Event" URL to be opened in a LB form so the event can be modified if ( IsNumeric(newEventDataPageID) ) { /* Build the URL to open the new Event LB form */ lbFormURL = lightBoxURL; lbFormURL = lbFormURL & "?bean=#formBean#"; lbFormURL = lbFormURL & "&method=#formMethod#"; lbFormURL = lbFormURL & "&appName=#actionApp#"; lbFormURL = lbFormURL & "&datapageid=#newEventDataPageID#"; lbFormURL = lbFormURL & "&lbAction=#arguments.lbAction#"; lbFormURL = lbFormURL & "&title=#editTitle#"; lbFormURL = lbFormURL & "&appcallback=#callbackAction#"; lbFormURL = lbFormURL & "&cbIDlist=#newCalEventID#"; } // Load the Scripts resources application.ptCalendar.scripts.loadJQuery(); application.ptCalendar.scripts.loadJQueryUI(themeName=uiTheme); application.ptCalendar.scripts.loadADFLightbox(); // Include the Calendar Admin Style Sheet application.ptCalendar.calService.loadCalendarAdminCSS();
// Load the inline JavaScript after the libraries have loaded application.ptCalendar.scripts.addFooterJS(eventCopyResultFooterJS, "TERTIARY"); // PRIMARY, SECONDARY, TERTIARY // If error message, add to return message if ( TRIM(errMsg) NEQ '' ) retHTML = errMsg & retHTML; else if ( TRIM(retMsg) NEQ '' ) retHTML = retMsg & retHTML; return retHTML;