Beispiel #1
0
        private static MvcHtmlString Editor(this HtmlHelper html, FieldValue pair, bool articleIsAgregated = false, bool forceReadonly = false)
        {
            var field         = pair.Field;
            var id            = pair.Field.FormName;
            var value         = pair.Value;
            var isVersionView = pair.Article.ViewType == ArticleViewType.CompareVersions;

            if (isVersionView)
            {
                switch (field.Type.Name)
                {
                case FieldTypeName.Textbox:
                case FieldTypeName.VisualEdit:
                    return(html.VersionArea(id, value));

                case FieldTypeName.Relation:
                case FieldTypeName.M2ORelation:
                    return(html.VersionRelation(id, value, pair.ValueToMerge, field, pair.Article.Id, pair.Article.ViewType));

                case FieldTypeName.File:
                case FieldTypeName.Image:
                    return(html.VersionFile(id, value, field, pair.Version, pair.Article.ViewType));

                case FieldTypeName.Time:
                    return(html.VersionTime(id, value, pair.ValueToMerge, pair.Article.ViewType));

                case FieldTypeName.Date:
                    return(html.VersionDate(id, value, pair.ValueToMerge, pair.Article.ViewType));

                case FieldTypeName.DateTime:
                    return(html.VersionDateTime(id, value, pair.ValueToMerge, pair.Article.ViewType));

                case FieldTypeName.Numeric:
                    return(field.IsClassifier
                            ? html.VersionClassifierField(id, value, field, pair.Article, pair.Version, true, pair.ValueToMerge)
                            : html.VersionText(id, value));

                default:
                    return(html.VersionText(id, value));
                }
            }

            var readOnly       = forceReadonly || pair.Article.IsReadOnly || field.IsReadOnly || !articleIsAgregated && pair.Article.Content.HasAggregatedFields;
            var htmlAttributes = html.QpHtmlProperties(id, field, -1, readOnly, pair.Field.Name);

            switch (field.ExactType)
            {
            case FieldExactTypes.Textbox:
                return(html.QpTextArea(id, value, htmlAttributes));

            case FieldExactTypes.VisualEdit:
                return(html.VisualEditor(id, value, htmlAttributes, field, readOnly));

            case FieldExactTypes.File:
            case FieldExactTypes.Image:
            case FieldExactTypes.DynamicImage:
                return(html.File(id, value, htmlAttributes, field, pair.Version?.Id ?? pair.Article.Id, pair.Version));

            case FieldExactTypes.DateTime:
                return(html.DateTime(id, value, htmlAttributes, !field.Required, readOnly));

            case FieldExactTypes.Date:
                return(html.Date(id, value, htmlAttributes, !field.Required, readOnly));

            case FieldExactTypes.Time:
                return(html.Time(id, value, htmlAttributes, !field.Required, readOnly));

            case FieldExactTypes.Boolean:
                return(html.QpCheckBox(id, null, Converter.ToBoolean(value), htmlAttributes));

            case FieldExactTypes.Numeric:
                return(html.NumericTextBox(id, value, htmlAttributes, field.DecimalPlaces));

            case FieldExactTypes.Classifier:
                if (pair.Version != null)
                {
                    return(html.VersionClassifierField(id, value, field, pair.Article, pair.Version, readOnly));
                }

                return(html.ClassifierField(id, value, field, pair.Article, readOnly));

            case FieldExactTypes.O2MRelation:
            case FieldExactTypes.M2MRelation:
            case FieldExactTypes.M2ORelation:
                var result = ArticleViewModel.GetListForRelation(field, value, pair.Article.Id);
                return(html.Relation(id, html.List(result.Items), new ControlOptions
                {
                    Enabled = !readOnly,
                    HtmlAttributes = htmlAttributes
                }, field, pair.Article.Id, result.IsListOverflow));

            case FieldExactTypes.StringEnum:
                return(html.StringEnumEditor(id, value, field, readOnly, pair.Article.IsNew));

            default:
                return(html.QpTextBox(id, value, htmlAttributes));
            }
        }