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 XrmDurationEditor(EditorArguments args) : base(args) { _args = args; _input = jQuery.FromHtml("<INPUT type=text class='editor-text' />"); _input.AppendTo(_args.Container); Focus(); }
public XrmBooleanEditor(EditorArguments args) : base(args) { input = jQuery.FromHtml("<input type='checkbox' class='editor-boolean'/>") .AppendTo(args.Container) .Bind("keydown.nav", delegate(jQueryEvent e) { if (e.Which == 37 || e.Which == 39) //LEFT or RIGHT key e.StopImmediatePropagation(); }) .Focus() .Select(); }
public XrmTextEditor(EditorArguments args) : base(args) { input = jQuery.FromHtml("<INPUT type=text class='editor-text' />") .AppendTo(args.Container) .Bind("keydown.nav",delegate(jQueryEvent e){ if (e.Which == 37 || e.Which == 39 ) //LEFT or RIGHT{ e.StopImmediatePropagation(); }) .Focus() .Select(); }
public XrmOptionSetEditor(EditorArguments args) : base(args) { // Get the option set values XrmOptionSetEditor self = this; OptionSetBindingOptions opts = (OptionSetBindingOptions)args.Column.Options; if (_options == null) { _options = MetadataCache.GetOptionSetValues(opts.entityLogicalName, opts.attributeLogicalName, opts.allowEmpty); } CreateSelect(self); }
public XrmMoneyEditor(EditorArguments args) : base(args) { numberFormatInfo = (NumberFormatInfo)args.Column.Options; currencySymbol = jQuery.FromHtml("<SPAN/>").AppendTo(args.Container); input = jQuery.FromHtml("<INPUT type=text class='editor-text' />") .AppendTo(args.Container) .Bind("keydown.nav",delegate(jQueryEvent e){ if (e.Which == 37 || e.Which == 39 ) //LEFT or RIGHT{ e.StopImmediatePropagation(); }) .Focus() .Select(); }
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 XrmTimeEditor(EditorArguments args) : base(args) { if (OrganizationServiceProxy.UserSettings != null) { _formatString = OrganizationServiceProxy.UserSettings.TimeFormatString; } _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='autocompleteButton' /></td></tr></table></div>"); _container.AppendTo(_args.Container); jQueryObject inputField = _container.Find(".sparkle-input-inline"); _input = inputField; _input.Focus().Select(); string timeFormatString = _formatString; AutoCompleteOptions options = GetTimePickerAutoCompleteOptions(timeFormatString); options.Select = delegate(jQueryEvent e, AutoCompleteSelectEvent uiEvent) { // Note we assume that the binding has added an array of string items //string value = ((Dictionary)uiEvent.Item)["value"].ToString(); }; inputField = inputField.Plugin<AutoCompleteObject>().AutoComplete(options); jQueryObject selectButton = _container.Find(".autocompleteButton"); // Add the click binding to show the drop down selectButton.Click(delegate(jQueryEvent e) { inputField.Plugin<AutoCompleteObject>().AutoComplete(AutoCompleteMethod.Search, ""); }); }
public XrmLookupEditor(EditorArguments args) : base(args) { _args = 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-lookup-button' /></td></tr></table></div>"); _container.AppendTo(_args.Container); jQueryObject inputField = _container.Find(".sparkle-input-inline"); jQueryObject selectButton = _container.Find(".sparkle-lookup-button"); _input = inputField; _input.Focus().Select(); _autoComplete = inputField.Plugin<AutoCompleteObject>(); AutoCompleteOptions options = new AutoCompleteOptions(); options.MinLength = 100000; options.Delay = 0; // TODO- set to something that makes sense bool justSelected = false; options.Select = delegate(jQueryEvent e, AutoCompleteSelectEvent uiEvent) { if (_value == null) _value = new EntityReference(null,null,null); // Note we assume that the binding has added an array of string items AutoCompleteItem item = (AutoCompleteItem)uiEvent.Item; string value = item.Label; _input.Value(value); _value.Id = ((EntityReference)item.Value).Id; _value.Name = ((EntityReference)item.Value).Name; _value.LogicalName = ((EntityReference)item.Value).LogicalName; justSelected = true; Script.Literal("return false;"); }; // options.Focus = delegate(jQueryEvent e, AutoCompleteFocusEvent uiEvent) { // Prevent the value being updated in the text box we scroll through the results Script.Literal("return false;"); }; XrmLookupEditorOptions editorOptions = (XrmLookupEditorOptions)args.Column.Options; // wire up source to CRM search Action<AutoCompleteRequest, Action<AutoCompleteItem[]>> queryDelegate = delegate(AutoCompleteRequest request, Action<AutoCompleteItem[]> response) { // Get the option set values editorOptions.queryCommand(request.Term, delegate(EntityCollection fetchResult) { AutoCompleteItem[] results = new AutoCompleteItem[fetchResult.Entities.Count]; for (int i = 0; i < fetchResult.Entities.Count; i++) { results[i] = new AutoCompleteItem(); results[i].Label = (string)fetchResult.Entities[i].GetAttributeValue(editorOptions.nameAttribute); EntityReference id = new EntityReference(null, null, null); id.Name = results[i].Label; id.LogicalName = fetchResult.Entities[i].LogicalName; id.Id = (Guid)fetchResult.Entities[i].GetAttributeValue(editorOptions.idAttribute); results[i].Value = id; string typeCodeName = fetchResult.Entities[i].LogicalName; // Get the type code from the name to find the icon if (!string.IsNullOrEmpty(editorOptions.typeCodeAttribute)) { typeCodeName = fetchResult.Entities[i].GetAttributeValue(editorOptions.typeCodeAttribute).ToString(); } results[i].Image = MetadataCache.GetSmallIconUrl(typeCodeName); } response(results); // Disable it now so typing doesn't trigger a search AutoCompleteOptions disableOption = new AutoCompleteOptions(); disableOption.MinLength = 100000; _autoComplete.AutoComplete(disableOption); }); }; options.Source = queryDelegate; inputField = _autoComplete.AutoComplete(options); ((RenderItemDelegate)Script.Literal("{0}.data('ui-autocomplete')", inputField))._renderItem = delegate(object ul, AutoCompleteItem item) { return (object)jQuery.Select("<li>").Append( "<a class='sparkle-menu-item'><span class='sparkle-menu-item-img'><img src='" + item.Image + "'/></span><span class='sparkle-menu-item-label'>" + item.Label + "</span></a>").AppendTo((jQueryObject)ul); }; // Add the click binding to show the drop down selectButton.Click(delegate(jQueryEvent e) { AutoCompleteOptions enableOption = new AutoCompleteOptions(); enableOption.MinLength = 0; _autoComplete.AutoComplete(enableOption); _autoComplete.AutoComplete(AutoCompleteMethod.Search, inputField.GetValue()); }); // Bind return to searching _input.Keydown(delegate(jQueryEvent e) { if (e.Which == 13 && !justSelected) // Return pressed - but we want to do a search not move to the next cell { if (inputField.GetValue().Length > 0) selectButton.Click(); else { // Set value to null _value = null; return; } } else if (e.Which == 13) { return; } switch (e.Which) { case 13: // Return case 38: // Up - don't navigate - but use the dropdown to select search results case 40: // Down - don't navigate - but use the dropdown to select search results e.PreventDefault(); e.StopPropagation(); break; } justSelected = false; }); }
public XrmTimeEditor(EditorArguments args) : base(args) { bool justSelected = false; XrmTimeEditor self = this; if (OrganizationServiceProxy.UserSettings != null) { _formatString = OrganizationServiceProxy.UserSettings.TimeFormatString; } _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='autocompleteButton' /></td></tr></table></div>"); _container.AppendTo(_args.Container); jQueryObject inputField = _container.Find(".sparkle-input-inline"); _input = inputField; _input.Focus().Select(); string timeFormatString = _formatString; AutoCompleteOptions options = GetTimePickerAutoCompleteOptions(timeFormatString); options.Select = delegate(jQueryEvent e, AutoCompleteSelectEvent uiEvent) { justSelected = true; }; options.Open = delegate(jQueryEvent e, jQueryObject o) { self._searchOpen = true; }; options.Close = delegate(jQueryEvent e, jQueryObject o) { self._searchOpen = false; }; inputField = inputField.Plugin<AutoCompleteObject>().AutoComplete(options); jQueryObject selectButton = _container.Find(".autocompleteButton"); // Add the click binding to show the drop down selectButton.Click(delegate(jQueryEvent e) { inputField.Plugin<AutoCompleteObject>().AutoComplete(AutoCompleteMethod.Search, ""); }); // Bind return to searching _input.Keydown(delegate(jQueryEvent e) { if (self._searchOpen) { switch (e.Which) { case 13: // Return case 38: // Up - don't navigate - but use the dropdown to select search results case 40: // Down - don't navigate - but use the dropdown to select search results e.PreventDefault(); e.StopPropagation(); break; } } justSelected = false; }); }
public GridEditorBase(EditorArguments args) { _args = args; }
public XrmLookupEditor(EditorArguments args) : base(args) { XrmLookupEditor self = this; _args = 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-lookup-button' /></td></tr></table></div>"); _container.AppendTo(_args.Container); jQueryObject inputField = _container.Find(".sparkle-input-inline"); jQueryObject selectButton = _container.Find(".sparkle-lookup-button"); _input = inputField; _input.Focus().Select(); _autoComplete = inputField.Plugin<AutoCompleteObject>(); AutoCompleteOptions options = new AutoCompleteOptions(); options.Position = new Dictionary<string, object>("collision", "fit"); options.MinLength = 100000; options.Delay = 0; // TODO- set to something that makes sense XrmLookupEditorOptions editorOptions = (XrmLookupEditorOptions)args.Column.Options; bool justSelected = false; options.Select = delegate(jQueryEvent e, AutoCompleteSelectEvent uiEvent) { if (_value == null) _value = new EntityReference(null,null,null); // Note we assume that the binding has added an array of string items AutoCompleteItem item = (AutoCompleteItem)uiEvent.Item; EntityReference itemRef = (EntityReference)item.Value; if (itemRef.LogicalName == "footerlink") { XrmLookupEditorButton button = editorOptions.footerButton; button.OnClick(item); } else { string value = item.Label; _input.Value(value); _value.Id = itemRef.Id; _value.Name = itemRef.Name; _value.LogicalName = ((EntityReference)item.Value).LogicalName; justSelected = true; } Script.Literal("return false;"); }; options.Focus = delegate(jQueryEvent e, AutoCompleteFocusEvent uiEvent) { // Prevent the value being updated in the text box as we scroll through the results Script.Literal("return false;"); }; options.Open = delegate(jQueryEvent e, jQueryObject o) { self._searchOpen = true; if (editorOptions.showFooter && totalRecordsReturned>0) { WidgetObject menu = (WidgetObject)Script.Literal("{0}.autocomplete({1})", _input, "widget"); AddFooter(menu,totalRecordsReturned); } }; options.Close = delegate(jQueryEvent e, jQueryObject o) { self._searchOpen = false; WidgetObject menu = (WidgetObject)Script.Literal("{0}.autocomplete({1})", _input, "widget"); jQueryObject footer = menu.Next(); if (footer.Length > 0 || footer.HasClass("sparkle-menu-footer")) { footer.Hide(); } }; // If there multiple names, add them to the columnAttributes string[] columns = editorOptions.nameAttribute.Split(","); if (columns.Length > 1) { editorOptions.columns = columns; editorOptions.nameAttribute = columns[0]; } // wire up source to CRM search Action<AutoCompleteRequest, Action<AutoCompleteItem[]>> queryDelegate = delegate(AutoCompleteRequest request, Action<AutoCompleteItem[]> response) { // Get the option set values editorOptions.queryCommand(request.Term, delegate(EntityCollection fetchResult) { if (fetchResult.TotalRecordCount > fetchResult.Entities.Count) { totalRecordsReturned = fetchResult.TotalRecordCount; } else { totalRecordsReturned = fetchResult.Entities.Count; } int recordsFound = fetchResult.Entities.Count; bool noRecordsFound = recordsFound == 0; XrmLookupEditorButton button = editorOptions.footerButton; bool footerButton = (button != null); AutoCompleteItem[] results = new AutoCompleteItem[recordsFound + (footerButton ? 1 : 0) + (noRecordsFound ? 1 :0) ]; for (int i = 0; i < recordsFound; i++) { results[i] = new AutoCompleteItem(); results[i].Label = (string)fetchResult.Entities[i].GetAttributeValue(editorOptions.nameAttribute); EntityReference id = new EntityReference(null, null, null); id.Name = results[i].Label; id.LogicalName = fetchResult.Entities[i].LogicalName; id.Id = (Guid)fetchResult.Entities[i].GetAttributeValue(editorOptions.idAttribute); results[i].Value = id; XrmLookupBinding.GetExtraColumns(editorOptions.columns, fetchResult, results, i); string typeCodeName = fetchResult.Entities[i].LogicalName; // Get the type code from the name to find the icon if (!string.IsNullOrEmpty(editorOptions.typeCodeAttribute)) { typeCodeName = fetchResult.Entities[i].GetAttributeValue(editorOptions.typeCodeAttribute).ToString(); } if (editorOptions.showImage) { results[i].Image = MetadataCache.GetSmallIconUrl(typeCodeName); } } int itemsCount = recordsFound; if (noRecordsFound) { AutoCompleteItem noRecordsItem = new AutoCompleteItem(); noRecordsItem.Label = SparkleResourceStrings.NoRecordsFound; results[itemsCount] = noRecordsItem; itemsCount++; } if (footerButton) { // Add the add new AutoCompleteItem addNewLink = new AutoCompleteItem(); addNewLink.Label = button.Label; addNewLink.Image = button.Image; addNewLink.ColumnValues = null; addNewLink.Value = new Entity("footerlink"); results[itemsCount] = addNewLink; } response(results); // Disable it now so typing doesn't trigger a search AutoCompleteOptions disableOption = new AutoCompleteOptions(); disableOption.MinLength = 100000; _autoComplete.AutoComplete(disableOption); }); }; options.Source = queryDelegate; inputField = _autoComplete.AutoComplete(options); RenderItemDelegate autoCompleteDelegates = ((RenderItemDelegate)Script.Literal("{0}.data('ui-autocomplete')", inputField)); autoCompleteDelegates._renderItem = delegate(object ul, AutoCompleteItem item) { if(item.Value==item.Label) { return (object)jQuery.Select("<li class='ui-state-disabled'>"+item.Label+"</li>").AppendTo((jQueryObject)ul); } string itemHtml = "<a class='sparkle-menu-item'>"; // Allow for no image by passing false to 'ShowImage' on the XrmLookupEditorOptions options if (item.Image != null) { itemHtml += "<span class='sparkle-menu-item-img'><img src='" + item.Image + "'/></span>"; } itemHtml += "<span class='sparkle-menu-item-label'>" + item.Label + "</span><br/>"; if (item.ColumnValues != null && item.ColumnValues.Length > 0) { foreach (string value in item.ColumnValues) { itemHtml += "<span class='sparkle-menu-item-moreinfo'>" + value + "</span>"; } } itemHtml += "</a>"; return (object)jQuery.Select("<li>").Append(itemHtml).AppendTo((jQueryObject)ul); }; // Add the click binding to show the drop down selectButton.Click(delegate(jQueryEvent e) { AutoCompleteOptions enableOption = new AutoCompleteOptions(); enableOption.MinLength = 0; _autoComplete.AutoComplete(enableOption); _autoComplete.AutoComplete(AutoCompleteMethod.Search, inputField.GetValue()); }); // Bind return to searching _input.Keydown(delegate(jQueryEvent e) { if (e.Which == 13 && !justSelected) // Return pressed - but we want to do a search not move to the next cell { if (inputField.GetValue().Length > 0) selectButton.Click(); else { // Set value to null _value = null; return; } } else if (e.Which == 13) { return; } if (self._searchOpen) { switch (e.Which) { case 9: case 13: // Return case 38: // Up - don't navigate - but use the dropdown to select search results case 40: // Down - don't navigate - but use the dropdown to select search results e.PreventDefault(); e.StopPropagation(); break; } } else { switch (e.Which) { case 13: // Return e.PreventDefault(); e.StopPropagation(); break; } } justSelected = false; }); }