2012-08-11 14 views
0

創建按鈕我已經創建一個用戶控件對於具有下面的另外兩個按鈕一個作爲在外表套上使用用戶控件功能區

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ViewItemsGroup.ascx.cs" Inherits="SDL.Examples.UI.Controls.ViewItemsGroup" %> 
<%@ Import Namespace="Tridion.Web.UI" %> 
<c:RibbonItemsGroup runat="server" ID="RibbonItemsGroup"> 
    <c:RibbonButton runat="server" CommandName="ViewStaging" Title="View in Staging" Label="View In Staging" IsSmallButton="true" ID="ViewStagingBtn" /> 
    <c:RibbonButton runat="server" CommandName="ViewLive" Title="View in Live" Label="View in Live" IsSmallButton="true" ID="ViewLiveBtn" /> 
</c:RibbonItemsGroup> 

在extension.config如下所示我指的用戶控件。

<ext:extension assignid="ViewItemsGroup" groupid="EditGroup" name="View" pageid="HomePage" insertbefore="PublishGroup"> 
    <ext:group>~/Controls/ViewItemsGroup.ascx</ext:group> 
    <ext:dependencies>  
    <cfg:dependency>My.Theme</cfg:dependency> 
    </ext:dependencies> 
    <ext:apply>  
    <ext:view name="DashboardView"> 
     <ext:control id="DashboardToolbar" /> 
    </ext:view> 
    <ext:view name="PageView"> 
     <ext:control id="ItemToolbar" /> 
    </ext:view> 
    </ext:apply> 
</ext:extension> 
  1. 我是否需要包括我的按鈕(一個或多個)的細節(像ID的用戶控件提到的)也extension.config?是否需要在<ext:command> ---- </ext:command>或任何其他地方添加。

  2. usercontrol創建的,我只是隨同extension.config,.js和引用到我的extension.config文件中的ascx。我是否需要將我的用戶控件放在任何其他文件夾中?

+1

你真的需要問的問題1?如果您從extension.config中刪除了詳細信息並且它不起作用,那麼顯然它們是必需的。 – 2012-08-11 11:57:09

+0

我試圖放置即使像' ButtonId '擴展名,但它說無效的子元素命令。我需要準確放置的位置? – pavan 2012-08-11 12:12:56

+1

你檢查過配置的模式嗎? http://stackoverflow.com/questions/11897745/where-can-i-find-the-schema-for-the-sdl-tridion-ui-extensions-configuration-file – 2012-08-11 13:28:01

回答

5
  1. 在你extension.config,你ext:dependencies節點下指定ItemsGroup的依賴關係。這應該指向你的cfg:group,你引用一個命令集,然後指向你的JavaScript文件。您需要正確地創建這些引用,否則SDL Tridion UI框架將無法知道在哪裏可以找到您的代碼。該系統就像我們無法施展魔法一樣,也沒有水晶球。

  2. 用戶控件也是如此,如果你不把它放在配置,​​JavaScript和CSS等其他擴展文件旁邊,UI框架如何能夠找到它。您放置它的位置,您在ext:group節點中指定。例如~/Controls/MyItemsGroup.ascx,然後將其放入擴展名根目錄的子目錄Controls中。

你的配置應該是這個樣子的話,與依賴指向你它上面的resources節點下指定的組:

<ext:ribbontoolbars> 
    <ext:add> 
    <ext:extension assignid="MyGroup" ...> 
     <ext:group>~/Controls/MyItemsGroup.ascx</ext:group> 
     <ext:dependencies> 
     <cfg:dependency>My.Commands</cfg:dependency> 
     </ext:dependencies> 
     ... 
    </ext:extension> 
    </ext:add> 
</ext:ribbontoolbars> 

然後在你的控制,你直接引用命令在其屬性中,這是JavaScript命令,其下的方法等等。控制將具有類似的內容:

<c:RibbonItemsGroup runat="server" ID="MyItemsGroup"> 
    <c:RibbonButton runat="server" 
        CommandName="MyBtn" 
        Title="My Title" Label="My Label" 
        IsSmallButton="true" ID="MyId" /> 
    ... 
</c:RibbonItemsGroup> 

最後一個實現那麼你的按鈕命令將使用的CommandName在其命名空間中的JavaScript:

Type.registerNamespace("Extensions"); 

Extensions.MyBtn = function Extensions$MyBtn() { 
    Type.enableInterface(this, "Extensions.MyBtn"); 
    this.addInterface("Tridion.Cme.Command", ["MyBtn"]); 
}; 

Extensions.MyBtn.prototype._isAvailable = function MyBtn$_isAvailable(selection) { 
    return true; 
}; 

Extensions.MyBtn.prototype._isEnabled = function MyBtn$_isEnabled(selection) { 
    return this._isAvailable(selection); 
}; 

Extensions.MyBtn.prototype._execute = function MyBtn$_execute(selection) { 
    // this is where your code comes 
}; 
相關問題