public override void InitHelpers()
 {
     Ajax = new AjaxHelper<object>(ViewContext, this);
     Html = new DnnHtmlHelper<object>(ViewContext, this);
     Url = new DnnUrlHelper(ViewContext);
     Dnn = new DnnHelper<object>(ViewContext, this);
     ConferenceModuleContext = new ContextHelper(ViewContext);
 }
Beispiel #2
0
        /// <summary>
        /// Template Label pour les views Edit/Settings
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="html"></param>
        /// <param name="expression"></param>
        /// <param name="labelText"></param>
        /// <param name="htmlAttributes"></param>
        /// <returns>une chaine de caractères représentant un template html.</returns>
        public static MvcHtmlString DnnLabelFor <TModel, TValue>(this DnnHtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression, string labelText = "", IDictionary <string, object> htmlAttributes = null, string helpText = "")
        {
            ModelMetadata metadata      = ModelMetadata.FromLambdaExpression(expression, html.ViewData);
            string        htmlFieldName = ExpressionHelper.GetExpressionText(expression);

            /* Text du label */
            //string labelText = metadata.DisplayName ?? metadata.PropertyName ?? htmlFieldName.Split('.').Last();
            //if (String.IsNullOrEmpty(labelText))
            //{
            //    return MvcHtmlString.Empty;
            //}
            if (string.IsNullOrWhiteSpace(labelText))
            {
                labelText = metadata.DisplayName ?? metadata.PropertyName ?? htmlFieldName.Split('.').Last();
            }

            TagBuilder tagDiv = new TagBuilder("div");

            tagDiv.AddCssClass("dnnLabel");

            TagBuilder tagLbl = new TagBuilder("label");

            if (htmlAttributes != null)
            {
                tagLbl.MergeAttributes(htmlAttributes);
            }
            //var _for = html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldId(htmlFieldName);
            //_for = metadata.PropertyName;
            //var _for = htmlFieldName.Split('.').Last();
            tagLbl.Attributes.Add("for", htmlFieldName);

            TagBuilder tagSpan = new TagBuilder("span");

            tagSpan.SetInnerText(labelText);

            // assign <span> to <label> inner html
            tagLbl.InnerHtml = tagSpan.ToString(TagRenderMode.Normal);

            TagBuilder tagA = new TagBuilder("a");

            tagA.AddCssClass("dnnFormHelp");

            TagBuilder _tagDiv = new TagBuilder("div");

            _tagDiv.AddCssClass("dnnTooltip");

            TagBuilder __tagDiv = new TagBuilder("div");

            __tagDiv.AddCssClass("dnnFormHelpContent dnnClear");

            TagBuilder _tagSpan = new TagBuilder("span");

            _tagSpan.AddCssClass("dnnHelpText");
            if (!string.IsNullOrWhiteSpace(helpText))
            {
                _tagSpan.SetInnerText(@"" + helpText);
            }

            TagBuilder _tagA = new TagBuilder("a");

            _tagA.AddCssClass("pinHelp");

            __tagDiv.InnerHtml = string.Format("{0}{1}", _tagSpan.ToString(TagRenderMode.Normal), _tagA.ToString(TagRenderMode.Normal));
            _tagDiv.InnerHtml  = __tagDiv.ToString(TagRenderMode.Normal);
            tagDiv.InnerHtml   = string.Format("{0}{1}{2}", tagLbl.ToString(TagRenderMode.Normal), tagA.ToString(TagRenderMode.Normal), _tagDiv.ToString(TagRenderMode.Normal));

            return(MvcHtmlString.Create(tagDiv.ToString(TagRenderMode.Normal)));
        }
Beispiel #3
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="TModel"></typeparam>
 /// <typeparam name="TValue"></typeparam>
 /// <param name="html"></param>
 /// <param name="expression"></param>
 /// <param name="labelText"></param>
 /// <param name="helpText"></param>
 /// <returns></returns>
 public static MvcHtmlString DnnLabelFor <TModel, TValue>(this DnnHtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression, string labelText, string helpText)
 {
     return(DnnLabelFor(html, expression, labelText, null, helpText));
 }
Beispiel #4
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="TModel"></typeparam>
 /// <typeparam name="TValue"></typeparam>
 /// <param name="html"></param>
 /// <param name="expression"></param>
 /// <param name="htmlAttributes"></param>
 /// <returns></returns>
 public static MvcHtmlString DnnLabelFor <TModel, TValue>(this DnnHtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression, object htmlAttributes)
 {
     return(DnnLabelFor(html, expression, "", new RouteValueDictionary(htmlAttributes), ""));
 }
Beispiel #5
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="html"></param>
        /// <param name="expression"></param>
        /// <param name="format"></param>
        /// <param name="htmlAttributes"></param>
        /// <param name="helpText"></param>
        /// <param name="readOnly"></param>
        /// <returns></returns>
        public static MvcHtmlString DnnTexBoxDateTimeFor <TModel, TValue>(
            this DnnHtmlHelper <TModel> html, Expression <Func <TModel
                                                                , TValue> > expression
            , string format
            , IDictionary <string, object> htmlAttributes = null
            , bool readOnly = false
            )
        {
            if (htmlAttributes == null)
            {
                htmlAttributes = new Dictionary <string, object>();
            }

            ModelMetadata modelMetadata = ModelMetadata.FromLambdaExpression(expression, html.ViewData);

            if (modelMetadata == null)
            {
                if (readOnly)
                {
                    if (htmlAttributes.ContainsKey("readonly") == false)
                    {
                        htmlAttributes.Add("readonly", "read-only");
                    }
                }
            }
            else
            {
                if (htmlAttributes.ContainsKey("placeholder") == false)
                {
                    var htmlFieldName = ExpressionHelper.GetExpressionText(expression);

                    var labelText =
                        modelMetadata.DisplayName ??
                        modelMetadata.PropertyName ??
                        htmlFieldName.Split('.').Last();

                    if (!string.IsNullOrWhiteSpace(labelText))
                    {
                        htmlAttributes.Add("placeholder", labelText);
                    }
                }

                if ((readOnly) || (modelMetadata.IsReadOnly))
                {
                    if (!htmlAttributes.ContainsKey("readonly"))
                    {
                        htmlAttributes.Add("readonly", "read-only");
                    }
                }
            }

            htmlAttributes.Add("class", "form-control");

            MemberExpression memberExpression = expression.Body as MemberExpression;

            if (memberExpression != null)
            {
                StringLengthAttribute stringLengthAttribute =
                    memberExpression
                    .Member
                    .GetCustomAttributes(typeof(StringLengthAttribute), false)
                    .FirstOrDefault() as StringLengthAttribute;

                if (stringLengthAttribute != null)
                {
                    if (htmlAttributes.ContainsKey("maxlength") == false)
                    {
                        htmlAttributes.Add("maxlength", stringLengthAttribute.MaximumLength);
                    }
                }
            }

            return(html.TextBoxFor(expression, format, htmlAttributes));
        }