コード例 #1
0
        /// <summary>
        /// Render an items tree for specified list
        /// </summary>
        /// <param name="list">The content list object</param>
        /// <param name="current">The content data item object.</param>
        /// <param name="htmlAttributes">The html attributes object.</param>
        /// <returns></returns>
        public static HelperResult Tree(ContentListDecorator list, ContentDataItemDecorator current = null, object htmlAttributes = null)
        {
            return(new HelperResult((w) =>
            {
                using (var writer = new Html32TextWriter(w))
                {
                    writer.WriteBeginTag("ul");
                    writer.WriteAttribute("data-role", "tree");
                    if (htmlAttributes != null)
                    {
                        var dict = htmlAttributes.ToDictionary();
                        foreach (var key in dict.Keys)
                        {
                            if (key.StartsWith("data_"))
                            {
                                writer.WriteAttribute(key.Replace("_", "-"), (string)dict[key]);
                            }
                            else
                            {
                                writer.WriteAttribute(key, (string)dict[key]);
                            }
                        }
                    }

                    writer.Write(Html32TextWriter.TagRightChar);
                    var items = list.GetItems(i => i.ParentItemID == Guid.Empty && i.IsPublished && i.IsCurrentVersion).OrderBy(i => i.Pos);
                    RenderChildren(writer, list, items, current);
                    writer.WriteEndTag("ul");
                }
            }));
        }
コード例 #2
0
 internal static DataRow CreateDataRow(DataTable dt, List<ContentField> fields, ContentDataItemDecorator item)
 {
     var row = dt.NewRow();
     Bind(fields, row, item);
     dt.Rows.Add(row);
     return row;
 }
コード例 #3
0
 /// <summary>
 /// Converts the content list item display form virtual (relative) path to an application absolute path.
 /// </summary>
 /// <param name="helper">The url helper object.</param>
 /// <param name="item">The content data item.</param>
 /// <returns>A string contains item display form absolute url. </returns>
 public static string Content(this UrlHelper helper, ContentDataItemDecorator item)
 {
     if (item == null)
     {
         throw new ArgumentNullException("item");
     }
     return(helper.Content(item.Url));
 }
コード例 #4
0
ファイル: ContentExtensions.cs プロジェクト: howej/dotnetage
 public static HelperResult DraftIcon(this HtmlHelper html, ContentDataItemDecorator dataItem)
 {
     return new HelperResult((w) =>
     {
         using (var writer = new Html32TextWriter(w))
         {
             if (!dataItem.IsPublished)
             {
                 writer.WriteBeginTag("span");
                 writer.WriteAttribute("title", "Draft");
                 writer.WriteAttribute("class", "d-icon d-icon-draft");
                 writer.Write(HtmlTextWriter.TagRightChar);
                 writer.WriteEndTag("span");
             }
         }
     });
 }
コード例 #5
0
ファイル: ContentExtensions.cs プロジェクト: howej/dotnetage
 public static HelperResult AttachIcon(this HtmlHelper html, ContentDataItemDecorator dataItem)
 {
     return new HelperResult((w) =>
     {
         using (var writer = new Html32TextWriter(w))
         {
             if (dataItem.HasAttachments)
             {
                 var url = new UrlHelper(html.ViewContext.RequestContext);
                 writer.WriteBeginTag("a");
                 writer.WriteAttribute("href", url.Content(dataItem) + "#attachments");
                 writer.WriteAttribute("class", "d-icon d-icon-attach");
                 writer.Write(HtmlTextWriter.TagRightChar);
                 writer.WriteEndTag("a");
             }
         }
     });
 }
コード例 #6
0
        public ActionResult Reshare(Guid id, string name, int toListID = 0)
        {
            if (id == Guid.Empty)
            {
                throw new ArgumentNullException("id");
            }

            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            var list = App.Get().CurrentWeb.Lists[name];

            if (list == null)
            {
                throw new ContentListNotFoundException();
            }

            var item = list.GetItem(id);

            if (item == null)
            {
                throw new ContentDataItemNotFoundException();
            }

            ContentDataItemDecorator reshare = null;

            if (toListID > 0)
            {
                var targetList = App.Get().DataContext.Find <ContentList>(toListID);
                reshare = item.ReshareTo(targetList);
            }
            else
            {
                reshare = item.ReshareTo();
            }
            string jsonStr = JsonConvert.SerializeObject(reshare.ToObject(), new JsonSerializerSettings()
            {
                DateFormatHandling = DateFormatHandling.MicrosoftDateFormat
            });

            return(Content(jsonStr, "application/json", Encoding.UTF8));
        }
コード例 #7
0
        internal static void Bind(List<ContentField> fields, DataRow row, ContentDataItemDecorator item)
        {
            int[] cats = null;
            if (item.Model.Categories != null)
                cats = item.Model.Categories.Select(c => c.ID).ToArray();

            row[DataNames.ID] = item.ID;
            row[DataNames.ParentID] = item.ParentItemID;
            row[DataNames.Privacy] = item.Privacy;
            row[DataNames.Created] = item.Created;
            row[DataNames.Pos] = item.Pos;
            if (item.Modified.HasValue)
                row[DataNames.Modified] = item.Modified;

            if (item.Published.HasValue)
                row[DataNames.Published] = item.Published;

            row[DataNames.IsPublished] = item.IsPublished;
            row[DataNames.Modifier] = item.Modifier;
            row[DataNames.State] = item.ModerateState;
            row[DataNames.Tags] = item.Tags;
            row[DataNames.Slug] = item.Slug;
            row[DataNames.Path] = item.Path;
            row[DataNames.Categories] = cats != null ? (string.Join(",", item.Context.Where<Category>(c => cats.Contains(c.ID)).Select(c => c.Name).ToArray())) : "";
            row[DataNames.EnableComments] = item.EnableComments;
            row[DataNames.Owner] = item.Owner;
            row[DataNames.Ratings] = item.Ratings;
            row[DataNames.Reads] = item.Reads;
            row[DataNames.TotalAttachs] = item.TotalAttachments;
            row[DataNames.TotalVotes] = item.TotalVotes;
            row[DataNames.TotalComms] = item.TotalComments;
            row[DataNames.TotalShares] = item.Parent.AllowResharing ? item.Reshares().Count() : 0;
            row[DataNames.Version] = item.Version;
            row[DataNames.HasChildren] = item.Parent.IsHierarchy ? item.Children().Count() > 0 : false;

            foreach (var field in fields)
            {
                var raw = item.Value(field.Name).Raw;
                if (raw == null)
                    row[field.Name] = DBNull.Value;
                else
                    row[field.Name] = raw;
            }
        }
コード例 #8
0
ファイル: ContentExtensions.cs プロジェクト: howej/dotnetage
 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]);
         }
     }
 }
コード例 #9
0
ファイル: UrlExtensions.cs プロジェクト: howej/dotnetage
 /// <summary>
 /// Converts the content list item display form virtual (relative) path to an application absolute path.
 /// </summary>
 /// <param name="helper">The url helper object.</param>
 /// <param name="item">The content data item.</param>
 /// <returns>A string contains item display form absolute url. </returns>
 public static string Content(this UrlHelper helper, ContentDataItemDecorator item)
 {
     if (item == null)
         throw new ArgumentNullException("item");
     return helper.Content(item.Url);
 }
コード例 #10
0
 internal static DataRow CreateDataRow(DataTable dt, ContentViewDecorator view, ContentDataItemDecorator item)
 {
     var vfs = view.FieldRefs.Count == 0 ? view.Parent.Fields.Select(f => f).ToList() : view.FieldRefs.Select(f => f.Field).ToList();
     return CreateDataRow(dt, vfs, item);
 }
コード例 #11
0
ファイル: ContentExtensions.cs プロジェクト: howej/dotnetage
        public static HelperResult ModerateStatus(this HtmlHelper html, ContentDataItemDecorator dataItem)
        {
            return new HelperResult((w) =>
            {
                using (var writer = new Html32TextWriter(w))
                {
                    writer.WriteBeginTag("span");
                    writer.Write(HtmlTextWriter.TagRightChar);
                    if (dataItem.IsPublished)
                    {
                        if (dataItem.Parent.IsModerated)
                        {
                            var state = (ModerateStates)dataItem.ModerateState;
                            switch (state)
                            {
                                case ModerateStates.Pending:
                                    writer.Write("Pending review");
                                    break;
                                case ModerateStates.Rejected:
                                    writer.Write("Rejected");
                                    break;
                                default:
                                    writer.Write("Published");
                                    break;
                            }
                        }
                        else
                            writer.Write("Published");
                    }
                    else
                        writer.Write("Draft");

                    writer.WriteEndTag("span");
                }
            });
        }
コード例 #12
0
ファイル: ContentExtensions.cs プロジェクト: howej/dotnetage
 public static HelperResult NewStatus(this HtmlHelper html, ContentDataItemDecorator dataItem)
 {
     return new HelperResult((w) =>
     {
         using (var writer = new Html32TextWriter(w))
         {
             if (dataItem.IsNew)
             {
                 writer.WriteBeginTag("sup");
                 //writer.WriteAttribute("for", field.ClientID);
                 writer.Write(HtmlTextWriter.TagRightChar);
                 writer.Write("new");
                 //writer.WriteEncodedText(field.Title);
                 writer.WriteEndTag("sup");
             }
         }
     });
 }
コード例 #13
0
        /// <summary>
        /// Render an items tree for specified list 
        /// </summary>
        /// <param name="list">The content list object</param>
        /// <param name="current">The content data item object.</param>
        /// <param name="htmlAttributes">The html attributes object.</param>
        /// <returns></returns>
        public static HelperResult Tree(ContentListDecorator list, ContentDataItemDecorator current = null, object htmlAttributes = null)
        {
            return new HelperResult((w) =>
            {
                using (var writer = new Html32TextWriter(w))
                {
                    writer.WriteBeginTag("ul");
                    writer.WriteAttribute("data-role", "tree");
                    if (htmlAttributes != null)
                    {
                        var dict = htmlAttributes.ToDictionary();
                        foreach (var key in dict.Keys)
                        {
                            if (key.StartsWith("data_"))
                                writer.WriteAttribute(key.Replace("_", "-"), (string)dict[key]);
                            else
                                writer.WriteAttribute(key, (string)dict[key]);
                        }
                    }

                    writer.Write(Html32TextWriter.TagRightChar);
                    var items = list.GetItems(i => i.ParentItemID == Guid.Empty && i.IsPublished && i.IsCurrentVersion).OrderBy(i => i.Pos);
                    RenderChildren(writer, list, items, current);
                    writer.WriteEndTag("ul");
                }
            });
        }
コード例 #14
0
        /// <summary>
        /// Gets the data table that contains all data rows
        /// </summary>
        /// <returns></returns>
        private DataTable GetDataTable()
        {
            //if (cacheTable == null)
            //    cacheTable = LoadFromCache();

            if (cacheTable != null)
            {
                cacheTable.DefaultView.Sort = "";
                cacheTable.DefaultView.RowFilter = "";
                return cacheTable;
            }

            var netdrive = App.Get().NetDrive;
            var listPath = Parent.DefaultListPath.ToString();
            var dataPath = netdrive.MapPath(new Uri(listPath + "cache/"));

            if (!Directory.Exists(dataPath))
                Directory.CreateDirectory(dataPath);

            var viewDataFile = netdrive.MapPath(new Uri(string.Format(listPath + "cache/view_{0}.xml", this.Name)));
            var schema = netdrive.MapPath(new Uri(string.Format(listPath + "cache/schema_{0}.xml", this.Name)));

            var dt = new DataTable();
            dt.TableName = this.Name;

            if (!File.Exists(viewDataFile))
            {
                //Generate the view data file
                var items = this.Parent.EnableVersioning ? Context.Where<ContentDataItem>(c => c.ParentID.Equals(this.ParentID) && c.IsCurrentVersion).OrderByDescending(v => v.Modified).ToList() :
                    Context.Where<ContentDataItem>(c => c.ParentID.Equals(this.ParentID)).OrderByDescending(v => v.Modified).ToList();
                var idColumn = new DataColumn(DataNames.ID, typeof(Guid));

                #region add columns

                dt.Columns.Add(idColumn);
                dt.Columns.Add(DataNames.ParentID, typeof(Guid));
                dt.Columns.Add(DataNames.Privacy, typeof(int));
                dt.Columns.Add(DataNames.Created, typeof(DateTime));
                dt.Columns.Add(DataNames.Modified, typeof(DateTime));
                dt.Columns.Add(DataNames.Published, typeof(DateTime));
                dt.Columns.Add(DataNames.Pos, typeof(int));
                dt.Columns.Add(DataNames.State, typeof(int));
                dt.Columns.Add(DataNames.IsPublished, typeof(bool));
                dt.Columns.Add(DataNames.EnableComments, typeof(bool));
                dt.Columns.Add(DataNames.Slug, typeof(string));
                dt.Columns.Add(DataNames.Path, typeof(string));
                dt.Columns.Add(DataNames.Tags, typeof(string));
                dt.Columns.Add(DataNames.Categories, typeof(string));
                dt.Columns.Add(DataNames.Owner, typeof(string));
                dt.Columns.Add(DataNames.Modifier, typeof(string));
                dt.Columns.Add(DataNames.Ratings, typeof(double));
                dt.Columns.Add(DataNames.Reads, typeof(int));
                dt.Columns.Add(DataNames.TotalAttachs, typeof(int));
                dt.Columns.Add(DataNames.TotalVotes, typeof(int));
                dt.Columns.Add(DataNames.TotalComms, typeof(int));
                dt.Columns.Add(DataNames.TotalShares, typeof(int));
                dt.Columns.Add(DataNames.Version, typeof(int));
                dt.Columns.Add(DataNames.HasChildren, typeof(bool));
                dt.PrimaryKey = new DataColumn[] { idColumn };

                #endregion

                var vfs = this.FieldRefs.Count == 0 ? this.Parent.Fields.Select(f => f).ToList() : this.FieldRefs.Select(f => f.Field).ToList();

                foreach (var f in vfs)
                    dt.Columns.Add(f.Name, f.SystemType);

                foreach (var item in items)
                {
                    var itemWrapper = new ContentDataItemDecorator(item, Context);
                    int[] cats = null;

                    if (item.Categories != null)
                        cats = item.Categories.Select(c => c.ID).ToArray();

                    #region add new row
                    var row = dt.NewRow();
                    row[DataNames.ID] = item.ID;
                    row[DataNames.ParentID] = item.ParentItemID;
                    row[DataNames.Privacy] = item.Privacy;
                    row[DataNames.Created] = item.Created;
                    row[DataNames.Pos] = item.Pos;
                    if (item.Modified.HasValue)
                        row[DataNames.Modified] = item.Modified;

                    if (item.Published.HasValue)
                        row[DataNames.Published] = item.Published;

                    row[DataNames.IsPublished] = item.IsPublished;
                    row[DataNames.Modifier] = item.Modifier;
                    row[DataNames.State] = item.ModerateState;
                    row[DataNames.Tags] = item.Tags;
                    row[DataNames.Slug] = item.Slug;
                    row[DataNames.Path] = item.Path;
                    row[DataNames.Categories] = cats != null ? (string.Join(",", Context.Where<Category>(c => cats.Contains(c.ID)).Select(c => c.Name).ToArray())) : "";
                    row[DataNames.EnableComments] = item.EnableComments;
                    row[DataNames.Owner] = item.Owner;
                    row[DataNames.Ratings] = item.Ratings;
                    row[DataNames.Reads] = item.Reads;
                    row[DataNames.TotalAttachs] = item.TotalAttachments;
                    row[DataNames.TotalVotes] = item.TotalVotes;
                    row[DataNames.TotalComms] = itemWrapper.TotalComments;
                    row[DataNames.TotalShares] = Parent.AllowResharing ? itemWrapper.Reshares().Count() : 0;
                    row[DataNames.Version] = itemWrapper.Version;
                    row[DataNames.HasChildren] = Parent.IsHierarchy ? itemWrapper.Children().Count() > 0 : false;

                    foreach (var v in vfs)
                    {
                        var raw = itemWrapper.Value(v.Name).Raw;
                        if (raw == null)
                            row[v.Name] = DBNull.Value;
                        else
                            row[v.Name] = raw;
                    }
                    dt.Rows.Add(row);

                    #endregion

                }

                dt.AcceptChanges();
                dt.DefaultView.Sort = this.Sort;
                dt.DefaultView.RowFilter = FormatFilter(this.Filter);

                //At first we need to apply the first filter for this table
                cacheTable = dt.DefaultView.ToTable();
                cacheTable.PrimaryKey = new DataColumn[] { cacheTable.Columns[DataNames.ID] };
                cacheTable.WriteXml(viewDataFile);
                cacheTable.WriteXmlSchema(schema, true);
            }
            else
            {
                dt.ReadXmlSchema(schema);
                dt.ReadXml(viewDataFile);
                cacheTable = dt;
            }
            //AddToCache(dt);
            return cacheTable;
        }
