Esempio n. 1
0
        public DateEditor AddDateRangeFilter(string field, string title = null)
        {
            DateEditor end = null;

            return(AddEqualityFilter <DateEditor>(field,
                                                  element: e1 =>
            {
                end = Widget.Create <DateEditor>(element: e2 => e2.InsertAfter(e1));
                end.Element.Change(x => e1.TriggerHandler("change"));
                J("<span/>").AddClass("range-separator").Text("-").InsertAfter(e1);
            },
                                                  handler: args =>
            {
                args.Active =
                    !string.IsNullOrEmpty(args.Widget.Value) ||
                    !string.IsNullOrEmpty(end.Value);

                if (!string.IsNullOrEmpty(args.Widget.Value))
                {
                    args.Request.Criteria &= new Criteria(args.Field) >= args.Widget.Value;
                }

                if (!string.IsNullOrEmpty(end.Value))
                {
                    args.Request.Criteria &= new Criteria(args.Field) <= end.Value;
                }
            }));
        }
Esempio n. 2
0
        public DateTimeEditor(jQueryObject input, DateTimeEditorOptions opt)
            : base(input, opt)
        {
            input.AddClass("dateQ s-DateTimeEditor")
            .DatePicker(new DatePickerOptions
            {
                ShowOn     = "button",
                BeforeShow = new Func <bool>(delegate
                {
                    return(!input.HasClass("readonly"));
                }),
                YearRange = options.YearRange ?? "-100:+50"
            });

            input.Bind("keyup." + this.uniqueName, e => {
                if (e.Which == 32 && !ReadOnly)
                {
                    if (this.ValueAsDate != JsDate.Now)
                    {
                        this.ValueAsDate = JsDate.Now;
                        this.element.Trigger("change");
                    }
                }
                else
                {
                    DateEditor.DateInputKeyup(e);
                }
            });
            input.Bind("change." + this.uniqueName, DateEditor.DateInputChange);

            time = J("<select/>").AddClass("editor s-DateTimeEditor time");
            var after = input.Next(".ui-datepicker-trigger");

            if (after.Length > 0)
            {
                time.InsertAfter(after);
            }
            else
            {
                after = input.Prev(".ui-datepicker-trigger");
                if (after.Length > 0)
                {
                    time.InsertBefore(after);
                }
                else
                {
                    time.InsertAfter(input);
                }
            }

            foreach (var t in GetTimeOptions(fromHour: options.StartHour ?? 0,
                                             toHour: options.EndHour ?? 23,
                                             stepMins: options.IntervalMinutes ?? 5))
            {
                Q.AddOption(time, t, t);
            }

            input.AddValidationRule(this.uniqueName, e =>
            {
                var value = this.Value;
                if (string.IsNullOrEmpty(value))
                {
                    return(null);
                }

                if (!string.IsNullOrEmpty(MinValue) &&
                    String.Compare(value, MinValue) < 0)
                {
                    return(String.Format(Q.Text("Validation.MinDate"),
                                         Q.FormatDate(MinValue)));
                }

                if (!string.IsNullOrEmpty(MaxValue) &&
                    String.Compare(value, MaxValue) >= 0)
                {
                    return(String.Format(Q.Text("Validation.MaxDate"),
                                         Q.FormatDate(MaxValue)));
                }

                return(null);
            });

            SqlMinMax = true;

            J("<div class='inplace-button inplace-now'><b></b></div>")
            .Attribute("title", "set to now")
            .InsertAfter(time)
            .Click(e =>
            {
                if (this.Element.HasClass("readonly"))
                {
                    return;
                }

                this.ValueAsDate = JsDate.Now;
            });

            time.On("change", e => input.TriggerHandler("change"));
        }