Module: Hydra::BatchEditBehavior

Extended by:
ActiveSupport::Concern
Included in:
BatchEditsController
Defined in:
app/controllers/concerns/hydra/batch_edit_behavior.rb

Instance Method Summary collapse

Instance Method Details

#after_destroy_collectionObject

pulled out to allow a user to override the default redirect


55
56
57
# File 'app/controllers/concerns/hydra/batch_edit_behavior.rb', line 55

def after_destroy_collection
  redirect_to catalog_index_path
end

#after_updateObject

pulled out to allow a user to override the default redirect


26
27
28
# File 'app/controllers/concerns/hydra/batch_edit_behavior.rb', line 26

def after_update
  redirect_to catalog_index_path
end

#allObject


46
47
48
49
50
51
52
# File 'app/controllers/concerns/hydra/batch_edit_behavior.rb', line 46

def all 
  self.batch = CurationConcerns::Collections::SearchService.new(session, current_user.user_key).last_search_documents.map(&:id)
  respond_to do |format|
    format.html { redirect_to edit_batch_edits_path }
    format.js { render :json => batch }
  end
end

#check_for_empty!Object


68
69
70
71
72
73
# File 'app/controllers/concerns/hydra/batch_edit_behavior.rb', line 68

def check_for_empty!
   if check_for_empty_batch?
     redirect_to :back
     return false
  end
end

#destroy_collectionObject


59
60
61
62
63
64
65
66
# File 'app/controllers/concerns/hydra/batch_edit_behavior.rb', line 59

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


22
23
# File 'app/controllers/concerns/hydra/batch_edit_behavior.rb', line 22

def edit
end

#indexObject

fetch the documents that match the ids in the folder


13
14
15
# File 'app/controllers/concerns/hydra/batch_edit_behavior.rb', line 13

def index
  @response, @documents = get_solr_response_for_field_values("id", batch)
end

#stateObject


17
18
19
20
# File 'app/controllers/concerns/hydra/batch_edit_behavior.rb', line 17

def state
  session[:batch_edit_state] = params[:state]
  render :json => {"OK" => "OK"}
end

#updateObject


36
37
38
39
40
41
42
43
44
# File 'app/controllers/concerns/hydra/batch_edit_behavior.rb', line 36

def update
  batch.each do |doc_id|
    obj = ActiveFedora::Base.find(doc_id, :cast=>true)
    update_document(obj)
    obj.save
  end
  flash[:notice] = "Batch update complete"
  after_update 
end

#update_document(obj) ⇒ Object

called before the save of the document on update to do addition processes on the document beyond update_attributes


31
32
33
34
# File 'app/controllers/concerns/hydra/batch_edit_behavior.rb', line 31

def update_document(obj)
    type = obj.class.to_s.underscore.to_sym
    obj.update_attributes(params[type].reject{|k, v| v.blank?})
end