]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/directives/copy2clipboard-button.directive.ts
import 15.2.4
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / directives / copy2clipboard-button.directive.ts
index 005b20157583a936459b7925335d1cacd2af1285..32f4cda3e85b845f97355c08db79ced66d2aa24d 100644 (file)
@@ -1,4 +1,5 @@
 import { Directive, ElementRef, HostListener, Input, OnInit, Renderer2 } from '@angular/core';
+import { I18n } from '@ngx-translate/i18n-polyfill';
 
 import { ToastrService } from 'ngx-toastr';
 
@@ -8,17 +9,21 @@ import { ToastrService } from 'ngx-toastr';
 export class Copy2ClipboardButtonDirective implements OnInit {
   @Input()
   private cdCopy2ClipboardButton: string;
+  @Input()
+  private formatted = 'no';
 
   constructor(
     private elementRef: ElementRef,
     private renderer: Renderer2,
-    private toastr: ToastrService
+    private toastr: ToastrService,
+    private i18n: I18n
   ) {}
 
   ngOnInit() {
     const iElement = this.renderer.createElement('i');
     this.renderer.addClass(iElement, 'fa');
     this.renderer.addClass(iElement, 'fa-clipboard');
+    this.renderer.setAttribute(iElement, 'title', this.i18n('Copy to clipboard'));
     this.renderer.appendChild(this.elementRef.nativeElement, iElement);
   }
 
@@ -29,8 +34,9 @@ export class Copy2ClipboardButtonDirective implements OnInit {
   @HostListener('click')
   onClick() {
     try {
+      const tagName = this.formatted === '' ? 'textarea' : 'input';
       // Create the input to hold our text.
-      const tmpInputElement = document.createElement('input');
+      const tmpInputElement = document.createElement(tagName);
       tmpInputElement.value = this.getInputElement().value;
       document.body.appendChild(tmpInputElement);
       // Copy text to clipboard.