[4] | 1 | class GalleriesController < ApplicationController |
---|
| 2 | #before_filter :login_required, :only => [:new, :edit, :create, :update, :destroy] |
---|
| 3 | layout "main" |
---|
| 4 | |
---|
| 5 | def index |
---|
| 6 | @galleries = Gallery.find(:all) |
---|
| 7 | |
---|
| 8 | respond_to do |format| |
---|
| 9 | format.html # index.html.erb |
---|
| 10 | format.xml { render :xml => @galleries } |
---|
| 11 | end |
---|
| 12 | end |
---|
| 13 | |
---|
| 14 | # GET /galleries/1 |
---|
| 15 | # GET /galleries/1.xml |
---|
| 16 | def show |
---|
| 17 | @gallery = Gallery.find(params[:id]) |
---|
| 18 | |
---|
| 19 | respond_to do |format| |
---|
| 20 | format.html # show.html.erb |
---|
| 21 | format.xml { render :xml => @gallery } |
---|
| 22 | end |
---|
| 23 | end |
---|
| 24 | |
---|
| 25 | # GET /galleries/new |
---|
| 26 | # GET /galleries/new.xml |
---|
| 27 | def new |
---|
| 28 | @gallery = Gallery.new |
---|
| 29 | |
---|
| 30 | respond_to do |format| |
---|
| 31 | format.html # new.html.erb |
---|
| 32 | format.xml { render :xml => @gallery } |
---|
| 33 | end |
---|
| 34 | end |
---|
| 35 | |
---|
| 36 | # GET /galleries/1/edit |
---|
| 37 | def edit |
---|
| 38 | @gallery = Gallery.find(params[:id]) |
---|
| 39 | end |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | # POST /galleries |
---|
| 43 | # POST /galleries.xml |
---|
| 44 | def create |
---|
| 45 | @gallery = Gallery.new(params[:gallery]) |
---|
| 46 | |
---|
| 47 | respond_to do |format| |
---|
| 48 | if @gallery.save |
---|
| 49 | createFile(@gallery.id) |
---|
| 50 | createMedia(@gallery.id) |
---|
| 51 | |
---|
| 52 | flash[:notice] = 'Gallery was successfully created.' |
---|
| 53 | format.html { redirect_to(@gallery) } |
---|
| 54 | format.xml { render :xml => @gallery, :status => :created, :location => @gallery } |
---|
| 55 | else |
---|
| 56 | format.html { render :action => "new" } |
---|
| 57 | format.xml { render :xml => @gallery.errors, :status => :unprocessable_entity } |
---|
| 58 | end |
---|
| 59 | end |
---|
| 60 | end |
---|
| 61 | |
---|
| 62 | # PUT /galleries/1 |
---|
| 63 | # PUT /galleries/1.xml |
---|
| 64 | def update |
---|
| 65 | @gallery = Gallery.find(params[:id]) |
---|
| 66 | |
---|
| 67 | respond_to do |format| |
---|
| 68 | if @gallery.update_attributes(params[:gallery]) |
---|
| 69 | |
---|
| 70 | createFile(params[:id]) |
---|
| 71 | createMedia(params[:id]) |
---|
| 72 | |
---|
| 73 | flash[:notice] = 'Gallery was successfully updated.' |
---|
| 74 | format.html { redirect_to(@gallery) } |
---|
| 75 | format.xml { head :ok } |
---|
| 76 | else |
---|
| 77 | format.html { render :action => "edit" } |
---|
| 78 | format.xml { render :xml => @gallery.errors, :status => :unprocessable_entity } |
---|
| 79 | end |
---|
| 80 | end |
---|
| 81 | end |
---|
| 82 | |
---|
| 83 | def createMedia |
---|
| 84 | params[:gallery_media].each do |media| |
---|
| 85 | GalleryMedia.create(:medianame => media[1], :gallery_id => params[:id] ) if !media[1].blank? |
---|
| 86 | end |
---|
| 87 | end |
---|
| 88 | |
---|
| 89 | def createFile |
---|
| 90 | params[:gallery_files].each do |file| |
---|
| 91 | GalleryFiles.create(:filename => file[1], :gallery_id => params[:id] ) if !file[1].blank? |
---|
| 92 | end |
---|
| 93 | end |
---|
| 94 | |
---|
| 95 | #Used to delete an uploaded file in a Gallery |
---|
| 96 | #Destroys the actual file from the hard disk using file_column |
---|
| 97 | #Destroys database link |
---|
| 98 | #Requires: |
---|
| 99 | # params: |
---|
| 100 | # :id -> id of model that contains the file |
---|
| 101 | # :file_id -> id of file to be deleted |
---|
| 102 | def destroy_file |
---|
| 103 | |
---|
| 104 | if params[:type] == "File" |
---|
| 105 | @file = GalleryFiles.find(params[:file_id]) |
---|
| 106 | elsif params[:type] == "Media" |
---|
| 107 | @file = GalleryMedia.find(params[:file_id]) |
---|
| 108 | end |
---|
| 109 | @file.destroy |
---|
| 110 | |
---|
| 111 | respond_to do |format| |
---|
| 112 | format.html { redirect_to(edit_setup_path(params[:id])) } |
---|
| 113 | format.js { |
---|
| 114 | render :update do |page| |
---|
| 115 | if params[:type] == "File" |
---|
| 116 | page.visual_effect :blind_up, "File_#{params[:file_id].to_s}" |
---|
| 117 | elsif params[:type] == "Media" |
---|
| 118 | page.visual_effect :blind_up, "Media_#{params[:file_id].to_s}" |
---|
| 119 | page.visual_effect :blind_up, "Media_Attributes_#{params[:file_id].to_s}" |
---|
| 120 | end |
---|
| 121 | end |
---|
| 122 | } |
---|
| 123 | end |
---|
| 124 | end |
---|
| 125 | |
---|
| 126 | # DELETE /galleries/1 |
---|
| 127 | # DELETE /galleries/1.xml |
---|
| 128 | def destroy |
---|
| 129 | @gallery = Gallery.find(params[:id]) |
---|
| 130 | @gallery.destroy |
---|
| 131 | |
---|
| 132 | respond_to do |format| |
---|
| 133 | format.html { redirect_to(galleries_url) } |
---|
| 134 | format.xml { head :ok } |
---|
| 135 | end |
---|
| 136 | end |
---|
| 137 | end |
---|