Merge branch '1.10.x' into dev

Conflicts:
	src/Orchard.Web/Core/Common/Views/EditorTemplates/Fields.Common.Text.Edit.cshtml
This commit is contained in:
Sebastien Ros
2016-03-31 15:33:14 -07:00
10 changed files with 503 additions and 37 deletions

View File

@@ -205,6 +205,11 @@
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
</Compile>
<Compile Include="Text.feature.cs">
<DependentUpon>Text.feature</DependentUpon>
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
</Compile>
<Compile Include="Input.feature.cs">
<DependentUpon>Input.feature</DependentUpon>
<AutoGen>True</AutoGen>
@@ -371,6 +376,10 @@
<None Include="Hosting\Orchard.Web\Config\HostComponents.Release.config">
<DependentUpon>HostComponents.config</DependentUpon>
</None>
<None Include="Text.feature">
<Generator>SpecFlowSingleFileGenerator</Generator>
<LastGenOutput>Text.feature.cs</LastGenOutput>
</None>
<None Include="Input.feature">
<Generator>SpecFlowSingleFileGenerator</Generator>
<LastGenOutput>Input.feature.cs</LastGenOutput>

View File

@@ -0,0 +1,126 @@
Feature: Text Field
In order to add Text content to my types
As an administrator
I want to create, edit and publish Text fields
Scenario: Creating and using Text fields
# Creating an Event content type
Given I have installed Orchard
And I have installed "Orchard.Fields"
When I go to "Admin/ContentTypes"
Then I should see "<a[^>]*>.*?Create new type</a>"
When I go to "Admin/ContentTypes/Create"
And I fill in
| name | value |
| DisplayName | Event |
| Name | Event |
And I hit "Create"
And I go to "Admin/ContentTypes/"
Then I should see "Event"
# Adding a Text field
When I go to "Admin/ContentTypes/Edit/Event"
And I follow "Add Field"
And I fill in
| name | value |
| DisplayName | Subject |
| Name | Subject |
| FieldTypeName | TextField |
And I hit "Save"
And I am redirected
Then I should see "The \"Subject\" field has been added."
# The display option should be effective
When I go to "Admin/ContentTypes/Edit/Event"
And I fill in
| name | value |
| Fields[0].TextFieldSettingsEventsViewModel.Settings.Flavor | Large |
And I hit "Save"
And I go to "Admin/Contents/Create/Event"
Then I should see "class=\"text large\""
# The value should be required
When I go to "Admin/ContentTypes/Edit/Event"
And I fill in
| name | value |
| Fields[0].TextFieldSettingsEventsViewModel.Settings.Required | true |
And I hit "Save"
And I go to "Admin/Contents/Create/Event"
And I fill in
| name | value |
| Event.Subject.Text | |
And I hit "Save"
Then I should see "The field Subject is mandatory."
# The hint should be displayed
When I go to "Admin/ContentTypes/Edit/Event"
And I fill in
| name | value |
| Fields[0].TextFieldSettingsEventsViewModel.Settings.Hint | Subject of the event |
And I hit "Save"
And I go to "Admin/Contents/Create/Event"
Then I should see "Subject of the event"
# Creating an Event content item
When I go to "Admin/Contents/Create/Event"
Then I should see "Subject"
When I fill in
| name | value |
| Event.Subject.Text | Orchard Harvest 2013 |
And I hit "Save"
And I am redirected
Then I should see "Your Event has been created."
And I should see "Orchard Harvest 2013"
# If not required and no value, the default value should be used
When I go to "Admin/ContentTypes/Edit/Event"
And I fill in
| name | value |
| Fields[0].TextFieldSettingsEventsViewModel.Settings.Required | false |
| Fields[0].TextFieldSettingsEventsViewModel.Settings.DefaultValue | Orchard Harvest 2014 |
And I hit "Save"
And I go to "Admin/Contents/Create/Event"
And I fill in
| name | value |
| Event.Subject.Text | |
And I hit "Save"
And I am redirected
Then I should see "Your Event has been created."
And I should see "Orchard Harvest 2014"
# If required and no value, the default value should be used
When I go to "Admin/ContentTypes/Edit/Event"
And I fill in
| name | value |
| Fields[0].TextFieldSettingsEventsViewModel.Settings.Required | true |
| Fields[0].TextFieldSettingsEventsViewModel.Settings.DefaultValue | Orchard Harvest 2015 |
And I hit "Save"
And I go to "Admin/Contents/Create/Event"
And I fill in
| name | value |
| Event.Subject.Text | |
And I hit "Save"
And I am redirected
Then I should see "Your Event has been created."
And I should see "Orchard Harvest 2015"
# If required and no default value, the required attribute should be used
When I go to "Admin/ContentTypes/Edit/Event"
And I fill in
| name | value |
| Fields[0].TextFieldSettingsEventsViewModel.Settings.Required | true |
| Fields[0].TextFieldSettingsEventsViewModel.Settings.DefaultValue | |
And I hit "Save"
And I go to "Admin/Contents/Create/Event"
Then I should see "required=\"required\""
# If required and a default value is set, the required attribute should not be used
When I go to "Admin/ContentTypes/Edit/Event"
And I fill in
| name | value |
| Fields[0].TextFieldSettingsEventsViewModel.Settings.Required | true |
| Fields[0].TextFieldSettingsEventsViewModel.Settings.DefaultValue | Orchard Harvest 2015 |
And I hit "Save"
And I go to "Admin/Contents/Create/Event"
Then I should not see "required=\"required\""

