forked from jpsb/agentecore
/
profiles_controller.rb
executable file
·158 lines (132 loc) · 3.92 KB
/
profiles_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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
146
147
148
149
150
151
152
153
154
155
156
157
class ProfilesController < ApplicationController
include ApplicationHelper
prepend_before_filter :get_profile, :except => [:new, :create, :index, :search]
before_filter :setup, :except => [:index, :search]
before_filter :search_results, :only => [:index, :search]
def followers
@lista = @profile.followers.paginate(:all, :order => 'last_activity_at DESC', :page => @page, :per_page => 30) rescue []
@tipo = "followers"
render "friends/index"
end
def followings
@lista = @profile.followings.paginate(:all, :order => 'last_activity_at DESC', :page => @page, :per_page => 30) rescue []
@tipo = "followings"
render "friends/index"
end
def show
#nless @profile.youtube_username.blank?
# begin
# client = YouTubeG::Client.new
# @video = client.videos_by(:user => @profile.youtube_username).videos.first
# rescue Exception, OpenURI::HTTPError
# end
#nd
begin
#@flickr = @profile.flickr_username.blank? ? [] : flickr_images(flickr.people.findByUsername(@profile.flickr_username))
@flickr = []
rescue Exception, OpenURI::HTTPError
@flickr = []
end
@comments = @profile.comments.paginate(:page => @page, :per_page => @per_page)
respond_to do |wants|
wants.html do
@feed_items = @profile.feed_items.recents
end
wants.rss do
@feed_items = @profile.feed_items.recents
render :layout => false
end
end
end
def search
render
end
def index
render :action => :search
end
def edit
render
end
def update
case params[:switch]
when 'name','image'
if @profile.update_attributes params[:profile]
flash[:notice] = "Settings have been saved."
redirect_to edit_profile_url(@profile)
else
flash.now[:error] = @profile.errors
render :action => :edit
end
when 'password'
if @user.change_password(params[:verify_password], params[:new_password], params[:confirm_password])
flash[:notice] = t(:password_has_been_changed)
redirect_to edit_profile_url(@profile)
else
flash.now[:error] = @user.errors
render :action=> :edit
end
when 'new_password'
respond_to do |wants|
#if @comment.save
# wants.js do
# render :update do |page|
# page.insert_html :top, "#{dom_id(@parent)}_comments", :partial => 'comments/comment', :object => @comment
# page.visual_effect :highlight, "comment_#{@comment.id}".to_sym
# page << 'tb_remove();'
# page << "jq('#comment_comment').val('');"
# end
# end
#else
wants.js do
render :update do |page|
page << "message('Erro qualquer... naum interessa, soh quero ver na tela.');"
end
end
#end
end
else
RAILS_ENV == 'test' ? render( :text=>'') : raise( 'Unsupported swtich in action')
end
end
def delete_icon
respond_to do |wants|
@p.update_attribute :icon, nil
wants.js {render :update do |page| page.visual_effect 'Puff', 'profile_icon_picture' end }
end
end
def destroy
#respond_to do |wants|
# @user.destroy
# cookies[:auth_token] = {:expires => Time.now-1.day, :value => ""}
# session[:user] = nil
# wants.js do
# render :update do |page|
# page.alert(t(:your_user_account_have_been_deleted))
# page << 'location.href = "/";'
# end
# end
#end
end
private
def allow_to
super :owner, :all => true
super :all, :only => [:show, :index, :search]
end
def get_profile
@profile = Profile[params[:id]]
end
def setup
@user = @profile.user
end
def search_results
@page
@per_page
puts ""
if params[:search]
p = params[:search].dup
else
p = []
end
@results = Profile.search(p.delete(:q) || '', :page => @page, :per_page => 21)
end
end