コード例 #1
0
        // TODO: something generic, move out of here
        protected virtual bool IsInEditMode(ModelPropertyContext context)
        {
            var editMode       = false;
            var modeDetected   = false;
            var requestContext = context.ExecutionContext.RequestContext;

            object contextMode;

            if (requestContext.RouteData.DataTokens.TryGetValue("contextmode", out contextMode))
            {
                editMode     = (ContextMode)contextMode == ContextMode.Edit;
                modeDetected = true;
            }

            if (!modeDetected)
            {
                editMode = PageEditing.PageIsInEditMode;
            }

            // skip processing for block previews to render them in ordinary view mode
            if (editMode && IsInBlockPreviewMode(context))
            {
                return(false);
            }

            return(editMode);
        }
コード例 #2
0
 protected virtual bool FilterByType(ModelPropertyContext context)
 {
     return((context.Property.PropertyType.Is <IHtmlString>() &&
             context.Property.PropertyType != typeof(ContentArea)) ||  // TODO: let's skip content areas for now
            context.Property.PropertyType.GetCollectionItemType().IfNotNull(t => t.Is <IHtmlString>()) ||
            (context.PropertyValue != null && context.PropertyValue.GetType().Is(typeof(EditableCollection <>))));
 }
コード例 #3
0
        public virtual void Process(ModelPropertyContext context)
        {
            var url         = (string)context.PropertyValue;
            var friendlyUrl = _urlRewriter.GetFriendlyUrl(url, context.ExecutionContext.RequestContext, RouteTable.Routes);

            context.PropertyValue = friendlyUrl;
        }
コード例 #4
0
        public virtual void Process(ModelPropertyContext context)
        {
            var url         = ((IHtmlString)context.PropertyValue).IfNotNull(x => x.ToHtmlString());
            var friendlyUrl = _urlRewriter.GetFriendlyUrl(url, context.ExecutionContext.RequestContext, RouteTable.Routes);

            context.PropertyValue = HtmlStringActivator.CreateInstance(context.Property.PropertyType, friendlyUrl);
        }
コード例 #5
0
        public override void Process(ModelPropertyContext context)
        {
            base.Process(context);

            var fieldHtml = InsertPageEditorMarkup(context, (IHtmlString)context.PropertyValue);

            context.PropertyValue = fieldHtml; // TODO: we could have an exception here (different types of property and setting value)
        }
コード例 #6
0
        private IHtmlString GetFieldEditHint(string editName, ModelPropertyContext context)
        {
            var editHint     = context.Property.Get <EditHintAttribute>() ?? new EditHintAttribute();
            var cssClassAttr = editHint.CssClass.IfNotNullOrEmpty(css => string.Format(" class=\"{0}\"", css));

            var html = string.Format("<span{0}>[{1}]</span>", cssClassAttr, editName.ToFriendlyString());

            return(new HtmlString(html));
        }
コード例 #7
0
        public virtual void Process(ModelPropertyContext context)
        {
            var links = (IEnumerable <Link>)context.PropertyValue;

            foreach (var link in links)
            {
                link.Url = _urlRewriter.GetFriendlyUrl(link.Url, context.ExecutionContext.RequestContext, RouteTable.Routes);
            }
        }
コード例 #8
0
        public override void Process(ModelPropertyContext context)
        {
            var editName = GetFieldEditName(context);
            var fakeLink = new Link
            {
                Url  = "#",
                Text = "[" + editName.ToFriendlyString() + "]"
            };

            context.PropertyValue = new List <Link>(new[] { fakeLink });
        }
コード例 #9
0
        public virtual void Process(ModelPropertyContext context)
        {
            if (context.Property.PropertyType.Is <IEnumerable>())
            {
                if (context.PropertyValue == null || !context.PropertyValue.GetType().Is(typeof(EditableCollection <>)))
                {
                    var itemType           = context.Property.PropertyType.GetCollectionItemType();
                    var collectionTemplate = typeof(EditableCollection <>).MakeGenericType(itemType);

                    context.PropertyValue = Activator.CreateInstance(collectionTemplate, context.PropertyValue);
                }
            }
        }
コード例 #10
0
        private bool IsInBlockPreviewMode(ModelPropertyContext context)
        {
            if (context.Model.GetType().Name.EndsWith("BlockModel"))
            {
                var httpContext  = context.ExecutionContext.RequestContext.HttpContext;
                var contentStack = httpContext.Items[ContentContext.ContentContextKey] as Stack <ContentContext.ContentPropertiesStack>;

                // TODO: check the stask and return true if the parent item is a content area.
                return(false);
            }

            return(false);
        }
コード例 #11
0
ファイル: XhtmlStringHandler.cs プロジェクト: whyleee/EPiGlue
        public virtual void Process(ModelPropertyContext context)
        {
            var value  = (XhtmlString)context.PropertyValue;
            var result = new StringBuilder();

            using (var writer = new StringWriter(result))
            {
                RenderXhtmlStringToWriter(value, writer,
                                          context.ExecutionContext.Controller,
                                          context.ExecutionContext.RequestContext
                                          );
            }

            context.PropertyValue = HtmlStringActivator.CreateInstance(context.Property.PropertyType, result.ToString());
        }
コード例 #12
0
        protected virtual string GetFieldEditName(ModelPropertyContext context)
        {
            var field        = context.Property;
            var editNameHint = field.Get <EditHintAttribute>().IfNotNull(x => x.EditName);

            if (editNameHint.IsNotNullOrEmpty())
            {
                return(editNameHint);
            }

            if (field.Has <EditHintNoPrefixAttribute>())
            {
                return(field.Name);
            }

            var editPrefix = context.Model.GetType().Get <EditHintPrefixAttribute>().IfNotNull(x => x.EditPrefix);

            return(editPrefix + field.Name);
        }
