Пример #1
0
        /// <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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        /// <summary>
        /// Attach a datepicker with the textbox.
        /// </summary>
        /// <param name="dateValidator"></param>
        private void RegisterDatePicker(Date dateValidator)
        {
            DatePickerOptions.Add("showOn", "button");
            if (dateValidator.Min.HasValue)
            {
                DatePickerOptions.Add("minDate", dateValidator.Min.Value);
            }
            if (dateValidator.Max.HasValue)
            {
                DatePickerOptions.Add("maxDate", dateValidator.Max.Value);
            }
            DatePickerOptions.Add("showOtherMonths", true);
            DatePickerOptions.Add("changeMonth", true);
            //DatePickerOptions.Add("buttonText", "<SPAN class=\"ui-button-icon-only ui-icon ui-icon-calendar\"></SPAN>");
            // Because of the possibility of watermark, we must use this
            // event to set the value. To help DropDownSuggest, we are raising the keypress event.
            DatePickerOptions.AddRaw("onSelect", @"function(dateText, inst) {
$(this).val(dateText).change();
}");

            // The date should use the current UI culture
            if (!this.DatePickerOptions.ContainsKey("dateFormat"))
            {
                switch (CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern)
                {
                case "M/d/yyyy":
                case "M'/'d'/'yyyy":
                    DatePickerOptions.Add("dateFormat", "m/d/yy");
                    break;

                case "d/M/yyyy":
                    DatePickerOptions.Add("dateFormat", "d/m/yy");
                    break;

                case "dd-MMM-yy":
                    DatePickerOptions.Add("dateFormat", "d-M-y");
                    break;

                case "MM/dd/yyyy":
                case "MM'/'dd'/'yyyy":
                    DatePickerOptions.Add("dateFormat", "mm/dd/yy");
                    break;

                default:
                    throw new NotImplementedException();
                }
            }
            this.ClientOptions.Add("pickerOptions", DatePickerOptions);
            switch (dateValidator.DateType)
            {
            case DateType.Default:
                break;

            case DateType.ToDate:
                TextBoxEx tbFrom = dateValidator.GetFromControl(this);
                this.ClientOptions.Add("fromSelector", tbFrom.ClientSelector);
                if (dateValidator.MaxRange > 0)
                {
                    this.ClientOptions.Add("maxDateRange", dateValidator.MaxRange);
                }
                break;

            default:
                break;
            }
        }
Пример #4
0
        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);
        }
Пример #5
0
        /// <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());
        }