Custom content blocks for top_links and footer
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
class Admin::SiteCustomization::ContentBlocksController < Admin::SiteCustomization::BaseController
|
||||
load_and_authorize_resource :content_block, class: "SiteCustomization::ContentBlock"
|
||||
|
||||
def index
|
||||
@content_blocks = SiteCustomization::ContentBlock.order(:name, :locale)
|
||||
end
|
||||
|
||||
def create
|
||||
if @content_block.save
|
||||
redirect_to admin_site_customization_content_blocks_path, notice: t('admin.site_customization.content_blocks.create.notice')
|
||||
else
|
||||
flash.now[:error] = t('admin.site_customization.content_blocks.create.error')
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if @content_block.update(content_block_params)
|
||||
redirect_to admin_site_customization_content_blocks_path, notice: t('admin.site_customization.content_blocks.update.notice')
|
||||
else
|
||||
flash.now[:error] = t('admin.site_customization.content_blocks.update.error')
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@content_block.destroy
|
||||
redirect_to admin_site_customization_content_blocks_path, notice: t('admin.site_customization.content_blocks.destroy.notice')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def content_block_params
|
||||
params.require(:site_customization_content_block).permit(
|
||||
:name,
|
||||
:locale,
|
||||
:body
|
||||
)
|
||||
end
|
||||
end
|
||||
@@ -51,4 +51,8 @@ module ApplicationHelper
|
||||
def image_path_for(filename)
|
||||
SiteCustomization::Image.image_path_for(filename) || filename
|
||||
end
|
||||
|
||||
def content_block(name, locale)
|
||||
SiteCustomization::ContentBlock.block_for(name, locale)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -54,6 +54,7 @@ module Abilities
|
||||
|
||||
can :manage, SiteCustomization::Page
|
||||
can :manage, SiteCustomization::Image
|
||||
can :manage, SiteCustomization::ContentBlock
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
11
app/models/site_customization/content_block.rb
Normal file
11
app/models/site_customization/content_block.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
class SiteCustomization::ContentBlock < ActiveRecord::Base
|
||||
VALID_BLOCKS = %w(top_links footer)
|
||||
|
||||
validates :locale, presence: true, inclusion: { in: I18n.available_locales.map(&:to_s) }
|
||||
validates :name, presence: true, uniqueness: { scope: :locale }, inclusion: { in: VALID_BLOCKS }
|
||||
|
||||
def self.block_for(name, locale)
|
||||
locale ||= I18n.default_locale
|
||||
find_by(name: name, locale: locale).try(:body)
|
||||
end
|
||||
end
|
||||
@@ -134,5 +134,11 @@
|
||||
<span class="icon-settings"></span><%= t("admin.menu.site_customization.images") %>
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
<li <%= "class=active" if controller_name == "content_blocks" %>>
|
||||
<%= link_to admin_site_customization_content_blocks_path do %>
|
||||
<span class="icon-settings"></span><%= t("admin.menu.site_customization.content_blocks") %>
|
||||
<% end %>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<%= form_for [:admin, @content_block], html: {class: "edit_page", data: {watch_changes: true}} do |f| %>
|
||||
|
||||
<% if @content_block.errors.any? %>
|
||||
|
||||
<div id="error_explanation" data-alert class="callout alert" data-closable>
|
||||
<button class="close-button" aria-label="<%= t("application.close") %>" type="button" data-close>
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
|
||||
<strong>
|
||||
<%= @content_block.errors.count %>
|
||||
<%= t("admin.site_customization.content_blocks.errors.form.error", count: @content_block.errors.count) %>
|
||||
</strong>
|
||||
</div>
|
||||
|
||||
<% end %>
|
||||
|
||||
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= f.label :name %>
|
||||
<%= f.select :name, SiteCustomization::ContentBlock::VALID_BLOCKS, label: false %>
|
||||
</div>
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= f.label :locale %>
|
||||
<%= f.select :locale, I18n.available_locales, label: false %>
|
||||
</div>
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= f.label :body %>
|
||||
<%= f.text_area :body, label: false, rows: 10 %>
|
||||
<%= f.submit class: "button success" %>
|
||||
</div>
|
||||
|
||||
<% end %>
|
||||
@@ -0,0 +1,15 @@
|
||||
<% provide :title do %>
|
||||
Admin - <%= t("admin.menu.site_customization.content_blocks") %> - <%= @content_block.name %> (<%= @content_block.locale %>)
|
||||
<% end %>
|
||||
|
||||
<%= link_to admin_site_customization_content_blocks_path, class: "back" do %>
|
||||
<span class="icon-angle-left"></span>
|
||||
<%= t("admin.site_customization.content_blocks.edit.back") %>
|
||||
<% end %>
|
||||
|
||||
<%= button_to t("admin.site_customization.content_blocks.index.delete"), admin_site_customization_content_block_path(@content_block), method: :delete, class: "button hollow alert float-right margin-right" %>
|
||||
|
||||
<div class="row margin-top">
|
||||
<h2><%= t("admin.site_customization.content_blocks.edit.title") %></h2>
|
||||
<%= render 'form' %>
|
||||
</div>
|
||||
@@ -0,0 +1,29 @@
|
||||
<% provide :title do %>
|
||||
Admin - <%= t("admin.menu.site_customization.content_blocks") %>
|
||||
<% end %>
|
||||
|
||||
<%= link_to t("admin.site_customization.content_blocks.index.create"), new_admin_site_customization_content_block_path, class: "button float-right margin-right" %>
|
||||
<h2 class="inline-block"><%= t("admin.site_customization.content_blocks.index.title") %></h2>
|
||||
|
||||
<table class="cms_page_list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= t("admin.site_customization.content_blocks.content_block.name") %></th>
|
||||
<th><%= t("admin.site_customization.content_blocks.content_block.body") %></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @content_blocks.each do |content_block| %>
|
||||
<tr id="<%= dom_id(content_block) %>">
|
||||
<td><%= link_to "#{content_block.name} (#{content_block.locale})", edit_admin_site_customization_content_block_path(content_block) %></td>
|
||||
<td><%= content_block.body %></td>
|
||||
<td>
|
||||
<%= button_to t("admin.site_customization.content_blocks.index.delete"),
|
||||
admin_site_customization_content_block_path(content_block),
|
||||
method: :delete, class: "button hollow alert" %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -0,0 +1,14 @@
|
||||
<% provide :title do %>
|
||||
Admin - <%= t("admin.menu.site_customization.content_blocks") %> - <%= t("admin.site_customization.content_blocks.new.title") %>
|
||||
<% end %>
|
||||
|
||||
<%= link_to admin_site_customization_content_blocks_path, class: "back" do %>
|
||||
<span class="icon-angle-left"></span>
|
||||
<%= t("admin.site_customization.content_blocks.new.back") %>
|
||||
<% end %>
|
||||
|
||||
<div class="row margin-top">
|
||||
<h2><%= t("admin.site_customization.content_blocks.new.title") %></h2>
|
||||
<%= render 'form' %>
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<footer>
|
||||
<div class="row">
|
||||
<div class="row">
|
||||
<div class="small-12 large-4 column">
|
||||
<h1 class="logo">
|
||||
<%= link_to t("layouts.header.open_gov", open: "#{t('layouts.header.open')}").html_safe %>
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
<div class="small-12 medium-4 column">
|
||||
<h2>
|
||||
<%= link_to t("layouts.footer.transparency_title"), t("layouts.footer.transparency_url") %>
|
||||
<%= link_to t("layouts.footer.transparency_title"), setting['transparency_url'].presence || t("layouts.footer.transparency_url") %>
|
||||
</h2>
|
||||
<p><%= t("layouts.footer.transparency_text") %></p>
|
||||
</div>
|
||||
@@ -96,4 +96,6 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= raw content_block("footer", I18n.locale) %>
|
||||
</footer>
|
||||
|
||||
@@ -1,21 +1,25 @@
|
||||
<ul class="no-bullet external-links">
|
||||
<li>
|
||||
<%= link_to t("layouts.header.external_link_transparency"),
|
||||
t("layouts.header.external_link_transparency_url"),
|
||||
setting['transparency_url'].presence || t("layouts.header.external_link_transparency_url"),
|
||||
target: "_blank",
|
||||
title: t('shared.target_blank_html') %>
|
||||
</li>
|
||||
<li>
|
||||
<%= link_to t("layouts.header.external_link_opendata"),
|
||||
t("layouts.header.external_link_opendata_url"),
|
||||
setting['opendata_url'].presence || t("layouts.header.external_link_opendata_url"),
|
||||
target: "_blank",
|
||||
title: t('shared.target_blank_html') %>
|
||||
</li>
|
||||
|
||||
<% if setting['blog_url'] %>
|
||||
<li>
|
||||
<%= link_to setting['blog_url'], title: t('shared.target_blank_html'), target: "_blank" do %>
|
||||
<%= t("layouts.header.external_link_blog") %>
|
||||
<% end %>
|
||||
<%= link_to t("layouts.header.external_link_blog"),
|
||||
setting['blog_url'],
|
||||
target: "_blank",
|
||||
title: t('shared.target_blank_html') %>
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
<%= raw content_block("top_links", I18n.locale) %>
|
||||
</ul>
|
||||
|
||||
Reference in New Issue
Block a user