コード例 #15
0
ファイル: ContentExtensions.cs プロジェクト: howej/dotnetage
        /// <summary>
        /// Render all fields display html to response output.
        /// </summary>
        /// <param name="helper">The html helper object.</param>
        /// <param name="dataItem">The data item to display.</param>
        public static void ForDispAll(this HtmlHelper helper, ContentDataItemDecorator dataItem)
        {
            foreach (var field in dataItem.Parent.DetailForm.Fields)
            {
                if (field.Name.Equals("title", StringComparison.OrdinalIgnoreCase))
                    continue;

                if (field.HideInDisplayForm)
                    continue;

                helper.ForDisp(field, dataItem, field.ShowLabel);
            }
        }
コード例 #16
0
ファイル: ContentExtensions.cs プロジェクト: howej/dotnetage
        /// <summary>
        ///  Render the 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="dataItem">The data item object to edit.</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 ForEdit(this HtmlHelper helper, ContentEditorField editor, ContentDataItemDecorator dataItem, bool withLabel = true, bool withNotes = true)
        {
            if (editor == null) return;

            var field = editor.Field;

            if (field == null || field.IsIngored) return;

            var list = editor.Parent;

            //App.Get().Wrap(field.Parent);
            var server = helper.ViewContext.RequestContext.HttpContext.Server;

            if (editor.IsHidden)
            {
                helper.Hidden(field, dataItem.Value(editor.Name).Raw).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, "_edit", dataItem);

                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/edit/_" + ((ContentFieldTypes)field.FieldType).ToString().ToLower() + ".cshtml", dataItem.Value(editor.Name));

            if (withNotes && !string.IsNullOrEmpty(field.Description))
            {
                // helper.ViewContext.Writer.Write("<div>");
                helper.Notes(field).WriteTo(helper.ViewContext.Writer);
                //helper.ViewContext.Writer.Write("</div>");
            }
            writer.Write("</div>");
        }
コード例 #17
0
ファイル: ContentExtensions.cs プロジェクト: howej/dotnetage
        /// <summary>
        /// Render the dispaly html to response output for specified field name.
        /// </summary>
        /// <param name="helper">The html helper object</param>
        /// <param name="fieldName">The field name.</param>
        /// <param name="dataItem">The data item to display</param>
        /// <param name="withLabel">Specified whether show the label on the left of the field value</param>
        public static void ForDisp(this HtmlHelper helper, string fieldName, ContentDataItemDecorator dataItem, bool? withLabel)
        {
            if (dataItem == null)
                return;

            if (string.IsNullOrEmpty(fieldName))
            {
                return;
                //helper.ForDisp(dataItem);
            }
            else
            {
                var fieldEditor = dataItem.Parent.DetailForm.Fields[fieldName];
                if (fieldEditor != null)
                    helper.ForDisp(fieldEditor, dataItem, withLabel);
            }
        }
コード例 #18
0
ファイル: ContentExtensions.cs プロジェクト: howej/dotnetage
        /// <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>");
        }
