Providing designer notes html for zones

IZoneManagerEvents interface added to inject designer notes in empty zones
Static html file matching zone names displayed when nothing else is in that location
An Edit link simulates the look of an html widget
Clicking it creates a widget with the designer notes html
Code that calculates media path refactored and moved to viewmodel state

--HG--
branch : dev
This commit is contained in:
Louis DeJardin
2010-03-06 01:25:17 -08:00
parent dab326c267
commit 0320862826
20 changed files with 271 additions and 96 deletions

View File

@@ -1,5 +1,4 @@
using System;
using System.Web.Mvc;
using System.Web.Mvc;
using Futures.Widgets.Models;
using Futures.Widgets.ViewModels;
using Orchard;
@@ -7,28 +6,39 @@ using Orchard.ContentManagement;
using Orchard.Core.Common.Models;
using Orchard.Localization;
using Orchard.Settings;
using Orchard.UI.Notify;
namespace Futures.Widgets.Controllers {
[ValidateInput(false)]
public class AdminController : Controller, IUpdateModel {
public AdminController(IOrchardServices services) {
Services = services;
T = NullLocalizer.Instance;
}
private IOrchardServices Services { get; set; }
protected virtual ISite CurrentSite { get; set; }
public Localizer T{ get; set;}
public ActionResult AddWidget() {
public ActionResult AddWidget(string zoneName, string themeName, string returnUrl) {
var hasWidgetsRecord = CurrentSite.As<HasWidgets>().Record;
var virtualPath = "~/Themes/" + themeName + "/DesignerNotes/" + zoneName + ".html";
var physicalPath = Server.MapPath(virtualPath);
if (!System.IO.File.Exists(physicalPath)) {
Services.Notifier.Error(T("Designer notes not found."));
return Redirect(returnUrl);
}
var widget = Services.ContentManager.Create<Widget>("HtmlWidget", init => {
init.Record.Scope = hasWidgetsRecord;
init.Record.Zone = "content";
init.Record.Position = "after";
init.As<BodyAspect>().Text = "Hello world!";
init.Record.Zone = zoneName;
init.Record.Position = "1";
init.As<BodyAspect>().Text = System.IO.File.ReadAllText(physicalPath);
});
return RedirectToAction("Edit", new {widget.ContentItem.Id });
return RedirectToAction("Edit", new { widget.ContentItem.Id, returnUrl });
}
public ActionResult Edit(int id, string returnUrl) {

View File

@@ -1,22 +0,0 @@
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}", currentModule.Descriptor.Name, routable != null && !string.IsNullOrEmpty(routable.ContainerPath) ? "/" + routable.ContainerPath : "");
}
}
}

View File

@@ -122,7 +122,6 @@
<Content Include="Scripts\utils\validate.js" />
</ItemGroup>
<ItemGroup>
<Compile Include="Extensions\HtmlHelperExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>

View File

@@ -19,7 +19,7 @@ using (this.Capture("end-of-page-scripts")) {%>
theme_advanced_buttons3: "",
convert_urls: false,
addmedia_action: "<%=Url.Action("AddFromClient", "Admin", new {area = "Orchard.Media"}) %>",
addmedia_path: "<%=Html.GetCurrentMediaPath() %>",
addmedia_path: "<%= Model.AddMediaPath %>",
request_verification_token: "<%=Html.AntiForgeryTokenValueOrchard() %>"
});
</script><%