fetty-generators 1.7.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. data/Gemfile +2 -0
  2. data/README.rdoc +42 -36
  3. data/Rakefile +1 -3
  4. data/lib/generators/fetty.rb +160 -10
  5. data/lib/generators/fetty/authentication/USAGE +4 -0
  6. data/lib/generators/fetty/authentication/authentication_generator.rb +171 -0
  7. data/lib/generators/fetty/authentication/templates/controllers/reset_passwords_controller.rb +45 -0
  8. data/lib/generators/fetty/authentication/templates/controllers/sessions_controller.rb +30 -0
  9. data/lib/generators/fetty/authentication/templates/controllers/users_controller.rb +78 -0
  10. data/lib/generators/fetty/authentication/templates/helpers/reset_passwords_helper.rb +2 -0
  11. data/lib/generators/fetty/authentication/templates/helpers/sessions_helper.rb +2 -0
  12. data/lib/generators/fetty/authentication/templates/helpers/users_helper.rb +2 -0
  13. data/lib/generators/fetty/authentication/templates/lib/sessions_authentication.rb +53 -0
  14. data/lib/generators/fetty/authentication/templates/lib/users_authentication.rb +110 -0
  15. data/lib/generators/fetty/authentication/templates/mailers/setup_mail.rb +11 -0
  16. data/lib/generators/fetty/authentication/templates/mailers/user_mailer.rb +14 -0
  17. data/lib/generators/fetty/authentication/templates/models/active_record/create_users.rb +17 -0
  18. data/lib/generators/fetty/authentication/templates/models/active_record/user.rb +15 -0
  19. data/lib/generators/fetty/authentication/templates/models/mongoid/user.rb +23 -0
  20. data/lib/generators/fetty/authentication/templates/spec/controllers/reset_passwords_controller_spec.rb +93 -0
  21. data/lib/generators/fetty/authentication/templates/spec/controllers/sessions_controller_spec.rb +61 -0
  22. data/lib/generators/fetty/authentication/templates/spec/controllers/users_controller_spec.rb +158 -0
  23. data/lib/generators/fetty/authentication/templates/spec/models/user_spec.rb +108 -0
  24. data/lib/generators/fetty/authentication/templates/spec/routing/reset_passwords_routing_spec.rb +21 -0
  25. data/lib/generators/fetty/authentication/templates/spec/routing/sessions_routing_spec.rb +17 -0
  26. data/lib/generators/fetty/authentication/templates/spec/routing/users_routing_spec.rb +37 -0
  27. data/lib/generators/fetty/authentication/templates/spec/support/user_factories.rb +6 -0
  28. data/lib/generators/fetty/authentication/templates/views/layouts/application.html.erb +33 -0
  29. data/lib/generators/fetty/authentication/templates/views/reset_passwords/edit.html.erb +19 -0
  30. data/lib/generators/fetty/authentication/templates/views/reset_passwords/new.html.erb +14 -0
  31. data/lib/generators/fetty/authentication/templates/views/sessions/new.html.erb +22 -0
  32. data/lib/generators/fetty/authentication/templates/views/user_mailer/user_activation.text.erb +4 -0
  33. data/lib/generators/fetty/authentication/templates/views/user_mailer/user_forgot_password.text.erb +7 -0
  34. data/lib/generators/fetty/authentication/templates/views/users/_table.html.erb +23 -0
  35. data/lib/generators/fetty/authentication/templates/views/users/edit.html.erb +21 -0
  36. data/lib/generators/fetty/authentication/templates/views/users/index.html.erb +7 -0
  37. data/lib/generators/fetty/authentication/templates/views/users/index.js.erb +1 -0
  38. data/lib/generators/fetty/authentication/templates/views/users/new.html.erb +23 -0
  39. data/lib/generators/fetty/authentication/templates/views/users/show.html.erb +19 -0
  40. data/lib/generators/fetty/messages/USAGE +4 -0
  41. data/lib/generators/fetty/messages/messages_generator.rb +136 -0
  42. data/lib/generators/fetty/messages/templates/assets/javascripts/jquery.tokeninput.js +718 -0
  43. data/lib/generators/fetty/messages/templates/assets/javascripts/messages.js +19 -0
  44. data/lib/generators/fetty/messages/templates/assets/stylesheets/messages.css +87 -0
  45. data/lib/generators/fetty/messages/templates/assets/stylesheets/token-input-facebook.css +122 -0
  46. data/lib/generators/fetty/messages/templates/controllers/messages_controller.rb +109 -0
  47. data/lib/generators/fetty/messages/templates/helpers/messages_helper.rb +2 -0
  48. data/lib/generators/fetty/messages/templates/lib/users_messages.rb +67 -0
  49. data/lib/generators/fetty/messages/templates/models/active_record/create_messages.rb +24 -0
  50. data/lib/generators/fetty/messages/templates/models/active_record/message.rb +67 -0
  51. data/lib/generators/fetty/messages/templates/models/mongoid/message.rb +81 -0
  52. data/lib/generators/fetty/messages/templates/spec/controllers/messages_controller_spec.rb +78 -0
  53. data/lib/generators/fetty/messages/templates/spec/models/message_spec.rb +53 -0
  54. data/lib/generators/fetty/messages/templates/spec/routing/messages_routing_spec.rb +61 -0
  55. data/lib/generators/fetty/messages/templates/spec/support/message_factories.rb +8 -0
  56. data/lib/generators/fetty/messages/templates/views/_head.html.erb +20 -0
  57. data/lib/generators/fetty/messages/templates/views/_messages.html.erb +56 -0
  58. data/lib/generators/fetty/messages/templates/views/_tabs_panel.html.erb +11 -0
  59. data/lib/generators/fetty/messages/templates/views/index.html.erb +10 -0
  60. data/lib/generators/fetty/messages/templates/views/index.js.erb +1 -0
  61. data/lib/generators/fetty/messages/templates/views/new.html.erb +26 -0
  62. data/lib/generators/fetty/messages/templates/views/show.html.erb +35 -0
  63. data/lib/generators/fetty/scaffold/USAGE +2 -52
  64. data/lib/generators/fetty/scaffold/scaffold_generator.rb +96 -329
  65. data/lib/generators/fetty/scaffold/templates/controllers/active_record/controller.rb +60 -0
  66. data/lib/generators/fetty/scaffold/templates/controllers/mongoid/controller.rb +60 -0
  67. data/lib/generators/fetty/scaffold/templates/helpers/helper.rb +2 -0
  68. data/lib/generators/fetty/scaffold/templates/models/active_record/migration.rb +16 -0
  69. data/lib/generators/fetty/scaffold/templates/models/active_record/model.rb +10 -0
  70. data/lib/generators/fetty/scaffold/templates/models/mongoid/model.rb +16 -0
  71. data/lib/generators/fetty/scaffold/templates/test/rspec/controller.rb +98 -0
  72. data/lib/generators/fetty/scaffold/templates/test/rspec/factories.rb +26 -0
  73. data/lib/generators/fetty/scaffold/templates/test/rspec/helper.rb +15 -0
  74. data/lib/generators/fetty/scaffold/templates/test/rspec/model.rb +9 -0
  75. data/lib/generators/fetty/scaffold/templates/test/rspec/request.rb +11 -0
  76. data/lib/generators/fetty/scaffold/templates/test/rspec/routing.rb +41 -0
  77. data/lib/generators/fetty/scaffold/templates/test/test_unit/controller.rb +62 -0
  78. data/lib/generators/fetty/scaffold/templates/{fixtures.yml → test/test_unit/fixtures.yml} +2 -0
  79. data/lib/generators/fetty/scaffold/templates/test/test_unit/helper.rb +4 -0
  80. data/lib/generators/fetty/scaffold/templates/test/test_unit/model.rb +7 -0
  81. data/lib/generators/fetty/scaffold/templates/views/_form.html.erb +20 -0
  82. data/lib/generators/fetty/scaffold/templates/views/_table.html.erb +48 -0
  83. data/lib/generators/fetty/scaffold/templates/views/edit.html.erb +13 -0
  84. data/lib/generators/fetty/scaffold/templates/views/index.html.erb +15 -0
  85. data/lib/generators/fetty/scaffold/templates/views/{erb/index.js.erb → index.js.erb} +0 -0
  86. data/lib/generators/fetty/scaffold/templates/views/new.html.erb +9 -0
  87. data/lib/generators/fetty/scaffold/templates/views/show.html.erb +28 -0
  88. data/lib/generators/fetty/setup/USAGE +3 -20
  89. data/lib/generators/fetty/setup/setup_generator.rb +122 -61
  90. data/lib/generators/fetty/setup/templates/ability.rb +0 -0
  91. data/lib/generators/fetty/setup/templates/ckeditor.rb +54 -0
  92. data/lib/generators/fetty/setup/templates/ckeditor.tar.gz +0 -0
  93. data/lib/generators/fetty/setup/templates/escape_utils.rb +7 -0
  94. data/lib/generators/fetty/setup/templates/file_uploader.rb +15 -0
  95. data/lib/generators/fetty/setup/templates/image_uploader.rb +48 -0
  96. data/lib/generators/fetty/setup/templates/spec_helper.rb +44 -0
  97. data/lib/generators/fetty/views/USAGE +5 -0
  98. data/lib/generators/fetty/{layout/templates/stylesheet.css → views/templates/application.css} +184 -166
  99. data/lib/generators/fetty/views/templates/application.html.erb +23 -0
  100. data/lib/generators/fetty/{layout → views}/templates/application.js +0 -0
  101. data/lib/generators/fetty/views/templates/application_helper.rb +10 -0
  102. data/lib/generators/fetty/views/templates/down_arrow.gif +0 -0
  103. data/lib/generators/fetty/{layout → views}/templates/error_messages_helper.rb +0 -0
  104. data/lib/generators/fetty/{layout → views}/templates/layout_helper.rb +0 -0
  105. data/lib/generators/fetty/views/templates/up_arrow.gif +0 -0
  106. data/lib/generators/fetty/views/views_generator.rb +51 -0
  107. data/lib/generators/scaffold.rb +204 -0
  108. metadata +126 -111
  109. data/LICENSE +0 -20
  110. data/lib/generators/fetty/layout/USAGE +0 -26
  111. data/lib/generators/fetty/layout/layout_generator.rb +0 -44
  112. data/lib/generators/fetty/layout/templates/layout.html.erb +0 -32
  113. data/lib/generators/fetty/layout/templates/layout.html.haml +0 -34
  114. data/lib/generators/fetty/layout/templates/no-devise-links-layout.html.erb +0 -23
  115. data/lib/generators/fetty/layout/templates/no-devise-links-layout.html.haml +0 -23
  116. data/lib/generators/fetty/layout/templates/stylesheet.sass +0 -163
  117. data/lib/generators/fetty/scaffold/templates/actions/create.rb +0 -8
  118. data/lib/generators/fetty/scaffold/templates/actions/destroy.rb +0 -5
  119. data/lib/generators/fetty/scaffold/templates/actions/edit.rb +0 -3
  120. data/lib/generators/fetty/scaffold/templates/actions/index.rb +0 -10
  121. data/lib/generators/fetty/scaffold/templates/actions/new.rb +0 -3
  122. data/lib/generators/fetty/scaffold/templates/actions/show.rb +0 -3
  123. data/lib/generators/fetty/scaffold/templates/actions/update.rb +0 -8
  124. data/lib/generators/fetty/scaffold/templates/controller.rb +0 -7
  125. data/lib/generators/fetty/scaffold/templates/helper.rb +0 -2
  126. data/lib/generators/fetty/scaffold/templates/migration.rb +0 -16
  127. data/lib/generators/fetty/scaffold/templates/model.rb +0 -7
  128. data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/create.rb +0 -11
  129. data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/destroy.rb +0 -6
  130. data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/edit.rb +0 -4
  131. data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/index.rb +0 -4
  132. data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/new.rb +0 -4
  133. data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/show.rb +0 -4
  134. data/lib/generators/fetty/scaffold/templates/tests/rspec/actions/update.rb +0 -11
  135. data/lib/generators/fetty/scaffold/templates/tests/rspec/controller.rb +0 -8
  136. data/lib/generators/fetty/scaffold/templates/tests/rspec/model.rb +0 -7
  137. data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/create.rb +0 -13
  138. data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/destroy.rb +0 -8
  139. data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/edit.rb +0 -6
  140. data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/index.rb +0 -6
  141. data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/new.rb +0 -6
  142. data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/show.rb +0 -6
  143. data/lib/generators/fetty/scaffold/templates/tests/shoulda/actions/update.rb +0 -13
  144. data/lib/generators/fetty/scaffold/templates/tests/shoulda/controller.rb +0 -5
  145. data/lib/generators/fetty/scaffold/templates/tests/shoulda/model.rb +0 -7
  146. data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/create.rb +0 -11
  147. data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/destroy.rb +0 -6
  148. data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/edit.rb +0 -4
  149. data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/index.rb +0 -4
  150. data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/new.rb +0 -4
  151. data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/show.rb +0 -4
  152. data/lib/generators/fetty/scaffold/templates/tests/testunit/actions/update.rb +0 -11
  153. data/lib/generators/fetty/scaffold/templates/tests/testunit/controller.rb +0 -5
  154. data/lib/generators/fetty/scaffold/templates/tests/testunit/model.rb +0 -7
  155. data/lib/generators/fetty/scaffold/templates/views/erb/_form.html.erb +0 -22
  156. data/lib/generators/fetty/scaffold/templates/views/erb/_table.html.erb +0 -50
  157. data/lib/generators/fetty/scaffold/templates/views/erb/edit.html.erb +0 -12
  158. data/lib/generators/fetty/scaffold/templates/views/erb/index.html.erb +0 -13
  159. data/lib/generators/fetty/scaffold/templates/views/erb/new.html.erb +0 -9
  160. data/lib/generators/fetty/scaffold/templates/views/erb/show.html.erb +0 -26
  161. data/lib/generators/fetty/scaffold/templates/views/haml/_form.html.haml +0 -8
  162. data/lib/generators/fetty/scaffold/templates/views/haml/_table.html.haml +0 -33
  163. data/lib/generators/fetty/scaffold/templates/views/haml/edit.html.haml +0 -14
  164. data/lib/generators/fetty/scaffold/templates/views/haml/index.html.haml +0 -12
  165. data/lib/generators/fetty/scaffold/templates/views/haml/index.js.haml +0 -1
  166. data/lib/generators/fetty/scaffold/templates/views/haml/new.html.haml +0 -8
  167. data/lib/generators/fetty/scaffold/templates/views/haml/show.html.haml +0 -23
