File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed
Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 113113 >
114114 Add Field
115115 </ button >
116+ < button
117+ @click ="copyDocument(); desktopMenuOpen = false "
118+ type ="button "
119+ class ="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-blue-100 "
120+ >
121+ Copy Document
122+ </ button >
116123 < button
117124 @click ="shouldShowDeleteModal=true; desktopMenuOpen = false "
118125 :disabled ="!canManipulate "
201208 >
202209 Add Field
203210 </ button >
211+ < button
212+ @click ="copyDocument(); mobileMenuOpen = false "
213+ type ="button "
214+ class ="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-blue-100 "
215+ >
216+ Copy Document
217+ </ button >
204218 < button
205219 @click ="shouldShowDeleteModal=true; mobileMenuOpen = false "
206220 :disabled ="!canManipulate "
Original file line number Diff line number Diff line change @@ -275,6 +275,43 @@ module.exports = app => app.component('document', {
275275 this . changes = { } ;
276276 }
277277 } ,
278+ copyDocument ( ) {
279+ if ( ! this . document ) {
280+ return ;
281+ }
282+
283+ const textToCopy = JSON . stringify ( this . document , null , 2 ) ;
284+ const fallbackCopy = ( ) => {
285+ if ( typeof document === 'undefined' ) {
286+ return ;
287+ }
288+ const textArea = document . createElement ( 'textarea' ) ;
289+ textArea . value = textToCopy ;
290+ textArea . setAttribute ( 'readonly' , '' ) ;
291+ textArea . style . position = 'absolute' ;
292+ textArea . style . left = '-9999px' ;
293+ document . body . appendChild ( textArea ) ;
294+ textArea . select ( ) ;
295+ try {
296+ document . execCommand ( 'copy' ) ;
297+ } finally {
298+ document . body . removeChild ( textArea ) ;
299+ }
300+ this . $toast . success ( 'Document copied!' ) ;
301+ } ;
302+
303+ if ( typeof navigator !== 'undefined' && navigator . clipboard && navigator . clipboard . writeText ) {
304+ navigator . clipboard . writeText ( textToCopy )
305+ . then ( ( ) => {
306+ this . $toast . success ( 'Document copied!' ) ;
307+ } )
308+ . catch ( ( ) => {
309+ fallbackCopy ( ) ;
310+ } ) ;
311+ } else {
312+ fallbackCopy ( ) ;
313+ }
314+ } ,
278315 goBack ( ) {
279316 // Preserve query parameters when going back to models page
280317 this . $router . push ( {
You can’t perform that action at this time.
0 commit comments