Module: Sufia::BatchEditsControllerBehavior

Extended by:
ActiveSupport::Concern
Included in:
BatchEditsController
Defined in:
lib/sufia/batch_edits_controller_behavior.rb

Instance Method Summary collapse

Instance Method Details

#after_updateObject



42
43
44
# File 'lib/sufia/batch_edits_controller_behavior.rb', line 42

def after_update
  redirect_to sufia.dashboard_index_path unless request.xhr?
end

#editObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/sufia/batch_edits_controller_behavior.rb', line 9

def edit
   super
   @generic_file = ::GenericFile.new
   @generic_file.depositor = current_user.user_key
   @terms = @generic_file.terms_for_editing - [:title, :format, :resource_type]

   # do we want to show the original values for anything...
   @show_file = ::GenericFile.new
   @show_file.depositor = current_user.user_key
   h  = {}
   @names = []
   permissions = []

   # For each of the files in the batch, set the attributes to be the concatination of all the attributes
   batch.each do |doc_id|
      gf = ::GenericFile.load_instance_from_solr(doc_id)
      gf.terms_for_editing.each do |key|
        h[key] ||= []
        h[key] = (h[key] + gf.send(key)).uniq
      end
      @names << gf.to_s
      permissions = (permissions + gf.permissions).uniq
   end

   initialize_fields(h, @show_file)

   # map the permissions to parameter like input so that the assign will work
   # todo sort the access level some how...
   perm_param ={'user'=>{},'group'=>{"public"=>"1"}}
   permissions.each{ |perm| perm_param[perm[:type]][perm[:name]] = perm[:access]}
   @show_file.permissions = HashWithIndifferentAccess.new(perm_param)
end

#updateObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/sufia/batch_edits_controller_behavior.rb', line 52

def update
  # keep the batch around if we are doing ajax calls
  batch_sav = batch.dup if request.xhr?
  catalog_index_path = sufia.dashboard_index_path
  type = params["update_type"]
  if type == "update"
    super
  elsif type == "delete_all"
    batch.each do |doc_id|
      gf = ::GenericFile.find(doc_id)
      gf.destroy
    end
    after_update
  end

  # reset the batch around if we are doing ajax calls
  if request.xhr?
    self.batch = batch_sav.dup
    @key = params["key"]
    if @key != "permissions"
      @vals = params["generic_file"][@key]
    else
      @vals = [""]
    end
    render :update_edit
  end
end

#update_document(obj) ⇒ Object



46
47
48
49
50
# File 'lib/sufia/batch_edits_controller_behavior.rb', line 46

def update_document(obj)
  super
  obj.date_modified = Time.now.ctime
  obj.set_visibility(params[:visibility])
end