@@ -149,30 +149,30 @@ export default {
149149 }
150150 } ,
151151
152- insertGraphic ( insertFile ) {
152+ insertFile_impl ( mimeTypeFilter , insertFileProc , insertHandler ) {
153153 if ( isPublic ) {
154- console . error ( '[FilesAppIntegration] insertGraphic is not supported' )
154+ console . error ( '[FilesAppIntegration] insertFile is not supported' )
155155 }
156156
157157 const insertFileFromPath = async ( path ) => {
158158 const filename = path . substring ( path . lastIndexOf ( '/' ) + 1 )
159159 const { data } = await axios . post ( generateUrl ( 'apps/richdocuments/assets' ) , { path } )
160- insertFile ( filename , data . url )
160+ insertFileProc ( filename , data . url )
161161 }
162162
163- if ( this . handlers . insertGraphic && this . handlers . insertGraphic ( this , { insertFileFromPath } ) ) {
163+ if ( insertHandler && insertHandler ( this , mimeTypeFilter , { insertFileFromPath } ) ) {
164164 return
165165 }
166166
167- getFilePickerBuilder ( t ( 'richdocuments' , 'Insert image from {name}' , { name : OC . theme . name } ) )
168- . setMimeTypeFilter ( [ 'image/png' , 'image/gif' , 'image/jpeg' , 'image/svg' ] )
167+ getFilePickerBuilder ( t ( 'richdocuments' , 'Insert file from {name}' , { name : OC . theme . name } ) )
168+ . setMimeTypeFilter ( mimeTypeFilter )
169169 . setFilter ( ( node ) => {
170170 const downloadShareAttribute = JSON . parse ( node . attributes [ 'share-attributes' ] ) . find ( ( shareAttribute ) => shareAttribute . key === 'download' )
171171 const downloadPermissions = downloadShareAttribute !== undefined ? ( downloadShareAttribute . enabled || downloadShareAttribute . value ) : true
172172 return ( node . permissions & OC . PERMISSION_READ ) && downloadPermissions
173173 } )
174174 . addButton ( {
175- label : t ( 'richdocuments' , 'Insert image ' ) ,
175+ label : t ( 'richdocuments' , 'Insert file ' ) ,
176176 callback : ( files ) => {
177177 if ( files && files . length ) {
178178 insertFileFromPath ( files [ 0 ] . path )
@@ -183,6 +183,16 @@ export default {
183183 . pick ( )
184184 } ,
185185
186+ insertGraphic ( insertFileProc ) {
187+ this . insertFile_impl ( [ 'image/png' , 'image/gif' , 'image/jpeg' , 'image/svg' ] ,
188+ insertFileProc ,
189+ ( filesAppIntegration , mimeTypeFilter , { insertFileFromPath } ) => { return this . handlers . insertGraphic && this . handlers . insertGraphic ( filesAppIntegration , { insertFileFromPath } ) } )
190+ } ,
191+
192+ insertFile ( mimeTypeFilter , insertFileProc ) {
193+ this . insertFile_impl ( mimeTypeFilter , insertFileProc , this . handlers . insertFile )
194+ } ,
195+
186196 getFileList ( ) {
187197 if ( this . fileList ) {
188198 return this . fileList
0 commit comments