// 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); }
private void addFileRow(DynamicTable table, BlobFile file, ActionPostBack deletePb, List <Func <bool> > deleteModMethods) { var cells = new List <EwfTableCell>(); var thumbnailControl = BlobFileOps.GetThumbnailControl(file, ThumbnailResourceInfoCreator); if (thumbnailControl != null) { cells.Add(thumbnailControl); } var fileIsUnread = fileIdsMarkedAsRead != null && !fileIdsMarkedAsRead.Contains(file.FileId); cells.Add( new PostBackButton( PostBack.CreateFull( id: PostBack.GetCompositeId(postBackIdBase, file.FileId.ToString()), firstModificationMethod: () => { if (fileIsUnread && markFileAsReadMethod != null) { markFileAsReadMethod(file.FileId); } }, actionGetter: () => new PostBackAction(new SecondaryResponse(new BlobFileResponse(file.FileId, () => true), false))), new TextActionControlStyle(file.FileName), false) { ToolTip = file.FileName }); cells.Add(file.UploadedDate.ToDayMonthYearString(false)); cells.Add((fileIsUnread ? "New!" : "").ToCell(new TableCellSetup(classes: "ewfNewness".ToSingleElementArray()))); var delete = false; var deleteCheckBox = FormItem.Create( "", new EwfCheckBox(false, postBack: deletePb), validationGetter: control => new EwfValidation((pbv, v) => { delete = control.IsCheckedInPostBack(pbv); }, deletePb)).ToControl(); cells.Add(ReadOnly ? null : deleteCheckBox); deleteModMethods.Add( () => { if (!delete) { return(false); } BlobFileOps.SystemProvider.DeleteFile(file.FileId); return(true); }); table.AddRow(cells.ToArray()); }
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); }
/// <summary> /// Returns null if the file is null, the file is not an image, or there is no thumbnail resource info creator. /// </summary> internal static IEnumerable <Control> GetThumbnailControl(BlobFile file, Func <decimal, ResourceInfo> thumbnailResourceInfoCreator) { // NOTE: We'd like to check here whether the file is a renderable image or not. But we can't because we don't have the file contents. // So, we'll have to make sure that all ThumbnailPageInfoCreators provide a page that knows how to handle NEF files (ideally we'd want // it to behave as if there was no thumbnail at all if there is an unrenderable image file). // The only alternative to this that I can think of is creating a new file table field called "IsRenderable" that we store when // we first save the image. if (file == null || !ContentTypes.IsImageType(file.ContentType) || thumbnailResourceInfoCreator == null) { return(Enumerable.Empty <Control>()); } return(new EwfImage(new ImageSetup(null, sizesToAvailableWidth: true), thumbnailResourceInfoCreator(file.FileId)).ToCollection().GetControls()); }
// 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 ); }
private void addFileRow( DynamicTable table, BlobFile file, ActionPostBack deletePb, List<Func<bool>> deleteModMethods ) { var cells = new List<EwfTableCell>(); var thumbnailControl = BlobFileOps.GetThumbnailControl( file, ThumbnailResourceInfoCreator ); if( thumbnailControl != null ) cells.Add( thumbnailControl ); var fileIsUnread = fileIdsMarkedAsRead != null && !fileIdsMarkedAsRead.Contains( file.FileId ); cells.Add( new PostBackButton( PostBack.CreateFull( id: PostBack.GetCompositeId( postBackIdBase, file.FileId.ToString() ), firstModificationMethod: () => { if( fileIsUnread && markFileAsReadMethod != null ) markFileAsReadMethod( file.FileId ); }, actionGetter: () => new PostBackAction( new SecondaryResponse( new BlobFileResponse( file.FileId, () => true ), false ) ) ), new TextActionControlStyle( file.FileName ), false ) { ToolTip = file.FileName } ); cells.Add( file.UploadedDate.ToDayMonthYearString( false ) ); cells.Add( ( fileIsUnread ? "New!" : "" ).ToCell( new TableCellSetup( classes: "ewfNewness".ToSingleElementArray() ) ) ); var delete = false; var deleteCheckBox = FormItem.Create( "", new EwfCheckBox( false, postBack: deletePb ), validationGetter: control => new EwfValidation( ( pbv, v ) => { delete = control.IsCheckedInPostBack( pbv ); }, deletePb ) ).ToControl(); cells.Add( ReadOnly ? null : deleteCheckBox ); deleteModMethods.Add( () => { if( !delete ) return false; BlobFileOps.SystemProvider.DeleteFile( file.FileId ); return true; } ); table.AddRow( cells.ToArray() ); }
/// <summary> /// Returns null if the file is null, the file is not an image, or there is no thumbnail resource info creator. /// </summary> internal static Control GetThumbnailControl( BlobFile file, Func<decimal, ResourceInfo> thumbnailResourceInfoCreator ) { // NOTE: We'd like to check here whether the file is a renderable image or not. But we can't because we don't have the file contents. // So, we'll have to make sure that all ThumbnailPageInfoCreators provide a page that knows how to handle NEF files (ideally we'd want // it to behave as if there was no thumbnail at all if there is an unrenderable image file). // The only alternative to this that I can think of is creating a new file table field called "IsRenderable" that we store when // we first save the image. if( file == null || !ContentTypes.IsImageType( file.ContentType ) || thumbnailResourceInfoCreator == null ) return null; return new EwfImage( thumbnailResourceInfoCreator( file.FileId ).GetUrl() ) { SizesToAvailableWidth = true }; }
/// <summary> /// Creates a BLOB-file response. /// </summary> /// <param name="fileId">The ID of the BLOB file.</param> /// <param name="processAsAttachmentGetter">A function that gets whether you want the response to be processed as an attachment. Return true if you want /// this behavior; otherwise return false or do not pass a function.</param> /// <param name="forcedImageWidthGetter">A function that gets the width in pixels to which the specified file should be scaled, while maintaining its aspect /// ratio. The file must be an image. Pass null or return null if the file is not an image or you do not want scaling.</param> public BlobFileResponse( int fileId, Func<bool> processAsAttachmentGetter, Func<int?> forcedImageWidthGetter = null ) { file = BlobFileOps.SystemProvider.GetFile( fileId ); processAsAttachment = new Lazy<bool>( processAsAttachmentGetter ?? ( () => false ) ); forcedImageWidth = new Lazy<int?>( forcedImageWidthGetter ?? ( () => null ) ); }