Merge branch '1.10.x' of https://github.com/LaserSrl/Orchard into Laser/1.10.x

This commit is contained in:
HermesSbicego-Laser 2016-10-28 16:32:52 +02:00
commit 708ed79ccb
20 changed files with 286 additions and 240 deletions

View File

@ -1,36 +1,24 @@
using System;
using System.Linq;
using Orchard.Blogs.Models;
using Orchard.Blogs.Services;
using Orchard.Commands;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects;
using Orchard.Core.Common.Models;
using Orchard.Security;
using Orchard.Settings;
using Orchard.Widgets.Models;
using Orchard.Widgets.Services;
namespace Orchard.Blogs.Commands {
public class BlogWidgetCommands : DefaultOrchardCommandHandler {
private readonly IWidgetsService _widgetsService;
private readonly IWidgetCommandsService _widgetCommandsService;
private readonly IBlogService _blogService;
private readonly ISiteService _siteService;
private readonly IMembershipService _membershipService;
private readonly IContentManager _contentManager;
private BlogPart blog;
public BlogWidgetCommands(
IWidgetsService widgetsService,
IWidgetCommandsService widgetCommandsService,
IBlogService blogService,
ISiteService siteService,
IMembershipService membershipService,
IContentManager contentManager) {
_widgetsService = widgetsService;
_widgetCommandsService = widgetCommandsService;
_blogService = blogService;
_siteService = siteService;
_membershipService = membershipService;
_contentManager = contentManager;
RenderTitle = true;
@ -75,11 +63,21 @@ namespace Orchard.Blogs.Commands {
public void CreateRecentBlogPostsWidget() {
var type = "RecentBlogPosts";
var widget = CreateStandardWidget(type);
// Check any custom parameters that could cause creating the widget to fail.
blog = GetBlog(BlogId, BlogPath);
if (blog == null) {
Context.Output.WriteLine(T("Creating {0} widget failed: blog was not found.", type));
return;
}
// Create the widget using the standard parameters.
var widget = _widgetCommandsService.CreateBaseWidget(
Context, type, Title, Name, Zone, Position, Layer, Identity, RenderTitle, Owner, null, false, null);
if (widget == null) {
return;
}
// Publish the successfully created widget.
widget.As<RecentBlogPostsPart>().BlogId = blog.Id;
// Setting count to 0 means all posts. It's an optional parameter and defaults to 5.
@ -90,7 +88,8 @@ namespace Orchard.Blogs.Commands {
}
}
_contentManager.Publish(widget.ContentItem);
// Publish the successfully created widget.
_widgetCommandsService.Publish(widget);
Context.Output.WriteLine(T("{0} widget created successfully.", type).Text);
}
@ -100,64 +99,28 @@ namespace Orchard.Blogs.Commands {
public void CreateBlogArchivesWidget() {
var type = "BlogArchives";
var widget = CreateStandardWidget(type);
// Check any custom parameters that could cause creating the widget to fail.
blog = GetBlog(BlogId, BlogPath);
if (blog == null) {
Context.Output.WriteLine(T("Creating {0} widget failed: blog was not found.", type));
return;
}
// Create the widget using the standard parameters.
var widget = _widgetCommandsService.CreateBaseWidget(
Context, type, Title, Name, Zone, Position, Layer, Identity, RenderTitle, Owner, null, false, null);
if (widget == null) {
return;
}
// Set the custom parameters.
widget.As<BlogArchivesPart>().BlogId = blog.Id;
_contentManager.Publish(widget.ContentItem);
// Publish the successfully created widget.
_widgetCommandsService.Publish(widget);
Context.Output.WriteLine(T("{0} widget created successfully.", type).Text);
}
private WidgetPart CreateStandardWidget(string type) {
var widgetTypeNames = _widgetsService.GetWidgetTypeNames().ToList();
if (!widgetTypeNames.Contains(type)) {
Context.Output.WriteLine(T("Creating widget failed: type {0} was not found. Supported widget types are: {1}.",
type,
string.Join(" ", widgetTypeNames)));
return null;
}
var layer = GetLayer(Layer);
if (layer == null) {
Context.Output.WriteLine(T("Creating {0} widget failed: layer {1} was not found.", type, Layer));
return null;
}
blog = GetBlog(BlogId, BlogPath);
if (blog == null) {
Context.Output.WriteLine(T("Creating {0} widget failed: blog was not found.", type));
return null;
}
var widget = _widgetsService.CreateWidget(layer.ContentItem.Id, type, T(Title).Text, Position, Zone);
if (!String.IsNullOrWhiteSpace(Name)) {
widget.Name = Name.Trim();
}
widget.RenderTitle = RenderTitle;
if (String.IsNullOrEmpty(Owner)) {
Owner = _siteService.GetSiteSettings().SuperUser;
}
var owner = _membershipService.GetUser(Owner);
widget.As<ICommonPart>().Owner = owner;
if (widget.Has<IdentityPart>() && !String.IsNullOrEmpty(Identity)) {
widget.As<IdentityPart>().Identifier = Identity;
}
return widget;
}
private LayerPart GetLayer(string layer) {
var layers = _widgetsService.GetLayers();
return layers.FirstOrDefault(layerPart => String.Equals(layerPart.Name, layer, StringComparison.OrdinalIgnoreCase));
}
private BlogPart GetBlog(int blogId, string blogPath) {
return _contentManager.Get<BlogPart>(blogId) ?? _blogService.Get(blogPath);
}

View File

@ -77,9 +77,13 @@ namespace Orchard.DynamicForms.Drivers {
}
protected override void OnDisplaying(EmailField element, ElementDisplayingContext context) {
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, context.GetTokenData());
context.ElementShape.ProcessedLabel = _tokenizer.Replace(element.Label, context.GetTokenData(), new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
context.ElementShape.ProcessedValue = element.RuntimeValue;
var tokenData = context.GetTokenData();
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, tokenData);
context.ElementShape.ProcessedLabel = _tokenizer.Replace(element.Label, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
// Allow the initial value to be tokenized.
// If a value was posted, use that value instead (without tokenizing it).
context.ElementShape.ProcessedValue = element.PostedValue != null ? element.PostedValue : _tokenizer.Replace(element.RuntimeValue, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
}
}
}

View File

@ -41,7 +41,13 @@ namespace Orchard.DynamicForms.Drivers {
Id: "InputType",
Name: "InputType",
Title: "Input Type",
Description: T("The control to render when presenting the list of options.")));
Description: T("The control to render when presenting the list of options.")),
_DefaultValue: shape.Textbox(
Id: "DefaultValue",
Name: "DefaultValue",
Title: "Default Value",
Classes: new[] { "text", "large", "tokenized" },
Description: T("The default value of this enumeration field.")));
form._InputType.Items.Add(new SelectListItem { Text = T("Select List").Text, Value = "SelectList" });
form._InputType.Items.Add(new SelectListItem { Text = T("Multi Select List").Text, Value = "MultiSelectList" });
@ -83,6 +89,13 @@ namespace Orchard.DynamicForms.Drivers {
var displayType = context.DisplayType;
var tokenData = context.GetTokenData();
// Allow the initially selected value to be tokenized.
// If a value was posted, use that value instead (without tokenizing it).
if (element.PostedValue == null) {
var defaultValue = _tokenizer.Replace(element.DefaultValue, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
element.RuntimeValue = defaultValue;
}
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, tokenData);
context.ElementShape.ProcessedLabel = _tokenizer.Replace(element.Label, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
context.ElementShape.ProcessedOptions = _tokenizer.Replace(element.Options, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode }).ToArray();

View File

@ -27,7 +27,7 @@ namespace Orchard.DynamicForms.Drivers {
Id: "Value",
Name: "Value",
Title: "Value",
Classes: new[] { "text", "medium" },
Classes: new[] { "text", "medium", "tokenized" },
Description: T("The value of this hidden field.")));
return form;
@ -35,8 +35,12 @@ namespace Orchard.DynamicForms.Drivers {
}
protected override void OnDisplaying(HiddenField element, ElementDisplayingContext context) {
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, context.GetTokenData());
context.ElementShape.ProcessedValue = element.RuntimeValue ?? string.Empty;
var tokenData = context.GetTokenData();
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, tokenData);
// Allow the initial value to be tokenized.
// If a value was posted, use that value instead (without tokenizing it).
context.ElementShape.ProcessedValue = element.PostedValue != null ? element.PostedValue : _tokenizer.Replace(element.RuntimeValue, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
}
}
}

