has_messages_generators 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (23) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.mdown +43 -0
  3. data/lib/generators/base.rb +179 -0
  4. data/lib/generators/has_messages/install/USAGE +10 -0
  5. data/lib/generators/has_messages/install/install_generator.rb +126 -0
  6. data/lib/generators/has_messages/install/templates/README +26 -0
  7. data/lib/generators/has_messages/install/templates/assets/javascripts/jquery.tokeninput.js +718 -0
  8. data/lib/generators/has_messages/install/templates/assets/javascripts/messages.js +19 -0
  9. data/lib/generators/has_messages/install/templates/assets/stylesheets/messages.css +107 -0
  10. data/lib/generators/has_messages/install/templates/assets/stylesheets/token-input-facebook.css +122 -0
  11. data/lib/generators/has_messages/install/templates/controllers/messages_controller.rb +111 -0
  12. data/lib/generators/has_messages/install/templates/helpers/messages_helper.rb +2 -0
  13. data/lib/generators/has_messages/install/templates/lib/has_messages.rb +67 -0
  14. data/lib/generators/has_messages/install/templates/models/create_messages.rb +24 -0
  15. data/lib/generators/has_messages/install/templates/models/message.rb +67 -0
  16. data/lib/generators/has_messages/install/templates/views/_head.html.erb +20 -0
  17. data/lib/generators/has_messages/install/templates/views/_messages.html.erb +56 -0
  18. data/lib/generators/has_messages/install/templates/views/_tabs_panel.html.erb +11 -0
  19. data/lib/generators/has_messages/install/templates/views/index.html.erb +10 -0
  20. data/lib/generators/has_messages/install/templates/views/index.js.erb +1 -0
  21. data/lib/generators/has_messages/install/templates/views/new.html.erb +26 -0
  22. data/lib/generators/has_messages/install/templates/views/show.html.erb +35 -0
  23. metadata +78 -0
