message_train 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e3ef63d3e6977148dded39c433adbef1ac11240
4
- data.tar.gz: 84b2abf62ebfd21b001a4c567914be08632b336e
3
+ metadata.gz: 643b64859228388c4280a61d9530c45eb0f0a08d
4
+ data.tar.gz: bb43432c7eb367a70633db2ad05ae93f15b27d5c
5
5
  SHA512:
6
- metadata.gz: 37a59f9a665e6fba41e8bfc13e896cca8b50c134357af69a3a4cf5ab1a075c9d1fe13ff3aec6636d4fe98d65948ecda2bda901d3aa87bd0b0599e84480387cfb
7
- data.tar.gz: 8449e580987a14bf4b79649e71a39d0a47e60e30111d4316a3ff001d0ae4ee21191fb78a86d5c7d4ef935b0aac3b5c03adb48cb86119f5ee3ee03fe5561137ac
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 user model, something like this:
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 address_book
66
- friends
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: :address_book
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] = :address_book
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.6
1
+ 0.1.7
@@ -58,16 +58,17 @@ function process_results(data) {
58
58
  }
59
59
  }
60
60
 
61
- function add_tag_magic(node) {
62
- div = $(node);
63
- $.getJSON('/box/in/participants.json', function(data){
64
- input = div.children('input');
65
- form = div.parents('form');
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
- add_tag_magic(".recipient-input");
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/in
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/in
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/in
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/in/conversations/1
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/in/conversations/1
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/in/conversations/1
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/in/messages/new
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/in/messages/1/edit
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/in/messages
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/in/messages/1
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/in/participants
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/in/participants/1
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 = MessageTrain.configuration.address_book_method
25
- if current_participant.respond_to? method
26
- @participants = current_participant.send(method)
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 = current_participant.class.all
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.box_participant_path(@box, participant.id)
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
- resources :participants, only: [:index, :show]
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 = [ :users ]
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
 
@@ -32,7 +32,7 @@ module MessageTrain
32
32
  end
33
33
 
34
34
  if relationships.include? :recipient
35
- config.recipient_tables |= [table_sym] # This adds the table to the array if not present
35
+ config.recipient_tables[table_sym] = name
36
36
  end
37
37
  end
38
38
 
@@ -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.6 ruby lib
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.6"
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 production. Works, but for how long?
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 slug_column: :slug, name_column: :display_name
18
+ message_train name_column: :display_name, address_book_method: :valid_recipients_for
19
19
 
20
- def contacts
21
- User.all + Group.all
20
+ def self.valid_recipients_for(sender)
21
+ all
22
22
  end
23
23
  end
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="1440294236.5479236" href="#" data-toggle="dropdown" class="dropdown-toggle">
31
+ <a role="button" id="1440524439.1923783" href="#" data-toggle="dropdown" class="dropdown-toggle">
32
32
  Inbox <span class="badge ">
33
- 15
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="1440294236.5479236">
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
- 15
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
- 12
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
- 15
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
- 12
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">User Recipients</label>
168
- <div id="message_recipients_to_save_users" data-field-name="message[recipients_to_save][users]" class="recipient-input tag-list bootstrap-tags bootstrap-3" style="padding-bottom: 2.6px;">
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">Group Recipients</label>
175
- <div id="message_recipients_to_save_groups" data-field-name="message[recipients_to_save][groups]" class="recipient-input tag-list bootstrap-tags bootstrap-3" style="padding-bottom: 2.6px;">
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>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: message_train
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karen Lundgren