Skip to content

Commit

Permalink
add basic implementation of general edit form
Browse files Browse the repository at this point in the history
  • Loading branch information
mejackreed committed Mar 13, 2018
1 parent 0e0032e commit bc80bf2
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/assets/stylesheets/spotlight/_spotlight.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
@import "spotlight/report_a_problem";
@import "spotlight/exhibits_index";
@import "spotlight/collapse_toggle";
@import "spotlight/translations";
@import "spotlight/utilities";



Expand Down
24 changes: 24 additions & 0 deletions app/assets/stylesheets/spotlight/_translations.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.translation-subheading {
border-bottom: 1px solid $navbar-default-border;
margin-bottom: 20px;
}

.form-group.translation-form {
.control-label {
padding-top: $panel-body-padding + $padding-base-vertical;
}
.glyphicon-ok {
color: #80BF77;
padding-top: $panel-body-padding + $padding-base-vertical;
}
}

.panel-translation {
background-color: #f5f5f5;
padding-bottom: 0;

.help-block {
color: #555555;
padding-left: 12px;
}
}
3 changes: 3 additions & 0 deletions app/assets/stylesheets/spotlight/_utilities.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.inline-block {
display: inline-block;
}
3 changes: 2 additions & 1 deletion app/controllers/spotlight/exhibits_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ def exhibit_params
:published,
:tag_list,
contact_emails_attributes: [:id, :email],
languages_attributes: [:id, :public]
languages_attributes: [:id, :public],
translations_attributes: [:id, :locale, :key, :value]
)
end

Expand Down
16 changes: 16 additions & 0 deletions app/controllers/spotlight/translations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Spotlight
##
# Base CRUD controller for translations
class TranslationsController < Spotlight::ApplicationController
before_action :authenticate_user!, :set_language
load_and_authorize_resource :exhibit, class: Spotlight::Exhibit

def index; end

private

def set_language
@language = params[:language] || current_exhibit.available_locales.first
end
end
end
3 changes: 2 additions & 1 deletion app/models/spotlight/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def initialize(user)
Spotlight::Resource,
Spotlight::Page,
Spotlight::Contact,
Spotlight::CustomField
Spotlight::CustomField,
Translation
], exhibit_id: user.exhibit_roles.pluck(:resource_id)

can :manage, Spotlight::Lock, by: user
Expand Down
2 changes: 1 addition & 1 deletion app/models/spotlight/exhibit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Exhibit < ActiveRecord::Base
belongs_to :thumbnail, class_name: 'Spotlight::ExhibitThumbnail', dependent: :destroy, optional: true

accepts_nested_attributes_for :about_pages, :attachments, :contacts, :custom_fields, :feature_pages, :languages,
:main_navigations, :owned_taggings, :resources, :searches, :solr_document_sidecars
:main_navigations, :owned_taggings, :resources, :searches, :solr_document_sidecars, :translations
accepts_nested_attributes_for :blacklight_configuration, :home_page, :filters, update_only: true
accepts_nested_attributes_for :masthead, :thumbnail, update_only: true, reject_if: proc { |attr| attr['iiif_tilesource'].blank? }
accepts_nested_attributes_for :contact_emails, reject_if: proc { |attr| attr['email'].blank? }
Expand Down
5 changes: 5 additions & 0 deletions app/views/spotlight/shared/_curation_sidebar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@
<% if can? :manage, Spotlight::AboutPage.new(exhibit: current_exhibit) %>
<li><%= link_to t(:'spotlight.curation.sidebar.about_pages'), spotlight.exhibit_about_pages_path(current_exhibit), 'data-no-turbolink' => true %></li>
<% end %>
<% if (can? :manage, current_exhibit.translations.first_or_initialize) && current_exhibit.languages.any? %>
<li>
<%= link_to t(:'spotlight.curation.sidebar.translations'), spotlight.exhibit_translations_path(current_exhibit), 'data-no-turbolink' => true %>
</li>
<% end %>
</ul>
73 changes: 73 additions & 0 deletions app/views/spotlight/translations/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<%= render 'spotlight/shared/exhibit_sidebar' %>

<div class='col-md-9 translation-edit-form'>
<%= curation_page_title 'Translations' %>

<div class='text-center'>
<ul class='nav nav-pills inline-block'>
<% current_exhibit.available_locales.each do |language| %>
<li role="presentation" class="<%= 'active' if @language == language %>">
<%= link_to spotlight.exhibit_translations_path(current_exhibit, language: language) do %>
<%= t("locales.#{language.downcase}") %>
<% end %>
</li>
<% end %>
</ul>
</div>

<ul class='nav nav-tabs'>
<li>
<a href='#'>General</a>
</li>
</ul>

<h2 class='translation-subheading'>
Basic Settings
</h2>

<%= bootstrap_form_for current_exhibit, layout: :horizontal do |f| %>
<% translation = Translation.find_or_initialize_by(exhibit: current_exhibit, key: "#{current_exhibit.slug}.title", locale: @language) %>
<%= f.fields_for :translations, translation do |translation_fields| %>
<%= translation_fields.hidden_field :key %>
<%= translation_fields.hidden_field :locale %>
<div class='form-group translation-form'>
<%= translation_fields.label :value, 'Title', class: 'control-label col-sm-2' %>
<div class='col-md-8 panel panel-body panel-translation'>
<%= translation_fields.text_field_without_bootstrap :value, class: 'form-control' %>
<p class="help-block">
<%= current_exhibit.title %>
</p>
</div>
<div class='col-md-2'>
<% if translation.value.present? %>
<span class='glyphicon glyphicon-ok'></span>
<% end %>
</div>
</div>
<% end %>
<% translation = Translation.find_or_initialize_by(exhibit: current_exhibit, key: "#{current_exhibit.slug}.subtitle", locale: @language) %>
<%= f.fields_for :translations, translation do |translation_fields| %>
<%= translation_fields.hidden_field :key %>
<%= translation_fields.hidden_field :locale %>
<div class='form-group translation-form'>
<%= translation_fields.label :value, 'Subtitle', class: 'control-label col-sm-2' %>
<div class='col-md-8 panel panel-body panel-translation'>
<%= translation_fields.text_field_without_bootstrap :value, class: 'form-control' %>
<p class="help-block">
<%= current_exhibit.subtitle %>
</p>
</div>
<div class='col-md-2'>
<% if translation.value.present? %>
<span class='glyphicon glyphicon-ok'></span>
<% end %>
</div>
</div>
<% end %>
<div class="form-actions">
<div class="primary-actions">
<%= f.submit nil, class: 'btn btn-primary' %>
</div>
</div>
<% end %>
</div>
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@
end
end
post 'solr/update' => 'solr#update'
resources :translations, only: [:index] do
end
end

get '/:exhibit_id' => 'home_pages#show', as: :exhibit_root
Expand Down

0 comments on commit bc80bf2

Please sign in to comment.