327
src/Orchard.Specs/Text.feature.cs generated Normal file
View File

@@ -0,0 +1,327 @@
// ------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by SpecFlow (http://www.specflow.org/).
// SpecFlow Version:1.9.0.77
// SpecFlow Generator Version:1.9.0.0
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
// ------------------------------------------------------------------------------
#region Designer generated code
#pragma warning disable
namespace Orchard.Specs
{
using TechTalk.SpecFlow;
[System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "1.9.0.77")]
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[NUnit.Framework.TestFixtureAttribute()]
[NUnit.Framework.DescriptionAttribute("Text Field")]
public partial class TextFieldFeature
{
private static TechTalk.SpecFlow.ITestRunner testRunner;
#line 1 "Text.feature"
#line hidden
[NUnit.Framework.TestFixtureSetUpAttribute()]
public virtual void FeatureSetup()
{
testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner();
TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Text Field", " In order to add Text content to my types\r\n As an administrator\r\n I want to cr" +
"eate, edit and publish Text fields", ProgrammingLanguage.CSharp, ((string[])(null)));
testRunner.OnFeatureStart(featureInfo);
}
[NUnit.Framework.TestFixtureTearDownAttribute()]
public virtual void FeatureTearDown()
{
testRunner.OnFeatureEnd();
testRunner = null;
}
[NUnit.Framework.SetUpAttribute()]
public virtual void TestInitialize()
{
}
[NUnit.Framework.TearDownAttribute()]
public virtual void ScenarioTearDown()
{
testRunner.OnScenarioEnd();
}
public virtual void ScenarioSetup(TechTalk.SpecFlow.ScenarioInfo scenarioInfo)
{
testRunner.OnScenarioStart(scenarioInfo);
}
public virtual void ScenarioCleanup()
{
testRunner.CollectScenarioErrors();
}
[NUnit.Framework.TestAttribute()]
[NUnit.Framework.DescriptionAttribute("Creating and using Text fields")]
public virtual void CreatingAndUsingTextFields()
{
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Creating and using Text fields", ((string[])(null)));
#line 6
this.ScenarioSetup(scenarioInfo);
#line 9
testRunner.Given("I have installed Orchard", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given ");
#line 10
testRunner.And("I have installed \"Orchard.Fields\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line 11
testRunner.When("I go to \"Admin/ContentTypes\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When ");
#line 12
testRunner.Then("I should see \"<a[^>]*>.*?Create new type</a>\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then ");
#line 13
testRunner.When("I go to \"Admin/ContentTypes/Create\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When ");
#line hidden
TechTalk.SpecFlow.Table table1 = new TechTalk.SpecFlow.Table(new string[] {
"name",
"value"});
table1.AddRow(new string[] {
"DisplayName",
"Event"});
table1.AddRow(new string[] {
"Name",
"Event"});
#line 14
testRunner.And("I fill in", ((string)(null)), table1, "And ");
#line 18
testRunner.And("I hit \"Create\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line 19
testRunner.And("I go to \"Admin/ContentTypes/\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line 20
testRunner.Then("I should see \"Event\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then ");
#line 23
testRunner.When("I go to \"Admin/ContentTypes/Edit/Event\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When ");
#line 24
testRunner.And("I follow \"Add Field\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line hidden
TechTalk.SpecFlow.Table table2 = new TechTalk.SpecFlow.Table(new string[] {
"name",
"value"});
table2.AddRow(new string[] {
"DisplayName",
"Subject"});
table2.AddRow(new string[] {
"Name",
"Subject"});
table2.AddRow(new string[] {
"FieldTypeName",
"TextField"});
#line 25
testRunner.And("I fill in", ((string)(null)), table2, "And ");
#line 30
testRunner.And("I hit \"Save\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line 31
testRunner.And("I am redirected", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line 32
testRunner.Then("I should see \"The \\\"Subject\\\" field has been added.\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then ");
#line 35
testRunner.When("I go to \"Admin/ContentTypes/Edit/Event\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When ");
#line hidden
TechTalk.SpecFlow.Table table3 = new TechTalk.SpecFlow.Table(new string[] {
"name",
"value"});
table3.AddRow(new string[] {
"Fields[0].TextFieldSettingsEventsViewModel.Settings.Flavor",
"Large"});
#line 36
testRunner.And("I fill in", ((string)(null)), table3, "And ");
#line 39
testRunner.And("I hit \"Save\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line 40
testRunner.And("I go to \"Admin/Contents/Create/Event\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line 41
testRunner.Then("I should see \"class=\\\"text large\\\"\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then ");
#line 44
testRunner.When("I go to \"Admin/ContentTypes/Edit/Event\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When ");
#line hidden
TechTalk.SpecFlow.Table table4 = new TechTalk.SpecFlow.Table(new string[] {
"name",
"value"});
table4.AddRow(new string[] {
"Fields[0].TextFieldSettingsEventsViewModel.Settings.Required",
"true"});
#line 45
testRunner.And("I fill in", ((string)(null)), table4, "And ");
#line 48
testRunner.And("I hit \"Save\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line 49
testRunner.And("I go to \"Admin/Contents/Create/Event\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line hidden
TechTalk.SpecFlow.Table table5 = new TechTalk.SpecFlow.Table(new string[] {
"name",
"value"});
table5.AddRow(new string[] {
"Event.Subject.Text",
""});
#line 50
testRunner.And("I fill in", ((string)(null)), table5, "And ");
#line 53
testRunner.And("I hit \"Save\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line 54
testRunner.Then("I should see \"The field Subject is mandatory.\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then ");
#line 57
testRunner.When("I go to \"Admin/ContentTypes/Edit/Event\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When ");
#line hidden
TechTalk.SpecFlow.Table table6 = new TechTalk.SpecFlow.Table(new string[] {
"name",
"value"});
table6.AddRow(new string[] {
"Fields[0].TextFieldSettingsEventsViewModel.Settings.Hint",
"Subject of the event"});
#line 58
testRunner.And("I fill in", ((string)(null)), table6, "And ");
#line 61
testRunner.And("I hit \"Save\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line 62
testRunner.And("I go to \"Admin/Contents/Create/Event\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line 63
testRunner.Then("I should see \"Subject of the event\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then ");
#line 66
testRunner.When("I go to \"Admin/Contents/Create/Event\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When ");
#line 67
testRunner.Then("I should see \"Subject\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then ");
#line hidden
TechTalk.SpecFlow.Table table7 = new TechTalk.SpecFlow.Table(new string[] {
"name",
"value"});
table7.AddRow(new string[] {
"Event.Subject.Text",
"Orchard Harvest 2013"});
#line 68
testRunner.When("I fill in", ((string)(null)), table7, "When ");
#line 71
testRunner.And("I hit \"Save\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line 72
testRunner.And("I am redirected", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line 73
testRunner.Then("I should see \"Your Event has been created.\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then ");
#line 74
testRunner.And("I should see \"Orchard Harvest 2013\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line 77
testRunner.When("I go to \"Admin/ContentTypes/Edit/Event\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When ");
#line hidden
TechTalk.SpecFlow.Table table8 = new TechTalk.SpecFlow.Table(new string[] {
"name",
"value"});
table8.AddRow(new string[] {
"Fields[0].TextFieldSettingsEventsViewModel.Settings.Required",
"false"});
table8.AddRow(new string[] {
"Fields[0].TextFieldSettingsEventsViewModel.Settings.DefaultValue",
"Orchard Harvest 2014"});
#line 78
testRunner.And("I fill in", ((string)(null)), table8, "And ");
#line 82
testRunner.And("I hit \"Save\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line 83
testRunner.And("I go to \"Admin/Contents/Create/Event\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line hidden
TechTalk.SpecFlow.Table table9 = new TechTalk.SpecFlow.Table(new string[] {
"name",
"value"});
table9.AddRow(new string[] {
"Event.Subject.Text",
""});
#line 84
testRunner.And("I fill in", ((string)(null)), table9, "And ");
#line 87
testRunner.And("I hit \"Save\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line 88
testRunner.And("I am redirected", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line 89
testRunner.Then("I should see \"Your Event has been created.\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then ");
#line 90
testRunner.And("I should see \"Orchard Harvest 2014\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line 93
testRunner.When("I go to \"Admin/ContentTypes/Edit/Event\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When ");
#line hidden
TechTalk.SpecFlow.Table table10 = new TechTalk.SpecFlow.Table(new string[] {
"name",
"value"});
table10.AddRow(new string[] {
"Fields[0].TextFieldSettingsEventsViewModel.Settings.Required",
"true"});
table10.AddRow(new string[] {
"Fields[0].TextFieldSettingsEventsViewModel.Settings.DefaultValue",
"Orchard Harvest 2015"});
#line 94
testRunner.And("I fill in", ((string)(null)), table10, "And ");
#line 98
testRunner.And("I hit \"Save\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line 99
testRunner.And("I go to \"Admin/Contents/Create/Event\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line hidden
TechTalk.SpecFlow.Table table11 = new TechTalk.SpecFlow.Table(new string[] {
"name",
"value"});
table11.AddRow(new string[] {
"Event.Subject.Text",
""});
#line 100
testRunner.And("I fill in", ((string)(null)), table11, "And ");
#line 103
testRunner.And("I hit \"Save\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line 104
testRunner.And("I am redirected", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line 105
testRunner.Then("I should see \"Your Event has been created.\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then ");
#line 106
testRunner.And("I should see \"Orchard Harvest 2015\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line 109
testRunner.When("I go to \"Admin/ContentTypes/Edit/Event\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When ");
#line hidden
TechTalk.SpecFlow.Table table12 = new TechTalk.SpecFlow.Table(new string[] {
"name",
"value"});
table12.AddRow(new string[] {
"Fields[0].TextFieldSettingsEventsViewModel.Settings.Required",
"true"});
table12.AddRow(new string[] {
"Fields[0].TextFieldSettingsEventsViewModel.Settings.DefaultValue",
""});
#line 110
testRunner.And("I fill in", ((string)(null)), table12, "And ");
#line 114
testRunner.And("I hit \"Save\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line 115
testRunner.And("I go to \"Admin/Contents/Create/Event\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line 116
testRunner.Then("I should see \"required=\\\"required\\\"\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then ");
#line 119
testRunner.When("I go to \"Admin/ContentTypes/Edit/Event\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When ");
#line hidden
TechTalk.SpecFlow.Table table13 = new TechTalk.SpecFlow.Table(new string[] {
"name",
"value"});
table13.AddRow(new string[] {
"Fields[0].TextFieldSettingsEventsViewModel.Settings.Required",
"true"});
table13.AddRow(new string[] {
"Fields[0].TextFieldSettingsEventsViewModel.Settings.DefaultValue",
"Orchard Harvest 2015"});
#line 120
testRunner.And("I fill in", ((string)(null)), table13, "And ");
#line 124
testRunner.And("I hit \"Save\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line 125
testRunner.And("I go to \"Admin/Contents/Create/Event\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
#line 126
testRunner.Then("I should not see \"required=\\\"required\\\"\"", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then ");
#line hidden
this.ScenarioCleanup();
}
}
}
#pragma warning restore
#endregion

View File

@@ -58,28 +58,19 @@ namespace Orchard.Core.Common.Drivers {
protected override DriverResult Editor(ContentPart part, TextField field, IUpdateModel updater, dynamic shapeHelper) {
var viewModel = new TextFieldDriverViewModel {
Field = field,
Text = field.Value,
Settings = field.PartFieldDefinition.Settings.GetModel<TextFieldSettings>(),
ContentItem = part.ContentItem
};
var viewModel = new TextFieldDriverViewModel();
if (updater.TryUpdateModel(viewModel, GetPrefix(field, part), null, null)) {
if (viewModel.Settings.Required && string.IsNullOrWhiteSpace(viewModel.Text)) {
updater.AddModelError("Text", T("The field {0} is mandatory", T(field.DisplayName)));
return ContentShape("Fields_Common_Text_Edit", GetDifferentiator(field, part),
() => shapeHelper.EditorTemplate(TemplateName: "Fields.Common.Text.Edit", Model: viewModel, Prefix: GetPrefix(field, part)));
}
field.Value = viewModel.Text;
var settings = field.PartFieldDefinition.Settings.GetModel<TextFieldSettings>();
if (String.IsNullOrEmpty(field.Value) && !String.IsNullOrEmpty(settings.DefaultValue)) {
field.Value = viewModel.Text;
if (String.IsNullOrWhiteSpace(field.Value) && !String.IsNullOrWhiteSpace(settings.DefaultValue)) {
field.Value = settings.DefaultValue;
}
else {
field.Value = viewModel.Text;
if (settings.Required && String.IsNullOrWhiteSpace(field.Value)) {
updater.AddModelError("Text", T("The field {0} is mandatory", T(field.DisplayName)));
}
}

View File

@@ -1,5 +1,7 @@
@model Orchard.Core.Common.ViewModels.TextFieldDriverViewModel
@{
var isRequired = Model.Settings.Required && String.IsNullOrWhiteSpace(Model.Settings.DefaultValue);
}
<fieldset>
<label for="@Html.FieldIdFor(m => m.Text)" @if(Model.Settings.Required) { <text>class="required"</text> }>@Model.Field.DisplayName</label>
@if (String.IsNullOrWhiteSpace(Model.Settings.Flavor)) {

View File

@@ -2,6 +2,7 @@
using Orchard.ContentManagement.Drivers;
using Orchard.Core.Common.Fields;
using Orchard.Core.Common.Settings;
using Orchard.Localization;
using Orchard.Tokens;
using System;
using System.Collections.Generic;
@@ -14,13 +15,20 @@ namespace Orchard.Fields.Drivers {
public TextFieldDriver(ITokenizer tokenizer) {
_tokenizer = tokenizer;
T = NullLocalizer.Instance;
}
public Localizer T { get; set; }
protected override DriverResult Editor(ContentPart part, TextField field, IUpdateModel updater, dynamic shapeHelper) {
var settings = field.PartFieldDefinition.Settings.GetModel<TextFieldSettings>();
if (!String.IsNullOrEmpty(settings.DefaultValue) && (String.IsNullOrEmpty(field.Value) || field.Value.Equals(settings.DefaultValue))) {
if (!String.IsNullOrWhiteSpace(settings.DefaultValue) && (String.IsNullOrWhiteSpace(field.Value) || field.Value.Equals(settings.DefaultValue))) {
field.Value = _tokenizer.Replace(settings.DefaultValue, new Dictionary<string, object> { { "Content", part.ContentItem } });
if (settings.Required && String.IsNullOrWhiteSpace(field.Value)) {
updater.AddModelError("Text", T("The field {0} is mandatory", T(field.DisplayName)));
}
}
return null;

View File

@@ -91,8 +91,15 @@
$("form:first").trigger("orchard-admin-contentpicker-open", {
types: $("#listManagement").data("itemtypes"),
callback: function(data) {
var id = parseInt(data.id);
insertItem(id);
if (Array.isArray && Array.isArray(data)) {
data.forEach(function (item) {
var id = parseInt(item.id);
insertItem(id);
});
} else {
var id = parseInt(data.id);
insertItem(id);
}
},
baseUrl: $("#listManagement").data("baseurl")
});

View File

@@ -1,4 +1 @@
(function(n){var t=function(t,i,r,u,f,e){var o=n("#ajaxError");o.hide();NProgress.start();NProgress.set(.4);n.ajax({type:e,url:t,data:i,cache:!1}).done(function(n){NProgress.set(.9);u&&u(n)}).fail(function(){r&&r();o.show()}).always(function(){f&&f();NProgress.done()})},i=function(i,r,u,f,e){r=n.extend(r,{__RequestVerificationToken:n("[name='__RequestVerificationToken']").val()});t(i,r,u,f,e,"POST")},u=function(n,i,r,u,f){t(n,i,r,u,f,"GET")},f=function(t){var r=n("#listManagement").data("insert-url"),u={itemId:t};i(r,u,null,function(t){n("#main").replaceWith(n("#main",n.parseHTML(t)));n(window).trigger("reinitialize")})},e=function(){var t=n("#listManagement").data("refresh-url");u(t,null,null,function(t){n("#main").replaceWith(n("#main",n.parseHTML(t)));n(window).trigger("reinitialize")})},o=function(t,r,u,f){if(u!=r){var e=n("#listManagement").data("update-url"),o={itemId:t,oldIndex:r,newIndex:u};i(e,o,f)}},s=function(){n("#layout-content").on("change","#listOperations",function(){var r=n(this).val(),t=n("#SortBy"),i=n("#SortByDirection");r==="Sort"?(t.css("display","inline"),i.css("display","inline")):(t.css("display","none"),i.css("display","none"))})},h=function(){n("#layout-content").on("click","#chooseItems",function(t){t.preventDefault();n("form:first").trigger("orchard-admin-contentpicker-open",{types:n("#listManagement").data("itemtypes"),callback:function(n){var t=parseInt(n.id);f(t)},baseUrl:n("#listManagement").data("baseurl")})})},c=function(){n("#layout-content").on("click",".create-content",function(t){var i=n(this).attr("href");n.colorbox({href:i,iframe:!0,reposition:!0,width:"100%",height:"100%",initialWidth:"100%",initialHeight:"100%",onLoad:function(){n("html, body").css("overflow","hidden");n("#cboxClose").remove()},onClosed:function(){n("html, body").css("overflow","auto");e()}});t.preventDefault()})},r=function(){var r=n("#listManagement").data("dragdrop"),t,i;r&&(t=-1,i=function(){n("table.content-list tbody").sortable("cancel")},n("table.content-list tbody").sortable({handle:"td:first",start:function(n,i){t=i.item.index()},stop:function(n,r){var u=r.item.index(),f=r.item.data("content-id");o(f,t,u,i)}}).disableSelection())},l=function(){n("#layout-content").on("change","table.content-list thead .toggle-all",function(){var t=n(this).parents("table:first").find("tbody");t.find("input[type='checkbox']").prop("checked",n(this).is(":checked"))})},a=function(){n("#layout-content").on("click",".switch-button",function(){n(".switch-button").removeClass("active");n(this).addClass("active");n("#listViewName").prop("checked",!0).val(n(this).data("listviewname"));n(this).parents("form:first").submit()})};NProgress.configure({showSpinner:!1});s();r();l();h();c();a();n(window).on("reinitialize",function(){r()})})(jQuery);
/*
//# sourceMappingURL=orchard-lists-admin.min.js.map
*/
(function(n){var t=function(t,i,r,u,f,e){var o=n("#ajaxError");o.hide();NProgress.start();NProgress.set(.4);n.ajax({type:e,url:t,data:i,cache:!1}).done(function(n){NProgress.set(.9);u&&u(n)}).fail(function(){r&&r();o.show()}).always(function(){f&&f();NProgress.done()})},i=function(i,r,u,f,e){r=n.extend(r,{__RequestVerificationToken:n("[name='__RequestVerificationToken']").val()});t(i,r,u,f,e,"POST")},f=function(n,i,r,u,f){t(n,i,r,u,f,"GET")},r=function(t){var r=n("#listManagement").data("insert-url"),u={itemId:t};i(r,u,null,function(t){n("#main").replaceWith(n("#main",n.parseHTML(t)));n(window).trigger("reinitialize")})},e=function(){var t=n("#listManagement").data("refresh-url");f(t,null,null,function(t){n("#main").replaceWith(n("#main",n.parseHTML(t)));n(window).trigger("reinitialize")})},o=function(t,r,u,f){if(u!=r){var e=n("#listManagement").data("update-url"),o={itemId:t,oldIndex:r,newIndex:u};i(e,o,f)}},s=function(){n("#layout-content").on("change","#listOperations",function(){var r=n(this).val(),t=n("#SortBy"),i=n("#SortByDirection");r==="Sort"?(t.css("display","inline"),i.css("display","inline")):(t.css("display","none"),i.css("display","none"))})},h=function(){n("#layout-content").on("click","#chooseItems",function(t){t.preventDefault();n("form:first").trigger("orchard-admin-contentpicker-open",{types:n("#listManagement").data("itemtypes"),callback:function(n){if(Array.isArray&&Array.isArray(n))n.forEach(function(n){var t=parseInt(n.id);r(t)});else{var t=parseInt(n.id);r(t)}},baseUrl:n("#listManagement").data("baseurl")})})},c=function(){n("#layout-content").on("click",".create-content",function(t){var i=n(this).attr("href");n.colorbox({href:i,iframe:!0,reposition:!0,width:"100%",height:"100%",initialWidth:"100%",initialHeight:"100%",onLoad:function(){n("html, body").css("overflow","hidden");n("#cboxClose").remove()},onClosed:function(){n("html, body").css("overflow","auto");e()}});t.preventDefault()})},u=function(){var r=n("#listManagement").data("dragdrop"),t,i;r&&(t=-1,i=function(){n("table.content-list tbody").sortable("cancel")},n("table.content-list tbody").sortable({handle:"td:first",start:function(n,i){t=i.item.index()},stop:function(n,r){var u=r.item.index(),f=r.item.data("content-id");o(f,t,u,i)}}).disableSelection())},l=function(){n("#layout-content").on("change","table.content-list thead .toggle-all",function(){var t=n(this).parents("table:first").find("tbody");t.find("input[type='checkbox']").prop("checked",n(this).is(":checked"))})},a=function(){n("#layout-content").on("click",".switch-button",function(){n(".switch-button").removeClass("active");n(this).addClass("active");n("#listViewName").prop("checked",!0).val(n(this).data("listviewname"));n(this).parents("form:first").submit()})};NProgress.configure({showSpinner:!1});s();u();l();h();c();a();n(window).on("reinitialize",function(){u()})})(jQuery);

View File

@@ -24,7 +24,7 @@ namespace Orchard.MediaLibrary.Controllers {
private readonly IContentDefinitionManager _contentDefinitionManager;
public AdminController(
IOrchardServices services,
IOrchardServices services,
IMediaLibraryService mediaLibraryService,
INavigationManager navigationManager,
IContentDefinitionManager contentDefinitionManager) {
@@ -111,7 +111,7 @@ namespace Orchard.MediaLibrary.Controllers {
return View(model);
}
var mediaParts = _mediaLibraryService.GetMediaContentItems(folderPath, skip, count, order, mediaType, VersionOptions.Latest);
var mediaPartsCount = _mediaLibraryService.GetMediaContentItemsCount(folderPath, mediaType, VersionOptions.Latest);
@@ -149,7 +149,7 @@ namespace Orchard.MediaLibrary.Controllers {
};
Response.ContentType = "text/json";
return View(viewModel);
}
@@ -213,8 +213,7 @@ namespace Orchard.MediaLibrary.Controllers {
}
return Json(true);
}
catch(Exception e) {
} catch (Exception e) {
Logger.Error(e, "Could not delete media items.");
return Json(false);
}
@@ -228,12 +227,12 @@ namespace Orchard.MediaLibrary.Controllers {
try {
var media = Services.ContentManager.Get(mediaItemId).As<MediaPart>();
if(!_mediaLibraryService.CanManageMediaFolder(media.FolderPath)) {
if (!_mediaLibraryService.CanManageMediaFolder(media.FolderPath)) {
return new HttpUnauthorizedResult();
}
var newFileName = Path.GetFileNameWithoutExtension(media.FileName) + " Copy" + Path.GetExtension(media.FileName);
var newFileName = _mediaLibraryService.GetUniqueFilename(media.FolderPath, media.FileName);
_mediaLibraryService.CopyFile(media.FolderPath, media.FileName, media.FolderPath, newFileName);
var clonedContentItem = Services.ContentManager.Clone(media.ContentItem);
@@ -241,13 +240,14 @@ namespace Orchard.MediaLibrary.Controllers {
var clonedTitlePart = clonedContentItem.As<TitlePart>();
clonedMediaPart.FileName = newFileName;
clonedMediaPart.FolderPath = media.FolderPath;
clonedMediaPart.MimeType = media.MimeType;
clonedTitlePart.Title = clonedTitlePart.Title + " Copy";
Services.ContentManager.Create(clonedContentItem);
Services.ContentManager.Publish(clonedContentItem);
return Json(true);
}
catch (Exception e) {
} catch (Exception e) {
Logger.Error(e, "Could not clone media item.");
return Json(false);
}
@@ -255,7 +255,7 @@ namespace Orchard.MediaLibrary.Controllers {
private FolderHierarchy GetFolderHierarchy(IMediaFolder root) {
Argument.ThrowIfNull(root, "root");
return new FolderHierarchy(root) {Children = _mediaLibraryService.GetMediaFolders(root.MediaPath).Select(GetFolderHierarchy)};
return new FolderHierarchy(root) { Children = _mediaLibraryService.GetMediaFolders(root.MediaPath).Select(GetFolderHierarchy) };
}
}
}

View File

@@ -10,4 +10,3 @@ Features:
Name: Resources
Description: Provides a variety of third-party client-side libraries (stylesheets and scripts) used by other modules.
Category: Core
Dependencies: Common