More in this section

Forums / Developing with Sitefinity / publications functionality

publications functionality

7 posts, 0 answered
  1. GV
    GV avatar
    33 posts
    Registered:
    11 Sep 2009
    04 Feb 2010
    Link to this post
    Hello,

    I need to provide publications functionality in my sitefinity CMS where
    1) The admin should be able to add/edit/delete the publications
    2) The end user should be able to view/search the list of all publications.

    Publication is made up of fields(columns) like publication date,author,type,type of audience,description etc.

    How do I go about this. Thanks for the support in advance

    -GV
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    04 Feb 2010
    Link to this post
    Hi GV,

    I think that you can use News or GenericContent module or provider for one of these modules. You can create a public control that filters the list using ContentFilterBuilder class which can filter by metakeys.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
  3. GV
    GV avatar
    33 posts
    Registered:
    11 Sep 2009
    18 Feb 2010
    Link to this post
    Thank you Ivan,

    Can you please elaborate this or give me some example?

    Thanks & regards
    GV
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    18 Feb 2010
    Link to this post
    Hello GV,

    1) The admin should be able to add/edit/delete the publications

    This could be done through backend UI or create a custom control like this one - Insert/Update/Delete content items with RadGrid for ASP.NET AJAX

    2) The end user should be able to view/search the list of all publications. Use on of the built-in user controls or crate a custom one where you need to expose public properties for setting search criteria

    sample code

    public class ContentViewCustomControl : ContentView
    {
        public ContentViewCustomControl()
        {
     
        }
     
        public override string ItemListTemplatePath
        {
            get
            {
                return "~/Sitefinity/ControlTemplates/Generic_Content/ContentViewItemList.ascx";
            }
     
        }
     
        // here you need to populate a control which will be used to pass the value to one of the ContentFilterBuilder operands
        void BindData()
        {
            ListItem i = new ListItem();
            // populate the drop down.
     
        }
     
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            dropDownList.SelectedIndexChanged += new dropDownListSelectedIndexChangedEventHandler(dropDownList_SelectedIndexChanged);
        }
     
        void dropDownList_SelectedIndexChanged(object o, dropDownList_SelectedIndexChangedEventArgs e)
        {
            string rightOperant = e.Value;
            // set the right operand
            ContentFilterBuilder filterBuilder = new ContentFilterBuilder(this);
            filterBuilder.ClearFilter();
            ContentFilterStatement statement = new ContentFilterStatement()'
            this.RecreateChildControls();
        }
       
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            dropDownList.AutoPostBack = true;
            this.BindCategories();
            
        }
     
        protected override IList CreateDataSource()
        {
            contentManager = new ContentManager("News");
            IList contentList = contentManager.GetContent();
            return contentList;
        }
     
        private ContentManager contentManager;
     
        // TO DO - ViewState property to persist selected value of the DropDownList the data during postback
     
        protected virtual DropDownList dropDownList
        {
            get
            {
                return ListContainer.GetControl<DropDownList>("dropDownList1", true);
            }
        }
     
     
        protected virtual ITextControl textBox
        {
            get
            {
                return ListContainer.GetControl<ITextControl>("textBox1", true);
            }
        }
     
    }


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. GV
    GV avatar
    33 posts
    Registered:
    11 Sep 2009
    22 Feb 2010
    Link to this post
    Hi Ivan,
    Thanks for the code. I tried to create the custom control for admin. ( Insert/Update/Delete content items with RadGrid for ASP.NET AJAX ). What I did was created the custom control derived from simplecontrol as discussed in the example. However, when I place the control on the form, I'm getting the Object Reference error. Could please have a look into the code?

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Cms.Web.UI;
    using Telerik.Web.UI;
    using System.Collections;
    using Telerik.Cms.Engine;
    using Telerik.News;
    using System.Web.UI.WebControls;
    using Telerik.News.WebControls.Admin;
    using System.Web.UI;
     
    namespace SKEPNetworkControls
    {
        /// <summary>
        /// Summary description for GridContentEditor
        /// </summary>
        public class ItemEditor : SimpleControl
        {
            public ItemEditor()
            {
     
            }
            #region Properties
     
            public override string LayoutTemplatePath
            {
                get
                {
                    return "~/Resources/Backend/PublicationsEditor.ascx";
                }
            }
     
            public string ProviderName
            {
                get
                {
                    return Combo.SelectedItem.Text;
                }
            }
     
            #endregion
     
            #region Methods
     
            protected override void InitializeControls(System.Web.UI.Control controlContainer)
            {
                base.InitializeControls(controlContainer);
                this.Combo.DataSource = GCProviders();
                this.Combo.AutoPostBack = true;
                this.Combo.DataBind();
                Grid.PreRender += new EventHandler(Grid_PreRender);
                Grid.UpdateCommand += new GridCommandEventHandler(Grid_UpdateCommand);
                Grid.DeleteCommand += new GridCommandEventHandler(Grid_DeleteCommand);
                Grid.NeedDataSource += new GridNeedDataSourceEventHandler(Grid_NeedDataSource);
                Grid.InsertCommand += new GridCommandEventHandler(Grid_InsertCommand);
     
                Grid.AllowMultiRowEdit = true;
            }
     
            void Grid_PreRender(object sender, EventArgs e)
            {
                foreach (GridColumn column in Grid.Columns)
                {
                    if (column.UniqueName == "Name")
                    {
                        if (this.ProviderName == WikiProviderName || this.ProviderName == GenericContentProviderName)
                        {
                            (column as GridBoundColumn).DataField = "Name";
                            break;
                        }
     
                        (column as GridBoundColumn).DataField = "Title";
                    }
     
                }
                Grid.Rebind();
            }
     
            void Grid_InsertCommand(object source, GridCommandEventArgs e)
            {
                manager = new ContentManager(ProviderName);
                GridEditableItem editedItem = e.Item as GridEditableItem;
     
                Hashtable newValues = new Hashtable();
                e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
                IContent insertContent = manager.CreateContent("text/html");
                if (CheckProvider(ProviderName))
                {
                    insertContent.SetMetaData("Title", newValues["Title"]);
                    insertContent.Content = newValues["Content"];
                    manager.SaveContent(insertContent);
                }
                else
                {
                    this.MetaData = "Name";
                    insertContent.SetMetaData(MetaData, newValues[MetaData]);
                    insertContent.Content = newValues["Content"];
                    manager.SaveContent(insertContent);
                }
     
                Grid.Rebind();
            }
     
            void Grid_UpdateCommand(object source, GridCommandEventArgs e)
            {
                manager = new ContentManager(ProviderName);
                GridEditableItem editedItem = e.Item as GridEditableItem;
                Guid cntId = (Guid)editedItem.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"];
     
                Hashtable newValues = new Hashtable();
                e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
                IContent UpdatedContent = manager.GetContent(cntId);
                if (CheckProvider(ProviderName))
                {
                    UpdatedContent.SetMetaData("Title", newValues["Title"]);
                    UpdatedContent.Content = newValues["Content"];
                    manager.SaveContent(UpdatedContent);
                }
                else
                {
                    this.MetaData = "Name";
                    UpdatedContent.SetMetaData(MetaData, newValues[MetaData]);
                    UpdatedContent.Content = newValues["Content"];
                    manager.SaveContent(UpdatedContent);
                }
            }
     
     
            void Grid_DeleteCommand(object source, GridCommandEventArgs e)
            {
                manager = new ContentManager(ProviderName);
                Guid deleteITemID = (Guid)e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"];
                IContent newCnt = manager.GetContent(deleteITemID) as IContent;
                manager.DeleteContent(newCnt.ID);
            }
     
            void Grid_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
            {
                Grid.DataSource = GridDataSource();
            }
     
            public IList GridDataSource()
            {
                manager = new ContentManager(ProviderName);
                IList allItems = manager.GetContent();
                return allItems;
            }
     
            public IList GCProviders()
            {
     
                List<string> providers = new List<string>(ContentManager.Providers.Count);
                foreach (ContentProviderBase provider in ContentManager.Providers.Values)
                {
                    if (provider != null)
                    {
                        providers.Add(provider.Name);
                    }
     
                }
                return providers.ToArray();
     
            }
     
            private bool CheckProvider(string providerName)
            {
                if ((providerName != GenericContentProviderName) && (providerName != WikiProviderName))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
     
            #endregion
     
            #region Control references
     
            public virtual RadGrid Grid
            {
                get
                {
                    return base.Container.GetControl<RadGrid>("RadGrid1", true);
                }
            }
     
     
            public virtual RadComboBox Combo
            {
                get
                {
                    return base.Container.GetControl<RadComboBox>("RadComboBox1", true);
                }
            }
     
            #endregion
     
     
            #region Private constraints
     
     
            private ContentManager manager;
            private string GenericContentProviderName = "Generic_Content";
            private string WikiProviderName = "Wiki";
            private string MetaData;
     
            #endregion
     
     
        }
    }

    Thanks & regards
    GV
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    22 Feb 2010
    Link to this post
    Hi GV,

    One of your objects is null and you are trying to use it. You can attach the code to VS debugger and see which is the problematic object.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  7. GV
    GV avatar
    33 posts
    Registered:
    11 Sep 2009
    23 Feb 2010
    Link to this post
    Thanks for the reply, but that didn't help me much. The error shows that it couldn't find items in the providers dropdown. Here is my template.Can you Please suggest me where I'm doing it wrong?

    <%@ Control Language="C#" ClassName="PublicationsEditor" %>
     
    <script runat="server">
     
    </script>
    <script type="text/javascript">
      
        function RemoveItem(object, args) {
            var combo = $find("<%= RadComboBox1.ClientID %>");        
            if (combo.findItemByText("Libraries") != null) {
                combo.trackChanges();
                combo.get_items().remove(combo.findItemByText("Libraries"));
                combo.commitChanges();
            }
        }
    </script>
     
     
    <telerik:RadAjaxManagerProxy ID="RadAjaxManager1" runat="server">
                    <AjaxSettings>
                        <telerik:AjaxSetting AjaxControlID="RadGrid1">
                            <UpdatedControls>
                                <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                            </UpdatedControls>
                        </telerik:AjaxSetting>
                    </AjaxSettings>
    </telerik:RadAjaxManagerProxy>
    <telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel1" BackgroundPosition="Center">
          <asp:Image runat="server" ID="Image1" ImageUrl="~/Images/ajax-loader.gif" />
    </telerik:RadAjaxLoadingPanel>
      
    <telerik:RadComboBox ID="RadComboBox1" OnClientLoad="RemoveItem" runat="server" Skin="Black"  />
    <telerik:RadGrid id="RadGrid1" runat="server" Skin="Black"  >
       <MasterTableView  EditMode="InPlace" CommandItemDisplay="TopAndBottom" AutoGenerateColumns="False" DataKeyNames="ID" AllowAutomaticInserts="true">
        <EditFormSettings   CaptionFormatString="Edit Item: {0}" CaptionDataField="ID" PopUpSettings-Modal="true" />
        <Columns>
         <telerik:GridBoundColumn HeaderText="ContentName" UniqueName="Name"></telerik:GridBoundColumn>
         <telerik:GridBoundColumn HeaderText="Content" DataField="Content" UniqueName="Content"></telerik:GridBoundColumn>
         <telerik:GridEditCommandColumn HeaderText="Edit" UniqueName="EditCommandColumn"></telerik:GridEditCommandColumn>
         <telerik:GridButtonColumn CommandName="Delete" Text="Delete" HeaderText="Delete"
          UniqueName= "DeleteColumn" />
        </Columns>
       </MasterTableView>
    </telerik:RadGrid>
Register for webinar
7 posts, 0 answered