Copied to clipboard

Flag this post as spam?

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


  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Dec 08, 2014 @ 19:12
    Ismail Mayat
    0

    Hide remove tab

    Guys,

    I am using http://our.umbraco.org/forum/umbraco-7/developing-umbraco-7-packages/57017-Umbraco-7-Event-RemoveHide-tab-for-User-X as a base and trying to show / hide tabs, my situation is slightly different its not driven by user but by a custom property on first tab. This is checkbox list when user selects an item one more more it will show hide tabs, the checkbox options map to tab aliases.

    The issue i have is that the method being used using webapihandler which is registered in startup events, however we already have an existing one which works fine. This new one is called via a url made up by me that is called from my property editor, the url is called /umbraco/backoffice/umbracoapi/content/updatetalenttabs however in the handler when i do 

                                    var data = response.Content;
                                    var content = ((ObjectContent)(data)).Value as ContentItemDisplay;

    the content is always null can you not have 2 handlers or am i missing something?

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Dec 09, 2014 @ 15:02
    Ismail Mayat
    0

    Ok just an update on this, what I have done is created a property editor that has checkbox list of values. When you select values it will make a http get to /umbraco/backoffice/api/content/updatetalenttabs I have created a webapi controller 

        public class ContentController : ContentControllerBase
        {
            /// <summary>
            /// Constructor
            /// </summary>
            public ContentController()
                : this(UmbracoContext.Current)
            {            
            }
    
            /// <summary>
            /// Constructor
            /// </summary>
            /// <param name="umbracoContext"></param>
            public ContentController(UmbracoContext umbracoContext)
                : base(umbracoContext)
            {            
            }
    
            /// <summary>
            /// stub method so that the tabs hider call from angular will work
            /// </summary>
            /// <param name="talents"></param>
            /// <param name="id"></param>
            /// <returns></returns> 
            [HttpGet]       
            public ContentItemDisplay updatetalenttabs(string talents, int id)
            {
                var foundContent = GetObjectFromRequest(() => Services.ContentService.GetById(id));
                if (foundContent == null)
                {
                    HandleContentNotFound(id);
                }
    
                var content = Mapper.Map<IContent, ContentItemDisplay>(foundContent);
                return content;
            }
        }

     

    I also have DelgatingHandler and that listens for the url /umbraco/backoffice/api/content/updatetalenttabs and then as per code in first post does

     //gets the current item
                                    var content = ((ObjectContent)(data)).Value as ContentItemDisplay;
    
                                    var tabs = new List<Tab<ContentPropertyDisplay>>();
    
    
    
                                    //loop through content tabs and if xml file dictates it is a tab to hide and user selection from querystring then add it to list to hide
                                    foreach (var tab in content.Tabs)
                                    {
                                        if (hideTabs.Contains(tab.Alias) && selectedTypes.Contains(tab.Alias))
                                        {
                                            tabs.Add(tab);
                                        }
                                    }
    
                                    content.Properties.ForEach(i =>
                                    {
                                        i.Config.Add("hidetabs", string.Join(",", tabs.Select(t => t.Label)));
                                    });
    
                                    //loop through tabs to hide and on the content item hide them
                                    foreach (var hideTab in tabs)
                                    {
                                        foreach (var property in hideTab.Properties)
                                        {
                                            property.Config.Add("hidetab", true);
                                            property.Config.Add("tablabel", hideTab.Label);
                                        }
                                    }

    it all runs fine no errors but tabs do not hide. Any ideas??

    Regards

     

    Ismail

  • Stephen 767 posts 2273 karma points c-trib
    Dec 09, 2014 @ 17:22
    Stephen
    0

    ouch - bit hard to answer :-(

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Dec 09, 2014 @ 18:13
    Ismail Mayat
    0

    Stephan,

    I just copied the code from another post however just to understand things a bit more, i.Config.Add("hidetabs and further adding hidetab are these special in umbraco angular so when content renders it will hide the tabs?  Also when the handler finishes does content get injected into the page I would assume so?  I suspect that whatever I am doing serverside is not being passed back client side.

    Regards

    Ismail

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    Dec 10, 2014 @ 02:47
    Shannon Deminick
    1

    I don't understand how that would work.

    From the sounds of it, all you are doing is sending and receiving a request to/from your property editor, correct? Just because it's a request that returns a content object doesn't mean that the content editor will know about it. The content editor didn't make or receive the request which, it has no idea what your code is doing.

    If you wanted the content editor to refresh based on new data from the server you'd have to save the new data... then the content editor will make a request to save the values and return the updated content item. This is the request that you could modify.

    There is no way to do this dynamically without saving - even if it could be done it would be really bad to do this because if there was other data that had changed, then you change a check box and the whole editor refreshed all that data would be reset.

    Show/hiding tabs dynamically in JS is possible, you can use the editorState angular service to get the current content object and then modify content.tabs. If you combine that with modifying the tabs on the content editor's request like that other document you might be able to get what you want done.

Please Sign in or register to post replies

Write your reply to:

Draft