mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-23 12:53:33 +08:00
Some more work on being able to add media from the (TinyMCE) editor
- TinyMCE module takes a dependency on the current media module api with the addmedia plugin which is functional to the point of being able to add media* * it still needs a setting of where the media should go (current spec and xmlrpc api say <blog slug>/<post slug> for a blog post but (1) I don't even have that context from the editor and (2) what about other content types) * it (the plugin) still needs to do an async post and handle the returned JSON appropriatly (insert image tag into the editor using returned url and close the dialog otherwise present any given error) --HG-- branch : dev
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
@@ -162,18 +163,27 @@ namespace Orchard.Media.Controllers {
|
|||||||
var viewModel = new MediaItemAddViewModel();
|
var viewModel = new MediaItemAddViewModel();
|
||||||
try {
|
try {
|
||||||
UpdateModel(viewModel);
|
UpdateModel(viewModel);
|
||||||
if (!Services.Authorizer.Authorize(Permissions.UploadMediaFiles, T("Couldn't upload media file")))
|
if (!Services.Authorizer.Authorize(Permissions.UploadMediaFiles))
|
||||||
return Json(T("ERROR: You don't have permission to upload media files"));
|
return Json(new { error = T("ERROR: You don't have permission to upload media files").ToString() });
|
||||||
|
|
||||||
foreach (string fileName in Request.Files) {
|
if (Request.Files.Count < 1 || Request.Files[0].ContentLength == 0)
|
||||||
HttpPostedFileBase file = Request.Files[fileName];
|
return Json(new { error = T("HEY: You didn't give me a file to upload").ToString() });
|
||||||
_mediaService.UploadMediaFile(viewModel.MediaPath, file);
|
|
||||||
|
try {
|
||||||
|
_mediaService.GetMediaFiles(viewModel.MediaPath);
|
||||||
|
}
|
||||||
|
catch //media api needs a little work, like everything else of course ;)
|
||||||
|
{
|
||||||
|
_mediaService.CreateFolder(viewModel.MediaPath, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
return Json(viewModel.MediaPath);
|
var file = Request.Files[0];
|
||||||
|
_mediaService.UploadMediaFile(viewModel.MediaPath, file);
|
||||||
|
|
||||||
|
return Json(new { url = Path.Combine(_mediaService.GetRootUrl(), string.Format("{0}/{1}", viewModel.MediaPath, file.FileName)).Replace("\\", "/") });
|
||||||
}
|
}
|
||||||
catch (Exception exception) {
|
catch (Exception exception) {
|
||||||
return Json("ERROR: Uploading media file failed: " + exception.Message);
|
return Json(new { error = T("ERROR: Uploading media file failed: {0}", exception.Message).ToString() });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -4,6 +4,7 @@ using Orchard.Media.Models;
|
|||||||
|
|
||||||
namespace Orchard.Media.Services {
|
namespace Orchard.Media.Services {
|
||||||
public interface IMediaService : IDependency {
|
public interface IMediaService : IDependency {
|
||||||
|
string GetRootUrl();
|
||||||
IEnumerable<MediaFolder> GetMediaFolders(string path);
|
IEnumerable<MediaFolder> GetMediaFolders(string path);
|
||||||
IEnumerable<MediaFile> GetMediaFiles(string path);
|
IEnumerable<MediaFile> GetMediaFiles(string path);
|
||||||
void CreateFolder(string path, string name);
|
void CreateFolder(string path, string name);
|
||||||
|
@@ -14,16 +14,22 @@ namespace Orchard.Media.Services {
|
|||||||
public class MediaService : IMediaService {
|
public class MediaService : IMediaService {
|
||||||
private readonly IStorageProvider _storageProvider;
|
private readonly IStorageProvider _storageProvider;
|
||||||
private readonly string _rootPath;
|
private readonly string _rootPath;
|
||||||
|
private readonly string _rootUrl;
|
||||||
|
|
||||||
public MediaService (
|
public MediaService (
|
||||||
IStorageProvider storageProvider) {
|
IStorageProvider storageProvider) {
|
||||||
_storageProvider = storageProvider;
|
_storageProvider = storageProvider;
|
||||||
_rootPath = HttpContext.Current.Server.MapPath("~/Media");
|
_rootPath = HttpContext.Current.Server.MapPath("~/Media");
|
||||||
|
_rootUrl = Path.Combine(HttpContext.Current.Request.ApplicationPath, "Media").Replace("\\", "/");
|
||||||
Logger = NullLogger.Instance;
|
Logger = NullLogger.Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ILogger Logger { get; set; }
|
public ILogger Logger { get; set; }
|
||||||
|
|
||||||
|
public string GetRootUrl() {
|
||||||
|
return _rootUrl;
|
||||||
|
}
|
||||||
|
|
||||||
public IEnumerable<MediaFolder> GetMediaFolders(string path) {
|
public IEnumerable<MediaFolder> GetMediaFolders(string path) {
|
||||||
var mediaFolders = new List<MediaFolder>();
|
var mediaFolders = new List<MediaFolder>();
|
||||||
var folders = (
|
var folders = (
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
<script type="text/javascript" src="js/addmedia.js"></script>
|
<script type="text/javascript" src="js/addmedia.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<form action="/Admin/Media/Add" enctype="multipart/form-data" method="post">
|
<form enctype="multipart/form-data" method="post">
|
||||||
<div class="tabs">
|
<div class="tabs">
|
||||||
<ul>
|
<ul>
|
||||||
<li id="general_tab" class="current"><span><a href="#general_tab">{#addmedia_dlg.title}</a></span></li>
|
<li id="general_tab" class="current"><span><a href="#general_tab">{#addmedia_dlg.title}</a></span></li>
|
||||||
@@ -16,15 +16,14 @@
|
|||||||
<table border="0" cellpadding="4" cellspacing="0">
|
<table border="0" cellpadding="4" cellspacing="0">
|
||||||
<tr>
|
<tr>
|
||||||
<td class="nowrap"><label for="pageTitle">{#addmedia_dlg.path_label}</label></td>
|
<td class="nowrap"><label for="pageTitle">{#addmedia_dlg.path_label}</label></td>
|
||||||
<td><input id="MediaItemPath" name="MediaItemPath" type="file" class="text" value="Browse" size="64"/></td>
|
<td><input id="MediaItemPath" name="MediaItemPath" type="file" class="text" size="64" /></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<input type="hidden" id="FolderName" name="FolderName" value="foo" />
|
<input type="hidden" id="MediaPath" name="MediaPath" />
|
||||||
<input type="hidden" id="MediaPath" name="MediaPath" value="foo" />
|
|
||||||
</div>
|
</div>
|
||||||
<div class="mceActionPanel">
|
<div class="mceActionPanel">
|
||||||
<div style="float:left">
|
<div style="float:left">
|
||||||
<input name="__RequestVerificationToken" type="hidden" value="7lDAM51YOmke7sRNx/GFjVMKaPf8QZNh7qZiEdQyNQXKKbw1DYehU/g6jNcAx6I3OGD/KDuaNlmyNIeQ/69CFpDizom9bROgo5keYyj+HcAKHtjQTRV5kNJm6SztNLwO" />
|
<input name="__RequestVerificationToken" type="hidden" />
|
||||||
<input type="submit" name="insert" value="{#insert}" id="insert" />
|
<input type="submit" name="insert" value="{#insert}" id="insert" />
|
||||||
</div>
|
</div>
|
||||||
<div style="float:right">
|
<div style="float:right">
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
(function() {
|
(function() {
|
||||||
// Load plugin specific language pack
|
// Load plugin specific language pack
|
||||||
tinymce.PluginManager.requireLangPack('dlg');
|
tinymce.PluginManager.requireLangPack("addmedia");
|
||||||
|
|
||||||
tinymce.create('tinymce.plugins.Orchard.AddMedia', {
|
tinymce.create('tinymce.plugins.Orchard.AddMedia', {
|
||||||
/**
|
/**
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
ed.addCommand('mceAddMedia', function() {
|
ed.addCommand('mceAddMedia', function() {
|
||||||
ed.windowManager.open({
|
ed.windowManager.open({
|
||||||
file: url + '/addmedia.htm',
|
file: url + '/addmedia.htm',
|
||||||
width: 480 + parseInt(ed.getLang('addmedia.delta_width', 0)),
|
width: 550 + parseInt(ed.getLang('addmedia.delta_width', 0)),
|
||||||
height: 110 + parseInt(ed.getLang('addmedia.delta_height', 0)),
|
height: 110 + parseInt(ed.getLang('addmedia.delta_height', 0)),
|
||||||
inline: 1
|
inline: 1
|
||||||
}, {
|
}, {
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
// Register example button
|
// Register example button
|
||||||
ed.addButton('addmedia', {
|
ed.addButton('addmedia', {
|
||||||
title: 'addmedia_desc',
|
title: ed.getLang('addmedia.title'),
|
||||||
cmd: 'mceAddMedia',
|
cmd: 'mceAddMedia',
|
||||||
image: url + '/img/picture_add.png'
|
image: url + '/img/picture_add.png'
|
||||||
});
|
});
|
||||||
|
@@ -1 +1,12 @@
|
|||||||
tinyMCEPopup.requireLangPack();
|
tinyMCEPopup.requireLangPack("addmedia");
|
||||||
|
|
||||||
|
var AddMediaDialog = {
|
||||||
|
init: function() {
|
||||||
|
var form = document.forms[0];
|
||||||
|
form.action = tinyMCE.activeEditor.getParam('addmedia_action');
|
||||||
|
form.MediaPath.value = tinyMCE.activeEditor.getParam('addmedia_path');
|
||||||
|
form.__RequestVerificationToken.value = tinyMCE.activeEditor.getParam('request_verification_token');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
tinyMCEPopup.onInit.add(AddMediaDialog.init, AddMediaDialog);
|
@@ -0,0 +1,6 @@
|
|||||||
|
tinyMCE.addI18n({ en: {
|
||||||
|
addmedia: {
|
||||||
|
title: "Add Media"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
@@ -1,4 +1,9 @@
|
|||||||
tinyMCE.addI18n('en.addmedia_dlg',{
|
tinyMCE.addI18n({ en: {
|
||||||
title:"Add Media",
|
addmedia_dlg: {
|
||||||
path_label:"Media File Path"
|
button_title: "Add Media",
|
||||||
|
title: "Add Media",
|
||||||
|
path_label: "Media File Path",
|
||||||
|
browse_button_text: "Browse"
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
@@ -140,6 +140,7 @@
|
|||||||
<Content Include="Scripts\plugins\addmedia\img\picture_add.png" />
|
<Content Include="Scripts\plugins\addmedia\img\picture_add.png" />
|
||||||
<Content Include="Scripts\plugins\addmedia\js\addmedia.js" />
|
<Content Include="Scripts\plugins\addmedia\js\addmedia.js" />
|
||||||
<Content Include="Scripts\plugins\addmedia\langs\en_dlg.js" />
|
<Content Include="Scripts\plugins\addmedia\langs\en_dlg.js" />
|
||||||
|
<Content Include="Scripts\plugins\addmedia\langs\en.js" />
|
||||||
<Content Include="Scripts\plugins\searchreplace\css\searchreplace.css" />
|
<Content Include="Scripts\plugins\searchreplace\css\searchreplace.css" />
|
||||||
<Content Include="Scripts\plugins\searchreplace\editor_plugin.js" />
|
<Content Include="Scripts\plugins\searchreplace\editor_plugin.js" />
|
||||||
<Content Include="Scripts\plugins\searchreplace\editor_plugin_src.js" />
|
<Content Include="Scripts\plugins\searchreplace\editor_plugin_src.js" />
|
||||||
|
@@ -12,7 +12,10 @@
|
|||||||
theme_advanced_toolbar_align: "left",
|
theme_advanced_toolbar_align: "left",
|
||||||
theme_advanced_buttons1: "search,replace,|,cut,copy,paste,|,undo,redo,|,image,addmedia,|,link,unlink,charmap,emoticon,codeblock,|,bold,italic,|,numlist,bullist,formatselect,|,code,fullscreen",
|
theme_advanced_buttons1: "search,replace,|,cut,copy,paste,|,undo,redo,|,image,addmedia,|,link,unlink,charmap,emoticon,codeblock,|,bold,italic,|,numlist,bullist,formatselect,|,code,fullscreen",
|
||||||
theme_advanced_buttons2: "",
|
theme_advanced_buttons2: "",
|
||||||
theme_advanced_buttons3: ""
|
theme_advanced_buttons3: "",
|
||||||
|
addmedia_action: "<%=Url.Action("AddFromClient", "Admin", new {area = "Orchard.Media"}) %>",
|
||||||
|
addmedia_path: "some/folder",
|
||||||
|
request_verification_token: "<%=Html.AntiForgeryTokenValueOrchard() %>"
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<%}%>
|
<%}%>
|
||||||
|
Reference in New Issue
Block a user