@@ -0,0 +1,19 @@
1
+ $(function() {
2
+ // Check all the checkboxes when the head one is selected
3
+ $(".checkall").live("click", function() {
4
+ $("input[type='checkbox']").attr('checked', $(this).is(':checked'));
5
+ });
6
+
7
+ // handle pagination through ajax
8
+ $("#tabs-messages .pagination a").live("click", function(e) {
9
+ $.getScript(this.href);
10
+ history.pushState(null, document.title, this.href);
11
+ e.preventDefault();
12
+ });
13
+
14
+ //bind window for postate
15
+ $(window).bind("popstate", function() {
16
+ $.getScript(location.href);
17
+ });
18
+
19
+ });
@@ -0,0 +1,87 @@
1
+ ul.tabs {
2
+ margin: 0;
3
+ padding: 0;
4
+ float: left;
5
+ list-style: none;
6
+ height: 32px; /*--Set height of tabs--*/
7
+ border-bottom: 1px solid #999;
8
+ border-left: 1px solid #999;
9
+ width: 100%;
10
+ }
11
+ ul.tabs li {
12
+ float: left;
13
+ margin: 0;
14
+ padding: 0;
15
+ height: 31px; /*--Subtract 1px from the height of the unordered list--*/
16
+ line-height: 31px; /*--Vertically aligns the text within the tab--*/
17
+ border: 1px solid #999;
18
+ border-left: none;
19
+ margin-bottom: -1px; /*--Pull the list item down 1px--*/
20
+ overflow: hidden;
21
+ position: relative;
22
+ background: #e0e0e0;
23
+ }
24
+ ul.tabs li a {
25
+ text-decoration: none;
26
+ color: #000;
27
+ display: block;
28
+ padding: 0 20px;
29
+ border: 1px solid #fff; /*--Gives the bevel look with a 1px white border inside the list item--*/
30
+ outline: none;
31
+ }
32
+ ul.tabs li a:hover {
33
+ background: #ccc;
34
+ }
35
+ html ul.tabs li.active, html ul.tabs li.active a:hover { /*--Makes sure that the active tab does not listen to the hover properties--*/
36
+ background: #fff;
37
+ border-bottom: 1px solid #fff; /*--Makes the active tab look like it's connected with its content--*/
38
+ }
39
+
40
+ .message {
41
+ margin: 8px 0;
42
+ padding: 8px 15px;
43
+ border: solid 1px #999;
44
+ width: 300px;
45
+ border-radius: 12px;
46
+ background-image: -webkit-gradient(
47
+ linear,
48
+ left bottom,
49
+ left top,
50
+ color-stop(0, #CCC),
51
+ color-stop(1, #F5F5F5)
52
+ );
53
+ background-image: -moz-linear-gradient(
54
+ center bottom,
55
+ #CCC 0%,
56
+ #F5F5F5 100%
57
+ );
58
+ }
59
+
60
+ .message .content a {
61
+ color: #000;
62
+ text-decoration: none;
63
+ }
64
+
65
+ .message .created_at {
66
+ color: #555;
67
+ font-size: 12px;
68
+ float: right;
69
+ }
70
+
71
+ .message .actions {
72
+ font-size: 12px;
73
+ margin-top: 5px;
74
+ }
75
+
76
+ .message .actions a {
77
+ text-decoration: none;
78
+ }
79
+
80
+ .nested_messages {
81
+ margin-left: 30px;
82
+ }
83
+
84
+ /*.nested_messages .nested_messages .nested_messages .nested_messages {
85
+ margin-left: 0;
86
+ }
87
+ */
@@ -0,0 +1,122 @@
1
+ /* Example tokeninput style #2: Facebook style */
2
+ ul.token-input-list-facebook {
3
+ overflow: hidden;
4
+ height: auto !important;
5
+ height: 1%;
6
+ width: 400px;
7
+ border: 1px solid #8496ba;
8
+ cursor: text;
9
+ font-size: 12px;
10
+ font-family: Verdana;
11
+ min-height: 1px;
12
+ z-index: 999;
13
+ margin: 0;
14
+ padding: 0;
15
+ background-color: #fff;
16
+ list-style-type: none;
17
+ clear: left;
18
+ }
19
+
20
+ ul.token-input-list-facebook li input {
21
+ border: 0;
22
+ width: 100px;
23
+ padding: 3px 8px;
24
+ background-color: white;
25
+ margin: 2px 0;
26
+ -webkit-appearance: caret;
27
+ }
28
+
29
+ li.token-input-token-facebook {
30
+ overflow: hidden;
31
+ height: auto !important;
32
+ height: 15px;
33
+ margin: 3px;
34
+ padding: 1px 3px;
35
+ background-color: #eff2f7;
36
+ color: #000;
37
+ cursor: default;
38
+ border: 1px solid #ccd5e4;
39
+ font-size: 11px;
40
+ border-radius: 5px;
41
+ -moz-border-radius: 5px;
42
+ -webkit-border-radius: 5px;
43
+ float: left;
44
+ white-space: nowrap;
45
+ }
46
+
47
+ li.token-input-token-facebook p {
48
+ display: inline;
49
+ padding: 0;
50
+ margin: 0;
51
+ }
52
+
53
+ li.token-input-token-facebook span {
54
+ color: #a6b3cf;
55
+ margin-left: 5px;
56
+ font-weight: bold;
57
+ cursor: pointer;
58
+ }
59
+
60
+ li.token-input-selected-token-facebook {
61
+ background-color: #5670a6;
62
+ border: 1px solid #3b5998;
63
+ color: #fff;
64
+ }
65
+
66
+ li.token-input-input-token-facebook {
67
+ float: left;
68
+ margin: 0;
69
+ padding: 0;
70
+ list-style-type: none;
71
+ }
72
+
73
+ div.token-input-dropdown-facebook {
74
+ position: absolute;
75
+ width: 400px;
76
+ background-color: #fff;
77
+ overflow: hidden;
78
+ border-left: 1px solid #ccc;
79
+ border-right: 1px solid #ccc;
80
+ border-bottom: 1px solid #ccc;
81
+ cursor: default;
82
+ font-size: 11px;
83
+ font-family: Verdana;
84
+ z-index: 1;
85
+ }
86
+
87
+ div.token-input-dropdown-facebook p {
88
+ margin: 0;
89
+ padding: 5px;
90
+ font-weight: bold;
91
+ color: #777;
92
+ }
93
+
94
+ div.token-input-dropdown-facebook ul {
95
+ margin: 0;
96
+ padding: 0;
97
+ }
98
+
99
+ div.token-input-dropdown-facebook ul li {
100
+ background-color: #fff;
101
+ padding: 3px;
102
+ margin: 0;
103
+ list-style-type: none;
104
+ }
105
+
106
+ div.token-input-dropdown-facebook ul li.token-input-dropdown-item-facebook {
107
+ background-color: #fff;
108
+ }
109
+
110
+ div.token-input-dropdown-facebook ul li.token-input-dropdown-item2-facebook {
111
+ background-color: #fff;
112
+ }
113
+
114
+ div.token-input-dropdown-facebook ul li em {
115
+ font-weight: bold;
116
+ font-style: normal;
117
+ }
118
+
119
+ div.token-input-dropdown-facebook ul li.token-input-selected-dropdown-item-facebook {
120
+ background-color: #3b5998;
121
+ color: #fff;
122
+ }
@@ -0,0 +1,109 @@
1
+ class MessagesController < ApplicationController
2
+
3
+ def index
4
+ @messagebox = params[:messagebox].blank? ? "inbox" : params[:messagebox]
5
+ @messages = current_user.send(@messagebox).group(:subject_id).page(params[:page]).per(10)
6
+
7
+ case @messagebox
8
+ when "trash"
9
+ @options = ["Read","Unread","Delete","Undelete"]
10
+ else
11
+ @options = ["Read","Unread","Delete"]
12
+ end
13
+ end
14
+
15
+ def show
16
+ unless params[:messagebox].blank?
17
+ message = current_user.send(params[:messagebox]).find(params[:id])
18
+
19
+ @messages = message.root.subtree
20
+ @parent_id = @messages.last.id
21
+
22
+ if @messages.last.copies
23
+ @user_tokens = @messages.last.recipient_id
24
+ @parent_id = @messages.last.ancestor_ids.last unless @parent_id.nil?
25
+ else
26
+ @user_tokens = @messages.last.sender_id
27
+ end
28
+
29
+ read_unread_messages(true, *@messages)
30
+ end
31
+ end
32
+
33
+ def new
34
+ end
35
+
36
+ def create
37
+ unless params[:user_tokens].blank? or params[:subject].blank? or params[:content].blank?
38
+ recipients = User.find(params[:user_tokens].split(",").collect { |id| id.to_i })
39
+ if current_user.send_message?(:recipients => recipients, :subject_id => params[:subject_id], :subject => params[:subject], :content => params[:content], :parent_id => params[:parent_id])
40
+ redirect_to box_messages_url(:inbox), :notice => 'Successfully send message.'
41
+ else
42
+ flash.now[:alert] = "Unable to send message."
43
+ render "new"
44
+ end
45
+ else
46
+ flash.now[:alert] = "Invalid input for sending message."
47
+ render "new"
48
+ end
49
+ end
50
+
51
+ def update
52
+ unless params[:messages].nil?
53
+ message = current_user.send(params[:messagebox]).find(params[:messages])
54
+ message.each do |message|
55
+ messages = message.root.subtree
56
+ if params[:option].downcase == "read"
57
+ read_unread_messages(true,*messages)
58
+ elsif params[:option].downcase == "unread"
59
+ read_unread_messages(false,*messages)
60
+ elsif params[:option].downcase == "delete"
61
+ delete_messages(true,*messages)
62
+ elsif params[:option].downcase == "undelete"
63
+ delete_messages(false,*messages)
64
+ end
65
+ end
66
+ end
67
+ redirect_to box_messages_url(params[:messagebox])
68
+ end
69
+
70
+ def empty
71
+ unless params[:messagebox].nil?
72
+ current_user.empty_messages(params[:messagebox].to_sym => true)
73
+ redirect_to box_messages_url(params[:messagebox]), :notice => "Successfully delete all messages."
74
+ end
75
+ end
76
+
77
+ def token
78
+ query = "%" + params[:q] + "%"
79
+ recipients = User.select("id,username").where("username like ?", query)
80
+ respond_to do |format|
81
+ format.json { render :json => recipients.map { |u| { "id" => u.id, "name" => u.username} } }
82
+ end
83
+ end
84
+
85
+ private
86
+
87
+ def read_unread_messages(isRead, *messages)
88
+ messages.each do |msg|
89
+ unless msg.copies
90
+ if isRead
91
+ msg.mark_as_read unless msg.read?
92
+ else
93
+ msg.mark_as_unread if msg.read?
94
+ end
95
+ end
96
+ end
97
+ end
98
+
99
+ def delete_messages(isDelete, *messages)
100
+ messages.each do |msg|
101
+ if isDelete
102
+ msg.delete
103
+ else
104
+ msg.undelete
105
+ end
106
+ end
107
+ end
108
+
109
+ end
@@ -0,0 +1,2 @@
1
+ module MessagesHelper
2
+ end
@@ -0,0 +1,67 @@
1
+ module UsersMessages
2
+
3
+ def send_message?(options)
4
+ send_message(options)
5
+ true
6
+ rescue Exception => e
7
+ false
8
+ end
9
+
10
+ def send_message(options)
11
+ unless options[:recipients].nil?
12
+ transaction do
13
+ recipients = options[:recipients]
14
+ options.delete(:recipients)
15
+
16
+ options[:subject_id] = Message.sequence_subject_id if options[:subject_id].nil?
17
+
18
+ recipients.each do |rec|
19
+ # => create message copies
20
+ options[:user_id] = self.id
21
+ options[:sender_id] = self.id
22
+ options[:recipient_id] = rec.id
23
+ options[:copies] = true
24
+ Message.create(options)
25
+ # => create message
26
+ options[:user_id] = rec.id
27
+ options[:sender_id] = self.id
28
+ options[:recipient_id] = rec.id
29
+ options[:copies] = false
30
+ options[:parent_id] = Message.next_parent_id(options[:parent_id]) unless options[:parent_id].nil?
31
+ Message.create(options)
32
+ end
33
+ end
34
+ else
35
+ raise "Required recipients"
36
+ end
37
+ rescue Exception => e
38
+ raise e
39
+ end
40
+
41
+ def inbox(options = {})
42
+ options[:deleted] = false
43
+ options[:copies] = false
44
+ self.messages.where(options)
45
+ end
46
+
47
+ def outbox(options = {})
48
+ options[:deleted] = false
49
+ options[:copies] = true
50
+ self.messages.where(options)
51
+ end
52
+
53
+ def trash(options = {})
54
+ options[:deleted] = true
55
+ self.messages.where(options)
56
+ end
57
+
58
+ def empty_messages(options = {})
59
+ if options.empty? or options[:inbox] or options[:outbox]
60
+ self.inbox.update_all(:deleted => true)
61
+ self.outbox.update_all(:deleted => true)
62
+ elsif options[:trash]
63
+ self.trash.delete_all
64
+ end
65
+ end
66
+
67
+ end
@@ -0,0 +1,24 @@
1
+ class CreateMessages < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :messages do |t|
4
+ t.integer :user_id
5
+ t.integer :sender_id
6
+ t.integer :recipient_id
7
+ t.integer :subject_id
8
+ t.string :subject
9
+ t.text :content
10
+ t.boolean :opened, :default => false
11
+ t.boolean :deleted, :default => false
12
+ t.boolean :copies, :default => false
13
+ t.string :ancestry
14
+ t.timestamps
15
+ end
16
+
17
+ add_index :messages, [:user_id, :subject_id, :ancestry], :name => "messages_idx"
18
+ end
19
+
20
+ def self.down
21
+ drop_index :messages, "messages_idx"
22
+ drop_table :messages
23
+ end
24
+ end
@@ -0,0 +1,67 @@
1
+ class Message < ActiveRecord::Base
2
+
3
+ has_ancestry
4
+
5
+ belongs_to :user
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