Ejemplo n.º 1
0
 public static int Register(Models.PageTemplate template)
 {
     return(Register(new List <Models.PageTemplate>()
     {
         template
     }));
 }
Ejemplo n.º 2
0
        public static string Import(string portalId, Models.PageTemplate pageTemplate, Dictionary <string, string> widgetContent, Dictionary <string, string> idMap, string userId = null)
        {
            userId = string.IsNullOrEmpty(userId) ? Account.AuditId : userId;
            var existing = Portal.GetPageTemplate(pageTemplate.Urls.Count > 0 ? pageTemplate.Urls[0] : "", portalId);   //todo:  by first url ok???

            pageTemplate.PortalId = portalId;
            pageTemplate.Roles    = Security.GetNewRoleIds(pageTemplate.Roles, idMap);
            pageTemplate.Id       = existing != null ? existing.Id : null;

            foreach (var widget in pageTemplate.Widgets)
            {
                widget.ManifestId = GetIdMap <Models.WidgetManifest>(widget.ManifestId, idMap);
                widget.Roles      = Security.GetNewRoleIds(widget.Roles, idMap);

                //todo: not creating/mapping new widget ids?
                if (widgetContent.ContainsKey(widget.Id))
                {
                    var contentProvider = widget.Manifest.GetContentProvider();
                    if (contentProvider != null)
                    {
                        widget.ContentIds = contentProvider.Import(portalId, widget.Id, widgetContent[widget.Id], idMap).Values.ToList(); //returns mapped dictionary of old id to new id... we just need to use the new ids
                    }
                }
            }
            Logging.Logger.DebugFormat("Importing page template {0}", pageTemplate.ToJson());
            return(Portal.Save(pageTemplate));
        }
Ejemplo n.º 3
0
        public static bool IsDuplicate(Models.PageTemplate pageTemplate)
        {
            var templates = GetPageTemplates();

            foreach (var url in pageTemplate.Urls)
            {
                //var t = GetTemplate(url, template.PortalId);
                var t = templates.Where(t2 => t2.Urls.Contains(url) && t2.PortalId == pageTemplate.PortalId).SingleOrDefault();
                if (t != null && t.Id != pageTemplate.Id)
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 4
0
        // Methods
        public static void RenderWidgets(this HtmlHelper helper, Models.PageTemplate Template, string PaneName)
        {
            if (Template != null)
            {
                foreach (var widget in Template.Widgets.Where(w => w.PaneName == PaneName && w.IsAuthorized))
                {
                    RenderWidget(helper, widget);
                }

                foreach (var widget in Template.LayoutWidgets.Where(w => w.PaneName == PaneName && w.IsAuthorized))
                {
                    RenderWidget(helper, widget);
                }
            }
            //return "";
        }
Ejemplo n.º 5
0
        public static void RegisterTheme(this HtmlHelper helper, Models.PageTemplate template)
        {
            var theme = Services.UI.PortalTheme;

            if (template != null && template.Layout != null && template.Layout.Theme != null)
            {
                theme = template.Layout.Theme;
            }
            if (template != null && template != null && template.Theme != null)
            {
                theme = template.Theme;
            }

            if (theme != null)
            {
                foreach (var file in theme.Files)
                {
                    if (file.Type == Models.ReferenceFileType.Css)
                    {
                        HtmlExtensions.RegisterStylesheet(helper, file.Path, true, new Dictionary <string, string>()
                        {
                            { "type", "theme" }
                        });
                    }
                    if (file.Type == Models.ReferenceFileType.Script)
                    {
                        HtmlExtensions.RegisterScript(helper, file.Path, true, new Dictionary <string, string>()
                        {
                            { "type", "theme" }
                        });
                    }
                }
            }
            else
            {
                HtmlExtensions.RegisterStylesheet(helper, "~/scripts/bootstrap-2.1.0/css/bootstrap.css", true, new Dictionary <string, string>()
                {
                    { "type", "theme" }
                });
            }
        }
Ejemplo n.º 6
0
        public static string Save(Models.PageTemplate pageTemplate, string userId = null)
        {
            userId = string.IsNullOrEmpty(userId) ? Account.AuditId : userId;
            pageTemplate.PortalId = string.IsNullOrEmpty(pageTemplate.PortalId) ? CurrentPortalId : pageTemplate.PortalId;
            //strip empty urls
            pageTemplate.Urls = pageTemplate.Urls.Where(u => !string.IsNullOrEmpty(u)).ToList();

            if (!IsDuplicate(pageTemplate))
            {
                var prevTemplate = GetPageTemplateById(pageTemplate.Id);

                if (prevTemplate != null)
                {
                    var missing = (from p in prevTemplate.Widgets
                                   where !(from w in pageTemplate.Widgets select w.Id).Contains(p.Id)
                                   select p);
                    foreach (var widget in missing)
                    {
                        widget.RemoveContent();
                    }
                }
                Repository.Current.StoreResource("Template", null, pageTemplate, userId);

                foreach (var widget in pageTemplate.Widgets)
                {
                    //widget.TemplateId = Template.Id;    //is this a hack?
                    if (widget.ContentJson != null)
                    {
                        widget.SaveContentJson(widget.ContentJson);
                    }
                }

                //after contentIds assigned, need to save them!
                var res = Repository.Current.StoreResource("Template", null, pageTemplate, userId);
                return(res.Id);
            }
            else
            {
                throw new Exception(string.Format(Localization.GetLocalization(LocalizationType.Exception, "DuplicateResource.Error", "{0} already exists.   Duplicates Not Allowed.", "Core"), "Template"));
            }
        }