Skip to content

Commit

Permalink
Add duplicate button to records list toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
marvindurot committed Jul 12, 2023
1 parent 6ca8d2f commit ace66c9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
12 changes: 12 additions & 0 deletions controllers/Records.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,16 @@ public function __construct()

BackendMenu::setContext('Winter.Test', 'test', 'records');
}

/**
* Called before a list record is duplicated.
* @param \Winter\Storm\Database\Model|\Winter\Storm\Halcyon\Model
*/
public function listBeforeReplicate($model, $original)
{
// Change original slug name
$model->slug = $original->slug . '_copy';
// Replicate attachment
$model->featured_image = $original->featured_image->replicate();
}
}
13 changes: 13 additions & 0 deletions controllers/records/_list_toolbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,17 @@ class="btn btn-danger wn-icon-trash-o"
data-stripe-load-indicator>
<?= e(trans('backend::lang.list.delete_selected')); ?>
</button>
<button
class="btn btn-default wn-icon-clipboard"
disabled="disabled"
onclick="$(this).data('request-data', { checked: $('.control-list').listWidget('getChecked') })"
data-request="onReplicate"
data-request-confirm="<?= e(trans('backend::lang.list.replicate_selected_confirm')); ?>"
data-trigger-action="enable"
data-trigger=".control-list input[type=checkbox]"
data-trigger-condition="checked"
data-request-success="$(this).prop('disabled', 'disabled')"
data-stripe-load-indicator>
<?= e(trans('backend::lang.list.replicate_selected')); ?>
</button>
</div>
5 changes: 5 additions & 0 deletions controllers/records/config_list.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ showSorting: true
# column: created_at
# direction: desc

replication:
enabled: true
allowed: [name, status]
ignored: []

# Display checkboxes next to each record
showCheckboxes: true

Expand Down

0 comments on commit ace66c9

Please sign in to comment.