Exemple #1
0
        protected string RenderPageButton(string textOrUrl, string disabledTexOrUrl, int index,
                                          PageButtonStyle pageButtonStyle, PageButtonType?pageButtonType, IDictionary <string, object> htmlAttributes = null, bool encoded = true)
        {
            if (htmlAttributes == null)
            {
                htmlAttributes = new Dictionary <string, object>();
            }
            string buttonType = getPageButtonClass(pageButtonType);
            string buttonId   = fieldId + "_" + buttonType;

            if (!pageButtonType.HasValue)
            {
                if (index < 0)
                {
                    buttonId = buttonId + "_" + (-index).ToString(CultureInfo.InvariantCulture);
                }
                else
                {
                    buttonId = buttonId + index.ToString(CultureInfo.InvariantCulture);
                }
                htmlAttributes["data-pager-index"] = index.ToString(CultureInfo.InvariantCulture);
            }
            htmlAttributes["id"] = buttonId;
            htmlAttributes["data-pager-button"] = buttonType;
            BasicHtmlHelper.AddClass(htmlAttributes, fieldId + "_class");
            BasicHtmlHelper.SetDefaultStyle(htmlAttributes, "cursor", "pointer");
            switch (pageButtonStyle)
            {
            case PageButtonStyle.Button:
                htmlAttributes["type"]  = "button";
                htmlAttributes["value"] = htmlHelper.Encode(textOrUrl);
                return(string.Format(buttonSchema, BasicHtmlHelper.GetAttributesString(htmlAttributes)));

            case PageButtonStyle.Image:
                htmlAttributes["src"] = textOrUrl;
                if (disabledTexOrUrl != null)
                {
                    htmlAttributes["data-disabled-src"] = disabledTexOrUrl;
                    htmlAttributes["data-enabled-src"]  = textOrUrl;
                }
                return(string.Format(imgSchema, BasicHtmlHelper.GetAttributesString(htmlAttributes)));

            default:
                htmlAttributes["href"] = "javascript:void(0);";
                return(string.Format(linkSchema, BasicHtmlHelper.GetAttributesString(htmlAttributes), encoded ? htmlHelper.Encode(textOrUrl): textOrUrl));
            }
        }
Exemple #2
0
/*
 *      public static MvcHtmlString OnOffViewFor<M>(
 *          this HtmlHelper<M> htmlHelper,
 *          Expression<Func<M, bool>> expression,
 *          string elementId
 *          )
 *      {
 *          if (elementId == null) throw (new ArgumentNullException("elementId"));
 *          if (expression == null) throw (new ArgumentNullException("expression"));
 *
 *          string partialName = ExpressionHelper.GetExpressionText(expression);
 *          string fullId = htmlHelper.ViewData.TemplateInfo.GetFullHtmlFieldId(partialName);
 *
 *          bool selection = false;
 *
 *          try
 *          {
 *              selection = (bool)(expression.Compile().Invoke(htmlHelper.ViewData.Model));
 *          }
 *          catch
 *          {
 *
 *          }
 *
 *          return
 *              MvcHtmlString.Create(
 *                  htmlHelper.Hidden(partialName, selection) +
 *                  string.Format(onOffViewSelectionScript, elementId, fullId, selection));
 *
 *      }
 */
/*     public static MvcHtmlString SelectButton<VM, T>(
 *       this HtmlHelper<VM> htmlHelper,
 *       string textOrUrl,
 *       Expression<Func<VM, T>> target,
 *       string groupName,
 *       string name,
 *       ManipulationButtonStyle manipulationButtonStyle = ManipulationButtonStyle.Button,
 *       IDictionary<string, object> htmlAttributes = null)
 *   {
 *       if (target == null) throw new ArgumentNullException("target");
 *       if (textOrUrl == null) throw new ArgumentNullException("textOrUrl");
 *       if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException("name");
 *       if (string.IsNullOrWhiteSpace(groupName)) throw new ArgumentNullException("groupName");
 *       string targetName = BasicHtmlHelper.IdFromName(htmlHelper.ViewData.TemplateInfo.GetFullHtmlFieldName(
 *           ExpressionHelper.GetExpressionText(target)));
 *       return
 *           SelectionButton<VM>(
 *               htmlHelper,
 *               textOrUrl,
 *               targetName,
 *               groupName,
 *               name,
 *               manipulationButtonStyle,
 *               htmlAttributes);
 *   }*/

        public static MvcHtmlString SelectionButton <VM>(
            this HtmlHelper <VM> htmlHelper,
            string textOrUrl,
            string targetName,
            string groupName,
            string name,
            ManipulationButtonStyle manipulationButtonStyle = ManipulationButtonStyle.Button,
            IDictionary <string, object> htmlAttributes     = null)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException("name");
            }
            if (textOrUrl == null)
            {
                throw new ArgumentNullException("textOrUrl");
            }
            if (targetName == null)
            {
                throw new ArgumentNullException("targetName");
            }
            if (string.IsNullOrWhiteSpace(groupName))
            {
                throw new ArgumentNullException("groupName");
            }

            if (htmlAttributes == null)
            {
                htmlAttributes = new Dictionary <string, object>();
            }

            string buttonId = BasicHtmlHelper.IdFromName(
                BasicHtmlHelper.AddField(htmlHelper.ViewData.TemplateInfo.HtmlFieldPrefix, name));

            htmlAttributes["id"] = buttonId;
            BasicHtmlHelper.AddClass(htmlAttributes, groupName + "_button");
            BasicHtmlHelper.AddClass(htmlAttributes, htmlHelper.PrefixedId(targetName) + "_button");
            switch (manipulationButtonStyle)
            {
            case ManipulationButtonStyle.Button:
                htmlAttributes["type"]  = "button";
                htmlAttributes["value"] = htmlHelper.Encode(textOrUrl);
                return(MvcHtmlString.Create(
                           string.Format(buttonSchema,
                                         BasicHtmlHelper.GetAttributesString(htmlAttributes),
                                         groupName,
                                         targetName,
                                         buttonId)));

            case ManipulationButtonStyle.Link:
                htmlAttributes["href"] = "javascript:void(0);";
                return(MvcHtmlString.Create(
                           string.Format(linkSchema,
                                         BasicHtmlHelper.GetAttributesString(htmlAttributes),
                                         groupName,
                                         targetName,
                                         buttonId,
                                         htmlHelper.Encode(textOrUrl))));

            default:
                htmlAttributes["src"] = textOrUrl;
                BasicHtmlHelper.SetDefaultStyle(htmlAttributes, "cursor", "pointer");
                return(MvcHtmlString.Create(
                           string.Format(imgSchema,
                                         BasicHtmlHelper.GetAttributesString(htmlAttributes),
                                         groupName,
                                         targetName,
                                         buttonId)));
            }
        }