Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Oct 17, 2012 @ 12:13
    Jeroen Breuer
    0

    Dashboard tab buttons

    Hello,

    I'm creating a dashboard and above the dashboad there is always a tab. I'd like to add a save button to that tab. Does anyone have an example? Thanks.

    Jeroen

  • Matt Bliss 176 posts 234 karma points
    Oct 17, 2012 @ 12:21
    Matt Bliss
    0

    Hi Jeroen,

    This code is based on the Custom Section Video on Umbraco TV:

            protected override void OnInit(EventArgs e)
            {
                base.OnInit(e);

                ImageButton save = Panel1.Menu.NewImageButton();
                save.ImageUrl = umbraco.GlobalSettings.Path + "/images/editor/save.gif";
                save.AlternateText = "Save";
                save.Click += new ImageClickEventHandler(save_Click);
            }

    Hope it helps

  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Oct 17, 2012 @ 12:23
    Dirk De Grave
    2

    Jeroen,

    Firstly, use a page event to tap into the Load event of umbracoPage object.

    umbracoPage.Load += UmbracoPageOnLoad;

    Also check what page it actually is, as this event is firing for editContent/editMedia/dashboard.axps.

    var page = (umbracoPage)sender;
    var path = page.Page.Request.Path.ToLowerInvariant();
    if (!path.Contains("dashboard.aspx"))
    {
    return;
    }

     And then some code to add a button to the menu bar of a specific tab page. Parameter passed in is the page object from above code snippet

     private static void AddDashboardMenuItems(Control control)
            {
                var contentPlaceHolder = (ContentPlaceHolder)control.FindControl("body");
                var tabView = FindControlRecursive(contentPlaceHolder, "dashboardTabs");

    if (tabView == null)
                {
                    return;
                }

    var tabPages = tabView.GetPanels().Cast();

    if (!tabPages.Any())
                {
                    return;
                }

    var mediaTabPage = tabPages.Last();
    var uploadImageButton = mediaTabPage.Menu.NewIcon(0);
    uploadImageButton.ID = string.Format("{0}_uploadImage", mediaTabPage.ID);
    uploadImageButton.ImageURL = SystemDirectories.Umbraco + "/images/editor/upload.png";
    uploadImageButton.OnClickCommand = "javascript:UmbClientMgr.openModalWindow('Dialogs/Dialog.aspx?nodeId=x', 'title', true, 600, 300, 0, 0, '', '');";
    uploadImageButton.AltText = "Alt";
            }

     Hope this helps.

    Cheers,

    /Dirk

     

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Oct 17, 2012 @ 12:24
    Jeroen Breuer
    0

    Thanks Matthew I've done that before, but this isn't a custom section. It a dashboard and I don't know how to get the webcontrol which I need to add the button.

    Jeroen

  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Oct 17, 2012 @ 12:25
    Dirk De Grave
    0
     private static T FindControlRecursive<T>(Control parent, string id) where T : Control
            {
                if ((parent is T) && (parent.ID == id))
                {
                    return (T)parent;
                }
    return (from Control control in parent.Controls select FindControlRecursive<T>(control, id)).FirstOrDefault(foundControl => foundControl != null);
            }
  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Oct 17, 2012 @ 12:27
    Dirk De Grave
    0

    Must say that I'm only having 2 dashboard controls and the second one is the one I had to add the button to... therefore the hardcoded

    var mediaTabPage = tabPages.Last(); 

     

    /Dirk

  • Matt Bliss 176 posts 234 karma points
    Oct 17, 2012 @ 12:28
    Matt Bliss
    0

    Sorry Jeroen, didn't read it properly, looks Like Dirk has provided the answer though!

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Oct 17, 2012 @ 13:00
    Jeroen Breuer
    0

    Thanks for the code Dirk. This is how I solved it:

    public partial class CreateNews : UserControl
    {
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
    
            var tabView = Page.FindControlRecursive<TabView>("dashboardTabs");
            TabPage tabPage = (TabPage)tabView.GetPanels()[0];
    
            ImageButton saveButton = tabPage.Menu.NewImageButton();
            saveButton.ID = "ImgBtnSaveNews";
            saveButton.Click += new ImageClickEventHandler(SaveButton_Click);
            saveButton.AlternateText = "Save";
            saveButton.ImageUrl = GlobalSettings.Path + "/images/editor/save.gif";
        }
    
        protected void SaveButton_Click(object sender, ImageClickEventArgs e)
        {
            //Todo save data.
    
            //Show the bubble that the data has been saved.
            BasePage.Current.ClientTools.ShowSpeechBubble(BasePage.speechBubbleIcon.save, "Saved", "The data has been saved succesfully");
        }
    }

    In this example I use my own version of FindControlRecursive which I already had :-). There is only one dashboard control so I need to fetch the first TabPage. I added this code inside the Dashboard usercontrol.

    Jeroen

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies