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.
|
//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.
|
//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 dataPartName = HttpUtility.JavaScriptStringEncode(Model.Part.PartDefinition.Name);
|
||||||
string dataFieldName = HttpUtility.JavaScriptStringEncode(Model.Field.PartFieldDefinition.Name);
|
string dataFieldName = HttpUtility.JavaScriptStringEncode(Model.Field.PartFieldDefinition.Name);
|
||||||
}
|
}
|
||||||
|
<input type="hidden" id="@dataPartName-@dataFieldName-tryTranslateMsg" value="@tryTranslateMsg" />
|
||||||
@using (Script.Foot()) {
|
@using (Script.Foot()) {
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(function () {
|
$(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) {
|
@foreach (var contentItem in Model.ContentItems) {
|
||||||
var loc = contentItem.As<LocalizationPart>();
|
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.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.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.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 }) {
|
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 });
|
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));
|
var op = (DateTimeOperator)Enum.Parse(typeof(DateTimeOperator), Convert.ToString(formState.Operator));
|
||||||
|
|
||||||
string type = Convert.ToString(formState.ValueType);
|
if (op == DateTimeOperator.IsNull)
|
||||||
|
return y => y.IsNull(property);
|
||||||
DateTime min, max;
|
else
|
||||||
|
if (op == DateTimeOperator.IsNotNull)
|
||||||
// Are those dates or time spans
|
return y => y.IsNotNull(property);
|
||||||
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 {
|
else {
|
||||||
if (op == DateTimeOperator.Between || op == DateTimeOperator.NotBetween) {
|
string type = Convert.ToString(formState.ValueType);
|
||||||
min = ApplyDelta(now, formState.MinUnit.Value, Int32.Parse(formState.Min.Value));
|
|
||||||
max = ApplyDelta(now, formState.MaxUnit.Value, Int32.Parse(formState.Max.Value));
|
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 {
|
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();
|
if (min.HasValue)
|
||||||
max = max.ToUniversalTime();
|
min = min.Value.ToUniversalTime();
|
||||||
|
|
||||||
object minValue = min;
|
if (max.HasValue)
|
||||||
object maxValue = max;
|
max = max.Value.ToUniversalTime();
|
||||||
|
|
||||||
if(asTicks) {
|
object minValue;
|
||||||
minValue = min.Ticks;
|
|
||||||
maxValue = max.Ticks;
|
if (min.HasValue)
|
||||||
}
|
minValue = min.Value;
|
||||||
|
else
|
||||||
|
minValue = "";
|
||||||
|
|
||||||
switch (op) {
|
object maxValue;
|
||||||
case DateTimeOperator.LessThan:
|
|
||||||
return x => x.Lt(property, maxValue);
|
if (max.HasValue)
|
||||||
case DateTimeOperator.LessThanEquals:
|
maxValue = max.Value;
|
||||||
return x => x.Le(property, maxValue);
|
else
|
||||||
case DateTimeOperator.Equals:
|
maxValue = "";
|
||||||
if (min == max) {
|
|
||||||
return x => x.Eq(property, minValue);
|
if(asTicks) {
|
||||||
}
|
if (min.HasValue)
|
||||||
return y => y.And(x => x.Ge(property, minValue), x => x.Le(property, maxValue));
|
minValue = min.Value.Ticks;
|
||||||
case DateTimeOperator.NotEquals:
|
else
|
||||||
if (min == max) {
|
minValue = 0;
|
||||||
return x => x.Not(y => y.Eq(property, minValue));
|
|
||||||
}
|
if (max.HasValue)
|
||||||
return y => y.Or(x => x.Lt(property, minValue), x => x.Gt(property, maxValue));
|
maxValue = max.Value.Ticks;
|
||||||
case DateTimeOperator.GreaterThan:
|
else
|
||||||
return x => x.Gt(property, minValue);
|
maxValue = 0;
|
||||||
case DateTimeOperator.GreaterThanEquals:
|
}
|
||||||
return x => x.Ge(property, minValue);
|
|
||||||
case DateTimeOperator.Between:
|
switch (op) {
|
||||||
return y => y.And(x => x.Ge(property, minValue), x => x.Le(property, maxValue));
|
case DateTimeOperator.LessThan:
|
||||||
case DateTimeOperator.NotBetween:
|
return x => x.Lt(property, maxValue);
|
||||||
return y => y.Or(x => x.Lt(property, minValue), x => x.Gt(property, maxValue));
|
case DateTimeOperator.LessThanEquals:
|
||||||
default:
|
return x => x.Le(property, maxValue);
|
||||||
throw new ArgumentOutOfRangeException();
|
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
|
/// Returns the low bound value of a date pattern. e.g., 2011-10 will return 2011-10-01 00:00:00
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>DateTime is stored in UTC but entered in local</remarks>
|
/// <remarks>DateTime is stored in UTC but entered in local</remarks>
|
||||||
protected static DateTime GetLowBoundPattern(string datePattern) {
|
protected static DateTime? GetLowBoundPattern(string datePattern) {
|
||||||
var match = _dateRegEx.Match(datePattern);
|
if (string.IsNullOrEmpty(datePattern)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var match = _dateRegEx.Match(datePattern);
|
||||||
|
|
||||||
return DateTime.Parse(
|
return DateTime.Parse(
|
||||||
String.Format("{0}-{1}-{2} {3}:{4}:{5}",
|
String.Format("{0}-{1}-{2} {3}:{4}:{5}",
|
||||||
match.Groups["year"].Success ? match.Groups["year"].Value : "1980",
|
match.Groups["year"].Success ? match.Groups["year"].Value : "1980",
|
||||||
match.Groups["month"].Success ? match.Groups["month"].Value : "01",
|
match.Groups["month"].Success ? match.Groups["month"].Value : "01",
|
||||||
match.Groups["day"].Success ? match.Groups["day"].Value : "01",
|
match.Groups["day"].Success ? match.Groups["day"].Value : "01",
|
||||||
match.Groups["hour"].Success ? match.Groups["hour"].Value : "00",
|
match.Groups["hour"].Success ? match.Groups["hour"].Value : "00",
|
||||||
match.Groups["minute"].Success ? match.Groups["minute"].Value : "00",
|
match.Groups["minute"].Success ? match.Groups["minute"].Value : "00",
|
||||||
match.Groups["second"].Success ? match.Groups["second"].Value : "00"),
|
match.Groups["second"].Success ? match.Groups["second"].Value : "00"),
|
||||||
CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal);
|
CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static DateTime ApplyDelta(DateTime now, string unit, int value) {
|
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) {
|
public static LocalizedString DisplayFilter(string fieldName, dynamic formState, Localizer T) {
|
||||||
var op = (DateTimeOperator)Enum.Parse(typeof(DateTimeOperator), Convert.ToString(formState.Operator));
|
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") {
|
if (op == DateTimeOperator.IsNull)
|
||||||
valueUnit = minUnit = maxUnit = String.Empty;
|
return T("{0} is null", fieldName);
|
||||||
}
|
else
|
||||||
|
if (op == DateTimeOperator.IsNotNull)
|
||||||
|
return T("{0} is not null", fieldName);
|
||||||
else {
|
else {
|
||||||
valueUnit = " " + valueUnit;
|
string type = Convert.ToString(formState.ValueType);
|
||||||
minUnit = " " + minUnit;
|
string value = Convert.ToString(formState.Value);
|
||||||
maxUnit = " " + maxUnit;
|
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) {
|
if (type == "0") {
|
||||||
case DateTimeOperator.LessThan:
|
valueUnit = minUnit = maxUnit = String.Empty;
|
||||||
return T("{0} is less than {1}{2}", fieldName, value, T(valueUnit));
|
}
|
||||||
case DateTimeOperator.LessThanEquals:
|
else {
|
||||||
return T("{0} is less than or equal to {1}{2}", fieldName, value, T(valueUnit));
|
valueUnit = " " + valueUnit;
|
||||||
case DateTimeOperator.Equals:
|
minUnit = " " + minUnit;
|
||||||
return T("{0} equals {1}{2}", fieldName, value, T(valueUnit));
|
maxUnit = " " + maxUnit;
|
||||||
case DateTimeOperator.NotEquals:
|
}
|
||||||
return T("{0} is not equal to {1}{2}", fieldName, value, T(valueUnit));
|
|
||||||
case DateTimeOperator.GreaterThan:
|
switch (op) {
|
||||||
return T("{0} is greater than {1}{2}", fieldName, value, T(valueUnit));
|
case DateTimeOperator.LessThan:
|
||||||
case DateTimeOperator.GreaterThanEquals:
|
return T("{0} is less than {1}{2}", fieldName, value, T(valueUnit));
|
||||||
return T("{0} is greater than or equal to {1}{2}", fieldName, value, T(valueUnit));
|
case DateTimeOperator.LessThanEquals:
|
||||||
case DateTimeOperator.Between:
|
return T("{0} is less than or equal to {1}{2}", fieldName, value, T(valueUnit));
|
||||||
return T("{0} is between {1}{2} and {3}{4}", fieldName, min, T(minUnit), max, T(maxUnit));
|
case DateTimeOperator.Equals:
|
||||||
case DateTimeOperator.NotBetween:
|
return T("{0} equals {1}{2}", fieldName, value, T(valueUnit));
|
||||||
return T("{0} is not between {1}{2} and {3}{4}", fieldName, min, T(minUnit), max, T(maxUnit));
|
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
|
// 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
|
/// Returns the low bound value of a date pattern. e.g., 2011-10 will return 2011-10-01 00:00:00
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>DateTime is stored in UTC but entered in local</remarks>
|
/// <remarks>DateTime is stored in UTC but entered in local</remarks>
|
||||||
protected static DateTime GetHighBoundPattern(string datePattern) {
|
protected static DateTime? GetHighBoundPattern(string datePattern) {
|
||||||
var match = _dateRegEx.Match(datePattern);
|
if (string.IsNullOrEmpty(datePattern)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var match = _dateRegEx.Match(datePattern);
|
||||||
|
|
||||||
string year, month;
|
string year, month;
|
||||||
return DateTime.Parse(
|
return DateTime.Parse(
|
||||||
String.Format("{0}-{1}-{2} {3}:{4}:{5}",
|
String.Format("{0}-{1}-{2} {3}:{4}:{5}",
|
||||||
year = match.Groups["year"].Success ? match.Groups["year"].Value : "2099",
|
year = match.Groups["year"].Success ? match.Groups["year"].Value : "2099",
|
||||||
month = match.Groups["month"].Success ? match.Groups["month"].Value : "12",
|
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["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["hour"].Success ? match.Groups["hour"].Value : "23",
|
||||||
match.Groups["minute"].Success ? match.Groups["minute"].Value : "59",
|
match.Groups["minute"].Success ? match.Groups["minute"].Value : "59",
|
||||||
match.Groups["second"].Success ? match.Groups["second"].Value : "59"),
|
match.Groups["second"].Success ? match.Groups["second"].Value : "59"),
|
||||||
CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal);
|
CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -299,7 +347,9 @@ namespace Orchard.Projections.FilterEditors.Forms {
|
|||||||
GreaterThan,
|
GreaterThan,
|
||||||
GreaterThanEquals,
|
GreaterThanEquals,
|
||||||
Between,
|
Between,
|
||||||
NotBetween
|
NotBetween,
|
||||||
|
IsNull,
|
||||||
|
IsNotNull
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum DateTimeSpan {
|
public enum DateTimeSpan {
|
||||||
|
|||||||
@@ -13,70 +13,77 @@ namespace Orchard.Projections.FilterEditors.Forms {
|
|||||||
public override void Validating(ValidatingContext context) {
|
public override void Validating(ValidatingContext context) {
|
||||||
if (context.FormName == DateTimeFilterForm.FormName) {
|
if (context.FormName == DateTimeFilterForm.FormName) {
|
||||||
|
|
||||||
var isRange = new[] {"Between", "NotBetween"}.Contains(context.ValueProvider.GetValue("Operator").AttemptedValue);
|
var op = (DateTimeOperator)Enum.Parse(typeof(DateTimeOperator), Convert.ToString(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");
|
|
||||||
|
|
||||||
// validating mandatory values
|
if (op == DateTimeOperator.IsNull || op == DateTimeOperator.IsNotNull) {
|
||||||
if (isRange) {
|
// no further validation needed
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (min == null || String.IsNullOrWhiteSpace(value.AttemptedValue)) {
|
var isRange = new[] {DateTimeOperator.Between, DateTimeOperator.NotBetween}.Contains(op);
|
||||||
context.ModelState.AddModelError("Value", T("The field {0} is required.", T("Value").Text).Text);
|
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) {
|
// validating mandatory values
|
||||||
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 (isRange) {
|
||||||
if (!Int32.TryParse(min.AttemptedValue, out number) && !IsToken(min.AttemptedValue)) {
|
if (min == null || String.IsNullOrWhiteSpace(min.AttemptedValue)) {
|
||||||
context.ModelState.AddModelError("Min", T("The field {0} must be a valid number.", T("Min").Text).Text);
|
context.ModelState.AddModelError("Min", T("The field {0} is required.", T("Min").Text).Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Int32.TryParse(max.AttemptedValue, out number) && !IsToken(max.AttemptedValue)) {
|
if (max == null || String.IsNullOrWhiteSpace(max.AttemptedValue)) {
|
||||||
context.ModelState.AddModelError("Max", T("The field {0} must be a valid number.", T("Max").Text).Text);
|
context.ModelState.AddModelError("Max", T("The field {0} is required.", T("Max").Text).Text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!Int32.TryParse(value.AttemptedValue, out number) && !IsToken(value.AttemptedValue)) {
|
if (min == null || String.IsNullOrWhiteSpace(value.AttemptedValue)) {
|
||||||
context.ModelState.AddModelError("Value", T("The field {0} must be a valid number.", T("Value").Text).Text);
|
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
|
// show/hide Min/Max fields
|
||||||
$("#operator option:selected").each(function () {
|
$("#operator option:selected").each(function () {
|
||||||
var val = $(this).val();
|
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-single').hide();
|
||||||
$('#fieldset-min').show();
|
|
||||||
$('#fieldset-max').show();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$('#fieldset-single').show();
|
|
||||||
$('#fieldset-min').hide();
|
$('#fieldset-min').hide();
|
||||||
$('#fieldset-max').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
|
// show/hide unit selectors
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ namespace Orchard.Tokens.Providers {
|
|||||||
|
|
||||||
FeedItem<ContentItem> item = feedItem;
|
FeedItem<ContentItem> item = feedItem;
|
||||||
context.Response.Contextualize(requestContext => {
|
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 });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -201,4 +201,4 @@ namespace Orchard.Tokens.Providers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user