mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-11-28 17:32:44 +08:00
Adding alternate creation gesture
--HG-- branch : dev
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.FileSystems.WebSite;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Security;
|
||||
using Orchard.Mvc.Extensions;
|
||||
using Orchard.Themes;
|
||||
|
||||
namespace Orchard.DesignerTools.Controllers
|
||||
{
|
||||
[Themed]
|
||||
public class AlternateController : Controller {
|
||||
private readonly IWebSiteFolder _webSiteFolder;
|
||||
private readonly IThemeManager _themeManager;
|
||||
|
||||
public AlternateController(IOrchardServices orchardServices, IWebSiteFolder webSiteFolder, IThemeManager themeManager) {
|
||||
_webSiteFolder = webSiteFolder;
|
||||
_themeManager = themeManager;
|
||||
Services = orchardServices;
|
||||
}
|
||||
|
||||
public IOrchardServices Services { get; set; }
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public ActionResult Create(string template, string alternate, string returnUrl) {
|
||||
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to create templates")) && !Request.IsLocal)
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
alternate = alternate.Replace("__", "-").Replace("_", ".");
|
||||
|
||||
var currentTheme = _themeManager.GetRequestTheme(Request.RequestContext);
|
||||
var alternateFilename = Server.MapPath(Path.Combine(currentTheme.Location, currentTheme.Id, "Views", alternate));
|
||||
|
||||
// use same extension as template, or ".cshtml" if it's a code template))
|
||||
if (System.IO.File.Exists(template)) {
|
||||
alternateFilename += Path.GetExtension(template);
|
||||
|
||||
using (var stream = System.IO.File.Create(alternateFilename)) {
|
||||
_webSiteFolder.CopyFileTo(template, stream);
|
||||
}
|
||||
}
|
||||
else {
|
||||
alternateFilename += ".cshtml";
|
||||
using (System.IO.File.Create(alternateFilename)) {}
|
||||
}
|
||||
|
||||
return this.RedirectLocal(returnUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,6 +100,7 @@
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Controllers\AlternateController.cs" />
|
||||
<Compile Include="Services\ObjectDumper.cs" />
|
||||
<Compile Include="Services\ShapeTracingFactory.cs" />
|
||||
<Compile Include="Services\UrlAlternatesFactory.cs" />
|
||||
@@ -108,7 +109,6 @@
|
||||
<Content Include="Views\ShapeTracingWrapper.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Controllers\" />
|
||||
<Folder Include="Models\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -37,20 +37,23 @@ namespace Orchard.DesignerTools.Services {
|
||||
}
|
||||
|
||||
_parents.Push(o);
|
||||
// starts a new container
|
||||
_node.Add(_node = new XElement("li"));
|
||||
try {
|
||||
// starts a new container
|
||||
_node.Add(_node = new XElement("li"));
|
||||
|
||||
if(o == null) {
|
||||
DumpValue(null, name);
|
||||
if (o == null) {
|
||||
DumpValue(null, name);
|
||||
}
|
||||
else if (o.GetType().IsValueType || o is string) {
|
||||
DumpValue(o, name);
|
||||
}
|
||||
else {
|
||||
DumpObject(o, name);
|
||||
}
|
||||
}
|
||||
else if (o.GetType().IsValueType || o is string) {
|
||||
DumpValue(o, name);
|
||||
finally {
|
||||
_parents.Pop();
|
||||
}
|
||||
else {
|
||||
DumpObject(o, name);
|
||||
}
|
||||
|
||||
_parents.Pop();
|
||||
|
||||
if(_node.DescendantNodes().Count() == 0) {
|
||||
_node.Remove();
|
||||
|
||||
@@ -252,4 +252,13 @@
|
||||
|
||||
#shape-tracing-window-content .shape-tracing-breadcrumb {
|
||||
margin: 3px 0px;
|
||||
}
|
||||
|
||||
button.create-template, background-image :hover {
|
||||
padding:0;
|
||||
margin:0;
|
||||
background-color:transparent;
|
||||
background-image:none;
|
||||
border:0;
|
||||
display:inline;
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
@functions {
|
||||
@using Orchard.Utility.Extensions;
|
||||
|
||||
@functions {
|
||||
string FormatShapeFilename(string type, string themeId) {
|
||||
return "~/Themes/" + themeId + "/Views/" + type.Replace("__", "-").Replace("_", ".") + ".cshtml";
|
||||
}
|
||||
@@ -13,7 +15,6 @@
|
||||
return regex.Replace(htmlContent, System.Environment.NewLine);
|
||||
}
|
||||
}
|
||||
|
||||
<div class="shape-tracing-meta" shape-id-meta="@Model.ShapeId" style="display:none">
|
||||
<ul class="shape-tracing-tabs">
|
||||
<li class="shape selected first"><a href="#">Shape</a></li>
|
||||
@@ -34,17 +35,27 @@
|
||||
<li class="sgd-a"><div class="name">Alternates (@Model.Alternates.Count)</div>
|
||||
<div class="value"> </div>
|
||||
<ul>
|
||||
@foreach(var alternate in Model.Alternates) {
|
||||
@foreach (var alternate in Model.Alternates) {
|
||||
var formatted = @FormatShapeFilename(alternate, WorkContext.CurrentTheme.Id);
|
||||
<li><div class="name"> </div><div class="value">@formatted</div></li>
|
||||
}
|
||||
<li>
|
||||
<div class="name">
|
||||
@using (Html.BeginFormAntiForgeryPost(Url.Action("Create", "Alternate", new { Area = "Orchard.DesignerTools" }), FormMethod.Post, new { @class = "inline link" })) {
|
||||
@Html.Hidden("Alternate", (string)alternate)
|
||||
@Html.Hidden("Template", (string)Model.Template)
|
||||
@Html.Hidden("ReturnUrl", Context.Request.RawUrl)
|
||||
<button type="submit" class="create-template">@T("Create").Text</button>
|
||||
}
|
||||
</div>
|
||||
<div class="value">@formatted</div>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</li>
|
||||
<li class="sgd-w"><div class="name">Wrappers (@Model.Wrappers.Count)</div>
|
||||
<div class="value"> </div>
|
||||
<ul>
|
||||
@foreach(var wrapper in Model.Wrappers) {
|
||||
if(wrapper != "ShapeTracing_Wrapper") {
|
||||
@foreach (var wrapper in Model.Wrappers) {
|
||||
if (wrapper != "ShapeTracing_Wrapper") {
|
||||
var formatted = @FormatShapeFilename(wrapper, WorkContext.CurrentTheme.Id);
|
||||
<li><div class="name"> </div><div class="value">@formatted</div></li>
|
||||
}
|
||||
@@ -65,7 +76,16 @@
|
||||
</div>
|
||||
|
||||
<div class="template" style="display:none">
|
||||
<textarea id="template-@Model.ShapeId" name="template-@Model.ShapeId">@Model.TemplateContent</textarea>
|
||||
<div class="shape-tracing-breadcrumb">@Model.Template</div>
|
||||
@if (String.IsNullOrWhiteSpace((string)Model.TemplateContent)) {
|
||||
if (!String.IsNullOrWhiteSpace((string)Model.Template)) {
|
||||
@T("Content not available as coming from source code.")
|
||||
}
|
||||
}
|
||||
else {
|
||||
<textarea id="template-@Model.ShapeId" name="template-@Model.ShapeId">@Model.TemplateContent</textarea>
|
||||
}
|
||||
|
||||
</div>
|
||||
|
||||
<div class="html" style="display:none">
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Foo
|
||||
Reference in New Issue
Block a user