Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/resources/lang/ca/crud.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@
'select_entry' => 'Selecciona un element',
'select_entries' => 'Selecciona elements',
'upload_multiple_files_selected' => 'Files selected. After save, they will show up above.',
'clipboard' => [
'confirmation_message' => 'Element copiat correctament',
'error_message' => 'No s\'ha pogut copiar l\'element',
],

// Table field
'table_cant_add' => 'No es pot afegir una nova :entity',
Expand Down
4 changes: 4 additions & 0 deletions src/resources/lang/en/crud.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@
'select_entry' => 'Select an entry',
'select_entries' => 'Select entries',
'upload_multiple_files_selected' => 'Files selected. After save, they will show up above.',
'clipboard' => [
'confirmation_message' => 'Item copied successfully',
'error_message' => 'Failed to copy item',
],

//Table field
'table_cant_add' => 'Cannot add new :entity',
Expand Down
4 changes: 4 additions & 0 deletions src/resources/lang/es/crud.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@
'new_item' => 'Nuevo elemento',
'select_entry' => 'Selecciona un elemento',
'select_entries' => 'Selecciona elementos',
'clipboard' => [
'confirmation_message' => 'Elemento copiado correctamente',
'error_message' => 'No se pudo copiar el elemento',
],

// Table field
'table_cant_add' => 'No se puede agregar una nueva :entity',
Expand Down
59 changes: 59 additions & 0 deletions src/resources/views/crud/columns/clipboard.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{{-- regular object attribute --}}
@php
$column['value'] = $column['value'] ?? data_get($entry, $column['name']);
$column['escaped'] = $column['escaped'] ?? true;
$column['limit'] = $column['limit'] ?? 32;
$column['prefix'] = $column['prefix'] ?? '';
$column['suffix'] = $column['suffix'] ?? '';
$column['text'] = $column['default'] ?? '-';

if ($column['value'] instanceof \Closure) {
$column['value'] = $column['value']($entry);
}

if (is_array($column['value'])) {
$column['value'] = json_encode($column['value']);
}

if (!empty($column['value'])) {
$column['text'] = $column['prefix'] . Str::limit($column['value'], $column['limit'], '…') . $column['suffix'];
}
@endphp

<span onclick="copyToClipboard('{{ $column['text'] }}')" role="button">
@includeWhen(!empty($column['wrapper']), 'crud::columns.inc.wrapper_start')
@if ($column['escaped'])
{{ $column['text'] }}
@else
{!! $column['text'] !!}
@endif
<i class="las la-copy"></i>

@includeWhen(!empty($column['wrapper']), 'crud::columns.inc.wrapper_end')
</span>

@bassetBlock('backpack/crud/columns/clipboard.js')
<script>
const copyToClipboard = async (text) => {
try {
await navigator.clipboard.writeText(text);
new Noty({
type: "success",
text: `{!! '<strong>' .
trans('backpack::base.success') .
'</strong><br>' .
trans('backpack::crud.clipboard.confirmation_message') !!}`
}).show();
} catch (error) {
console.error("Failed to copy to clipboard:", error);
new Noty({
type: "error",
text: `{!! '<strong>' .
trans('backpack::base.error') .
'</strong><br>' .
trans('backpack::crud.clipboard.error_message') !!}`
}).show();
}
};
</script>
@endBassetBlock