Пример #1
0
        /// <summary>
        /// Returns display item of a value with caption truncated by the given length and use bootstrap pop-over to display the complete value
        /// </summary>
        /// <param name="name">Unique name for the display tag</param>
        /// <param name="value">Value to display</param>
        /// <param name="labelText">Item caption text</param>
        /// <param name="spanOf12">Number represents bootstrap column span for the item width</param>
        /// <param name="textMaxLength">Maximum length of the displayed text</param>
        /// <param name="popOverTitle">The pop-over title text</param>
        /// <param name="seeMoreHtml">html text for see more if the text is truncated</param>
        /// <param name="showAllContentInPopover">True if you want to show the complete value in the pop-over. False to display the rest of the value only</param>
        /// <param name="htmlAttributes">custom htmlAttributes applied to the value tag</param>
        /// <param name="postBackValue">If true, value will be posted back in hidden input field</param>
        ///  <param name="hint">Optional text to add after the caption label as a hint</param>
        /// <returns>HtmlString</returns>
        public static IHtmlContent DisplayFormItemWithTruncate <TModel>(
            this IHtmlHelper <TModel> helper, string name, string value, string labelText = "", int spanOf12 = 6,
            int textMaxLength     = 50, string popOverTitle  = "", string seeMoreHtml = " المزيد >>", bool showAllContentInPopover = false,
            object htmlAttributes = null, bool postBackValue = false, string hint     = "", TruncateMethod method = TruncateMethod.Popover)
        {
            HtmlContentBuilder htmlContentBuilder = new HtmlContentBuilder();

            var col          = new ItemsColumnTagBuilder(spanOf12, null);
            var frmGroup     = new FormGroupTagBuilder();
            var valueDisplay = new ParagraphTagBuilder(name, htmlAttributes);

            valueDisplay.InnerHtml.AppendHtml(helper.DisplayWithTruncate(name, value, textMaxLength, popOverTitle, seeMoreHtml, showAllContentInPopover, method));

            htmlContentBuilder.AppendHtml(col.RenderStartTag())
            .AppendHtml(frmGroup.RenderStartTag())
            .AppendHtml(helper.Label(labelText));

            if (!string.IsNullOrEmpty(hint))
            {
                htmlContentBuilder.AppendHtml(new FormItemHintTagBuilder(hint));
            }

            htmlContentBuilder.AppendHtml(valueDisplay);

            if (postBackValue)
            {
                htmlContentBuilder.AppendHtml(helper.Hidden(name, value));
            }

            htmlContentBuilder.AppendHtml(frmGroup.RenderEndTag())
            .AppendHtml(col.RenderEndTag());

            return(htmlContentBuilder);
        }
Пример #2
0
        /// <summary>
        /// Returns display value with caption as bootstrap form item
        /// </summary>
        /// <param name="value">Item value to display</param>
        /// <param name="labelText">Item caption text</param>
        /// <param name="spanOf12">Number represents bootstrap column span for the item width</param>
        /// <param name="htmlAttributes">custom htmlAttributes applied to the value tag</param>
        /// <param name="postBackValue">If true, value will be posted back in hidden input field</param>
        /// <param name="name">Unique name for the hidden field</param>
        ///  <param name="hint">Optional text to add after the caption label as a hint</param>
        /// <returns>HtmlString</returns>
        public static IHtmlContent DisplayFormItem <TModel>(
            this IHtmlHelper <TModel> helper, string value, string labelText = "", int spanOf12 = 6, object htmlAttributes = null, bool postBackValue = false, string name = "postValue", string hint = "")
        {
            HtmlContentBuilder htmlContentBuilder = new HtmlContentBuilder();

            var col            = new ItemsColumnTagBuilder(spanOf12, null);
            var frmGroup       = new FormGroupTagBuilder();
            var valueParagraph = new ParagraphTagBuilder(name, value, htmlAttributes);

            htmlContentBuilder.AppendHtml(col.RenderStartTag())
            .AppendHtml(frmGroup.RenderStartTag())
            .AppendHtml(helper.Label(labelText));

            if (!string.IsNullOrEmpty(hint))
            {
                htmlContentBuilder.AppendHtml(new FormItemHintTagBuilder(hint));
            }

            htmlContentBuilder.AppendHtml(valueParagraph);

            if (postBackValue)
            {
                htmlContentBuilder.AppendHtml(helper.Hidden(name, value));
            }

            htmlContentBuilder.AppendHtml(frmGroup.RenderEndTag())
            .AppendHtml(col.RenderEndTag());

            return(htmlContentBuilder);
        }
