protected void MasterDetail_Item_List_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                WebModuleInfo    MasterDetailModule = (WebModuleInfo)e.Row.DataItem;
                WebpageInfo      page = MasterDetailModule.Webpage;
                MasterDetailItem item = MasterDetailItem.GetSafeResource(MasterDetailModule.Id);
                System.Web.UI.HtmlControls.HtmlAnchor selectLink = (System.Web.UI.HtmlControls.HtmlAnchor)e.Row.FindControl("SelectLink");
                selectLink.HRef = ResolveUrl(MasterDetailModule.GetEditUrl())
                                  //cheesy
                                  + "&returnTo=" + Server.UrlEncode(Request.Url.PathAndQuery);

                selectLink.InnerHtml = MasterDetailItem.Chop(page.Title, 45, true);

                Literal postDateCtl = (Literal)e.Row.FindControl("PostDateCtl");
                if (page.PostDate.HasValue)
                {
                    postDateCtl.Text = page.PostDate.Value.ToShortDateString();
                    if (page.PostDate.Value.TimeOfDay.TotalSeconds > .001)
                    {
                        postDateCtl.Text = string.Format("{0} {1}", postDateCtl.Text, page.PostDate.Value.ToShortTimeString());
                    }
                }

                CheckBox visibleCtl = (CheckBox)e.Row.FindControl("VisibleCtl");
                visibleCtl.Checked = page.Visible;

                CheckBox featuredCtl = (CheckBox)e.Row.FindControl("FeaturedCtl");
                featuredCtl.Checked = item.IsFeatured;
            }
        }
