Example #1
0
        /// <summary>
        /// Creates a form item with a change based check box list, which is a check box list that is based on changes to the selections rather than the absolute
        /// set of selected items.
        /// </summary>
        /// <typeparam name="ItemIdType"></typeparam>
        /// <param name="label"></param>
        /// <param name="items"></param>
        /// <param name="modificationMethod">A method that executes the change handlers of the items that were selected or deselected on this post back.</param>
        /// <param name="caption"></param>
        /// <param name="includeSelectAndDeselectAllButtons"></param>
        /// <param name="numberOfColumns"></param>
        /// <param name="postBack"></param>
        /// <param name="cellSpan"></param>
        /// <param name="textAlignment"></param>
        /// <param name="validationPredicate"></param>
        /// <param name="validationList"></param>
        /// <returns></returns>
        public static FormItem GetFormItem <ItemIdType>(
            FormItemLabel label, IEnumerable <ChangeBasedListItemWithSelectionState <ItemIdType> > items, out Action modificationMethod, string caption = "",
            bool includeSelectAndDeselectAllButtons = false, byte numberOfColumns = 1, PostBack postBack = null, int?cellSpan = null,
            TextAlignment textAlignment             = TextAlignment.NotSpecified, Func <bool> validationPredicate = null, ValidationList validationList = null)
        {
            var itemArray         = items.ToArray();
            var selectedItemIds   = itemArray.Where(i => i.IsSelected).Select(i => i.Item.Item.Id);
            var uiSelectedItemIds = itemArray.Where(i => i.IsSelectedInUi).Select(i => i.Item.Item.Id);
            var checkBoxList      = new ChangeBasedCheckBoxList <ItemIdType>(
                itemArray.Select(i => i.Item),
                selectedItemIds,
                caption,
                includeSelectAndDeselectAllButtons,
                numberOfColumns,
                uiSelectedItemIds,
                postBack);

            modificationMethod = checkBoxList.ModifyData;
            return(FormItem.Create(
                       label,
                       checkBoxList,
                       cellSpan: cellSpan,
                       textAlignment: textAlignment,
                       validationGetter: control => new EwfValidation(
                           (pbv, validator) => {
                if (validationPredicate != null && !validationPredicate())
                {
                    return;
                }
                control.Validate(pbv);
            },
                           validationList ?? EwfPage.Instance.DataUpdate)));
        }
Example #2
0
 public static FormItem <WysiwygHtmlEditor> GetBodyHtmlFormItem(this EmailMessage emailMessage, ValidationList vl, string value = "")
 {
     return(FormItem.Create(
                "Body",
                new WysiwygHtmlEditor(value),
                validationGetter: control => new Validation((pbv, validator) => emailMessage.BodyHtml = control.GetPostBackValue(pbv), vl)));
 }
Example #3
0
 public static FormItem <EwfTextBox> GetSubjectFormItem(this EmailMessage emailMessage, ValidationList vl, string value = "")
 {
     return(FormItem.Create(
                "Subject",
                new EwfTextBox(value),
                validationGetter: control => new EwfValidation(
                    (pbv, validator) => {
         emailMessage.Subject = validator.GetString(new ValidationErrorHandler("subject"), control.GetPostBackValue(pbv), false);
         if (Regex.Match(emailMessage.Subject, RegularExpressions.HtmlTag, RegexOptions.IgnoreCase).Success)
         {
             validator.NoteErrorAndAddMessage("HTML is not allowed in the subject field.");
         }
     },
                    vl)));
 }
        void ControlTreeDataLoader.LoadData()
        {
            if (hideIfEmpty && !formItems.Any())
            {
                Visible = false;
                return;
            }

            CssClass = CssClass.ConcatenateWithSpace(CssElementCreator.CssClass);

            var theButton = button;

#pragma warning disable 618 // Disables obsolete warning
            if (IncludeButtonWithThisText != null)
            {
                theButton = new PostBackButton(EwfPage.Instance.DataUpdatePostBack, new ButtonActionControlStyle(IncludeButtonWithThisText));
            }
#pragma warning restore 618
            if (theButton != null)
            {
                theButton.ActionControlStyle = new ButtonActionControlStyle(theButton.ActionControlStyle.Text);
                theButton.Width = Unit.Percentage(50);

                // We need to do logic to get the button to be on the right of the row.
                if (useFormItemListMode && numberOfColumns.HasValue)
                {
                    var widthOfLastRowWithButton     = getFormItemRows(formItems, numberOfColumns.Value).Last().Sum(fi => getCellSpan(fi)) + defaultFormItemCellSpan;
                    var numberOfPlaceholdersRequired = 0;
                    if (widthOfLastRowWithButton < numberOfColumns.Value)
                    {
                        numberOfPlaceholdersRequired = numberOfColumns.Value - widthOfLastRowWithButton;
                    }
                    if (widthOfLastRowWithButton > numberOfColumns.Value)
                    {
                        numberOfPlaceholdersRequired = numberOfColumns.Value - ((widthOfLastRowWithButton - numberOfColumns.Value) % numberOfColumns.Value);
                    }

                    numberOfPlaceholdersRequired.Times(() => formItems.Add(getPlaceholderFormItem()));
                }
                formItems.Add(
                    FormItem.Create(
                        "",
                        theButton,
                        textAlignment: TextAlignment.Right,
                        cellSpan: defaultFormItemCellSpan));
            }
            Controls.Add(useFormItemListMode ? getTableForFormItemList() : getTableForFormItemTable());
        }
 private int getCellSpan(FormItem formItem)
 {
     return(formItem.CellSpan ?? defaultFormItemCellSpan);
 }
 private FormItem <Literal> getPlaceholderFormItem()
 {
     return(FormItem.Create("", "".GetLiteralControl(), cellSpan: 1));
 }