mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-24 18:25:04 +08:00
Merge branch 'refs/heads/1.10.x' into dev
This commit is contained in:
@@ -17,13 +17,18 @@
|
||||
|
||||
//We will use a script to find the fieldset for the field we are currently processing.
|
||||
//The fieldset contains a span of class "hint". We will add tryTranslateMsg to it.
|
||||
//We will check if the field exists in the page DOM, just in case a Placement.info suppresses it.
|
||||
string dataPartName = HttpUtility.JavaScriptStringEncode(Model.Part.PartDefinition.Name);
|
||||
string dataFieldName = HttpUtility.JavaScriptStringEncode(Model.Field.PartFieldDefinition.Name);
|
||||
}
|
||||
<input type="hidden" id="@dataPartName-@dataFieldName-tryTranslateMsg" value="@tryTranslateMsg" />
|
||||
@using (Script.Foot()) {
|
||||
<script type="text/javascript">
|
||||
$(function () {
|
||||
$("fieldset[data-part-name='@dataPartName'][data-field-name='@dataFieldName']").find("span.hint")[0].innerText += "@tryTranslateMsg";
|
||||
var hint = $("fieldset[data-part-name='@dataPartName'][data-field-name='@dataFieldName']").find("span.hint")[0];
|
||||
if (hint) {
|
||||
hint.innerText += " " + $("#@dataPartName-@dataFieldName-tryTranslateMsg").val();
|
||||
}
|
||||
});
|
||||
@foreach (var contentItem in Model.ContentItems) {
|
||||
var loc = contentItem.As<LocalizationPart>();
|
||||
|
||||
@@ -104,6 +104,8 @@ namespace Orchard.Projections.FilterEditors.Forms {
|
||||
f._Operator.Add(new SelectListItem { Value = Convert.ToString(DateTimeOperator.GreaterThan), Text = T("Is greater than").Text });
|
||||
f._Operator.Add(new SelectListItem { Value = Convert.ToString(DateTimeOperator.Between), Text = T("Is between").Text });
|
||||
f._Operator.Add(new SelectListItem { Value = Convert.ToString(DateTimeOperator.NotBetween), Text = T("Is not between").Text });
|
||||
f._Operator.Add(new SelectListItem { Value = Convert.ToString(DateTimeOperator.IsNull), Text = T("Is null").Text });
|
||||
f._Operator.Add(new SelectListItem { Value = Convert.ToString(DateTimeOperator.IsNotNull), Text = T("Is not null").Text });
|
||||
|
||||
foreach (var unit in new[] { f._FieldSetSingle._ValueUnit, f._FieldSetMin._MinUnit, f._FieldSetMax._MaxUnit }) {
|
||||
unit.Add(new SelectListItem { Value = Convert.ToString(DateTimeSpan.Year), Text = T("Year").Text });
|
||||
@@ -125,67 +127,95 @@ namespace Orchard.Projections.FilterEditors.Forms {
|
||||
|
||||
var op = (DateTimeOperator)Enum.Parse(typeof(DateTimeOperator), Convert.ToString(formState.Operator));
|
||||
|
||||
string type = Convert.ToString(formState.ValueType);
|
||||
|
||||
DateTime min, max;
|
||||
|
||||
// Are those dates or time spans
|
||||
if (type == "0") {
|
||||
if (op == DateTimeOperator.Between || op == DateTimeOperator.NotBetween) {
|
||||
min = GetLowBoundPattern(Convert.ToString(formState.Min));
|
||||
max = GetHighBoundPattern(Convert.ToString(formState.Max));
|
||||
}
|
||||
else {
|
||||
min = GetLowBoundPattern(Convert.ToString(formState.Value));
|
||||
max = GetHighBoundPattern(Convert.ToString(formState.Value));
|
||||
}
|
||||
}
|
||||
if (op == DateTimeOperator.IsNull)
|
||||
return y => y.IsNull(property);
|
||||
else
|
||||
if (op == DateTimeOperator.IsNotNull)
|
||||
return y => y.IsNotNull(property);
|
||||
else {
|
||||
if (op == DateTimeOperator.Between || op == DateTimeOperator.NotBetween) {
|
||||
min = ApplyDelta(now, formState.MinUnit.Value, Int32.Parse(formState.Min.Value));
|
||||
max = ApplyDelta(now, formState.MaxUnit.Value, Int32.Parse(formState.Max.Value));
|
||||
string type = Convert.ToString(formState.ValueType);
|
||||
|
||||
DateTime? min, max;
|
||||
|
||||
// Are those dates or time spans
|
||||
if (type == "0") {
|
||||
if (op == DateTimeOperator.Between || op == DateTimeOperator.NotBetween) {
|
||||
min = GetLowBoundPattern(Convert.ToString(formState.Min));
|
||||
max = GetHighBoundPattern(Convert.ToString(formState.Max));
|
||||
}
|
||||
else {
|
||||
min = GetLowBoundPattern(Convert.ToString(formState.Value));
|
||||
max = GetHighBoundPattern(Convert.ToString(formState.Value));
|
||||
}
|
||||
}
|
||||
else {
|
||||
min = max = ApplyDelta(now, Convert.ToString(formState.ValueUnit), Convert.ToInt32(formState.Value));
|
||||
if (op == DateTimeOperator.Between || op == DateTimeOperator.NotBetween) {
|
||||
min = ApplyDelta(now, formState.MinUnit.Value, Int32.Parse(formState.Min.Value));
|
||||
max = ApplyDelta(now, formState.MaxUnit.Value, Int32.Parse(formState.Max.Value));
|
||||
}
|
||||
else {
|
||||
min = max = ApplyDelta(now, Convert.ToString(formState.ValueUnit), Convert.ToInt32(formState.Value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
min = min.ToUniversalTime();
|
||||
max = max.ToUniversalTime();
|
||||
if (min.HasValue)
|
||||
min = min.Value.ToUniversalTime();
|
||||
|
||||
object minValue = min;
|
||||
object maxValue = max;
|
||||
if (max.HasValue)
|
||||
max = max.Value.ToUniversalTime();
|
||||
|
||||
if(asTicks) {
|
||||
minValue = min.Ticks;
|
||||
maxValue = max.Ticks;
|
||||
}
|
||||
object minValue;
|
||||
|
||||
switch (op) {
|
||||
case DateTimeOperator.LessThan:
|
||||
return x => x.Lt(property, maxValue);
|
||||
case DateTimeOperator.LessThanEquals:
|
||||
return x => x.Le(property, maxValue);
|
||||
case DateTimeOperator.Equals:
|
||||
if (min == max) {
|
||||
return x => x.Eq(property, minValue);
|
||||
}
|
||||
return y => y.And(x => x.Ge(property, minValue), x => x.Le(property, maxValue));
|
||||
case DateTimeOperator.NotEquals:
|
||||
if (min == max) {
|
||||
return x => x.Not(y => y.Eq(property, minValue));
|
||||
}
|
||||
return y => y.Or(x => x.Lt(property, minValue), x => x.Gt(property, maxValue));
|
||||
case DateTimeOperator.GreaterThan:
|
||||
return x => x.Gt(property, minValue);
|
||||
case DateTimeOperator.GreaterThanEquals:
|
||||
return x => x.Ge(property, minValue);
|
||||
case DateTimeOperator.Between:
|
||||
return y => y.And(x => x.Ge(property, minValue), x => x.Le(property, maxValue));
|
||||
case DateTimeOperator.NotBetween:
|
||||
return y => y.Or(x => x.Lt(property, minValue), x => x.Gt(property, maxValue));
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
if (min.HasValue)
|
||||
minValue = min.Value;
|
||||
else
|
||||
minValue = "";
|
||||
|
||||
object maxValue;
|
||||
|
||||
if (max.HasValue)
|
||||
maxValue = max.Value;
|
||||
else
|
||||
maxValue = "";
|
||||
|
||||
if(asTicks) {
|
||||
if (min.HasValue)
|
||||
minValue = min.Value.Ticks;
|
||||
else
|
||||
minValue = 0;
|
||||
|
||||
if (max.HasValue)
|
||||
maxValue = max.Value.Ticks;
|
||||
else
|
||||
maxValue = 0;
|
||||
}
|
||||
|
||||
switch (op) {
|
||||
case DateTimeOperator.LessThan:
|
||||
return x => x.Lt(property, maxValue);
|
||||
case DateTimeOperator.LessThanEquals:
|
||||
return x => x.Le(property, maxValue);
|
||||
case DateTimeOperator.Equals:
|
||||
if (min == max) {
|
||||
return x => x.Eq(property, minValue);
|
||||
}
|
||||
return y => y.And(x => x.Ge(property, minValue), x => x.Le(property, maxValue));
|
||||
case DateTimeOperator.NotEquals:
|
||||
if (min == max) {
|
||||
return x => x.Not(y => y.Eq(property, minValue));
|
||||
}
|
||||
return y => y.Or(x => x.Lt(property, minValue), x => x.Gt(property, maxValue));
|
||||
case DateTimeOperator.GreaterThan:
|
||||
return x => x.Gt(property, minValue);
|
||||
case DateTimeOperator.GreaterThanEquals:
|
||||
return x => x.Ge(property, minValue);
|
||||
case DateTimeOperator.Between:
|
||||
return y => y.And(x => x.Ge(property, minValue), x => x.Le(property, maxValue));
|
||||
case DateTimeOperator.NotBetween:
|
||||
return y => y.Or(x => x.Lt(property, minValue), x => x.Gt(property, maxValue));
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,18 +223,23 @@ namespace Orchard.Projections.FilterEditors.Forms {
|
||||
/// Returns the low bound value of a date pattern. e.g., 2011-10 will return 2011-10-01 00:00:00
|
||||
/// </summary>
|
||||
/// <remarks>DateTime is stored in UTC but entered in local</remarks>
|
||||
protected static DateTime GetLowBoundPattern(string datePattern) {
|
||||
var match = _dateRegEx.Match(datePattern);
|
||||
protected static DateTime? GetLowBoundPattern(string datePattern) {
|
||||
if (string.IsNullOrEmpty(datePattern)) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
var match = _dateRegEx.Match(datePattern);
|
||||
|
||||
return DateTime.Parse(
|
||||
String.Format("{0}-{1}-{2} {3}:{4}:{5}",
|
||||
match.Groups["year"].Success ? match.Groups["year"].Value : "1980",
|
||||
match.Groups["month"].Success ? match.Groups["month"].Value : "01",
|
||||
match.Groups["day"].Success ? match.Groups["day"].Value : "01",
|
||||
match.Groups["hour"].Success ? match.Groups["hour"].Value : "00",
|
||||
match.Groups["minute"].Success ? match.Groups["minute"].Value : "00",
|
||||
match.Groups["second"].Success ? match.Groups["second"].Value : "00"),
|
||||
CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal);
|
||||
return DateTime.Parse(
|
||||
String.Format("{0}-{1}-{2} {3}:{4}:{5}",
|
||||
match.Groups["year"].Success ? match.Groups["year"].Value : "1980",
|
||||
match.Groups["month"].Success ? match.Groups["month"].Value : "01",
|
||||
match.Groups["day"].Success ? match.Groups["day"].Value : "01",
|
||||
match.Groups["hour"].Success ? match.Groups["hour"].Value : "00",
|
||||
match.Groups["minute"].Success ? match.Groups["minute"].Value : "00",
|
||||
match.Groups["second"].Success ? match.Groups["second"].Value : "00"),
|
||||
CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal);
|
||||
}
|
||||
}
|
||||
|
||||
protected static DateTime ApplyDelta(DateTime now, string unit, int value) {
|
||||
@@ -230,40 +265,48 @@ namespace Orchard.Projections.FilterEditors.Forms {
|
||||
|
||||
public static LocalizedString DisplayFilter(string fieldName, dynamic formState, Localizer T) {
|
||||
var op = (DateTimeOperator)Enum.Parse(typeof(DateTimeOperator), Convert.ToString(formState.Operator));
|
||||
string type = Convert.ToString(formState.ValueType);
|
||||
string value = Convert.ToString(formState.Value);
|
||||
string min = Convert.ToString(formState.Min);
|
||||
string max = Convert.ToString(formState.Max);
|
||||
string valueUnit = Convert.ToString(formState.ValueUnit);
|
||||
string minUnit = Convert.ToString(formState.MinUnit);
|
||||
string maxUnit = Convert.ToString(formState.MaxUnit);
|
||||
|
||||
if (type == "0") {
|
||||
valueUnit = minUnit = maxUnit = String.Empty;
|
||||
}
|
||||
if (op == DateTimeOperator.IsNull)
|
||||
return T("{0} is null", fieldName);
|
||||
else
|
||||
if (op == DateTimeOperator.IsNotNull)
|
||||
return T("{0} is not null", fieldName);
|
||||
else {
|
||||
valueUnit = " " + valueUnit;
|
||||
minUnit = " " + minUnit;
|
||||
maxUnit = " " + maxUnit;
|
||||
}
|
||||
string type = Convert.ToString(formState.ValueType);
|
||||
string value = Convert.ToString(formState.Value);
|
||||
string min = Convert.ToString(formState.Min);
|
||||
string max = Convert.ToString(formState.Max);
|
||||
string valueUnit = Convert.ToString(formState.ValueUnit);
|
||||
string minUnit = Convert.ToString(formState.MinUnit);
|
||||
string maxUnit = Convert.ToString(formState.MaxUnit);
|
||||
|
||||
switch (op) {
|
||||
case DateTimeOperator.LessThan:
|
||||
return T("{0} is less than {1}{2}", fieldName, value, T(valueUnit));
|
||||
case DateTimeOperator.LessThanEquals:
|
||||
return T("{0} is less than or equal to {1}{2}", fieldName, value, T(valueUnit));
|
||||
case DateTimeOperator.Equals:
|
||||
return T("{0} equals {1}{2}", fieldName, value, T(valueUnit));
|
||||
case DateTimeOperator.NotEquals:
|
||||
return T("{0} is not equal to {1}{2}", fieldName, value, T(valueUnit));
|
||||
case DateTimeOperator.GreaterThan:
|
||||
return T("{0} is greater than {1}{2}", fieldName, value, T(valueUnit));
|
||||
case DateTimeOperator.GreaterThanEquals:
|
||||
return T("{0} is greater than or equal to {1}{2}", fieldName, value, T(valueUnit));
|
||||
case DateTimeOperator.Between:
|
||||
return T("{0} is between {1}{2} and {3}{4}", fieldName, min, T(minUnit), max, T(maxUnit));
|
||||
case DateTimeOperator.NotBetween:
|
||||
return T("{0} is not between {1}{2} and {3}{4}", fieldName, min, T(minUnit), max, T(maxUnit));
|
||||
if (type == "0") {
|
||||
valueUnit = minUnit = maxUnit = String.Empty;
|
||||
}
|
||||
else {
|
||||
valueUnit = " " + valueUnit;
|
||||
minUnit = " " + minUnit;
|
||||
maxUnit = " " + maxUnit;
|
||||
}
|
||||
|
||||
switch (op) {
|
||||
case DateTimeOperator.LessThan:
|
||||
return T("{0} is less than {1}{2}", fieldName, value, T(valueUnit));
|
||||
case DateTimeOperator.LessThanEquals:
|
||||
return T("{0} is less than or equal to {1}{2}", fieldName, value, T(valueUnit));
|
||||
case DateTimeOperator.Equals:
|
||||
return T("{0} equals {1}{2}", fieldName, value, T(valueUnit));
|
||||
case DateTimeOperator.NotEquals:
|
||||
return T("{0} is not equal to {1}{2}", fieldName, value, T(valueUnit));
|
||||
case DateTimeOperator.GreaterThan:
|
||||
return T("{0} is greater than {1}{2}", fieldName, value, T(valueUnit));
|
||||
case DateTimeOperator.GreaterThanEquals:
|
||||
return T("{0} is greater than or equal to {1}{2}", fieldName, value, T(valueUnit));
|
||||
case DateTimeOperator.Between:
|
||||
return T("{0} is between {1}{2} and {3}{4}", fieldName, min, T(minUnit), max, T(maxUnit));
|
||||
case DateTimeOperator.NotBetween:
|
||||
return T("{0} is not between {1}{2} and {3}{4}", fieldName, min, T(minUnit), max, T(maxUnit));
|
||||
}
|
||||
}
|
||||
|
||||
// should never be hit, but fail safe
|
||||
@@ -274,19 +317,24 @@ namespace Orchard.Projections.FilterEditors.Forms {
|
||||
/// Returns the low bound value of a date pattern. e.g., 2011-10 will return 2011-10-01 00:00:00
|
||||
/// </summary>
|
||||
/// <remarks>DateTime is stored in UTC but entered in local</remarks>
|
||||
protected static DateTime GetHighBoundPattern(string datePattern) {
|
||||
var match = _dateRegEx.Match(datePattern);
|
||||
protected static DateTime? GetHighBoundPattern(string datePattern) {
|
||||
if (string.IsNullOrEmpty(datePattern)) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
var match = _dateRegEx.Match(datePattern);
|
||||
|
||||
string year, month;
|
||||
return DateTime.Parse(
|
||||
String.Format("{0}-{1}-{2} {3}:{4}:{5}",
|
||||
year = match.Groups["year"].Success ? match.Groups["year"].Value : "2099",
|
||||
month = match.Groups["month"].Success ? match.Groups["month"].Value : "12",
|
||||
match.Groups["day"].Success ? match.Groups["day"].Value : DateTime.DaysInMonth(Int32.Parse(year), Int32.Parse(month)).ToString(),
|
||||
match.Groups["hour"].Success ? match.Groups["hour"].Value : "23",
|
||||
match.Groups["minute"].Success ? match.Groups["minute"].Value : "59",
|
||||
match.Groups["second"].Success ? match.Groups["second"].Value : "59"),
|
||||
CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal);
|
||||
string year, month;
|
||||
return DateTime.Parse(
|
||||
String.Format("{0}-{1}-{2} {3}:{4}:{5}",
|
||||
year = match.Groups["year"].Success ? match.Groups["year"].Value : "2099",
|
||||
month = match.Groups["month"].Success ? match.Groups["month"].Value : "12",
|
||||
match.Groups["day"].Success ? match.Groups["day"].Value : DateTime.DaysInMonth(Int32.Parse(year), Int32.Parse(month)).ToString(),
|
||||
match.Groups["hour"].Success ? match.Groups["hour"].Value : "23",
|
||||
match.Groups["minute"].Success ? match.Groups["minute"].Value : "59",
|
||||
match.Groups["second"].Success ? match.Groups["second"].Value : "59"),
|
||||
CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -299,7 +347,9 @@ namespace Orchard.Projections.FilterEditors.Forms {
|
||||
GreaterThan,
|
||||
GreaterThanEquals,
|
||||
Between,
|
||||
NotBetween
|
||||
NotBetween,
|
||||
IsNull,
|
||||
IsNotNull
|
||||
}
|
||||
|
||||
public enum DateTimeSpan {
|
||||
|
||||
@@ -13,70 +13,77 @@ namespace Orchard.Projections.FilterEditors.Forms {
|
||||
public override void Validating(ValidatingContext context) {
|
||||
if (context.FormName == DateTimeFilterForm.FormName) {
|
||||
|
||||
var isRange = new[] {"Between", "NotBetween"}.Contains(context.ValueProvider.GetValue("Operator").AttemptedValue);
|
||||
var min = context.ValueProvider.GetValue("Min");
|
||||
var max = context.ValueProvider.GetValue("Max");
|
||||
var value = context.ValueProvider.GetValue("Value");
|
||||
var valueType = context.ValueProvider.GetValue("ValueType");
|
||||
var op = (DateTimeOperator)Enum.Parse(typeof(DateTimeOperator), Convert.ToString(context.ValueProvider.GetValue("Operator").AttemptedValue));
|
||||
|
||||
// validating mandatory values
|
||||
if (isRange) {
|
||||
if (min == null || String.IsNullOrWhiteSpace(min.AttemptedValue)) {
|
||||
context.ModelState.AddModelError("Min", T("The field {0} is required.", T("Min").Text).Text);
|
||||
}
|
||||
|
||||
if (max == null || String.IsNullOrWhiteSpace(max.AttemptedValue)) {
|
||||
context.ModelState.AddModelError("Max", T("The field {0} is required.", T("Max").Text).Text);
|
||||
}
|
||||
if (op == DateTimeOperator.IsNull || op == DateTimeOperator.IsNotNull) {
|
||||
// no further validation needed
|
||||
}
|
||||
else {
|
||||
if (min == null || String.IsNullOrWhiteSpace(value.AttemptedValue)) {
|
||||
context.ModelState.AddModelError("Value", T("The field {0} is required.", T("Value").Text).Text);
|
||||
}
|
||||
}
|
||||
var isRange = new[] {DateTimeOperator.Between, DateTimeOperator.NotBetween}.Contains(op);
|
||||
var min = context.ValueProvider.GetValue("Min");
|
||||
var max = context.ValueProvider.GetValue("Max");
|
||||
var value = context.ValueProvider.GetValue("Value");
|
||||
var valueType = context.ValueProvider.GetValue("ValueType");
|
||||
|
||||
if (!context.ModelState.IsValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
// validating data type
|
||||
if (valueType.AttemptedValue == "0") {
|
||||
// A date
|
||||
|
||||
if(isRange) {
|
||||
if(!_dateRegEx.IsMatch(min.AttemptedValue) && !IsToken(min.AttemptedValue)) {
|
||||
context.ModelState.AddModelError("Min", T("The field {0} should contain a valid date (YYYY-MM-DD hh:mm:ss)", T("Min").Text).Text);
|
||||
}
|
||||
|
||||
if (!_dateRegEx.IsMatch(max.AttemptedValue) && !IsToken(max.AttemptedValue)) {
|
||||
context.ModelState.AddModelError("Max", T("The field {0} should contain a valid date (YYYY-MM-DD hh:mm:ss)", T("Max").Text).Text);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!_dateRegEx.IsMatch(value.AttemptedValue) && !IsToken(value.AttemptedValue)) {
|
||||
context.ModelState.AddModelError("Value", T("The field {0} should contain a valid date (YYYY-MM-DD hh:mm:ss)", T("Value").Text).Text);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
// An offset
|
||||
int number;
|
||||
// validating mandatory values
|
||||
if (isRange) {
|
||||
if (!Int32.TryParse(min.AttemptedValue, out number) && !IsToken(min.AttemptedValue)) {
|
||||
context.ModelState.AddModelError("Min", T("The field {0} must be a valid number.", T("Min").Text).Text);
|
||||
if (min == null || String.IsNullOrWhiteSpace(min.AttemptedValue)) {
|
||||
context.ModelState.AddModelError("Min", T("The field {0} is required.", T("Min").Text).Text);
|
||||
}
|
||||
|
||||
if (!Int32.TryParse(max.AttemptedValue, out number) && !IsToken(max.AttemptedValue)) {
|
||||
context.ModelState.AddModelError("Max", T("The field {0} must be a valid number.", T("Max").Text).Text);
|
||||
if (max == null || String.IsNullOrWhiteSpace(max.AttemptedValue)) {
|
||||
context.ModelState.AddModelError("Max", T("The field {0} is required.", T("Max").Text).Text);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!Int32.TryParse(value.AttemptedValue, out number) && !IsToken(value.AttemptedValue)) {
|
||||
context.ModelState.AddModelError("Value", T("The field {0} must be a valid number.", T("Value").Text).Text);
|
||||
if (min == null || String.IsNullOrWhiteSpace(value.AttemptedValue)) {
|
||||
context.ModelState.AddModelError("Value", T("The field {0} is required.", T("Value").Text).Text);
|
||||
}
|
||||
}
|
||||
|
||||
if (!context.ModelState.IsValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
// validating data type
|
||||
if (valueType.AttemptedValue == "0") {
|
||||
// A date
|
||||
|
||||
if(isRange) {
|
||||
if(!_dateRegEx.IsMatch(min.AttemptedValue) && !IsToken(min.AttemptedValue)) {
|
||||
context.ModelState.AddModelError("Min", T("The field {0} should contain a valid date (YYYY-MM-DD hh:mm:ss)", T("Min").Text).Text);
|
||||
}
|
||||
|
||||
if (!_dateRegEx.IsMatch(max.AttemptedValue) && !IsToken(max.AttemptedValue)) {
|
||||
context.ModelState.AddModelError("Max", T("The field {0} should contain a valid date (YYYY-MM-DD hh:mm:ss)", T("Max").Text).Text);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!_dateRegEx.IsMatch(value.AttemptedValue) && !IsToken(value.AttemptedValue)) {
|
||||
context.ModelState.AddModelError("Value", T("The field {0} should contain a valid date (YYYY-MM-DD hh:mm:ss)", T("Value").Text).Text);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
// An offset
|
||||
int number;
|
||||
if (isRange) {
|
||||
if (!Int32.TryParse(min.AttemptedValue, out number) && !IsToken(min.AttemptedValue)) {
|
||||
context.ModelState.AddModelError("Min", T("The field {0} must be a valid number.", T("Min").Text).Text);
|
||||
}
|
||||
|
||||
if (!Int32.TryParse(max.AttemptedValue, out number) && !IsToken(max.AttemptedValue)) {
|
||||
context.ModelState.AddModelError("Max", T("The field {0} must be a valid number.", T("Max").Text).Text);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!Int32.TryParse(value.AttemptedValue, out number) && !IsToken(value.AttemptedValue)) {
|
||||
context.ModelState.AddModelError("Value", T("The field {0} must be a valid number.", T("Value").Text).Text);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,16 +2,30 @@
|
||||
// show/hide Min/Max fields
|
||||
$("#operator option:selected").each(function () {
|
||||
var val = $(this).val();
|
||||
if (val == 'Between' || val == 'NotBetween') {
|
||||
|
||||
if (val == 'IsNull' || val == 'IsNotNull') {
|
||||
$('#value-type-date').closest('div').hide();
|
||||
$('#value-type-timespan').closest('div').hide();
|
||||
|
||||
$('#fieldset-single').hide();
|
||||
$('#fieldset-min').show();
|
||||
$('#fieldset-max').show();
|
||||
}
|
||||
else {
|
||||
$('#fieldset-single').show();
|
||||
$('#fieldset-min').hide();
|
||||
$('#fieldset-max').hide();
|
||||
}
|
||||
else {
|
||||
$('#value-type-date').closest('div').show();
|
||||
$('#value-type-timespan').closest('div').show();
|
||||
|
||||
if (val == 'Between' || val == 'NotBetween') {
|
||||
$('#fieldset-single').hide();
|
||||
$('#fieldset-min').show();
|
||||
$('#fieldset-max').show();
|
||||
}
|
||||
else {
|
||||
$('#fieldset-single').show();
|
||||
$('#fieldset-min').hide();
|
||||
$('#fieldset-max').hide();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// show/hide unit selectors
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace Orchard.Tokens.Providers {
|
||||
|
||||
FeedItem<ContentItem> item = feedItem;
|
||||
context.Response.Contextualize(requestContext => {
|
||||
author.Value = _tokenizer.Replace(settings.Title, new { Content = item.Item, Text = author.Value });
|
||||
author.Value = _tokenizer.Replace(settings.Author, new { Content = item.Item, Text = author.Value });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user