Skip to content
Snippets Groups Projects
Commit e4335879 authored by Arnaud Levy's avatar Arnaud Levy
Browse files

page duplicate

parent 8f0fd88e
No related branches found
No related tags found
No related merge requests found
......@@ -71,6 +71,11 @@ class Admin::Communication::Websites::PagesController < Admin::Communication::We
end
end
def duplicate
redirect_to [:admin, @page.duplicate],
notice: t('admin.successfully_duplicated_html', model: @page.to_s)
end
def destroy
if @page.is_special_page?
redirect_back(fallback_location: admin_communication_website_page_path(@page), alert: t('admin.communication.website.pages.delete_special_page_notice'))
......
......@@ -45,6 +45,13 @@ module Admin::ApplicationHelper
aria-controls=\"preview\">#{ t 'preview.button'}</button>"
end
def duplicate_link(object)
link_to t('admin.duplicate'),
[:duplicate, :admin, object],
method: :post,
class: button_classes
end
def button_classes(additional = '', **options)
classes = "btn btn-primary btn-xs #{additional}"
classes += ' disabled' if options[:disabled]
......@@ -68,13 +75,6 @@ module Admin::ApplicationHelper
form: form.options.dig(:html, :id)
end
def duplicate(object)
link_to t('admin.duplicate'),
[:duplicate, :admin, object],
method: :post,
class: button_classes
end
def prepare_html_for_static(html, university)
text = html.to_s
text = sanitize text
......
......@@ -145,6 +145,18 @@ class Communication::Website::Page < ApplicationRecord
"/#{language.iso_code}" if website.languages.any? && language_id
end
def duplicate
page = self.dup
page.published = false
page.save
blocks.each do |block|
b = block.duplicate
b.about = page
b.save
end
page
end
def to_s
"#{title}"
end
......
......@@ -32,8 +32,10 @@
<td><%= block.template_kind_i18n %></td>
<td><%= render 'admin/application/a11y/status', about: block %></td>
<td class="text-end">
<%= duplicate block %>
<%= edit_link block %>
<div class="btn-group">
<%= duplicate_link block %>
<%= edit_link block %>
</div>
</td>
</tr>
<% end %>
......
......@@ -14,7 +14,7 @@
<%= f.input :title %>
</div>
<div class="col-xxl-3 col-lg-6">
<label class="form-label">&nbsp;</label>
<label class="form-label d-none d-lg-block">&nbsp;</label>
<%= f.input :published %>
</div>
</div>
......
......@@ -28,6 +28,7 @@
<span class="me-3 show-on-hover"><%= t("communication.website.pages.defaults.#{page.kind}.admin_description") %></span>
<% end %>
<div class="btn-group">
<%= duplicate_link page if page.is_regular_page?%>
<%= edit_link page %>
<%= destroy_link page, confirm_message: page.children.any? ? t('please_confirm_with_children') : t('please_confirm') if page.is_regular_page? %>
</div>
......
......@@ -15,6 +15,7 @@ namespace :communication do
get :children
get :static
get :preview
post :duplicate
end
end
resources :categories, controller: 'websites/categories' do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment