Ejemplo n.º 1
0
 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");
             }
         }
     });
 }
Ejemplo n.º 2
0
        public static string Pager(this HtmlHelper htmlHelper, IPagination pagination, string actionName, string controllerName, RouteValueDictionary routeValues)
        {
            routeValues = routeValues ?? new RouteValueDictionary();
            var routeValueDictionary = new RouteValueDictionary(routeValues);
            if(!routeValueDictionary.ContainsKey("page"))
                routeValueDictionary.Add("page", 0);

            if(!routeValueDictionary.ContainsKey("controller"))
                routeValueDictionary.Add("controller", controllerName);

            int min = Math.Max(pagination.PageNumber - 2, 1);
            int max = Math.Min(pagination.PageNumber + 2, pagination.TotalPages);

            int startPage = Math.Min(min, 1);
            int endPage = Math.Max(max, pagination.TotalPages);
            int currentPage = pagination.PageNumber;

            var sb = new StringBuilder();
            var sw = new StringWriter(sb, System.Globalization.CultureInfo.InvariantCulture);
            var hw = new Html32TextWriter(sw, "    ");

            hw.WriteFullBeginTag("ul");

            if (pagination.HasPreviousPage)
            {
                hw.WriteLine();
                hw.WriteFullBeginTag("li");
                routeValueDictionary["page"] = currentPage - 1;
                hw.Write(htmlHelper.ActionLink("prev", actionName, routeValueDictionary,
                                               new Dictionary<string, object> {{"class", "previous"}}));
                hw.WriteEndTag("li");
            }

            if(min != startPage)
            {
                hw.WriteLine();
                hw.WriteFullBeginTag("li");
                routeValueDictionary["page"] = startPage;
                hw.Write(htmlHelper.ActionLink(startPage.ToInvariantString(), actionName, routeValueDictionary));
                hw.WriteEndTag("li");

                if (min - startPage > 1)
                {
                    hw.WriteFullBeginTag("li");
                    hw.Write("...");
                    hw.WriteEndTag("li");
                }
            }

            for (var i = min; i <= max; i++)
            {
                hw.WriteLine();
                hw.WriteFullBeginTag("li");
                routeValueDictionary["page"] = i;
                if (i == currentPage)
                {
                    hw.WriteFullBeginTag("span");
                    hw.Write(i.ToInvariantString());
                    hw.WriteEndTag("span");
                }
                else
                    hw.Write(htmlHelper.ActionLink(i.ToInvariantString(), actionName, routeValueDictionary));

                hw.WriteEndTag("li");
            }

            if(max != endPage)
            {
                if (endPage - max > 1)
                {
                    hw.WriteLine();
                    hw.WriteFullBeginTag("li");
                    hw.Write("...");
                    hw.WriteEndTag("li");
                }

                hw.WriteLine();
                hw.WriteFullBeginTag("li");
                routeValueDictionary["page"] = endPage;
                hw.Write(htmlHelper.ActionLink(endPage.ToInvariantString(), actionName, routeValueDictionary));
                hw.WriteEndTag("li");
            }

            if(pagination.HasNextPage)
            {
                hw.WriteLine();
                hw.WriteFullBeginTag("li");
                routeValueDictionary["page"] = currentPage + 1;
                hw.Write(htmlHelper.ActionLink("next", actionName, routeValueDictionary,
                                               new Dictionary<string, object> {{"class", "next"}}));
                hw.WriteEndTag("li");
            }

            hw.WriteLine();
            hw.WriteEndTag("ul");
            return sb.ToString();

            //StringBuilder sb1 = new StringBuilder();

            //int seed = pagination.PageNumber % pagination.PageSize == 0 ? pagination.PageNumber : pagination.PageNumber - (pagination.PageNumber % pagination.PageSize);

            //if (pagination.PageNumber > 1)
            //    sb1.AppendLine(htmlHelper.ActionLink("prev", "index", controllerName, new { page = pagination.PageNumber }));// String.Format("<a href=\"{0}/{1}\">Previous</a>", urlPrefix, pagination.PageNumber));

            //if (pagination.PageNumber - pagination.PageSize >= 1)
            //{
            //    var pageNumber = (pagination.PageNumber - pagination.PageSize) + 1)
            //    sb1.AppendLine(htmlHelper.ActionLink("...", "index", controllerName, new {page = pageNumber}));
            //}
            //for (int i = seed; i < Math.Round((pagination.TotalItems / 10) + 0.5) && i < seed + pagination.PageSize; i++)
            //{
            //    //sb1.AppendLine(htmlHelper.ActionLink("{0}".ToFormat(i + 1)) String.Format("<a href=\"{0}/{1}\">{1}</a>", urlPrefix, i + 1));
            //}

            //if (pagination.PageNumber + pagination.PageSize <= (Math.Round((pagination.TotalItems / 10) + 0.5) - 1))
            //    sb1.AppendLine(String.Format("<a href=\"{0}/{1}\">...</a>", urlPrefix, (pagination.PageNumber + pagination.PageSize) + 1));

            //if (currentPage < (Math.Round((pagination.TotalItems / 10) + 0.5) - 1))
            //    sb1.AppendLine(String.Format("<a href=\"{0}/{1}\">Next</a>", urlPrefix, pagination.PageNumber + 2));

            //return sb1.ToString();

            //var pagesToDisplay = 5;

            //var sb = new StringBuilder();
            //var textWriter = new StringWriter(sb);
            //var builder = new HtmlTextWriter(textWriter);

            ////opening ul tag
            //builder.RenderBeginTag("ul");

            ////prev tag
            //builder.RenderBeginTag("li");
            //if (pagination.HasPreviousPage)
            //    builder.Write(urlHelper.ActionLink("prev", actionName, new{id = pagination.PageNumber - 1}));
            //else
            //    builder.WriteEncodedUrl("prev");
            //builder.RenderEndTag();

            ////R
            //builder.RenderBeginTag("li");
            //if(pag)

            ////next tag
            //builder.RenderBeginTag("li");
            //if (pagination.HasPreviousPage)
            //    builder.Write(urlHelper.ActionLink("next", actionName, new { id = pagination.LastItem }));
            //else
            //    builder.WriteEncodedUrl("next");
            //builder.RenderEndTag();

            ////close ul tag
            //builder.RenderEndTag();
            //return sb.ToString();
        }
