mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Converting Futures.Widgets module
--HG-- branch : dev
This commit is contained in:
@@ -1,20 +0,0 @@
|
||||
using System.Web.Routing;
|
||||
using Futures.Widgets.Models;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
|
||||
namespace Futures.Widgets.Drivers {
|
||||
public class WidgetsPartDriver : ContentItemDriver<WidgetPart> {
|
||||
public override RouteValueDictionary GetEditorRouteValues(WidgetPart item) {
|
||||
return new RouteValueDictionary {
|
||||
{"Area", "Futures.Widgets"},
|
||||
{"Controller", "Admin"},
|
||||
{"Action", "Edit"},
|
||||
{"Id", item.ContentItem.Id}
|
||||
};
|
||||
}
|
||||
|
||||
protected override bool UseDefaultTemplate {
|
||||
get { return true; }
|
||||
}
|
||||
}
|
||||
}
|
@@ -39,6 +39,7 @@
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Web.ApplicationServices" />
|
||||
@@ -71,7 +72,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Module.txt" />
|
||||
<Content Include="Views\Admin\Edit.ascx" />
|
||||
<None Include="Views\Admin\Edit.cshtml" />
|
||||
<Content Include="Web.config" />
|
||||
<Content Include="Views\Web.config" />
|
||||
</ItemGroup>
|
||||
|
@@ -1,8 +1,7 @@
|
||||
using Orchard.Mvc.ViewModels;
|
||||
|
||||
|
||||
namespace Futures.Widgets.ViewModels {
|
||||
public class WidgetEditViewModel : BaseViewModel {
|
||||
public ContentItemViewModel Widget { get; set; }
|
||||
public class WidgetEditViewModel {
|
||||
public dynamic Widget { get; set; }
|
||||
public string ReturnUrl { get; set;}
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +0,0 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<WidgetEditViewModel>" %>
|
||||
<%@ Import Namespace="Futures.Widgets.ViewModels" %>
|
||||
<h1><%: Html.TitleForPage(T("Edit Widget").ToString()) %></h1>
|
||||
<% using (Html.BeginFormAntiForgeryPost()) { %>
|
||||
<%: Html.ValidationSummary() %>
|
||||
<%: Html.EditorForItem(m => m.Widget) %>
|
||||
<fieldset>
|
||||
<%: Html.HiddenFor(m => m.ReturnUrl) %>
|
||||
<input class="button primaryAction" type="submit" name="submit.Save" value="Save"/>
|
||||
</fieldset>
|
||||
<%} %>
|
@@ -0,0 +1,9 @@
|
||||
@model Futures.Widgets.ViewModels.WidgetEditViewModel
|
||||
|
||||
<h1>@Html.TitleForPage(T("Edit Widget").ToString())</h1>
|
||||
|
||||
@using (Html.BeginFormAntiForgeryPost()) {
|
||||
@Html.ValidationSummary()
|
||||
@Display(Model.Widget)
|
||||
@Html.HiddenFor(m => m.ReturnUrl)
|
||||
}
|
@@ -1,40 +1,44 @@
|
||||
using System.Web.Mvc;
|
||||
using Futures.Widgets.Models;
|
||||
using Orchard;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Mvc.Filters;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
using Orchard.Settings;
|
||||
using Orchard.UI.Admin;
|
||||
|
||||
namespace Futures.Widgets {
|
||||
public class WidgetFilter : FilterProvider, IActionFilter {
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IWorkContextAccessor _workContextAccessor;
|
||||
|
||||
public WidgetFilter(IContentManager contentManager) {
|
||||
public WidgetFilter(IContentManager contentManager, IWorkContextAccessor workContextAccessor) {
|
||||
_contentManager = contentManager;
|
||||
_workContextAccessor = workContextAccessor;
|
||||
}
|
||||
|
||||
public virtual ISite CurrentSite { get; set; }
|
||||
|
||||
public void OnActionExecuting(ActionExecutingContext filterContext) {
|
||||
}
|
||||
|
||||
public void OnActionExecuted(ActionExecutedContext filterContext) {
|
||||
var model = BaseViewModel.From(filterContext.Result);
|
||||
if (model == null || AdminFilter.IsApplied(filterContext.RequestContext)) {
|
||||
var workContext = _workContextAccessor.GetContext(filterContext);
|
||||
|
||||
if (workContext == null ||
|
||||
workContext.Page == null ||
|
||||
workContext.CurrentSite == null ||
|
||||
AdminFilter.IsApplied(filterContext.RequestContext)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var siteWidgets = CurrentSite.As<WidgetsPart>();
|
||||
var siteWidgets = workContext.CurrentSite.As<WidgetsPart>();
|
||||
if (siteWidgets == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var zones = model.Zones;
|
||||
var zones = workContext.Page.Zones;
|
||||
foreach (var widget in siteWidgets.Widgets) {
|
||||
zones.AddDisplayItem(
|
||||
widget.Record.Zone + ":" + widget.Record.Position,
|
||||
_contentManager.BuildDisplayModel(widget, "Widget"));
|
||||
var widgetShape = _contentManager.BuildDisplayModel(widget);
|
||||
|
||||
zones[widget.Record.Zone].Add(widgetShape, widget.Record.Position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -90,9 +90,9 @@ namespace Orchard.Setup.Services {
|
||||
"Orchard.Comments",
|
||||
"Orchard.Tags",
|
||||
"Orchard.Media",
|
||||
//"Futures.Widgets"
|
||||
"Futures.Widgets",
|
||||
|
||||
"Orchard.DevTools"
|
||||
"Orchard.DevTools",
|
||||
};
|
||||
|
||||
context.EnabledFeatures = hardcoded;
|
||||
|
Reference in New Issue
Block a user