Class: PhotosController

Inherits:
BaseController show all
Includes:
Viewable
Defined in:
app/controllers/photos_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#advertise, #cache_action?, #css_help, #footer_content, #homepage_features, #plaxo, #rss_site_index, #site_index

Methods included from LocalizedApplication

#get_matching_ui_locale, #get_sorted_langs_from_accept_header, #get_valid_lang_from_accept_header, #set_locale

Methods included from AuthenticatedSystem

#login_by_token, #update_last_seen_at

Instance Method Details

#createObject

POST /photos POST /photos.xml



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'app/controllers/photos_controller.rb', line 102

def create
  @user = current_user
  @photo = Photo.new(params[:photo])
  @photo.user = @user
  @photo.tag_list = params[:tag_list] || ''
  
  @photo.album_id = params[:album_id] || ''    
  @photo.album_id = params[:album_selected] unless params[:album_selected].blank?


  respond_to do |format|
    if @photo.save
      flash[:notice] = :photo_was_successfully_created.l

      format.html {      
        render :action => 'inline_new', :layout => false and return if params[:inline]
        if params[:album_id]
          redirect_to user_album_path(current_user,params[:album_id])
        else  
          redirect_to user_photo_url(:id => @photo, :user_id => @photo.user)
        end
      }
      format.js {
        responds_to_parent do
          render :update do |page|
            page << "upload_image_callback('#{@photo.photo.url()}', '#{@photo.display_name}', '#{@photo.id}');"
          end
        end
      }
    else
      format.html {
        render :action => 'inline_new', :layout => false and return if params[:inline]
        render :action => "new"
      }
      format.js {
        responds_to_parent do
          render :update do |page|
            page.alert(:sorry_there_was_an_error_uploading_the_photo.l)
          end
        end
      }
    end
  end
end

#destroyObject

DELETE /photos/1 DELETE /photos/1.xml



168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'app/controllers/photos_controller.rb', line 168

def destroy
  @user = User.find(params[:user_id])
  @photo = Photo.find(params[:id])
  if @user.avatar.eql?(@photo)
    @user.avatar = nil
    @user.save!
  end
  @photo.destroy

  respond_to do |format|
    format.html { redirect_to user_photos_url(@photo.user)   }
  end
end

#editObject

GET /photos/1;edit



95
96
97
98
# File 'app/controllers/photos_controller.rb', line 95

def edit
  @photo = Photo.find(params[:id])
  @user = @photo.user
end

#indexObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/photos_controller.rb', line 21

def index
  @user = User.find(params[:user_id])

  @photos = Photo.where(:user_id => @user.id).includes(:tags)
  if params[:tag_name]
    @photos = @photos.where('tags.name = ?', params[:tag_name])
  end
  
  @photos = @photos.recent.page(params[:page]).per(20)

  @tags = Photo.includes(:taggings).where(:user_id => @user.id).tag_counts(:limit => 20)

  @rss_title = "#{configatron.community_name}: #{@user.login}'s photos"
  @rss_url = user_photos_path(@user,:format => :rss)

  respond_to do |format|
    format.html 
    format.rss {
      render_rss_feed_for(@photos,
         { :feed => {:title => @rss_title, :link => url_for(:controller => 'photos', :action => 'index', :user_id => @user) },
           :item => {:title => :name,
                     :description => Proc.new {|photo| description_for_rss(photo)},
                     :link => Proc.new {|photo| user_photo_url(photo.user, photo)},
                     :pub_date => :created_at} })

    }
    format.xml { render :action => 'index.rxml', :layout => false}
  end
end

#manage_photosObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/photos_controller.rb', line 51

def manage_photos
  if logged_in?
    @user = current_user      
    @photos = current_user.photos.recent.includes(:tags)      
    if params[:tag_name]
      @photos = @photos.where('tags.name = ?', params[:tag_name])
    end
    @selected = params[:photo_id]
    @photos = @photos.page(params[:page]).per(10)
  end
  respond_to do |format|
    format.js
  end
end

#newObject

GET /photos/new



85
86
87
88
89
90
91
92
# File 'app/controllers/photos_controller.rb', line 85

def new
  @user = User.find(params[:user_id])
  @photo = Photo.new
  if params[:inline]
    render :action => 'inline_new', :layout => false
  end

end

#recentObject



17
18
19
# File 'app/controllers/photos_controller.rb', line 17

def recent
  @photos = Photo.recent.page(params[:page])
end

#showObject

GET /photos/1 GET /photos/1.xml



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/controllers/photos_controller.rb', line 68

def show
  @photo = @user.photos.find(params[:id])
  update_view_count(@photo) if current_user && current_user.id != @photo.user_id
  
  @is_current_user = @user.eql?(current_user)
  @comment = Comment.new(params[:comment])

  @previous = @photo.previous_photo
  @next = @photo.next_photo
  @related = Photo.find_related_to(@photo)

  respond_to do |format|
    format.html # show.rhtml
  end
end

#updateObject

PUT /photos/1 PUT /photos/1.xml



150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'app/controllers/photos_controller.rb', line 150

def update
  @photo = Photo.find(params[:id])
  @user = @photo.user
  @photo.tag_list = params[:tag_list] || ''
  @photo.album_id = params[:photo][:album_id]

  respond_to do |format|
    if @photo.update_attributes(params[:photo])
      format.html { redirect_to user_photo_url(@photo.user, @photo) }
    else
      format.html { render :action => "edit" }
    end
  end
end