コード例 #13
0
        private bool IsInBlockPreviewMode(ModelPropertyContext context)
        {
            if (!context.Model.GetType().Name.EndsWith("BlockModel"))
            {
                return(false);
            }

            var parentViewContext = context.ExecutionContext.ParentActionViewContext;

            if (parentViewContext == null)
            {
                return(false);
            }

            var controllerType = parentViewContext.Controller.GetType();

            return(!controllerType.Has <TemplateDescriptorAttribute>(
                       with: attr => attr.Tags.Contains(RenderingTags.Preview)
                       ));
        }
コード例 #14
0
        private IHtmlString InsertPageEditorMarkup(ModelPropertyContext context, IHtmlString fieldHtml)
        {
            var editHtml    = fieldHtml is IEditHtmlString ? (IEditHtmlString)fieldHtml : new EditableHtmlString(fieldHtml);
            var htmlBuilder = new StringBuilder();
            var editHint    = context.Property.Get <EditHintAttribute>() ?? new EditHintAttribute();

            using (var writer = new StringWriter(htmlBuilder))
            {
                using (var editContainer = new MvcEditContainer(
                           requestContext: context.ExecutionContext.RequestContext,
                           epiPropertyKey: PageEditing.DataEPiPropertyName,
                           epiPropertyName: GetFieldEditName(context),
                           editElementName: editHint.EditTag,
                           editElementCssClass: editHint.EditCssClass,
                           writer: writer))
                {
                    Func <string> renderSettingsWriter = null;
                    var           renderSettings       = new RouteValueDictionary();

                    if (editHint.CssClass.IsNotNullOrEmpty())
                    {
                        renderSettings.Add("CssClass", editHint.CssClass);
                    }
                    if (editHint.ChildrenCssClass.IsNotNullOrEmpty())
                    {
                        renderSettings.Add("ChildrenCssClass", editHint.ChildrenCssClass);
                    }

                    renderSettingsWriter = () => AttrsWriter(renderSettings, PageEditing.DataEPiPropertyRenderSettings);

                    editContainer.CreateStartElementForEditMode(renderSettingsWriter);
                    editHtml.EditorStart = new HtmlString(writer.ToString());
                    htmlBuilder.Clear();
                }

                editHtml.EditorEnd = new HtmlString(writer.ToString());
            }

            return(editHtml);
        }
コード例 #15
0
        public override void Process(ModelPropertyContext context)
        {
            base.Process(context);

            var editName  = GetFieldEditName(context);
            var editHint  = GetFieldEditHint(editName, context);
            var fieldType = context.Property.PropertyType;

            if (fieldType.Is <IEditHtmlString>())
            {
                var fieldValue = Activator.CreateInstance(fieldType);
                ((IEditHtmlString)fieldValue).DefaultValue = editHint;

                context.PropertyValue = fieldValue;
            }
            else if (fieldType == typeof(IHtmlString))
            {
                context.PropertyValue = editHint;
            }
            else
            {
                // Don't know how to insert the hint, skipping this field..
            }
        }
コード例 #16
0
 protected override bool FilterByType(ModelPropertyContext context)
 {
     return(context.Property.PropertyType.Is <IEnumerable <Link> >());
 }
コード例 #17
0
 protected override bool FilterByValue(ModelPropertyContext context)
 {
     return(context.PropertyValue == null || ((IEnumerable <Link>)context.PropertyValue).IsEmpty());
 }
コード例 #18
0
 public virtual bool CanHandle(ModelPropertyContext context)
 {
     return(IsInEditMode(context) && FilterByType(context) && FilterIgnored(context) && FilterByValue(context));
 }
コード例 #19
0
 public override bool CanHandle(ModelPropertyContext context)
 {
     return(base.CanHandle(context) && !IsInBlockPreviewMode(context));
 }
コード例 #20
0
 protected override bool FilterByValue(ModelPropertyContext context)
 {
     return(context.PropertyValue == null);
 }
コード例 #21
0
 protected virtual bool FilterIgnored(ModelPropertyContext context)
 {
     return(!context.Model.GetType().Has <EditIgnoreAttribute>() && !context.Property.Has <EditIgnoreAttribute>());
 }
コード例 #22
0
 protected virtual bool FilterByValue(ModelPropertyContext context)
 {
     return(true);
 }
コード例 #23
0
ファイル: XhtmlStringHandler.cs プロジェクト: whyleee/EPiGlue
 public virtual bool CanHandle(ModelPropertyContext context)
 {
     return(context.PropertyValue != null && context.PropertyValue.GetType() == typeof(XhtmlString));
 }
コード例 #24
0
        public virtual void Process(ModelPropertyContext context)
        {
            var link = (Link)context.PropertyValue;

            link.Url = _urlRewriter.GetFriendlyUrl(link.Url, context.ExecutionContext.RequestContext, RouteTable.Routes);
        }
コード例 #25
0
 public virtual bool CanHandle(ModelPropertyContext context)
 {
     return(context.PropertyValue is string &&
            context.Property.Has <UIHintAttribute>(with: x => x.UIHint == UIHint.Document));
 }
コード例 #26
0
 public virtual bool CanHandle(ModelPropertyContext context)
 {
     return(context.PropertyValue is Link);
 }
コード例 #27
0
 public virtual bool CanHandle(ModelPropertyContext context)
 {
     return(context.PropertyValue is IEnumerable <Link>);
 }