Skip to content
This repository has been archived by the owner on May 14, 2022. It is now read-only.

Commit

Permalink
Adding button to save and create another EphemeraFolder with pre-fill…
Browse files Browse the repository at this point in the history
…ed values
  • Loading branch information
escowles committed Jun 27, 2017
1 parent dcbf1ed commit 49b7da2
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
19 changes: 19 additions & 0 deletions app/controllers/hyrax/ephemera_folders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,24 @@ class EphemeraFoldersController < Hyrax::HyraxController
self.curation_concern_type = EphemeraFolder
self.show_presenter = EphemeraFolderPresenter
skip_load_and_authorize_resource only: ::SearchBuilder.show_actions

def after_create_response
params[:save_and_create_another] ? create_another : super
end

def after_update_response
params[:save_and_create_another] ? create_another : super
end

def create_another
redirect_to polymorphic_path([main_app, :new, :hyrax, :parent, :ephemera_folder],
parent_id: params[:parent_id], create_another: curation_concern.id)
end

def new
curation_concern.attributes = ActiveFedora::Base.find(params[:create_another]).attributes
.except("id", "barcode", "folder_number", "state") if params[:create_another]
super
end
end
end
38 changes: 38 additions & 0 deletions app/views/hyrax/ephemera_folders/_form_progress.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<aside id="form-progress" class="form-progress panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><%= t("hyrax.works.progress.header") %></h3>
</div>
<div class="list-group">
<div class="list-group-item">
<fieldset>
<legend class="legend-save-work"><%= t('.requirements') %></legend>
<ul class="requirements">
<li class="incomplete" id="required-metadata"><%= t('.required_descriptions') %></li>
<% if Hyrax.config.work_requires_files? %>
<li class="incomplete" id="required-files"><%= t('.required_files') %></li>
<% end %>
</ul>
</fieldset>
</div>

<div class="set-access-controls list-group-item">
<%= render 'form_visibility_component', f: f %>
</div>
<% unless current_user.can_make_deposits_for.empty? %>
<div class="list-group-item">
<%= f.input :on_behalf_of, collection: current_user.can_make_deposits_for.map(&:user_key), prompt: "Yourself" %>
</div>
<% end %>
</div>
<div class="panel-footer text-center">
<br>
<% if params[:action] == 'new' %>
<%= link_to t(:'helpers.action.cancel'), main_app.hyrax_ephemera_box_path(params[:parent_id]), class: 'btn btn-default' %>
<% else %>
<%= link_to t(:'helpers.action.cancel'), polymorphic_path([main_app, curation_concern]), class: 'btn btn-default' %>
<% end %>
<%= f.input Hyrax::Actors::OptimisticLockValidator.version_field, as: :hidden if f.object.persisted? %>
<%= f.submit class: 'btn btn-primary', id: "with_files_submit", name: "save_with_files" %>
<%= f.submit "Save and Create Another", class: 'btn btn-primary', id: "save_and_create_another", name: "save_and_create_another" %>
</div>
</aside>
20 changes: 20 additions & 0 deletions spec/features/edit_ephemera_folder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'rails_helper'

RSpec.feature 'EphemeraFoldersController', type: :feature, admin_set: true do
let(:user) { FactoryGirl.create(:ephemera_editor) }
let(:box) { FactoryGirl.create(:ephemera_box) }
let(:folder) { FactoryGirl.create(:ephemera_folder, language: ['Spanish']) }

before(:each) do
sign_in user
end

scenario 'creating a new folder and then creating another' do
puts "/concern/parent/#{box.id}/ephemera_folders/new?create_another=#{folder.id}"
visit "/concern/parent/#{box.id}/ephemera_folders/new?create_another=#{folder.id}"
expect(find_field('Barcode').value).to eq(nil)
expect(find_field('Folder number').value).to eq(nil)
expect(find_field('Title').value).to have_content('Example Folder')
expect(find_field('Language').value).to have_content('Spanish')
end
end

0 comments on commit 49b7da2

Please sign in to comment.