Пример #3
0
        /// <summary>
        /// Return file uploader control full item (with caption) initialized with finUploader plugin
        /// </summary>
        /// <param name="expression">Lambda expression for the string property to bind file path to</param>
        /// <param name="controllerName">Upload controller name that contains upload and delete actions</param>
        /// <param name="allowedExtensions">Allowed extensions to upload</param>
        /// <param name="fileMaxSize">Maximum file size to upload</param>
        /// <param name="withValidation">Add Validation message control?</param>
        /// <param name="spanOf12">Number represents bootstrap column span for the item width</param>
        /// <param name="onSuccessCallback">Javascript function name to call after upload success</param>
        /// <param name="onDeleteCallback">Javascript function name to call after deleting afile from the uploader</param>
        /// <param name="hint">Optional text to add after the caption label as a hint</param>
        /// <returns>HtmlString for uploader control with caption label</returns>
        public static IHtmlContent FileUploadFormItemFor <TModel, TProperty>(
            this IHtmlHelper <TModel> helper,
            Expression <Func <TModel, TProperty> > expression,
            string controllerName = "Upload",
            IEnumerable <string> allowedExtensions = null,
            int fileMaxSize           = 2048,
            int numberOfFilesToUpload = 1,
            bool multiple             = false,
            bool withValidation       = true,
            int spanOf12             = 6,
            string onSuccessCallback = "",
            string onDeleteCallback  = "",
            string hint = "")
        {
            HtmlContentBuilder htmlContentBuilder = new HtmlContentBuilder();
            var expresionProvider = helper.ViewContext.HttpContext.RequestServices
                                    .GetService(typeof(ModelExpressionProvider)) as ModelExpressionProvider;
            string name = expresionProvider.GetExpressionText(expression);

            if (allowedExtensions == null || !allowedExtensions.Any())
            {
                allowedExtensions = allowedExtensionsDeafault;
            }

            var col      = new ItemsColumnTagBuilder(spanOf12, null);
            var frmGroup = new FormGroupTagBuilder();
            var uploader = helper.FileUploaderFor(expression, controllerName, allowedExtensions, fileMaxSize, numberOfFilesToUpload, multiple, onSuccessCallback, onDeleteCallback);

            htmlContentBuilder.AppendHtml(col.RenderStartTag())
            .AppendHtml(frmGroup.RenderStartTag())
            .AppendHtml(helper.LabelFor(expression));

            if (!string.IsNullOrEmpty(hint))
            {
                htmlContentBuilder.AppendHtml(new FormItemHintTagBuilder(hint));
            }

            htmlContentBuilder.AppendHtml(uploader);

            if (withValidation)
            {
                htmlContentBuilder.AppendHtml(helper.ValidationMessageFor(expression));
            }

            htmlContentBuilder.AppendHtml(frmGroup.RenderEndTag())
            .AppendHtml(col.RenderEndTag());

            return(htmlContentBuilder);
        }
