예제 #1
0
        protected override DriverResult Editor(ContentPart part, Fields.SmartContentPickerField field, dynamic shapeHelper)
        {
            return(ContentShape("Fields_SmartContentPicker_Edit", GetDifferentiator(field, part),
                                () => {
                var settings = field.PartFieldDefinition.Settings.GetModel <SmartContentPickerFieldSettings>();
                IEnumerable <ContentTypeDefinition> contentTypes;
                if (!String.IsNullOrEmpty(settings.DisplayedContentTypes))
                {
                    var rawTypes = settings.DisplayedContentTypes.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                    contentTypes = _contentDefinitionManager
                                   .ListTypeDefinitions()
                                   .Where(x => x.Parts.Any(p => rawTypes.Contains(p.PartDefinition.Name)) || rawTypes.Contains(x.Name))
                                   .ToArray();
                }
                else
                {
                    contentTypes = GetCreatableTypes(false).ToList();
                }

                var contentItems = Services.ContentManager.Query(VersionOptions.Latest, contentTypes.Select(ctd => ctd.Name).ToArray())
                                   .OrderBy <TitlePartRecord>(cr => cr.Title)
                                   //.OrderByDescending<CommonPartRecord>(cr => cr.ModifiedUtc)
                                   .List();

                var contentType = contentTypes.Select(ctd => ctd.Name).ToArray();

                if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner))
                {
                    if (contentType.Contains("App"))
                    {
                        //App content item permission filtering by role
                        var roles = (Services.WorkContext.CurrentUser.ContentItem).As <UserRolesPart>().Roles;
                        contentItems = contentItems.Where(ci => roles.Select(x => x).Intersect((ci.As <ContentPermissionsPart>().ViewContent == null ? "0" : ci.As <ContentPermissionsPart>().ViewContent).Split(',')).Any());
                    }
                    else
                    {
                        //filter by owned items
                        //contentItems = contentItems.Where(cr => cr.As<CommonPart>().Owner.Id == Services.WorkContext.CurrentUser.Id);
                        contentItems = contentItems.Where(cr => Services.WorkContext.CurrentUser.Id == (cr.As <CommonPart>().Owner == null ? 0 : cr.As <CommonPart>().Owner.Id));
                    }
                }

                var model = new SmartContentPickerFieldViewModel
                {
                    Field = field,
                    Part = part,
                    ContentItems = _contentManager.GetMany <ContentItem>(field.Ids, VersionOptions.Published, QueryHints.Empty).ToList(),
                    AvailableContentItems = contentItems
                };

                //model.SelectedIds = string.Concat(",", field.Ids);

                return shapeHelper.EditorTemplate(TemplateName: "Fields/SmartContentPicker.Edit", Model: model, Prefix: GetPrefix(field, part));
            }));
        }
예제 #2
0
        protected override DriverResult Editor(ContentPart part, Fields.SmartContentPickerField field, IUpdateModel updater, dynamic shapeHelper)
        {
            var model = new SmartContentPickerFieldViewModel();

            updater.TryUpdateModel(model, GetPrefix(field, part), null, null);

            var settings = field.PartFieldDefinition.Settings.GetModel <SmartContentPickerFieldSettings>();

            if (model.SelectedIds == null || model.SelectedIds.Length == 0 || (model.SelectedIds.Length == 1 && model.SelectedIds[0] == string.Empty))
            {
                field.Ids = new int[0];
            }
            else
            {
                field.Ids = Array.ConvertAll(model.SelectedIds, int.Parse);
            }

            if (settings.Required && field.Ids.Length == 0)
            {
                updater.AddModelError("Id", T("The field {0} is mandatory", field.Name.CamelFriendly()));
            }

            return(Editor(part, field, shapeHelper));
        }