internal void AddValidationRule(InputControlBase ctl, string ruleName, object ruleParams, object message) { RegisterScripts(ScriptTypes.Core | ScriptTypes.Validation); if (_rules == null) { _rules = new Dictionary <InputControlBase, JQueryOptions>(); } JQueryOptions options; if (!_rules.TryGetValue(ctl, out options)) { options = new JQueryOptions(); _rules.Add(ctl, options); } options.Add(ruleName, ruleParams); if (message != null) { if (_messages == null) { _messages = new Dictionary <string, JQueryOptions>(); } if (!_messages.TryGetValue(ctl.UniqueID, out options)) { options = new JQueryOptions(); _messages.Add(ctl.UniqueID, options); } options.Add(ruleName, message); } }
/// <summary> /// /// </summary> /// <param name="widgetName"></param> protected WidgetBase(string widgetName) { _clientOptions = new JQueryOptions(); _widgetName = widgetName; _clientEvents = new MultiKeyDictionary <string, string>(); this.Enabled = true; // ReSharper disable DoNotCallOverridableMethodsInConstructor this.EnableViewState = false; // ReSharper restore DoNotCallOverridableMethodsInConstructor }
/// <summary> /// Adds the jquery options for this button to the passed <paramref name="buttonOptions"/>. /// </summary> /// <param name="containingDialog"></param> /// <param name="buttonOptions"></param> public void AddButtonOption(Dialog containingDialog, JQueryOptions buttonOptions) { string func = GetFunction(containingDialog); if (string.IsNullOrEmpty(this.Text)) { this.Text = "Button"; } buttonOptions.AddRaw(this.Text, func); }
/// <summary> /// Helper function to register the validation rule with the script manager. /// If ID has been specified, cloneScript is used to clone the rule /// </summary> /// <param name="ctlInputControl">The control for which client validation needs to be registered</param> /// <param name="ruleName">The name of the client validation rule</param> /// <param name="jqRuleParams">Parameters to pass to the rule in javascript syntax</param> /// <param name="defaultMsg">Used only if MessageFormatString is empty</param> protected void DoRegisterValidator(InputControlBase ctlInputControl, string ruleName, object jqRuleParams, object defaultMsg) { object script = GetDependencyFunction(ctlInputControl); if (script != null) { JQueryOptions options = new JQueryOptions(); options.Add("param", jqRuleParams); options.Add("depends", script); jqRuleParams = options; } object msg; if (!string.IsNullOrEmpty(this.ClientMessageFunction)) { msg = new JScriptCode(this.ClientMessageFunction); } else if (!string.IsNullOrEmpty(this.ClientMessage)) { // Special handling. Show row number when control within grid. GridViewRow row = ctlInputControl.NamingContainer as GridViewRow; if (row == null) { msg = this.ClientMessage; } else { msg = string.Format("Row {0}: ", row.RowIndex + 1) + this.ClientMessage; } } else if (defaultMsg is string) { // Special handling. Show row number when control within grid. GridViewRow row = ctlInputControl.NamingContainer as GridViewRow; if (row == null) { msg = defaultMsg; } else { msg = string.Format("Row {0}: ", row.RowIndex + 1) + defaultMsg; } } else { msg = defaultMsg; } JQueryScriptManager.Current.AddValidationRule(ctlInputControl, ruleName, jqRuleParams, msg); }
/// <summary> /// Pass options to the client widget /// </summary> protected override void PreCreateScripts() { JQueryScriptManager.Current.RegisterScripts(ScriptTypes.UiCore); EnsureFilterList(); JQueryOptions options = new JQueryOptions(); foreach (var ctl in _usedParams.Where(p => !string.IsNullOrEmpty(p.QueryString) && !string.IsNullOrEmpty(p.QueryStringValue))) { options.Add(ctl.QueryString, ctl.QueryStringValue); } this.ClientOptions.Add("filters", options); //string script = string.Format("$('{0} #{1}').appliedFilters({{ filters: {2} }});", // JQueryScriptManager.Current.OutermostContainer, this.ClientID, options); //JQueryScriptManager.Current.RegisterScriptBlock("AppliedFiltersScripts", Properties.Resources.AppliedFiltersScripts); }
/// <summary> /// Generates the options which need to be passed to the jQuery <c>selectable</c> widget. /// </summary> /// <param name="owner"></param> /// <param name="gridOptions"></param> internal void MakeSelectable(GridViewEx owner, JQueryOptions gridOptions) { if (!this.IsSelectable) { return; } JQueryOptions selectableOptions = new JQueryOptions(); if (owner.EnableViewState) { gridOptions.Add("enableClientState", true); } //options.Add("autoRefresh", false); selectableOptions.Add("filter", this.Filter); selectableOptions.Add("tolerance", "touch"); // Multiple selection will not start until the mouse is dragged beyond these many pixels //options.Add("distance", 8); if (string.IsNullOrEmpty(this.Cancel)) { // If any of the header rows is clicked, do not modify selection selectableOptions.Add("cancel", ":input,option,a[href], tr.gvex-masterrow *, tr.gvex-subtotal-row *, thead *, tfoot *"); } else { selectableOptions.Add("cancel", this.Cancel); } if (!string.IsNullOrEmpty(this.OnSelectableStop)) { //options.AddRaw("stop", this.OnSelectableStop); owner.ClientEvents.Add("selectablestop", this.OnSelectableStop); } if (!string.IsNullOrEmpty(this.OnSelectableSelecting)) { owner.ClientEvents.Add("selectableselecting", this.OnSelectableSelecting); } if (!string.IsNullOrEmpty(this.OnSelectableUnselected)) { owner.ClientEvents.Add("selectableunselected", this.OnSelectableUnselected); } if (!string.IsNullOrEmpty(this.OnSelectableSelected)) { owner.ClientEvents.Add("selectableselected", this.OnSelectableSelected); } gridOptions.Add("selectable", selectableOptions); }
/// <summary> /// Attach a datepicker with the textbox /// </summary> /// <param name="ctlInputControl"></param> private void RegisterDatePicker(InputControlBase ctlInputControl) { JQueryOptions options = new JQueryOptions(); options.Add("showOn", "button"); string script; if (this.Min.HasValue) { options.Add("minDate", this.Min.Value); options.Add("origMinDays", this.Min.Value); } if (this.Max.HasValue) { options.Add("maxDate", this.Max.Value); options.Add("origMaxDays", this.Max.Value); } script = string.Format("$('{0}').datepicker({1});", ctlInputControl.ClientSelector, options); JQueryScriptManager.Current.RegisterReadyScript(script); }
internal void UpdateStartupOptions(Dialog dlg, JQueryOptions options) { if (!string.IsNullOrEmpty(this.Url)) { options.Add("url", dlg.ResolveUrl(this.Url)); } if (this.Cache) { options.Add("cache", this.Cache); } if (!string.IsNullOrEmpty(this.OnAjaxDialogClosing)) { options.AddRaw("closing", this.OnAjaxDialogClosing); } if (!string.IsNullOrEmpty(this.OnAjaxDialogLoaded)) { options.AddRaw("loaded", this.OnAjaxDialogLoaded); } if (!string.IsNullOrEmpty(this.OnAjaxDialogSubmitting)) { options.AddRaw("submitting", this.OnAjaxDialogSubmitting); } if (!string.IsNullOrEmpty(this.OnAjaxDialogLoading)) { options.AddRaw("loading", this.OnAjaxDialogLoading); } if (!this.UseDialog) { options.Add("_useDialog", false); } if (dlg.DialogStyle == DialogStyle.Picker) { options.Add("autoClose", false); } JQueryScriptManager.Current.RegisterScripts(ScriptTypes.Json); }
/// <summary> /// <inheritdoc /> /// </summary> protected override void PreCreateScripts() { JQueryOptions buttonOptions = new JQueryOptions(); foreach (DialogButton btn in this.Buttons) { btn.AddButtonOption(this, buttonOptions); } ClientOptions.Add("buttons", buttonOptions); if (Buttons.Count > 0) { // If no button has been specified as default, use the cancel button. If no cancel button, use the first one. DialogButton defButton = Buttons.FirstOrDefault(p => p.IsDefault); if (defButton == null) { defButton = Buttons.OfType <CloseButton>().FirstOrDefault(); } if (defButton == null) { // Use the first button as default defButton = Buttons[0]; } ClientOptions.Add("_defButtonText", defButton.Text); } if (this.EnablePostBack) { ClientOptions.Add("_enablePostBack", true); } if (_ajax != null) { _ajax.UpdateStartupOptions(this, this.ClientOptions); } if (this.Width != Unit.Empty) { if (this.Width.Type != UnitType.Pixel) { throw new HttpException("Dialog width can only be specified in pixels"); } this.ClientOptions.Add("width", this.Width.Value.ToString()); } switch (this.DialogStyle) { case DialogStyle.Default: break; case DialogStyle.Picker: this.ClientOptions.Add("dialogClass", "ui-pickerdialog"); if (!this.ClientOptions.ContainsKey("modal")) { this.ClientOptions.Add("modal", true); } break; case DialogStyle.AlwaysVisible: this.ClientOptions.Add("dialogClass", "ui-fixeddialog"); break; default: throw new NotImplementedException(); } JQueryScriptManager.Current.RegisterScripts(ScriptTypes.AjaxDialog); if (JQueryScriptManager.IsAjaxCall && this.Page.Form != null && _ajax != null && _ajax.UseDialog) { // Make sure we get destroyed if and when the page posts back string script = string.Format(@"$('#{0}').submit(function(e) {{ $('#{1}').dialog('destroy').remove(); }});", this.Page.Form.ClientID, this.ClientID); JQueryScriptManager.Current.RegisterReadyScript(script); } }
internal void CreateCascadeScripts(InputControlBase ctlPassed) { if (string.IsNullOrEmpty(this.WebMethod)) { // We are not cascadable. Nothing to do. return; } string loadData = ctlPassed.GetClientCode(ClientCodeType.LoadData); // If there is no way to load data, then we are not cascadable even if web method has been specified. // AutoComplete provides its own implementation for cascadable properties if (string.IsNullOrEmpty(loadData)) { return; } string str; // JSON stringifies data passed to the web method JQueryScriptManager.Current.RegisterScripts(ScriptTypes.Json | ScriptTypes.Core | ScriptTypes.Cascade); JQueryOptions options = new JQueryOptions(); if (!string.IsNullOrEmpty(this.CascadeParentId)) { InputControlBase ctlParent = (InputControlBase)ctlPassed.NamingContainer.FindControl(this.CascadeParentId); if (ctlParent == null) { str = string.Format("Could not find cascade parent {0}", this.CascadeParentId); throw new InvalidOperationException(str); } options.Add("parentChangeEventName", ctlParent.ClientChangeEventName); options.AddRaw("parentValue", ctlParent.GetClientCode(ClientCodeType.GetValue)); options.Add("cascadeParentSelector", ctlParent.ClientSelector); //ctlParent.ClientIdRequired = true; } if (string.IsNullOrEmpty(this.WebServicePath)) { options.Add("webServicePath", ctlPassed.Page.Request.Path); } else { options.Add("webServicePath", ctlPassed.Page.ResolveUrl(this.WebServicePath)); } options.Add("webMethodName", this.WebMethod); options.AddRaw("loadData", loadData); str = ctlPassed.GetClientCode(ClientCodeType.PreLoadData); if (!string.IsNullOrEmpty(str)) { options.AddRaw("preLoadData", str); } options.Add("interestEvent", ctlPassed.GetClientCode(ClientCodeType.InterestEvent)); //if (!ctlPassed.Page.IsPostBack && this.InitializeAtStartup) if (this.InitializeAtStartup) { options.Add("initializeAtStartup", this.InitializeAtStartup); } //if (this.HideParentsFromChildren) //{ // options.Add("hideParentsFromChildren", true); //} str = string.Format(".cascade({0})", options.ToJson()); ctlPassed.ReadyScripts.Add(str); }
/// <summary> /// No validation rules are generated if the page has no form /// </summary> /// <param name="writer"></param> private void PrepareFormForValidation(HtmlTextWriter writer) { if (_rules == null) { return; } if (this.DisableClientValidation || ((_scripts & ScriptTypes.Validation) != ScriptTypes.Validation)) { // If validation scripts not requested, validation framework is not generated return; } JQueryOptions validateOptions = new JQueryOptions(); // Hide all summaries. Error placement will make the correct one visible string script = @" function(map, list) { $.each(list, function(i) { $.buttonEx.validationSummary.append('<li>' + this.message + '</li>').removeClass('ui-helper-hidden'); }); }"; validateOptions.AddRaw("showErrors", script); validateOptions.Add("ignoreTitle", true); validateOptions.Add("ignore", ".{0}", CssClassIgnoreValidation); // false because our button is responsible for validating validateOptions.Add("onsubmit", false); validateOptions.Add("onfocusin", false); validateOptions.Add("onfocusout", false); validateOptions.Add("onclick", false); validateOptions.Add("onkeyup", false); validateOptions.Add("focusInvalid", false); validateOptions.Add("focusCleanup", false); if (_rules != null) { JQueryOptions rules = new JQueryOptions(); foreach (var rule in _rules) { rules.Add(rule.Key.UniqueID, rule.Value); } validateOptions.Add("rules", rules); //validateOptions.Add("rules", _rules.Aggregate(new JQueryOptions(), (rules, rule) => rules.Add(rule.Key.UniqueID, rule.Value))); } if (_messages != null) { JQueryOptions messages = new JQueryOptions(); foreach (var msg in _messages) { messages.Add(msg.Key, msg.Value); } validateOptions.Add("messages", messages); //validateOptions.Add("messages", _messages.Aggregate(new JQueryOptions(), (messages, msg) => messages.Add(msg.Key, msg.Value))); } // Validation requires that all input controls are within a form string formSelector; if (!string.IsNullOrEmpty(this.FormSelector)) { formSelector = this.FormSelector; } else if (this.Page.Form != null) { if (string.IsNullOrEmpty(this.Page.Form.ClientID)) { // Make sure the form has an ID. this.Page.Form.ClientIDMode = System.Web.UI.ClientIDMode.AutoID; } formSelector = string.Format("#{0}", this.Page.Form.ClientID); } else { throw new NotSupportedException("You must either have a server form or specify FormSelector"); } writer.WriteLine("$('{0}').validate({1});", formSelector, validateOptions.ToJson()); }