1 | class GalleryController < ApplicationController |
---|
2 | #before_filter :login_required |
---|
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 | def new |
---|
15 | @gallery = Gallery.new |
---|
16 | |
---|
17 | respond_to do |format| |
---|
18 | format.html # new.html.erb |
---|
19 | format.xml { render :xml => @galleries } |
---|
20 | end |
---|
21 | end |
---|
22 | |
---|
23 | def edit |
---|
24 | |
---|
25 | @gallery = Gallery.find(params[:id]) |
---|
26 | |
---|
27 | respond_to do |format| |
---|
28 | format.html # new.html.erb |
---|
29 | format.xml { render :xml => @galleries } |
---|
30 | end |
---|
31 | end |
---|
32 | |
---|
33 | def create |
---|
34 | |
---|
35 | @gallery = Gallery.new(params[:gallery]) |
---|
36 | |
---|
37 | # Save or display error text |
---|
38 | respond_to do |format| |
---|
39 | if @gallery.save |
---|
40 | |
---|
41 | # Process multiple file uploads |
---|
42 | id = @gallery.id |
---|
43 | params[:gallery_files].each do |preview| |
---|
44 | GalleryFiles.create(:filename => preview[1], :gallery_id => id.to_i, :sType => "Artwork" ) if !preview[1].blank? |
---|
45 | end |
---|
46 | |
---|
47 | # if params[:setups] |
---|
48 | # params[:setups].each do |relate| |
---|
49 | # SetupsModel.create(:sDIS => '', :setup_id => relate, :model_id => id.to_i ) if !relate.blank? |
---|
50 | # end |
---|
51 | # end |
---|
52 | |
---|
53 | #Regular Display |
---|
54 | flash[:notice] = 'Gallery was successfully created.' |
---|
55 | format.html { redirect_to("/") } |
---|
56 | format.xml { render :xml => @gallery, :status => :created, :location => @gallery } |
---|
57 | else |
---|
58 | #Error Display |
---|
59 | format.html { render :action => "new" } |
---|
60 | format.xml { render :xml => @gallery.errors, :status => :unprocessable_entity } |
---|
61 | end |
---|
62 | end |
---|
63 | end |
---|
64 | |
---|
65 | def createMedia |
---|
66 | |
---|
67 | #Make similar to create_file etc |
---|
68 | |
---|
69 | # Old Way : |
---|
70 | # |
---|
71 | # id = @gallery.id |
---|
72 | # params[:model_files].each do |preview| |
---|
73 | # ModelFiles.create(:filename => preview[1], :model_id => id.to_i ) if !preview[1].blank? |
---|
74 | # end |
---|
75 | |
---|
76 | # @art = Art.new(params[:model]) |
---|
77 | end |
---|
78 | |
---|
79 | def createFile |
---|
80 | |
---|
81 | #Make similar to create_file etc |
---|
82 | |
---|
83 | # Old Way : |
---|
84 | # |
---|
85 | # id = @gallery.id |
---|
86 | # params[:model_files].each do |preview| |
---|
87 | # ModelFiles.create(:filename => preview[1], :model_id => id.to_i ) if !preview[1].blank? |
---|
88 | # end |
---|
89 | |
---|
90 | # @art = Art.new(params[:model]) |
---|
91 | end |
---|
92 | |
---|
93 | def update |
---|
94 | |
---|
95 | @gallery = Gallery.find(params[:id]) |
---|
96 | |
---|
97 | # Process multiple file uploads |
---|
98 | #Do using javascript that dynamically calls createGalleryFile |
---|
99 | |
---|
100 | # Old Way : |
---|
101 | # |
---|
102 | # id = @gallery.id |
---|
103 | # params[:model_files].each do |preview| |
---|
104 | # ModelFiles.create(:filename => preview[1], :model_id => id.to_i ) if !preview[1].blank? |
---|
105 | # end |
---|
106 | |
---|
107 | respond_to do |format| |
---|
108 | if @gallery.update_attributes(params[:gallery]) |
---|
109 | flash[:notice] = 'Gallery was successfully updated.' |
---|
110 | format.html { redirect_to("/") } |
---|
111 | format.xml { head :ok } |
---|
112 | else |
---|
113 | format.html { render :action => "edit" } |
---|
114 | format.xml { render :xml => @gallery.errors, :status => :unprocessable_entity } |
---|
115 | end |
---|
116 | end |
---|
117 | end |
---|
118 | |
---|
119 | |
---|
120 | def destroy |
---|
121 | |
---|
122 | @gallery = Gallery.find(params[:id]) |
---|
123 | @gallery.destroy |
---|
124 | |
---|
125 | respond_to do |format| |
---|
126 | format.html { redirect_to(models_url) } |
---|
127 | format.xml { head :ok } |
---|
128 | end |
---|
129 | end |
---|
130 | |
---|
131 | #Used to delete an uploaded file in a Gallery |
---|
132 | #Destroys the actual file from the hard disk using file_column |
---|
133 | #Destroys database link |
---|
134 | #Requires: |
---|
135 | # params: |
---|
136 | # :id -> id of model that contains the file |
---|
137 | # :file_id -> id of file to be deleted |
---|
138 | def destroy_file |
---|
139 | |
---|
140 | if params[:type] == "file" |
---|
141 | @file = GalleryFiles.find(params[:file_id]) |
---|
142 | else |
---|
143 | @file = GalleryMedia.find(params[:file_id]) |
---|
144 | end |
---|
145 | @file.destroy |
---|
146 | |
---|
147 | respond_to do |format| |
---|
148 | format.html { redirect_to(edit_setup_path(params[:id])) } |
---|
149 | format.js { |
---|
150 | render :update do |page| |
---|
151 | page.visual_effect :blind_up, "File_#{params[:file_id].to_s}" |
---|
152 | end |
---|
153 | } |
---|
154 | end |
---|
155 | end |
---|
156 | end |
---|