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