mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-21 19:34:40 +08:00
Squash
This commit is contained in:
@@ -132,31 +132,41 @@ namespace Orchard.Fields.Drivers {
|
|||||||
var showDate = settings.Display == DateTimeFieldDisplays.DateAndTime || settings.Display == DateTimeFieldDisplays.DateOnly;
|
var showDate = settings.Display == DateTimeFieldDisplays.DateAndTime || settings.Display == DateTimeFieldDisplays.DateOnly;
|
||||||
var showTime = settings.Display == DateTimeFieldDisplays.DateAndTime || settings.Display == DateTimeFieldDisplays.TimeOnly;
|
var showTime = settings.Display == DateTimeFieldDisplays.DateAndTime || settings.Display == DateTimeFieldDisplays.TimeOnly;
|
||||||
|
|
||||||
|
DateTime? value = null;
|
||||||
|
var IsParseError = false;
|
||||||
|
|
||||||
|
// If required and one field is missing, don't try to parse data.
|
||||||
if (settings.Required && ((showDate && String.IsNullOrWhiteSpace(viewModel.Editor.Date)) || (showTime && String.IsNullOrWhiteSpace(viewModel.Editor.Time)))) {
|
if (settings.Required && ((showDate && String.IsNullOrWhiteSpace(viewModel.Editor.Date)) || (showTime && String.IsNullOrWhiteSpace(viewModel.Editor.Time)))) {
|
||||||
updater.AddModelError(GetPrefix(field, part), T("{0} is required.", field.DisplayName));
|
// And use the default value only if all required fields are empty.
|
||||||
|
if (!showDate || !showTime || (String.IsNullOrWhiteSpace(viewModel.Editor.Date) && String.IsNullOrWhiteSpace(viewModel.Editor.Time))) {
|
||||||
|
value = settings.DefaultValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
try {
|
try {
|
||||||
var utcDateTime = DateLocalizationServices.ConvertFromLocalizedString(viewModel.Editor.Date, viewModel.Editor.Time, options);
|
var utcDateTime = DateLocalizationServices.ConvertFromLocalizedString(viewModel.Editor.Date, viewModel.Editor.Time, options);
|
||||||
|
value = utcDateTime.HasValue ? utcDateTime : settings.DefaultValue;
|
||||||
if (utcDateTime.HasValue) {
|
|
||||||
// Hackish workaround to make sure a time-only field with an entered time equivalent to
|
|
||||||
// 00:00 UTC doesn't get stored as a full DateTime.MinValue in the database, resulting
|
|
||||||
// in it being interpreted as an empty value when subsequently retrieved.
|
|
||||||
if (settings.Display == DateTimeFieldDisplays.TimeOnly && utcDateTime.Value == DateTime.MinValue) {
|
|
||||||
field.DateTime = utcDateTime.Value.AddDays(1);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
field.DateTime = utcDateTime.Value;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
field.DateTime = settings.DefaultValue.HasValue ? settings.DefaultValue.Value : DateTime.MinValue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
|
IsParseError = true;
|
||||||
updater.AddModelError(GetPrefix(field, part), T("{0} could not be parsed as a valid date and time.", field.DisplayName));
|
updater.AddModelError(GetPrefix(field, part), T("{0} could not be parsed as a valid date and time.", field.DisplayName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!IsParseError) {
|
||||||
|
// Hackish workaround to make sure a time-only field with an entered time equivalent to
|
||||||
|
// 00:00 UTC doesn't get stored as a full DateTime.MinValue in the database, resulting
|
||||||
|
// in it being interpreted as an empty value when subsequently retrieved.
|
||||||
|
if (value.HasValue && settings.Display == DateTimeFieldDisplays.TimeOnly && value == DateTime.MinValue) {
|
||||||
|
value = value.Value.AddDays(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.Required && (!value.HasValue || (settings.Display != DateTimeFieldDisplays.TimeOnly && value.Value.Date == DateTime.MinValue))) {
|
||||||
|
updater.AddModelError(GetPrefix(field, part), T("{0} is required.", field.DisplayName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
field.DateTime = value.HasValue ? value.Value : DateTime.MinValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Editor(part, field, shapeHelper);
|
return Editor(part, field, shapeHelper);
|
||||||
|
@@ -46,11 +46,11 @@ namespace Orchard.Fields.Drivers {
|
|||||||
if (updater.TryUpdateModel(field, GetPrefix(field, part), null, null)) {
|
if (updater.TryUpdateModel(field, GetPrefix(field, part), null, null)) {
|
||||||
var settings = field.PartFieldDefinition.Settings.GetModel<InputFieldSettings>();
|
var settings = field.PartFieldDefinition.Settings.GetModel<InputFieldSettings>();
|
||||||
|
|
||||||
if (field.Value == null && !String.IsNullOrEmpty(settings.DefaultValue)) {
|
if (String.IsNullOrWhiteSpace(field.Value) && !String.IsNullOrWhiteSpace(settings.DefaultValue)) {
|
||||||
field.Value = _tokenizer.Replace(settings.DefaultValue, new Dictionary<string, object> { { "Content", part.ContentItem } });
|
field.Value = _tokenizer.Replace(settings.DefaultValue, new Dictionary<string, object> { { "Content", part.ContentItem } });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings.Required && string.IsNullOrWhiteSpace(field.Value)) {
|
if (settings.Required && String.IsNullOrWhiteSpace(field.Value)) {
|
||||||
updater.AddModelError(GetPrefix(field, part), T("The field {0} is mandatory.", T(field.DisplayName)));
|
updater.AddModelError(GetPrefix(field, part), T("The field {0} is mandatory.", T(field.DisplayName)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -46,21 +46,21 @@ namespace Orchard.Fields.Drivers {
|
|||||||
if (updater.TryUpdateModel(field, GetPrefix(field, part), null, null)) {
|
if (updater.TryUpdateModel(field, GetPrefix(field, part), null, null)) {
|
||||||
var settings = field.PartFieldDefinition.Settings.GetModel<LinkFieldSettings>();
|
var settings = field.PartFieldDefinition.Settings.GetModel<LinkFieldSettings>();
|
||||||
|
|
||||||
if (String.IsNullOrEmpty(field.Value) && !String.IsNullOrEmpty(settings.DefaultValue)) {
|
if (String.IsNullOrWhiteSpace(field.Value) && !String.IsNullOrWhiteSpace(settings.DefaultValue)) {
|
||||||
field.Value = _tokenizer.Replace(settings.DefaultValue, new Dictionary<string, object> { { "Content", part.ContentItem } });
|
field.Value = _tokenizer.Replace(settings.DefaultValue, new Dictionary<string, object> { { "Content", part.ContentItem } });
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!String.IsNullOrEmpty(settings.TextDefaultValue) && String.IsNullOrWhiteSpace(field.Text)) {
|
if(!String.IsNullOrWhiteSpace(settings.TextDefaultValue) && String.IsNullOrWhiteSpace(field.Text)) {
|
||||||
field.Text = _tokenizer.Replace(settings.TextDefaultValue, new Dictionary<string, object> { { "Content", part.ContentItem } });
|
field.Text = _tokenizer.Replace(settings.TextDefaultValue, new Dictionary<string, object> { { "Content", part.ContentItem } });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings.Required && string.IsNullOrWhiteSpace(field.Value)) {
|
if (settings.Required && String.IsNullOrWhiteSpace(field.Value)) {
|
||||||
updater.AddModelError(GetPrefix(field, part), T("Url is required for {0}", field.DisplayName));
|
updater.AddModelError(GetPrefix(field, part), T("Url is required for {0}", field.DisplayName));
|
||||||
}
|
}
|
||||||
else if (!string.IsNullOrWhiteSpace(field.Value) && !Uri.IsWellFormedUriString(field.Value, UriKind.RelativeOrAbsolute)) {
|
else if (!String.IsNullOrWhiteSpace(field.Value) && !Uri.IsWellFormedUriString(field.Value, UriKind.RelativeOrAbsolute)) {
|
||||||
updater.AddModelError(GetPrefix(field, part), T("{0} is an invalid url.", field.Value));
|
updater.AddModelError(GetPrefix(field, part), T("{0} is an invalid url.", field.Value));
|
||||||
}
|
}
|
||||||
else if (settings.LinkTextMode == LinkTextMode.Required && string.IsNullOrWhiteSpace(field.Text)) {
|
else if (settings.LinkTextMode == LinkTextMode.Required && String.IsNullOrWhiteSpace(field.Text)) {
|
||||||
updater.AddModelError(GetPrefix(field, part), T("Text is required for {0}.", field.DisplayName));
|
updater.AddModelError(GetPrefix(field, part), T("Text is required for {0}.", field.DisplayName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -81,7 +81,7 @@
|
|||||||
<div>
|
<div>
|
||||||
<label for="@Html.FieldIdFor(m => m.DefaultValue)">@T("Default value")</label>
|
<label for="@Html.FieldIdFor(m => m.DefaultValue)">@T("Default value")</label>
|
||||||
@Html.TextBoxFor(m => m.DefaultValue, new { @class = "text large tokenized ui-autocomplete-input" })
|
@Html.TextBoxFor(m => m.DefaultValue, new { @class = "text large tokenized ui-autocomplete-input" })
|
||||||
<span class="hint">@T("A valid url as a default value, i.e. http://orchardproject.net, /content/file.pdf ... You can use tokens in this field. (optional)")</span>
|
<span class="hint">@T("Default value for the field. You can use tokens in this field. If there is no value given for the actual field, this will be filled in. (optional)")</span>
|
||||||
@Html.ValidationMessageFor(m => m.DefaultValue)
|
@Html.ValidationMessageFor(m => m.DefaultValue)
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
@@ -3,10 +3,11 @@
|
|||||||
@using Orchard.Fields.Settings;
|
@using Orchard.Fields.Settings;
|
||||||
@{
|
@{
|
||||||
var settings = Model.PartFieldDefinition.Settings.GetModel<InputFieldSettings>();
|
var settings = Model.PartFieldDefinition.Settings.GetModel<InputFieldSettings>();
|
||||||
|
var isRequired = settings.Required && String.IsNullOrWhiteSpace(settings.DefaultValue);
|
||||||
}
|
}
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<label for="@Html.FieldIdFor(m => m.Value)" @if(settings.Required) { <text>class="required"</text> }>@Model.DisplayName</label>
|
<label for="@Html.FieldIdFor(m => m.Value)" @if (settings.Required) { <text> class="required" </text> }>@Model.DisplayName</label>
|
||||||
<input type="@settings.Type.ToString().ToLower()" id="@Html.FieldIdFor(m => m.Value)" name="@Html.FieldNameFor(m => m.Value)"@if(!String.IsNullOrWhiteSpace(settings.Title)) {<text> title="@settings.Title"</text>} value="@Model.Value"@if(settings.Required) {<text> required="required"</text> }@if(settings.AutoFocus) {<text> autofocus="autofocus"</text> }@if(settings.AutoComplete) {<text> autocomplete="on"</text> }@if(!string.IsNullOrWhiteSpace(settings.Placeholder)) {<text> placeholder="@settings.Placeholder"</text>}@if(!string.IsNullOrEmpty(settings.Pattern)) {<text> pattern="@settings.Pattern"</text>}@if(!string.IsNullOrEmpty(settings.EditorCssClass)) {<text> class="@settings.EditorCssClass"</text>} else {<text> class="text medium"</text>} @if(settings.MaxLength > 1) {<text> maxlength="@settings.MaxLength.ToString()"</text>} />
|
<input type="@settings.Type.ToString().ToLower()" id="@Html.FieldIdFor(m => m.Value)" name="@Html.FieldNameFor(m => m.Value)" @if (!String.IsNullOrWhiteSpace(settings.Title)) { <text> title="@settings.Title" </text> } value="@Model.Value" @if (isRequired) { <text> required="required" </text> } @if (settings.AutoFocus) { <text> autofocus="autofocus" </text> } @if (settings.AutoComplete) { <text> autocomplete="on" </text> } @if (!String.IsNullOrWhiteSpace(settings.Placeholder)) { <text> placeholder="@settings.Placeholder" </text> } @if (!String.IsNullOrWhiteSpace(settings.Pattern)) { <text> pattern="@settings.Pattern" </text> } @if (!String.IsNullOrWhiteSpace(settings.EditorCssClass)) { <text> class="@settings.EditorCssClass" </text> } else { <text> class="text medium" </text> } @if (settings.MaxLength > 1) { <text> maxlength="@settings.MaxLength.ToString()" </text> } />
|
||||||
@Html.ValidationMessageFor(m => m.Value)
|
@Html.ValidationMessageFor(m => m.Value)
|
||||||
@if (HasText(settings.Hint)) {
|
@if (HasText(settings.Hint)) {
|
||||||
<span class="hint">@settings.Hint</span>
|
<span class="hint">@settings.Hint</span>
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
@using Orchard.Fields.Settings;
|
@using Orchard.Fields.Settings;
|
||||||
@{
|
@{
|
||||||
var settings = Model.PartFieldDefinition.Settings.GetModel<LinkFieldSettings>();
|
var settings = Model.PartFieldDefinition.Settings.GetModel<LinkFieldSettings>();
|
||||||
string target = string.Empty;
|
string target = String.Empty;
|
||||||
switch (settings.TargetMode) {
|
switch (settings.TargetMode) {
|
||||||
case TargetMode.NewWindow:
|
case TargetMode.NewWindow:
|
||||||
target = "_blank";
|
target = "_blank";
|
||||||
@@ -14,6 +14,9 @@
|
|||||||
target = "_top";
|
target = "_top";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var isRequired = settings.Required && String.IsNullOrWhiteSpace(settings.DefaultValue);
|
||||||
|
var isTextRequired = settings.LinkTextMode == LinkTextMode.Required && String.IsNullOrWhiteSpace(settings.TextDefaultValue);
|
||||||
}
|
}
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<label for="@Html.FieldIdFor(m => m.Value)">@Model.DisplayName</label>
|
<label for="@Html.FieldIdFor(m => m.Value)">@Model.DisplayName</label>
|
||||||
@@ -21,10 +24,10 @@
|
|||||||
<span class="hint">@settings.Hint</span>
|
<span class="hint">@settings.Hint</span>
|
||||||
}
|
}
|
||||||
<div class="editor-label">
|
<div class="editor-label">
|
||||||
<label for="@Html.FieldIdFor(m => m.Value)" @if(settings.Required) { <text>class="required"</text> }>@T("Url")</label>
|
<label for="@Html.FieldIdFor(m => m.Value)" @if (settings.Required) { <text> class="required" </text> }>@T("Url")</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="editor-field">
|
<div class="editor-field">
|
||||||
@Html.TextBoxFor(m => m.Value, new { @class = "text large" })
|
@(isRequired ? Html.TextBoxFor(m => m.Value, new { @class = "text large", required = "required" }) : Html.TextBoxFor(m => m.Value, new { @class = "text large" }))
|
||||||
<span class="hint">@T("A valid url, i.e. http://orchardproject.net, /content/file.pdf, ...")</span>
|
<span class="hint">@T("A valid url, i.e. http://orchardproject.net, /content/file.pdf, ...")</span>
|
||||||
</div>
|
</div>
|
||||||
@if (!String.IsNullOrWhiteSpace(settings.DefaultValue)) {
|
@if (!String.IsNullOrWhiteSpace(settings.DefaultValue)) {
|
||||||
@@ -32,10 +35,10 @@
|
|||||||
}
|
}
|
||||||
@if (settings.LinkTextMode == LinkTextMode.Optional || settings.LinkTextMode == LinkTextMode.Required) {
|
@if (settings.LinkTextMode == LinkTextMode.Optional || settings.LinkTextMode == LinkTextMode.Required) {
|
||||||
<div class="editor-label">
|
<div class="editor-label">
|
||||||
<label for="@Html.FieldIdFor(m => m.Text)" @if(settings.LinkTextMode == LinkTextMode.Required) { <text>class="required"</text> }>@T("Text")</label>
|
<label for="@Html.FieldIdFor(m => m.Text)" @if (settings.LinkTextMode == LinkTextMode.Required) { <text> class="required" </text> }>@T("Text")</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="editor-field">
|
<div class="editor-field">
|
||||||
@Html.TextBoxFor(m => m.Text, new { @class = "text medium" })
|
@(isTextRequired ? Html.TextBoxFor(m => m.Text, new { @class = "text medium", required = "required" }) : Html.TextBoxFor(m => m.Text, new { @class = "text medium" }))
|
||||||
@if (!String.IsNullOrWhiteSpace(settings.TextDefaultValue)) {
|
@if (!String.IsNullOrWhiteSpace(settings.TextDefaultValue)) {
|
||||||
<span class="hint">@T("If the field is left empty then the default value will be used.")</span>
|
<span class="hint">@T("If the field is left empty then the default value will be used.")</span>
|
||||||
}
|
}
|
||||||
@@ -50,7 +53,7 @@
|
|||||||
<label for="@Html.FieldIdFor(m => m.Target)">@T("Target")</label>
|
<label for="@Html.FieldIdFor(m => m.Target)">@T("Target")</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="editor-field">
|
<div class="editor-field">
|
||||||
@Html.TextBoxFor(m => m.Target, new { @class = "text"})
|
@Html.TextBoxFor(m => m.Target, new { @class = "text" })
|
||||||
<span class="hint">@T("A valid HTML target attribute value. e.g., _blank, _parent, _top, or an anchor. ")</span>
|
<span class="hint">@T("A valid HTML target attribute value. e.g., _blank, _parent, _top, or an anchor. ")</span>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user