public ActionResult EditCss(string name, string type, string csstext) { var form = _GetForm(name, type); ViewBag.CssText = csstext; if (!string.IsNullOrEmpty(csstext)) { var root = new XElement("styles"); root.Add(new XElement("styleSheet", new XCData(Server.HtmlDecode(csstext)))); form.StyleSheetsXml = root.OuterXml(); } else { form.StyleSheetsXml = ""; } form.Save(); return PartialView(form); }
/// <summary> /// Render inline path navigation elements for current page. /// </summary> /// <param name="htmlAttributes">The html attributes for output element.</param> /// <param name="showCurrent">Show current states</param> /// <param name="showRoot">Show the root node of the path.</param> /// <returns></returns> public static HelperResult RenderPagePath(object htmlAttributes = null, bool showCurrent = true, bool showRoot = true) { return new HelperResult(writer => { var curPage = AppModel.Get().CurrentPage; if (curPage != null) { var parents = curPage.Parents().Where(p => !p.IsShared).OrderBy(p => p.Path).ToList().Select(n => { var wrapper = AppModel.Get().Wrap(n); var element = new XElement("li", new XElement("a", wrapper.Title, new XAttribute("href", wrapper.Url))); if (!string.IsNullOrEmpty(wrapper.Description)) element.Add(new XAttribute("title", wrapper.Description)); return element; }); var ul = new XElement("ul"); if (showRoot) { ul.Add(new XElement("li", new XElement("a", AppModel.Get().CurrentWeb.Title, new XAttribute("href", UrlHelper.GenerateContentUrl(AppModel.Get().CurrentWeb.Url, Context)) ))); } if (htmlAttributes != null) { var attrs = htmlAttributes.ToDictionary(); foreach (var attr in attrs.Keys) { ul.Add(new XAttribute(attr.Replace("_", "-"), attrs[attr])); } } if (parents.Count() > 0) ul.Add(parents); if (showCurrent && !curPage.IsShared) { ul.Add(new XElement("li", new XElement("a", curPage.Title, new XAttribute("href", "javascript:void(0);") ), new XAttribute("class", "d-link d-state-active"))); } var ctx = AppModel.Get().Context; if (ctx.View != null) { ul.Add(new XElement("li", new XElement("a", ctx.View.Title, new XAttribute("href", UrlHelper.GenerateContentUrl(ctx.View.Url, Context))))); } //Render context form , item and views if (ctx.DataItem != null) { var list = ctx.DataItem.Parent; if (list.IsHierarchy) { var parentItems = ctx.DataItem.Parents(); if (parentItems != null) { var itemParentEles = parentItems.ToList() .Select(p => { var itemWrapper = AppModel.Get().Wrap(p); var title = itemWrapper.GetDefaultTitleValue(); var element = new XElement("li", new XElement("a", title, new XAttribute("href", UrlHelper.GenerateContentUrl(itemWrapper.Url, Context)))); return element; }); if (itemParentEles.Count() > 0) ul.Add(itemParentEles); } } ul.Add(new XElement("li", new XElement("a", ctx.DataItem.GetDefaultTitleValue(), new XAttribute("href", DNA.Utility.UrlUtility.CreateUrlHelper().Action("Catalog", "Contents", new { Area = "", name = list.Name, website = list.Web.Name, locale = list.Locale, id = ctx.DataItem.ID })), new XAttribute("data-rel", "panel"), new XAttribute("data-panel-fill", "true"), new XAttribute("data-panel-display", "push"), new XAttribute("data-panel-title", ctx.DataItem.Parent.Title) ), new XAttribute("class", "d-state-active"))); } if (ul.HasElements) writer.Write(ul.OuterXml()); } }); }
/// <summary> /// Render a HTML button that use to show the new form for specified content list object. /// </summary> /// <param name="html">The html helper object.</param> /// <param name="list">The content list object.</param> /// <returns></returns> public static HelperResult NewItemDialogButton(this HtmlHelper html, ContentListDecorator list) { return new HelperResult(writer => { var newForm = list.NewForm; if (newForm == null) return; var Url = new UrlHelper(html.ViewContext.RequestContext); var addNewUrl = UrlBuilder.Create(Url.Content(list.GetNewItemUrl())).AddParam("locale", list.Locale).ToString(); var xEle = new XElement("a", string.IsNullOrEmpty(newForm.Title) ? HttpContext.GetGlobalResourceObject("Contents", "AddItem").ToString() : newForm.Title, new XAttribute("data-role", "button"), new XAttribute("data-rel", "dialog"), new XAttribute("data-default", "true"), new XAttribute("data-dialog-title", newForm.Title), new XAttribute("data-dialog-cache", "false"), new XAttribute("data-dialog-modal", "true"), new XAttribute("data-dialog-fullscreen", "true"), new XAttribute("href", addNewUrl)); writer.Write(xEle.OuterXml()); }); }
public virtual void Load(XElement element, string locale = "") { var ns = element.GetDefaultNamespace(); this.Name = element.StrAttr(NAME); this.IsDefault = element.BoolAttr(DEFAULT); this.Icon = element.StrAttr(ICON); this.IsHierarchy = element.BoolAttr(HIERARCHY); this.HideToolbar = element.BoolAttr(HIDE_TOOLBAR); this.Roles = element.StrAttr(ACCESS_ROLES); this.Sort = element.StrAttr(SORT); this.Filter = element.StrAttr(FILTER); var title = element.ElementWithLocale(ns + TITLE, locale); var desc = element.ElementWithLocale(ns + DESC, locale); var paging = element.Element(ns + PAGING); if (element.Attribute(ANONYMOUS) != null) this.AllowAnonymous = element.BoolAttr(ANONYMOUS); else this.AllowAnonymous = true; if (title == null) title = element.ElementWithLocale(ns + TITLE, ""); if (desc == null) desc = element.ElementWithLocale(ns + DESC, ""); if (title != null) this.Title = title.Value; if (desc != null) this.Description = desc.Value; if (paging != null) { this.PageIndex = paging.IntAttr(INDEX); this.PageSize = paging.IntAttr(SIZE); this.AllowPaging = paging.BoolAttr(ALLOW); } var fieldsEle = element.Element(ns + FIELDS); if (fieldsEle != null) FieldRefsXml = fieldsEle.OuterXml(); //FieldRefsXml = string.Format("<fields>{0}</fields>", fieldsEle.InnerXml()); var body = element.ElementWithLocale(ns + BODY, locale); if (body == null) body = element.ElementWithLocale(ns + BODY, ""); if (body != null) this.BodyTemplateXml = body.OuterXml(); var empty = element.ElementWithLocale(ns + EMPTY_PATTERN, locale); if (empty == null) element.ElementWithLocale(ns + EMPTY_PATTERN, ""); if (empty != null) this.EmptyTemplateXml = empty.OuterXml(); this.NoPage = element.BoolAttr(NOPAGE); #region style and scripts var scripts = element.ElementsWithLocale(ns + SCRIPT, locale); var styles = element.ElementsWithLocale(ns + STYLE_SHEET, locale); if (scripts == null || (scripts != null && scripts.Count() == 0)) scripts = element.ElementsWithLocale(ns + SCRIPT, ""); if (styles == null || (styles != null && styles.Count() == 0)) styles = element.ElementsWithLocale(ns + STYLE_SHEET, ""); if (scripts != null && scripts.Count() > 0) { var scriptEl = new XElement("scripts", scripts); this.ScriptsXml = scriptEl.OuterXml(); } if (styles != null && styles.Count() > 0) { var styleEl = new XElement("styles", styles); this.StyleSheetsXml = styleEl.OuterXml(); } #endregion }
/// <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>"); }
/// <summary> /// Render the field value to response output for View by specified field name and data item object. /// </summary> /// <param name="helper">The html helper object.</param> /// <param name="fieldName">The field name which defined in ViewFields</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 ForView(this HtmlHelper helper, string fieldName, ContentQueryResultItem dataItem, bool? withLabel = null) { if (dataItem == null) return; var view = dataItem.View; var fieldRef = view.FieldRefs[fieldName]; if (fieldRef == null) { //Render the error holder && view.Parent.Fields[fieldName] == null var title = fieldName; if (view.Parent.Fields[fieldName] != null) title = view.Parent.Fields[fieldName].Title; helper.ViewContext.Writer.Write("<div class='d-state-error' style=\"padding:10px;\">Can not found the <strong>" + title + "</strong> field in this view</div>"); return; } if (fieldRef.IsHidden) { helper.Hidden(fieldRef.Field, dataItem[fieldName]).WriteTo(helper.ViewContext.Writer); return; } var showLabel = fieldRef.ShowLabel; if (withLabel.HasValue) showLabel = withLabel.Value; if (showLabel && !dataItem.IsNull(fieldName)) { var labelEl = new XElement("label", fieldRef.Title + ":"); helper.ViewContext.Writer.Write(labelEl.OuterXml()); } var tmpl = fieldRef.Template; if (!fieldRef.Template.IsEmpty) { if (tmpl.ContentType.Equals(TemplateContentTypes.Razor, StringComparison.OrdinalIgnoreCase)) helper.RenderViewFieldTemplate(fieldRef, "_viewitem", dataItem); if (tmpl.ContentType.Equals(TemplateContentTypes.Xslt, StringComparison.OrdinalIgnoreCase)) { throw new NotImplementedException(); } if (tmpl.ContentType.Equals(TemplateContentTypes.Xml, StringComparison.OrdinalIgnoreCase)) { throw new NotImplementedException(); } //When the view field has template definition exit this process return; } else { var field = fieldRef.Field; var server = helper.ViewContext.RequestContext.HttpContext.Server; var explicitTmpl = "~/content/types/base/fields/view/_" + field.FieldTypeString.ToLower() + ".cshtml"; if (File.Exists(server.MapPath(explicitTmpl))) { // render default field tmpl helper.RenderPartial(explicitTmpl, new ContentViewFieldValue(fieldRef, dataItem)); } else { var linkToItem = field.IsLinkToItem; var url = new UrlHelper(helper.ViewContext.RequestContext); var writer = helper.ViewContext.Writer; var linkFormat = "<a href=\"{0}\" class=\"d-link\">"; var fieldVal = field.Format(dataItem[field.Name]); var link = url.Content(dataItem); if (linkToItem) writer.Write(string.Format(linkFormat, link)); if (field.FieldType == (int)ContentFieldTypes.Computed) { var f = field as ComputedField; if (f != null) f.RenderPattern(dataItem).WriteTo(writer); } writer.Write(fieldVal); if (linkToItem) { writer.Write("</a>"); } } } }
/// <summary> /// Render HTML pager element for specified search query. /// </summary> /// <param name="html">The html helper object.</param> /// <param name="query">The search query object.</param> /// <param name="htmlAttributes">The html attributes object for the output html element.</param> /// <returns></returns> public static HelperResult Pager(this HtmlHelper html, SearchQuery query, object htmlAttributes = null) { return new HelperResult(writer => { var Url = new UrlHelper(html.ViewContext.RequestContext); var website = html.ViewContext.RouteData.Values["website"].ToString(); var locale = html.ViewContext.RouteData.Values["locale"].ToString(); var _url = App.Get().Context.AppUrl + website + "/" + locale + "search/" + query.Source; var maxPageCount = 10; var curIndex = query.Index; var startIndex = 1; var endIndex = maxPageCount * startIndex; var curPage = (int)Math.Ceiling((decimal)((decimal)curIndex / (decimal)maxPageCount)); if (curPage > 1) startIndex = (curPage * maxPageCount) - maxPageCount + 1; endIndex = startIndex + maxPageCount; if (endIndex > query.TotalPages) endIndex = query.TotalPages; var _params = new List<string>(); var queryString = html.ViewContext.RequestContext.HttpContext.Request.QueryString; if (queryString != null) { foreach (var key in queryString.AllKeys) { if (key.Equals("index", StringComparison.OrdinalIgnoreCase) || key.Equals("size", StringComparison.OrdinalIgnoreCase)) continue; _params.Add(string.Format("{0}={1}", key, queryString[key])); } } var isLast = curPage * maxPageCount >= query.TotalPages; var isFirst = startIndex == 1; var builder = new UriBuilder(); //if (startIndex == endIndex && startIndex == 1) // return; if (isLast) endIndex++; var pageElement = new XElement("div", new XAttribute("class", "d-pager")); pageElement.AddHtmlAttributes(htmlAttributes); if (!isFirst) { pageElement.Add( new XElement("a", new XAttribute("href", Url.BuildUrl(_url, _params)), new XAttribute("title", "First"), new XAttribute("class", "d-ui-widget d-button"), new XElement("span", new XAttribute("class", "d-icon d-icon-first"))), new XElement("a", new XAttribute("href", _url + "?index=" + (curIndex - 1).ToString() + "&size=" + query.Size + (_params.Count > 0 ? ("&" + string.Join("&", _params.ToArray())) : "")), new XAttribute("title", "Prev"), new XElement("span", new XAttribute("class", "d-icon d-icon-prev"))) ); } for (int i = startIndex; i < endIndex; i++) { var pagerItem = new XElement("a", i != curIndex ? i : curIndex); if (i == curIndex) pagerItem.Add(new XAttribute("class", "d-ui-widget d-button d-state-active")); else pagerItem.Add(new XAttribute("class", "d-ui-widget d-button")); if (i != curIndex) pagerItem.Add(new XAttribute("href", _url + "?index=" + i.ToString() + "&size=" + query.Size + (_params.Count > 0 ? ("&" + string.Join("&", _params.ToArray())) : ""))); pageElement.Add(pagerItem); } if (!isLast) { pageElement.Add( new XElement("a", new XAttribute("href", _url + "?index=" + (curIndex + 1).ToString() + "&size=" + query.Size + (_params.Count > 0 ? ("&" + string.Join("&", _params.ToArray())) : "")), new XAttribute("title", "Next"), new XAttribute("class", "d-ui-widget d-button"), new XElement("span", new XAttribute("class", "d-icon d-icon-next"))), new XElement("a", new XAttribute("href", _url + "?index=" + (query.TotalPages).ToString() + "&size=" + query.Size + (_params.Count > 0 ? ("&" + string.Join("&", _params.ToArray())) : "")), new XAttribute("title", "Last"), new XAttribute("class", "d-ui-widget d-button"), new XElement("span", new XAttribute("class", "d-icon d-icon-last"))) ); } writer.Write(pageElement.OuterXml()); }); }
private static void WriteStyles(TextWriter w, string stylesXml, ContentPackage pkg) { if (!string.IsNullOrEmpty(stylesXml)) { var Url = DNA.Utility.UrlUtility.CreateUrlHelper(); var stylesEl = XElement.Parse(stylesXml); if (stylesEl != null && stylesEl.HasElements) { foreach (var style in stylesEl.Elements()) { var src = style.StrAttr("src"); if (!string.IsNullOrEmpty(src)) { #region link element var linkElement = new XElement("link", new XAttribute("type", "text/css"), new XAttribute("rel", "stylesheet")); var formattedSrc = src; if (!src.StartsWith("http")) { if (src.StartsWith("~")) formattedSrc = Url.Content(src); else formattedSrc = Url.Content(pkg.ResolveUri(src)); } linkElement.Add(new XAttribute("href", formattedSrc)); w.Write(linkElement.OuterXml()); #endregion } else { w.Write("<style type=\"text/css\" >"); var csstext = string.IsNullOrEmpty(style.Value) ? style.InnerXml() : style.Value; if (!string.IsNullOrEmpty(csstext)) w.Write(csstext); w.Write("</style>"); } } } } }
/// <summary> /// Render an items tree by specified item query result. /// </summary> /// <param name="items">The item query result.</param> /// <param name="currentPath">The current data item path.</param> /// <param name="htmlAttributes">The html attributes for treeview element.</param> /// <param name="dynamicLoad">Specified the tree node load on demand.</param> /// <returns></returns> public static HelperResult Tree(ContentQueryResult items, string currentPath = "", object htmlAttributes = null, bool dynamicLoad = true) { return new HelperResult((w) => { var root = new XElement("ul", new XAttribute("data-role", "tree")); root.AddHtmlAttributes(htmlAttributes); AddChildren(root, items, items.View, currentPath); w.Write(root.OuterXml()); }); }
/// <summary> /// Render HTML pager element for specified content query result. /// </summary> /// <param name="html">The html helper object.</param> /// <param name="model"></param> /// <param name="htmlAttributes">The html attributes object for the output html element.</param> /// <returns></returns> public static HelperResult Pager(this HtmlHelper html, ContentQueryResult model, object htmlAttributes = null) { return new HelperResult(writer => { var Url = new UrlHelper(html.ViewContext.RequestContext); if (model.View.AllowPaging) { var maxPageCount = 10; var curIndex = model.Query.Index; var startIndex = 1; var endIndex = maxPageCount * startIndex; var curPage = (int)Math.Ceiling((decimal)((decimal)curIndex / (decimal)maxPageCount)); if (curPage > 1) startIndex = (curPage * maxPageCount) - maxPageCount + 1; endIndex = startIndex + maxPageCount; if (endIndex > model.Query.TotalPages) endIndex = model.Query.TotalPages; var _params = new List<string>(); var queryString = html.ViewContext.RequestContext.HttpContext.Request.QueryString; if (queryString != null) { foreach (var key in queryString.AllKeys) { if (key.Equals("index", StringComparison.OrdinalIgnoreCase) || key.Equals("size", StringComparison.OrdinalIgnoreCase)) continue; _params.Add(string.Format("{0}={1}", key, queryString[key])); } } if (model.Query.TotalPages <=1) return; var isLast = curPage * maxPageCount >= model.Query.TotalPages; var isFirst = startIndex == 1; var builder = new UriBuilder(); if (isLast) endIndex++; var pageElement = new XElement("div", new XAttribute("data-role", "pager"), new XAttribute("data-index", curIndex - 1)); pageElement.AddHtmlAttributes(htmlAttributes); if (!isFirst) { pageElement.Add( new XElement("a", new XAttribute("href", Url.BuildUrl(model.View.Url, _params)), new XAttribute("title", "Go to first page"), new XAttribute("class", "d-ui-widget d-button"), new XElement("span", new XAttribute("class", "d-icon d-icon-first"))), new XElement("a", new XAttribute("href", Url.Content(model.View.Url) + "?index=" + (curIndex - 1).ToString() + "&size=" + model.Query.Size + (_params.Count > 0 ? ("&" + string.Join("&", _params.ToArray())) : "")), new XAttribute("title", "Go to prev page"), new XAttribute("class", "d-ui-widget d-button"), new XElement("span", new XAttribute("class", "d-icon d-icon-prev"))) ); } for (int i = startIndex; i < endIndex; i++) { var pagerItem = new XElement("a", i != curIndex ? i : curIndex); //if (i == curIndex) // pagerItem.Add(new XAttribute("class", "d-ui-widget d-button d-state-active")); //else pagerItem.Add(new XAttribute("class", "d-ui-widget d-button")); if (i != curIndex) pagerItem.Add(new XAttribute("href", Url.Content(model.View.Url) + "?index=" + i.ToString() + "&size=" + model.Query.Size + (_params.Count > 0 ? ("&" + string.Join("&", _params.ToArray())) : ""))); pageElement.Add(pagerItem); } if (!isLast) { pageElement.Add( new XElement("a", new XAttribute("href", Url.Content(model.View.Url) + "?index=" + (curIndex + 1).ToString() + "&size=" + model.Query.Size + (_params.Count > 0 ? ("&" + string.Join("&", _params.ToArray())) : "")), new XAttribute("title", "Go to next page"), new XAttribute("class", "d-ui-widget d-button"), new XElement("span", new XAttribute("class", "d-icon d-icon-next"))), new XElement("a", new XAttribute("href", Url.Content(model.View.Url) + "?index=" + (model.Query.TotalPages).ToString() + "&size=" + model.Query.Size + (_params.Count > 0 ? ("&" + string.Join("&", _params.ToArray())) : "")), new XAttribute("title", "Go to last page"), new XAttribute("class", "d-ui-widget d-button"), new XElement("span", new XAttribute("class", "d-icon d-icon-last"))) ); } writer.Write(pageElement.OuterXml()); } }); }
public ActionResult EditCss(string name, string slug, string csstext) { var view = Find(name, slug); ViewBag.CssText = csstext; if (!string.IsNullOrEmpty(csstext)) { var root = new XElement("styles"); root.Add(new XElement("styleSheet", new XCData(Server.HtmlDecode(csstext)))); view.StyleSheetsXml = root.OuterXml(); } else { view.StyleSheetsXml = ""; } view.Save(); return PartialView(view); }
public override void RenderContent(HtmlTextWriter writer) { var descroptor = Model.WidgetDescriptor; if (Model.ShowHeader) { writer.WriteBeginTag("div"); if (!string.IsNullOrEmpty(Model.HeaderClass)) writer.WriteAttribute("class", "d-ui-widget-header d-h3 d-widget-header" + Model.HeaderClass); else writer.WriteAttribute("class", "d-ui-widget-header d-h3 d-widget-header"); if (!string.IsNullOrEmpty(Model.HeaderCssText)) writer.WriteAttribute("style", Model.HeaderCssText); writer.Write(HtmlTextWriter.TagRightChar); writer.WriteBeginTag("a"); writer.WriteAttribute("class", "d-link d-widget-title-link"); if (!string.IsNullOrEmpty(Model.Link)) { //writer.WriteAttribute("itemprop", "url"); writer.WriteAttribute("href", Url.Content(Model.Link)); } else writer.WriteAttribute("href", "javascript:void(0);"); writer.Write(HtmlTextWriter.TagRightChar); if (!string.IsNullOrEmpty(Model.IconUrl)) { if (Model.IconUrl.StartsWith("d-icon-")) { writer.WriteBeginTag("span"); writer.WriteAttribute("class", "d-widget-icon"); writer.WriteAttribute("data-icon", Model.IconUrl); writer.WriteAttribute("title", GE.GetContent(Model.Title)); writer.Write(HtmlTextWriter.TagRightChar); writer.WriteEndTag("span"); } else { writer.WriteBeginTag("img"); writer.WriteAttribute("class", "d-widget-icon"); writer.WriteAttribute("src", Url.Content(Model.IconUrl)); writer.WriteAttribute("alt", GE.GetContent(Model.Title)); writer.Write(HtmlTextWriter.SelfClosingTagEnd); } } writer.WriteBeginTag("span"); writer.WriteAttribute("class", "d-widget-title-text"); writer.Write(HtmlTextWriter.TagRightChar); writer.Write(GE.GetContent(Model.Title)); writer.WriteEndTag("span"); writer.WriteEndTag("a"); writer.WriteEndTag("div"); } writer.WriteBeginTag("div"); if (!string.IsNullOrEmpty(Model.BodyClass)) writer.WriteAttribute("class", "d-ui-widget-body d-content d-widget-body " + Model.BodyClass); else writer.WriteAttribute("class", "d-ui-widget-body d-content d-widget-body"); if (!string.IsNullOrEmpty(Model.BodyCssText)) writer.WriteAttribute("style", Model.BodyCssText); //else //{ // if (descroptor.Height > 0) // writer.WriteAttribute("style", "height:" + descroptor.Height.ToString()+"px"); //} writer.Write(HtmlTextWriter.TagRightChar); try { if (!string.IsNullOrEmpty(descroptor.Controller) && !string.IsNullOrEmpty(descroptor.Action)) { if (string.IsNullOrEmpty(descroptor.Area)) Html.RenderAction(descroptor.Action, descroptor.Controller, new { Area = "", id = Model.ID.ToString() }); else Html.RenderAction(descroptor.Action, descroptor.Controller, new { Area = descroptor.Area, id = Model.ID.ToString() }); } else { Html.RenderAction("Generic", "Widget", new { Area = "", id = Model.ID.ToString() }); } } catch (Exception e) { var errList = new StringBuilder(); var internalErr = e; errList.AppendLine(descroptor.Name + " - "); var i = 1; while (internalErr != null) { errList.AppendLine(i + "." + internalErr.Message); internalErr = internalErr.InnerException; i++; } var defaultEmail = string.IsNullOrEmpty(descroptor.AuthorEmail) ? "*****@*****.**" : descroptor.AuthorEmail; var errEle = new XElement("p", new XAttribute("class", "warn"), new XElement("strong", descroptor.Name + " runtime error."), new XElement("span", "Please ")); var contactEle = new XElement("a", "Send report"); contactEle.Add(new XAttribute("href", "mailto:" + defaultEmail + "?subject=Widget error report&body=" + errList.ToString())); errEle.Add(contactEle); errEle.Add(new XElement("span", " to author in order to fixed this bug.")); //errEle.Add(new XElement("span", new XAttribute("class", "d-icon-plus-2"), //new XAttribute("style","font-size:1.2em;float:right;"),new XAttribute("onclick","$(this).next().toggle();"))); //errEle.Add(new XElement("span", errList.ToString(), new XAttribute("style", "display:none;float:none;"))); ///TODO: Show the detail error in debug mode. writer.Write(errEle.OuterXml()); } writer.WriteEndTag("div"); }
public virtual void Load(XElement element, string locale) { var ns = element.GetDefaultNamespace(); this.IsAjax = element.BoolAttr(AJAX); this.FormType = (int)((ContentFormTypes)Enum.Parse(typeof(ContentFormTypes), element.StrAttr(TYPE))); this.Roles = element.StrAttr(DataNames.AccessRoles); //this.CaptionField = element.StrAttr(CAPTION_FIELD); //this.HideCaption = element.BoolAttr(HIDE_CAP); //this.ShowAuthor = element.BoolAttr(SHOW_AUTHOR); this.NoPage = element.BoolAttr(NOPAGE); var title = element.ElementWithLocale(ns + DataNames.Title, locale); var desc = element.ElementWithLocale(ns + DataNames.Description, locale); var tmpl = element.ElementWithLocale(ns + DataNames.Body, locale); //if (element.Attribute(ANONYMOUS) != null) this.AllowAnonymous = element.BoolAttr(ANONYMOUS); //else //this.AllowAnonymous = true; if (title==null) title=element.ElementWithLocale(ns + DataNames.Title, ""); if (desc==null) desc=element.ElementWithLocale(ns + DataNames.Description, ""); if (tmpl==null) tmpl = element.ElementWithLocale(ns + DataNames.Body, ""); if (title != null) this.Title = title.Value; if (desc != null) this.Description = desc.Value; var fieldsEle = element.Element(ns + "fields"); if (fieldsEle != null) FieldsXml = fieldsEle.OuterXml(); //string.Format("<fields>{0}</fields>", fieldsEle.InnerXml()); if (tmpl != null) this.BodyTemplateXml = tmpl.OuterXml(); #region style and scripts var scripts = element.ElementsWithLocale(ns + SCRIPT, locale); var styles = element.ElementsWithLocale(ns + STYLE_SHEET, locale); if (scripts == null || (scripts != null && scripts.Count() == 0)) scripts = element.ElementsWithLocale(ns + SCRIPT, ""); if (styles == null || (styles != null && styles.Count() == 0)) styles = element.ElementsWithLocale(ns + STYLE_SHEET, ""); if (scripts!=null && scripts.Count() > 0) { var scriptEl = new XElement("scripts", scripts); this.ScriptsXml = scriptEl.OuterXml(); } if (styles!=null && styles.Count() > 0) { var styleEl = new XElement("styles", styles); this.StyleSheetsXml = styleEl.OuterXml(); } #endregion }
public virtual void SaveFields(IEnumerable<ContentField> fields) { XNamespace ns = DefaultNamespace; var fieldsElement = new XElement(ns + "fields", new XAttribute("xmlns", DefaultNamespace)); foreach (var f in fields) fieldsElement.Add(f.Element()); FieldsXml = fieldsElement.OuterXml(); }
public virtual void Load(XElement element, string locale = "") { this.EnableVersioning = element.BoolAttr(VERSIONING); this.AllowComments = element.BoolAttr(ALLOW_COMMENTS); this.AllowAttachments = element.BoolAttr(ALLOW_ATTACHS); this.AllowVotes = element.BoolAttr(ALLOW_VOTES); this.AllowResharing = element.BoolAttr(ALLOW_RESHARING); this.AllowCategoriesAndTags = element.BoolAttr(ALLOW_CATE_TAGS); this.IsHierarchy = element.BoolAttr(HIERARCHY); this.IsModerated = element.BoolAttr(MODERATED); this.IsSingle = element.BoolAttr(SINGLE); this.IsSystem = element.BoolAttr(SYS); this.ItemType = element.StrAttr("itemtype"); this.UID = element.StrAttr("id"); this.Version = element.StrAttr("version"); if (string.IsNullOrEmpty(Version)) this.Version = "1.0.0"; this.Master = element.StrAttr("master"); this.IsActivity = element.BoolAttr(ACTIVITY); var ns = element.GetDefaultNamespace(); var defaultLocale = element.StrAttr(DEFAULT_LOCALE); var targetLocale = locale.Equals(defaultLocale, StringComparison.OrdinalIgnoreCase) ? "" : locale; var title = element.ElementWithLocale(ns + TITLE, targetLocale); var desc = element.ElementWithLocale(ns + DESC, targetLocale); this.Locale = targetLocale; if (string.IsNullOrEmpty(targetLocale)) { if (string.IsNullOrEmpty(this.Locale)) this.Locale = "en-US"; string baseType = element.StrAttr(BASE); if (string.IsNullOrEmpty(baseType)) { this.BaseType = element.StrAttr(NAME); } else { this.Name = element.StrAttr(NAME); this.BaseType = element.StrAttr(BASE); } } if (title == null) title = element.ElementWithLocale(ns + TITLE, ""); if (desc == null) desc = element.ElementWithLocale(ns + DESC, ""); if (title != null) this.Title = title.Value; if (desc != null) this.Description = desc.Value; var factory = new DNA.Web.Contents.ContentFieldFactory(); var fields = element.Elements(ns + FIELDS) .Elements(ns + FIELD) .Select(f => { var field = factory.Create(f, targetLocale); field.Parent = this; return field; }); var fieldElements = new XElement(FIELDS, new XAttribute("xmlns", DefaultNamespace), fields.Select(f => f.Element())); this.FieldsXml = fieldElements.OuterXml(); //this.FieldsXml = element.Element(ns + FIELDS).OuterXml(); //Views var viewElements = element.Descendants(ns + "view"); this.Views = new List<ContentView>(); foreach (var viewEle in viewElements) { var v = new ContentView() { Parent = this }; v.Load(viewEle, targetLocale); this.Views.Add(v); } //Forms this.Forms = new List<ContentForm>(); var formElements = element.Descendants(ns + "form"); this.Forms = new List<ContentForm>(); foreach (var formEle in formElements) { var f = new ContentForm() { Parent = this }; f.Load(formEle, targetLocale); this.Forms.Add(f); } //Items this.Items = new List<ContentDataItem>(); var itemEles = element.Descendants(ns + "row"); this.Items = new List<ContentDataItem>(); foreach (var row in itemEles) { var r = new ContentDataItem() { Parent = this, Locale = this.Locale }; r.Load(row); this.Items.Add(r); } }