mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-07-15 14:46:12 +08:00

- Removed dependency on Orchard.Taxonomies - Removed dependency on Orchard.Media You will need to remove the Orchard_MediaLibrary tables and also the Data Migration record corresponding to this module if you want to upgrade from 1.x. You can also apply the database changes by hand, remove all the records then use the Upgrade module to import all media. --HG-- branch : 1.x extra : rebase_source : 46100428d9546c3082bf65ce85d8d891543dc0a9
139 lines
5.6 KiB
C#
139 lines
5.6 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Web.Mvc;
|
|
using Orchard.Core.Contents.Controllers;
|
|
using Orchard.Localization;
|
|
using Orchard.Logging;
|
|
using Orchard.MediaLibrary.Models;
|
|
using Orchard.MediaLibrary.Services;
|
|
using Orchard.MediaLibrary.ViewModels;
|
|
using Orchard.UI.Admin;
|
|
using Orchard.UI.Notify;
|
|
|
|
namespace Orchard.MediaLibrary.Controllers {
|
|
[Admin]
|
|
public class FolderController : Controller {
|
|
private readonly IMediaLibraryService _mediaLibraryService;
|
|
|
|
public FolderController(
|
|
IOrchardServices services,
|
|
IMediaLibraryService mediaManagerService
|
|
) {
|
|
_mediaLibraryService = mediaManagerService;
|
|
|
|
Services = services;
|
|
Logger = NullLogger.Instance;
|
|
T = NullLocalizer.Instance;
|
|
}
|
|
|
|
public IOrchardServices Services { get; set; }
|
|
public ILogger Logger { get; set; }
|
|
public Localizer T { get; set; }
|
|
|
|
public ActionResult Create(string folderPath) {
|
|
if (!Services.Authorizer.Authorize(Permissions.ManageMediaContent, T("Couldn't create media folder")))
|
|
return new HttpUnauthorizedResult();
|
|
|
|
var viewModel = new MediaManagerFolderCreateViewModel {
|
|
Hierarchy = _mediaLibraryService.GetMediaFolders(folderPath),
|
|
FolderPath = folderPath
|
|
};
|
|
|
|
return View(viewModel);
|
|
}
|
|
|
|
[HttpPost, ActionName("Create")]
|
|
public ActionResult Create() {
|
|
if (!Services.Authorizer.Authorize(Permissions.ManageMediaContent, T("Couldn't create media folder")))
|
|
return new HttpUnauthorizedResult();
|
|
|
|
var viewModel = new MediaManagerFolderCreateViewModel();
|
|
UpdateModel(viewModel);
|
|
|
|
try {
|
|
_mediaLibraryService.CreateFolder(viewModel.FolderPath, viewModel.Name);
|
|
Services.Notifier.Information(T("Media folder created"));
|
|
}
|
|
catch (ArgumentException argumentException) {
|
|
Services.Notifier.Error(T("Creating Folder failed: {0}", argumentException.Message));
|
|
Services.TransactionManager.Cancel();
|
|
return View(viewModel);
|
|
}
|
|
|
|
return RedirectToAction("Index", "Admin", new { area = "Orchard.MediaLibrary" });
|
|
|
|
}
|
|
|
|
public ActionResult Edit(string folderPath) {
|
|
if (!Services.Authorizer.Authorize(Permissions.ManageMediaContent, T("Couldn't edit media folder")))
|
|
return new HttpUnauthorizedResult();
|
|
|
|
var viewModel = new MediaManagerFolderEditViewModel {
|
|
Hierarchy = _mediaLibraryService.GetMediaFolders(folderPath),
|
|
FolderPath = folderPath,
|
|
Name = folderPath.Split('/').LastOrDefault()
|
|
};
|
|
|
|
return View(viewModel);
|
|
}
|
|
|
|
[HttpPost, ActionName("Edit")]
|
|
[FormValueRequired("submit.Save")]
|
|
public ActionResult Edit() {
|
|
if (!Services.Authorizer.Authorize(Permissions.ManageMediaContent, T("Couldn't edit media folder")))
|
|
return new HttpUnauthorizedResult();
|
|
|
|
var viewModel = new MediaManagerFolderEditViewModel();
|
|
UpdateModel(viewModel);
|
|
|
|
try {
|
|
_mediaLibraryService.RenameFolder(viewModel.FolderPath, viewModel.Name);
|
|
Services.Notifier.Information(T("Media folder renamed"));
|
|
}
|
|
catch (ArgumentException argumentException) {
|
|
Services.Notifier.Error(T("Editing Folder failed: {0}", argumentException.Message));
|
|
Services.TransactionManager.Cancel();
|
|
return View(viewModel);
|
|
}
|
|
|
|
return RedirectToAction("Index", "Admin", new { area = "Orchard.MediaLibrary" });
|
|
}
|
|
|
|
[HttpPost, ActionName("Edit")]
|
|
[FormValueRequired("submit.Delete")]
|
|
public ActionResult Delete() {
|
|
if (!Services.Authorizer.Authorize(Permissions.ManageMediaContent, T("Couldn't delete media folder")))
|
|
return new HttpUnauthorizedResult();
|
|
|
|
var viewModel = new MediaManagerFolderEditViewModel();
|
|
UpdateModel(viewModel);
|
|
|
|
try {
|
|
_mediaLibraryService.DeleteFolder(viewModel.FolderPath);
|
|
Services.Notifier.Information(T("Media folder deleted"));
|
|
}
|
|
catch (ArgumentException argumentException) {
|
|
Services.Notifier.Error(T("Deleting Folder failed: {0}", argumentException.Message));
|
|
Services.TransactionManager.Cancel();
|
|
return View(viewModel);
|
|
}
|
|
|
|
return RedirectToAction("Index", "Admin", new { area = "Orchard.MediaLibrary" });
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult Move(string folderPath, int[] mediaItemIds) {
|
|
if (!Services.Authorizer.Authorize(Permissions.ManageMediaContent, T("Couldn't move media items")))
|
|
return new HttpUnauthorizedResult();
|
|
|
|
foreach (var media in Services.ContentManager.Query().ForPart<MediaPart>().ForContentItems(mediaItemIds).List()) {
|
|
var uniqueFilename = _mediaLibraryService.GetUniqueFilename(folderPath, media.FileName);
|
|
_mediaLibraryService.MoveFile(media.FolderPath, media.FileName, folderPath, uniqueFilename);
|
|
media.FolderPath = folderPath;
|
|
media.FileName = uniqueFilename;
|
|
}
|
|
|
|
return Json(true);
|
|
}
|
|
}
|
|
} |