void ControlTreeDataLoader.LoadData() { CssClass = CssClass.ConcatenateWithSpace(CssElementCreator.CssClass); if (minuteInterval < 30) { textBox = new EwfTextBox(value.HasValue ? value.Value.ToTimeOfDayHourAndMinuteString() : "", disableBrowserAutoComplete: true, autoPostBack: autoPostBack); Controls.Add(new ControlLine(textBox, getIconButton())); } else { var minuteValues = new List <int>(); for (var i = 0; i < 60; i += minuteInterval) { minuteValues.Add(i); } selectList = SelectList.CreateDropDown( from hour in Enumerable.Range(0, 24) from minute in minuteValues let timeSpan = new TimeSpan(hour, minute, 0) select SelectListItem.Create <TimeSpan?>(timeSpan, timeSpan.ToTimeOfDayHourAndMinuteString()), value, width: Unit.Percentage(100), placeholderIsValid: true, placeholderText: "", autoPostBack: autoPostBack); Controls.Add(selectList); } if (ToolTip != null || ToolTipControl != null) { new ToolTip(ToolTipControl ?? EnterpriseWebFramework.Controls.ToolTip.GetToolTipTextControl(ToolTip), this); } }
private void buildNavigationBox() { var jumpList = SelectList.CreateDropDown( from i in Enumerable.Range(-3, 7) select SelectListItem.Create(i, formatDateTimeForJumpList(adjustDateByNumberOfIntervals(date, i))), 0, autoPostBack: true); jumpList.Width = JumpListWidth; var numIntervals = 0; EwfPage.Instance.DataUpdate.AddTopValidationMethod((pbv, validator) => numIntervals = jumpList.ValidateAndGetSelectedItemIdInPostBack(pbv, validator)); EwfPage.Instance.DataUpdate.AddModificationMethod(() => dateModificationMethod(adjustDateByNumberOfIntervals(date, numIntervals))); var previousLink = new PostBackButton( PostBack.CreateFull(id: "prev", firstModificationMethod: () => dateModificationMethod(adjustDateByNumberOfIntervals(date, -1))), PreviousButton, usesSubmitBehavior: false); var todayLink = new PostBackButton( PostBack.CreateFull(id: "today", firstModificationMethod: () => dateModificationMethod(DateTime.Today)), CurrentDateButton, usesSubmitBehavior: false); var nextLink = new PostBackButton( PostBack.CreateFull(id: "next", firstModificationMethod: () => dateModificationMethod(adjustDateByNumberOfIntervals(date, 1))), NextButton, usesSubmitBehavior: false); var table = new DynamicTable { CssClass = "calendarViewHeader ewfNavigationBoxHeader", IsStandard = false }; var navControls = new Panel(); foreach (var postBackButton in new List <PostBackButton> { previousLink, todayLink, nextLink }) { navControls.Controls.Add(postBackButton); } table.AddRow(jumpList, navControls.ToCell(new TableCellSetup(classes: "calendarViewNavButtons".ToSingleElementArray()))); Controls.Add(table); }
private IEnumerable <FormItem> getDropDownItems() { foreach (var items in new[] { new[] { SelectListItem.Create(null as int?, "NULL"), SelectListItem.Create(1 as int?, "This is item One"), SelectListItem.Create(2 as int?, "This is item Two"), SelectListItem.Create(3 as int?, "This is item Three") }, new[] { SelectListItem.Create(1 as int?, "This is item One"), SelectListItem.Create(2 as int?, "This is item Two"), SelectListItem.Create(3 as int?, "This is item Three") } }) { foreach (var selectedItemId in new int?[] { null, 1 }) { foreach (var defaultValueItemLabel in new[] { "", "None" }) { foreach (var placeholderIsValid in new[] { false, true }) { yield return(SelectList .CreateDropDown( DropDownSetup.Create(items), selectedItemId, defaultValueItemLabel: defaultValueItemLabel, placeholderIsValid: placeholderIsValid, validationMethod: (postBackValue, validator) => {}) .ToFormItem( label: StringTools.ConcatenateWithDelimiter( ", ", items.Length == 4 ? "Default in list" : "Default not in list", selectedItemId.HasValue ? "One selected" : "default selected", defaultValueItemLabel.Any() ? "default label" : "no default label", placeholderIsValid ? "placeholder valid" : "placeholder not valid") .ToComponents())); } } } } }
private IEnumerable <FormItem> getDropDownItems() { foreach (var items in new[] { new[] { SelectListItem.Create(null as int?, "NULL"), SelectListItem.Create(1 as int?, "This is item One"), SelectListItem.Create(2 as int?, "This is item Two"), SelectListItem.Create(3 as int?, "This is item Three") }, new[] { SelectListItem.Create(1 as int?, "This is item One"), SelectListItem.Create(2 as int?, "This is item Two"), SelectListItem.Create(3 as int?, "This is item Three") } }) { foreach (var selectedItemId in new int?[] { null, 1 }) { foreach (var defaultValueItemLabel in new[] { "", "None" }) { foreach (var placeholderIsValid in new[] { false, true }) { yield return (FormItem.Create( StringTools.ConcatenateWithDelimiter( ", ", items.Count() == 4 ? "Default in list" : "Default not in list", selectedItemId.HasValue ? "One selected" : "default selected", defaultValueItemLabel.Any() ? "default label" : "no default label", placeholderIsValid ? "placeholder valid" : "placeholder not valid"), SelectList.CreateDropDown(items, selectedItemId, defaultValueItemLabel: defaultValueItemLabel, placeholderIsValid: placeholderIsValid), validationGetter: control => new EwfValidation((pbv, validator) => control.ValidateAndGetSelectedItemIdInPostBack(pbv, validator), pb))); } } } } }
/// <summary> /// Call this during LoadData. /// </summary> /// <param name="userId"></param> /// <param name="vl"></param> /// <param name="availableRoles">Pass a restricted list of <see cref="Role"/>s the user may select. Otherwise, Roles available /// in the System Provider are used.</param> /// <param name="validationPredicate">If the function returns true, validation continues.</param> public void LoadData(int?userId, ValidationList vl, List <Role> availableRoles = null, Func <bool> validationPredicate = null) { availableRoles = (availableRoles != null ? availableRoles.OrderBy(r => r.Name) : UserManagementStatics.SystemProvider.GetRoles()).ToList(); user = userId.HasValue ? UserManagementStatics.GetUser(userId.Value, true) : null; if (includePasswordControls() && user != null) { facUser = FormsAuthStatics.GetUser(user.UserId, true); } Func <bool> validationShouldRun = () => validationPredicate == null || validationPredicate(); var b = FormItemBlock.CreateFormItemTable(heading: "Security Information"); b.AddFormItems( FormItem.Create( "Email address", new EwfTextBox(user != null ? user.Email : ""), validationGetter: control => new Validation( (pbv, validator) => { if (validationShouldRun()) { Email = validator.GetEmailAddress(new ValidationErrorHandler("email address"), control.GetPostBackValue(pbv), false); } }, vl))); if (includePasswordControls()) { var group = new RadioButtonGroup(false); var keepPassword = FormItem.Create( "", group.CreateInlineRadioButton(true, label: userId.HasValue ? "Keep the current password" : "Do not create a password"), validationGetter: control => new Validation( (pbv, validator) => { if (!validationShouldRun() || !control.IsCheckedInPostBack(pbv)) { return; } if (user != null) { Salt = facUser.Salt; SaltedPassword = facUser.SaltedPassword; MustChangePassword = facUser.MustChangePassword; } else { genPassword(false); } }, vl)); var generatePassword = FormItem.Create( "", group.CreateInlineRadioButton(false, label: "Generate a " + (userId.HasValue ? "new, " : "") + "random password and email it to the user"), validationGetter: control => new Validation( (pbv, validator) => { if (validationShouldRun() && control.IsCheckedInPostBack(pbv)) { genPassword(true); } }, vl)); var newPassword = new DataValue <string>(); var confirmPassword = new DataValue <string>(); var newPasswordTable = EwfTable.Create(style: EwfTableStyle.StandardExceptLayout); newPasswordTable.AddItem( new EwfTableItem( "Password", FormItem.Create( "", new EwfTextBox("", masksCharacters: true, disableBrowserAutoComplete: true) { Width = Unit.Pixel(200) }, validationGetter: control => new Validation((pbv, v) => newPassword.Value = control.GetPostBackValue(pbv), vl)).ToControl())); newPasswordTable.AddItem( new EwfTableItem( "Password again", FormItem.Create( "", new EwfTextBox("", masksCharacters: true, disableBrowserAutoComplete: true) { Width = Unit.Pixel(200) }, validationGetter: control => new Validation((pbv, v) => confirmPassword.Value = control.GetPostBackValue(pbv), vl)).ToControl())); var providePasswordRadio = group.CreateBlockRadioButton(false, label: "Provide a " + (userId.HasValue ? "new " : "") + "password"); providePasswordRadio.NestedControls.Add(newPasswordTable); var providePassword = FormItem.Create( "", providePasswordRadio, validationGetter: control => new Validation( (pbv, validator) => { if (!validationShouldRun() || !control.IsCheckedInPostBack(pbv)) { return; } FormsAuthStatics.ValidatePassword(validator, newPassword, confirmPassword); var p = new Password(newPassword.Value); Salt = p.Salt; SaltedPassword = p.ComputeSaltedHash(); MustChangePassword = false; }, vl)); b.AddFormItems( FormItem.Create("Password", ControlStack.CreateWithControls(true, keepPassword.ToControl(), generatePassword.ToControl(), providePassword.ToControl()))); } b.AddFormItems( FormItem.Create( "Role", SelectList.CreateDropDown( from i in availableRoles select SelectListItem.Create(i.RoleId as int?, i.Name), user != null ? user.Role.RoleId as int? : null), validationGetter: control => new Validation( (pbv, validator) => { if (validationShouldRun()) { RoleId = control.ValidateAndGetSelectedItemIdInPostBack(pbv, validator) ?? default(int); } }, vl))); Controls.Add(b); }
/// <summary> /// Call this during LoadData. /// </summary> /// <param name="userId"></param> /// <param name="availableRoles">Pass a restricted list of <see cref="Role"/>s the user may select. Otherwise, Roles available /// in the System Provider are used.</param> /// <param name="validationPredicate">If the function returns true, validation continues.</param> public void LoadData(int?userId, List <Role> availableRoles = null, Func <bool> validationPredicate = null) { availableRoles = (availableRoles != null ? availableRoles.OrderBy(r => r.Name) : UserManagementStatics.SystemProvider.GetRoles()).ToList(); user = userId.HasValue ? UserManagementStatics.GetUser(userId.Value, true) : null; if (includePasswordControls() && user != null) { facUser = FormsAuthStatics.GetUser(user.UserId, true); } Func <bool> validationShouldRun = () => validationPredicate == null || validationPredicate(); var b = FormItemBlock.CreateFormItemTable(heading: "Security Information"); b.AddFormItems( FormItem.Create( "Email address", new EwfTextBox(user != null ? user.Email : ""), validationGetter: control => new EwfValidation( (pbv, validator) => { if (validationShouldRun()) { Email = validator.GetEmailAddress(new ValidationErrorHandler("email address"), control.GetPostBackValue(pbv), false); } }))); if (includePasswordControls()) { var group = new RadioButtonGroup(false); var keepPassword = FormItem.Create( "", group.CreateInlineRadioButton(true, label: userId.HasValue ? "Keep the current password" : "Do not create a password"), validationGetter: control => new EwfValidation( (pbv, validator) => { if (!validationShouldRun() || !control.IsCheckedInPostBack(pbv)) { return; } if (user != null) { Salt = facUser.Salt; SaltedPassword = facUser.SaltedPassword; MustChangePassword = facUser.MustChangePassword; } else { genPassword(false); } })); var generatePassword = FormItem.Create( "", group.CreateInlineRadioButton(false, label: "Generate a " + (userId.HasValue ? "new, " : "") + "random password and email it to the user"), validationGetter: control => new EwfValidation( (pbv, validator) => { if (validationShouldRun() && control.IsCheckedInPostBack(pbv)) { genPassword(true); } })); var providePassword = FormState.ExecuteWithValidationPredicate( validationShouldRun, () => { var providePasswordSelected = new DataValue <bool>(); return(FormItem.Create( "", group.CreateBlockRadioButton( false, (postBackValue, validator) => providePasswordSelected.Value = postBackValue.Value, label: "Provide a {0}".FormatWith(userId.HasValue ? "new password" : "password"), nestedControlListGetter: () => { return FormState.ExecuteWithValidationPredicate( () => providePasswordSelected.Value, () => { var password = new DataValue <string>(); var newPasswordTable = EwfTable.Create(style: EwfTableStyle.StandardExceptLayout); foreach (var i in password.GetPasswordModificationFormItems(textBoxWidth: Unit.Pixel(200))) { newPasswordTable.AddItem(new EwfTableItem(i.Label, i.ToControl(omitLabel: true))); } new EwfValidation( validator => { var p = new Password(password.Value); Salt = p.Salt; SaltedPassword = p.ComputeSaltedHash(); MustChangePassword = false; }); return newPasswordTable.ToCollection(); }); }), validationGetter: control => control.Validation)); }); b.AddFormItems( FormItem.Create("Password", ControlStack.CreateWithControls(true, keepPassword.ToControl(), generatePassword.ToControl(), providePassword.ToControl()))); } b.AddFormItems( FormItem.Create( "Role", SelectList.CreateDropDown( from i in availableRoles select SelectListItem.Create(i.RoleId as int?, i.Name), user != null ? user.Role.RoleId as int? : null), validationGetter: control => new EwfValidation( (pbv, validator) => { if (validationShouldRun()) { RoleId = control.ValidateAndGetSelectedItemIdInPostBack(pbv, validator) ?? default(int); } }))); Controls.Add(b); }