4

All.

I have GUI Extension which should print id of selected item. It is setup so it works if item is selected in main central part of UI and user choose ribbon button or from right click context menu.

code is

Extensions.Tr.prototype.isEnabled = function Tr$isEnabled(selection, pipeline) {
//is disabled
settings = this.getUserSettings();
if (settings) {
    var allowed = this.AllowedFoUser();
    if (allowed) {
        userID = settings.User["@ID"];
        var items = selection.getItems();
        if (items.length >= 1) {
            //multiselect   

            for (var i = 0, len = items.length; i < len; i++) {
                var itemId = selection.getItem(0);

                var item = $models.getItem(itemId);

                reg = new RegExp("8192$");
                if (item) {
                    if (item.getItemType() != $const.ItemType.COMPONENT
                            && item.getItemType() != $const.ItemType.PAGE
                            && item.getItemType() != $const.ItemType.STRUCTURE_GROUP
                            && item.getItemType() != $const.ItemType.FOLDER
                            && item.getItemType() != $const.ItemType.CATEGORY
                            && item.getItemType() != $const.ItemType.KEYWORD
                            && (itemId.indexOf("catman-") == -1)
                            && !reg.test(itemId)) {
                        return false;
                    }
                }

            }
            return true;
        }
    }
}
return false;

};

GUI Extension should be disabled only if item is publication.

But if item is selected from left navigation menu (left side navigation) button in Ribbon is disabled even if item is folder.

I debugged this code and items.Length is 0 if selection is made from left menu navigation.

Is this expected behavior? Can we do some other configuration how to enable it from left menu navigation/side navigation?

Thanks.

2
  • Out of curiosity, why did you tag your question 2013 and Web8? Guess you're building an extension that should work on both? (just curious really, as this doesn't happen very often in this forum)
    – Nuno Linhares
    Commented Dec 6, 2016 at 16:55
  • I automatically chosen that, removed now. You are right, it is enough to put gui extensions Commented Dec 7, 2016 at 13:09

1 Answer 1

5

You've run into one of the oddities of the UI code: if the selection is in the tree (as opposed to the list), it's not part of the selection.getItems() collection. Instead, you have to get it from the getParentItemUri() method -- and keep in mind that this could be null too.

For simplicity's sake, you might want to create a method that handles this logic and always returns an array of items.

0

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.