View File

@ -68,6 +68,12 @@ namespace Orchard.DynamicForms.Drivers {
Value: "{Content.Id}",
Description: T("Specify the expression to get the value of each option."),
Classes: new[]{"text", "large", "tokenized"}),
_DefaultValue: shape.Textbox(
Id: "DefaultValue",
Name: "DefaultValue",
Title: "Default Value",
Classes: new[] { "text", "large", "tokenized" },
Description: T("The default value of this query field.")),
_InputType: shape.SelectList(
Id: "InputType",
Name: "InputType",
@ -122,6 +128,13 @@ namespace Orchard.DynamicForms.Drivers {
var displayType = context.DisplayType;
var tokenData = context.GetTokenData();
// Allow the initially selected value to be tokenized.
// If a value was posted, use that value instead (without tokenizing it).
if (element.PostedValue == null) {
var defaultValue = _tokenizer.Replace(element.DefaultValue, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
element.RuntimeValue = defaultValue;
}
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, tokenData);
context.ElementShape.ProcessedLabel = _tokenizer.Replace(element.Label, tokenData);
context.ElementShape.Options = GetOptions(element, context.DisplayType, queryId, tokenData).ToArray();

View File

@ -67,6 +67,12 @@ namespace Orchard.DynamicForms.Drivers {
Value: "{Content.Id}",
Description: T("Specify the expression to get the value of each option."),
Classes: new[] { "text", "large", "tokenized" }),
_DefaultValue: shape.Textbox(
Id: "DefaultValue",
Name: "DefaultValue",
Title: "Default Value",
Classes: new[] { "text", "large", "tokenized" },
Description: T("The default value of this query field.")),
_InputType: shape.SelectList(
Id: "InputType",
Name: "InputType",
@ -126,6 +132,13 @@ namespace Orchard.DynamicForms.Drivers {
var displayType = context.DisplayType;
var tokenData = context.GetTokenData();
// Allow the initially selected value to be tokenized.
// If a value was posted, use that value instead (without tokenizing it).
if (element.PostedValue == null) {
var defaultValue = _tokenizer.Replace(element.DefaultValue, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
element.RuntimeValue = defaultValue;
}
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, tokenData);
context.ElementShape.ProcessedLabel = _tokenizer.Replace(element.Label, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
context.ElementShape.TermOptions = GetTermOptions(element, context.DisplayType, taxonomyId, tokenData).ToArray();

View File

@ -88,9 +88,13 @@ namespace Orchard.DynamicForms.Drivers {
}
protected override void OnDisplaying(TextArea element, ElementDisplayingContext context) {
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, context.GetTokenData());
context.ElementShape.ProcessedLabel = _tokenizer.Replace(element.Label, context.GetTokenData(), new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
context.ElementShape.ProcessedValue = element.RuntimeValue;
var tokenData = context.GetTokenData();
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, tokenData);
context.ElementShape.ProcessedLabel = _tokenizer.Replace(element.Label, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
// Allow the initial value to be tokenized.
// If a value was posted, use that value instead (without tokenizing it).
context.ElementShape.ProcessedValue = element.PostedValue != null ? element.PostedValue : _tokenizer.Replace(element.RuntimeValue, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
}
}
}

View File

@ -83,9 +83,13 @@ namespace Orchard.DynamicForms.Drivers {
}
protected override void OnDisplaying(TextField element, ElementDisplayingContext context) {
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, context.GetTokenData());
context.ElementShape.ProcessedLabel = _tokenizer.Replace(element.Label, context.GetTokenData(), new ReplaceOptions {Encoding = ReplaceOptions.NoEncode});
context.ElementShape.ProcessedValue = element.RuntimeValue;
var tokenData = context.GetTokenData();
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, tokenData);
context.ElementShape.ProcessedLabel = _tokenizer.Replace(element.Label, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
// Allow the initial value to be tokenized.
// If a value was posted, use that value instead (without tokenizing it).
context.ElementShape.ProcessedValue = element.PostedValue != null ? element.PostedValue : _tokenizer.Replace(element.RuntimeValue, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
}
}
}

View File

@ -71,9 +71,13 @@ namespace Orchard.DynamicForms.Drivers {
}
protected override void OnDisplaying(UrlField element, ElementDisplayingContext context) {
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, context.GetTokenData());
context.ElementShape.ProcessedLabel = _tokenizer.Replace(element.Label, context.GetTokenData(), new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
context.ElementShape.ProcessedValue = element.RuntimeValue;
var tokenData = context.GetTokenData();
context.ElementShape.ProcessedName = _tokenizer.Replace(element.Name, tokenData);
context.ElementShape.ProcessedLabel = _tokenizer.Replace(element.Label, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
// Allow the initial value to be tokenized.
// If a value was posted, use that value instead (without tokenizing it).
context.ElementShape.ProcessedValue = element.PostedValue != null ? element.PostedValue : _tokenizer.Replace(element.RuntimeValue, tokenData, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
}
}
}

View File

@ -20,6 +20,10 @@ namespace Orchard.DynamicForms.Elements {
get { return _options.Value; }
}
public string DefaultValue {
get { return this.Retrieve(x => x.DefaultValue); }
}
public IEnumerable<string> RuntimeValues {
get { return _runtimeValues.Value; }
}

View File

@ -27,6 +27,10 @@ namespace Orchard.DynamicForms.Elements {
get { return this.Retrieve(x => x.ValueExpression, () => "{Content.Id}"); }
}
public string DefaultValue {
get { return this.Retrieve(x => x.DefaultValue); }
}
public EnumerationValidationSettings ValidationSettings {
get { return Data.GetModel<EnumerationValidationSettings>(""); }
}

View File

@ -34,6 +34,10 @@ namespace Orchard.DynamicForms.Elements {
set { this.Store(x => x.ValueExpression, value); }
}
public string DefaultValue {
get { return this.Retrieve(x => x.DefaultValue); }
}
public EnumerationValidationSettings ValidationSettings {
get { return Data.GetModel<EnumerationValidationSettings>(""); }
}

View File

@ -1,31 +1,16 @@
using System;
using System.Linq;
using Orchard.Commands;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects;
using Orchard.Core.Common.Models;
using Orchard.Security;
using Orchard.Settings;
using Orchard.Tags.Models;
using Orchard.Widgets.Models;
using Orchard.Widgets.Services;
namespace Orchard.Tags.Commands {
public class TagWidgetCommands : DefaultOrchardCommandHandler {
private readonly IWidgetsService _widgetsService;
private readonly ISiteService _siteService;
private readonly IMembershipService _membershipService;
private readonly IContentManager _contentManager;
private readonly IWidgetCommandsService _widgetCommandsService;
public TagWidgetCommands(
IWidgetsService widgetsService,
ISiteService siteService,
IMembershipService membershipService,
IContentManager contentManager) {
_widgetsService = widgetsService;
_siteService = siteService;
_membershipService = membershipService;
_contentManager = contentManager;
IWidgetCommandsService widgetCommandsService) {
_widgetCommandsService = widgetCommandsService;
RenderTitle = true;
}
@ -66,34 +51,18 @@ namespace Orchard.Tags.Commands {
public void CreateTagsCloudWidget() {
var type = "TagCloud";
var layer = GetLayer(Layer);
if (layer == null) {
Context.Output.WriteLine(T("Creating {0} widget failed: layer {1} was not found.", type, Layer));
return;
}
// Check any custom parameters that could cause creating the widget to fail.
// Nothing to check in this widget, see BlogWidgetCommands.cs for an example.
var widget = _widgetsService.CreateWidget(layer.ContentItem.Id, type, T(Title).Text, Position, Zone);
if (!String.IsNullOrWhiteSpace(Name)) {
widget.Name = Name.Trim();
}
widget.RenderTitle = RenderTitle;
if (String.IsNullOrEmpty(Owner)) {
Owner = _siteService.GetSiteSettings().SuperUser;
}
var owner = _membershipService.GetUser(Owner);
widget.As<ICommonPart>().Owner = owner;
if (widget.Has<IdentityPart>() && !String.IsNullOrEmpty(Identity)) {
widget.As<IdentityPart>().Identifier = Identity;
}
// Create the widget using the standard parameters.
var widget = _widgetCommandsService.CreateBaseWidget(
Context, type, Title, Name, Zone, Position, Layer, Identity, RenderTitle, Owner, null, false, null);
if (widget == null) {
return;
}
// Set the custom parameters.
widget.As<TagCloudPart>().Slug = Slug;
// It's an optional parameter and defaults to 5.
@ -104,13 +73,9 @@ namespace Orchard.Tags.Commands {
}
}
_contentManager.Publish(widget.ContentItem);
// Publish the successfully created widget.
_widgetCommandsService.Publish(widget);
Context.Output.WriteLine(T("{0} widget created successfully.", type).Text);
}
private LayerPart GetLayer(string layer) {
var layers = _widgetsService.GetLayers();
return layers.FirstOrDefault(layerPart => String.Equals(layerPart.Name, layer, StringComparison.OrdinalIgnoreCase));
}
}
}

View File

@ -1,37 +1,13 @@
using System;
using System.Linq;
using Orchard.Commands;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects;
using Orchard.Core.Common.Models;
using Orchard.Core.Navigation.Models;
using Orchard.Core.Navigation.Services;
using Orchard.Security;
using Orchard.Settings;
using Orchard.Widgets.Models;
using Orchard.Commands;
using Orchard.Widgets.Services;
namespace Orchard.Widgets.Commands {
public class WidgetCommands : DefaultOrchardCommandHandler {
private readonly IWidgetsService _widgetsService;
private readonly ISiteService _siteService;
private readonly IMembershipService _membershipService;
private readonly IMenuService _menuService;
private readonly IContentManager _contentManager;
private const string LoremIpsum = "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur a nibh ut tortor dapibus vestibulum. Aliquam vel sem nibh. Suspendisse vel condimentum tellus.</p>";
private readonly IWidgetCommandsService _widgetCommandsService;
public WidgetCommands(
IWidgetsService widgetsService,
ISiteService siteService,
IMembershipService membershipService,
IMenuService menuService,
IContentManager contentManager) {
_widgetsService = widgetsService;
_siteService = siteService;
_membershipService = membershipService;
_menuService = menuService;
_contentManager = contentManager;
IWidgetCommandsService widgetCommandsService) {
_widgetCommandsService = widgetCommandsService;
RenderTitle = true;
}
@ -76,67 +52,15 @@ namespace Orchard.Widgets.Commands {
[CommandHelp("widget create <type> /Title:<title> /Name:<name> /Zone:<zone> /Position:<position> /Layer:<layer> [/Identity:<identity>] [/RenderTitle:true|false] [/Owner:<owner>] [/Text:<text>] [/UseLoremIpsumText:true|false] [/MenuName:<name>]\r\n\t" + "Creates a new widget")]
[OrchardSwitches("Title,Name,Zone,Position,Layer,Identity,Owner,Text,UseLoremIpsumText,MenuName,RenderTitle")]
public void Create(string type) {
var widgetTypeNames = _widgetsService.GetWidgetTypeNames().ToList();
if (!widgetTypeNames.Contains(type)) {
Context.Output.WriteLine(T("Creating widget failed : type {0} was not found. Supported widget types are: {1}.",
type,
string.Join(" ", widgetTypeNames)));
var widget = _widgetCommandsService.CreateBaseWidget(
Context, type, Title, Name, Zone, Position, Layer, Identity, RenderTitle, Owner, Text, UseLoremIpsumText, MenuName);
if (widget == null) {
return;
}
var layer = GetLayer(Layer);
if (layer == null) {
Context.Output.WriteLine(T("Creating widget failed : layer {0} was not found.", Layer));
return;
}
var widget = _widgetsService.CreateWidget(layer.ContentItem.Id, type, T(Title).Text, Position, Zone);
if (!String.IsNullOrWhiteSpace(Name)) {
widget.Name = Name.Trim();
}
var text = String.Empty;
if (widget.Has<BodyPart>()) {
if (UseLoremIpsumText) {
text = T(LoremIpsum).Text;
}
else {
if (!String.IsNullOrEmpty(Text)) {
text = Text;
}
}
widget.As<BodyPart>().Text = text;
}
widget.RenderTitle = RenderTitle;
if(widget.Has<MenuWidgetPart>() && !String.IsNullOrWhiteSpace(MenuName)) {
var menu = _menuService.GetMenu(MenuName);
if(menu != null) {
widget.RenderTitle = false;
widget.As<MenuWidgetPart>().MenuContentItemId = menu.ContentItem.Id;
}
}
if (String.IsNullOrEmpty(Owner)) {
Owner = _siteService.GetSiteSettings().SuperUser;
}
var owner = _membershipService.GetUser(Owner);
widget.As<ICommonPart>().Owner = owner;
if (widget.Has<IdentityPart>() && !String.IsNullOrEmpty(Identity)) {
widget.As<IdentityPart>().Identifier = Identity;
}
_contentManager.Publish(widget.ContentItem);
_widgetCommandsService.Publish(widget);
Context.Output.WriteLine(T("Widget created successfully.").Text);
}
private LayerPart GetLayer(string layer) {
var layers = _widgetsService.GetLayers();
return layers.FirstOrDefault(layerPart => String.Equals(layerPart.Name, layer, StringComparison.OrdinalIgnoreCase));
}
}
}

View File

@ -116,6 +116,7 @@
<Compile Include="Filters\WidgetFilter.cs" />
<Compile Include="ResourceManifest.cs" />
<Compile Include="Conditions\ContentDisplayedRuleProvider.cs" />
<Compile Include="Services\IWidgetCommandsService.cs" />
<Compile Include="Services\RuleManager.cs" />
<Compile Include="Services\DefaultLayerEvaluationService.cs" />
<Compile Include="Services\ILayerEvaluationService.cs" />
@ -124,6 +125,7 @@
<Compile Include="Services\IWidgetsService.cs" />
<Compile Include="Services\LayerResolverSelector.cs" />
<Compile Include="Services\RuleContext.cs" />
<Compile Include="Services\WidgetCommandsService.cs" />
<Compile Include="Services\WidgetsService.cs" />
<Compile Include="Shapes.cs" />
<Compile Include="ViewModels\WidgetElementViewModel.cs" />

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Orchard.Commands;
using Orchard.Widgets.Models;
namespace Orchard.Widgets.Services {
public interface IWidgetCommandsService : IDependency {
WidgetPart CreateBaseWidget(CommandContext context, string type, string title, string name, string zone, string position, string layer, string identity, bool renderTitle, string owner, string text, bool useLoremIpsumText, string menuName);
void Publish(WidgetPart widget);
}
}

View File

@ -0,0 +1,106 @@
using System;
using System.Linq;
using Orchard.Commands;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects;
using Orchard.Core.Common.Models;
using Orchard.Core.Navigation.Models;
using Orchard.Core.Navigation.Services;
using Orchard.Localization;
using Orchard.Security;
using Orchard.Settings;
using Orchard.Widgets.Models;
namespace Orchard.Widgets.Services {
public class WidgetCommandsService : IWidgetCommandsService {
private readonly IMenuService _menuService;
private readonly IWidgetsService _widgetsService;
private readonly ISiteService _siteService;
private readonly IMembershipService _membershipService;
private readonly IContentManager _contentManager;
private const string LoremIpsum = "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur a nibh ut tortor dapibus vestibulum. Aliquam vel sem nibh. Suspendisse vel condimentum tellus.</p>";
public WidgetCommandsService(
IWidgetsService widgetsService,
IMenuService menuService,
ISiteService siteService,
IMembershipService membershipService,
IContentManager contentManager) {
_siteService = siteService;
_membershipService = membershipService;
_widgetsService = widgetsService;
_menuService = menuService;
_contentManager = contentManager;
T = NullLocalizer.Instance;
}
public Localizer T { get; set; }
public WidgetPart CreateBaseWidget(CommandContext context, string type, string title, string name, string zone, string position, string layer, string identity, bool renderTitle, string owner, string text, bool useLoremIpsumText, string menuName) {
var widgetTypeNames = _widgetsService.GetWidgetTypeNames().ToList();
if (!widgetTypeNames.Contains(type)) {
context.Output.WriteLine(T("Creating widget failed : type {0} was not found. Supported widget types are: {1}.",
type,
string.Join(" ", widgetTypeNames)));
return null;
}
var layerPart = GetLayer(layer);
if (layerPart == null) {
context.Output.WriteLine(T("Creating widget failed : layer {0} was not found.", layer));
return null;
}
var widget = _widgetsService.CreateWidget(layerPart.ContentItem.Id, type, T(title).Text, position, zone);
if (!String.IsNullOrWhiteSpace(name)) {
widget.Name = name.Trim();
}
var widgetText = String.Empty;
if (widget.Has<BodyPart>()) {
if (useLoremIpsumText) {
widgetText = T(LoremIpsum).Text;
}
else {
if (!String.IsNullOrEmpty(text)) {
widgetText = text;
}
}
widget.As<BodyPart>().Text = text;
}
widget.RenderTitle = renderTitle;
if (widget.Has<MenuWidgetPart>() && !String.IsNullOrWhiteSpace(menuName)) {
var menu = _menuService.GetMenu(menuName);
if (menu != null) {
widget.RenderTitle = false;
widget.As<MenuWidgetPart>().MenuContentItemId = menu.ContentItem.Id;
}
}
if (String.IsNullOrEmpty(owner)) {
owner = _siteService.GetSiteSettings().SuperUser;
}
var widgetOwner = _membershipService.GetUser(owner);
widget.As<ICommonPart>().Owner = widgetOwner;
if (widget.Has<IdentityPart>() && !String.IsNullOrEmpty(identity)) {
widget.As<IdentityPart>().Identifier = identity;
}
return widget;
}
private LayerPart GetLayer(string layer) {
var layers = _widgetsService.GetLayers();
return layers.FirstOrDefault(layerPart => String.Equals(layerPart.Name, layer, StringComparison.OrdinalIgnoreCase));
}
public void Publish(WidgetPart widget) {
_contentManager.Publish(widget.ContentItem);
}
}
}

View File

@ -9,8 +9,8 @@
var returnUrl = Request.RawUrl;
}
<div id="widgets-layers-control" class="widgets-container">
@if (layers.Any()) {
using (Html.BeginForm("index", "admin", FormMethod.Get, new { area = "Orchard.Widgets" })) {
@using (Html.BeginForm("index", "admin", FormMethod.Get, new { area = "Orchard.Widgets" })) {
if (layers.Any()) {
<fieldset class="bulk-actions-auto">
<label for="layerId">@T("Current Layer:")</label>
<select id="layerId" name="layerId">
@ -22,23 +22,20 @@
@Html.Link(T("Edit").Text, Url.Action("EditLayer", "Admin", new { area = "Orchard.Widgets", id = Model.CurrentLayer.Id, returnUrl }), new { @class = "button" })
</fieldset>
}
}
<div id="widgets-layer-add">
@Html.Link(T("Add a new layer...").Text, Url.Action("AddLayer", "Admin", new { area = "Orchard.Widgets", returnUrl }))
</div>
@if (cultures.Count() > 1) {
using (Html.BeginForm("index", "admin", FormMethod.Get, new { area = "Orchard.Widgets" })) {
<fieldset class="bulk-actions-auto">
<label for="culture">@T("Current Culture:")</label>
<select id="culture" name="culture">
@Html.SelectOption((string)Model.CurrentCulture, "", T("any (show all)").ToString())
@foreach (var culture in cultures) {
@Html.SelectOption((string)Model.CurrentCulture, (string)culture, System.Globalization.CultureInfo.GetCultureInfo(culture).DisplayName)
}
</select>
<button type="submit" class="apply-bulk-actions-auto">@T("Show")</button>
</fieldset>
<div id="widgets-layer-add">
@Html.Link(T("Add a new layer...").Text, Url.Action("AddLayer", "Admin", new { area = "Orchard.Widgets", returnUrl }))
</div>
if (cultures.Count() > 1) {
<fieldset class="bulk-actions-auto">
<label for="culture">@T("Current Culture:")</label>
<select id="culture" name="culture">
@Html.SelectOption((string)Model.CurrentCulture, "", T("any (show all)").ToString())
@foreach (var culture in cultures) {
@Html.SelectOption((string)Model.CurrentCulture, (string)culture, System.Globalization.CultureInfo.GetCultureInfo(culture).DisplayName)
}
</select>
<button type="submit" class="apply-bulk-actions-auto">@T("Show")</button>
</fieldset>
}
}

View File

@ -6,5 +6,5 @@ Version: 1.10.1
OrchardVersion: 1.9
Description: The TinyMCE module enables rich text contents to be created using a "What You See Is What You Get" user interface.
FeatureDescription: TinyMCE HTML WYSIWYG editor.
FeatureDependencies: Orchard.Resources
Dependencies: Orchard.Resources
Category: Input Editor

View File

@ -39,18 +39,23 @@ namespace Orchard.Events {
// static IEnumerable<T> IEnumerable.OfType<T>(this IEnumerable source)
// where T is from returnType's IEnumerable<T>
var enumerableOfTypeT = _enumerableOfTypeTDictionary.GetOrAdd( returnType, type => typeof(Enumerable).GetGenericMethod("OfType", type.GetGenericArguments(), new[] { typeof(IEnumerable) }, typeof(IEnumerable<>)));
return enumerableOfTypeT.Invoke(null, new[] { results });
return (enumerableOfTypeT != null) ? enumerableOfTypeT.Invoke(null, new[] { results }) : null;
}
}
public static class Extensions {
public static MethodInfo GetGenericMethod(this Type t, string name, Type[] genericArgTypes, Type[] argTypes, Type returnType) {
return (from m in t.GetMethods(BindingFlags.Public | BindingFlags.Static)
where m.Name == name &&
m.GetGenericArguments().Length == genericArgTypes.Length &&
m.GetParameters().Select(pi => pi.ParameterType).SequenceEqual(argTypes) &&
(m.ReturnType.IsGenericType && !m.ReturnType.IsGenericTypeDefinition ? returnType.GetGenericTypeDefinition() : m.ReturnType) == returnType
select m).Single().MakeGenericMethod(genericArgTypes);
var method = (from m in t.GetMethods(BindingFlags.Public | BindingFlags.Static)
where m.Name == name &&
m.GetGenericArguments().Length == genericArgTypes.Length &&
m.GetParameters().Select(pi => pi.ParameterType).SequenceEqual(argTypes) &&
(m.ReturnType.IsGenericType && !m.ReturnType.IsGenericTypeDefinition ? returnType.GetGenericTypeDefinition() : m.ReturnType) == returnType
select m).SingleOrDefault();
if (method != null) {
return method.MakeGenericMethod(genericArgTypes);
}
return null;
}
}