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



57
58
59
# File 'app/controllers/concerns/hydra/batch_edit_behavior.rb', line 57

def after_destroy_collection
  redirect_to catalog_index_path
end

#after_updateObject

pulled out to allow a user to override the default redirect



28
29
30
# File 'app/controllers/concerns/hydra/batch_edit_behavior.rb', line 28

def after_update
  redirect_to catalog_index_path
end

#allObject



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

def all 
  self.batch = Hydra::BatchEdit::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



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

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

#destroy_collectionObject



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

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



24
25
# File 'app/controllers/concerns/hydra/batch_edit_behavior.rb', line 24

def edit
end

#indexObject

fetch the documents that match the ids in the folder



15
16
17
# File 'app/controllers/concerns/hydra/batch_edit_behavior.rb', line 15

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

#stateObject



19
20
21
22
# File 'app/controllers/concerns/hydra/batch_edit_behavior.rb', line 19

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

#updateObject



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

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



33
34
35
36
# File 'app/controllers/concerns/hydra/batch_edit_behavior.rb', line 33

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