private void createChildControlsAndWireUpEvents() { captionTable = TableOps.CreateUnderlyingTable(); captionTable.CssClass = "ewfStandardDynamicTableCaption"; captionTable.Visible = false; var row = new TableRow(); var captionCell = new TableCell(); captionCell.Controls.Add(captionStack = ControlStack.Create(false)); row.Cells.Add(captionCell); var actionLinksCell = new TableCell { CssClass = "ewfAddItemLink" }; actionLinksCell.Controls.Add(actionLinkStack = ControlStack.Create(false)); row.Cells.Add(actionLinksCell); captionTable.Rows.Add(row); Controls.Add(captionTable); table = TableOps.CreateUnderlyingTable(); Controls.Add(table); PreRender += ewfTable_PreRender; dataModifications = FormState.Current.DataModifications; }
// NOTE: EVERYTHING should be done here. We shouldn't have LoadData. We should audit everyone using this control and see if we can improve things. // NOTE: This should also be full of delegates that run when events (such as deleting a file) are occurring. // NOTE: There should be a way to tell if a file was uploaded. void ControlTreeDataLoader.LoadData() { if (fileCollectionId != null) { file = BlobFileOps.GetFirstFileFromCollection(fileCollectionId.Value); } var controlStack = ControlStack.Create(true); if (file != null) { var download = new PostBackButton( PostBack.CreateFull( id: PostBack.GetCompositeId("ewfFile", file.FileId.ToString()), actionGetter: () => { // Refresh the file here in case a new one was uploaded on the same post-back. return (new PostBackAction( new SecondaryResponse(new BlobFileResponse(BlobFileOps.GetFirstFileFromCollection(fileCollectionId.Value).FileId, () => true), false))); }), new TextActionControlStyle(Translation.DownloadExisting + " (" + file.FileName + ")"), false); controlStack.AddControls(download); } else if (!HideNoExistingFileMessage) { controlStack.AddControls(new Label { Text = Translation.NoExistingFile }); } uploadedFile = new EwfFileUpload(); if (file != null) { uploadedFile.SetInitialDisplay(false); var replaceExistingFileLink = new ToggleButton( uploadedFile.ToSingleElementArray(), new TextActionControlStyle(Translation.ClickHereToReplaceExistingFile)) { AlternateText = "" }; controlStack.AddControls(replaceExistingFileLink); } controlStack.AddControls(uploadedFile); var thumbnailControl = BlobFileOps.GetThumbnailControl(file, ThumbnailResourceInfoCreator); if (thumbnailControl != null) { Controls.Add(thumbnailControl); } Controls.Add(controlStack); }
public BlobFileManager(int?fileCollectionId) { this.fileCollectionId = fileCollectionId; if (fileCollectionId != null) { file = BlobFileOps.GetFirstFileFromCollection(fileCollectionId.Value); } var controlStack = ControlStack.Create(true); if (file != null) { var download = new PostBackButton( new TextActionControlStyle(Translation.DownloadExisting + " (" + file.FileName + ")"), usesSubmitBehavior: false, postBack: PostBack.CreateFull( id: PostBack.GetCompositeId("ewfFile", file.FileId.ToString()), actionGetter: () => { // Refresh the file here in case a new one was uploaded on the same post-back. return (new PostBackAction( new SecondaryResponse(new BlobFileResponse(BlobFileOps.GetFirstFileFromCollection(fileCollectionId.Value).FileId, () => true), false))); })); controlStack.AddControls(download); } else if (!HideNoExistingFileMessage) { controlStack.AddControls(new Label { Text = Translation.NoExistingFile }); } uploadedFile = new EwfFileUpload(); if (file != null) { uploadedFile.SetInitialDisplay(false); var replaceExistingFileLink = new ToggleButton( uploadedFile.ToCollection(), new TextActionControlStyle(Translation.ClickHereToReplaceExistingFile), false, (postBackValue, validator) => { }) { AlternateText = "" }; controlStack.AddControls(replaceExistingFileLink); } controlStack.AddControls(uploadedFile); this.AddControlsReturnThis(BlobFileOps.GetThumbnailControl(file, ThumbnailResourceInfoCreator)); Controls.Add(controlStack); }
void ControlTreeDataLoader.LoadData() { CssClass = CssClass.ConcatenateWithSpace(CssElementCreator.CssClass); var controlStack = ControlStack.Create(false); if (label != null) { controlStack.AddControls(label); } if (validation != null) { controlStack.AddModificationErrorItem(validation, new ListErrorDisplayStyle()); } controlStack.AddControls(new PlaceHolder().AddControlsReturnThis(wrappedControls)); Controls.Add(controlStack); }
/// <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); }
/// <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 EwfValidation( (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 EwfValidation( (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 EwfValidation( (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 EwfValidation((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 EwfValidation((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 EwfValidation( (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 EwfValidation( (pbv, validator) => { if (validationShouldRun()) { RoleId = control.ValidateAndGetSelectedItemIdInPostBack(pbv, validator) ?? default(int); } }, vl))); Controls.Add(b); }