Ejemplo n.º 3
0
 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");
             }
         }
     });
 }
Ejemplo n.º 4
0
        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");
                }
            });
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Render html element for specified field object.
        /// </summary>
        /// <param name="html">The html helper object.</param>
        /// <param name="field">The field object</param>
        /// <returns></returns>
        public static HelperResult Label(this HtmlHelper html, ContentField field)
        {
            return new HelperResult((w) =>
            {
                using (var writer = new Html32TextWriter(w))
                {
                    try
                    {
                        writer.WriteBeginTag("label");
                        writer.WriteAttribute("for", field.ClientID);
                        writer.Write(HtmlTextWriter.TagRightChar);
                        if (!string.IsNullOrEmpty(field.Title))
                            writer.WriteEncodedText(field.Title);
                        else
                            writer.WriteEncodedText(field.Name);
                        writer.WriteEndTag("label");
                    }
                    catch
                    {

                    }
                }
            });
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Render hidden input element for field value.
 /// </summary>
 /// <param name="html">The html helper object.</param>
 /// <param name="field">The field object</param>
 /// <param name="value">the field value</param>
 /// <returns></returns>
 public static HelperResult Hidden(this HtmlHelper html, ContentField field, object value = null)
 {
     return new HelperResult((w) =>
     {
         using (var writer = new Html32TextWriter(w))
         {
             writer.WriteBeginTag("input");
             writer.WriteAttribute("type", "hidden");
             writer.WriteAttribute("id", field.ClientID);
             writer.WriteAttribute("name", field.Name);
             if (value != null)
             {
                 writer.WriteAttribute("value", value.ToString());
             }
             else
             {
                 if (field.DefaultValue != null)
                     writer.WriteAttribute("value", field.DefaultValue.ToString());
             }
             writer.Write(HtmlTextWriter.SelfClosingTagEnd);
         }
     });
 }
Ejemplo n.º 7
0
        private static void RenderChildren(Html32TextWriter writer, ContentListDecorator list, IEnumerable<ContentDataItem> items, ContentDataItem current)
        {
            var app = App.Get();
            var fieldName = list.GetDefaultTitleField().Name;
            var Url = DNA.Utility.UrlUtility.CreateUrlHelper();
            foreach (var item in items)
            {
                var itemWrapper = app.Wrap(item);
                writer.WriteBeginTag("li");
                var _class = "d-node";
                var children = itemWrapper.Children();
                var childrenCount = children.Count();
                if (childrenCount > 0)
                    _class += " d-node-hasChildren";

                //writer.WriteAttribute("class", "d-node d-node-hasChildren");

                var isInPath = false;
                if (current != null && !string.IsNullOrEmpty(current.Path) && !string.IsNullOrEmpty(item.Path) && current.Path.StartsWith(item.Path))
                {
                    isInPath = true;
                    if (childrenCount > 0)
                        writer.WriteAttribute("data-expanded", "true");

                }
                writer.WriteAttribute("data-id", itemWrapper.ID.ToString());

                if (current != null && itemWrapper.ID.Equals(current.ID))
                    writer.WriteAttribute("data-selected", "true");

                if (itemWrapper.ParentItemID != Guid.Empty)
                    writer.WriteAttribute("data-parentid", itemWrapper.ParentItemID.ToString());

                if (childrenCount > 0)
                {
                    if (!isInPath)
                    {
                        var urlformat = "~/api/contents/items?name={0}&slug={1}&parentId={2}";
                        var popupUrl = Url.Content(string.Format(urlformat, list.Name, list.Views.Default.Name, itemWrapper.ID.ToString()));
                        writer.WriteAttribute("data-popupurl", popupUrl);
                    }
                }
                writer.WriteAttribute("class", _class);
                writer.Write(Html32TextWriter.TagRightChar);

                writer.WriteBeginTag("a");
                writer.WriteAttribute("href", itemWrapper.UrlComponent);
                writer.Write(Html32TextWriter.TagRightChar);
                writer.Write(itemWrapper.Value(fieldName).Raw);
                writer.WriteEndTag("a");

                if (childrenCount > 0)
                {
                    if (isInPath)
                    {
                        writer.WriteFullBeginTag("ul");
                        RenderChildren(writer, list, children, current);
                        writer.WriteEndTag("ul");
                    }
                }

                writer.WriteEndTag("li");
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Writes the header of the webpage. The header contains references to bootstrap, a favoicon and some stylefile.
 /// </summary>
 /// <param name='htw'>
 /// A <see cref="Html32TextWriter"/> to write the content to.
 /// </param>
 private void WriteHeader(Html32TextWriter htw)
 {
     htw.RenderBeginTag (HtmlTextWriterTag.Title);
     {
         htw.Write (this.device.Navigationbar.Name);
     }
     htw.RenderEndTag ();
     htw.AddAttribute (HtmlTextWriterAttribute.Name, "generator");
     htw.AddAttribute (HtmlTextWriterAttribute.Content, ProgramManager.ProgramNameVersion);
     htw.RenderBeginTag (HtmlTextWriterTag.Meta);
     {}
     htw.RenderEndTag ();
     htw.WriteLine ();
     htw.AddAttribute (HtmlTextWriterAttribute.Name, "viewport");
     htw.AddAttribute (HtmlTextWriterAttribute.Content, "width=device-width, initial-scale=1.0");
     htw.RenderBeginTag (HtmlTextWriterTag.Meta);
     {}
     htw.RenderEndTag ();
     htw.WriteLine ();
     htw.AddAttribute (HtmlTextWriterAttribute.Href, "http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css");
     htw.AddAttribute (HtmlTextWriterAttribute.Rel, "stylesheet");
     htw.RenderBeginTag (HtmlTextWriterTag.Link);
     {}
     htw.RenderEndTag ();
     htw.WriteLine ();
     htw.AddAttribute (HtmlTextWriterAttribute.Href, IconName);
     htw.AddAttribute (HtmlTextWriterAttribute.Rel, "icon");
     htw.AddAttribute (HtmlTextWriterAttribute.Type, "image/x-icon");
     htw.RenderBeginTag (HtmlTextWriterTag.Link);
     {}
     htw.RenderEndTag ();
     htw.WriteLine ();
     htw.RenderBeginTag (HtmlTextWriterTag.Style);
     {
         htw.Write ("body {min-height: 2000px;padding-top: 70px;}");
     }
     htw.RenderEndTag ();
     htw.AddAttribute ("language", "javascript");
     htw.RenderBeginTag (HtmlTextWriterTag.Script);
     {
         htw.WriteLine ("function genericAjax (source, target) {");
         htw.WriteLine ("    var xmlhttp;");
         htw.WriteLine ("    if (window.XMLHttpRequest) {");
         htw.WriteLine ("        xmlhttp=new XMLHttpRequest();");
         htw.WriteLine ("    } else {");
         htw.WriteLine ("        xmlhttp=new ActiveXObject(\"Microsoft.XMLHTTP\");");
         htw.WriteLine ("    }");
         htw.WriteLine ("    xmlhttp.onreadystatechange=function() {");
         htw.WriteLine ("        if (xmlhttp.readyState==4) {");
         htw.WriteLine ("            if(xmlhttp.status==200) {");
         htw.WriteLine ("                document.getElementById(target).innerHTML=xmlhttp.responseText;");
         htw.WriteLine ("            } else {");
         htw.WriteLine ("                document.getElementById(target).innerHTML=\"<div class='alert alert-warning'><strong>Warning:</strong> something went wrong during an AJAX call. Error code: \"+xmlhttp.status+\", Source: \"+source+\".</div>\";");
         htw.WriteLine ("            }");
         htw.WriteLine ("        }");
         htw.WriteLine ("    }");
         htw.WriteLine ("    xmlhttp.open(\"GET\",source,true);");
         htw.WriteLine ("    xmlhttp.send();");
         htw.WriteLine ("}");
     }
     htw.RenderEndTag ();
     htw.WriteLine ();
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Render validation HTML elements for specified field object.
 /// </summary>
 /// <param name="html">The html helper object.</param>
 /// <param name="field">The field object.</param>
 /// <returns></returns>
 public static HelperResult ValidationMessage(this HtmlHelper html, ContentField field)
 {
     return new HelperResult((w) =>
     {
         using (var writer = new Html32TextWriter(w))
         {
             writer.WriteBeginTag("span");
             writer.WriteAttribute("class", "d-field-val-msg d-valmsg");
             writer.WriteAttribute("data-valmsg-for", field.Name);
             writer.WriteAttribute("data-valmsg-replace", "true");
             writer.Write(HtmlTextWriter.TagRightChar);
             //writer.WriteEncodedText(field.Description);
             writer.WriteEndTag("span");
         }
     });
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Render the tags element for specified data item.
 /// </summary>
 /// <param name="helper">The html helper object.</param>
 /// <param name="dataItem">The data item instance.</param>
 /// <returns></returns>
 public static HelperResult Tags(this HtmlHelper helper, ContentDataItem dataItem)
 {
     return new HelperResult((w) =>
     {
         using (var writer = new Html32TextWriter(w))
         {
             if (!string.IsNullOrEmpty(dataItem.Tags))
             {
                 writer.WriteBeginTag("input");
                 writer.WriteAttribute("data-role", "tags");
                 writer.WriteAttribute("readonly", "readonly");
                 writer.WriteAttribute("value", dataItem.Tags);
                 writer.Write(Html32TextWriter.SelfClosingTagEnd);
             }
         }
     });
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Render the empty view html to response ouput.
        /// </summary>
        /// <param name="view">The view object.</param>
        /// <returns></returns>
        public static HelperResult RenderEmptyPattern(this ContentViewDecorator view)
        {
            return new HelperResult(w =>
               {
               using (var writer = new Html32TextWriter(w))
               {
                   var url = new UrlHelper(HttpContext.Current.Request.RequestContext);
                   var emptyDocument = new XmlDocument();
                   if (!string.IsNullOrEmpty(view.EmptyTemplateXml))
                       emptyDocument.LoadXml(view.EmptyTemplateXml);
                   else
                   {
                       writer.Write("<div style=\"line-height:50px;text-align:center;\" class=\"d-title\">No item found</div>");
                       return;
                   }

                   var emptyNode = emptyDocument.DocumentElement;
                   var contentType = emptyNode.Attributes["contentType"] != null ? emptyNode.Attributes["contentType"].Value : "text/xml";

                   if (contentType == "text/html")
                   {
                       var contentText = emptyNode.InnerText;
                       if (!string.IsNullOrEmpty(contentText))
                       {
                           writer.Write(contentText);
                       }
                       return;
                   }

                   if (contentType == "application/x-ms-aspnet")
                   {
                       return;
                   }

                   if (contentType == "text/xml")
                   {
                       var nodes = emptyNode.ChildNodes;
                       for (int i = 0; i < nodes.Count; i++)
                       {
                           var node = nodes[i];
                           if (node.Name == "url")
                           {
                               var type = node.Attributes["type"] != null && !string.IsNullOrEmpty(node.Attributes["type"].Value) ? node.Attributes["type"].Value : "new";

                               if (type == "new")
                                   writer.Write(url.Content(view.Parent.GetNewItemUrl()));
                               if (type == "request")
                                   writer.Write(HttpContext.Current.Request.Url.ToString());
                               continue;
                           }

                           if (node.Name == "html")
                           {
                               writer.Write(node.InnerText);
                               continue;
                           }
                       }
                   }
               }
               });
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Render field description text for specified field object.
 /// </summary>
 /// <param name="html">The html helper object.</param>
 /// <param name="field">The field object.</param>
 /// <returns></returns>
 public static HelperResult Notes(this HtmlHelper html, ContentField field)
 {
     return new HelperResult((w) =>
     {
         using (var writer = new Html32TextWriter(w))
         {
             if (!string.IsNullOrEmpty(field.Description))
             {
                 writer.WriteBeginTag("small");
                 //writer.WriteAttribute("class", "d-field-notes d-notes");
                 writer.Write(HtmlTextWriter.TagRightChar);
                 writer.WriteEncodedText(field.Description);
                 writer.WriteEndTag("small");
             }
         }
     });
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Render the widget to current response output.
        /// </summary>
        /// <param name="writer"></param>
        public override void Render(HtmlTextWriter writer)
        {
            var locale = App.Get().Context.Locale;
            if (!string.IsNullOrEmpty(locale))
                App.Get().SetCulture(locale);

            bool isPreviewMode = false;
            Dictionary<string, PropertyDescriptor> propertyDescriptors = null;
            Dictionary<string, object> userdata = new Dictionary<string, object>();

            var bag = Html.ViewContext.Controller.ViewBag;
            if (bag != null)
            {
                if (bag.PropertyDescriptors != null)
                {
                    propertyDescriptors = bag.PropertyDescriptors as Dictionary<string, PropertyDescriptor>;
                    if (propertyDescriptors != null)
                    {
                        foreach (var key in propertyDescriptors.Keys)
                            userdata.Add(key, propertyDescriptors[key].Value);
                    }
                }

                if (bag.IsPreview != null)
                    isPreviewMode = bag.IsPreview;

                Model = bag.WidgetInstance;
            }

            var widgetHelper = new WidgetHelper()
            {
                Model = Model,
                UserPreferences = userdata,
                PropertyDescriptors = propertyDescriptors
            };

            if (isPreviewMode)
            {
                if (!PreviewTemplate.IsEmpty)
                    PreviewTemplate.WriteTo(widgetHelper, writer);
                else
                {
                    if (!ContentTemplate.IsEmpty)
                        ContentTemplate.WriteTo(widgetHelper, writer);
                }
            }
            else
            {
                if (IsDesignMode)
                {
                    if (userdata.Count > 0 && this.Model.WidgetDescriptor.WidgetType==1)
                    {
                        var urlhelper = new UrlHelper(Request.RequestContext);

                        writer.WriteBeginTag("form");
                        writer.WriteAttribute("class", "d-widget-prefs d-tran-fast d-form");
                        writer.WriteAttribute("data-ajax", "true");
                        writer.WriteAttribute("data-ajax-url", urlhelper.Content("~/api/" + AppModel.Get().Context.Website + "/widgets/apply"));
                        writer.WriteAttribute("data-ajax-method", "post");
                        //writer.WriteAttribute("data-ajax-begin", "$.loading()");
                        writer.WriteAttribute("data-ajax-success", "$('#widget_" + this.Model.ID.ToString() + "').widget('refresh');" + (AutoSave ? "" : "$.closePanels();"));
                        if (this.HideUserPreferences)
                            writer.WriteAttribute("data-hidden", "true");

                        if (this.AutoSave)
                        {
                            writer.WriteAttribute("data-auto-save", "true");
                            writer.WriteAttribute("onchange", "$(this).submit();");
                        }

                        //    writer.WriteAttribute("data-allow-pop", "false");

                        writer.Write(HtmlTextWriter.TagRightChar);

                        writer.WriteBeginTag("input");
                        writer.WriteAttribute("type", "hidden");
                        writer.WriteAttribute("name", "id");
                        writer.WriteAttribute("value", Model.ID.ToString());
                        writer.Write(HtmlTextWriter.SelfClosingTagEnd);

                        if (!UserPreferencesTemplate.IsEmpty)
                        {
                            UserPreferencesTemplate.WriteTo(widgetHelper, writer);
                        }
                        else
                        {
                            foreach (var key in propertyDescriptors.Keys)
                            {
                                if (!propertyDescriptors[key].IsReadonly)
                                    RenderPropertyControl(writer, widgetHelper, propertyDescriptors[key]);
                            }
                        }

                        writer.WriteEndTag("form");

                    }

                    if (!DesignTemplate.IsEmpty)
                        DesignTemplate.WriteTo(widgetHelper, writer);
                    else
                        if (!ContentTemplate.IsEmpty)
                            ContentTemplate.WriteTo(widgetHelper, writer);
                    writer.Write("<script type=\"text/javascript\">$(function(){ $('#widget_" + this.Model.ID.ToString() + "').taoUI(); });</script>");
                    //writer.Write("<script type=\"text/javascript\">$(function(){ $('#widget_" + this.Model.ID.ToString() + "').unobtrusive_ajax().taoUI(); });</script>");
                }
                else
                {
                    if (Model.Cached)
                    {
                        //Render cachable widget eg:Html widget
                        var cachedHtml = "";
                        var cachedKey = "widget" + Model.ID.ToString() + "_caching_html";
                        if (Context.Cache[cachedKey] != null)
                        {
                            cachedHtml = Context.Cache[cachedKey].ToString();
                        }
                        else
                        {
                            var cachedBuilder = new StringBuilder();
                            using (var cachedTextWriter = new System.IO.StringWriter(cachedBuilder))
                            {
                                using (var cachedWriter = new Html32TextWriter(cachedTextWriter))
                                {
                                    if (!ContentTemplate.IsEmpty)
                                        ContentTemplate.WriteTo(widgetHelper, cachedWriter);
                                    if (!HeaderTemplate.IsEmpty && Model.ShowHeader)
                                    {
                                        cachedWriter.Write("<div id=\"widget_" + this.Model.ID.ToString() + "_header_holder\" style=\"display:none;\">");
                                        HeaderTemplate.WriteTo(widgetHelper, cachedWriter);
                                        cachedWriter.Write("</div>");
                                        cachedWriter.Write("<script type=\"text/javascript\">$(function(){ if ($('#widget_" + this.Model.ID.ToString() + "').find('.d-widget-header').length) { $('#widget_" + this.Model.ID.ToString() + "').find('.d-widget-header').empty().append($('#widget_" + this.Model.ID.ToString() + "_header_holder').children());$('#widget_" + this.Model.ID.ToString() + "_header_holder').remove(); }  });</script>");
                                    }
                                }
                            }
                            cachedHtml = cachedBuilder.ToString();
                            Context.Cache.Add(cachedKey, cachedHtml, null, DateTime.Now.AddMinutes(5), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Default, null);
                        }
                        writer.Write(cachedHtml);
                    }
                    else
                    {
                        if (!ContentTemplate.IsEmpty)
                            ContentTemplate.WriteTo(widgetHelper, writer);

                        if (!HeaderTemplate.IsEmpty && Model.ShowHeader)
                        {
                            writer.Write("<div id=\"widget_" + this.Model.ID.ToString() + "_header_holder\" style=\"display:none;\">");
                            HeaderTemplate.WriteTo(widgetHelper, writer);
                            writer.Write("</div>");
                            writer.Write("<script type=\"text/javascript\">$(function(){ if ($('#widget_" + this.Model.ID.ToString() + "').find('.d-widget-header').length) { $('#widget_" + this.Model.ID.ToString() + "').find('.d-widget-header').empty().append($('#widget_" + this.Model.ID.ToString() + "_header_holder').children());$('#widget_" + this.Model.ID.ToString() + "_header_holder').remove(); }  });</script>");
                        }
                    }
                }
            }
            //writer.Write(System.Web.Optimization.Scripts.Render("~/bundles/jqueryval"));
            //writer.Write(html.StartupScripts().ToString());
        }
Ejemplo n.º 14
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");
                }
            });
        }
Ejemplo n.º 15
0
 /// <summary>
 ///  Render the webpage onto the give specified engine. 
 /// </summary>
 /// <param name='serverFolder'>
 ///  The root of the folder of the web server. 
 /// </param>
 /// <param name='engine'>
 ///  The given specified engine. 
 /// </param>
 /// <param name='writer'>
 ///  The html writer to write content to. 
 /// </param>
 public override void Render(string serverFolder, HttpEngine engine, Html32TextWriter writer)
 {
     writer.Write (this.fragment);
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Writes a footer of every webpage to the given <see cref="Html32TextWriter"/> instance.
 /// </summary>
 /// <param name='htw'>
 /// The <see cref="Html32TextWriter"/> to write the webpage to.
 /// </param>
 private void WriteFooter(Html32TextWriter htw)
 {
     htw.RenderBeginTag (HtmlTextWriterTag.Hr);
     htw.RenderEndTag ();
     htw.AddAttribute (HtmlTextWriterAttribute.Class, "footer");
     htw.RenderBeginTag (HtmlTextWriterTag.Div);
     htw.RenderBeginTag (HtmlTextWriterTag.P);
     htw.Write ("This page is created with {0}", ProgramManager.ProgramNameVersion);
     htw.RenderEndTag ();
     htw.RenderEndTag ();
 }
Ejemplo n.º 17
0
 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");
             }
         }
     });
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Writes the navigation bar to the given <see cref="Html32TextWriter"/>.
 /// </summary>
 /// <param name='htw'>
 /// The <see cref="Html32TextWriter"/> to write the content to.
 /// </param>
 /// <param name='webpage'>
 /// The webpage that is currently displayed. This is needed to denote the current page.
 /// </param>
 private void WriteMasthead(Html32TextWriter htw, IWebPage webpage)
 {
     INavbar navbar = this.device.Navigationbar;
     htw.AddAttribute (HtmlTextWriterAttribute.Class, "navbar navbar-default navbar-fixed-top");
     htw.AddAttribute ("role", "navigation");
     htw.RenderBeginTag (HtmlTextWriterTag.Div);
     {
         htw.AddAttribute (HtmlTextWriterAttribute.Class, "container-fluid");
         htw.RenderBeginTag (HtmlTextWriterTag.Div);
         {
             htw.AddAttribute (HtmlTextWriterAttribute.Class, "navbar-header");
             htw.RenderBeginTag (HtmlTextWriterTag.Div);
             {
                 htw.AddAttribute (HtmlTextWriterAttribute.Class, "navbar-brand");
                 htw.AddAttribute (HtmlTextWriterAttribute.Href, "#");
                 htw.RenderBeginTag (HtmlTextWriterTag.A);
                 {
                     htw.Write (navbar.Name);
                 }
                 htw.RenderEndTag ();
             }
             htw.RenderEndTag ();
             htw.AddAttribute (HtmlTextWriterAttribute.Class, "navbar-collapse collapse");
             htw.RenderBeginTag (HtmlTextWriterTag.Div);
             {
                 htw.AddAttribute (HtmlTextWriterAttribute.Class, "nav navbar-nav");
                 htw.RenderBeginTag (HtmlTextWriterTag.Ul);
                 {
                     foreach (IWebPage wp in navbar.Pages) {
                         if (wp == webpage) {
                             htw.AddAttribute (HtmlTextWriterAttribute.Class, "active");
                         }
                         htw.RenderBeginTag (HtmlTextWriterTag.Li);
                         htw.AddAttribute (HtmlTextWriterAttribute.Href, wp.Href);
                         htw.RenderBeginTag (HtmlTextWriterTag.A);
                         htw.Write (wp.Name);
                         htw.RenderEndTag ();
                         htw.RenderEndTag ();
                     }
                 }
                 htw.RenderEndTag ();
             }
             htw.RenderEndTag ();
         }
         htw.RenderEndTag ();
     }
     htw.RenderEndTag ();
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Render the webpage onto the give specified engine.
 /// </summary>
 /// <param name="serverFolder">The root of the folder of the web server.</param>
 /// <param name="engine">The given specified engine.</param>
 /// <param name="writer">The html writer to write content to.</param>
 public override void Render(string serverFolder, HttpEngine engine, Html32TextWriter writer)
 {
     writer.AddAttribute (HtmlTextWriterAttribute.Class, "table table-hover table-condensed table-bordered");
     writer.RenderBeginTag (HtmlTextWriterTag.Table);
     {
         writer.RenderBeginTag (HtmlTextWriterTag.Thead);
         {
             writer.RenderBeginTag (HtmlTextWriterTag.Tr);
             {
                 foreach (WebPredicateTableColumn column in this.Columns) {
                     writer.RenderBeginTag (HtmlTextWriterTag.Th);
                     writer.Write (column.Name);
                     writer.RenderEndTag ();
                 }
                 writer.RenderBeginTag (HtmlTextWriterTag.Th);
                 writer.AddAttribute (HtmlTextWriterAttribute.Class, "btn-group");
                 writer.RenderBeginTag (HtmlTextWriterTag.Div);
                 {
                     writer.AddAttribute (HtmlTextWriterAttribute.Onclick, string.Format ("genericAjax (\"{0}\", \"landing{1}\");", this.Href, this.Id));
                     writer.AddAttribute (HtmlTextWriterAttribute.Class, "btn btn-info btn-xs");
                     writer.RenderBeginTag (HtmlTextWriterTag.Button);
                     writer.WriteLine ("<i class=\"glyphicon glyphicon-refresh\"></i>");
                     writer.RenderEndTag ();
                     writer.AddAttribute (HtmlTextWriterAttribute.Class, "btn btn-success btn-xs");
                     writer.RenderBeginTag (HtmlTextWriterTag.Button);
                     writer.WriteLine ("<i class=\"glyphicon glyphicon-plus\"></i>");
                     writer.RenderEndTag ();
                 }
                 writer.RenderEndTag ();
                 writer.RenderEndTag ();
             }
             writer.RenderEndTag ();
         }
         writer.RenderEndTag ();
         writer.RenderBeginTag (HtmlTextWriterTag.Tbody);
         {
             IEnumerable<int> indices = this.Columns.Select (x => x.Index).ToArray ();
             foreach (IEnumerable<object> row in this.Source) {
                 writer.WriteLine ();
                 writer.RenderBeginTag (HtmlTextWriterTag.Tr);
                 foreach (object item in row.IndicesOrdered (indices)) {
                     writer.RenderBeginTag (HtmlTextWriterTag.Td);
                     writer.Write (item);
                     writer.RenderEndTag ();
                 }
                 writer.RenderBeginTag (HtmlTextWriterTag.Td);
                 writer.AddAttribute (HtmlTextWriterAttribute.Class, "btn-group");
                 writer.RenderBeginTag (HtmlTextWriterTag.Div);
                 {
                     writer.AddAttribute (HtmlTextWriterAttribute.Onclick, string.Format ("genericAjax (\"{0}\", \"landing{1}\");", this.Href, this.Id));
                     writer.AddAttribute (HtmlTextWriterAttribute.Class, "btn btn-warning btn-xs");
                     writer.RenderBeginTag (HtmlTextWriterTag.Button);
                     writer.WriteLine ("<i class=\"glyphicon glyphicon-edit\"></i>");
                     writer.RenderEndTag ();
                     writer.AddAttribute (HtmlTextWriterAttribute.Class, "btn btn-danger btn-xs");
                     writer.RenderBeginTag (HtmlTextWriterTag.Button);
                     writer.WriteLine ("<i class=\"glyphicon glyphicon-remove\"></i>");
                     writer.RenderEndTag ();
                 }
                 writer.RenderEndTag ();
                 writer.RenderEndTag ();
                 writer.RenderEndTag ();
             }
         }
         writer.RenderEndTag ();
     }
     writer.RenderEndTag ();
 }