From f5e4c28fc1edefc3514ce18b2a7715d60485c412 Mon Sep 17 00:00:00 2001 From: Kara Diaby Date: Tue, 29 Nov 2022 09:37:58 +0100 Subject: [PATCH] controller --- .../instructeurs/procedures_controller.rb | 5 +++ .../controllers/clipboard_controller.ts | 34 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 app/javascript/controllers/clipboard_controller.ts diff --git a/app/controllers/instructeurs/procedures_controller.rb b/app/controllers/instructeurs/procedures_controller.rb index e6cf1eddc..90fd54944 100644 --- a/app/controllers/instructeurs/procedures_controller.rb +++ b/app/controllers/instructeurs/procedures_controller.rb @@ -244,6 +244,11 @@ module Instructeurs redirect_to instructeur_procedure_path(@procedure) end + def administrateurs + @procedure = procedure + @administrateurs = procedure.administrateurs + end + private def create_bulk_message_mail(dossier_count, dossier_state) diff --git a/app/javascript/controllers/clipboard_controller.ts b/app/javascript/controllers/clipboard_controller.ts new file mode 100644 index 000000000..40597f8f6 --- /dev/null +++ b/app/javascript/controllers/clipboard_controller.ts @@ -0,0 +1,34 @@ +import { Controller } from '@hotwired/stimulus'; + +const SUCCESS_MESSAGE_TIMEOUT = 1000; + +export class ClipboardController extends Controller { + static values = { text: String }; + static targets = ['success']; + + declare readonly textValue: string; + declare readonly successTarget: HTMLElement; + declare readonly hasSuccessTarget: boolean; + + #timer?: ReturnType; + + disconnect(): void { + clearTimeout(this.#timer); + } + + copy() { + navigator.clipboard + .writeText(this.textValue) + .then(() => this.displayCopyConfirmation()); + } + + private displayCopyConfirmation() { + if (this.hasSuccessTarget) { + this.successTarget.classList.remove('hidden'); + clearTimeout(this.#timer); + this.#timer = setTimeout(() => { + this.successTarget.classList.add('hidden'); + }, SUCCESS_MESSAGE_TIMEOUT); + } + } +}