message_train 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.rdoc +6 -5
- data/VERSION +1 -1
- data/app/assets/javascripts/message_train.js +10 -7
- data/app/controllers/message_train/boxes_controller.rb +3 -3
- data/app/controllers/message_train/conversations_controller.rb +3 -3
- data/app/controllers/message_train/messages_controller.rb +5 -5
- data/app/controllers/message_train/participants_controller.rb +14 -6
- data/app/views/message_train/messages/_form.html.haml +1 -1
- data/app/views/message_train/participants/_field.html.haml +1 -1
- data/app/views/message_train/participants/_participant.json.jbuilder +1 -1
- data/config/routes.rb +2 -1
- data/lib/message_train/configuration.rb +2 -2
- data/lib/message_train/mixin.rb +1 -1
- data/message_train.gemspec +2 -2
- data/spec/controllers/message_train/participants_controller_spec.rb +2 -2
- data/spec/dummy/app/models/user.rb +4 -4
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/public/capybara.html +11 -11
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 643b64859228388c4280a61d9530c45eb0f0a08d
|
4
|
+
data.tar.gz: bb43432c7eb367a70633db2ad05ae93f15b27d5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6429bef65560c118eb49f457988ad56451e64a407f83ab55b8ba3d1fd233d1816ee5344a737bdbe90d466b55b92b34188e2e81807841eb117e12f4cfafbf94df
|
7
|
+
data.tar.gz: 40b6b596b498d4a4db7fca577f9943d68fc0368d77d40584c2af873e724cdf662298ac09f59ea7800120dab816af704f26b93b942cd0cfa148acad1892846fef
|
data/README.rdoc
CHANGED
@@ -60,19 +60,20 @@ The `message_train` mixin takes the following options:
|
|
60
60
|
|
61
61
|
=== Smaller address book
|
62
62
|
|
63
|
-
By default, the address book will contain all objects of the current_user_method object's model type. To change this behavior, define an address book method on your
|
63
|
+
By default, the address book will contain all objects of the current_user_method object's model type. To change this behavior, define an address book method on your recipient models, something like this:
|
64
64
|
|
65
|
-
def
|
66
|
-
|
65
|
+
def self.valid_recipients_for(user)
|
66
|
+
# Supposing you use rolify
|
67
|
+
with_role(:friend, user)
|
67
68
|
end
|
68
69
|
|
69
70
|
And in your model:
|
70
71
|
|
71
|
-
message_train address_book_method: :
|
72
|
+
message_train address_book_method: :valid_recipients_for
|
72
73
|
|
73
74
|
Or in your initializer:
|
74
75
|
|
75
|
-
config.address_book_methods[:users] = :
|
76
|
+
config.address_book_methods[:users] = :valid_recipients_for
|
76
77
|
|
77
78
|
== View Helpers
|
78
79
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.7
|
@@ -58,16 +58,17 @@ function process_results(data) {
|
|
58
58
|
}
|
59
59
|
}
|
60
60
|
|
61
|
-
function add_tag_magic(
|
62
|
-
div = $(
|
63
|
-
|
64
|
-
|
65
|
-
|
61
|
+
function add_tag_magic(selector) {
|
62
|
+
var div = $(selector);
|
63
|
+
var model = div.data('model');
|
64
|
+
var request_string = '/box/in/participants/' + model + '.json';
|
65
|
+
$.getJSON(request_string, function(data){
|
66
|
+
var form = div.parents('form');
|
66
67
|
var suggestions = [];
|
67
68
|
$.each(data.participants, function (i, participant) {
|
68
69
|
suggestions.push(participant.slug);
|
69
70
|
});
|
70
|
-
tags = div.tags({
|
71
|
+
var tags = div.tags({
|
71
72
|
suggestions: suggestions,
|
72
73
|
tagSize: 'lg',
|
73
74
|
promptText: 'Comma separated list'
|
@@ -134,5 +135,7 @@ $(document).ready(function(){
|
|
134
135
|
$(this).find('.collapse').collapse('hide');
|
135
136
|
});
|
136
137
|
|
137
|
-
|
138
|
+
$('.recipient-input').each(function() {
|
139
|
+
add_tag_magic('#' + $(this).attr('id'));
|
140
|
+
});
|
138
141
|
});
|
@@ -2,13 +2,13 @@ module MessageTrain
|
|
2
2
|
class BoxesController < MessageTrain::ApplicationController
|
3
3
|
before_filter :load_conversations
|
4
4
|
|
5
|
-
# GET /box
|
5
|
+
# GET /box/:division
|
6
6
|
def show
|
7
7
|
@conversations = @conversations.page(params[:page])
|
8
8
|
render :show
|
9
9
|
end
|
10
10
|
|
11
|
-
# PATCH/PUT /box
|
11
|
+
# PATCH/PUT /box/:division
|
12
12
|
def update
|
13
13
|
if params[:mark_to_set].present? && @objects.present?
|
14
14
|
@box.mark(params[:mark_to_set], @objects)
|
@@ -16,7 +16,7 @@ module MessageTrain
|
|
16
16
|
respond_to_marking
|
17
17
|
end
|
18
18
|
|
19
|
-
# DELETE /box
|
19
|
+
# DELETE /box/:division
|
20
20
|
def destroy
|
21
21
|
if ['ignore', 'unignore'].include? params[:mark_to_set]
|
22
22
|
@box.send(params[:mark_to_set], @objects)
|
@@ -3,14 +3,14 @@ module MessageTrain
|
|
3
3
|
before_filter :load_conversation
|
4
4
|
after_filter :mark_as_read
|
5
5
|
|
6
|
-
# GET /box/
|
6
|
+
# GET /box/:division/conversations/:id
|
7
7
|
def show
|
8
8
|
@messages = @conversation.messages.page(params[:page])
|
9
9
|
render :show
|
10
10
|
@box.mark :read, @messages
|
11
11
|
end
|
12
12
|
|
13
|
-
# PATCH/PUT /box/
|
13
|
+
# PATCH/PUT /box/:division/conversations/:id
|
14
14
|
def update
|
15
15
|
if params[:mark_to_set].present? && @objects.present?
|
16
16
|
@box.mark params[:mark_to_set], @objects
|
@@ -18,7 +18,7 @@ module MessageTrain
|
|
18
18
|
respond_to_marking
|
19
19
|
end
|
20
20
|
|
21
|
-
# DELETE /box/
|
21
|
+
# DELETE /box/:division/conversations/:id
|
22
22
|
def destroy
|
23
23
|
if ['ignore', 'unignore'].include? params[:mark_to_set]
|
24
24
|
@box.send(params[:mark_to_set], @conversation)
|
@@ -9,19 +9,19 @@ module MessageTrain
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
# GET /box/
|
12
|
+
# GET /box/:division/messages/new
|
13
13
|
def new
|
14
14
|
@message = @box.new_message(conversation_id: params[:conversation_id])
|
15
15
|
end
|
16
16
|
|
17
|
-
# GET /box/
|
17
|
+
# GET /box/:division/messages/:id/edit
|
18
18
|
def edit
|
19
19
|
unless @message.draft
|
20
20
|
raise ActiveRecord::RecordNotFound
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
# POST /box/
|
24
|
+
# POST /box/:division/messages
|
25
25
|
def create
|
26
26
|
@message = @box.send_message(message_params)
|
27
27
|
if @box.errors.all.empty?
|
@@ -36,7 +36,7 @@ module MessageTrain
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
# PATCH/PUT /box/
|
39
|
+
# PATCH/PUT /box/:division/messages/:id
|
40
40
|
def update
|
41
41
|
unless @message.draft
|
42
42
|
raise ActiveRecord::RecordNotFound
|
@@ -67,7 +67,7 @@ module MessageTrain
|
|
67
67
|
:body,
|
68
68
|
:draft,
|
69
69
|
attachments: [:attachment],
|
70
|
-
recipients_to_save: MessageTrain.configuration.recipient_tables
|
70
|
+
recipients_to_save: MessageTrain.configuration.recipient_tables.keys
|
71
71
|
)
|
72
72
|
end
|
73
73
|
end
|
@@ -3,14 +3,14 @@ module MessageTrain
|
|
3
3
|
before_filter :load_participants
|
4
4
|
before_filter :load_participant, only: :show
|
5
5
|
|
6
|
-
# GET /box/
|
6
|
+
# GET /box/:division/participants/:model
|
7
7
|
def index
|
8
8
|
respond_to do |format|
|
9
9
|
format.json { render :index }
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
# GET /box/
|
13
|
+
# GET /box/:division/participants/:model/:id
|
14
14
|
def show
|
15
15
|
respond_to do |format|
|
16
16
|
format.json { render :show }
|
@@ -20,12 +20,20 @@ module MessageTrain
|
|
20
20
|
private
|
21
21
|
|
22
22
|
def load_participants
|
23
|
+
if params[:model].nil?
|
24
|
+
raise ActiveRecord::RecordNotFound
|
25
|
+
end
|
26
|
+
model_sym = params[:model].to_sym
|
27
|
+
model = MessageTrain.configuration.recipient_tables[model_sym].constantize
|
28
|
+
method = MessageTrain.configuration.address_book_methods[model_sym]
|
29
|
+
fallback_method = MessageTrain.configuration.address_book_method
|
23
30
|
current_participant = send(MessageTrain.configuration.current_user_method)
|
24
|
-
method
|
25
|
-
|
26
|
-
|
31
|
+
if !method.nil? && model.respond_to?(method)
|
32
|
+
@participants = model.send(method, current_participant)
|
33
|
+
elsif !fallback_method.nil? && model.respond_to?(fallback_method)
|
34
|
+
@participants = model.send(fallback_method, current_participant)
|
27
35
|
else
|
28
|
-
@participants =
|
36
|
+
@participants = model.all
|
29
37
|
end
|
30
38
|
end
|
31
39
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
- resource = message.new_record? ? message_train.box_messages_path(@box) : message_train.box_message_path(@box, message)
|
2
2
|
= bootstrap_form_for message, url: resource do |f|
|
3
|
-
- MessageTrain.configuration.recipient_tables.each do |table_sym|
|
3
|
+
- MessageTrain.configuration.recipient_tables.each do |table_sym, class_name|
|
4
4
|
= render partial: 'message_train/participants/field', locals: { message: message, field_name: table_sym }
|
5
5
|
= f.text_field :subject
|
6
6
|
= f.text_area :body
|
@@ -1,4 +1,4 @@
|
|
1
1
|
.form-group
|
2
2
|
%label.control-label= "#{field_name.to_s.singularize.humanize.titleize} Recipients"
|
3
|
-
.recipient-input.tag-list{ data: { field_name: "message[recipients_to_save][#{field_name}]" }, id: "message_recipients_to_save_#{field_name}" }
|
3
|
+
.recipient-input.tag-list{ data: { field_name: "message[recipients_to_save][#{field_name}]", model: field_name }, id: "message_recipients_to_save_#{field_name}" }
|
4
4
|
.tag-data= message.recipients_to_save[field_name]
|
@@ -2,4 +2,4 @@ json.id participant.id
|
|
2
2
|
json.model_name participant.class.name
|
3
3
|
json.slug box_participant_slug(participant)
|
4
4
|
json.name box_participant_name(participant)
|
5
|
-
json.path message_train.
|
5
|
+
json.path message_train.box_model_participant_path(@box, participant.class.table_name, participant.id)
|
data/config/routes.rb
CHANGED
@@ -3,7 +3,8 @@ MessageTrain::Engine.routes.draw do
|
|
3
3
|
resources :boxes, path: 'box', param: :division, only: [:show, :update, :destroy] do
|
4
4
|
resources :conversations, only: [:show, :update, :destroy]
|
5
5
|
resources :messages, except: [:index, :destroy]
|
6
|
-
|
6
|
+
get 'participants/:model', as: :model_participants, to: 'participants#index'
|
7
|
+
get 'participants/:model/:id', as: :model_participant, to: 'participants#show'
|
7
8
|
end
|
8
9
|
end
|
9
10
|
|
@@ -21,13 +21,13 @@ module MessageTrain
|
|
21
21
|
:recipient_tables
|
22
22
|
|
23
23
|
def initialize
|
24
|
-
self.recipient_tables =
|
24
|
+
self.recipient_tables = {}
|
25
25
|
self.slug_columns = { users: :slug }
|
26
26
|
self.name_columns = { users: :name }
|
27
27
|
self.current_user_method = :current_user
|
28
28
|
self.user_sign_in_path = '/users/sign_in'
|
29
29
|
self.user_route_authentication_method = :user
|
30
|
-
self.address_book_method = :address_book
|
30
|
+
self.address_book_method = :address_book # This is a fallback
|
31
31
|
self.address_book_methods = {}
|
32
32
|
end
|
33
33
|
|
data/lib/message_train/mixin.rb
CHANGED
data/message_train.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: message_train 0.1.
|
5
|
+
# stub: message_train 0.1.7 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "message_train"
|
9
|
-
s.version = "0.1.
|
9
|
+
s.version = "0.1.7"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
@@ -11,7 +11,7 @@ describe MessageTrain::ParticipantsController do
|
|
11
11
|
|
12
12
|
describe "GET #index" do
|
13
13
|
before do
|
14
|
-
get :index, box_division: 'in', format: :json
|
14
|
+
get :index, box_division: 'in', model: 'users', format: :json
|
15
15
|
end
|
16
16
|
it_should_behave_like 'a successful page', which_renders: 'index'
|
17
17
|
|
@@ -23,7 +23,7 @@ describe MessageTrain::ParticipantsController do
|
|
23
23
|
|
24
24
|
describe "GET #show" do
|
25
25
|
before do
|
26
|
-
get :show, box_division: 'in', id: first_user.id, format: :json
|
26
|
+
get :show, box_division: 'in', model: 'users', id: first_user.id, format: :json
|
27
27
|
end
|
28
28
|
it_should_behave_like 'a successful page', which_renders: 'show'
|
29
29
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'group' #TODO This is a hack to get the group model to load in
|
1
|
+
require 'group' #TODO This is a hack to get the group model to load in development. Works, but for how long?
|
2
2
|
|
3
3
|
class User < ActiveRecord::Base
|
4
4
|
# Rolify Gem
|
@@ -15,9 +15,9 @@ class User < ActiveRecord::Base
|
|
15
15
|
:recoverable, :rememberable, :trackable, :validatable
|
16
16
|
|
17
17
|
# MessageTrain Gem
|
18
|
-
message_train
|
18
|
+
message_train name_column: :display_name, address_book_method: :valid_recipients_for
|
19
19
|
|
20
|
-
def
|
21
|
-
|
20
|
+
def self.valid_recipients_for(sender)
|
21
|
+
all
|
22
22
|
end
|
23
23
|
end
|
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|
@@ -28,24 +28,24 @@ Message Train
|
|
28
28
|
<div id="navbar-to-collapse" class="collapse navbar-collapse">
|
29
29
|
<ul class="nav navbar-nav navbar-right">
|
30
30
|
<li class="dropdown ">
|
31
|
-
<a role="button" id="
|
31
|
+
<a role="button" id="1440524439.1923783" href="#" data-toggle="dropdown" class="dropdown-toggle">
|
32
32
|
Inbox <span class="badge ">
|
33
|
-
|
33
|
+
14
|
34
34
|
</span>
|
35
35
|
|
36
36
|
<b class="caret"></b>
|
37
37
|
</a>
|
38
|
-
<ul role="menu" class="dropdown-menu" aria-labelledby="
|
38
|
+
<ul role="menu" class="dropdown-menu" aria-labelledby="1440524439.1923783">
|
39
39
|
<li class="">
|
40
40
|
<a href="/box/in">Inbox <span class="badge badge-info pull-right">
|
41
|
-
|
41
|
+
14
|
42
42
|
</span>
|
43
43
|
</a>
|
44
44
|
</li>
|
45
45
|
|
46
46
|
<li class="">
|
47
47
|
<a href="/box/sent">Sent Messages <span class="badge badge-info pull-right">
|
48
|
-
|
48
|
+
13
|
49
49
|
</span>
|
50
50
|
</a>
|
51
51
|
</li>
|
@@ -107,7 +107,7 @@ Inbox <span class="badge ">
|
|
107
107
|
<li class="list-group-item">
|
108
108
|
<a href="/box/in">Inbox</a>
|
109
109
|
<span class="badge ">
|
110
|
-
|
110
|
+
14
|
111
111
|
</span>
|
112
112
|
|
113
113
|
</li>
|
@@ -115,7 +115,7 @@ Inbox <span class="badge ">
|
|
115
115
|
<li class="list-group-item">
|
116
116
|
<a href="/box/sent">Sent Messages</a>
|
117
117
|
<span class="badge ">
|
118
|
-
|
118
|
+
13
|
119
119
|
</span>
|
120
120
|
|
121
121
|
</li>
|
@@ -164,15 +164,15 @@ Inbox <span class="badge ">
|
|
164
164
|
|
165
165
|
</div>
|
166
166
|
<form method="post" accept-charset="UTF-8" action="/box/in/messages" id="new_message" class="new_message" role="form"><input type="hidden" value="✓" name="utf8" /><div class="form-group">
|
167
|
-
<label class="control-label">
|
168
|
-
<div id="
|
167
|
+
<label class="control-label">Group Recipients</label>
|
168
|
+
<div id="message_recipients_to_save_groups" data-model="groups" data-field-name="message[recipients_to_save][groups]" class="recipient-input tag-list bootstrap-tags bootstrap-3" style="padding-bottom: 2.6px;">
|
169
169
|
<div class="tag-data"></div>
|
170
170
|
<div class="tags"></div><input type="text" class="form-control tags-input input-lg" placeholder="Comma separated list" style="padding-left: 12px; padding-top: 0px; width: 663px;" /><ul class="tags-suggestion-list dropdown-menu"></ul></div>
|
171
171
|
</div>
|
172
172
|
|
173
173
|
<div class="form-group">
|
174
|
-
<label class="control-label">
|
175
|
-
<div id="
|
174
|
+
<label class="control-label">User Recipients</label>
|
175
|
+
<div id="message_recipients_to_save_users" data-model="users" data-field-name="message[recipients_to_save][users]" class="recipient-input tag-list bootstrap-tags bootstrap-3" style="padding-bottom: 2.6px;">
|
176
176
|
<div class="tag-data"></div>
|
177
177
|
<div class="tags"></div><input type="text" class="form-control tags-input input-lg" placeholder="Comma separated list" style="padding-left: 12px; padding-top: 0px; width: 663px;" /><ul class="tags-suggestion-list dropdown-menu"></ul></div>
|
178
178
|
</div>
|