Class: Gluttonberg::Admin::Content::GalleriesController

Inherits:
BaseController
  • Object
show all
Includes:
ActionView::Helpers::TextHelper
Defined in:
app/controllers/gluttonberg/admin/content/galleries_controller.rb

Instance Method Summary collapse

Instance Method Details

#add_imageObject



77
78
79
80
81
82
83
84
# File 'app/controllers/gluttonberg/admin/content/galleries_controller.rb', line 77

def add_image
  @gallery =Gallery.find(params[:id])
  max_position = @gallery.gallery_images.length
  @gallery_item = @gallery.gallery_images.create(:asset_id => params[:asset_id] , :position => (max_position )  )
  @gallery_images = @gallery.gallery_images.order("position ASC")
  Gluttonberg::Feed.log(current_user,@gallery, @gallery.title , "added image '#{@gallery_item.image.name}'")
  render :layout => false
end

#createObject



25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/gluttonberg/admin/content/galleries_controller.rb', line 25

def create
  @gallery = Gallery.new(params[:gluttonberg_gallery])
  @gallery.user_id = current_user.id if @gallery.user_id.blank?
  if @gallery.save
    save_collection_images
    flash[:notice] = "The gallery was successfully created."
    redirect_to edit_admin_gallery_path(@gallery)
  else
    render :edit
  end
end

#deleteObject



51
52
53
54
55
56
57
58
# File 'app/controllers/gluttonberg/admin/content/galleries_controller.rb', line 51

def delete
  display_delete_confirmation(
    :title      => "Delete gallery '#{@gallery.name}'?",
    :url        => admin_gallery_path(@gallery),
    :return_url => admin_galleries_path,
    :warning    => ""
  )
end

#destroyObject



60
61
62
63
64
65
66
67
68
# File 'app/controllers/gluttonberg/admin/content/galleries_controller.rb', line 60

def destroy
  if @gallery.delete
    flash[:notice] = "The gallery was successfully deleted."
    redirect_to admin_galleries_path
  else
    flash[:error] = "There was an error deleting the gallery."
    redirect_to admin_galleries_path
  end
end

#editObject



37
38
# File 'app/controllers/gluttonberg/admin/content/galleries_controller.rb', line 37

def edit
end

#indexObject



17
18
19
# File 'app/controllers/gluttonberg/admin/content/galleries_controller.rb', line 17

def index
  @galleries = Gallery.paginate(:per_page => Gluttonberg::Setting.get_setting("number_of_per_page_items"), :page => params[:page])
end

#newObject



21
22
23
# File 'app/controllers/gluttonberg/admin/content/galleries_controller.rb', line 21

def new
  @gallery = Gallery.new
end

#remove_imageObject



70
71
72
73
74
75
# File 'app/controllers/gluttonberg/admin/content/galleries_controller.rb', line 70

def remove_image
  item =GalleryImage.find(params[:id])
  Gluttonberg::Feed.log(current_user,item.gallery, item.gallery.title , "removed image '#{item.image.name}'")
  item.delete
  render :text => "{success:true}"
end

#updateObject



40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/gluttonberg/admin/content/galleries_controller.rb', line 40

def update
  if @gallery.update_attributes(params[:gluttonberg_gallery])
    save_collection_images
    flash[:notice] = "The gallery was successfully updated."
    redirect_to edit_admin_gallery_path(@gallery)
  else
    flash[:error] = "Sorry, The gallery could not be updated."
    render :edit
  end
end