Skip to content

Commit

Permalink
Merge pull request #221 from pulibrary/save_and_create_another
Browse files Browse the repository at this point in the history
Add Save and Create Another.
  • Loading branch information
jrgriffiniii committed Sep 20, 2017
2 parents 915da90 + 675b4d4 commit 518ad1a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/assets/javascripts/form/save_work_control.es6
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ export default class SaveWorkControl {
*
*/
preventSubmitIfAlreadyInProgress() {
let master = this
this.saveButton.on('click', function(evt) {
if (master.isValid()) {
let input = $("<input type='hidden' />").attr("name", $(this)[0].name).attr("value", $(this)[0].value);
$(this).closest('form').append(input);
}
})
this.form.on('submit', (evt) => {
if (this.isValid())
this.saveButton.prop("disabled", true);
Expand Down
11 changes: 11 additions & 0 deletions app/controllers/ephemera_folders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,21 @@ class EphemeraFoldersController < ApplicationController
)
before_action :load_collections, only: [:new, :edit]

def after_create_success(obj, _change_set)
if params[:commit] == "Save and Create Another"
redirect_to parent_new_ephemera_box_path(parent_id: resource_params[:append_id], create_another: obj.id.to_s)
else
super
end
end

def new_resource
if params[:template_id]
template = find_resource(params[:template_id])
template.nested_properties.first
elsif params[:create_another]
resource = find_resource(params[:create_another])
resource.new(id: nil, created_at: nil, updated_at: nil)
else
resource_class.new
end
Expand Down
13 changes: 13 additions & 0 deletions spec/controllers/ephemera_folders_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@

get :new, params: { template_id: template.id.to_s }

expect(response.body).to have_field "Language", with: "Test"
end
it "can be passed a previously created record to pre-generate fields" do
record = FactoryGirl.create_for_repository(:ephemera_folder, language: "Test")

get :new, params: { create_another: record.id.to_s }

expect(response.body).to have_field "Language", with: "Test"
end
end
Expand Down Expand Up @@ -135,6 +142,12 @@
id = response.location.gsub("http://test.host/catalog/", "").gsub("%2F", "/").gsub(/^id-/, "")
expect(find_resource(id).folder_number).to contain_exactly "one"
end
it "can save and create another" do
box = FactoryGirl.create_for_repository(:ephemera_box)
post :create, params: { commit: "Save and Create Another", ephemera_folder: valid_params.merge(append_id: box.id) }
expect(response).to be_redirect
expect(response.location).to start_with "http://test.host/concern/ephemera_boxes/#{box.id}/ephemera_folders/new?create_another"
end
context "when something bad goes wrong" do
it "doesn't persist anything at all when it's solr erroring" do
allow(Valkyrie::MetadataAdapter.find(:index_solr)).to receive(:persister).and_return(
Expand Down
3 changes: 3 additions & 0 deletions valhalla/app/views/valhalla/base/_form_progress.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@
class: 'btn btn-default' %>
<%= f.submit class: 'btn btn-primary' %>
<% if f.object.resource.is_a?(EphemeraFolder) && params[:controller] == "ephemera_folders" %>
<%= f.submit "Save and Create Another", class: 'btn btn-primary' %>
<% end %>
</div>
</aside>

0 comments on commit 518ad1a

Please sign in to comment.