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

Duplicate #3434

Open
wants to merge 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
.delete_section_icon {@include icon('minus-circle', $icon_delete_colour);}

.download_icon {@include icon('download');}
.duplicate_icon {@include icon('copy');}
.edit_email_icon {@include icon('envelope-o');}
.edit_icon {@include icon('edit', $icon_edit_colour);}
.email_icon {@include icon('envelope-o');}
Expand Down
2 changes: 2 additions & 0 deletions core/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ en:
updated: '%{what} was successfully updated.'
destroyed: '%{what} was successfully removed.'
not_destroyed: '%{what} was not removed.'
duplicated: '%{what} was duplicated.'
duplicate_suffix: ' Copy'
site_bar:
log_out: Log out
switch_to_your_website: Switch to your website
Expand Down
13 changes: 12 additions & 1 deletion core/lib/refinery/crud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def self.crudify_options
end

prepend_before_action :find_#{singular_name},
:only => [:update, :destroy, :edit, :show]
:only => [:update, :destroy, :edit, :show, :duplicate]
prepend_before_action :merge_position_into_params!, :only => :create

def new
Expand All @@ -83,6 +83,17 @@ def create
def edit
# object gets found by find_#{singular_name} function
end

def duplicate
original = @#{singular_name}
@#{singular_name} = original.dup
parndt marked this conversation as resolved.
Show resolved Hide resolved
@#{singular_name}.title << duplicate_suffix
render 'edit'
end

def duplicate_suffix
t('refinery.crudify.duplicate_suffix')
end

def update
if @#{singular_name}.update(#{singular_name}_params)
Expand Down