Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add duplicate button to records list toolbar #17

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
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: []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case it would be more useful to set the ignored property to just status as there are a lot of test fields in the Record model.


# Display checkboxes next to each record
showCheckboxes: true

Expand Down