Take the 2-minute tour ×
Tridion Stack Exchange is a question and answer site for Tridion developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
Did you place a breakpoint in the JavaScript? Is it being loaded/executed? –  Frank van Puffelen Aug 28 at 15:56

1 Answer 1

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.

share|improve this answer
    
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. –  Manish Mehmood Aug 29 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 Aug 29 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. –  Manish Mehmood Aug 29 at 14:01
    
Is your javascript loaded in ComponentView? When Tridion can't find your Javascript functions he will show the button as disabled. –  Thomas Hendrickx Aug 29 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 :( –  Manish Mehmood Aug 30 at 6:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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