Description:
added message hiding for admin in msg console
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@371 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r173:d8e86bba9b6f - - 3 files changed: 18 inserted, 1 deleted
@@ -1,71 +1,80 | |||
|
1 | 1 | class MessagesController < ApplicationController |
|
2 | 2 | |
|
3 | 3 | before_filter :authenticate |
|
4 | 4 | |
|
5 | 5 | verify :method => :post, :only => ['create'], |
|
6 | 6 | :redirect_to => { :action => 'list' } |
|
7 | 7 | |
|
8 |
- before_filter :admin_authorization, :only => ['console','show', |
|
|
8 | + before_filter :admin_authorization, :only => ['console','show', | |
|
9 | + 'reply','hide'] | |
|
9 | 10 | |
|
10 | 11 | def list |
|
11 | 12 | @user = User.find(session[:user_id]) |
|
12 | 13 | @messages = Message.find_all_sent_by_user(@user) |
|
13 | 14 | end |
|
14 | 15 | |
|
15 | 16 | def console |
|
16 | 17 | @user = User.find(session[:user_id]) |
|
17 | 18 | @messages = Message.find_all_system_unreplied_messages |
|
18 | 19 | end |
|
19 | 20 | |
|
20 | 21 | def show |
|
21 | 22 | @message = Message.find(params[:id]) |
|
22 | 23 | end |
|
23 | 24 | |
|
24 | 25 | def create |
|
25 | 26 | user = User.find(session[:user_id]) |
|
26 | 27 | @message = Message.new(params[:message]) |
|
27 | 28 | @message.sender = user |
|
28 | 29 | if !@message.save |
|
29 | 30 | render :action => 'list' and return |
|
30 | 31 | else |
|
31 | 32 | flash[:notice] = 'New message posted' |
|
32 | 33 | redirect_to :action => 'list' |
|
33 | 34 | end |
|
34 | 35 | end |
|
35 | 36 | |
|
36 | 37 | def reply |
|
37 | 38 | user = User.find(session[:user_id]) |
|
38 | 39 | @message = Message.new(params[:r_message]) |
|
39 | 40 | @message.sender = user |
|
40 | 41 | if !@message.save |
|
41 | 42 | render :action => 'show' and return |
|
42 | 43 | else |
|
43 | 44 | flash[:notice] = 'Message replied' |
|
44 | 45 | rep_msg = @message.replying_message |
|
45 | 46 | rep_msg.replied = true |
|
46 | 47 | rep_msg.save |
|
47 | 48 | redirect_to :action => 'console' |
|
48 | 49 | end |
|
49 | 50 | end |
|
50 | 51 | |
|
52 | + def hide | |
|
53 | + message = Message.find(params[:id]) | |
|
54 | + message.replied = true | |
|
55 | + message.save | |
|
56 | + flash[:notice] = 'Message hided (just marked replied)' | |
|
57 | + redirect_to :action => 'console' | |
|
58 | + end | |
|
59 | + | |
|
51 | 60 | protected |
|
52 | 61 | def build_replying_message_hierarchy(user) |
|
53 | 62 | @all_messages = {} |
|
54 | 63 | |
|
55 | 64 | |
|
56 | 65 | # manually build replies hierarchy (to improve efficiency) |
|
57 | 66 | [@messages, @replied_messages].each do |collection| |
|
58 | 67 | collection.each do |m| |
|
59 | 68 | @all_messages[m.id] = {:msg => m, :replies => []} |
|
60 | 69 | end |
|
61 | 70 | end |
|
62 | 71 | |
|
63 | 72 | @all_messages.each do |m| |
|
64 | 73 | rep_id = m.replying_message_id |
|
65 | 74 | if @all_messages[rep_id]!=nil |
|
66 | 75 | @all_messages[rep_id][:replies] << m |
|
67 | 76 | end |
|
68 | 77 | end |
|
69 | 78 | end |
|
70 | 79 | |
|
71 | 80 | end |
@@ -1,6 +1,7 | |||
|
1 | 1 | %tr |
|
2 | 2 | %td=h short_message.sender.full_name |
|
3 | 3 | %td= "#{short_message.created_at}" |
|
4 | 4 | %td=h truncate(short_message.body) |
|
5 | 5 | %td |
|
6 | 6 | = link_to "[reply]", :action => 'show', :id => short_message.id |
|
7 | + = link_to "[hide]", :action => 'hide', :id => short_message.id |
@@ -1,13 +1,20 | |||
|
1 | 1 | %h3 Message |
|
2 | 2 | |
|
3 | 3 | .message |
|
4 | 4 | .stat |
|
5 | 5 | = "#{@message.sender.full_name} at #{@message.created_at}" |
|
6 | 6 | .body= simple_format(@message.body) |
|
7 | 7 | |
|
8 | 8 | %h3 Your reply: |
|
9 | 9 | - form_for 'r_message', nil, :url => { :action => 'reply'} do |f| |
|
10 | 10 | = f.text_area :body, :rows => 5, :cols => 100 |
|
11 | 11 | = f.hidden_field :receiver_id, {:value => @message.sender_id } |
|
12 | 12 | = f.hidden_field :replying_message_id, {:value => @message.id } |
|
13 | 13 | = submit_tag "Post" |
|
14 | + | |
|
15 | + %p | |
|
16 | + If you do not want to reply, but want to hide this message from | |
|
17 | + console, you can | |
|
18 | + = link_to "[hide]", :action => 'hide', :id => @message.id | |
|
19 | + this message. (This message will be marked as replied.) | |
|
20 | + |
You need to be logged in to leave comments.
Login now