1

I've requirements to create a custom popup, everytime the author saves an item. The popup has text and two buttons Proceed or Cancel.

Any guidelines on how this can be done?

2 Answers 2

3

I had the same requirement to create a custom popup on the Sitecore client that looks like this

enter image description here

and here are some general steps you need to follow.

  1. Go to core database and open this path. /sitecore/content/Applications/Content Editor/Ribbons/Chunks

  2. Using insert from template, Create new chunk item (template path : /sitecore/templates/System/Ribbon/Chunk)

  3. Using insert from template, on this chunk, create a Large Button (template path: /sitecore/templates/System/Ribbon/Large Button) and enter details.

  4. Go to the path (/sitecore/content/Applications/Content Editor/Ribbons/Strips). Expand this item and you will see name of existing menus. Choose any one where you want to add this button. In this example I am adding under home item.

  5. Add a new item using the template (i.e. /sitecore/templates/System/Reference)

  6. On the publish folder go to the path (\sitecore\shell\Applications\Content Manager\Dialogs). Create a folder (I have named it “CustomUrl”) and create a file called (CustomUrl.xml). The file is will look like this.

         <Script>
         function generateUrl()
         {
            var textFrom = document.getElementById("TextFrom").value;
            var textTo = document.getElementById("TextTo").value;
            var textDestination = document.getElementById("TextDestination").value;
            var url = "?fromtext=" + textFrom + "&totext=" + textTo + "&destination=" + textDestination;
            var textUrl = document.getElementById("TextUrl");
            textUrl.innerText = url;
         }
          </Script>
          <style>
          .scFormDialogFooter{
          display: none !important; 
          }
        .scFormDialogFooter .footerOkCancel{
          display: none !important; 
        }        
      </style>
    
         <div class="scStretch" >
            <div class="col2">
               <Border Background="transparent" Border="none" GridPanel.VAlign="top" Padding="4px 0px 0px 0px">
                  <GridPanel Class="scFormTable" CellPadding="2" Columns="2" Width="100%" GridPanel.Height="100%">
                        <Label For="TextFrom" GridPanel.NoWrap="true">
                        <Literal Text="From Text:" />
                     </Label>
                     <Edit ID="TextFrom" Width="100%" OnChange="generateUrl()"/>
                     <Label for="TextTo" GridPanel.NoWrap="true">
                        <Literal Text="To Text:" />
                     </Label>
                     <Edit ID="TextTo" Width="100%" OnChange="generateUrl()"/>
                     <Label for="TextDestination" GridPanel.NoWrap="true">
                        <Literal Text="Destination Link:" />
                     </Label>
                     <Edit ID="TextDestination" Width="100%" OnChange="generateUrl()"/>
    
                     <Label for="TextUrl" GridPanel.NoWrap="true">
                        <Literal Text="Copy Url:" />
                     </Label>
                     <Label ID="TextUrl" GridPanel.NoWrap="true">
                     </Label>
                  </GridPanel>
               </Border>
            </div>
         </div>
      </FormDialog>
    
  7. Add the code file.

using System;
using Sitecore;
using Sitecore.Shell.Framework.Commands;
using Sitecore.Text;
using Sitecore.Web.UI.Sheer;
 
namespace YourNameSpace
{
    public class CustomUrl: Sitecore.Shell.Framework.Commands.Command
    {
        public override void Execute(CommandContext context)
        {
            Sitecore.Context.ClientPage.Start(this, "Run", context.Parameters);
        }
 
        protected static void Run(ClientPipelineArgs args)
        {
            if (!args.IsPostBack)
            {
                UrlString urlString = new UrlString(UIUtil.GetUri("control:CustomUrl"));
                SheerResponse.ShowModalDialog(urlString.ToString(), "800", "300", "", true);
                args.WaitForPostBack();
            }
            else
            {
                if (args.HasResult)
                {
                    if (Sitecore.Context.Item.Name == "Content Editor")
                    {
                        Sitecore.Context.ClientPage.ClientResponse.SetLocation(Sitecore.Links.LinkManager.GetItemUrl(Sitecore.Context.Item));
                    }
                }
            }
        }
    }
}

And add an entry of this new command in the config.

You may refer to my blog for all the details with a graphical representation of this.

https://sbhatiablogs.wordpress.com/2019/07/07/custom-sitecore-menu-button-with-custom-popup-dialog/

Hope this helps.

2
  • Thanks Sumit, the challenge here, if I want to use buttons in this dialog, let's say "proceed" or "cancel" how I would handle this in the code, I can add the buttons that is fine, but I just don't know how to send the buttons events to the "Run" Processor again, e.g. i clicked proceed this request should be send back from my dialog to the processor again.
    – Jose
    Feb 19 at 14:48
  • @Jose I think you should try running the pipeline in the execute method that I have mentioned in the answer. See this one for more details. archive.doc.sitecore.com/xp/en/developers/def/v1.2/remote-sdk/… Feb 20 at 6:06
1

I would recommend creating a custom event within item:saving event, invoking a dialog processor in the client pipeline, and pass it a set of arguments.

Create a custom event handler

public class SaveConfirmPopup
{
    private void StartDialog()
    {
        var savedItem = Event.ExtractParameter(args, 0) as Item;

        if (savedItem == null || savedItem.Database.Name.ToLower() != "master")
        {
            return;
        }

        // Start the dialog and pass in an item ID as an argument
        ClientPipelineArgs cpa = new ClientPipelineArgs();
        cpa.Parameters.Add("id", Item.ID.ToString());

        // Kick off the processor in the client pipeline
        Context.ClientPage.Start(this, "DialogProcessor", cpa);
    }

    protected void DialogProcessor(ClientPipelineArgs args)
    {
        var id = args.Parameters["id"];

        if (!args.IsPostBack)
        {
            // Show the modal dialog if it is not a post back
            SheerResponse.YesNoCancel("Are you sure you want to do this?", "300px", "100px");

            // Suspend the pipeline to wait for a postback and resume from another processor
            args.WaitForPostBack(true);
        }
        else
        {
            // The result of a dialog is handled because a post back has occurred
            switch (args.Result)
            {
                case "yes":

                    var item = Context.ContentDatabase.GetItem(new ID(id));
                    if (item != null)
                    {
                        // TODO: act on the item

                        // Reload content editor with this item selected...
                        var load = String.Format("item:load(id={0})", item.ID);
                        Context.ClientPage.SendMessage(this, load);
                    }

                    break;

                case "no":

                    // TODO: cancel ItemSavingEventArgs

                    break;

                case "cancel":
                    break;
            }
        }
    }
}

Create a config patch file

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <events>
      <event name="item:saving">
        <handler type="Custom.Events.SaveConfirmPopup, Custom" method="StartDialog"/>
      </event>
    </events>
  </sitecore>
</configuration>

Reference: How to display a popup when saving a Sitecore item?

Hope it helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.