summaryrefslogtreecommitdiff
path: root/app/views/pms/index.html.erb
blob: 1175cb210b79a0cd1295f150e271d3f7b4031241 (plain)
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
<h1>Listing pms</h1>

<table>
  <thead>
    <tr>
      <th>Author</th>
      <th>Recipient</th>
      <th>Message</th>
      <th></th>
      <th></th>
      <th></th>
    </tr>
  </thead>

  <tbody>

    <tr>
      <td><h2>Inbox<h2></td>
    </tr>

    <% message = @pms.where(recipient: current_user) %>
    <% unless message.empty? then message.each do |pm| %>
      <tr>
        <td><%= pm.author.user_name %></td>
        <td><%= pm.recipient.user_name %></td>
        <td><%= pm.message %></td>
        <td><%= link_to 'Show', pm %></td>
        <td><%# link_to 'Edit', edit_pm_path(pm) %></td>
        <td><%= link_to 'Delete', pm, method: :delete, data: { confirm: 'Are you sure (also deletes the author\'s copy)?' } %></td>
      </tr>
      <% end %>
    <% else %>
      <td><h3>No New Messages</h3></td>
    <% end %>

    <tr>
      <td><h2>Outbox<h2></td>
    </tr>

    <% message = @pms.where(author: current_user) %>
    <% unless message.empty? then message.each do |pm| %>
      <tr>
        <td><%= pm.author.user_name %></td>
        <td><%= pm.recipient.user_name %></td>
        <td><%= pm.message %></td>
        <td><%= link_to 'Show', pm %></td>
        <td><%# link_to 'Edit', edit_pm_path(pm) %></td>
        <td><%= link_to 'Delete', pm, method: :delete, data: { confirm: 'Are you sure (also deletes the recipient\'s copy)?'} %></td>
      </tr>
      <% end %>
    <% else %>
      <td><h3>No New Messages</h3></td>
    <% end %>

    <tr>
      <td><h2>Conversations<h2></td>
    </tr>
    <tr>
      <td><h3>Inbox<h3></td>
    </tr>
    <tr>
      <% conversations = current_user.mailbox.inbox %>
      <% if !conversations.nil? %>
        <tr>
          <td><b>From</b></td>
          <td><b>Subject</b></td>
          <td><b>Body</b></td>
        </tr>
        <% conversations.each do |conversation| %>
          <% receipts = conversation.receipts_for current_user %>
          <% receipts.each do |receipt| %>
            <% message = receipt.message %>
            <tr>
            <td><%= conversation.last_sender.user_name %></td>
            <td><%= message.subject %></td>
            <td><%= message.body %></td>
            <td><%# link_to 'Show', pm %></td>
            </tr>
          <% end %>
        <% end %>

      <% else %>
          <td><p> No Messages </p></td>
      <% end %>
     </tr>

     <tr>
      <td><h3>Outbox<h3></td>
    </tr>
    <tr>
      <% conversations = current_user.mailbox.sentbox %>
      <% if !conversations.nil? %>
        <tr>
          <td><b>To</b></td>
          <td><b>Subject</b></td>
          <td><b>Body</b></td>
        </tr>
        <% conversations.each do |conversation| %>
          <% receipts = conversation.receipts_for current_user %>
          <% receipts.each do |receipt| %>
            <% message = receipt.message %>
            <tr>
            <td>Doesn't work</td>
            <td><%= message.subject %></td>
            <td><%= message.body %></td>
            <td><%# link_to 'Show', conversation %></td>
            </tr>
          <% end %>
        <% end %>
            
      <% else %>
          <td><p> No Messages </p></td>
      <% end %>
     </tr>

  </tbody>
</table>

<br>

<%= link_to 'New Pm', new_pm_path %>