Class: Alchemy::Admin::PicturesController

Inherits:
BaseController show all
Defined in:
app/controllers/alchemy/admin/pictures_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#leave

Methods included from Modules

included, #module_definition_for, register_module

Methods included from ConfigurationMethods

#configuration, #multi_language?, #multi_site?

Instance Method Details

#createObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/alchemy/admin/pictures_controller.rb', line 27

def create
  @picture = Picture.new(picture_params)
  @picture.name = @picture.humanized_name
  if @picture.save
    set_size_or_default
    if in_overlay?
      set_instance_variables
    end
    message = _t('Picture uploaded succesfully', name: @picture.name)
    render json: {files: [@picture.to_jq_upload], growl_message: message}, status: :created
  else
    message = _t('Picture validation error', name: @picture.name)
    render json: {files: [@picture.to_jq_upload], growl_message: message}, status: :unprocessable_entity
  end
end

#delete_multipleObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/controllers/alchemy/admin/pictures_controller.rb', line 66

def delete_multiple
  if request.delete? && params[:picture_ids].present?
    pictures = Picture.find(params[:picture_ids])
    names = []
    not_deletable = []
    pictures.each do |picture|
      if picture.deletable?
        names << picture.name
        picture.destroy
      else
        not_deletable << picture.name
      end
    end
    if not_deletable.any?
      flash[:warn] = _t("These pictures could not be deleted, because they were in use", :names => not_deletable.to_sentence)
    else
      flash[:notice] = _t("Pictures deleted successfully", :names => names.to_sentence)
    end
  else
    flash[:warn] = _t("Could not delete Pictures")
  end
rescue Exception => e
  flash[:error] = e.message
ensure
  redirect_to_index
end

#destroyObject



93
94
95
96
97
98
99
100
101
# File 'app/controllers/alchemy/admin/pictures_controller.rb', line 93

def destroy
  name = @picture.name
  @picture.destroy
  flash[:notice] = _t("Picture deleted successfully", :name => name)
rescue Exception => e
  flash[:error] = e.message
ensure
  do_redirect_to admin_pictures_path(:per_page => params[:per_page], :page => params[:page], :query => params[:query])
end

#edit_multipleObject



43
44
45
46
# File 'app/controllers/alchemy/admin/pictures_controller.rb', line 43

def edit_multiple
  @pictures = Picture.where(id: params[:picture_ids])
  @tags = @pictures.collect(&:tag_list).flatten.uniq.join(', ')
end

#flushObject



103
104
105
106
# File 'app/controllers/alchemy/admin/pictures_controller.rb', line 103

def flush
  FileUtils.rm_rf Rails.root.join('public', Alchemy::MountPoint.get, 'pictures')
  @notice = _t('Picture cache flushed')
end

#indexObject



11
12
13
14
15
16
17
# File 'app/controllers/alchemy/admin/pictures_controller.rb', line 11

def index
  @size = params[:size].present? ? params[:size] : 'medium'
  @pictures = Picture.find_paginated(params, pictures_per_page_for_size(@size))
  if in_overlay?
    archive_overlay
  end
end

#newObject



19
20
21
22
23
24
25
# File 'app/controllers/alchemy/admin/pictures_controller.rb', line 19

def new
  @picture = Picture.new
  set_size_or_default
  if in_overlay?
    set_instance_variables
  end
end

#updateObject



48
49
50
51
52
53
54
55
# File 'app/controllers/alchemy/admin/pictures_controller.rb', line 48

def update
  if @picture.update_attributes(picture_params)
    flash[:notice] = _t(:picture_updated_successfully, name: @picture.name)
  else
    flash[:error] = _t(:picture_update_failed)
  end
  redirect_to_index
end

#update_multipleObject



57
58
59
60
61
62
63
64
# File 'app/controllers/alchemy/admin/pictures_controller.rb', line 57

def update_multiple
  @pictures = Picture.find(params[:picture_ids])
  @pictures.each do |picture|
    picture.update_name_and_tag_list!(params)
  end
  flash[:notice] = _t("Pictures updated successfully")
  redirect_to_index
end