Esempio n. 1
0
        /// <summary>
        /// Get editable text for
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="helper"></param>
        /// <param name="expression"></param>
        /// <param name="mode"></param>
        /// <param name="htmlAttributes"></param>
        /// <param name="rootFolder"></param>
        /// <param name="uploadFolder"></param>
        /// <returns></returns>
        public static MvcHtmlString MediaBrowserFor <TModel, TValue>(this HtmlHelper <TModel> helper,
                                                                     Expression <Func <TModel, TValue> > expression, MediaEnums.MediaBrowserSelectMode mode = MediaEnums.MediaBrowserSelectMode.All,
                                                                     object htmlAttributes = null, string rootFolder = FrameworkConstants.MediaPath,
                                                                     string uploadFolder   = "")
        {
            var attributes = htmlAttributes != null
                ? new RouteValueDictionary(htmlAttributes)
                : new RouteValueDictionary();


            attributes.Append("data-mode", mode.ToString());
            attributes.Append("data-root", rootFolder);
            attributes.Append("data-upload", string.IsNullOrEmpty(uploadFolder) ? rootFolder : uploadFolder);
            var textbox = helper.TextBoxFor(expression, attributes);

            var simpleUploadTag = new TagBuilder("div");

            simpleUploadTag.Attributes.Append("class", "simple-upload");
            simpleUploadTag.Attributes.Append("data-rel", "tooltip");

            var tag = new TagBuilder("a");

            tag.Attributes.Append("class", "btn btn-info btn-xs browsefile");
            tag.Attributes.Append("href", "javascript:void(0)");
            tag.Attributes.Append("data-rel", "tooltip");

            switch (mode)
            {
            case MediaEnums.MediaBrowserSelectMode.Image:
                simpleUploadTag = null;

                tag.Attributes.Append("title", "Select Image");
                tag.InnerHtml = "<i class='fa fa-picture-o bigger-110 icon-only'></i>";
                break;

            case MediaEnums.MediaBrowserSelectMode.File:
                simpleUploadTag = null;

                tag.Attributes.Append("title", "Select File");
                tag.InnerHtml = "<i class='fa fa-file-o bigger-110 icon-only'></i>";
                break;

            case MediaEnums.MediaBrowserSelectMode.Folder:
                simpleUploadTag = null;

                tag.Attributes.Append("title", "Select Folder");
                tag.InnerHtml = "<i class='fa fa-folder-o bigger-110 icon-only'></i>";
                break;

            case MediaEnums.MediaBrowserSelectMode.All:
                simpleUploadTag = null;

                tag.Attributes.Append("title", "Select File Or Folder");
                tag.InnerHtml = "<i class='fa fa-file-o bigger-110 icon-only'></i>";
                break;

            case MediaEnums.MediaBrowserSelectMode.SimpleImageUpload:
                simpleUploadTag.Attributes.Append("title", "Upload Image");

                tag = null;
                break;

            case MediaEnums.MediaBrowserSelectMode.ComplexImageUpload:
                simpleUploadTag.Attributes.Append("title", "Upload Image");

                tag.Attributes.Append("title", "Select Image");
                tag.InnerHtml = "<i class='fa fa-picture-o bigger-110 icon-only'></i>";
                break;

            case MediaEnums.MediaBrowserSelectMode.SimpleFileUpload:
                simpleUploadTag.Attributes.Append("title", "Upload File");

                tag = null;
                break;

            case MediaEnums.MediaBrowserSelectMode.ComplexFileUpload:
                simpleUploadTag.Attributes.Append("title", "Upload File");

                tag.Attributes.Append("title", "Select File");
                tag.InnerHtml = "<i class='fa fa-file-o bigger-110 icon-only'></i>";
                break;
            }

            var tagHtml          = tag == null ? string.Empty : tag.ToString(TagRenderMode.Normal);
            var simpleUploadHtml = simpleUploadTag == null
                ? string.Empty
                : simpleUploadTag.ToString(TagRenderMode.Normal);

            return(MvcHtmlString.Create(textbox + tagHtml + simpleUploadHtml));
        }