Beispiel #1
0
        private static void AfterMap(IMedia media, MediaItemDisplay display, IDataTypeService dataTypeService)
        {
            //map the tree node url
            if (HttpContext.Current != null)
            {
                var urlHelper = new UrlHelper(new RequestContext(new HttpContextWrapper(HttpContext.Current), new RouteData()));
                var url       = urlHelper.GetUmbracoApiService <MediaTreeController>(controller => controller.GetTreeNode(display.Id.ToString(), null));
                display.TreeNodeUrl = url;
            }

            if (media.ContentType.IsContainer)
            {
                TabsAndPropertiesResolver.AddListView(display, "media", dataTypeService);
            }

            TabsAndPropertiesResolver.MapGenericProperties(media, display);
        }
        private static void AfterMap(IMedia media, MediaItemDisplay display, IDataTypeService dataTypeService, ILocalizedTextService localizedText, IContentTypeService contentTypeService, ILogger logger)
        {
            // Adapted from ContentModelMapper
            //map the IsChildOfListView (this is actually if it is a descendant of a list view!)
            var parent = media.Parent();

            display.IsChildOfListView = parent != null && (parent.ContentType.IsContainer || contentTypeService.HasContainerInPath(parent.Path));

            //map the tree node url
            if (HttpContext.Current != null)
            {
                var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);
                var url       = urlHelper.GetUmbracoApiService <MediaTreeController>(controller => controller.GetTreeNode(display.Id.ToString(), null));
                display.TreeNodeUrl = url;
            }

            if (media.ContentType.IsContainer)
            {
                TabsAndPropertiesResolver.AddListView(display, "media", dataTypeService, localizedText);
            }

            var genericProperties = new List <ContentPropertyDisplay>
            {
                new ContentPropertyDisplay
                {
                    Alias = string.Format("{0}doctype", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
                    Label = localizedText.Localize("content/mediatype"),
                    Value = localizedText.UmbracoDictionaryTranslate(display.ContentTypeName),
                    View  = PropertyEditorResolver.Current.GetByAlias(Constants.PropertyEditors.NoEditAlias).ValueEditor.View
                }
            };

            TabsAndPropertiesResolver.MapGenericProperties(media, display, localizedText, genericProperties, properties =>
            {
                if (HttpContext.Current != null && UmbracoContext.Current != null && UmbracoContext.Current.Security.CurrentUser != null &&
                    UmbracoContext.Current.Security.CurrentUser.AllowedSections.Any(x => x.Equals(Constants.Applications.Settings)))
                {
                    var mediaTypeLink = string.Format("#/settings/mediatypes/edit/{0}", media.ContentTypeId);

                    //Replace the doctype property
                    var docTypeProperty   = properties.First(x => x.Alias == string.Format("{0}doctype", Constants.PropertyEditors.InternalGenericPropertiesPrefix));
                    docTypeProperty.Value = new List <object>
                    {
                        new
                        {
                            linkText = media.ContentType.Name,
                            url      = mediaTypeLink,
                            target   = "_self",
                            icon     = "icon-item-arrangement"
                        }
                    };
                    docTypeProperty.View = "urllist";
                }

                // inject 'Link to media' as the first generic property
                var links = media.GetUrls(UmbracoConfig.For.UmbracoSettings().Content, logger);
                if (links.Any())
                {
                    var link = new ContentPropertyDisplay
                    {
                        Alias = string.Format("{0}urls", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
                        Label = localizedText.Localize("media/urls"),
                        Value = string.Join(",", links),
                        View  = "urllist"
                    };
                    properties.Insert(0, link);
                }
            });
        }
Beispiel #3
0
        /// <summary>
        /// Maps the generic tab with custom properties for content
        /// </summary>
        /// <param name="content"></param>
        /// <param name="display"></param>
        /// <param name="dataTypeService"></param>
        /// <param name="localizedText"></param>
        /// <param name="contentTypeService"></param>
        private static void AfterMap(IContent content, ContentItemDisplay display, IDataTypeService dataTypeService,
                                     ILocalizedTextService localizedText, IContentTypeService contentTypeService)
        {
            //map the IsChildOfListView (this is actually if it is a descendant of a list view!)
            //TODO: Fix this shorthand .Ancestors() lookup, at least have an overload to use the current
            if (content.HasIdentity)
            {
                var ancesctorListView = content.Ancestors().FirstOrDefault(x => x.ContentType.IsContainer);
                display.IsChildOfListView = ancesctorListView != null;
            }
            else
            {
                //it's new so it doesn't have a path, so we need to look this up by it's parent + ancestors
                var parent = content.Parent();
                if (parent == null)
                {
                    display.IsChildOfListView = false;
                }
                else if (parent.ContentType.IsContainer)
                {
                    display.IsChildOfListView = true;
                }
                else
                {
                    var ancesctorListView = parent.Ancestors().FirstOrDefault(x => x.ContentType.IsContainer);
                    display.IsChildOfListView = ancesctorListView != null;
                }
            }


            //map the tree node url
            if (HttpContext.Current != null)
            {
                var urlHelper = new UrlHelper(new RequestContext(new HttpContextWrapper(HttpContext.Current), new RouteData()));
                var url       = urlHelper.GetUmbracoApiService <ContentTreeController>(controller => controller.GetTreeNode(display.Id.ToString(), null));
                display.TreeNodeUrl = url;
            }

            //fill in the template config to be passed to the template drop down.
            var templateItemConfig = new Dictionary <string, string> {
                { "", "Choose..." }
            };

            foreach (var t in content.ContentType.AllowedTemplates
                     .Where(t => t.Alias.IsNullOrWhiteSpace() == false && t.Name.IsNullOrWhiteSpace() == false))
            {
                templateItemConfig.Add(t.Alias, t.Name);
            }

            if (content.ContentType.IsContainer)
            {
                TabsAndPropertiesResolver.AddListView(display, "content", dataTypeService);
            }

            var properties = new List <ContentPropertyDisplay>
            {
                new ContentPropertyDisplay
                {
                    Alias = string.Format("{0}releasedate", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
                    Label = localizedText.Localize("content/releaseDate"),
                    Value = display.ReleaseDate.HasValue ? display.ReleaseDate.Value.ToIsoString() : null,
                    View  = "datepicker" //TODO: Hard coding this because the templatepicker doesn't necessarily need to be a resolvable (real) property editor
                },
                new ContentPropertyDisplay
                {
                    Alias = string.Format("{0}expiredate", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
                    Label = localizedText.Localize("content/unpublishDate"),
                    Value = display.ExpireDate.HasValue ? display.ExpireDate.Value.ToIsoString() : null,
                    View  = "datepicker" //TODO: Hard coding this because the templatepicker doesn't necessarily need to be a resolvable (real) property editor
                },
                new ContentPropertyDisplay
                {
                    Alias  = string.Format("{0}template", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
                    Label  = "Template", //TODO: localize this?
                    Value  = display.TemplateAlias,
                    View   = "dropdown", //TODO: Hard coding until we make a real dropdown property editor to lookup
                    Config = new Dictionary <string, object>
                    {
                        { "items", templateItemConfig }
                    }
                },
                new ContentPropertyDisplay
                {
                    Alias = string.Format("{0}urls", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
                    Label = localizedText.Localize("content/urls"),
                    Value = string.Join(",", display.Urls),
                    View  = "urllist" //TODO: Hard coding this because the templatepicker doesn't necessarily need to be a resolvable (real) property editor
                }
            };

            TabsAndPropertiesResolver.MapGenericProperties(content, display, properties.ToArray(),
                                                           genericProperties =>
            {
                //TODO: This would be much nicer with the IUmbracoContextAccessor so we don't use singletons
                //If this is a web request and there's a user signed in and the
                // user has access to the settings section, we will
                if (HttpContext.Current != null && UmbracoContext.Current != null && UmbracoContext.Current.Security.CurrentUser != null &&
                    UmbracoContext.Current.Security.CurrentUser.AllowedSections.Any(x => x.Equals(Constants.Applications.Settings)))
                {
                    var currentDocumentType     = contentTypeService.GetContentType(display.ContentTypeAlias);
                    var currentDocumentTypeName = currentDocumentType == null ? string.Empty : currentDocumentType.Name;

                    var currentDocumentTypeId = currentDocumentType == null ? string.Empty : currentDocumentType.Id.ToString(CultureInfo.InvariantCulture);
                    //TODO: Hard coding this is not good
                    var docTypeLink = string.Format("#/settings/framed/settings%252FeditNodeTypeNew.aspx%253Fid%253D{0}", currentDocumentTypeId);

                    //Replace the doc type property
                    var docTypeProp   = genericProperties.First(x => x.Alias == string.Format("{0}doctype", Constants.PropertyEditors.InternalGenericPropertiesPrefix));
                    docTypeProp.Value = new List <object>
                    {
                        new
                        {
                            linkText = currentDocumentTypeName,
                            url      = docTypeLink,
                            target   = "_self", icon = "icon-item-arrangement"
                        }
                    };
                    //TODO: Hard coding this because the templatepicker doesn't necessarily need to be a resolvable (real) property editor
                    docTypeProp.View = "urllist";
                }
            });
        }
Beispiel #4
0
        /// <summary>
        /// Maps the generic tab with custom properties for content
        /// </summary>
        /// <param name="memberService"></param>
        /// <param name="member"></param>
        /// <param name="display"></param>
        /// <remarks>
        /// If this is a new entity and there is an approved field then we'll set it to true by default.
        /// </remarks>
        private static void MapGenericCustomProperties(IMemberService memberService, IMember member, MemberDisplay display)
        {
            var membersProvider = Core.Security.MembershipProviderExtensions.GetMembersMembershipProvider();

            //map the tree node url
            if (HttpContext.Current != null)
            {
                var urlHelper = new UrlHelper(new RequestContext(new HttpContextWrapper(HttpContext.Current), new RouteData()));
                var url       = urlHelper.GetUmbracoApiService <MemberTreeController>(controller => controller.GetTreeNode(display.Key.ToString("N"), null));
                display.TreeNodeUrl = url;
            }

            var genericProperties = new List <ContentPropertyDisplay>
            {
                GetLoginProperty(memberService, member, display),
                new ContentPropertyDisplay
                {
                    Alias      = string.Format("{0}email", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
                    Label      = ui.Text("general", "email"),
                    Value      = display.Email,
                    View       = "email",
                    Validation = { Mandatory = true }
                },
                new ContentPropertyDisplay
                {
                    Alias = string.Format("{0}password", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
                    Label = ui.Text("password"),
                    //NOTE: The value here is a json value - but the only property we care about is the generatedPassword one if it exists, the newPassword exists
                    // only when creating a new member and we want to have a generated password pre-filled.
                    Value = new Dictionary <string, object>
                    {
                        { "generatedPassword", member.GetAdditionalDataValueIgnoreCase("GeneratedPassword", null) },
                        { "newPassword", member.GetAdditionalDataValueIgnoreCase("NewPassword", null) },
                    },
                    //TODO: Hard coding this because the changepassword doesn't necessarily need to be a resolvable (real) property editor
                    View = "changepassword",
                    //initialize the dictionary with the configuration from the default membership provider
                    Config = new Dictionary <string, object>(membersProvider.GetConfiguration())
                    {
                        //the password change toggle will only be displayed if there is already a password assigned.
                        { "hasPassword", member.RawPasswordValue.IsNullOrWhiteSpace() == false }
                    }
                },
                new ContentPropertyDisplay
                {
                    Alias  = string.Format("{0}membergroup", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
                    Label  = ui.Text("content", "membergroup"),
                    Value  = GetMemberGroupValue(display.Username),
                    View   = "membergroups",
                    Config = new Dictionary <string, object> {
                        { "IsRequired", true }
                    }
                }
            };

            TabsAndPropertiesResolver.MapGenericProperties(member, display, genericProperties);

            //check if there's an approval field
            var provider = membersProvider as global::umbraco.providers.members.UmbracoMembershipProvider;

            if (member.HasIdentity == false && provider != null)
            {
                var approvedField = provider.ApprovedPropertyTypeAlias;
                var prop          = display.Properties.FirstOrDefault(x => x.Alias == approvedField);
                if (prop != null)
                {
                    prop.Value = 1;
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Maps the generic tab with custom properties for content
        /// </summary>
        /// <param name="memberService"></param>
        /// <param name="userService"></param>
        /// <param name="member"></param>
        /// <param name="display"></param>
        /// <param name="localizedText"></param>
        /// <remarks>
        /// If this is a new entity and there is an approved field then we'll set it to true by default.
        /// </remarks>
        private static void MapGenericCustomProperties(IMemberService memberService, IUserService userService, IMember member, MemberDisplay display, ILocalizedTextService localizedText)
        {
            var membersProvider = Core.Security.MembershipProviderExtensions.GetMembersMembershipProvider();

            //map the tree node url
            if (HttpContext.Current != null)
            {
                var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);
                var url       = urlHelper.GetUmbracoApiService <MemberTreeController>(controller => controller.GetTreeNode(display.Key.ToString("N"), null));
                display.TreeNodeUrl = url;
            }

            var genericProperties = new List <ContentPropertyDisplay>
            {
                new ContentPropertyDisplay
                {
                    Alias = string.Format("{0}doctype", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
                    Label = localizedText.Localize("content/membertype"),
                    Value = localizedText.UmbracoDictionaryTranslate(display.ContentTypeName),
                    View  = PropertyEditorResolver.Current.GetByAlias(Constants.PropertyEditors.NoEditAlias).ValueEditor.View
                },
                GetLoginProperty(memberService, member, display, localizedText),
                new ContentPropertyDisplay
                {
                    Alias      = string.Format("{0}email", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
                    Label      = localizedText.Localize("general/email"),
                    Value      = display.Email,
                    View       = "email",
                    Validation = { Mandatory = true }
                },
                new ContentPropertyDisplay
                {
                    Alias = string.Format("{0}password", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
                    Label = localizedText.Localize("password"),
                    //NOTE: The value here is a json value - but the only property we care about is the generatedPassword one if it exists, the newPassword exists
                    // only when creating a new member and we want to have a generated password pre-filled.
                    Value = new Dictionary <string, object>
                    {
                        { "generatedPassword", member.GetAdditionalDataValueIgnoreCase("GeneratedPassword", null) },
                        { "newPassword", member.GetAdditionalDataValueIgnoreCase("NewPassword", null) },
                    },
                    //TODO: Hard coding this because the changepassword doesn't necessarily need to be a resolvable (real) property editor
                    View = "changepassword",
                    //initialize the dictionary with the configuration from the default membership provider
                    Config = new Dictionary <string, object>(membersProvider.GetConfiguration(userService))
                    {
                        //the password change toggle will only be displayed if there is already a password assigned.
                        { "hasPassword", member.RawPasswordValue.IsNullOrWhiteSpace() == false }
                    }
                },
                new ContentPropertyDisplay
                {
                    Alias  = string.Format("{0}membergroup", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
                    Label  = localizedText.Localize("content/membergroup"),
                    Value  = GetMemberGroupValue(display.Username),
                    View   = "membergroups",
                    Config = new Dictionary <string, object> {
                        { "IsRequired", true }
                    }
                }
            };

            TabsAndPropertiesResolver.MapGenericProperties(member, display, localizedText, genericProperties, properties =>
            {
                if (HttpContext.Current != null && UmbracoContext.Current != null && UmbracoContext.Current.Security.CurrentUser != null &&
                    UmbracoContext.Current.Security.CurrentUser.AllowedSections.Any(x => x.Equals(Constants.Applications.Settings)))
                {
                    var memberTypeLink = string.Format("#/member/memberTypes/edit/{0}", member.ContentTypeId);

                    //Replace the doctype property
                    var docTypeProperty   = properties.First(x => x.Alias == string.Format("{0}doctype", Constants.PropertyEditors.InternalGenericPropertiesPrefix));
                    docTypeProperty.Value = new List <object>
                    {
                        new
                        {
                            linkText = member.ContentType.Name,
                            url      = memberTypeLink,
                            target   = "_self",
                            icon     = "icon-item-arrangement"
                        }
                    };
                    docTypeProperty.View = "urllist";
                }
            });

            //check if there's an approval field
            var provider = membersProvider as global::umbraco.providers.members.UmbracoMembershipProvider;

            if (member.HasIdentity == false && provider != null)
            {
                var approvedField = provider.ApprovedPropertyTypeAlias;
                var prop          = display.Properties.FirstOrDefault(x => x.Alias == approvedField);
                if (prop != null)
                {
                    prop.Value = 1;
                }
            }
        }
        /// <summary>
        /// Maps the generic tab with custom properties for content
        /// </summary>
        /// <param name="content"></param>
        /// <param name="display"></param>
        /// <param name="dataTypeService"></param>
        /// <param name="localizedText"></param>
        /// <param name="contentTypeService"></param>
        private static void AfterMap(IContent content, ContentItemDisplay display, IDataTypeService dataTypeService,
                                     ILocalizedTextService localizedText, IContentTypeService contentTypeService)
        {
            // map the IsChildOfListView (this is actually if it is a descendant of a list view!)
            var parent = content.Parent();

            display.IsChildOfListView = parent != null && (parent.ContentType.IsContainer || contentTypeService.HasContainerInPath(parent.Path));

            //map the tree node url
            if (HttpContext.Current != null)
            {
                var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);
                var url       = urlHelper.GetUmbracoApiService <ContentTreeController>(controller => controller.GetTreeNode(display.Id.ToString(), null));
                display.TreeNodeUrl = url;
            }

            //fill in the template config to be passed to the template drop down.
            var templateItemConfig = new Dictionary <string, string> {
                { "", localizedText.Localize("general/choose") }
            };

            foreach (var t in content.ContentType.AllowedTemplates
                     .Where(t => t.Alias.IsNullOrWhiteSpace() == false && t.Name.IsNullOrWhiteSpace() == false))
            {
                templateItemConfig.Add(t.Alias, t.Name);
            }

            if (content.ContentType.IsContainer)
            {
                TabsAndPropertiesResolver.AddListView(display, "content", dataTypeService, localizedText);
            }

            var properties = new List <ContentPropertyDisplay>
            {
                new ContentPropertyDisplay
                {
                    Alias = string.Format("{0}doctype", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
                    Label = localizedText.Localize("content/documentType"),
                    Value = localizedText.UmbracoDictionaryTranslate(display.ContentTypeName),
                    View  = PropertyEditorResolver.Current.GetByAlias(Constants.PropertyEditors.NoEditAlias).ValueEditor.View
                },
                new ContentPropertyDisplay
                {
                    Alias = string.Format("{0}releasedate", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
                    Label = localizedText.Localize("content/releaseDate"),
                    Value = display.ReleaseDate.HasValue ? display.ReleaseDate.Value.ToIsoString() : null,
                    //Not editible for people without publish permission (U4-287)
                    View   = display.AllowedActions.Contains(ActionPublish.Instance.Letter) ? "datepicker" : PropertyEditorResolver.Current.GetByAlias(Constants.PropertyEditors.NoEditAlias).ValueEditor.View,
                    Config = new Dictionary <string, object>
                    {
                        { "offsetTime", "1" }
                    }
                    //TODO: Fix up hard coded datepicker
                },
                new ContentPropertyDisplay
                {
                    Alias = string.Format("{0}expiredate", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
                    Label = localizedText.Localize("content/unpublishDate"),
                    Value = display.ExpireDate.HasValue ? display.ExpireDate.Value.ToIsoString() : null,
                    //Not editible for people without publish permission (U4-287)
                    View   = display.AllowedActions.Contains(ActionPublish.Instance.Letter) ? "datepicker" : PropertyEditorResolver.Current.GetByAlias(Constants.PropertyEditors.NoEditAlias).ValueEditor.View,
                    Config = new Dictionary <string, object>
                    {
                        { "offsetTime", "1" }
                    }
                    //TODO: Fix up hard coded datepicker
                },
                new ContentPropertyDisplay
                {
                    Alias  = string.Format("{0}template", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
                    Label  = localizedText.Localize("template/template"),
                    Value  = display.TemplateAlias,
                    View   = "dropdown", //TODO: Hard coding until we make a real dropdown property editor to lookup
                    Config = new Dictionary <string, object>
                    {
                        { "items", templateItemConfig }
                    }
                }
            };


            TabsAndPropertiesResolver.MapGenericProperties(content, display, localizedText, properties.ToArray(),
                                                           genericProperties =>
            {
                //TODO: This would be much nicer with the IUmbracoContextAccessor so we don't use singletons
                //If this is a web request and there's a user signed in and the
                // user has access to the settings section, we will
                if (HttpContext.Current != null && UmbracoContext.Current != null && UmbracoContext.Current.Security.CurrentUser != null &&
                    UmbracoContext.Current.Security.CurrentUser.AllowedSections.Any(x => x.Equals(Constants.Applications.Settings)))
                {
                    var currentDocumentType     = contentTypeService.GetContentType(display.ContentTypeAlias);
                    var currentDocumentTypeName = currentDocumentType == null ? string.Empty : localizedText.UmbracoDictionaryTranslate(currentDocumentType.Name);

                    var currentDocumentTypeId = currentDocumentType == null ? string.Empty : currentDocumentType.Id.ToString(CultureInfo.InvariantCulture);
                    //TODO: Hard coding this is not good
                    var docTypeLink = string.Format("#/settings/documenttypes/edit/{0}", currentDocumentTypeId);

                    //Replace the doc type property
                    var docTypeProperty   = genericProperties.First(x => x.Alias == string.Format("{0}doctype", Constants.PropertyEditors.InternalGenericPropertiesPrefix));
                    docTypeProperty.Value = new List <object>
                    {
                        new
                        {
                            linkText = currentDocumentTypeName,
                            url      = docTypeLink,
                            target   = "_self",
                            icon     = "icon-item-arrangement"
                        }
                    };
                    //TODO: Hard coding this because the templatepicker doesn't necessarily need to be a resolvable (real) property editor
                    docTypeProperty.View = "urllist";
                }

                // inject 'Link to document' as the first generic property
                genericProperties.Insert(0, new ContentPropertyDisplay
                {
                    Alias = string.Format("{0}urls", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
                    Label = localizedText.Localize("content/urls"),
                    Value = string.Join(",", display.Urls),
                    View  = "urllist"    //TODO: Hard coding this because the templatepicker doesn't necessarily need to be a resolvable (real) property editor
                });
            });
        }