コード例 #19
0
 internal static void Bind(ContentViewDecorator view, DataRow row, ContentDataItemDecorator item)
 {
     var vfs = view.FieldRefs.Count == 0 ? view.Parent.Fields.Select(f => f).ToList() : view.FieldRefs.Select(f => f.Field).ToList();
     Bind(vfs, row, item);
 }
コード例 #20
0
ファイル: ContentExtensions.cs プロジェクト: howej/dotnetage
        /// <summary>
        /// Render computed field display pattern html to response output.
        /// </summary>
        /// <param name="field">The computed field instance.</param>
        /// <param name="dataItem">The data item instance.</param>
        /// <returns></returns>
        public static HelperResult RenderPattern(this ComputedField field, ContentDataItemDecorator dataItem)
        {
            return new HelperResult(writer =>
            {
                //var pattern = string.Format("<pattern>{0}</pattern>", field.DispPattern);
                var root = XElement.Parse(field.DispPattern);
                var ns = root.GetDefaultNamespace();
                foreach (var element in root.Elements())
                {
                    if (element.Name.Equals(ns + "html"))
                        writer.Write(element.Value);

                    if (element.Name.Equals(ns + "col") && element.HasAttributes)
                    {
                        var name = element.StrAttr("name");
                        var output = element.StrAttr("output");
                        if (string.IsNullOrEmpty(output))
                            output = "formatted";
                        if (!string.IsNullOrEmpty(name))
                        {
                            var val = dataItem[name];
                            if (val != null)
                            {
                                if (output == "formatted")
                                    writer.Write(val.Formatted);
                                else
                                    writer.Write(val.Raw);
                            }
                            else
                            {
                                if (name.Equals("ID", StringComparison.OrdinalIgnoreCase))
                                    writer.Write(dataItem.ID);
                                if (name.Equals("ParentID", StringComparison.OrdinalIgnoreCase))
                                    writer.Write(dataItem.ParentID);
                                if (name.Equals("Owner", StringComparison.OrdinalIgnoreCase))
                                    writer.Write(dataItem.Owner);
                                if (name.Equals("Modified", StringComparison.OrdinalIgnoreCase))
                                    writer.Write(dataItem.Modified);
                            }
                        }
                    }
                }
            });
        }
コード例 #21
0
ファイル: ContentExtensions.cs プロジェクト: howej/dotnetage
        /// <summary>
        /// Renders the data item with form item template.
        /// </summary>
        /// <param name="html">The html helper object.</param>
        /// <param name="form">The form object.</param>
        /// <param name="dataItem">The data item object.</param>
        /// <returns></returns>
        public static HelperResult RenderFormTemplate(this HtmlHelper html, ContentFormDecorator form, ContentDataItemDecorator dataItem = null)
        {
            return new HelperResult(writer =>
            {
                var body = form.Body;
                var _contentType = body.ContentType;

                #region razor template
                if (_contentType == TemplateContentTypes.Razor)
                {
                    var viewFile = string.Format("_form_{0}_tmpl.cshtml", form.FormTypeString.ToLower());
                    var viewUrl = TemplateHelper.SaveAsView(form.Parent, body.Text, viewFile);
                    html.RenderPartial(viewUrl, dataItem);
                    return;
                }
                #endregion

                if (_contentType == TemplateContentTypes.Html)
                {
                    throw new NotImplementedException();
                }

                #region xml template

                if (_contentType == TemplateContentTypes.Xml)
                {
                    var doc = XDocument.Parse(body.Text);

                    foreach (var element in doc.Elements())
                    {
                        if (element.Name == "label")
                        {
                            var nameAttr = element.StrAttr("name");
                            var field = form.Parent.Fields[nameAttr];
                            if (field != null)
                                html.ViewContext.Writer.Write(html.Label(field));
                            continue;
                        }

                        if (element.Name == "notes")
                        {
                            var nameAttr = element.StrAttr("name");
                            var field = form.Parent.Fields[nameAttr];
                            if (field != null)
                                html.ViewContext.Writer.Write(html.Notes(field));
                            continue;
                        }

                        if (element.Name.Equals("col"))
                        {
                            var nameAttr = element.StrAttr("name");
                            var field = form.Fields[nameAttr];
                            var hasLabel = element.BoolAttr("hasLabel");
                            var hasNotes = element.BoolAttr("hasNotes");

                            if (field != null)
                            {
                                switch ((ContentFormTypes)form.FormType)
                                {
                                    case ContentFormTypes.Display:
                                        html.ForDisp(field, dataItem, hasLabel);
                                        break;
                                    case ContentFormTypes.Edit:
                                        html.ForEdit(field, dataItem, hasLabel, hasNotes);
                                        break;
                                    case ContentFormTypes.New:
                                        html.ForNew(field, hasLabel, hasNotes);
                                        break;
                                }
                            }
                        }

                        if (element.Name == "html")
                        {
                            writer.Write(element.InnerXml());
                            continue;
                        }
                    }
                }

                #endregion

                #region xslt template

                if (_contentType == TemplateContentTypes.Xslt)
                {
                    throw new NotImplementedException();
                }

                #endregion

            });
        }