@@ -0,0 +1,67 @@
1
+ class Message < ActiveRecord::Base
2
+
3
+ has_ancestry
4
+
5
+ belongs_to :user, :class_name => "<%= @class_name %>"
6
+
7
+ attr_accessible :user_id,
8
+ :sender_id,
9
+ :recipient_id,
10
+ :subject_id,
11
+ :subject,
12
+ :content,
13
+ :opened,
14
+ :deleted,
15
+ :copies,
16
+ :parent_id
17
+
18
+ validates_presence_of :user_id, :sender_id, :recipient_id, :subject_id, :subject, :content
19
+
20
+ def self.sequence_subject_id
21
+ id = self.maximum(:subject_id).to_i
22
+ id = 0 if id.nil?
23
+ id += 1
24
+ id
25
+ end
26
+
27
+ def self.next_parent_id(parent_id)
28
+ parent_id = parent_id.to_i - 1
29
+ if self.where(:id => parent_id).empty?
30
+ parent_id = nil
31
+ end
32
+ parent_id
33
+ end
34
+
35
+ def read?
36
+ self.opened?
37
+ end
38
+
39
+ def mark_as_read
40
+ self.update_attributes!(:opened => true)
41
+ end
42
+
43
+ def mark_as_unread
44
+ self.update_attributes!(:opened => false)
45
+ end
46
+
47
+ def delete
48
+ unless self.deleted?
49
+ self.update_attributes!(:deleted => true)
50
+ else
51
+ self.destroy
52
+ end
53
+ end
54
+
55
+ def undelete
56
+ self.update_attributes!(:deleted => false)
57
+ end
58
+
59
+ def from
60
+ User.find_by_id(self.sender_id)
61
+ end
62
+
63
+ def to
64
+ User.find_by_id(self.recipient_id)
65
+ end
66
+
67
+ end
@@ -0,0 +1,20 @@
1
+ <% content_for :head do %>
2
+
3
+ <%= stylesheet_link_tag "messages" %>
4
+ <%= javascript_include_tag "messages" %>
5
+
6
+ <%- if controller.action_name == "new" -%>
7
+ <%= stylesheet_link_tag "token-input-facebook" %>
8
+ <%= javascript_include_tag "jquery.tokeninput" %>
9
+ <script type="text/javascript">
10
+
11
+ $(document).ready(function() {
12
+ $("#user_tokens").tokenInput("/messages/token.json", {
13
+ crossDomain: false,
14
+ theme: "facebook"
15
+ });
16
+ });
17
+
18
+ </script>
19
+ <%- end -%>
20
+ <% end %>
@@ -0,0 +1,56 @@
1
+ <%= form_tag messages_path, :method => :put, :remote => true do %>
2
+ <table class="pretty" width="100%">
3
+ <tbody>
4
+ <tr>
5
+ <td class="middle">
6
+ <input type="checkbox" class="checkall" id="checkbox" name="checkbox">
7
+ </td>
8
+ <td colspan="3">
9
+ <%= select_tag "option", options_for_select(@options) %>
10
+ <%= submit_tag "Apply to Selected" %>
11
+ <%= link_to "Empty #{@messagebox}", empty_messages_path(@messagebox), :confirm => "Are you sure want to delete all?", :method => :post %>
12
+ <%= hidden_field_tag :messagebox, @messagebox %>
13
+ </td>
14
+ </tr>
15
+ <!-- this will render the messages -->
16
+ <%-
17
+ x = 0
18
+ @messages.reverse_each do |message|
19
+ convTree = message.root.subtree
20
+
21
+ flag = convTree.where(:copies => false).empty?
22
+ display_names = convTree.collect do |c|
23
+ unless flag
24
+ c.copies ? "me" : c.from.email
25
+ else
26
+ c.to.email
27
+ end
28
+ end.uniq.join(", ").concat( convTree.count > 1 ? " (#{convTree.count})" : "")
29
+
30
+ style = ""
31
+ flag = convTree.where(:copies => false, :opened => false).empty?
32
+ unless flag
33
+ style = "unread "
34
+ end
35
+ style << "alt" if ((x += 1) % 2 == 0)
36
+
37
+ title = convTree.last.created_at.strftime("%a, %b %d, %Y at %I:%M %p")
38
+ created_at = convTree.last.created_at.strftime( ((convTree.last.created_at < 1.days.ago) ? "%b %d, %Y" : "%I:%M %p"))
39
+ -%>
40
+ <tr class="<%= style -%>">
41
+ <td><%= check_box_tag "[messages][]", message.id %></td>
42
+ <td><%= display_names %></td>
43
+ <td><%= link_to message.subject, show_messages_path(@messagebox, message.id) %></td>
44
+ <td title='<%= title %>'><%= created_at %></td>
45
+ </tr>
46
+ <%- end -%>
47
+ <!-- END MESSAGES -->
48
+ <tr>
49
+ <td colspan="4"><%= paginate @messages %></td>
50
+ </tr>
51
+ </tbody>
52
+ </table>
53
+ <%- end -%>
54
+ <p>
55
+ <%= link_to "Compose New Message", new_message_path %>
56
+ </p>
@@ -0,0 +1,11 @@
1
+ <ul class="tabs">
2
+ <li class=<%= "active" if @messagebox == "inbox" %>>
3
+ <%= link_to "Inbox", box_messages_path(:inbox) %>
4
+ </li>
5
+ <li class=<%= "active" if @messagebox == "outbox" %>>
6
+ <%= link_to "Outbox", box_messages_path(:outbox) %>
7
+ </li>
8
+ <li class=<%= "active" if @messagebox == "trash" %>>
9
+ <%= link_to "Trash", box_messages_path(:trash) %>
10
+ </li>
11
+ </ul>
@@ -0,0 +1,10 @@
1
+ <h1>Messages</h1>
2
+
3
+ <%= render "head" %>
4
+
5
+ <div>
6
+ <%= render "tabs_panel" %>
7
+ <div id="tabs-messages">
8
+ <%= render 'messages' %>
9
+ </div>
10
+ </div>
@@ -0,0 +1 @@
1
+ $("#tabs-messages").html("<%= escape_javascript(render("messages")) %>");
@@ -0,0 +1,26 @@
1
+ <h1>New Messages</h1>
2
+
3
+ <%= render "head" %>
4
+
5
+ <div>
6
+ <%= render :partial => "tabs_panel" %>
7
+ <div id="tabs-messages" style="padding-top:50px;">
8
+ <%= form_tag messages_path, :method => :post do %>
9
+ <p>
10
+ <%= label_tag :user_tokens, "User" %><br />
11
+ <%= text_field_tag :user_tokens %>
12
+ </p>
13
+ <p>
14
+ <%= label_tag :subject, "Subject" %><br />
15
+ <%= text_field_tag :subject, nil, :size => 75 %>
16
+ </p>
17
+ <p>
18
+ <%= label_tag :content, "Messages" %><br />
19
+ <%= text_area_tag :content, nil, :rows => 20, :cols => 55 %>
20
+ </p>
21
+ <p>
22
+ <%= submit_tag "Send" %>
23
+ </p>
24
+ <% end %>
25
+ </div>
26
+ </div>
@@ -0,0 +1,35 @@
1
+ <h1>Show Messages</h1>
2
+
3
+ <%= render "head" %>
4
+
5
+ <div>
6
+ <%= render :partial => "tabs_panel" %>
7
+ <div id="tabs-messages" style="padding-top:50px;">
8
+ <%= form_tag messages_path, :method => :post do %>
9
+ <h3><%= @messages.last.subject %></h3>
10
+
11
+ <% for msg in @messages %>
12
+ <div class="message">
13
+ <div class="created_at"><%= msg.created_at.strftime("%B %d, %Y") %></div>
14
+ <div class="content">
15
+ <strong><%= msg.from.email %></strong><br />
16
+ <%= msg.content %>
17
+ </div>
18
+ </div>
19
+ <% end %>
20
+
21
+ <p>
22
+ <%= label_tag :content, "Reply Message" %><br />
23
+ <%= text_area_tag :content, nil, :rows => 20, :cols => 55 %>
24
+ </p>
25
+ <p>
26
+ <%= submit_tag "Reply" %>
27
+ </p>
28
+ <%= hidden_field_tag :user_tokens, @user_tokens %>
29
+ <%= hidden_field_tag :subject, @messages.last.subject %>
30
+ <%= hidden_field_tag :subject_id, @messages.last.subject_id %>
31
+ <%= hidden_field_tag :parent_id, @parent_id %>
32
+ <% end -%>
33
+ </div>
34
+ </div>
35
+
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: has_messages_generators
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Fajri Fachriansyah
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-25 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &2151877400 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2151877400
25
+ description: This is just a simple messaging generators for Rails 3.x, enable user
26
+ to sending messages across the app.
27
+ email: fajri82@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - lib/generators/base.rb
33
+ - lib/generators/has_messages/install/install_generator.rb
34
+ - lib/generators/has_messages/install/templates/assets/javascripts/jquery.tokeninput.js
35
+ - lib/generators/has_messages/install/templates/assets/javascripts/messages.js
36
+ - lib/generators/has_messages/install/templates/assets/stylesheets/messages.css
37
+ - lib/generators/has_messages/install/templates/assets/stylesheets/token-input-facebook.css
38
+ - lib/generators/has_messages/install/templates/controllers/messages_controller.rb
39
+ - lib/generators/has_messages/install/templates/helpers/messages_helper.rb
40
+ - lib/generators/has_messages/install/templates/lib/has_messages.rb
41
+ - lib/generators/has_messages/install/templates/models/create_messages.rb
42
+ - lib/generators/has_messages/install/templates/models/message.rb
43
+ - lib/generators/has_messages/install/templates/README
44
+ - lib/generators/has_messages/install/templates/views/_head.html.erb
45
+ - lib/generators/has_messages/install/templates/views/_messages.html.erb
46
+ - lib/generators/has_messages/install/templates/views/_tabs_panel.html.erb
47
+ - lib/generators/has_messages/install/templates/views/index.html.erb
48
+ - lib/generators/has_messages/install/templates/views/index.js.erb
49
+ - lib/generators/has_messages/install/templates/views/new.html.erb
50
+ - lib/generators/has_messages/install/templates/views/show.html.erb
51
+ - lib/generators/has_messages/install/USAGE
52
+ - MIT-LICENSE
53
+ - README.mdown
54
+ homepage: https://github.com/fajrif/has_messages_generators
55
+ licenses: []
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 1.8.10
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: Simple messaging generators for Rails 3.x
78
+ test_files: []