Ejemplo n.º 1
0
        public ActionResult MediaBrowser(string rootFolder, string imageUrl, MediaEnums.MediaBrowserSelectMode mode = MediaEnums.MediaBrowserSelectMode.All)
        {
            if (string.IsNullOrEmpty(rootFolder))
            {
                rootFolder = FrameworkConstants.MediaPath;
            }

            var model = new MediaBrowserSetupModel
            {
                RootFolder = rootFolder,
                Mode       = mode
            };

            if (!string.IsNullOrEmpty(imageUrl))
            {
                model.FileTreeAttribute = new FileTreeAttribute
                {
                    Id      = imageUrl.ToIdString(),
                    Path    = imageUrl,
                    IsImage = imageUrl.IsImage(),
                };
            }

            return(View(model));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Check if current path is valid
        /// </summary>
        /// <param name="path"></param>
        /// <param name="mode"></param>
        /// <returns></returns>
        public ResponseModel CheckPathValid(string path, MediaEnums.MediaBrowserSelectMode mode)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(new ResponseModel
                {
                    Success = false,
                    Message = T("Media_Message_EmptyPath")
                });
            }

            var physicalPath = HttpContext.Current.Server.MapPath(path);

            switch (mode)
            {
            case MediaEnums.MediaBrowserSelectMode.Folder:
                if (!Directory.Exists(physicalPath))
                {
                    //Check if user select file of folder
                    if (File.Exists(physicalPath))
                    {
                        var fileInfo = new FileInfo(physicalPath);
                        path = fileInfo.DirectoryName;
                    }
                    else
                    {
                        return(new ResponseModel
                        {
                            Success = false,
                            Message = T("Media_Message_WrongFolderPath")
                        });
                    }
                }
                break;

            case MediaEnums.MediaBrowserSelectMode.File:
            case MediaEnums.MediaBrowserSelectMode.ComplexFileUpload:
                if (!File.Exists(physicalPath))
                {
                    return(new ResponseModel
                    {
                        Success = false,
                        Message = T("Media_Message_WrongFilePath")
                    });
                }
                break;

            case MediaEnums.MediaBrowserSelectMode.Image:
            case MediaEnums.MediaBrowserSelectMode.ComplexImageUpload:
                if (!File.Exists(physicalPath) || !physicalPath.IsImage())
                {
                    return(new ResponseModel
                    {
                        Success = false,
                        Message = T("Media_Message_WrongImagePath")
                    });
                }
                break;
            }

            return(new ResponseModel
            {
                Success = true,
                Data = path
            });
        }
Ejemplo n.º 3
0
 public JsonResult CheckPathValid(string path, MediaEnums.MediaBrowserSelectMode mode)
 {
     return(Json(_mediaService.CheckPathValid(path, mode)));
 }
Ejemplo n.º 4
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));
        }