示例#2
0
        public static List <WebModuleInfo> GetMasterDetailChildrenFiltered(int moduleId,
                                                                           bool filteryByPostDateAndRemoveDate,
                                                                           bool orderByMostRecentPosting,
                                                                           string filterTag)
        {
            //get the module object.
            WebModuleInfo module = WebModule.GetModule(moduleId);
            //get the container page of the module.
            WebpageInfo page = module.Webpage;
            //get all the MasterDetail modules on the child pages.
            List <WebpageInfo>   childPages          = page.Children;
            List <WebModuleInfo> MasterDetailModules = new List <WebModuleInfo>();

            foreach (WebpageInfo p in childPages)
            {
                MasterDetailModules.AddRange(p.Modules.FindAll(
                                                 delegate(WebModuleInfo m)
                {
                    return(m.WebModuleType == MasterDetailItem.ModuleType && !m.IsAlias);
                }));
            }

            if (filteryByPostDateAndRemoveDate)
            { //remove premature/expired/non-visible items.
                MasterDetailModules.RemoveAll(
                    delegate(WebModuleInfo m)
                {
                    WebpageInfo p = m.Webpage;
                    return((p.PostDate.HasValue && DateTime.Now < p.PostDate) ||
                           (p.RemoveDate.HasValue && DateTime.Today >= p.RemoveDate) ||
                           (!p.Visible));
                });
            }

            if (!string.IsNullOrEmpty(filterTag))
            {
                //remove non-matching tags.
                MasterDetailModules.RemoveAll(
                    delegate(WebModuleInfo m)
                {
                    MasterDetailItem item = MasterDetailItem.GetSafeResource(m.Id);
                    string[] tagArray     = item.Tags.Split(',');
                    foreach (var s in tagArray)
                    {
                        if (s == filterTag)
                        {
                            return(false);
                        }
                    }
                    return(true);
                });
            }

            if (orderByMostRecentPosting)
            {
                MasterDetailModules.Sort(CompareWebModulesByPostDate);
            }

            return(MasterDetailModules);
        }
        protected void SummaryListRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                WebModuleInfo    module = (WebModuleInfo)e.Item.DataItem;
                WebpageInfo      page   = module.Webpage;
                MasterDetailItem item   = MasterDetailItem.GetSafeResource(module.Id);

                if (item != null)
                {
                    if (item.IsFeatured)
                    {
                        HtmlControl divSummary = (HtmlControl)e.Item.FindControl("divSummary");
                        if (divSummary != null)
                        {
                            divSummary.Attributes["class"] += " MasterDetail_ListItemFeatured";
                        }

                        HtmlControl trFeaturedHeader = (HtmlControl)e.Item.FindControl("trFeaturedHeader");
                        if (trFeaturedHeader != null)
                        {
                            trFeaturedHeader.Visible = item.IsFeatured;
                        }
                    }

                    Image         imgMain    = (Image)e.Item.FindControl("imgMain");
                    HtmlTableCell tdImageCol = (HtmlTableCell)e.Item.FindControl("tdImageCol");
                    imgMain.Visible = !string.IsNullOrEmpty(item.ImagePath);
                    if (imgMain.Visible)
                    {
                        imgMain.ImageUrl = ResolveUrl(string.Format("~/Image.ashx?File={0}&Size=100", item.ImagePath));
                    }
                    else
                    {
                        if (!_itemList.ShowImageIfBlank)
                        {
                            tdImageCol.Visible = false;
                        }
                    }

                    if (_itemList.IsPostDateVisible)
                    {
                        Label postDateCtl = (Label)e.Item.FindControl("lblPostDate");
                        if (page.PostDate.HasValue)
                        {
                            postDateCtl.Text = page.PostDate.Value.ToLongDateString();
                        }
                    }

                    HyperLink hypTitle = (HyperLink)e.Item.FindControl("hypTitle");
                    hypTitle.NavigateUrl = ResolveUrl(page.Path);
                    hypTitle.Text        = MasterDetailItem.Chop(page.Text, 150, true);

                    HyperLink hypReadMore = (HyperLink)e.Item.FindControl("hypReadMore");
                    hypReadMore.NavigateUrl = ResolveUrl(page.Path);

                    Literal litSummary = (Literal)e.Item.FindControl("litSummary");
                    litSummary.Text = item.GetSummary(page);

                    if (item.Tags != null)
                    {
                        // Build unique list of tags for all articles in the summary display
                        string[] tagArray = item.Tags.Split(',');
                        foreach (var s in tagArray)
                        {
                            if (!TagList.Contains(s))
                            {
                                TagList.Add(s);
                            }
                        }
                    }
                }
                else
                {
                    e.Item.Visible = false;
                }
            }
        }
        protected void MiniSummaryRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Label lblCategory = e.Item.FindControl("lblCategory") as Label;
                if (lblCategory != null)
                {
                    int         pageId         = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "PageId"));
                    WebpageInfo parentPageInfo = Webpage.GetWebpageByPageId(pageId);
                    if (parentPageInfo != null)
                    {
                        lblCategory.Text = parentPageInfo.Parent.Text + ":&nbsp;&nbsp;";
                    }

                    HyperLink hypTitle = e.Item.FindControl("hypTitle") as HyperLink;
                    if (hypTitle != null)
                    {
                        hypTitle.NavigateUrl = DataBinder.Eval(e.Item.DataItem, "Path").ToString();

                        string scriptStr = "autoEllipseText('" + hypTitle.ClientID + "', \""
                                           + (DataBinder.Eval(e.Item.DataItem, "NavigationText")).ToString().Replace("\"", "&quot;") + "\", '"
                                           + lblCategory.ClientID + "');";
                        Page.ClientScript.RegisterStartupScript(GetType(), "truncate" + e.Item.ItemIndex, scriptStr, true);
                    }
                }

                // TODO: Cache this info
                int moduleId = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "ModuleId"));
                MasterDetailItem               item               = MasterDetailItem.GetSafeResource(moduleId);
                MasterDetailSetting            setting            = item.GetContentList();
                MasterDetailMiniSummarySetting miniSummarySetting = MasterDetailMiniSummarySetting.FetchByID(this.ModuleId);

                Label lblCommentCount = e.Item.FindControl("lblCommentCount") as Label;
                if (lblCommentCount != null)
                {
                    if ((setting != null) && (setting.AllowComments))
                    {
                        int numComments =
                            MasterDetailComment.Query().WHERE(MasterDetailComment.Columns.ModuleId, moduleId).GetCount(
                                MasterDetailComment.Columns.ModuleId);
                        if (numComments > 999)
                        {
                            numComments = 999;                    // max display size is 3 digits.
                        }
                        lblCommentCount.Text    = numComments.ToString();
                        lblCommentCount.ToolTip = numComments + " Reader Comments";
                    }
                    else
                    {
                        lblCommentCount.Visible = false;
                    }
                }

                Label lblTimestamp = e.Item.FindControl("lblTimestamp") as Label;
                if (lblTimestamp != null)
                {
                    if ((miniSummarySetting != null) && ((bool)miniSummarySetting.ShowElapsedTime))
                    {
                        DateTime postDate = Convert.ToDateTime(DataBinder.Eval(e.Item.DataItem, "PostDate"));
                        TimeSpan ts       = DateTime.Now.Subtract(postDate);
                        if (ts.Days > 0)
                        {
                            lblTimestamp.Text = ts.Days + "d ago";
                        }
                        else if (ts.Hours > 0)
                        {
                            lblTimestamp.Text = ts.Hours + "h ago";
                        }
                        else if (ts.Minutes > 0)
                        {
                            lblTimestamp.Text = ts.Minutes + "m ago";
                        }
                        else
                        {
                            lblTimestamp.Text = "< 1m ago";
                        }
                    }
                    else
                    {
                        lblTimestamp.Visible = false;
                    }
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            HtmlLink cssLink = new HtmlLink();

            cssLink.Href = "~/WebModules/MasterDetail/public/css/MasterDetail.css";
            cssLink.Attributes["rel"]  = "stylesheet";
            cssLink.Attributes["type"] = "text/css";
            this.Page.Header.Controls.AddAt(1, cssLink);

            // AntiSpam session var
            Session.Add("AntiSpamVar", "0");

            if (!IsPostBack)
            {
                WebpageInfo         page     = this.WebModuleInfo.Webpage;
                MasterDetailItem    item     = MasterDetailItem.GetSafeResource(this.ModuleId);
                MasterDetailSetting itemList = item.GetContentList();

                CurrentModuleId = item.ModuleId;

                if (itemList != null)
                {
                    lblPostDate.Visible   = itemList.IsPostDateVisible;
                    CommentsPanel.Visible = itemList.AllowComments;

                    if (itemList.AllowComments)
                    {
                        Query q = MasterDetailComment.Query().WHERE(MasterDetailComment.Columns.ModuleId, CurrentModuleId);
                        litCommentsLink.Text = "&nbsp;&nbsp;|&nbsp;&nbsp;<a href='#Comments'>" + q.GetCount(MasterDetailComment.Columns.Id) + " Comment(s)</a>";
                    }
                    if (Page.User.Identity.IsAuthenticated || !itemList.RequireAuthentication)
                    {
                        submitCommentsDiv.Visible = true;
                        lblLoginMsg.Visible       = false;
                    }
                    else
                    {
                        submitCommentsDiv.Visible = false;
                        lblLoginMsg.Visible       = true;
                    }
                }

                if (lblPostDate.Visible)
                {
                    if (page.PostDate.HasValue)
                    {
                        lblPostDate.Text = page.PostDate.Value.ToLongDateString();
                    }
                }

                if (string.IsNullOrEmpty(item.ImagePath))
                {
                    img.Visible = false;
                }
                else
                {
                    img.ImageUrl = ResolveUrl(item.ImagePath);
                }

                litTitle.Text       = page.Text;
                litBody.Text        = item.LongDescription;
                hypBack.NavigateUrl = this.WebModuleInfo.Webpage.Parent.Path;

                CommentsListRepeater.DataSource = new MasterDetailCommentCollection()
                                                  .Where(MasterDetailComment.Columns.ModuleId, CurrentModuleId)
                                                  .OrderByDesc(MasterDetailComment.Columns.CreatedOn)
                                                  .Load();
                CommentsListRepeater.DataBind();
            }
        }