ektron中的模板控制

时间:2013-10-21 07:10:28

标签: ektron

我尝试使用分类树检索分类列表,在编辑中我选择分类法并获取TaxonomyID,使用taxonomyID我想使用分类过滤器使用模板化控件显示数据。我无法检索数据我正在附加HTML和代码,所以请帮我解决问题。

    <asp:View ID="View" runat="server">          

    <asp:Label ID="lblID" runat="server"></asp:Label>            
    <CMS:Directory CssClass="taxList" ID="TaxonomySummary1" EnableAjax="true" runat="server"
                EnablePaging="false"  />

          <ektron:ContentModelSource ID="cntModelSourcs" runat="server" OrderByField="DateCreated" 
    OrderByDirection="Descending">    


   <TaxonomyFilters>
        <ektron:ContentTaxonomyFilter Operator="Contains"  ID="taxFilter" runat="server" />

    </TaxonomyFilters>

     <ContentFilters>   
       <ektron:ContentFilter Field="Id" Operator="EqualTo" Value=""   />
    </ContentFilters>
</ektron:ContentModelSource>

<ektron:ContentView ID="ContentView1" runat="server"  ModelSourceID="cntModelSourcs"  
    EktronCustomTemplate="Ektron_ContentList_Template" >

</ektron:ContentView>
    </asp:View>

enter code here       _edit“class =”TSWidget“&gt;

    <div class="ByTaxonomy TSTabPanel">
                    <div style="height: 150px; overflow: auto;">
                        <UC:TaxonomyTree ID="TaxonomyTree1" runat="server" />

                    </div>
                    <hr />

                </div>
    <div class="ByProperty TSTabPanel">
                    <table style="width: auto;">
                        <tr>
                            <td class="label">
                                <%=m_refMsg.GetMessage("lbl taxonomy id:")%>

                            </td>
                            <td>
                                <asp:TextBox ID="taxonomyid" CssClass="folderid" runat="server" Style="width: auto;"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td class="label">
                                <%=m_refMsg.GetMessage("lbl taxonomy path:")%>
                            </td>
                            <td>
                                <asp:Label ID="taxonomypath" CssClass="taxonomypath" runat="server"></asp:Label>
                              </td> 
                        </tr>                           
                    </table>
                </div>
    <div class="TSEditControls">
                    <asp:Button ID="CancelButton" CssClass="TSCancel" runat="server" Text="Cancel" OnClick="CancelButton_Click" />
                    <asp:Button ID="SaveButton" CssClass="TSSave" runat="server" OnClick="SaveButton_Click" Text="Save" />                       
                </div>
  </div>

