/// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            if (this.GetAttributeValue("ShowClipboardIcon").AsBoolean())
            {
                // Setup for being able to copy text to clipboard
                RockPage.AddScriptLink(this.Page, "~/Scripts/clipboard.js/clipboard.min.js");
                string script = string.Format(@"
    new ClipboardJS('#{0}');
    $('#{0}').tooltip();
", btnCopyToClipboard.ClientID);
                ScriptManager.RegisterStartupScript(btnCopyToClipboard, btnCopyToClipboard.GetType(), "share-copy", script, true);

                Uri uri = new Uri(Request.Url.ToString());
                btnCopyToClipboard.Attributes["data-clipboard-text"] = uri.Scheme + "://" + uri.GetComponents(UriComponents.HostAndPort, UriFormat.UriEscaped) + CurrentPageReference.BuildUrl();
                btnCopyToClipboard.Visible = true;
            }
            else
            {
                btnCopyToClipboard.Visible = false;
            }

            // this event gets fired after block settings are updated. it's nice to repaint the screen if these settings would alter it
            this.BlockUpdated += Block_BlockUpdated;
            this.AddConfigurationUpdateTrigger(upnlContent);
        }
Example #2
0
        /// <summary>
        /// Handles the Click event of the btnCopy control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnCopy_Click(object sender, EventArgs e)
        {
            if (Page.IsValid && CommunicationId.HasValue)
            {
                var rockContext   = new RockContext();
                var service       = new CommunicationService(rockContext);
                var communication = service.Get(CommunicationId.Value);
                if (communication != null)
                {
                    var newCommunication = communication.Clone(false);
                    newCommunication.CreatedByPersonAlias    = null;
                    newCommunication.CreatedByPersonAliasId  = null;
                    newCommunication.CreatedDateTime         = RockDateTime.Now;
                    newCommunication.ModifiedByPersonAlias   = null;
                    newCommunication.ModifiedByPersonAliasId = null;
                    newCommunication.ModifiedDateTime        = RockDateTime.Now;
                    newCommunication.Id   = 0;
                    newCommunication.Guid = Guid.Empty;
                    newCommunication.SenderPersonAliasId = CurrentPersonAliasId;
                    newCommunication.Status = CommunicationStatus.Draft;
                    newCommunication.ReviewerPersonAliasId = null;
                    newCommunication.ReviewedDateTime      = null;
                    newCommunication.ReviewerNote          = string.Empty;
                    newCommunication.SendDateTime          = null;

                    communication.Recipients.ToList().ForEach(r =>
                                                              newCommunication.Recipients.Add(new CommunicationRecipient()
                    {
                        PersonAliasId             = r.PersonAliasId,
                        Status                    = CommunicationRecipientStatus.Pending,
                        StatusNote                = string.Empty,
                        AdditionalMergeValuesJson = r.AdditionalMergeValuesJson
                    }));


                    foreach (var attachment in communication.Attachments.ToList())
                    {
                        var newAttachment = new CommunicationAttachment();
                        newAttachment.BinaryFileId      = attachment.BinaryFileId;
                        newAttachment.CommunicationType = attachment.CommunicationType;
                        newCommunication.Attachments.Add(newAttachment);
                    }

                    service.Add(newCommunication);
                    rockContext.SaveChanges();

                    // Redirect to new communication
                    if (CurrentPageReference.Parameters.ContainsKey("CommunicationId"))
                    {
                        CurrentPageReference.Parameters["CommunicationId"] = newCommunication.Id.ToString();
                    }
                    else
                    {
                        CurrentPageReference.Parameters.Add("CommunicationId", newCommunication.Id.ToString());
                    }

                    Response.Redirect(CurrentPageReference.BuildUrl());
                    Context.ApplicationInstance.CompleteRequest();
                }
            }
        }