コード例 #22
0
ファイル: ContentExtensions.cs プロジェクト: howej/dotnetage
        /// <summary>
        /// Render the form html to response output by specified the form object.This method will auto determine which mode to render.
        /// </summary>
        /// <param name="helper">The html helper object.</param>
        /// <param name="form">The content form object.</param>
        /// <param name="model">The data item for edit,display and activity form</param>
        /// <returns></returns>
        public static HelperResult RenderForm(this HtmlHelper helper, ContentFormDecorator form, ContentDataItemDecorator model = null)
        {
            return new HelperResult(writer =>
            {
                var server = helper.ViewContext.HttpContext.Server;
                var list = form.Parent;
                var defaultViewFile = "";
                var format = "~/content/types/base/forms/{0}.cshtml";

                switch (form.FormType)
                {
                    case (int)ContentFormTypes.New:
                        defaultViewFile = string.Format(format, "_new");
                        break;
                    case (int)ContentFormTypes.Edit:
                        defaultViewFile = string.Format(format, "_edit");
                        break;
                    case (int)ContentFormTypes.Activity:
                        defaultViewFile = string.Format(format, "_activity");
                        break;
                    default:
                        defaultViewFile = string.Format(format, "_detail");
                        break;
                }

                var body = form.Body;
                if (form.HasTemplate)
                {
                    //The form must be has template
                    if (!string.IsNullOrEmpty(body.Source))
                    {
                        #region file template
                        var viewFile = list.Package.ResolveUri(form.Body.Source);
                        if (!File.Exists(server.MapPath(viewFile)))
                        {
                            viewFile = defaultViewFile;
                        }
                        #endregion

                        if (model != null)
                            helper.RenderPartial(viewFile, model, helper.ViewData);
                        else
                            helper.RenderPartial(viewFile, helper.ViewData);
                    }
                    else
                    {
                        helper.RenderFormTemplate(form, model);
                    }
                }
                else
                {
                    //The form has no any template definition
                    if (model != null)
                        helper.RenderPartial(defaultViewFile, model, helper.ViewData);
                    else
                        helper.RenderPartial(defaultViewFile, helper.ViewData);
                }
            });
        }
コード例 #23
0
ファイル: ContentExtensions.cs プロジェクト: howej/dotnetage
 /// <summary>
 /// Render fields elements to response output by specified form and item object.
 /// </summary>
 /// <param name="helper">The html helper object.</param>
 /// <param name="form">The form object.</param>
 /// <param name="item">The data item to render.</param>
 public static void RenderFields(this HtmlHelper helper, ContentFormDecorator form, ContentDataItemDecorator item = null)
 {
     foreach (var f in form.Fields)
     {
         switch ((ContentFormTypes)form.FormType)
         {
             case ContentFormTypes.New:
                 helper.ForNew(f);
                 break;
             case ContentFormTypes.Edit:
                 helper.ForEdit(f, item);
                 break;
             case ContentFormTypes.Activity:
                 helper.ForAct(f, item, null);
                 break;
             default:
                 helper.ForDisp(f, item, null);
                 break;
         }
     }
 }