4

I am trying to enable my control for DashboardView and ComponentView. In DashboardView view I can enable the control on selection of component which is working fine BUT if i open the component in ComponentView the control is not getting enabled. If some have the solution? Here is the code

Extensions.HW.prototype.isAvailable = function HW$isAvailable(selection, pipeline)
{
 var items = selection.getItems();
  var item = $models.getItem(selection.getItem(0));

if (items.length >= 1 &&  item.getItemType() == $const.ItemType.COMPONENT ) { 
    return true;
    }
    else {
        return false;
    }
};

Extensions.HW.prototype.isEnabled = function HW$isEnabled(selection, pipeline) {
    var items = selection.getItems();
     var item = $models.getItem(selection.getItem(0));
    if (items.length >= 1 && item.getItemType() == $const.ItemType.COMPONENT ) {        
            return true;
    }
    else {
        return false;
    }
};

I am using two views in configuration as

      <cfg:dependency>HelloWorldRibbon.Commands</cfg:dependency>
      </ext:dependencies>

      <ext:apply>
        <ext:view name="DashboardView">
          <ext:control id="DashboardToolbar" />
            </ext:view>
         <ext:view name="ComponentView">
          <ext:control id="ItemToolbar" />

        </ext:view>

      </ext:apply>
    </ext:extension>

Here is the screenshot on which control is disabled enter image description here

I want to enable this control while component is opened.

1
  • Did you place a breakpoint in the JavaScript? Is it being loaded/executed? Commented Aug 28, 2014 at 15:56

1 Answer 1

9

Your logic for isEnabled and isAvailable is triggered around the selection variable, and in your case checking to see if the item selected is a component and that the number of items selected is at least one. This works in your DashboardView when you select a component because your selection now has a length of one, and the item.getItemType() is a component.

However in your ComponentView, you don't have anything selected. You'll want to adapt your logic here to remain the same for DashboardView, but to always show for ComponentView.

You can modify your check to do something like:

if ($display.getView().getId() === "ComponentView") {
    return true;
}
...
can be considered a DashboardView at this point, put your existing logic here from your example to check the selection variable
...

Hope that helps! You should now have your extension always showing in the Component View (assuming that's what was desired), and only enabled in Dashboard view if you have selected a component item.

6
  • Thanks Alex for your help. I tried this but unfortunately it returning 'DashboardView' when i tried alert($display.getView().getId()); inside isEnable and isAvailable methods. When i open the component in new window it still alert DashboardView. Commented Aug 29, 2014 at 12:18
  • Interesting, my experiment with 2013 has this working as "ComponentView" when I open up the component view window. I've tried both as a command and in the console window... try typing in $display.getView().getId() from your console in the component window? An alternative that you can try as well is : if ($display.getItem().getItemType() === $const.ItemType.COMPONENT) { ... }
    – Alex Klock
    Commented Aug 29, 2014 at 13:37
  • Thanks Alex for your suggestion.I have tried this as well and after that I have removed all checks and just returning true from the Available and executes methods but it is still disabled in ComponentView. Commented Aug 29, 2014 at 14:01
  • Is your javascript loaded in ComponentView? When Tridion can't find your Javascript functions he will show the button as disabled. Commented Aug 29, 2014 at 14:15
  • Yes, If i open or refresh my componentView page, The _IsAvailavle method is called. I can check it by alert($display.getView().getId()); method but it always displays "DashboardView" as a result in the alert box. I also followed this link : tridion.stackexchange.com/questions/7409/… but it did not work for me :( Commented Aug 30, 2014 at 6:29

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.