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 8484 >
8585 Add Field
8686 </ button >
87+ < button
88+ @click ="copyDocument(); desktopMenuOpen = false "
89+ type ="button "
90+ class ="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-blue-100 "
91+ >
92+ Copy Document
93+ </ button >
8794 < button
8895 @click ="shouldShowDeleteModal=true; desktopMenuOpen = false "
8996 :disabled ="!canManipulate "
157164 >
158165 Add Field
159166 </ button >
167+ < button
168+ @click ="copyDocument(); mobileMenuOpen = false "
169+ type ="button "
170+ class ="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-blue-100 "
171+ >
172+ Copy Document
173+ </ button >
160174 < button
161175 @click ="shouldShowDeleteModal=true; mobileMenuOpen = false "
162176 :disabled ="!canManipulate "
Original file line number Diff line number Diff line change @@ -137,6 +137,43 @@ module.exports = app => app.component('document', {
137137 this . changes = { } ;
138138 }
139139 } ,
140+ copyDocument ( ) {
141+ if ( ! this . document ) {
142+ return ;
143+ }
144+
145+ const textToCopy = JSON . stringify ( this . document , null , 2 ) ;
146+ const fallbackCopy = ( ) => {
147+ if ( typeof document === 'undefined' ) {
148+ return ;
149+ }
150+ const textArea = document . createElement ( 'textarea' ) ;
151+ textArea . value = textToCopy ;
152+ textArea . setAttribute ( 'readonly' , '' ) ;
153+ textArea . style . position = 'absolute' ;
154+ textArea . style . left = '-9999px' ;
155+ document . body . appendChild ( textArea ) ;
156+ textArea . select ( ) ;
157+ try {
158+ document . execCommand ( 'copy' ) ;
159+ } finally {
160+ document . body . removeChild ( textArea ) ;
161+ }
162+ this . $toast . success ( 'Document copied!' ) ;
163+ } ;
164+
165+ if ( typeof navigator !== 'undefined' && navigator . clipboard && navigator . clipboard . writeText ) {
166+ navigator . clipboard . writeText ( textToCopy )
167+ . then ( ( ) => {
168+ this . $toast . success ( 'Document copied!' ) ;
169+ } )
170+ . catch ( ( ) => {
171+ fallbackCopy ( ) ;
172+ } ) ;
173+ } else {
174+ fallbackCopy ( ) ;
175+ }
176+ } ,
140177 goBack ( ) {
141178 // Preserve query parameters when going back to models page
142179 this . $router . push ( {
You can’t perform that action at this time.
0 commit comments