private static void SetUpDatePicker(TimeSheetViewModel vm) { jQueryObject element = jQuery.Select("#datepicker"); string dateFormat = "dd/MM/yy"; if (OrganizationServiceProxy.UserSettings != null) { dateFormat = OrganizationServiceProxy.UserSettings.DateFormatString; } DatePickerOptions2 options2 = new DatePickerOptions2(); options2.NumberOfMonths = 3; options2.FirstDay = OrganizationServiceProxy.OrganizationSettings.WeekStartDayCode.Value.Value; options2.DateFormat = dateFormat.Replace("MM", "mm").Replace("yyyy", "yy").Replace("M", "m"); // Wire up onSelect event options2.OnSelect = delegate(string dateText, object instance) { // Commit any of the current edits EditController controller = sessionsGrid.GetEditController(); bool editCommited = controller.commitCurrentEdit(); if (editCommited) { DateTime date = (DateTime)element.Plugin <DatePickerObject>().DatePicker(DatePickerMethod.GetDate); vm.Days.SetCurrentWeek(date); } }; element.Plugin <DatePickerPlugIn>().DatePicker(options2); }
public XrmDateEditor(EditorArguments args) : base(args) { XrmDateEditor self = this; _container = jQuery.FromHtml("<div ><table class='inline-edit-container' cellspacing='0' cellpadding='0'><tr>" + "<td><INPUT type=text class='sparkle-input-inline' /></td>" + "<td class='lookup-button-td'><input type=button class='sparkle-imagestrip-inlineedit_calendar_icon' /></td></tr></table></div>"); _container.AppendTo(_args.Container); _input = _container.Find(".sparkle-input-inline"); _input.Bind("keydown.nav", delegate(jQueryEvent e) { if (!_calendarOpen && (e.Which == 38 || e.Which == 40) && e.CtrlKey) // Ctrl-Up/Down shows date picker { _input.Plugin <DatePickerPlugIn>().DatePicker(DatePickerMethod2.Show); e.StopImmediatePropagation(); } else if (_calendarOpen && e.Which == 13) { e.PreventDefault(); } }); jQueryObject selectButton = _container.Find(".sparkle-imagestrip-inlineedit_calendar_icon"); _input.Focus().Select(); DatePickerOptions2 options2 = new DatePickerOptions2(); options2.ShowOtherMonths = true; options2.ShowOn = ""; // Date Pickers in CRM do not show when they are focused - you click the button options2.FirstDay = OrganizationServiceProxy.OrganizationSettings != null ? OrganizationServiceProxy.OrganizationSettings.WeekStartDayCode.Value.Value : 0; options2.BeforeShow = delegate() { this._calendarOpen = true; }; options2.OnClose = delegate() { this._calendarOpen = false; _selectedValue = GetSelectedValue(); }; options2.OnSelect = delegate(string dateString, object instance) { // Select the date text field when selecting a date Focus(); }; if (OrganizationServiceProxy.UserSettings != null) { _dateFormat = OrganizationServiceProxy.UserSettings.DateFormatString; } options2.DateFormat = _dateFormat; _input.Plugin <DatePickerPlugIn>().DatePicker(options2); // Wire up the date picker button selectButton.Click(delegate(jQueryEvent e){ _input.Plugin <DatePickerPlugIn>().DatePicker(DatePickerMethod2.Show); Focus(); }); }
public XrmDateEditor(EditorArguments args) : base(args) { XrmDateEditor self = this; _container = jQuery.FromHtml("<div ><table class='inline-edit-container' cellspacing='0' cellpadding='0'><tr>" + "<td><INPUT type=text class='sparkle-input-inline' /></td>" + "<td class='lookup-button-td'><input type=button class='sparkle-imagestrip-inlineedit_calendar_icon' /></td></tr></table></div>"); _container.AppendTo(_args.Container); _input = _container.Find(".sparkle-input-inline"); _input.Bind("keydown.nav", delegate(jQueryEvent e) { if (!_calendarOpen && (e.Which == 38 || e.Which == 40) && e.CtrlKey) // Ctrl-Up/Down shows date picker { _input.Plugin<DatePickerPlugIn>().DatePicker(DatePickerMethod2.Show); e.StopImmediatePropagation(); } else if (_calendarOpen && e.Which == 13) { e.PreventDefault(); } }); jQueryObject selectButton = _container.Find(".sparkle-imagestrip-inlineedit_calendar_icon"); _input.Focus().Select(); DatePickerOptions2 options2 = new DatePickerOptions2(); options2.ShowOtherMonths = true; options2.ShowOn = ""; // Date Pickers in CRM do not show when they are focused - you click the button options2.FirstDay = OrganizationServiceProxy.OrganizationSettings != null ? OrganizationServiceProxy.OrganizationSettings.WeekStartDayCode.Value.Value : 0; options2.BeforeShow = delegate() { this._calendarOpen = true; }; options2.OnClose = delegate() { this._calendarOpen = false; _selectedValue = GetSelectedValue(); }; options2.OnSelect = delegate(string dateString, object instance) { // Select the date text field when selecting a date Focus(); }; if (OrganizationServiceProxy.UserSettings != null) { _dateFormat = OrganizationServiceProxy.UserSettings.DateFormatString; } options2.DateFormat = _dateFormat; _input.Plugin<DatePickerPlugIn>().DatePicker(options2); // Wire up the date picker button selectButton.Click(delegate(jQueryEvent e){ _input.Plugin<DatePickerPlugIn>().DatePicker(DatePickerMethod2.Show); Focus(); }); }
public XrmDateEditor(EditorArguments args) : base(args) { _container = jQuery.FromHtml("<div ><table class='inline-edit-container' cellspacing='0' cellpadding='0'><tr>" + "<td><INPUT type=text class='sparkle-input-inline' /></td>" + "<td class='lookup-button-td'><input type=button class='sparkle-imagestrip-inlineedit_calendar_icon' /></td></tr></table></div>"); _container.AppendTo(_args.Container); _input = _container.Find(".sparkle-input-inline"); jQueryObject selectButton = _container.Find(".sparkle-imagestrip-inlineedit_calendar_icon"); _input.Focus().Select(); DatePickerOptions2 options2 = new DatePickerOptions2(); options2.ShowOtherMonths = true; options2.FirstDay = OrganizationServiceProxy.OrganizationSettings != null ? OrganizationServiceProxy.OrganizationSettings.WeekStartDayCode.Value.Value : 0; options2.BeforeShow = delegate() { this._calendarOpen = true; }; options2.OnClose = delegate() { this._calendarOpen = false; _selectedValue = GetSelectedValue(); }; if (OrganizationServiceProxy.UserSettings != null) { _dateFormat = OrganizationServiceProxy.UserSettings.DateFormatString; } options2.DateFormat = _dateFormat; _input.Plugin<DatePickerPlugIn>().DatePicker(options2); // Wire up the date picker button selectButton.Click(delegate(jQueryEvent e){ _input.Plugin<DatePickerPlugIn>().DatePicker(DatePickerMethod2.Show); }); //_input.Width(_input.GetWidth() - 24); }
public XrmDateEditor(EditorArguments args) : base(args) { _container = jQuery.FromHtml("<div ><table class='inline-edit-container' cellspacing='0' cellpadding='0'><tr>" + "<td><INPUT type=text class='sparkle-input-inline' /></td>" + "<td class='lookup-button-td'><input type=button class='sparkle-imagestrip-inlineedit_calendar_icon' /></td></tr></table></div>"); _container.AppendTo(_args.Container); _input = _container.Find(".sparkle-input-inline"); jQueryObject selectButton = _container.Find(".sparkle-imagestrip-inlineedit_calendar_icon"); _input.Focus().Select(); DatePickerOptions options = new DatePickerOptions(); DatePickerOptions2 options2 = (DatePickerOptions2)(object)options; options2.BeforeShow = delegate() { this._calendarOpen = true; }; options2.OnClose = delegate() { this._calendarOpen = false; _selectedValue = GetSelectedValue(); }; if (OrganizationServiceProxy.UserSettings != null) { _dateFormat = OrganizationServiceProxy.UserSettings.DateFormatString; } options.DateFormat = _dateFormat; _input.Plugin <DatePickerObject>().DatePicker(options); // Wire up the date picker button selectButton.Click(delegate(jQueryEvent e){ _input.Plugin <DatePickerPlugIn>().DatePicker(DatePickerMethod2.Show); }); //_input.Width(_input.GetWidth() - 24); }
public override void Init(System.Html.Element element, Func<object> valueAccessor, Func<System.Collections.Dictionary> allBindingsAccessor, object viewModel, object context) { jQueryObject container = jQuery.FromElement(element); jQueryObject dateTime = container.Find(".sparkle-input-datepicker-part"); jQueryObject dateButton = container.Find(".sparkle-input-datepicker-button-part"); // Add Date Picker DatePickerOptions2 options = new DatePickerOptions2(); options.ShowOn = ""; options.ButtonImageOnly = true; options.FirstDay = OrganizationServiceProxy.OrganizationSettings!=null ? OrganizationServiceProxy.OrganizationSettings.WeekStartDayCode.Value.Value : 0; //options.ButtonImage = @"../images/btn_off_Cal.gif"; string dateFormat = "dd/MM/yy"; if (OrganizationServiceProxy.UserSettings != null) { dateFormat = OrganizationServiceProxy.UserSettings.DateFormatString; } options.DateFormat = dateFormat; dateTime.Plugin<DatePickerPlugIn>().DatePicker(options); //// Get current value //Observable<DateTime> dateValueAccessor = (Observable<DateTime>)valueAccessor(); //DateTime intialValue = dateValueAccessor.GetValue(); //dateTime.Plugin<DatePickerObject>().DatePicker(DatePickerMethod.SetDate, intialValue); dateButton.Click(delegate(jQueryEvent e) { // Note: This is using a custom plugin definition since the standard didn't include show dateTime.Plugin<DatePickerPlugIn>().DatePicker(DatePickerMethod2.Show); }); //handle the field changing KnockoutUtils.RegisterEventHandler(dateTime.GetElement(0), "change", delegate(object sender, EventArgs e) { Observable<DateTime> observable = (Observable<DateTime>)valueAccessor(); bool isValid = true; if (((string)Script.Literal("typeof({0}.IsValid)",observable))!="undefined") { isValid = ((IValidatedObservable)observable).IsValid() == true; } if (isValid) { DateTime selectedDate = (DateTime)dateTime.Plugin<DatePickerObject>().DatePicker(DatePickerMethod.GetDate); // Get Current observable value - we only want to set the date part DateTime currentValue = observable.GetValue(); DateTimeEx.SetTime(selectedDate, currentValue); observable.SetValue(selectedDate); } dateTime.Blur(); }); Action disposeCallBack = delegate() { Script.Literal("$({0}).datepicker(\"destroy\")",element); }; //handle disposal (if KO removes by the template binding) Script.Literal("ko.utils.domNodeDisposal.addDisposeCallback({0}, {1})", element, (object)disposeCallBack); //Knockout.BindingHandlers["validationCore"].Init(element, valueAccessor, allBindingsAccessor,null,null); }
public override void Init(System.Html.Element element, Func <object> valueAccessor, Func <System.Collections.Dictionary> allBindingsAccessor, object viewModel, object context) { jQueryObject container = jQuery.FromElement(element); jQueryObject dateTime = container.Find(".sparkle-input-datepicker-part"); jQueryObject dateButton = container.Find(".sparkle-input-datepicker-button-part"); // Add Date Picker DatePickerOptions2 options = new DatePickerOptions2(); options.ShowOn = ""; options.ButtonImageOnly = true; options.FirstDay = OrganizationServiceProxy.OrganizationSettings != null ? OrganizationServiceProxy.OrganizationSettings.WeekStartDayCode.Value.Value : 0; //options.ButtonImage = @"../images/btn_off_Cal.gif"; string dateFormat = "dd/MM/yy"; if (OrganizationServiceProxy.UserSettings != null) { dateFormat = OrganizationServiceProxy.UserSettings.DateFormatString; } options.DateFormat = dateFormat; dateTime.Plugin <DatePickerPlugIn>().DatePicker(options); //// Get current value //Observable<DateTime> dateValueAccessor = (Observable<DateTime>)valueAccessor(); //DateTime intialValue = dateValueAccessor.GetValue(); //dateTime.Plugin<DatePickerObject>().DatePicker(DatePickerMethod.SetDate, intialValue); dateButton.Click(delegate(jQueryEvent e) { // Note: This is using a custom plugin definition since the standard didn't include show dateTime.Plugin <DatePickerPlugIn>().DatePicker(DatePickerMethod2.Show); }); //handle the field changing KnockoutUtils.RegisterEventHandler(dateTime.GetElement(0), "change", delegate(object sender, EventArgs e) { Observable <DateTime> observable = (Observable <DateTime>)valueAccessor(); bool isValid = true; if (((string)Script.Literal("typeof({0}.IsValid)", observable)) != "undefined") { isValid = ((IValidatedObservable)observable).IsValid() == true; } if (isValid) { DateTime selectedDate = (DateTime)dateTime.Plugin <DatePickerObject>().DatePicker(DatePickerMethod.GetDate); // Get Current observable value - we only want to set the date part DateTime currentValue = observable.GetValue(); DateTimeEx.SetTime(selectedDate, currentValue); observable.SetValue(selectedDate); } dateTime.Blur(); }); Action disposeCallBack = delegate() { Script.Literal("$({0}).datepicker(\"destroy\")", element); }; //handle disposal (if KO removes by the template binding) Script.Literal("ko.utils.domNodeDisposal.addDisposeCallback({0}, {1})", element, (object)disposeCallBack); //Knockout.BindingHandlers["validationCore"].Init(element, valueAccessor, allBindingsAccessor,null,null); }