Initializing localizer

Adding information notifications
Adding localization invocations where necessary
Replacing tabs for spaces in views

--HG--
branch : dev
This commit is contained in:
Andre Rodrigues
2010-11-24 15:19:14 -08:00
parent 2652425378
commit fd4c58d4b4
11 changed files with 59 additions and 38 deletions

View File

@@ -5,6 +5,10 @@ namespace Orchard.Media {
public class AdminMenu : INavigationProvider {
public Localizer T { get; set; }
public AdminMenu() {
T = NullLocalizer.Instance;
}
public string MenuName { get { return "admin"; } }
public void GetNavigation(NavigationBuilder builder) {
@@ -13,4 +17,4 @@ namespace Orchard.Media {
.Permission(Permissions.ManageMediaFiles)));
}
}
}
}

View File

@@ -18,6 +18,8 @@ namespace Orchard.Media.Controllers {
public AdminController(IOrchardServices services, IMediaService mediaService) {
Services = services;
_mediaService = mediaService;
T = NullLocalizer.Instance;
}
public IOrchardServices Services { get; set;}
@@ -61,6 +63,8 @@ namespace Orchard.Media.Controllers {
UpdateModel(viewModel);
_mediaService.CreateFolder(viewModel.MediaPath, viewModel.Name);
Services.Notifier.Information(T("Media folder created"));
return RedirectToAction("Index");
}
catch (Exception exception) {
@@ -86,6 +90,8 @@ namespace Orchard.Media.Controllers {
if (!Services.Authorizer.Authorize(Permissions.ManageMediaFiles, T("Couldn't delete media file")))
return new HttpUnauthorizedResult();
_mediaService.DeleteFile(fileName, folderName);
Services.Notifier.Information(T("Media file deleted"));
}
else if (key.StartsWith("Checkbox.Folder.") && input[key] == "true") {
string folderName = key.Substring("Checkbox.Folder.".Length);
@@ -93,6 +99,8 @@ namespace Orchard.Media.Controllers {
if (!Services.Authorizer.Authorize(Permissions.ManageMediaFiles, T("Couldn't delete media folder")))
return new HttpUnauthorizedResult();
_mediaService.DeleteFolder(folderPath);
Services.Notifier.Information(T("Media folder deleted"));
}
}
return RedirectToAction("Index");
@@ -120,10 +128,11 @@ namespace Orchard.Media.Controllers {
_mediaService.DeleteFolder(viewModel.MediaPath);
Services.Notifier.Information(T("Media folder deleted"));
return RedirectToAction("Index");
}
catch (Exception exception) {
Services.Notifier.Error(T("Modifying Folder Properties failed: {0}", exception.Message));
Services.Notifier.Error(T("Deleting media folder failed: {0}", exception.Message));
return View(viewModel);
}
}
@@ -140,9 +149,10 @@ namespace Orchard.Media.Controllers {
_mediaService.RenameFolder(viewModel.MediaPath, viewModel.Name);
Services.Notifier.Information(T("Media folder properties modified"));
return RedirectToAction("Index");
} catch (Exception exception) {
Services.Notifier.Error(T("Modifying Folder Properties failed: {0}", exception.Message));
Services.Notifier.Error(T("Modifying media folder properties failed: {0}", exception.Message));
return View(viewModel);
}
}
@@ -182,6 +192,7 @@ namespace Orchard.Media.Controllers {
_mediaService.UploadMediaFile(viewModel.MediaPath, file);
}
Services.Notifier.Information(T("Media file(s) uploaded"));
return RedirectToAction("Edit", new { name = viewModel.FolderName, mediaPath = viewModel.MediaPath });
}
catch (Exception exception) {
@@ -244,6 +255,8 @@ namespace Orchard.Media.Controllers {
UpdateModel(viewModel);
_mediaService.DeleteFile(viewModel.Name, viewModel.MediaPath);
Services.Notifier.Information(T("Media deleted"));
return RedirectToAction("Edit", new { name = viewModel.FolderName, mediaPath = viewModel.MediaPath });
} catch (Exception exception) {
Services.Notifier.Error(T("Removing media file failed: {0}", exception.Message));
@@ -268,6 +281,7 @@ namespace Orchard.Media.Controllers {
viewModelName = input["NewName"];
}
Services.Notifier.Information(T("Media information updated"));
return RedirectToAction("EditMedia", new { name = viewModelName,
caption = viewModel.Caption,
lastUpdated = viewModel.LastUpdated,

View File

@@ -25,4 +25,4 @@ namespace Orchard.Media.Helpers {
return navigations;
}
}
}
}

View File

@@ -1,5 +1,4 @@
using Orchard.ContentManagement;
using System;
namespace Orchard.Media.Models {
public class MediaSettingsPart : ContentPart<MediaSettingsPartRecord> {

View File

@@ -1,6 +1,5 @@
using System.Net.Mail;
using Orchard.ContentManagement.Records;
using System.ComponentModel.DataAnnotations;
using Orchard.ContentManagement.Records;
namespace Orchard.Media.Models {
public class MediaSettingsPartRecord : ContentPartRecord {

View File

@@ -6,7 +6,7 @@ using ICSharpCode.SharpZipLib.Zip;
using JetBrains.Annotations;
using Orchard.ContentManagement;
using Orchard.FileSystems.Media;
using Orchard.Logging;
using Orchard.Localization;
using Orchard.Media.Models;
namespace Orchard.Media.Services {
@@ -18,10 +18,11 @@ namespace Orchard.Media.Services {
public MediaService(IStorageProvider storageProvider, IOrchardServices orchardServices) {
_storageProvider = storageProvider;
_orchardServices = orchardServices;
Logger = NullLogger.Instance;
T = NullLocalizer.Instance;
}
public ILogger Logger { get; set; }
public Localizer T { get; set; }
public string GetPublicUrl(string path) {
return _storageProvider.GetPublicUrl(path);
@@ -84,7 +85,7 @@ namespace Orchard.Media.Services {
public void RenameFile(string name, string newName, string folderName) {
if (!FileAllowed(newName, false)) {
throw new ArgumentException("New file name " + newName + " not allowed.");
throw new ArgumentException(T("New file name {0} not allowed", newName).ToString());
}
_storageProvider.RenameFile(_storageProvider.Combine(folderName, name), _storageProvider.Combine(folderName, newName));

View File

@@ -17,12 +17,12 @@
<fieldset>
<label for="pageTitle">@T("File Path <span> - multiple files must be in a zipped folder</span>")</label>
<input id="MediaItemPath" name="MediaItemPath" type="file" value="@T("Browse")" size="64"/>
<span class="hint">@T("After your files have been uploaded, you can edit the titles and descriptions.")</span>
<span class="hint">@T("After your files have been uploaded, you can edit the titles and descriptions.")</span>
<input type="hidden" id="FolderName" name="FolderName" value="@Model.FolderName" />
<input type="hidden" id="MediaPath" name="MediaPath" value="@Model.MediaPath" />
</fieldset>
<fieldset>
<button class="primaryAction" type="submit">@T("Upload")</button>
@Html.AntiForgeryTokenOrchard()
</fieldset>
@Html.AntiForgeryTokenOrchard()
</fieldset>
}

View File

@@ -6,20 +6,20 @@
<h1>@Html.TitleForPage(T("Add a Folder").ToString())</h1>
<div class="breadCrumbs">
<p>@Html.ActionLink(T("Media Folders").ToString(), "Index") &#62;
@foreach (FolderNavigation navigation in MediaHelpers.GetFolderNavigationHierarchy(Model.MediaPath)) {
@Html.ActionLink(navigation.FolderName, "Edit", new {name = navigation.FolderName, mediaPath = navigation.FolderPath}) <text>&#62;</text>
}
@T("Add a Folder") </p>
@foreach (FolderNavigation navigation in MediaHelpers.GetFolderNavigationHierarchy(Model.MediaPath)) {
@Html.ActionLink(navigation.FolderName, "Edit", new {name = navigation.FolderName, mediaPath = navigation.FolderPath}) <text>&#62;</text>
}
@T("Add a Folder") </p>
</div>
@using (Html.BeginFormAntiForgeryPost()) {
@Html.ValidationSummary()
<fieldset>
<label for="Name">@T("Folder Name")</label>
<input id="Name" class="textMedium" name="Name" type="text" />
<input type="hidden" id="MediaPath" name="MediaPath" value="@Model.MediaPath" />
<input id="Name" class="textMedium" name="Name" type="text" />
<input type="hidden" id="MediaPath" name="MediaPath" value="@Model.MediaPath" />
</fieldset>
<fieldset>
<fieldset>
<button class="primaryAction" type="submit">@T("Save")</button>
</fieldset>
}

View File

@@ -24,7 +24,7 @@
@* todo: make these real (including markup) *@
<div>
@* <label>@T("Dimensions: <span>500 x 375 pixels</span>")</label> *@
<label>@T("Size: <span>{0}</span>", Model.Size.ToFriendlySizeString())</label>
<label>@T("Added on: <span>{0}</span>", Model.LastUpdated)</label>

View File

@@ -9,7 +9,6 @@
@foreach (FolderNavigation navigation in MediaHelpers.GetFolderNavigationHierarchy(Model.MediaPath)) {
@Html.ActionLink(navigation.FolderName, "Edit",
new {name = navigation.FolderName, mediaPath = navigation.FolderPath}) <text>&#62;</text>
}
@T("Folder Properties")</p>
</div>
@@ -18,10 +17,10 @@
@Html.ValidationSummary()
<fieldset>
<label for="Name">@T("Folder Name:")</label>
<input id="MediaPath" name="MediaPath" type="hidden" value="@Model.MediaPath" />
<input id="Name" class="textMedium" name="Name" type="text" value="@Model.Name" />
<input id="MediaPath" name="MediaPath" type="hidden" value="@Model.MediaPath" />
<input id="Name" class="textMedium" name="Name" type="text" value="@Model.Name" />
</fieldset>
<fieldset>
<fieldset>
<button class="primaryAction" type="submit" name="submit.Save" value="@T("Save")">@T("Save")</button>
<button type="submit" name="submit.Delete" value="@T("Remove")">@T("Remove")</button>
</fieldset>

View File

@@ -5,6 +5,7 @@ using System.IO;
using System.Linq;
using System.Web.Hosting;
using Orchard.Environment.Configuration;
using Orchard.Localization;
namespace Orchard.FileSystems.Media {
public class FileSystemStorageProvider : IStorageProvider {
@@ -28,8 +29,12 @@ namespace Orchard.FileSystems.Media {
appPath = '/' + appPath;
_publicPath = appPath + "Media/" + settings.Name + "/";
T = NullLocalizer.Instance;
}
public Localizer T { get; set; }
string Map(string path) {
return string.IsNullOrEmpty(path) ? _storagePath : Path.Combine(_storagePath, path);
}
@@ -51,14 +56,14 @@ namespace Orchard.FileSystems.Media {
public IStorageFile GetFile(string path) {
if (!File.Exists(Map(path))) {
throw new ArgumentException("File " + path + " does not exist");
throw new ArgumentException(T("File {0} does not exist", path).ToString());
}
return new FileSystemStorageFile(Fix(path), new FileInfo(Map(path)));
}
public IEnumerable<IStorageFile> ListFiles(string path) {
if (!Directory.Exists(Map(path))) {
throw new ArgumentException("Directory " + path + " does not exist");
throw new ArgumentException(T("Directory {0} does not exist", path).ToString());
}
return new DirectoryInfo(Map(path))
@@ -74,7 +79,7 @@ namespace Orchard.FileSystems.Media {
Directory.CreateDirectory(Map(path));
}
catch (Exception ex) {
throw new ArgumentException(string.Format("The folder could not be created at path: {0}. {1}", path, ex));
throw new ArgumentException(T("The folder could not be created at path: {0}. {1}", path, ex).ToString());
}
}
@@ -91,7 +96,7 @@ namespace Orchard.FileSystems.Media {
public void CreateFolder(string path) {
if (Directory.Exists(Map(path))) {
throw new ArgumentException("Directory " + path + " already exists");
throw new ArgumentException(T("Directory {0} already exists", path).ToString());
}
Directory.CreateDirectory(Map(path));
@@ -99,7 +104,7 @@ namespace Orchard.FileSystems.Media {
public void DeleteFolder(string path) {
if (!Directory.Exists(Map(path))) {
throw new ArgumentException("Directory " + path + " does not exist");
throw new ArgumentException(T("Directory {0} does not exist", path).ToString());
}
Directory.Delete(Map(path), true);
@@ -107,11 +112,11 @@ namespace Orchard.FileSystems.Media {
public void RenameFolder(string path, string newPath) {
if (!Directory.Exists(Map(path))) {
throw new ArgumentException("Directory " + path + "does not exist");
throw new ArgumentException(T("Directory {0} does not exist", path).ToString());
}
if (Directory.Exists(Map(newPath))) {
throw new ArgumentException("Directory " + newPath + " already exists");
throw new ArgumentException(T("Directory {0} already exists", newPath).ToString());
}
Directory.Move(Map(path), Map(newPath));
@@ -119,7 +124,7 @@ namespace Orchard.FileSystems.Media {
public IStorageFile CreateFile(string path) {
if (File.Exists(Map(path))) {
throw new ArgumentException("File " + path + " already exists");
throw new ArgumentException(T("File {0} already exists", path).ToString());
}
var fileInfo = new FileInfo(Map(path));
@@ -130,7 +135,7 @@ namespace Orchard.FileSystems.Media {
public void DeleteFile(string path) {
if (!File.Exists(Map(path))) {
throw new ArgumentException("File " + path + " does not exist");
throw new ArgumentException(T("File {0} does not exist", path).ToString());
}
File.Delete(Map(path));
@@ -138,11 +143,11 @@ namespace Orchard.FileSystems.Media {
public void RenameFile(string path, string newPath) {
if (!File.Exists(Map(path))) {
throw new ArgumentException("File " + path + " does not exist");
throw new ArgumentException(T("File {0} does not exist", path).ToString());
}
if (File.Exists(Map(newPath))) {
throw new ArgumentException("File " + newPath + " already exists");
throw new ArgumentException(T("File {0} already exists", newPath).ToString());
}
File.Move(Map(path), Map(newPath));