Skip to content

Commit

Permalink
Add a duplicate action to crud. Create an icon for it too.
Browse files Browse the repository at this point in the history
Add duplicated to the locale texts
Using a translation string to create the title for the new object
changes as suggested
Fix spacing in en.yml
  • Loading branch information
anitagraham committed Mar 25, 2021
1 parent 1b73e0b commit bccc465
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
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
@#{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

0 comments on commit bccc465

Please sign in to comment.