Пример #4
0
        /// <summary>
        /// Return file uploader control full item (with caption) initialized with finUploader plugin
        /// </summary>
        /// <param name="name">Unique name for the uploader</param>
        /// <param name="spanOf12">Number represents bootstrap column span for the item width</param>
        /// <param name="labelText">Caption text</param>
        /// <param name="controllerName">Upload controller name that contains upload and delete actions</param>
        /// <param name="allowedExtensions">Allowed extensions to upload</param>
        /// <param name="fileMaxSize">Maximum file size to upload</param>
        /// <param name="required">Add required validation?</param>
        /// <param name="validationMessage">Validation message for required validation</param>
        /// <param name="onSuccessCallback">Javascript function name to call after upload success</param>
        /// <param name="onDeleteCallback">Javascript function name to call after deleting afile from the uploader</param>
        /// <param name="hint">Optional text to add after the caption label as a hint</param>
        /// <returns>HtmlString for uploader control with caption label</returns>
        public static IHtmlContent FileUploadFormItem <TModel>(
            this IHtmlHelper <TModel> helper,
            string name,
            int spanOf12          = 6,
            string labelText      = "",
            string controllerName = "Upload",
            IEnumerable <string> allowedExtensions = null,
            int fileMaxSize           = 2048,
            int numberOfFilesToUpload = 1,
            bool multiple             = false,
            bool required             = true, string validationMessage = "الملف مطلوب",
            string onSuccessCallback  = "", string onDeleteCallback    = "", string hint = "")
        {
            HtmlContentBuilder htmlContentBuilder = new HtmlContentBuilder();

            if (allowedExtensions == null || !allowedExtensions.Any())
            {
                allowedExtensions = allowedExtensionsDeafault;
            }

            var col      = new ItemsColumnTagBuilder(spanOf12, null);
            var frmGroup = new FormGroupTagBuilder();
            var uploader = helper.FileUploader(name, controllerName, allowedExtensions, fileMaxSize, numberOfFilesToUpload, multiple, onSuccessCallback, onDeleteCallback, required, validationMessage);

            htmlContentBuilder.AppendHtml(col.RenderStartTag())
            .AppendHtml(frmGroup.RenderStartTag())
            .AppendHtml(helper.Label(labelText));

            if (!string.IsNullOrEmpty(hint))
            {
                htmlContentBuilder.AppendHtml(new FormItemHintTagBuilder(hint));
            }

            htmlContentBuilder.AppendHtml(uploader);

            if (required)
            {
                htmlContentBuilder.AppendHtml(helper.ValidationMessage(name, validationMessage));
            }

            htmlContentBuilder.AppendHtml(frmGroup.RenderEndTag())
            .AppendHtml(col.RenderEndTag());

            return(htmlContentBuilder);
        }
Пример #5
0
        /// <summary>
        /// Returns display value for model property with the display name as caption in bootstrap form item
        /// </summary>
        /// <param name="expression">Lambda expression for the property</param>
        /// <param name="spanOf12">Number represents bootstrap column span for the item width</param>
        /// <param name="htmlAttributes">custom htmlAttributes applied to the value tag</param>
        /// <param name="postBackValue">If true, value will be posted back in hidden input field</param>
        /// <param name="hint">Optional text to add after the caption label as a hint</param>
        /// <returns>HtmlString</returns>
        public static IHtmlContent DisplayFormItemFor <TModel, TProperty>(
            this IHtmlHelper <TModel> helper,
            Expression <Func <TModel, TProperty> > expression, int spanOf12 = 6, object htmlAttributes = null, bool postBackValue = false, string hint = "")
        {
            var expresionProvider = helper.ViewContext.HttpContext.RequestServices
                                    .GetService(typeof(ModelExpressionProvider)) as ModelExpressionProvider;
            HtmlContentBuilder htmlContentBuilder = new HtmlContentBuilder();
            string             name = helper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(expresionProvider.GetExpressionText(expression));

            var col            = new ItemsColumnTagBuilder(spanOf12, null);
            var frmGroup       = new FormGroupTagBuilder();
            var valueParagraph = new ParagraphTagBuilder(name, htmlAttributes);

            valueParagraph.InnerHtml.AppendHtml(helper.DisplayFor(expression));

            htmlContentBuilder.AppendHtml(col.RenderStartTag())
            .AppendHtml(frmGroup.RenderStartTag())
            .AppendHtml(helper.LabelFor(expression));

            if (!string.IsNullOrEmpty(hint))
            {
                htmlContentBuilder.AppendHtml(new FormItemHintTagBuilder(hint));
            }

            htmlContentBuilder.AppendHtml(valueParagraph);

            if (postBackValue)
            {
                htmlContentBuilder.AppendHtml(helper.HiddenFor(expression));
            }

            htmlContentBuilder.AppendHtml(frmGroup.RenderEndTag())
            .AppendHtml(col.RenderEndTag());

            return(htmlContentBuilder);
        }