Skip to content

Commit

Permalink
Send new private messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
fredwu committed Jul 12, 2011
1 parent 92a2538 commit 1b5cd60
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 4 deletions.
16 changes: 16 additions & 0 deletions app/assets/javascripts/concerns/form.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,21 @@ jQuery ->
e.preventDefault()
)

# AutoSuggest
$('.multi_add input').autoSuggest(
'/' + $('.multi_add').data('target'),
asHtmlID: $('.multi_add').data('target')
startText: $('.multi_add').data('start_text')
selectionLimit: ($('.multi_add').data('selection_limit') || false)
limitText: window.label.no_more_selections_allowed
selectedValuesProp: 'id'
selectedItemProp: 'name'
searchObjProps: 'name'
preFill: $('.multi_add input').data('source')
)
$('.multi_add').parents('form').submit(->
$('.multi_add input').attr('value', $('input#as-values-' + $('.multi_add').data('target')).attr('value')[1..-2])
)

# read only forms
$('.read_only form :input:not([type=submit])').attr('disabled', 'disabled')
4 changes: 4 additions & 0 deletions app/assets/stylesheets/style.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ div.message {
margin-left: $input_margin;
}

#new_private_message .as-results {
margin-left: 0;
}

/* ------------------------------
form
------------------------------ */
Expand Down
9 changes: 9 additions & 0 deletions app/controllers/messages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ def create
end
end

def send_private_message
result = current_user.send_private_message(User.find(params[:users]), params[:message][:content])

respond_to do |format|
format.json { render :json => result }
format.html { redirect_to :back }
end
end

def show_private_message
@topic = Message.topics.find(params[:id])
end
Expand Down
7 changes: 7 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ class UsersController < ApplicationController

before_filter :hide_sidebar, :only => [:show, :message_inboxes]

def index
respond_to do |format|
format.json { render :json => collection.for_auto_suggest }
format.html { render 'users/_index', :locals => { :meta => {} } }
end
end

def home
@micro_posts = resource.followed_micro_posts.page(params[:p])
end
Expand Down
10 changes: 10 additions & 0 deletions app/views/messages/_index.html.slim
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
- if meta[:new_message?]
h1= params[:type].titleize
#new_private_message
= simple_form_for Message.new, :url => my_private_messages_path do |f|
.multi_add.input.string data-target="users" data-start_text="#{t('text.enter_recipient_names')}" data-selection_limit="#{Settings.recipient_limit.private_messages}"
= label_tag :users, t('label.recipients')
= text_field_tag :users, User.all.map(&:id).join(','), :class => 'string required'
= f.input :content
= f.button :submit
.clear
- if collection.any?
ul#messages
- collection.each do |resource|
Expand Down
4 changes: 2 additions & 2 deletions app/views/proposals/_form.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ ul#proposal_section_selector.multistage_selector
= simple_form_for resource, :url => submit_path, :validate => true, :html => { :class => 'multistage' } do |f|
fieldset#investors
legend= t('label.investors')
.multi_add.input.string
.multi_add.input.string data-target="investors" data-start_text="#{t('text.enter_investor_names')}" data-selection_limit="#{Settings.recipient_limit.proposals}"
= label_tag :investors, t('label.investors')
= text_field_tag :investors, resource.investors.map(&:id).join(','), :class => 'string required', :'data-investors' => resource.investors.for_auto_suggest.to_json
= text_field_tag :investors, resource.investors.map(&:id).join(','), :class => 'string required', :'data-source' => resource.investors.for_auto_suggest.to_json
.grouped_buttons
= submit_tag t('label.next'), :class => 'navigation next'
fieldset#product
Expand Down
1 change: 1 addition & 0 deletions app/views/users/_message_inboxes.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ ul
li= link_to_current t('label.inbox_messages'), my_message_inbox_path(:inbox_messages)
li= link_to_current t('label.sent_messages') , my_message_inbox_path(:sent_messages)
li= link_to_current t('label.archived_messages') , my_message_inbox_path(:archived_messages)

hr
h3= t('label.startup_proposals')
ul
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/message_inboxes.html.slim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.grid_3
= render 'message_inboxes'
.grid_9
= render 'messages/index', :collection => @messages, :meta => { :linkable => true }
= render 'messages/index', :collection => @messages, :meta => { :linkable => true, :new_message? => true }
4 changes: 4 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ en:
inbox_proposals: Inbox proposals
sent_proposals: Sent proposals
archived_proposals: Archived proposals
recipients: Recipients
message:
proposal_saved: The proposal has been saved!
proposal_submitted: The proposal has been submitted to the investors!
Expand All @@ -139,3 +140,6 @@ en:
not_an_investor: You are not an investor,
no_invested_startups_found: No invested startups found.
default_text_for_proposal_review: Please review this proposal.
enter_recipient_names: Recipient name ...
enter_investor_names: Investor names ...
no_more_selections_allowed: No more selections are allowed.
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
AngelNest::Application.routes.draw do
devise_for :users

resources :users, :except => :index do
resources :users do
resources :startups
resource :investor
end
Expand All @@ -28,6 +28,7 @@

match 'my/profile' => 'users#show', :via => :get
match 'my/home' => 'users#home', :via => :get
match 'my/private_messages' => 'messages#send_private_message', :via => :post, :as => :my_private_messages
match 'my/private_messages/:id' => 'messages#show_private_message', :via => :get, :as => :my_private_message
match 'my/private_messages/:id' => 'messages#reply_private_message', :via => :post, :as => :my_private_message
match 'my/message_inboxes(/:type)' => 'users#message_inboxes', :via => :get, :as => :my_message_inbox
Expand Down
3 changes: 3 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
currencies:
- USD
- CNY
recipient_limit:
private_messages: 1
proposals: 5
group:
logo:
full:
Expand Down
7 changes: 7 additions & 0 deletions spec/controllers/messages_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
current_user.send_private_message(target_user, 'Hello there!')
end

it "sends a message (topic)" do
post :send_private_message, :users => target_user.id, :message => { :content => 'Hello world!' }

current_user.outgoing_messages.count.should == 2
current_user.outgoing_messages[1].content.should == 'Hello world!'
end

it "shows a topic" do
get :show_private_message, :id => 1

Expand Down

0 comments on commit 1b5cd60

Please sign in to comment.