</asp:View>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ektron.Cms;
using Ektron.Cms.Widget;
using Ektron.Cms.Common;
using Ektron.Cms.API;
using Ektron.Cms.Organization;
using Ektron.Cms.Framework.Organization;
using System.Text;
using Ektron.Cms.Search.Expressions;
using Ektron.Cms.Search;
using Ektron.Cms.Framework;
public partial class widgets_Content_TaxonomyFilter : System.Web.UI.UserControl,IWidget
{
# region Properties
protected string appPath = "";
private Ektron.Cms.CommonApi _commonAPI = new CommonApi();
private long _taxonomyid;
public string TaxonomySelected = "selected";
public string PropertySelected = "selected";
public string m_strTaxonomyPath = "/";
private string _taxonomypath;

[WidgetDataMember(0)]
public long TaxonomyId { get { return _taxonomyid; } set { _taxonomyid = value; } }

[WidgetDataMember("")]
public string TaxonomyPaths { get { return _taxonomypath; } set { 
_taxonomypath         =       value; } }    private IWidgetHost _host;    
protected ContentAPI m_refContentApi = new ContentAPI();
protected EkMessageHelper m_refMsg;
#endregion

# region Page Load
protected void Page_Load(object sender, EventArgs e)
{
    taxFilter.Value = TaxonomyId.ToString();
    ContentView1.DataBind();
}
#endregion

#region Page Init
protected void Page_Init(object sender, EventArgs e)
{
    m_refMsg = m_refContentApi.EkMsgRef;
    CancelButton.Text = m_refMsg.GetMessage("btn cancel");
    SaveButton.Text = m_refMsg.GetMessage("btn save");
    _host = Ektron.Cms.Widget.WidgetHost.GetHost(this);
    _host.Title = "Templated Control";
    _host.Edit += new EditDelegate(EditEvent);
    _host.Maximize += new MaximizeDelegate(delegate() { Visible = true; });
    _host.Minimize += new MinimizeDelegate(delegate() { Visible = false; });
    _host.Create += new CreateDelegate(delegate() { EditEvent(""); });
    _host.ExpandOptions = Expandable.ExpandOnEdit;
    appPath = _commonAPI.AppPath;
    Load += new EventHandler(delegate(object PreRenderSender, EventArgs Evt) { if 
    (ViewSet.GetActiveView() != Edit) SetTaxonomySummary(); });
    ViewSet.SetActiveView(View);
    }

protected void SetTaxonomySummary()
{
    if (TaxonomyId > 0)
    {
        lblID.Text = Convert.ToString(taxFilter.Value);

    }

}
#endregion

#region EditEvent
void EditEvent(string settings)
{
    try
    {
        string sitepath = _commonAPI.SitePath;
        string webserviceURL = sitepath + "widgets/taxonomysummary/TSHandler.ashx";
        JS.RegisterJSInclude(this, JS.ManagedScript.EktronJS);
        Ektron.Cms.API.JS.RegisterJSInclude(this, 
 Ektron.Cms.API.JS.ManagedScript.EktronJQueryClueTipJS);
        JS.RegisterJSInclude(this, JS.ManagedScript.EktronScrollToJS);
        JS.RegisterJSInclude(this, sitepath + "widgets/taxonomysummary/behavior.js", 
 "TaxonomySummaryWidgetBehaviorJS");

        if (TaxonomyId > 0)
        {
            TaxonomySelected = "";
            JS.RegisterJSBlock(this, "Ektron.PFWidgets.TaxonomySummary.webserviceURL = 
\"" + webserviceURL + "\"; 
 Ektron.PFWidgets.TaxonomySummary.setupAll();
 Ektron.PFWidgets.TaxonomySummary.SetTabs.init()
 ; ", "EktronPFWidgetsTSInit");
        }
        else
        {
            PropertySelected = "";
            JS.RegisterJSBlock(this, "Ektron.PFWidgets.TaxonomySummary.webserviceURL = 
  \"" + webserviceURL + "\"; 
 Ektron.PFWidgets.TaxonomySummary.setupAll(); ", "EktronPFWidgetsTSInit");
        }

        Css.RegisterCss(this, sitepath + "widgets/taxonomysummary/TSStyle.css",  
  "TSWidgetCSS");
        ViewSet.SetActiveView(Edit);
        //set taxonomy path
        Ektron.Cms.API.Content.Taxonomy _apiTaxonomy = new  
        Ektron.Cms.API.Content.Taxonomy();
        Ektron.Cms.TaxonomyRequest taxRequest = new Ektron.Cms.TaxonomyRequest();
        taxRequest.TaxonomyId = TaxonomyId;
        taxRequest.IncludeItems = false;
        taxRequest.TaxonomyLanguage = _apiTaxonomy.ContentLanguage;
        Ektron.Cms.TaxonomyData taxData = _apiTaxonomy.LoadTaxonomy(ref taxRequest);

        if (!(taxData == null || string.IsNullOrEmpty(taxData.Path)))
        {
            taxonomypath.Text = taxData.Path;
            m_strTaxonomyPath = taxData.Path;
        }
        else
        {
            m_strTaxonomyPath = "";
        }
    }
    catch (Exception e)
    {
        ViewSet.SetActiveView(View);
    }
}
#endregion

#region Button Events
protected void CancelButton_Click(object sender, EventArgs e)
{
    ViewSet.SetActiveView(View);

}
protected void SaveButton_Click(object sender, EventArgs e)
{
    int taxID = Convert.ToInt32(taxonomyid.Text);
    TaxonomyId = taxID;
    taxFilter.Value = TaxonomyId.ToString();

    SetTaxonomySummary();
    _host.SaveWidgetDataMembers();
    ViewSet.SetActiveView(View);

}

#endregion

public EventArgs e { get; set; }

}

1 个答案:

答案 0 :(得分:1)

如果我正确理解您的问题,您就拥有分类标识,并希望显示该分类中的所有内容。如果那不是你想要的,那么请澄清你的问题,我会尽力帮助你。

我发现附带的小部件随附的行李有时会使测试正确的API和服务器控件使用变得困难。出于这个原因,我建议从一个简单的ASPX页面开始。

<ektron:ContentModelSource ID="contentModelSource" runat="server">
</ektron:ContentModelSource>

<ektron:ContentView ID="ContentView1" runat="server"  ModelSourceID="contentModelSource" EktronCustomTemplate="Ektron_ContentList_Template">
</ektron:ContentView>

通常,您将为模板化服务器控件找到的示例显示用于设置过滤器的声明性语法,您可以将它们直接放入ASPX标记中 - 就在ContentModelSource控件内部。类似的东西:

<TaxonomyFilters> 
    <ektron:ContentTaxonomyFilter Field="Id" Operator="EqualTo" Value="208" />
</TaxonomyFilters>

(更多示例herehere。)

但是对于你想要完成的事情,你需要通过代码定义过滤器。这段代码就是这样:

protected long TaxonomyId
{
    get
    {
        long id;
        long.TryParse(Request.QueryString["id"], out id);
        return id;
    }
}

protected bool IsRecursive
{
    get
    {
        bool recursive;
        bool.TryParse(Request.QueryString["recursive"], out recursive);
        return recursive;
    }
}

protected void Page_Init(object sender, EventArgs e)
{
    if (TaxonomyId > 0)
    {
        if (IsRecursive)
        {
            var tm = new TaxonomyManager();
            var td = tm.GetItem(TaxonomyId);
            if (td != null)
            {
                var pathFilter = new ContentTaxonomyFilter();
                pathFilter.Field = ContentTaxonomyProperty.Path;
                pathFilter.Operator = CriteriaFilterOperator.StartsWith;
                pathFilter.Value = td.Path;

                contentModelSource.TaxonomyFilters.Add(pathFilter);
            }
        }
        else
        {
            var filter = new ContentTaxonomyFilter();
            filter.Field = ContentTaxonomyProperty.Id;
            filter.Value = TaxonomyId.ToString();
            filter.Operator = CriteriaFilterOperator.EqualTo;

            contentModelSource.TaxonomyFilters.Add(filter);                
        }
    }
}

有几点需要注意:

  • TaxonomyId是一个属性。我这样做是为了在这个简单的ASPX页面和一个自定义小部件之间进行简单的比较,其中你的属性将使用WidgetDataMember属性进行修饰。
  • 代码位于Page_Init事件处理程序中。这很重要。 Page_Load在页面的生命周期中为时已晚。我认为在小部件的上下文中也是如此。
  • 我的代码IsRecursive == true未必优化。您可以通过turning on caching in the FrameworkAPI获得合理的性能,但调用api获取taxonomyData然后使用它来设置内容过滤器的想法似乎有点过时了。理想情况下,ContentTaxonomyFilter将具有“递归”属性。