示例#1
0
        /// <summary>
        /// Returns Page object from cache.  If page does not already exist in cache, it
        /// will be read and added to cache
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static PageCache Read(int id)
        {
            string cacheKey = PageCache.CacheKey(id);

            ObjectCache cache = MemoryCache.Default;
            PageCache   page  = cache[cacheKey] as PageCache;

            if (page != null)
            {
                return(page);
            }
            else
            {
                Rock.Model.PageService pageService = new Model.PageService();
                Rock.Model.Page        pageModel   = pageService.Get(id);
                if (pageModel != null)
                {
                    pageModel.LoadAttributes();

                    page = PageCache.CopyModel(pageModel);

                    cache.Set(cacheKey, page, new CacheItemPolicy());

                    return(page);
                }
                else
                {
                    return(null);
                }
            }
        }
示例#2
0
 /// <summary>
 /// Saves the attribute values for the page
 /// </summary>
 /// <param name="personId">The person id.</param>
 public void SaveAttributeValues(int?personId)
 {
     Rock.Model.PageService pageService = new Model.PageService();
     Rock.Model.Page        pageModel   = pageService.Get(this.Id);
     if (pageModel != null)
     {
         pageModel.LoadAttributes();
         foreach (var attribute in pageModel.Attributes)
         {
             Rock.Attribute.Helper.SaveAttributeValues(pageModel, attribute.Value, this.AttributeValues[attribute.Key], personId);
         }
     }
 }
示例#3
0
        /// <summary>
        /// Shows the edit details.
        /// </summary>
        /// <param name="page">The page.</param>
        private void ShowEditDetails(Rock.Model.Page page)
        {
            if (page.Id > 0)
            {
                lTitle.Text = ActionTitle.Edit(Rock.Model.Page.FriendlyTypeName).FormatAsHtmlTitle();
                lIcon.Text  = "<i class='fa fa-square-o'></i>";
            }
            else
            {
                lTitle.Text = ActionTitle.Add(Rock.Model.Page.FriendlyTypeName).FormatAsHtmlTitle();

                if (!string.IsNullOrEmpty(page.IconCssClass))
                {
                    lIcon.Text = string.Format("<i class='{0}'></i>", page.IconCssClass);
                }
                else
                {
                    lIcon.Text = "<i class='fa fa-file-text-o'></i>";
                }
            }

            SetEditMode(true);

            var         rockContext = new RockContext();
            PageService pageService = new PageService(rockContext);

            if (page.Layout != null)
            {
                ddlSite.SetValue(page.Layout.SiteId);
            }
            else if (page.ParentPageId.HasValue)
            {
                var parentPageCache = PageCache.Read(page.ParentPageId.Value);
                if (parentPageCache != null && parentPageCache.Layout != null)
                {
                    ddlSite.SetValue(parentPageCache.Layout.SiteId);
                }
            }

            LoadLayouts(rockContext, SiteCache.Read(ddlSite.SelectedValue.AsInteger()));
            if (page.LayoutId == 0)
            {
                // default a new page's layout to whatever the parent page's layout is
                if (page.ParentPage != null)
                {
                    page.LayoutId = page.ParentPage.LayoutId;
                }
            }

            ddlLayout.SetValue(page.LayoutId);

            phPageAttributes.Controls.Clear();
            page.LoadAttributes();

            if (page.Attributes != null && page.Attributes.Any())
            {
                wpPageAttributes.Visible = true;
                Rock.Attribute.Helper.AddEditControls(page, phPageAttributes, true, BlockValidationGroup);
            }
            else
            {
                wpPageAttributes.Visible = false;
            }

            rptProperties.DataSource = _tabs;
            rptProperties.DataBind();

            tbPageName.Text     = page.InternalName;
            tbPageTitle.Text    = page.PageTitle;
            tbBrowserTitle.Text = page.BrowserTitle;
            tbBodyCssClass.Text = page.BodyCssClass;
            ppParentPage.SetValue(pageService.Get(page.ParentPageId ?? 0));
            tbIconCssClass.Text = page.IconCssClass;

            cbPageTitle.Checked       = page.PageDisplayTitle;
            cbPageBreadCrumb.Checked  = page.PageDisplayBreadCrumb;
            cbPageIcon.Checked        = page.PageDisplayIcon;
            cbPageDescription.Checked = page.PageDisplayDescription;

            ddlMenuWhen.SelectedValue = (( int )page.DisplayInNavWhen).ToString();
            cbMenuDescription.Checked = page.MenuDisplayDescription;
            cbMenuIcon.Checked        = page.MenuDisplayIcon;
            cbMenuChildPages.Checked  = page.MenuDisplayChildPages;

            cbBreadCrumbIcon.Checked = page.BreadCrumbDisplayIcon;
            cbBreadCrumbName.Checked = page.BreadCrumbDisplayName;

            cbRequiresEncryption.Checked = page.RequiresEncryption;
            cbEnableViewState.Checked    = page.EnableViewState;
            cbIncludeAdminFooter.Checked = page.IncludeAdminFooter;
            cbAllowIndexing.Checked      = page.AllowIndexing;
            tbCacheDuration.Text         = page.OutputCacheDuration.ToString();
            tbDescription.Text           = page.Description;
            ceHeaderContent.Text         = page.HeaderContent;
            tbPageRoute.Text             = string.Join(",", page.PageRoutes.Select(route => route.Route).ToArray());

            // Add enctype attribute to page's <form> tag to allow file upload control to function
            Page.Form.Attributes.Add("enctype", "multipart/form-data");
        }