Exemple #1
0
        public virtual void Visit(FormNumberSpinner formNumberSpinner)
        {
            formNumberSpinner.Content = values[formNumberSpinner.Path];

            if (source != formNumberSpinner)
            {
                return;
            }

            switch (argument)
            {
            case "Incr":
                if (formNumberSpinner.HasValue)
                {
                    formNumberSpinner.Content = (formNumberSpinner.Value + formNumberSpinner.Step).ToString();
                }
                break;

            case "Decr":
                if (formNumberSpinner.HasValue)
                {
                    formNumberSpinner.Content = (formNumberSpinner.Value - formNumberSpinner.Step).ToString();
                }
                break;

            default:
                break;
            }
        }
Exemple #2
0
 public virtual void Visit(FormNumberSpinner formNumberSpinner)
 {
     sb.AppendLine(string.Format("{0}{1}: {2}", formNumberSpinner.Label, Mark(formNumberSpinner), formNumberSpinner.Value));
 }
        private HtmlDiv BuildDivNumberSpinner(FormNumberSpinner formNumberSpinner, HtmlTextBox htmlTextBox)
        {
            HtmlDiv htmlDivNumberSpinner = new HtmlDiv();

            string btnDecrName = verbose ? string.Format("{0}{1}", "Decr", formNumberSpinner.Path) : "";
            string btnIncrName = verbose ? string.Format("{0}{1}", "Incr", formNumberSpinner.Path) : "";

            string btnDecrOnClick = null;
            string btnIncrOnClick = null;

            if (formNumberSpinner.Update)
            {
                btnDecrOnClick = string.Format("__doPostBack('{0}', 'Decr');", formNumberSpinner.Path);
                btnIncrOnClick = string.Format("__doPostBack('{0}', 'Incr');", formNumberSpinner.Path);
            }
            else if (htmlTextBox.Id.IsSet)
            {
                btnDecrOnClick = string.Format("NumberSpinnerDecr('{0}');", htmlTextBox.Id.Value);
                btnIncrOnClick = string.Format("NumberSpinnerIncr('{0}');", htmlTextBox.Id.Value);

                scriptRegistry.Include("NumberSpinnerDecr");
                scriptRegistry.Include("NumberSpinnerIncr");
            }

            HtmlButton htmlButtonDecr = new HtmlButton(btnDecrName, btnDecrOnClick);
            HtmlButton htmlButtonIncr = new HtmlButton(btnIncrName, btnIncrOnClick);

            htmlButtonDecr.Value.Value = formNumberSpinner.DecrText;
            htmlButtonIncr.Value.Value = formNumberSpinner.IncrText;

            htmlButtonDecr.Disabled.Value = htmlButtonIncr.Disabled.Value = formNumberSpinner.IsReadOnly || (formNumberSpinner.Update && !formNumberSpinner.HasValue);

            if (!initialize && firstInvalidId == null)
            {
                if (formNumberSpinner.IsRequired && !formNumberSpinner.HasValue || !formNumberSpinner.IsValid)
                {
                    firstInvalidId = htmlTextBox.Id.Value;
                }
            }

            switch (formNumberSpinner.OrderNumberSpinner)
            {
            case OrderNumberSpinner.NumberDecrIncr:

                htmlDivNumberSpinner.Add(htmlTextBox);
                htmlDivNumberSpinner.Add(htmlButtonDecr);
                htmlDivNumberSpinner.Add(htmlButtonIncr);

                break;

            case OrderNumberSpinner.NumberIncrDecr:

                htmlDivNumberSpinner.Add(htmlTextBox);
                htmlDivNumberSpinner.Add(htmlButtonIncr);
                htmlDivNumberSpinner.Add(htmlButtonDecr);

                break;

            case OrderNumberSpinner.DecrNumberIncr:

                htmlDivNumberSpinner.Add(htmlButtonDecr);
                htmlDivNumberSpinner.Add(htmlTextBox);
                htmlDivNumberSpinner.Add(htmlButtonIncr);

                break;

            case OrderNumberSpinner.IncrNumberDecr:

                htmlDivNumberSpinner.Add(htmlButtonIncr);
                htmlDivNumberSpinner.Add(htmlTextBox);
                htmlDivNumberSpinner.Add(htmlButtonDecr);

                break;

            case OrderNumberSpinner.DecrIncrNumber:

                htmlDivNumberSpinner.Add(htmlButtonDecr);
                htmlDivNumberSpinner.Add(htmlButtonIncr);
                htmlDivNumberSpinner.Add(htmlTextBox);

                break;

            case OrderNumberSpinner.IncrDecrNumber:

                htmlDivNumberSpinner.Add(htmlButtonIncr);
                htmlDivNumberSpinner.Add(htmlButtonDecr);
                htmlDivNumberSpinner.Add(htmlTextBox);

                break;

            default:
            case OrderNumberSpinner.NotSet:

                break;
            }

            return(htmlDivNumberSpinner);
        }
        public virtual void Visit(FormNumberSpinner formNumberSpinner, HtmlContainer htmlContainer)
        {
            HtmlDiv htmlDiv = verbose ? new HtmlDiv(formNumberSpinner.Path) : new HtmlDiv();

            htmlDiv.Class.Add("formNumberSpinner");

            if (!string.IsNullOrWhiteSpace(formNumberSpinner.CssClass))
            {
                htmlDiv.Class.AddRange(formNumberSpinner.CssClass.Split(' ').Where(s => s != string.Empty));
            }

            if (!string.IsNullOrWhiteSpace(formNumberSpinner.Path))
            {
                htmlDiv.Class.Add(string.Format("{0}{1}", "formId", formNumberSpinner.Path));
            }

            htmlDiv.Class.Add("formField");

            if (initialize)
            {
                htmlDiv.Class.Add(formNumberSpinner.IsRequired ? "formRequired" : "formOptional");
            }
            else
            {
                if (formNumberSpinner.HasValue)
                {
                    htmlDiv.Class.Add(formNumberSpinner.IsValid ? "formValid" : "formInvalid");
                }
                else
                {
                    htmlDiv.Class.Add(formNumberSpinner.IsRequired ? "formNotEntered" : "formOptional");
                }
            }

            htmlDiv.Hidden.Value = formNumberSpinner.IsHidden;

            htmlContainer.Add(htmlDiv);

            HtmlTextBox htmlTextBox = new HtmlTextBox(formNumberSpinner.Path);

            htmlTextBox.Disabled.Value = formNumberSpinner.IsDisabled;
            htmlTextBox.ReadOnly.Value = formNumberSpinner.IsReadOnly || !formNumberSpinner.IsDirectInput;
            htmlTextBox.Value.Value    = formNumberSpinner.HasValue ? formNumberSpinner.Value.ToString(string.Format("F{0}", formNumberSpinner.Precision)) : "";

            string placeholder = null;

            if (!string.IsNullOrWhiteSpace(formNumberSpinner.Placeholder))
            {
                if (formNumberSpinner.IsRequired && formNumberSpinner.IsRequiredInPlaceholder && !string.IsNullOrWhiteSpace(formNumberSpinner.RequiredMark))
                {
                    placeholder = string.Format("{0} {1}", formNumberSpinner.Placeholder, formNumberSpinner.RequiredMark);
                }
                else if (!formNumberSpinner.IsRequired && formNumberSpinner.IsOptionalInPlaceholder && !string.IsNullOrWhiteSpace(formNumberSpinner.OptionalMark))
                {
                    placeholder = string.Format("{0} {1}", formNumberSpinner.Placeholder, formNumberSpinner.OptionalMark);
                }
                else
                {
                    placeholder = formNumberSpinner.Placeholder;
                }
            }

            htmlTextBox.Placeholder.Value = placeholder;

            if (formNumberSpinner.Update)
            {
                htmlTextBox.Change.Value = string.Format("__doPostBack('{0}', '');", formNumberSpinner.Path);
            }
            else
            {
                if (formNumberSpinner.HasValue)
                {
                    htmlTextBox.DataNumber.Value = formNumberSpinner.Value;
                }

                if (formNumberSpinner.Min.HasValue)
                {
                    htmlTextBox.DataMin.Value = formNumberSpinner.Min.Value;
                }

                if (formNumberSpinner.Max.HasValue)
                {
                    htmlTextBox.DataMax.Value = formNumberSpinner.Max.Value;
                }

                htmlTextBox.DataStep.Value = formNumberSpinner.Step;

                htmlTextBox.DataPrecision.Value = formNumberSpinner.Precision;

                htmlTextBox.Blur.Value = string.Format("NumberSpinnerBlur('{0}')", htmlTextBox.Id.Value);

                scriptRegistry.Include("NumberSpinnerBlur");
            }

            HtmlDiv htmlDivNumberSpinner = BuildDivNumberSpinner(formNumberSpinner, htmlTextBox);

            switch (formNumberSpinner.OrderElements)
            {
            case OrderElements.LabelMarkInput:

                AddLabelMark(formNumberSpinner, htmlTextBox, htmlDiv);
                htmlDiv.Add(htmlDivNumberSpinner);

                break;

            case OrderElements.MarkLabelInput:

                AddMarkLabel(formNumberSpinner, htmlTextBox, htmlDiv);
                htmlDiv.Add(htmlDivNumberSpinner);

                break;

            case OrderElements.InputLabelMark:

                htmlDiv.Add(htmlTextBox);
                AddLabelMark(formNumberSpinner, htmlTextBox, htmlDiv);

                break;

            case OrderElements.InputMarkLabel:

                htmlDiv.Add(htmlDivNumberSpinner);
                AddMarkLabel(formNumberSpinner, htmlTextBox, htmlDiv);

                break;

            case OrderElements.LabelInputMark:

                AddLabel(formNumberSpinner, htmlTextBox, htmlDiv);
                htmlDiv.Add(htmlDivNumberSpinner);
                AddMark(formNumberSpinner, htmlTextBox, htmlDiv);

                break;

            case OrderElements.MarkInputLabel:

                AddMark(formNumberSpinner, htmlTextBox, htmlDiv);
                htmlDiv.Add(htmlDivNumberSpinner);
                AddLabel(formNumberSpinner, htmlTextBox, htmlDiv);

                break;

            default:
            case OrderElements.NotSet:

                break;
            }

            if (initialize)
            {
                return;
            }

            string message = null;

            if (formNumberSpinner.UseLastMessage)
            {
                if (!string.IsNullOrEmpty(formNumberSpinner.LastMessage))
                {
                    message = formNumberSpinner.LastMessage;
                }
            }
            else if (formNumberSpinner.IsRequired && !formNumberSpinner.HasValue)
            {
                message = formNumberSpinner.RequiredMessage;
            }
            else if (!formNumberSpinner.IsValid)
            {
                message = formNumberSpinner.ValidationMessage;
            }

            if (message == null)
            {
                return;
            }

            HtmlLabel htmlLabelMessage = new HtmlLabel(verbose ? string.Format("{0}{1}", formNumberSpinner.Path, "Message") : "");

            htmlLabelMessage.Class.Add("formValidationMessage");
            htmlLabelMessage.For.Value = htmlTextBox.Id.Value;
            htmlLabelMessage.Add(new HtmlText(message));
            htmlDiv.Add(htmlLabelMessage);
        }