Class: Hyrax::BatchEditsController

Inherits:
ApplicationController
  • Object
show all
Includes:
Breadcrumbs, Collections::AcceptsBatches, FileSetHelper
Defined in:
app/controllers/hyrax/batch_edits_controller.rb

Instance Method Summary collapse

Methods included from Collections::AcceptsBatches

#batch, #batch=, #check_for_empty_batch?

Methods included from Breadcrumbs

#add_breadcrumb_for_action, #build_breadcrumbs, #default_trail, #trail_from_referer

Methods included from FileSetHelper

#media_display, #media_display_partial, #parent_path

Instance Method Details

#after_destroy_collectionObject



27
28
29
# File 'app/controllers/hyrax/batch_edits_controller.rb', line 27

def after_destroy_collection
  redirect_to_return_controller unless request.xhr?
end

#after_updateObject



20
21
22
23
24
25
# File 'app/controllers/hyrax/batch_edits_controller.rb', line 20

def after_update
  respond_to do |format|
    format.json { head :no_content }
    format.html { redirect_to_return_controller }
  end
end

#check_for_empty!Object



31
32
33
34
35
# File 'app/controllers/hyrax/batch_edits_controller.rb', line 31

def check_for_empty!
  return unless check_for_empty_batch?
  redirect_back fallback_location: hyrax.batch_edits_path
  false
end

#destroy_collectionObject



37
38
39
40
41
42
43
44
# File 'app/controllers/hyrax/batch_edits_controller.rb', line 37

def destroy_collection
  batch.each do |doc_id|
    obj = ActiveFedora::Base.find(doc_id, cast: true)
    obj.destroy
  end
  flash[:notice] = "Batch delete complete"
  after_destroy_collection
end

#editObject



14
15
16
17
18
# File 'app/controllers/hyrax/batch_edits_controller.rb', line 14

def edit
  work = form_class.model_class.new
  work.depositor = current_user.user_key
  @form = form_class.new(work, current_user, batch)
end

#updateObject



53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/hyrax/batch_edits_controller.rb', line 53

def update
  case params["update_type"]
  when "update"
    batch.each do |doc_id|
      update_document(ActiveFedora::Base.find(doc_id))
    end
    flash[:notice] = "Batch update complete"
    after_update
  when "delete_all"
    destroy_batch
  end
end

#update_document(obj) ⇒ Object



46
47
48
49
50
51
# File 'app/controllers/hyrax/batch_edits_controller.rb', line 46

def update_document(obj)
  obj.attributes = work_params
  obj.date_modified = Time.current.ctime
  obj.visibility = params[:visibility]
  obj.save
end