Ejemplo n.º 1
0
        /// <summary>
        /// Set editor fields and display orders.
        /// </summary>
        /// <param name="orders">The ordered field names</param>
        public void SetFields(string[] orders)
        {
            var tmpFields = Fields.ToList();

            Fields.Clear();

            foreach (var f in orders)
            {
                var editor = tmpFields.FirstOrDefault(e => e.Name.Equals(f));
                if (editor == null)
                {
                    editor = new ContentEditorField(this, Parent.Fields[f]);
                }
                Fields.Add(editor);
            }

            Fields.Save();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Render the new field editor to response ouput by specified editor field object.
        /// </summary>
        /// <param name="helper">The html helper object.</param>
        /// <param name="editor">The field editor object.</param>
        /// <param name="withLabel">Specified whether show the label on the left of the field editor.</param>
        /// <param name="withNotes">Specified whether show the field notes on the bottom of the field editor.</param>
        public static void ForNew(this HtmlHelper helper, ContentEditorField editor, bool withLabel = true, bool withNotes = true)
        {
            if (editor == null) return;
            if (editor.Field.IsIngored) return;

            var list = editor.Parent;
            var field = editor.Field;
            var server = helper.ViewContext.RequestContext.HttpContext.Server;

            if (editor.IsHidden)
            {
                helper.Hidden(field).WriteTo(helper.ViewContext.Writer);
                return;
            }

            var writer = helper.ViewContext.Writer;
            writer.Write(string.Format("<div class=\"d-field d-{0}-field {1}\">", field.FieldTypeString.ToLower(), field.Name));

            if (withLabel)
            {
                // helper.ViewContext.Writer.Write("<div>");
                helper.Label(field).WriteTo(helper.ViewContext.Writer);
            }

            var tmpl = editor.Template;
            if (!tmpl.IsEmpty)
            {
                if (tmpl.ContentType.Equals(TemplateContentTypes.Razor, StringComparison.OrdinalIgnoreCase))
                    helper.RenderEditorFieldTemplate(editor, "_new");

                if (tmpl.ContentType.Equals(TemplateContentTypes.Xslt, StringComparison.OrdinalIgnoreCase))
                {
                    throw new NotImplementedException();
                }

                if (tmpl.ContentType.Equals(TemplateContentTypes.Xml, StringComparison.OrdinalIgnoreCase))
                {
                    throw new NotImplementedException();
                }

            }
            else
                helper.RenderPartial("~/content/types/base/fields/new/_" + field.FieldTypeString.ToLower() + ".cshtml",
                    editor.Field);

            if (withNotes && !string.IsNullOrEmpty(field.Description))
            {
                //writer.Write("<div>");
                helper.Notes(field).WriteTo(helper.ViewContext.Writer);
                //writer.Write("</div>");
            }

            writer.Write("</div>");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Render the field editor to response output by specified editor field object.
        /// </summary>
        /// <param name="helper">The html helper object.</param>
        /// <param name="field">The editor field which defined in target EditForm</param>
        /// <param name="dataItem">The data item to edit.</param>
        /// <param name="withLabel">Specified whether show the label on the left of the field editor.</param>
        public static void ForDisp(this HtmlHelper helper, ContentEditorField field, ContentDataItemDecorator dataItem, bool? withLabel)
        {
            if (field == null)
                return;

            var writer = helper.ViewContext.Writer;

            if (field.HideInDisplayForm || field.IsHidden)
            {
                helper.Hidden(field.Name, dataItem[field.Name].Raw);
                if (!string.IsNullOrEmpty(field.ItemProp))
                    writer.Write("<meta itemprop=\"" + field.ItemProp + "\" content=\"" + dataItem[field.Name].Raw + "\" />");
                return;
            }

            var list = App.Get().Wrap(field.Parent);
            var server = helper.ViewContext.RequestContext.HttpContext.Server;
            ContentFieldValue val = dataItem.Value(field.Name);

            if (val.IsNull && field.Template.IsEmpty && field.Field.FieldType != (int)ContentFieldTypes.Computed)
                return;

            var showLabel = field.ShowLabel;

            if (withLabel.HasValue)
                showLabel = withLabel.Value;

            if (!string.IsNullOrEmpty(field.ItemProp))
                writer.Write(string.Format("<div class=\"d-field d-{0}-field" + (field.IsCaption ? " d-caption-field" : "") + " {1}\" itemprop=\"{2}\">", field.FieldTypeString.ToLower(), field.Name, field.ItemProp));
            else
                writer.Write(string.Format("<div class=\"d-field d-{0}-field" + (field.IsCaption ? " d-caption-field" : "") + " {1}\">", field.FieldTypeString.ToLower(), field.Name));

            if (showLabel && !val.IsNull)
            {
                var labelEl = new XElement("label", field.Field.Title);
                helper.ViewContext.Writer.Write(labelEl.OuterXml());
            }

            var linkToItem = field.IsLinkToItem;
            if (linkToItem && field.FieldType == (int)ContentFieldTypes.Lookup)
            {
                //if ()
                //{
                var lookupField = field.Field as LookupField;
                if (!lookupField.IsLinkToItem)
                {
                    var lookupList = list.Web.Lists[lookupField.ListName];
                    var lookupItem = lookupList.GetItem(Guid.Parse(dataItem[field.Name].Raw.ToString()));
                    writer.Write(string.Format("<a href=\"{0}\" class=\"d-link\">", lookupItem.UrlComponent));
                }
                else
                    linkToItem = false;
                //}
                //else
                //    helper.ViewContext.Writer.Write(string.Format("<a href=\"{0}\" class=\"d-link\">", dataItem.UrlComponent));
            }
            else
                linkToItem = false;

            var tmpl = field.Template;

            if (!tmpl.IsEmpty)
            {
                if (tmpl.ContentType.Equals(TemplateContentTypes.Razor, StringComparison.OrdinalIgnoreCase))
                    helper.RenderEditorFieldTemplate(field, "_disp", dataItem);

                if (tmpl.ContentType.Equals(TemplateContentTypes.Xslt, StringComparison.OrdinalIgnoreCase))
                {
                    throw new NotImplementedException();
                }

                if (tmpl.ContentType.Equals(TemplateContentTypes.Xml, StringComparison.OrdinalIgnoreCase))
                {
                    throw new NotImplementedException();
                }
            }
            else
            {
                if (field.Field.FieldType == (int)ContentFieldTypes.Computed)
                {
                    //Render Computed Field should we put this code back to ComputedField object?
                    var f = field.Field as ComputedField;
                    f.RenderPattern(dataItem).WriteTo(helper.ViewContext.Writer);
                }
                else
                {
                    var explicitTmpl = "~/content/types/base/fields/disp/_" + field.Field.FieldTypeString.ToLower() + ".cshtml";
                    var commonTmpl = "~/content/types/base/fields/disp/_common.cshtml";
                    var actalTmpl = explicitTmpl;

                    if (!File.Exists(server.MapPath(explicitTmpl)))
                        actalTmpl = commonTmpl;

                    helper.RenderPartial(actalTmpl, val);
                }
            }

            if (linkToItem)
                writer.Write("</a>");

            writer.Write("</div>");
        }
Ejemplo n.º 4
0
 private static void RenderEditorFieldTemplate(this HtmlHelper helper, ContentEditorField field, string filePrefix, ContentDataItemDecorator item = null)
 {
     var tmpl = field.Template;
     var list = field.Parent;
     var server = helper.ViewContext.RequestContext.HttpContext.Server;
     if (!string.IsNullOrEmpty(tmpl.Source))
     {
         var viewFileName = list.Package.ResolveUri(field.Template.Source);
         if (File.Exists(server.MapPath(viewFileName)))
         {
             if (item == null)
                 helper.RenderPartial(viewFileName, field.Field);
             else
                 helper.RenderPartial(viewFileName, item[field.Name]);
         }
         else
             helper.ViewContext.Writer.Write("<span>Field template file not found.</span>");
     }
     else
     {
         if (!string.IsNullOrEmpty(tmpl.Text))
         {
             var viewFile = string.Format("_form_{0}_field_{1}_tmpl.cshtml", field.ParentForm.FormTypeString.ToLower(), field.Name.ToLower());
             var viewUrl = TemplateHelper.SaveAsView(field.Parent, tmpl.Text, viewFile);
             if (item == null)
                 helper.RenderPartial(viewUrl, field.Field);
             else
                 helper.RenderPartial(viewUrl, item[field.Name]);
         }
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Set editor fields and display orders.
        /// </summary>
        /// <param name="orders">The ordered field names</param>
        public void SetFields(string[] orders)
        {
            var tmpFields = Fields.ToList();
            Fields.Clear();

            foreach (var f in orders)
            {
                var editor = tmpFields.FirstOrDefault(e => e.Name.Equals(f));
                if (editor == null)
                    editor = new ContentEditorField(this, Parent.Fields[f]);
                Fields.Add(editor);
            }

            Fields.Save();
        }