carrier 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +27 -0
- data/LICENSE.txt +20 -0
- data/MIT-LICENSE +20 -0
- data/README.textile +111 -0
- data/Rakefile +48 -0
- data/VERSION +1 -0
- data/app/assets/images/.gitkeep +0 -0
- data/app/assets/javascripts/autocomplete.js +4 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery-ui-i18n.js +1379 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-af.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-ar-DZ.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-ar.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-az.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-bg.js +24 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-bs.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-ca.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-cs.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-da.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-de.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-el.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-en-AU.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-en-GB.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-en-NZ.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-eo.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-es.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-et.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-eu.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-fa.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-fi.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-fo.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-fr-CH.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-fr.js +25 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-gl.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-he.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-hr.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-hu.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-hy.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-id.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-is.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-it.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-ja.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-ko.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-kz.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-lt.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-lv.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-ml.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-ms.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-nl.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-no.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-pl.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-pt-BR.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-pt.js +22 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-rm.js +21 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-ro.js +26 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-ru.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-sk.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-sl.js +24 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-sq.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-sr-SR.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-sr.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-sv.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-ta.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-th.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-tj.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-tr.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-uk.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-vi.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-zh-CN.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-zh-HK.js +23 -0
- data/app/assets/javascripts/autocomplete/i18n/jquery.ui.datepicker-zh-TW.js +23 -0
- data/app/assets/javascripts/autocomplete/jquery.ui.autocomplete.min.js +32 -0
- data/app/assets/javascripts/autocomplete/jquery.ui.core.min.js +17 -0
- data/app/assets/javascripts/autocomplete/jquery.ui.position.min.js +16 -0
- data/app/assets/javascripts/autocomplete/jquery.ui.widget.min.js +15 -0
- data/app/assets/javascripts/carrier.js +8 -0
- data/app/assets/javascripts/jquery.min.js +16 -0
- data/app/assets/javascripts/rails.js +169 -0
- data/app/assets/javascripts/rich-multiselect/jquery-ui.min.js +405 -0
- data/app/assets/javascripts/rich-multiselect/locale/ui-multiselect-de.js +11 -0
- data/app/assets/javascripts/rich-multiselect/locale/ui-multiselect-en.js +11 -0
- data/app/assets/javascripts/rich-multiselect/locale/ui-multiselect-es.js +11 -0
- data/app/assets/javascripts/rich-multiselect/locale/ui-multiselect-fr.js +11 -0
- data/app/assets/javascripts/rich-multiselect/locale/ui-multiselect-it.js +13 -0
- data/app/assets/javascripts/rich-multiselect/plugins/localisation/jquery.localisation-min.js +7 -0
- data/app/assets/javascripts/rich-multiselect/plugins/localisation/jquery.localisation-pack.js +7 -0
- data/app/assets/javascripts/rich-multiselect/plugins/localisation/jquery.localisation.js +99 -0
- data/app/assets/javascripts/rich-multiselect/plugins/scrollTo/README.txt +37 -0
- data/app/assets/javascripts/rich-multiselect/plugins/scrollTo/changes.txt +82 -0
- data/app/assets/javascripts/rich-multiselect/plugins/scrollTo/jquery.scrollTo-min.js +11 -0
- data/app/assets/javascripts/rich-multiselect/plugins/scrollTo/jquery.scrollTo.js +207 -0
- data/app/assets/javascripts/rich-multiselect/ui.multiselect.js +339 -0
- data/app/assets/stylesheets/carrier.css +227 -0
- data/app/assets/stylesheets/carrier_rich.css +48 -0
- data/app/assets/stylesheets/carrier_simple.css +15 -0
- data/app/assets/stylesheets/rich-multiselect/ui.multiselect.css +30 -0
- data/app/assets/stylesheets/ui-lightness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/app/assets/stylesheets/ui-lightness/images/ui-bg_flat_55_fbf9ee_40x100.png +0 -0
- data/app/assets/stylesheets/ui-lightness/images/ui-bg_flat_65_ffffff_40x100.png +0 -0
- data/app/assets/stylesheets/ui-lightness/images/ui-bg_flat_75_cccccc_40x100.png +0 -0
- data/app/assets/stylesheets/ui-lightness/images/ui-bg_flat_75_dadada_40x100.png +0 -0
- data/app/assets/stylesheets/ui-lightness/images/ui-bg_flat_75_e6e6e6_40x100.png +0 -0
- data/app/assets/stylesheets/ui-lightness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/app/assets/stylesheets/ui-lightness/images/ui-bg_flat_95_fef1ec_40x100.png +0 -0
- data/app/assets/stylesheets/ui-lightness/images/ui-icons_222222_256x240.png +0 -0
- data/app/assets/stylesheets/ui-lightness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/app/assets/stylesheets/ui-lightness/images/ui-icons_454545_256x240.png +0 -0
- data/app/assets/stylesheets/ui-lightness/images/ui-icons_888888_256x240.png +0 -0
- data/app/assets/stylesheets/ui-lightness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/app/assets/stylesheets/ui-lightness/jquery-ui-1.8.14.custom.css +342 -0
- data/app/controllers/carrier/application_controller.rb +5 -0
- data/app/controllers/carrier/chains_controller.rb +16 -0
- data/app/controllers/carrier/messages_controller.rb +59 -0
- data/app/helpers/carrier/application_helper.rb +26 -0
- data/app/helpers/carrier/post_helper.rb +4 -0
- data/app/models/carrier/chain.rb +59 -0
- data/app/models/carrier/message.rb +118 -0
- data/app/models/carrier/message/scopes.rb +51 -0
- data/app/models/carrier/message/subject.rb +25 -0
- data/app/models/carrier/message/validations.rb +7 -0
- data/app/validators/recipients/exclude_self.rb +10 -0
- data/app/validators/recipients/recipients_validator.rb +10 -0
- data/app/views/carrier/chains/archive.js.erb +1 -0
- data/app/views/carrier/chains/unarchive.js.erb +1 -0
- data/app/views/carrier/messages/_archive_chain.html.erb +6 -0
- data/app/views/carrier/messages/_form.html.erb +30 -0
- data/app/views/carrier/messages/_head.html.erb +8 -0
- data/app/views/carrier/messages/_index_message.html.erb +13 -0
- data/app/views/carrier/messages/_message_collapsed.html.erb +12 -0
- data/app/views/carrier/messages/_message_expanded.html.erb +10 -0
- data/app/views/carrier/messages/_nav_messages.html.erb +15 -0
- data/app/views/carrier/messages/_reply.html.erb +19 -0
- data/app/views/carrier/messages/as_sent.html.erb +36 -0
- data/app/views/carrier/messages/collapsed.js.erb +1 -0
- data/app/views/carrier/messages/create.js.erb +1 -0
- data/app/views/carrier/messages/expanded.js.erb +1 -0
- data/app/views/carrier/messages/index.html.erb +9 -0
- data/app/views/carrier/messages/new.html.erb +7 -0
- data/app/views/carrier/messages/new.js.erb +1 -0
- data/app/views/carrier/messages/reply.js.erb +6 -0
- data/app/views/carrier/messages/rich/_multiselect.html.erb +18 -0
- data/app/views/carrier/messages/rich/_recipients.html.erb +6 -0
- data/app/views/carrier/messages/show.html.erb +35 -0
- data/app/views/carrier/messages/simple/_autocomplete.html.erb +45 -0
- data/app/views/carrier/messages/simple/_autocomplete_includes.html.erb +7 -0
- data/app/views/carrier/messages/simple/_recipients.html.erb +3 -0
- data/app/views/layouts/carrier/application.html.erb +16 -0
- data/app/views/partials/_error_messages_for.html.erb +9 -0
- data/carrier.gemspec +331 -0
- data/config/locales/carrier.en.yml +48 -0
- data/config/locales/carrier.ru.yml +48 -0
- data/config/routes.rb +24 -0
- data/db/migrate/001_create_messages.rb +26 -0
- data/db/migrate/002_create_chains.rb +34 -0
- data/db/migrate/003_create_read_marks +16 -0
- data/lib/carrier.rb +22 -0
- data/lib/carrier/configuration.rb +35 -0
- data/lib/carrier/configuration/models.rb +31 -0
- data/lib/carrier/configuration/ui.rb +28 -0
- data/lib/carrier/rails.rb +5 -0
- data/lib/carrier/rails/engine.rb +50 -0
- data/lib/carrier/rails/helpers.rb +30 -0
- data/lib/tasks/carrier_tasks.rake +4 -0
- data/script/rails +6 -0
- data/spec/carrier/app/controllers/application_controller_spec.rb +1 -0
- data/spec/carrier/app/models/message_scopes_spec.rb +25 -0
- data/spec/carrier/app/models/message_spec.rb +38 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +9 -0
- data/spec/dummy/app/assets/javascripts/default.js +2 -0
- data/spec/dummy/app/assets/javascripts/jquery.js +16 -0
- data/spec/dummy/app/assets/javascripts/jquery_ujs.js +169 -0
- data/spec/dummy/app/assets/javascripts/posts.js +2 -0
- data/spec/dummy/app/assets/stylesheets/application.css +7 -0
- data/spec/dummy/app/assets/stylesheets/default.css +4 -0
- data/spec/dummy/app/assets/stylesheets/posts.css +4 -0
- data/spec/dummy/app/assets/stylesheets/scaffold.css +56 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/default_controller.rb +5 -0
- data/spec/dummy/app/controllers/posts_controller.rb +83 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/helpers/default_helper.rb +2 -0
- data/spec/dummy/app/helpers/posts_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/models/post.rb +2 -0
- data/spec/dummy/app/models/user.rb +15 -0
- data/spec/dummy/app/views/default/index.html.erb +4 -0
- data/spec/dummy/app/views/devise/confirmations/new.html.erb +12 -0
- data/spec/dummy/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
- data/spec/dummy/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
- data/spec/dummy/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
- data/spec/dummy/app/views/devise/passwords/edit.html.erb +16 -0
- data/spec/dummy/app/views/devise/passwords/new.html.erb +12 -0
- data/spec/dummy/app/views/devise/registrations/edit.html.erb +25 -0
- data/spec/dummy/app/views/devise/registrations/new.html.erb +18 -0
- data/spec/dummy/app/views/devise/sessions/new.html.erb +17 -0
- data/spec/dummy/app/views/devise/shared/_links.erb +25 -0
- data/spec/dummy/app/views/devise/unlocks/new.html.erb +12 -0
- data/spec/dummy/app/views/layouts/application.html.erb +16 -0
- data/spec/dummy/app/views/posts/_form.html.erb +17 -0
- data/spec/dummy/app/views/posts/edit.html.erb +6 -0
- data/spec/dummy/app/views/posts/index.html.erb +21 -0
- data/spec/dummy/app/views/posts/new.html.erb +5 -0
- data/spec/dummy/app/views/posts/show.html.erb +5 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +51 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +26 -0
- data/spec/dummy/config/database_mysql.yml +29 -0
- data/spec/dummy/config/database_pgsql.yml +35 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +24 -0
- data/spec/dummy/config/environments/production.rb +52 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/carrier.rb +3 -0
- data/spec/dummy/config/initializers/devise.rb +204 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +12 -0
- data/spec/dummy/config/locales/devise.en.yml +53 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +15 -0
- data/spec/dummy/db/migrate/007_devise_create_users.rb +29 -0
- data/spec/dummy/db/migrate/20110130210000_create_read_marks.rb +16 -0
- data/spec/dummy/db/migrate/20110814064637_create_posts.rb +8 -0
- data/spec/dummy/db/migrate/20110814164228_create_messages.rb +26 -0
- data/spec/dummy/db/migrate/20110814164229_create_chains.rb +34 -0
- data/spec/dummy/db/schema.rb +79 -0
- data/spec/dummy/db/seeds.rb +26 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/test/fixtures/posts.yml +11 -0
- data/spec/dummy/test/fixtures/users.yml +11 -0
- data/spec/dummy/test/functional/default_controller_test.rb +9 -0
- data/spec/dummy/test/functional/posts_controller_test.rb +49 -0
- data/spec/dummy/test/unit/helpers/default_helper_test.rb +4 -0
- data/spec/dummy/test/unit/helpers/posts_helper_test.rb +4 -0
- data/spec/dummy/test/unit/post_test.rb +7 -0
- data/spec/dummy/test/unit/user_test.rb +7 -0
- data/spec/dummy_spec_helper.rb +70 -0
- data/spec/integration/carrier_spec.rb +71 -0
- data/spec/requests/main_spec.rb +31 -0
- data/spec/support/controller_macros.rb +10 -0
- data/spec/support/factories.rb +47 -0
- data/spec/support/rspec_helpers.rb +22 -0
- data/test/helper.rb +18 -0
- data/test/test_carrier.rb +7 -0
- metadata +450 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Carrier
|
3
|
+
class ChainsController < ApplicationController
|
4
|
+
def archive
|
5
|
+
@chain = Chain.find(params[:chain_id])
|
6
|
+
@user = User.find(params[:user_id])
|
7
|
+
@chain.archive_for!(@user)
|
8
|
+
end
|
9
|
+
|
10
|
+
def unarchive
|
11
|
+
@chain = Chain.find(params[:chain_id])
|
12
|
+
@user = User.find(params[:user_id])
|
13
|
+
@chain.unarchive_for!(@user)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Carrier
|
4
|
+
class MessagesController < ApplicationController
|
5
|
+
|
6
|
+
after_filter :only => [:as_sent, :show] { @message.mark_as_read! :for => current_user }
|
7
|
+
|
8
|
+
[:collapsed, :expanded].each do |mode|
|
9
|
+
define_method(mode) do
|
10
|
+
@message = Message.find(params[:id])
|
11
|
+
@message.mark_as_read! :for => current_user if mode == :expanded
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def reply
|
16
|
+
@message = Message.new_answer params[:id], current_user
|
17
|
+
end
|
18
|
+
|
19
|
+
def archive
|
20
|
+
@messages = Message.archived_messages_with(current_user).page params[:page]
|
21
|
+
render 'index'
|
22
|
+
end
|
23
|
+
|
24
|
+
def index
|
25
|
+
@messages = Message.messages_index(current_user).page params[:page]
|
26
|
+
end
|
27
|
+
|
28
|
+
def sent
|
29
|
+
@messages = Message.messages_sent(current_user).page params[:page]
|
30
|
+
render 'index'
|
31
|
+
end
|
32
|
+
|
33
|
+
def as_sent
|
34
|
+
@message = Message.find(params[:id], :include => :chain)
|
35
|
+
end
|
36
|
+
|
37
|
+
def show
|
38
|
+
@message = Message.find(params[:id], :include => :chain)
|
39
|
+
end
|
40
|
+
|
41
|
+
def new
|
42
|
+
@message = Message.new
|
43
|
+
end
|
44
|
+
|
45
|
+
def create
|
46
|
+
@message = Message.new(params[:message])
|
47
|
+
respond_to do |format|
|
48
|
+
if @message.save
|
49
|
+
format.html { redirect_to(as_sent_message_path(@message), :notice => 'Message successfully created!') }
|
50
|
+
format.js
|
51
|
+
else
|
52
|
+
format.js { render :action => "new" }
|
53
|
+
format.html { render :action => "new" }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Carrier
|
2
|
+
module ApplicationHelper
|
3
|
+
def error_messages_for(resource)
|
4
|
+
if resource.errors.any?
|
5
|
+
render :partial => "partials/error_messages_for", :locals => {:resource => resource}
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def archived? message
|
10
|
+
return false if !message || message.new_record?
|
11
|
+
message.archived_for? current_user
|
12
|
+
end
|
13
|
+
|
14
|
+
def b string
|
15
|
+
raw "<b>%s</b>" % string
|
16
|
+
end
|
17
|
+
|
18
|
+
def without_current_user
|
19
|
+
User.all.without(current_user).map{|user| "'#{user.username}'" }.join(', ')
|
20
|
+
end
|
21
|
+
|
22
|
+
def without_current_user_select
|
23
|
+
User.all.without(current_user).collect {|user| [user.username, user.id] }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Carrier
|
3
|
+
class Chain < ActiveRecord::Base
|
4
|
+
|
5
|
+
set_table_name Carrier.config.models.table_for :chain
|
6
|
+
|
7
|
+
serialize :participants, Array
|
8
|
+
serialize :archived_for, Array
|
9
|
+
|
10
|
+
paginates_per 25
|
11
|
+
|
12
|
+
has_many :messages, :order => "created_at"
|
13
|
+
|
14
|
+
accepts_nested_attributes_for :messages, :reject_if => proc { |attrs| attrs.all? {|k,v| v.blank?}}
|
15
|
+
|
16
|
+
belongs_to :having_chain, :polymorphic => true
|
17
|
+
|
18
|
+
def last_message
|
19
|
+
messages.last
|
20
|
+
end
|
21
|
+
|
22
|
+
def unarchive!
|
23
|
+
unarchive
|
24
|
+
self.save!
|
25
|
+
end
|
26
|
+
|
27
|
+
def unarchive
|
28
|
+
self.archived_for.clear
|
29
|
+
end
|
30
|
+
|
31
|
+
def unarchive_for!(user)
|
32
|
+
archived_for.delete(user.id)
|
33
|
+
save!
|
34
|
+
end
|
35
|
+
|
36
|
+
def archive_for!(user)
|
37
|
+
self.archived_for = (archived_for << user.id).uniq
|
38
|
+
self.save
|
39
|
+
end
|
40
|
+
|
41
|
+
def archived_for?(user)
|
42
|
+
archived_for.include?(user.id) ? true : false
|
43
|
+
end
|
44
|
+
|
45
|
+
def archived_for_any_user?
|
46
|
+
archived_for.any? ? true : false
|
47
|
+
end
|
48
|
+
|
49
|
+
def participants_names
|
50
|
+
participants.map{|p| User.find(p, :select => "username").username }
|
51
|
+
end
|
52
|
+
|
53
|
+
def participants!(participants_arr)
|
54
|
+
self.participants = participants_arr | participants
|
55
|
+
self.save!
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module Carrier
|
3
|
+
class Message < ActiveRecord::Base
|
4
|
+
set_table_name Carrier.config.models.table_for :message
|
5
|
+
|
6
|
+
concerned_with :scopes, :subject, :validations
|
7
|
+
|
8
|
+
serialize :recipients, Array
|
9
|
+
paginates_per 25
|
10
|
+
|
11
|
+
belongs_to :chain, :counter_cache => true
|
12
|
+
belongs_to :sender_user, :foreign_key => "sender", :class_name => "User"
|
13
|
+
|
14
|
+
delegate :archived_for?, :archived_for_any_user?, :participants!, :to => :chain
|
15
|
+
|
16
|
+
acts_as_readable :on => :created_at
|
17
|
+
|
18
|
+
attr_accessor :answers_to
|
19
|
+
|
20
|
+
before_create do
|
21
|
+
default_subject!
|
22
|
+
make_last
|
23
|
+
chain.unarchive! if chain_archived?
|
24
|
+
chain!
|
25
|
+
end
|
26
|
+
|
27
|
+
after_create do
|
28
|
+
Message.find(answers_to).clear_last! if answers_to
|
29
|
+
mark_as_read! :for => sender_user
|
30
|
+
participants! participants
|
31
|
+
end
|
32
|
+
|
33
|
+
class << self
|
34
|
+
def new_answer id, user
|
35
|
+
in_answer_to = find id
|
36
|
+
new :sender => user.id,
|
37
|
+
:recipients => find_recipients(in_answer_to, user),
|
38
|
+
:subject => re(in_answer_to.subject),
|
39
|
+
:chain_id => in_answer_to.chain_id,
|
40
|
+
:answers_to => in_answer_to.id
|
41
|
+
end
|
42
|
+
|
43
|
+
def find_recipients message, user
|
44
|
+
([message.sender] + message.recipients).without(user.id)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def chain_archived?
|
49
|
+
chain && archived_for_any_user?
|
50
|
+
end
|
51
|
+
|
52
|
+
def chain!
|
53
|
+
self.chain = Chain.create if !chain
|
54
|
+
end
|
55
|
+
|
56
|
+
def make_last
|
57
|
+
self.last = true
|
58
|
+
end
|
59
|
+
|
60
|
+
def & messages
|
61
|
+
messages & chain_messages
|
62
|
+
end
|
63
|
+
|
64
|
+
def answers
|
65
|
+
chain_messages.without self
|
66
|
+
end
|
67
|
+
|
68
|
+
def clear_last!
|
69
|
+
self.last = false
|
70
|
+
save!
|
71
|
+
end
|
72
|
+
|
73
|
+
def default_subject!
|
74
|
+
self.subject = I18n.t 'models.carrier.no_subject' if !subject || subject.empty?
|
75
|
+
end
|
76
|
+
|
77
|
+
def sender_name
|
78
|
+
sender_user.username
|
79
|
+
end
|
80
|
+
|
81
|
+
def recipients_names
|
82
|
+
recipients.collect{|id| User.find(id, :select => "username").username}.join(', ') #
|
83
|
+
end
|
84
|
+
|
85
|
+
def recipients_ids
|
86
|
+
recipients
|
87
|
+
end
|
88
|
+
|
89
|
+
def recipients_ids= ra
|
90
|
+
self.recipients = ra.scan(/\w+/).map(&:to_i)
|
91
|
+
end
|
92
|
+
|
93
|
+
def recipients_names= recipients_array
|
94
|
+
self.recipients = recipients_array.scan(/\w+/).map do |name|
|
95
|
+
begin
|
96
|
+
User.find_by_username!(name).id
|
97
|
+
rescue
|
98
|
+
nil
|
99
|
+
end
|
100
|
+
end.uniq
|
101
|
+
end
|
102
|
+
|
103
|
+
def participants
|
104
|
+
[] | recipients << sender
|
105
|
+
end
|
106
|
+
|
107
|
+
def chain_messages
|
108
|
+
chain.messages
|
109
|
+
end
|
110
|
+
|
111
|
+
def date_formatted
|
112
|
+
created_at.strftime('%H:%M %d.%m')
|
113
|
+
end
|
114
|
+
|
115
|
+
protected
|
116
|
+
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Carrier
|
2
|
+
class Message < ActiveRecord::Base
|
3
|
+
|
4
|
+
t = Arel::Table.new(table_name)
|
5
|
+
c = Arel::Table.new(Chain.table_name)
|
6
|
+
|
7
|
+
scope :for, lambda{|user| where(t[:recipients].matches("% #{user.id}\n%")) }
|
8
|
+
scope :by, lambda{|user| where(:sender => user.id) }
|
9
|
+
|
10
|
+
scope :for_or_by, lambda{|user| where(t[:sender].eq(user.id).or(t[:recipients].matches("% #{user.id}\n%"))) }
|
11
|
+
|
12
|
+
scope :for_index, lambda{|user|
|
13
|
+
for_or_by(user).where("exists(select * from #{table_name} m where (m.recipients LIKE '% #{user.id}\n%' AND m.chain_id = #{table_name}.chain_id) )")
|
14
|
+
}
|
15
|
+
|
16
|
+
scope :for_sent, lambda{|user|
|
17
|
+
for_or_by(user).where("exists(select * from #{table_name} m where (m.sender = #{user.id} AND m.chain_id = #{table_name}.chain_id) )")
|
18
|
+
}
|
19
|
+
|
20
|
+
scope :not_archived_for, lambda { |user|
|
21
|
+
where(c[:archived_for].does_not_match("% #{user.id}\n%") )
|
22
|
+
}
|
23
|
+
|
24
|
+
scope :archived_for, lambda {|user| where(c[:archived_for].matches("% #{user.id}\n%")) }
|
25
|
+
|
26
|
+
scope :top, lambda{ where(:last => true) }
|
27
|
+
|
28
|
+
scope :reversed, order("#{table_name}.created_at DESC")
|
29
|
+
|
30
|
+
scope :messages_sent, lambda {|user| top
|
31
|
+
.for_sent(user)
|
32
|
+
.not_archived_for(user)
|
33
|
+
.includes(:chain)
|
34
|
+
.reversed }
|
35
|
+
|
36
|
+
scope :messages_index, lambda {|user| top
|
37
|
+
.for_index(user)
|
38
|
+
.not_archived_for(user)
|
39
|
+
.includes(:chain)
|
40
|
+
.reversed }
|
41
|
+
|
42
|
+
scope :archived_messages_with, lambda {|user| top
|
43
|
+
.for_or_by(user)
|
44
|
+
.archived_for(user)
|
45
|
+
.joins(:chain)
|
46
|
+
.reversed }
|
47
|
+
|
48
|
+
scope :unread, lambda {|user| for_or_by(user).unread_by(user) }
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Carrier
|
2
|
+
class Message < ActiveRecord::Base
|
3
|
+
|
4
|
+
class << self
|
5
|
+
def re name
|
6
|
+
if name.match(/re/).nil?
|
7
|
+
return "re: "+name
|
8
|
+
elsif !name.match(/re:/).nil?
|
9
|
+
return name.sub(/re:/,'re[2]:')
|
10
|
+
elsif name.match(/re\[\d+\]/)
|
11
|
+
re_count = name.match(/re\[\d+\]:/)[0].match(/\d+/)[0]
|
12
|
+
re_count = re_count.to_i + 1
|
13
|
+
return name.sub(/re\[\d+\]/, 're['+re_count.to_s+']')
|
14
|
+
end
|
15
|
+
name
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def subject_without_re
|
20
|
+
subject.gsub(/re\[\d+\]: /,'')
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class ExcludeSelfValidator < ActiveModel::EachValidator
|
2
|
+
def validate_each(record, attribute, value)
|
3
|
+
recipients = record.send(attribute)
|
4
|
+
|
5
|
+
if recipients.include?(record.sender)
|
6
|
+
record.errors.add attribute, (options[:message] || "cannot write to self!")
|
7
|
+
recipients.delete(record.sender)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class RecipientsValidator < ActiveModel::EachValidator
|
2
|
+
def validate_each(record, attribute, value)
|
3
|
+
recipients = record.send(attribute)
|
4
|
+
|
5
|
+
if recipients.include?(nil)
|
6
|
+
record.errors.add attribute, (options[:message] || I18n.t('activerecord.errors.models.carrier/message.attributes.recipients.wrong'))
|
7
|
+
recipients.compact!
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
$('#archive_chain').html('<%= escape_javascript(render :partial => 'carrier/messages/archive_chain', :locals => {:chain => @chain}) %>')
|
@@ -0,0 +1 @@
|
|
1
|
+
$('#archive_chain').html('<%= escape_javascript(render :partial => 'carrier/messages/archive_chain', :locals => {:chain => @chain}) %>')
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<% if chain.archived_for?(current_user) %>
|
2
|
+
<%= b raw(t 'views.carrier.thread_archived') %>
|
3
|
+
<%= link_to raw(t 'views.carrier.unarchive_link'), unarchive_chain_path(:chain_id => chain, :user_id => current_user), :remote => true, :method => :post %>
|
4
|
+
<% else %>
|
5
|
+
<%= link_to raw(t 'views.carrier.archive_link'), archive_chain_path(:chain_id => chain, :user_id => current_user), :remote => true, :method => :post %>
|
6
|
+
<% end %>
|
@@ -0,0 +1,30 @@
|
|
1
|
+
<%= form_for([carrier, @message], :html => { :autocomplete => :off }) do |f| %>
|
2
|
+
|
3
|
+
<%= error_messages_for @message %>
|
4
|
+
|
5
|
+
<div class="message_ma_new_wrapper">
|
6
|
+
<div class="message_ma_new_wrapper_1">
|
7
|
+
<div class="field">
|
8
|
+
<%= f.label :recipients_names, t('views.carrier.new_recipients') %><br />
|
9
|
+
<div id="recipients">
|
10
|
+
<%= render :partial => "carrier/messages/#{carrier_ui}/recipients", :locals => {:f => f } %>
|
11
|
+
</div>
|
12
|
+
</div>
|
13
|
+
</div>
|
14
|
+
<div class="message_ma_new_wrapper_2">
|
15
|
+
<div class="field">
|
16
|
+
<%= f.label :subject, t('views.carrier.new_subject') %><br />
|
17
|
+
<%= f.text_field :subject %>
|
18
|
+
</div>
|
19
|
+
<div class="field">
|
20
|
+
<%= f.label :content, t('views.carrier.new_content') %><br />
|
21
|
+
<%= f.text_area :content, :rows => 6 %>
|
22
|
+
</div>
|
23
|
+
<%= f.hidden_field :sender, :value => current_user.id %>
|
24
|
+
<div class="actions">
|
25
|
+
<%= f.submit t('views.carrier.new_send') %>
|
26
|
+
</div>
|
27
|
+
</div>
|
28
|
+
</div>
|
29
|
+
|
30
|
+
<% end %>
|