mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 11:44:58 +08:00
Added a html helper to generate a media path for tinymce
--HG-- branch : dev
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Core.Common.ViewModels;
|
||||
using Orchard.Extensions;
|
||||
using Orchard.Mvc.Html;
|
||||
|
||||
namespace TinyMce.Extensions {
|
||||
public static class HtmlHelperExtensions {
|
||||
public static string GetCurrentMediaPath(this HtmlHelper<BodyEditorViewModel> htmlHelper) {
|
||||
var body = htmlHelper.ViewData.Model.BodyAspect;
|
||||
var currentDriver = htmlHelper.Resolve<IEnumerable<IContentItemDriver>>().Where(cid => cid.GetContentTypes().Any(ct => string.Compare(ct.Name, body.ContentItem.ContentType, true) == 0)).FirstOrDefault();
|
||||
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;
|
||||
|
||||
return string.Format("{0}/{1}{2}", "~/Media", currentModule.Descriptor.Name, routable != null && !string.IsNullOrEmpty(routable.ContainerPath) ? "/" + routable.ContainerPath : "");
|
||||
}
|
||||
}
|
||||
}
|
@@ -122,6 +122,7 @@
|
||||
<Content Include="Scripts\utils\validate.js" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Extensions\HtmlHelperExtensions.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -133,6 +134,10 @@
|
||||
<Project>{2D1D92BB-4555-4CBE-8D0E-63563D6CE4C6}</Project>
|
||||
<Name>Orchard</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\Core\Orchard.Core.csproj">
|
||||
<Project>{9916839C-39FC-4CEB-A5AF-89CA7E87119F}</Project>
|
||||
<Name>Orchard.Core</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Scripts\plugins\addmedia\addmedia.htm" />
|
||||
|
@@ -1,7 +1,11 @@
|
||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<string>" %>
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<string>" %>
|
||||
<%@ Import Namespace="TinyMce.Extensions"%>
|
||||
<%@ Import Namespace="Orchard.Core.Common.ViewModels"%>
|
||||
<% Html.RegisterScript("tiny_mce.js"); %>
|
||||
<%=Html.TextArea("", Model, 25, 80, new { @class = "html" }) %>
|
||||
<%using (this.Capture("end-of-page-scripts")) {%>
|
||||
|
||||
<%
|
||||
using (this.Capture("end-of-page-scripts")) {%>
|
||||
<script type="text/javascript">
|
||||
tinyMCE.init({
|
||||
theme: "advanced",
|
||||
@@ -14,8 +18,8 @@
|
||||
theme_advanced_buttons2: "",
|
||||
theme_advanced_buttons3: "",
|
||||
addmedia_action: "<%=Url.Action("AddFromClient", "Admin", new {area = "Orchard.Media"}) %>",
|
||||
addmedia_path: "some/folder",
|
||||
addmedia_path: "somepath",
|
||||
request_verification_token: "<%=Html.AntiForgeryTokenValueOrchard() %>"
|
||||
});
|
||||
</script>
|
||||
<%}%>
|
||||
</script><%
|
||||
}%>
|
Reference in New Issue
Block a user