Files
MokoSuiteClient/src/packages/plg_system_mokowaas/Field/CopyableTokenField.php
T
Jonathan Miller 33a3184dfc chore: bump version 02.30.00 → 02.31.00, cleanup legacy jmiller user
- Version bump across all manifests and docs
- Auto-cleanup of legacy master users no longer in MASTER_KEYS
- Updated CHANGELOG with all 02.31.00 changes

Authored-by: Moko Consulting
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-31 12:40:05 -05:00

64 lines
1.9 KiB
PHP

<?php
/**
* @package MokoWaaS
* @subpackage plg_system_mokowaas
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
* @license GNU General Public License version 3 or later; see LICENSE
*
* FILE INFORMATION
* DEFGROUP: Joomla.Plugin
* INGROUP: MokoWaaS
* VERSION: 02.31.00
* PATH: /src/Field/CopyableTokenField.php
* BRIEF: Read-only token field with a copy-to-clipboard button
*/
namespace Moko\Plugin\System\MokoWaaS\Field;
defined('_JEXEC') or die;
use Joomla\CMS\Form\FormField;
/**
* Renders a read-only text input with a "Copy" button, similar to
* Joomla's API token field in the user profile.
*
* @since 02.25.00
*/
class CopyableTokenField extends FormField
{
protected $type = 'CopyableToken';
protected function getInput()
{
$value = htmlspecialchars($this->value ?? '', ENT_QUOTES, 'UTF-8');
$id = $this->id;
if (empty($this->value))
{
return '<div class="alert alert-warning mb-0 py-2">Token will be generated automatically on first save.</div>';
}
return <<<HTML
<div class="input-group">
<input type="text" id="{$id}" name="{$this->name}" value="{$value}"
class="form-control" readonly="readonly" style="font-family:monospace;font-size:0.85em" />
<button type="button" class="btn btn-outline-secondary" onclick="
var inp = document.getElementById('{$id}');
if (navigator.clipboard) {
navigator.clipboard.writeText(inp.value).then(function() {
var btn = inp.nextElementSibling;
var orig = btn.innerHTML;
btn.innerHTML = '<span class=&quot;icon-check&quot; aria-hidden=&quot;true&quot;></span> Copied';
btn.classList.replace('btn-outline-secondary','btn-success');
setTimeout(function(){ btn.innerHTML = orig; btn.classList.replace('btn-success','btn-outline-secondary'); }, 2000);
});
} else {
inp.select(); document.execCommand('copy');
}
"><span class="icon-copy" aria-hidden="true"></span> Copy</button>
</div>
HTML;
}
}