如何在组件窗口上启用按钮

时间:2012-08-02 15:47:58

标签: tridion tridion-2011

我创建了一个按钮,仅在打开Component时才会在工具栏中显示。我已经编写了相同的config和js文件,但问题是这个按钮显示为禁用。按钮在那里,但没有启用。 请帮助我,我该如何启用它。

EDITED

Type.registerNamespace("Extensions.Commands");

Extensions.Commands.Button = function Extensions.Commands$Button(element) {
Type.enableInterface(this, "Extensions.Commands.Button");
this.addInterface("Tridion.Cme.Command", [element]);
this.addInterface("Tridion.Cme.FaCommand", [element]);
alert('inside the pageload');
}; 

Extensions.Commands.Button.prototype._isAvailable = function Button$_isAvailable(target) {
alert('inside the available mode');
if (target.editor.getDisposed()) {
    return false;
}

return true;
};

Extensions.Commands.Button.prototype._isEnabled = function Button$_isEnabled(target) {
alert('inside the enable mode');
if (!Tridion.OO.implementsInterface(target.editor, "Tridion.FormatArea") ||     target.editor.getDisposed()) {
alert('indise if loop');
    return false;
}

return true;
};

我的配置文件是这样的

<resources cache="true">
<cfg:filters/>
<cfg:groups>
  <cfg:group name="Extensions.Commands" >
    <cfg:fileset>          
      <cfg:file type="script">/Popups/PopupReference.js</cfg:file>

    </cfg:fileset>

    <cfg:dependencies>
      <cfg:dependency>Tridion.Web.UI.Editors.CME</cfg:dependency>
      <cfg:dependency>Tridion.Web.UI.Editors.CME.commands</cfg:dependency>
    </cfg:dependencies>
  </cfg:group>

   <cfg:group name="Extensions.Commands.Button.Commands"  merger="Tridion.Web.UI.Core.Configuration.Resources.CommandGroupProcessor"   include="byreference" merge="release">
    <cfg:fileset>
      <cfg:file type="script">/Commands/Button.js</cfg:file>

      <cfg:file type="reference">Extensions.Button.CommandSet</cfg:file>
    </cfg:fileset>

    <cfg:dependencies>
      <cfg:dependency>Tridion.Web.UI.Editors.CME</cfg:dependency>
      <cfg:dependency>Tridion.Web.UI.Editors.CME.commands</cfg:dependency>
    </cfg:dependencies>
  </cfg:group> 

  </cfg:groups>
 </resources>
 <definitionfiles/>
 <extensions>
   <ext:editorextensions>
  <ext:editorextension target="CME">
    <ext:editurls/>
    <ext:listdefinitions/>
    <ext:taskbars/>
    <ext:commands/>
    <ext:commandextensions/>
    <ext:contextmenus/>
    <ext:lists/>
    <ext:tabpages/>
    <ext:toolbars/>
    <ext:ribbontoolbars>
      <ext:add>
        <!-- RIBBON TAB -->
 <!-- GROUPS -->
        <ext:extension assignid="ExtensionGroup" pageid="FormatPage" name="ExtensionsName">
          <ext:group/>
          <ext:apply>
            <ext:view name="ComponentView">
              <ext:control id="ItemToolbar"/>
            </ext:view>
          </ext:apply>
        </ext:extension>

        <!-- BUTTONS -->
        <ext:extension pageid="FormatPage" groupid="ExtensionGroup" name="Button" assignid="Button">
          <ext:command>Button</ext:command>
          <ext:title>Button</ext:title>
          <ext:dependencies>
            <cfg:dependency>Extensions.Commands.Button</cfg:dependency>
          </ext:dependencies>
          <ext:apply>
            <ext:view name="ComponentView">
              <ext:control id="ItemToolbar"/>
            </ext:view>
          </ext:apply>
        </ext:extension>
      </ext:add>
    </ext:ribbontoolbars>
  </ext:editorextension>
  </ext:editorextensions>
  <ext:dataextenders/>
</extensions>            
<commands>
 <cfg:commandset id="Extensions.Commands.Button.CommandSet">
  <cfg:command name="Button" implementation="Extensions.Commands.Button"/>
  <cfg:dependencies>
<cfg:dependency>Extensions.Commands.Button</cfg:dependency>
    <cfg:dependency />
  </cfg:dependencies>
 </cfg:commandset>
 </commands>
 <contextmenus/>
 <localization/>
 <settings>
<defaultpage/>
<navigatorurl/>
<editurls/>
<listdefinitions/>
<itemicons/>
<theme>
  <path>Themes</path>
</theme>
<customconfiguration/>
 </settings>

2 个答案:

答案 0 :(得分:4)

配置文件中从不引用资源组“Extensions.Commands.Button.Commands”。 除了在Button扩展组中,您依赖于“Extensions.Commands.Button”组,该组在配置文件中不存在。 所以建议清理配置文件,删除不需要的依赖项等。

P.S。没有必要继承“Tridion.Cme.Command”和“Tridion.Cme.FaCommand”,因为最后一个已经继承了第一个。

答案 1 :(得分:2)

弗兰克说我会检查_IsEnabled。当此方法返回true时,将在SDL Tridion GUI中启用该按钮

我会按照以下方式调试它(注意:在我的JS调试中我有点老了)))

RTFExtensions.Commands.Button.prototype._isEnabled = function Customtags$_isEnabled(target) {
if (!Tridion.OO.implementsInterface(target.editor, "Tridion.FormatArea") ||  target.editor.getDisposed()) {
    return false;
}

以下列方式:

  • 检查firebug是否有任何JS错误
  • 在_isEnabled中发出提醒以查看是否正在输入
  • 在IF语句中发出警报以查看是否始终输入

一旦你有了它的工作,我有兴趣知道出了什么问题,或许你可以在这里提供解决方案吗?