mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-24 05:23:33 +08:00
Finishing up the initial functionality for the addmedia (tinyMCE) plugin
--HG-- branch : dev
This commit is contained in:
@@ -168,7 +168,7 @@ namespace Orchard.Media.Controllers {
|
|||||||
return Content(string.Format("<script type=\"text/javascript\">var result = {{ error: \"{0}\" }};</script>", T("ERROR: You don't have permission to upload media files")));
|
return Content(string.Format("<script type=\"text/javascript\">var result = {{ error: \"{0}\" }};</script>", T("ERROR: You don't have permission to upload media files")));
|
||||||
|
|
||||||
if (Request.Files.Count < 1 || Request.Files[0].ContentLength == 0)
|
if (Request.Files.Count < 1 || Request.Files[0].ContentLength == 0)
|
||||||
return Content(string.Format("<scipt type=\"text/javascript\">var result = {{ error: \"{0}\" }};</script>", T("HEY: You didn't give me a file to upload")));
|
return Content(string.Format("<script type=\"text/javascript\">var result = {{ error: \"{0}\" }};</script>", T("HEY: You didn't give me a file to upload")));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
_mediaService.GetMediaFiles(viewModel.MediaPath);
|
_mediaService.GetMediaFiles(viewModel.MediaPath);
|
||||||
@@ -181,7 +181,7 @@ namespace Orchard.Media.Controllers {
|
|||||||
var file = Request.Files[0];
|
var file = Request.Files[0];
|
||||||
_mediaService.UploadMediaFile(viewModel.MediaPath, file);
|
_mediaService.UploadMediaFile(viewModel.MediaPath, file);
|
||||||
|
|
||||||
return Content(string.Format("<script type=\"text/javascript\">var result = {{ url: \"{0}\" }};</script>", Path.Combine(_mediaService.GetRootUrl(), string.Format("{0}/{1}", viewModel.MediaPath, Path.GetFileName(file.FileName))).Replace("\\", "/")));
|
return Content(string.Format("<script type=\"text/javascript\">var result = {{ url: \"{0}\" }};</script>", Path.Combine(_mediaService.GetRootUrl(), string.Format("{0}/{1}", viewModel.MediaPath, Path.GetFileName(file.FileName)).Replace("//", "/")).Replace("\\", "/")));
|
||||||
}
|
}
|
||||||
catch (Exception exception) {
|
catch (Exception exception) {
|
||||||
return Content(string.Format("<script type=\"text/javascript\">var result = {{ error: \"{0}\" }};</script>", T("ERROR: Uploading media file failed: {0}", exception.Message)));
|
return Content(string.Format("<script type=\"text/javascript\">var result = {{ error: \"{0}\" }};</script>", T("ERROR: Uploading media file failed: {0}", exception.Message)));
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using System.Web.UI;
|
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.ContentManagement.Drivers;
|
using Orchard.ContentManagement.Drivers;
|
||||||
using Orchard.Core.Common.Models;
|
using Orchard.Core.Common.Models;
|
||||||
@@ -17,8 +16,7 @@ namespace TinyMce.Extensions {
|
|||||||
var currentModule = htmlHelper.Resolve<IExtensionManager>().ActiveExtensions().FirstOrDefault(ee => ee.Descriptor.ExtensionType == "Module" && ee.Assembly == currentDriver.GetType().Assembly);
|
var currentModule = htmlHelper.Resolve<IExtensionManager>().ActiveExtensions().FirstOrDefault(ee => ee.Descriptor.ExtensionType == "Module" && ee.Assembly == currentDriver.GetType().Assembly);
|
||||||
var routable = body.ContentItem.Has<RoutableAspect>() ? body.ContentItem.As<RoutableAspect>() : null;
|
var routable = body.ContentItem.Has<RoutableAspect>() ? body.ContentItem.As<RoutableAspect>() : null;
|
||||||
|
|
||||||
//TODO: (erikpo) Get the value for the media folder from settings instead of hardcoding it
|
return string.Format("{0}{1}", currentModule.Descriptor.Name, routable != null && !string.IsNullOrEmpty(routable.ContainerPath) ? "/" + routable.ContainerPath : "");
|
||||||
return ((Control)htmlHelper.ViewDataContainer).ResolveUrl(string.Format("{0}/{1}{2}", "~/Media", currentModule.Descriptor.Name, routable != null && !string.IsNullOrEmpty(routable.ContainerPath) ? "/" + routable.ContainerPath : ""));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -12,7 +12,7 @@
|
|||||||
* @param {string} url Absolute URL to where the plugin is located.
|
* @param {string} url Absolute URL to where the plugin is located.
|
||||||
*/
|
*/
|
||||||
init: function(ed, url) {
|
init: function(ed, url) {
|
||||||
// Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('mceExample');
|
// Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('mceAddMedia');
|
||||||
ed.addCommand('mceAddMedia', function() {
|
ed.addCommand('mceAddMedia', function() {
|
||||||
ed.windowManager.open({
|
ed.windowManager.open({
|
||||||
file: url + '/addmedia.htm',
|
file: url + '/addmedia.htm',
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Register example button
|
// Register addmedia button
|
||||||
ed.addButton('addmedia', {
|
ed.addButton('addmedia', {
|
||||||
title: ed.getLang('addmedia.title'),
|
title: ed.getLang('addmedia.title'),
|
||||||
cmd: 'mceAddMedia',
|
cmd: 'mceAddMedia',
|
||||||
|
@@ -10,44 +10,53 @@ var AddMediaDialog = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
addMedia: function(form) {
|
addMedia: function(form) {
|
||||||
var callback = AddMediaDialog.insertMediaAndClose;
|
|
||||||
var iframeName = "addmedia__" + (new Date()).getTime()
|
var iframeName = "addmedia__" + (new Date()).getTime()
|
||||||
var iframe = document.createElement("iframe");
|
var iframe = document.createElement("iframe");
|
||||||
iframe.name = iframeName;
|
iframe.name = iframeName;
|
||||||
iframe.src = "about:blank";
|
iframe.src = "about:blank";
|
||||||
|
|
||||||
tinymce.DOM.setStyles(iframe, { display: "none" });
|
tinymce.DOM.setStyles(iframe, { display: "none" });
|
||||||
tinymce.dom.Event.add(iframe, 'load', function(ev) {
|
var iframeLoadHandler = tinymce.dom.Event.add(iframe, 'load', function(ev) {
|
||||||
var result = window.frames[iframeName].result;
|
var result = window.frames[iframeName].result, close = 0;
|
||||||
if (result && result.url) {
|
if (result && result.url) {
|
||||||
return callback(result.url);
|
window.parent.AddMediaDialog.insertMedia(result.url);
|
||||||
} else if (false && result && result.error) {
|
close = 1;
|
||||||
alert("Wait, there was an error:\n\r\n\r" + result.error);
|
} else if (result && result.error) {
|
||||||
|
alert(tinyMCEPopup.getLang("addmedia_dlg.msg_error") + "\n\r\n\r" + result.error);
|
||||||
} else {
|
} else {
|
||||||
var somethingPotentiallyHorrible = window.frames[iframeName].document.getElementsByTagName("body")[0].innerHTML;
|
var somethingPotentiallyHorrible = "";
|
||||||
|
try {
|
||||||
|
somethingPotentiallyHorrible = window.frames[iframeName].document.getElementsByTagName("body")[0].innerHTML;
|
||||||
|
} catch (ex) { // some browsers flip out trying to access anything in the iframe when there's an error. best we can do is guess at this point
|
||||||
|
somethingPotentiallyHorrible = tinyMCEPopup.getLang("addmedia_dlg.msg_error_unknown");
|
||||||
|
}
|
||||||
if (somethingPotentiallyHorrible) {
|
if (somethingPotentiallyHorrible) {
|
||||||
alert("Something unexpected happened:\n\r\n\r" + somethingPotentiallyHorrible);
|
alert(tinyMCEPopup.getLang("addmedia_dlg.msg_error_unexpected") + "\n\r\n\r" + somethingPotentiallyHorrible);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//cleanup
|
//cleanup
|
||||||
setTimeout(function() { callback = null; tinymce.DOM.remove(iframe); }, 123);
|
setTimeout(function() {
|
||||||
|
tinymce.dom.Event.remove(iframe, 'load', iframeLoadHandler);
|
||||||
|
tinymce.DOM.remove(iframe);
|
||||||
|
iframe = null;
|
||||||
|
if (close) window.parent.tinyMCEPopup.close();
|
||||||
|
},
|
||||||
|
123);
|
||||||
});
|
});
|
||||||
|
|
||||||
form.target = iframeName;
|
form.target = iframeName;
|
||||||
tinymce.DOM.add(document.body, iframe);
|
tinymce.DOM.add(document.body, iframe);
|
||||||
},
|
},
|
||||||
|
|
||||||
insertMediaAndClose: function(url) {
|
insertMedia: function(url) {
|
||||||
if (!url) return;
|
if (!url) return;
|
||||||
|
|
||||||
//todo: (heskew) needs more awesome
|
|
||||||
var markup = /\.(jpe?g|png|gif)$/i.test(url)
|
var markup = /\.(jpe?g|png|gif)$/i.test(url)
|
||||||
? "<img src=\"" + url + "\" />"
|
? "<img src=\"" + url + "\" />"
|
||||||
: "<a href=\"" + url + "\">" + url + "</a>";
|
: "<a href=\"" + url + "\">" + url + "</a>";
|
||||||
|
|
||||||
tinyMCE.activeEditor.execCommand("mceInsertContent", false, markup);
|
tinyMCE.activeEditor.execCommand("mceInsertContent", false, markup);
|
||||||
tinyMCEPopup.close();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -3,7 +3,10 @@ tinyMCE.addI18n({ en: {
|
|||||||
button_title: "Add Media",
|
button_title: "Add Media",
|
||||||
title: "Add Media",
|
title: "Add Media",
|
||||||
path_label: "Media File Path",
|
path_label: "Media File Path",
|
||||||
browse_button_text: "Browse"
|
browse_button_text: "Browse",
|
||||||
|
msg_error: "Wait, there was an error:",
|
||||||
|
msg_error_unexpected: "Something unexpected happened:",
|
||||||
|
msg_error_unknown: "Can't get the error from the response. This can happen when the server throws an error. Is the file size larger than what the server is configured to accept?"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
@@ -17,6 +17,7 @@ using (this.Capture("end-of-page-scripts")) {%>
|
|||||||
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: "",
|
||||||
|
convert_urls: false,
|
||||||
addmedia_action: "<%=Url.Action("AddFromClient", "Admin", new {area = "Orchard.Media"}) %>",
|
addmedia_action: "<%=Url.Action("AddFromClient", "Admin", new {area = "Orchard.Media"}) %>",
|
||||||
addmedia_path: "<%=Html.GetCurrentMediaPath() %>",
|
addmedia_path: "<%=Html.GetCurrentMediaPath() %>",
|
||||||
request_verification_token: "<%=Html.AntiForgeryTokenValueOrchard() %>"
|
request_verification_token: "<%=Html.AntiForgeryTokenValueOrchard() %>"
|
||||||
|
Reference in New Issue
Block a user