mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-21 03:14:10 +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 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)))) {
|
||||
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 {
|
||||
try {
|
||||
var utcDateTime = DateLocalizationServices.ConvertFromLocalizedString(viewModel.Editor.Date, viewModel.Editor.Time, options);
|
||||
|
||||
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;
|
||||
}
|
||||
value = utcDateTime.HasValue ? utcDateTime : settings.DefaultValue;
|
||||
}
|
||||
catch {
|
||||
IsParseError = true;
|
||||
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);
|
||||
|
@@ -46,11 +46,11 @@ namespace Orchard.Fields.Drivers {
|
||||
if (updater.TryUpdateModel(field, GetPrefix(field, part), null, null)) {
|
||||
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 } });
|
||||
}
|
||||
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
@@ -46,21 +46,21 @@ namespace Orchard.Fields.Drivers {
|
||||
if (updater.TryUpdateModel(field, GetPrefix(field, part), null, null)) {
|
||||
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 } });
|
||||
}
|
||||
|
||||
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 } });
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
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));
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
@@ -81,7 +81,7 @@
|
||||
<div>
|
||||
<label for="@Html.FieldIdFor(m => m.DefaultValue)">@T("Default value")</label>
|
||||
@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)
|
||||
</div>
|
||||
</fieldset>
|
||||
</fieldset>
|
||||
|
@@ -3,13 +3,14 @@
|
||||
@using Orchard.Fields.Settings;
|
||||
@{
|
||||
var settings = Model.PartFieldDefinition.Settings.GetModel<InputFieldSettings>();
|
||||
var isRequired = settings.Required && String.IsNullOrWhiteSpace(settings.DefaultValue);
|
||||
}
|
||||
<fieldset>
|
||||
<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>} />
|
||||
<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 (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)
|
||||
@if (HasText(settings.Hint)) {
|
||||
<span class="hint">@settings.Hint</span>
|
||||
<span class="hint">@settings.Hint</span>
|
||||
}
|
||||
@if (!String.IsNullOrWhiteSpace(settings.DefaultValue)) {
|
||||
<span class="hint">@T("If the field is left empty then the default value will be used.")</span>
|
||||
|
@@ -2,7 +2,7 @@
|
||||
@using Orchard.Fields.Settings;
|
||||
@{
|
||||
var settings = Model.PartFieldDefinition.Settings.GetModel<LinkFieldSettings>();
|
||||
string target = string.Empty;
|
||||
string target = String.Empty;
|
||||
switch (settings.TargetMode) {
|
||||
case TargetMode.NewWindow:
|
||||
target = "_blank";
|
||||
@@ -13,18 +13,21 @@
|
||||
case TargetMode.Top:
|
||||
target = "_top";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var isRequired = settings.Required && String.IsNullOrWhiteSpace(settings.DefaultValue);
|
||||
var isTextRequired = settings.LinkTextMode == LinkTextMode.Required && String.IsNullOrWhiteSpace(settings.TextDefaultValue);
|
||||
}
|
||||
<fieldset>
|
||||
<label for="@Html.FieldIdFor(m => m.Value)">@Model.DisplayName</label>
|
||||
@if (HasText(settings.Hint)) {
|
||||
<span class="hint">@settings.Hint</span>
|
||||
<span class="hint">@settings.Hint</span>
|
||||
}
|
||||
<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 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>
|
||||
</div>
|
||||
@if (!String.IsNullOrWhiteSpace(settings.DefaultValue)) {
|
||||
@@ -32,10 +35,10 @@
|
||||
}
|
||||
@if (settings.LinkTextMode == LinkTextMode.Optional || settings.LinkTextMode == LinkTextMode.Required) {
|
||||
<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 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)) {
|
||||
<span class="hint">@T("If the field is left empty then the default value will be used.")</span>
|
||||
}
|
||||
@@ -44,13 +47,13 @@
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
|
||||
@if (settings.TargetMode == TargetMode.UserChoice) {
|
||||
<div class="editor-label">
|
||||
<label for="@Html.FieldIdFor(m => m.Target)">@T("Target")</label>
|
||||
</div>
|
||||
<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>
|
||||
</div>
|
||||
}
|
||||
|
Reference in New Issue
Block a user