| Class | Admin::CommentsController |
| In: |
app/controllers/admin/comments_controller.rb
|
| Parent: | Sadmin::BaseController |
# File app/controllers/admin/comments_controller.rb, line 114
114: def comments_on_item
115: @status = params[:status]
116: if @status
117: @conditions[0] << " AND comments.status=:status"
118: @conditions[1] = @conditions[1].merge({:status => @status})
119: end
120:
121: @oficiales = (params[:oficiales] && params[:oficiales].to_i == 1) || false
122: if @oficiales
123: @conditions[0] << " AND users.type in (#{User::STAFF.collect {|u| "'#{u}'"}.join(',')})"
124: end
125:
126: @item = params[:type].constantize.find(params[:id])
127: @comments = @item.comments.paginate :conditions => @conditions, :order => "created_at DESC",
128: :joins => "INNER JOIN users ON (users.id = comments.user_id)" + @joins,
129: :per_page => 20, :page => params[:page]
130:
131: @title = "Comentarios en #{@item.class.human_name} \"#{@item.title_es}\""
132: rewrite_current_tab
133: end
# File app/controllers/admin/comments_controller.rb, line 84
84: def destroy
85: @comment = Comment.find(params[:id], :joins => @joins, :conditions => @conditions)
86: if @comment.destroy
87: respond_to do |format|
88: format.html {
89: flash[:notice] = 'El comentario ha sido eliminado'
90: redirect_to admin_comments_path
91: }
92: format.js {
93: render :update do |page|
94: page.visual_effect :fade, "comment_#{@comment.id}"
95: end
96: }
97: end
98: else
99: respond_to do |format|
100: format.html {
101: flash[:error] = 'El comentario no ha podido ser eliminado'
102: redirect_to admin_comments_path
103: }
104: format.js {
105: render :update do |page|
106: page.alert "El comentario no se ha borrado"
107: end
108: }
109: end
110:
111: end
112: end
# File app/controllers/admin/comments_controller.rb, line 36
36: def do_reject
37: @comment = Comment.find(params[:id], :joins => @joins, :conditions => @conditions, :readonly => false)
38: if @comment.update_attributes(:status => "rechazado")
39: if params[:reject_and_mail]
40: email = Notifier.create_rejected_comment(@comment)
41:
42: begin
43: logger.info("Mandando email sobre comentario rechazado a #{@comment.user.email}")
44: Notifier.deliver(email)
45: flash[:notice] = "El email ha sido enviado"
46: rescue Net::SMTPServerBusy, Net::SMTPSyntaxError => err_type
47: logger.info("Error al mandar el email: " + err_type)
48: flash[:error] = t('session.Error_servidor_correo')
49: end
50: end
51: redirect_to(params[:return_to].present? ? params[:return_to] : admin_comments_path)
52: else
53: render :action => :reject
54: end
55: end
# File app/controllers/admin/comments_controller.rb, line 28
28: def edit
29: @comment = Comment.find(params[:id], :joins => @joins, :conditions => @conditions)
30: end
# File app/controllers/admin/comments_controller.rb, line 6
6: def index
7:
8: @title ||= 'Todos los comentarios'
9:
10: @status = params[:status]
11: if @status
12: @conditions[0] << " AND comments.status=:status"
13: @conditions[1] = @conditions[1].merge({:status => @status})
14: end
15:
16: @oficiales = (params[:oficiales] && params[:oficiales].to_i == 1) || false
17: if @oficiales
18: official_commenters = User.all.select {|u| u.is_official_commenter?}.collect(&:id)
19: @conditions[0] << " AND users.id IN (#{official_commenters.join(', ')})"
20: end
21:
22: @comments = Comment.paginate :per_page => 20,
23: :conditions => @conditions,
24: :joins => "INNER JOIN users ON (users.id = comments.user_id) " + @joins ,
25: :page => params[:page], :order => "created_at DESC"
26: end
# File app/controllers/admin/comments_controller.rb, line 78
78: def mark_as_ham
79: @comment = Comment.find(params[:id], :joins => @joins, :conditions => @conditions, :readonly => false)
80: @comment.mark_as_ham!
81: render_updated_comment
82: end
# File app/controllers/admin/comments_controller.rb, line 72
72: def mark_as_spam
73: @comment = Comment.find(params[:id], :joins => @joins, :conditions => @conditions, :readonly => false)
74: @comment.mark_as_spam!
75: render_updated_comment
76: end
# File app/controllers/admin/comments_controller.rb, line 32
32: def reject
33: @comment = Comment.find(params[:id], :joins => @joins, :conditions => @conditions)
34: end
# File app/controllers/admin/comments_controller.rb, line 57
57: def update
58: @comment = Comment.find(params[:id], :joins => @joins, :conditions => @conditions, :readonly => false)
59: if @comment.update_attributes(params[:comment])
60: redirect_to(params[:return_to].present? ? params[:return_to] : admin_comments_path)
61: else
62: render :action => :edit
63: end
64: end
# File app/controllers/admin/comments_controller.rb, line 135
135: def update_comments_status
136: @item = params[:type].constantize.find(params[:item_id], :readonly => false)
137: if @item.update_attribute(:comments_closed, params[:comments_closed])
138: render :update do |page|
139: page.replace :comments_status, :partial => 'comments_status'
140: end
141: end
142: end
# File app/controllers/admin/comments_controller.rb, line 66
66: def update_status
67: @comment = Comment.find(params[:id], :joins => @joins, :conditions => @conditions, :readonly => false)
68: @comment.update_attributes(params[:comment])
69: render_updated_comment
70: end
# File app/controllers/admin/comments_controller.rb, line 152
152: def zforward
153: @comment = Comment.find(params[:id], :joins => @joins, :conditions => @conditions, :readonly => false)
154:
155: body_for_z = "#{@comment.body}
156: ---------
157: Esta consulta corresponde al comentario nº #{@comment.id} de Irekia."
158:
159: res = Net::HTTP.post_form(URI.parse('http://www.ej-gv.net/o53/visualizador/o53regbuzonEuskadi.jsp'),
160: {'por'=>params[:por], 'lenguaje'=>'1', 'sugerencia' => body_for_z, 'name' => @comment.user.public_name, 'usuario' => @comment.user.email})
161:
162: # res = Net::HTTP.post_form(URI.parse('http://www.google.es/'),
163: # {'por'=> params[:por], 'lenguaje'=>'1', 'sugerencia' => body_for_z, 'name' => @comment.user.public_name, 'usuario' => @comment.user.email})
164:
165: case res
166: when Net::HTTPSuccess #, Net::HTTPRedirection
167: flash[:notice] = "El comentario se ha redigido correctamente"
168: # La respuesta esta en res.read_body
169: @comment.update_attributes(:zforwarded_at => Time.zone.now, :zforwarded_to => params[:por])
170: redirect_to :back
171: when Net::HTTPRedirection
172: flash[:error] = "Peticion redirigida a #{res['location']}"
173: redirect_to :back
174: # response = Net::HTTP.get(URI.parse(res['location']))
175: else
176: flash[:error] = "La redirección del comentario no ha funcionado: #{res.body}"
177: redirect_to :back
178: # res.error!
179: end
180:
181: end
# File app/controllers/admin/comments_controller.rb, line 144
144: def zforward_form
145: @comment = Comment.find(params[:id], :joins => @joins, :conditions => @conditions, :readonly => false)
146: render :update do |page|
147: page.replace_html "comment_id_#{@comment.id}", :partial => "zforward_form", :locals => {:comment => @comment}
148: end
149: end