Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added ability to send/recieve messages
- Loading branch information
Jeff Dickey
committed
Dec 4, 2011
1 parent
d683518
commit 0b1cf1a
Showing
30 changed files
with
726 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,15 @@ | ||
source "http://rubygems.org" | ||
|
||
# Declare your gem's dependencies in messaging.gemspec. | ||
# Bundler will treat runtime dependencies like base dependencies, and | ||
# development dependencies will be added by default to the :development group. | ||
gemspec | ||
|
||
# jquery-rails is used by the dummy application | ||
gem 'haml' | ||
gem 'devise' | ||
gem 'simple_form' | ||
gem 'mailboxer' | ||
gem "jquery-rails" | ||
gem 'coffee-rails' | ||
gem 'sass-rails' | ||
|
||
# Declare any dependencies that are still in development here instead of in | ||
# your gemspec. These might include edge Rails or gems from your path or | ||
# Git. Remember to move these dependencies to your gemspec before releasing | ||
# your gem to rubygems.org. | ||
|
||
# To use debugger | ||
# gem 'ruby-debug19', :require => 'ruby-debug' | ||
group :development, :test do | ||
gem 'sqlite3' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,6 @@ | |
// the compiled file. | ||
// | ||
//= require jquery | ||
//= require jquery-ui | ||
//= require jquery_ujs | ||
//= require_tree . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
split = (val) -> | ||
val.split /,\s*/ | ||
|
||
extractLast = (term) -> | ||
split(term).pop() | ||
|
||
$ -> | ||
|
||
recipients = $('#message_recipients').data('autocomplete-source') | ||
console.log recipients | ||
|
||
# don't navigate away from the field on tab when selecting an item | ||
$('#message_recipients').bind "keydown", (event) -> | ||
if event.keyCode == $.ui.keyCode.TAB and $(@).data("autocomplete").menu.active then event.preventDefault() | ||
$('#message_recipients').autocomplete | ||
minLength: 0 | ||
source: (request, response) -> | ||
# delegate back to autocomplete, but extract the last term | ||
recipients = $('#message_recipients').data('autocomplete-source') | ||
console.log recipients | ||
response $.ui.autocomplete.filter(recipients, extractLast(request.term)) | ||
focus: -> return false # prevent last value inserted on focus | ||
select: (event, ui) -> | ||
terms = split(@value) | ||
# remove the current input | ||
terms.pop() | ||
# add the selected item | ||
terms.push ui.item.value | ||
# add placeholder to get the comma-and-space at the end | ||
terms.push "" | ||
@value = terms.join ", " | ||
return false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
ul.ui-autocomplete | ||
position: absolute | ||
list-style: none | ||
margin: 0 | ||
padding: 0 | ||
border: solid 1px #999 | ||
cursor: default | ||
li | ||
background-color: #FFF | ||
border-top: solid 1px #DDD | ||
margin: 0 | ||
padding: 0 | ||
a | ||
color: #000 | ||
display: block | ||
padding: 3px | ||
a.ui-state-hover, a.ui-state-active | ||
background-color: #FFFCB2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Messaging | ||
class MessagesController < ApplicationController | ||
def index | ||
@mailbox = current_user.mailbox | ||
end | ||
|
||
def new | ||
@message = Message.new | ||
end | ||
|
||
def create | ||
@message = Message.new params[:message] | ||
unless @message.valid? | ||
return render :new | ||
end | ||
|
||
puts @message.recipients.first.email | ||
current_user.send_message(@message.recipients, @message.body, @message.subject) | ||
flash[:notice] = "Message sent." | ||
|
||
redirect_to root_path | ||
end | ||
|
||
def show | ||
@conversation = Conversation.find_by_id(params[:id]) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Messaging | ||
class Message | ||
include ActiveModel::Validations | ||
include ActiveModel::Conversion | ||
extend ActiveModel::Naming | ||
|
||
attr_accessor :recipients, :subject, :body | ||
|
||
validates :recipients, presence: true | ||
validates :subject, presence: true | ||
validates :body, presence: true | ||
|
||
def initialize(attributes = {}) | ||
attributes.each do |name, value| | ||
send("#{name}=", value) | ||
end | ||
end | ||
|
||
def persisted? | ||
false | ||
end | ||
|
||
|
||
def recipients | ||
@recipient_list | ||
end | ||
|
||
def recipients=(string='') | ||
@recipient_list = [] | ||
string.split(',').each do |s| | ||
@recipient_list << User.find_by_email!(s.strip) unless s.blank? | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
!!! | ||
%html | ||
%head | ||
%title Messaging | ||
= stylesheet_link_tag "messaging/application" | ||
= javascript_include_tag "messaging/application" | ||
= csrf_meta_tags | ||
%body | ||
= yield |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
%h1 Messages | ||
%h2 Inbox | ||
%ul | ||
- @mailbox.inbox.each do |m| | ||
%li= link_to m.subject, message_path(m) | ||
%nav | ||
= link_to "Compose message", new_message_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
= simple_form_for @message do |f| | ||
= f.input :recipients, input_html: { data: { autocomplete_source: User.all.map(&:name) } } | ||
= f.input :subject | ||
= f.input :body, as: :text | ||
= f.button :submit, 'Send message' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
%ul | ||
- @conversation.messages.each do |message| | ||
%li | ||
%h2.subject= message.subject | ||
.from= message.sender | ||
.body= message.body |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
Messaging::Engine.routes.draw do | ||
resources :messages | ||
root to: 'messages#index' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class HomeController < ApplicationController | ||
def index | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class User < ActiveRecord::Base | ||
# Include default devise modules. Others available are: | ||
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable | ||
devise :database_authenticatable, :registerable, | ||
:recoverable, :rememberable, :trackable, :validatable | ||
|
||
# Setup accessible (or protected) attributes for your model | ||
attr_accessible :email, :password, :password_confirmation, :remember_me | ||
|
||
acts_as_messageable | ||
|
||
def name | ||
self.to_s | ||
end | ||
|
||
def mailboxer_email(message) | ||
end | ||
|
||
def to_s | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
%p Welcome the the Mailboxer Messenger Dummy app. | ||
%nav | ||
- if current_user | ||
= link_to "Inbox", messaging_path | ||
= link_to "Sign out", destroy_user_session_path, method: :delete | ||
- else | ||
= link_to "Register", new_user_registration_path | ||
= link_to "Sign in", new_user_session_path |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
!!! | ||
%html | ||
%head | ||
%title Mailboxer Messenger Dummy App | ||
= stylesheet_link_tag "application" | ||
= javascript_include_tag "application" | ||
= csrf_meta_tags | ||
%body | ||
#alert= alert | ||
#notice= notice | ||
= yield |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.