enju_message 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +36 -0
- data/app/controllers/message_requests_controller.rb +62 -0
- data/app/controllers/message_templates_controller.rb +18 -0
- data/app/controllers/messages_controller.rb +155 -0
- data/app/helpers/messages_helper.rb +2 -0
- data/app/models/message.rb +86 -0
- data/app/models/message_request.rb +87 -0
- data/app/models/message_template.rb +42 -0
- data/app/views/layouts/messages.html.erb +24 -0
- data/app/views/message_requests/edit.html.erb +40 -0
- data/app/views/message_requests/index.html.erb +58 -0
- data/app/views/message_requests/new.html.erb +40 -0
- data/app/views/message_requests/show.html.erb +55 -0
- data/app/views/message_templates/_form.html.erb +27 -0
- data/app/views/message_templates/edit.html.erb +13 -0
- data/app/views/message_templates/index.html.erb +44 -0
- data/app/views/message_templates/new.html.erb +12 -0
- data/app/views/message_templates/show.html.erb +33 -0
- data/app/views/messages/_form.html.erb +37 -0
- data/app/views/messages/edit.html.erb +42 -0
- data/app/views/messages/index.atom.builder +15 -0
- data/app/views/messages/index.html.erb +66 -0
- data/app/views/messages/index.rss.builder +41 -0
- data/app/views/messages/new.html.erb +43 -0
- data/app/views/messages/show.html.erb +48 -0
- data/app/views/notifier/message_notification.en.text.erb +14 -0
- data/app/views/notifier/message_notification.ja.text.erb +14 -0
- data/config/routes.rb +9 -0
- data/db/fixtures/message_templates.yml +54 -0
- data/db/migrate/149_create_message_templates.rb +18 -0
- data/db/migrate/154_create_messages.rb +24 -0
- data/db/migrate/20080819181903_create_message_requests.rb +20 -0
- data/db/migrate/20110913115320_add_lft_and_rgt_to_message.rb +11 -0
- data/lib/enju_message/engine.rb +17 -0
- data/lib/enju_message/version.rb +3 -0
- data/lib/enju_message.rb +4 -0
- data/lib/tasks/enju_message_tasks.rake +5 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +9 -0
- data/test/dummy/app/assets/stylesheets/application.css +7 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config/application.rb +45 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +30 -0
- data/test/dummy/config/environments/production.rb +60 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +10 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +0 -0
- data/test/dummy/log/test.log +3 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +26 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/enju_message_test.rb +7 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/test_helper.rb +10 -0
- metadata +337 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2011 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'EnjuSubject'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
24
|
+
load 'rails/tasks/engine.rake'
|
25
|
+
|
26
|
+
|
27
|
+
Bundler::GemHelper.install_tasks
|
28
|
+
|
29
|
+
require 'rspec/core'
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
|
32
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
33
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
34
|
+
end
|
35
|
+
|
36
|
+
task :default => :spec
|
@@ -0,0 +1,62 @@
|
|
1
|
+
class MessageRequestsController < ApplicationController
|
2
|
+
load_and_authorize_resource
|
3
|
+
|
4
|
+
# GET /message_requests
|
5
|
+
# GET /message_requests.json
|
6
|
+
def index
|
7
|
+
case params[:mode]
|
8
|
+
when 'sent'
|
9
|
+
@message_requests = MessageRequest.sent.order('created_at DESC').page(params[:page])
|
10
|
+
when 'all'
|
11
|
+
@message_requests = MessageRequest.order('created_at DESC').page(params[:page])
|
12
|
+
else
|
13
|
+
@message_requests = MessageRequest.not_sent.order('created_at DESC').page(params[:page])
|
14
|
+
end
|
15
|
+
|
16
|
+
respond_to do |format|
|
17
|
+
format.html # index.html.erb
|
18
|
+
format.json { render :json => @message_requests }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# GET /message_requests/1
|
23
|
+
# GET /message_requests/1.json
|
24
|
+
def show
|
25
|
+
respond_to do |format|
|
26
|
+
format.html # show.html.erb
|
27
|
+
format.json { render :json => @message_request }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# GET /message_requests/1/edit
|
32
|
+
def edit
|
33
|
+
@message_templates = MessageTemplate.all
|
34
|
+
end
|
35
|
+
|
36
|
+
# PUT /message_requests/1
|
37
|
+
# PUT /message_requests/1.json
|
38
|
+
def update
|
39
|
+
respond_to do |format|
|
40
|
+
if @message_request.update_attributes(params[:message_request])
|
41
|
+
flash[:notice] = t('controller.successfully_updated', :model => t('activerecord.models.message_request'))
|
42
|
+
format.html { redirect_to(@message_request) }
|
43
|
+
format.json { head :ok }
|
44
|
+
else
|
45
|
+
@message_templates = MessageTemplate.all
|
46
|
+
format.html { render :action => "edit" }
|
47
|
+
format.json { render :json => @message_request.errors, :status => :unprocessable_entity }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# DELETE /message_requests/1
|
53
|
+
# DELETE /message_requests/1.json
|
54
|
+
def destroy
|
55
|
+
@message_request.destroy
|
56
|
+
|
57
|
+
respond_to do |format|
|
58
|
+
format.html { redirect_to(message_requests_url) }
|
59
|
+
format.json { head :ok }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class MessageTemplatesController < InheritedResources::Base
|
2
|
+
respond_to :html, :json
|
3
|
+
load_and_authorize_resource
|
4
|
+
|
5
|
+
def update
|
6
|
+
@message_template = MessageTemplate.find(params[:id])
|
7
|
+
if params[:position]
|
8
|
+
@message_template.insert_at(params[:position])
|
9
|
+
redirect_to message_templates_url
|
10
|
+
return
|
11
|
+
end
|
12
|
+
update!
|
13
|
+
end
|
14
|
+
|
15
|
+
def index
|
16
|
+
@message_templates = MessageTemplate.page(params[:page])
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,155 @@
|
|
1
|
+
class MessagesController < ApplicationController
|
2
|
+
load_and_authorize_resource :except => :index
|
3
|
+
authorize_resource :only => :index
|
4
|
+
before_filter :get_user_if_nil, :only => :index
|
5
|
+
after_filter :solr_commit, :only => [:create, :update, :destroy, :destroy_selected]
|
6
|
+
|
7
|
+
# GET /messages
|
8
|
+
# GET /messages.json
|
9
|
+
def index
|
10
|
+
query = params[:query].to_s.strip
|
11
|
+
search = Sunspot.new_search(Message)
|
12
|
+
user = current_user
|
13
|
+
case params[:mode]
|
14
|
+
when 'read'
|
15
|
+
is_read = true
|
16
|
+
when 'unread'
|
17
|
+
is_read = false
|
18
|
+
else
|
19
|
+
is_read = nil
|
20
|
+
end
|
21
|
+
search.build do
|
22
|
+
fulltext query
|
23
|
+
order_by :created_at, :desc
|
24
|
+
with(:receiver_id).equal_to user.id
|
25
|
+
facet(:is_read)
|
26
|
+
end
|
27
|
+
@message_facet = search.execute!.facet('is_read').rows
|
28
|
+
search.build do
|
29
|
+
with(:is_read).equal_to is_read unless is_read.nil?
|
30
|
+
end
|
31
|
+
page = params[:page] || 1
|
32
|
+
search.query.paginate(page.to_i, Message.per_page)
|
33
|
+
@messages = search.execute!.results
|
34
|
+
|
35
|
+
respond_to do |format|
|
36
|
+
format.html # index.rhtml
|
37
|
+
format.json { render :json => @messages }
|
38
|
+
format.rss
|
39
|
+
format.atom
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# GET /messages/1
|
44
|
+
# GET /messages/1.json
|
45
|
+
def show
|
46
|
+
@message = current_user.received_messages.find(params[:id])
|
47
|
+
@message.sm_read!
|
48
|
+
|
49
|
+
respond_to do |format|
|
50
|
+
format.html # show.rhtml
|
51
|
+
format.json { render :json => @message }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# GET /messages/new
|
56
|
+
def new
|
57
|
+
parent = get_parent(params[:parent_id])
|
58
|
+
@message = current_user.sent_messages.new
|
59
|
+
if params[:recipient] && current_user.has_role?('Librarian')
|
60
|
+
@message.recipient = params[:recipient]
|
61
|
+
else
|
62
|
+
@message.recipient = parent.sender.username if parent
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# GET /messages/1;edit
|
67
|
+
def edit
|
68
|
+
@message = current_user.received_messages.find(params[:id])
|
69
|
+
@message.sm_read!
|
70
|
+
end
|
71
|
+
|
72
|
+
# POST /messages
|
73
|
+
# POST /messages.json
|
74
|
+
def create
|
75
|
+
@message = current_user.sent_messages.new(params[:message])
|
76
|
+
get_parent(@message.parent_id)
|
77
|
+
@message.receiver = User.find(@message.recipient) rescue nil
|
78
|
+
|
79
|
+
respond_to do |format|
|
80
|
+
if @message.save
|
81
|
+
flash[:notice] = t('controller.successfully_created', :model => t('activerecord.models.message'))
|
82
|
+
format.html { redirect_to messages_url }
|
83
|
+
format.json { render :json => @message, :status => :created, :location => @message }
|
84
|
+
else
|
85
|
+
format.html { render :action => "new" }
|
86
|
+
format.json { render :json => @message.errors, :status => :unprocessable_entity }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# PUT /messages/1
|
92
|
+
# PUT /messages/1.json
|
93
|
+
def update
|
94
|
+
@message = current_user.received_messages.find(params[:id])
|
95
|
+
|
96
|
+
if @message.update_attributes(params[:message])
|
97
|
+
flash[:notice] = t('controller.successfully_updated', :model => t('activerecord.models.message'))
|
98
|
+
format.html { redirect_to message_url(@message) }
|
99
|
+
format.json { head :ok }
|
100
|
+
else
|
101
|
+
format.html { render :action => "edit" }
|
102
|
+
format.json { render :json => @message.errors, :status => :unprocessable_entity }
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# DELETE /messages/1
|
107
|
+
# DELETE /messages/1.json
|
108
|
+
def destroy
|
109
|
+
@message = current_user.received_messages.find(params[:id])
|
110
|
+
@message.destroy
|
111
|
+
|
112
|
+
respond_to do |format|
|
113
|
+
format.html { redirect_to messages_url }
|
114
|
+
format.json { head :ok }
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def destroy_selected
|
119
|
+
if current_user
|
120
|
+
unless current_user.has_role?('Librarian')
|
121
|
+
access_denied
|
122
|
+
end
|
123
|
+
else
|
124
|
+
redirect_to new_user_session_url
|
125
|
+
return
|
126
|
+
end
|
127
|
+
respond_to do |format|
|
128
|
+
if params[:delete].present?
|
129
|
+
messages = params[:delete].map{|m| Message.find_by_id(m)}
|
130
|
+
end
|
131
|
+
if messages.present?
|
132
|
+
messages.each do |message|
|
133
|
+
message.destroy
|
134
|
+
end
|
135
|
+
flash[:notice] = t('message.messages_were_deleted')
|
136
|
+
format.html { redirect_to messages_url }
|
137
|
+
else
|
138
|
+
flash[:notice] = t('message.select_messages')
|
139
|
+
format.html { redirect_to messages_url }
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
private
|
145
|
+
def get_parent(id)
|
146
|
+
parent = Message.where(:id => id).first
|
147
|
+
unless current_user.has_role?('Librarian')
|
148
|
+
unless parent.try(:receiver) == current_user
|
149
|
+
access_denied; return
|
150
|
+
end
|
151
|
+
else
|
152
|
+
parent
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
class Message < ActiveRecord::Base
|
3
|
+
scope :unread, where(:state => 'unread')
|
4
|
+
belongs_to :message_request
|
5
|
+
belongs_to :sender, :class_name => 'User'
|
6
|
+
belongs_to :receiver, :class_name => 'User'
|
7
|
+
validates_presence_of :subject, :body #, :sender
|
8
|
+
validates_presence_of :recipient, :on => :create
|
9
|
+
validates_presence_of :receiver, :on => :update
|
10
|
+
before_save :set_receiver
|
11
|
+
after_save :index
|
12
|
+
after_destroy :remove_from_index
|
13
|
+
after_create :send_notification
|
14
|
+
|
15
|
+
acts_as_nested_set
|
16
|
+
attr_accessor :recipient
|
17
|
+
|
18
|
+
state_machine :initial => :unread do
|
19
|
+
before_transition any => :read, :do => :read
|
20
|
+
before_transition :read => :unread, :do => :unread
|
21
|
+
|
22
|
+
event :sm_read do
|
23
|
+
transition any => :read
|
24
|
+
end
|
25
|
+
|
26
|
+
event :sm_unread do
|
27
|
+
transition :read => :unread
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
searchable do
|
32
|
+
text :body, :subject
|
33
|
+
string :subject
|
34
|
+
integer :receiver_id
|
35
|
+
integer :sender_id
|
36
|
+
time :created_at
|
37
|
+
boolean :is_read do
|
38
|
+
self.read?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.per_page
|
43
|
+
10
|
44
|
+
end
|
45
|
+
|
46
|
+
def set_receiver
|
47
|
+
if self.recipient
|
48
|
+
self.receiver = User.find(self.recipient)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def send_notification
|
53
|
+
Notifier.delay.message_notification(self) if receiver.try(:email).present?
|
54
|
+
end
|
55
|
+
|
56
|
+
def read
|
57
|
+
self.read_at = Time.zone.now unless self.read_at
|
58
|
+
self.save(:validate => false)
|
59
|
+
end
|
60
|
+
|
61
|
+
def read?
|
62
|
+
return true if state == 'read'
|
63
|
+
false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
# == Schema Information
|
69
|
+
#
|
70
|
+
# Table name: messages
|
71
|
+
#
|
72
|
+
# id :integer not null, primary key
|
73
|
+
# read_at :datetime
|
74
|
+
# receiver_id :integer
|
75
|
+
# sender_id :integer
|
76
|
+
# subject :string(255) not null
|
77
|
+
# body :text
|
78
|
+
# created_at :datetime
|
79
|
+
# updated_at :datetime
|
80
|
+
# message_request_id :integer
|
81
|
+
# state :string(255)
|
82
|
+
# parent_id :integer
|
83
|
+
# lft :integer
|
84
|
+
# rgt :integer
|
85
|
+
#
|
86
|
+
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'erubis'
|
2
|
+
class MessageRequest < ActiveRecord::Base
|
3
|
+
scope :not_sent, where('sent_at IS NULL AND state = ?', 'pending')
|
4
|
+
scope :sent, where(:state => 'sent')
|
5
|
+
scope :started, where(:state => 'started')
|
6
|
+
belongs_to :message_template, :validate => true
|
7
|
+
belongs_to :sender, :class_name => "User", :foreign_key => "sender_id", :validate => true
|
8
|
+
belongs_to :receiver, :class_name => "User", :foreign_key => "receiver_id", :validate => true
|
9
|
+
has_many :messages
|
10
|
+
|
11
|
+
validates_associated :sender, :receiver, :message_template
|
12
|
+
validates_presence_of :sender, :receiver, :message_template
|
13
|
+
|
14
|
+
state_machine :initial => :pending do
|
15
|
+
before_transition any - :sent => :sent, :do => :send_message
|
16
|
+
|
17
|
+
event :sm_send_message do
|
18
|
+
transition any - :sent => :sent
|
19
|
+
end
|
20
|
+
|
21
|
+
event :sm_start do
|
22
|
+
transition :pending => :started
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.per_page
|
27
|
+
10
|
28
|
+
end
|
29
|
+
|
30
|
+
def start_sending_message
|
31
|
+
sm_start!
|
32
|
+
sm_send_message!
|
33
|
+
end
|
34
|
+
|
35
|
+
def send_message
|
36
|
+
message = nil
|
37
|
+
MessageRequest.transaction do
|
38
|
+
if self.body
|
39
|
+
message = Message.create!(:sender => self.sender, :recipient => self.receiver.username, :subject => self.subject, :body => self.body)
|
40
|
+
end
|
41
|
+
self.update_attributes({:sent_at => Time.zone.now})
|
42
|
+
if ['reservation_expired_for_patron', 'reservation_expired_for_patron'].include?(self.message_template.status)
|
43
|
+
self.receiver.reserves.each do |reserve|
|
44
|
+
reserve.update_attribute(:expiration_notice_to_patron, true)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
return message
|
49
|
+
end
|
50
|
+
|
51
|
+
def subject
|
52
|
+
self.message_template.title
|
53
|
+
end
|
54
|
+
|
55
|
+
def save_message_body(options = {})
|
56
|
+
options = {
|
57
|
+
:receiver => self.receiver.patron,
|
58
|
+
:locale => self.receiver.locale
|
59
|
+
}.merge(options)
|
60
|
+
self.update_attributes!({:body => self.message_template.embed_body(options)})
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.send_messages
|
64
|
+
count = MessageRequest.not_sent.size
|
65
|
+
MessageRequest.not_sent.each do |request|
|
66
|
+
request.start_sending_message
|
67
|
+
end
|
68
|
+
logger.info "#{Time.zone.now} sent #{count} messages!"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# == Schema Information
|
73
|
+
#
|
74
|
+
# Table name: message_requests
|
75
|
+
#
|
76
|
+
# id :integer not null, primary key
|
77
|
+
# sender_id :integer
|
78
|
+
# receiver_id :integer
|
79
|
+
# message_template_id :integer
|
80
|
+
# sent_at :datetime
|
81
|
+
# deleted_at :datetime
|
82
|
+
# body :text
|
83
|
+
# state :string(255)
|
84
|
+
# created_at :datetime
|
85
|
+
# updated_at :datetime
|
86
|
+
#
|
87
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class MessageTemplate < ActiveRecord::Base
|
2
|
+
default_scope :order => "position"
|
3
|
+
has_many :message_requests
|
4
|
+
|
5
|
+
validates_uniqueness_of :status
|
6
|
+
validates_presence_of :status, :title, :body
|
7
|
+
|
8
|
+
acts_as_list
|
9
|
+
|
10
|
+
def self.per_page
|
11
|
+
10
|
12
|
+
end
|
13
|
+
|
14
|
+
def embed_body(options = {})
|
15
|
+
template = Erubis::Eruby.new(body)
|
16
|
+
context = {
|
17
|
+
:library_group => LibraryGroup.site_config
|
18
|
+
}.merge(options)
|
19
|
+
template.evaluate(context)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.localized_template(status, locale)
|
23
|
+
MessageTemplate.where(:status => status, :locale => locale).first || MessageTemplate.where(:status => status).first
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
# == Schema Information
|
30
|
+
#
|
31
|
+
# Table name: message_templates
|
32
|
+
#
|
33
|
+
# id :integer not null, primary key
|
34
|
+
# status :string(255) not null
|
35
|
+
# title :text not null
|
36
|
+
# body :text not null
|
37
|
+
# position :integer
|
38
|
+
# created_at :datetime
|
39
|
+
# updated_at :datetime
|
40
|
+
# locale :string(255) default("ja")
|
41
|
+
#
|
42
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<%= @locale.to_s -%>" lang="<%= @locale.to_s -%>">
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8" />
|
5
|
+
<title><%= t('message.user_message', :login_name => current_user.username) -%></title>
|
6
|
+
<%= render 'page/include' -%>
|
7
|
+
<%= auto_discovery_link_tag(:rss, messages_url(:format => :rss), :title => (t('message.user_message', :login_name => current_user.username) + " (RSS)")) %>
|
8
|
+
<%= auto_discovery_link_tag(:atom, messages_url(:format => :atom), :title => (t('message.user_message', :login_name => current_user.username) + " (Atom)")) %>
|
9
|
+
</head>
|
10
|
+
<body>
|
11
|
+
|
12
|
+
<%= render 'page/header' -%>
|
13
|
+
<%= render 'page/menu' -%>
|
14
|
+
|
15
|
+
<div id="content">
|
16
|
+
|
17
|
+
<%= yield -%>
|
18
|
+
|
19
|
+
</div>
|
20
|
+
|
21
|
+
<%= render 'page/footer' -%>
|
22
|
+
|
23
|
+
</body>
|
24
|
+
</html>
|
@@ -0,0 +1,40 @@
|
|
1
|
+
<div id="content_detail" class="ui-corner-all">
|
2
|
+
<h1 class="title"><%= t('page.editing', :model => t('activerecord.models.message_request')) -%></h1>
|
3
|
+
<div id="content_list">
|
4
|
+
|
5
|
+
<%= form_for(@message_request) do |f| -%>
|
6
|
+
<%= f.error_messages -%>
|
7
|
+
|
8
|
+
<div class="field">
|
9
|
+
<%= f.label t('message.sender') -%><br />
|
10
|
+
<%= link_to @message_request.sender.username, @message_request.sender -%>
|
11
|
+
</div>
|
12
|
+
<div class="field">
|
13
|
+
<%= f.label t('message.receiver') -%><br />
|
14
|
+
<%= link_to @message_request.receiver.username, @message_request.receiver -%>
|
15
|
+
</div>
|
16
|
+
<div class="field">
|
17
|
+
<%= f.label t('activerecord.models.message_template') -%><br />
|
18
|
+
<%= f.select(:message_template_id, @message_templates.collect{|m| [m.title, m.id]}) -%>
|
19
|
+
</div>
|
20
|
+
<div class="field">
|
21
|
+
<%= f.label t('activerecord.attributes.message.subject') -%><br />
|
22
|
+
<%= @message_request.subject -%>
|
23
|
+
</div>
|
24
|
+
<div class="field">
|
25
|
+
<%= f.label t('activerecord.attributes.message.body') -%><br />
|
26
|
+
<%= textilize(@message_request.body) -%>
|
27
|
+
</div>
|
28
|
+
<div class="actions">
|
29
|
+
<%= f.submit %>
|
30
|
+
</div>
|
31
|
+
<%- end -%>
|
32
|
+
</div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="submenu" class="ui-corner-all">
|
36
|
+
<ul>
|
37
|
+
<li><%= link_to t('page.show'), @message_request -%></li>
|
38
|
+
<li><%= link_to t('page.back'), message_requests_path -%></li>
|
39
|
+
</ul>
|
40
|
+
</div>
|
@@ -0,0 +1,58 @@
|
|
1
|
+
<div id="content_detail" class="ui-corner-all">
|
2
|
+
<h1 class="title"><%= t('page.listing', :model => t('activerecord.models.message_request')) -%></h1>
|
3
|
+
<div id="content_list">
|
4
|
+
|
5
|
+
<table class="index">
|
6
|
+
<tr>
|
7
|
+
<th>
|
8
|
+
<%= t('message.sender') -%>
|
9
|
+
/
|
10
|
+
<%= t('message.receiver') -%>
|
11
|
+
</th>
|
12
|
+
<th><%= t('activerecord.models.message_template') -%></th>
|
13
|
+
<th><%= t('activerecord.attributes.message.subject') -%></th>
|
14
|
+
<th><%= t('page.created_at') -%></th>
|
15
|
+
<th><%= t('activerecord.attributes.message_request.sent_at') -%></th>
|
16
|
+
<th></th>
|
17
|
+
</tr>
|
18
|
+
|
19
|
+
<%- @message_requests.each do |message_request| -%>
|
20
|
+
<tr class="line<%= cycle("0", "1") -%>">
|
21
|
+
<td>
|
22
|
+
<%= link_to message_request.sender.username, message_request.sender -%>
|
23
|
+
<br />
|
24
|
+
->
|
25
|
+
<%= link_to message_request.receiver.username, message_request.receiver -%>
|
26
|
+
</td>
|
27
|
+
<td><%= link_to message_request.message_template.status, message_template_path(message_request.message_template) -%></td>
|
28
|
+
<td><%= message_request.subject -%></td>
|
29
|
+
<td><%= l(message_request.created_at) -%></td>
|
30
|
+
<td><%= l(message_request.sent_at) if message_request.sent_at -%></td>
|
31
|
+
<td>
|
32
|
+
<%= link_to t('page.show'), message_request -%>
|
33
|
+
<%= link_to t('page.edit'), edit_message_request_path(message_request) -%>
|
34
|
+
<%= link_to t('page.destroy'), message_request, :confirm => t('page.are_you_sure'), :method => :delete -%>
|
35
|
+
</td>
|
36
|
+
</tr>
|
37
|
+
<%- end -%>
|
38
|
+
</table>
|
39
|
+
|
40
|
+
<%= will_paginate(@message_requests) -%>
|
41
|
+
</div>
|
42
|
+
</div>
|
43
|
+
|
44
|
+
<div id="submenu" class="ui-corner-all">
|
45
|
+
<ul>
|
46
|
+
<%- case params[:mode] when 'sent' -%>
|
47
|
+
<li><%= link_to t('message_request.not_sent'), message_requests_path(:mode => 'not_sent') -%></li>
|
48
|
+
<li><%= link_to t('message_request.all'), message_requests_path(:mode => 'all') -%></li>
|
49
|
+
<%- when 'all' -%>
|
50
|
+
<li><%= link_to t('message_request.not_sent'), message_requests_path(:mode => 'not_sent') -%></li>
|
51
|
+
<li><%= link_to t('message_request.sent'), message_requests_path(:mode => 'sent') -%></li>
|
52
|
+
<%- else -%>
|
53
|
+
<li><%= link_to t('message_request.sent'), message_requests_path(:mode => 'sent') -%></li>
|
54
|
+
<li><%= link_to t('message_request.all'), message_requests_path(:mode => 'all') -%></li>
|
55
|
+
<%- end -%>
|
56
|
+
</ul>
|
57
|
+
</div>
|
58
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
<div id="content_detail" class="ui-corner-all">
|
2
|
+
<h1 class="title"><%= t('page.new', :model => t('activerecord.models.message_request')) -%></h1>
|
3
|
+
<div id="content_list">
|
4
|
+
|
5
|
+
<%= form_for(@message_request) do |f| -%>
|
6
|
+
<%= f.error_messages -%>
|
7
|
+
|
8
|
+
<div class="field">
|
9
|
+
<%= f.label t('message.sender') -%><br />
|
10
|
+
<%= link_to current_user.username, current_user -%>
|
11
|
+
<%= f.hidden_field :sender_id -%>
|
12
|
+
</div>
|
13
|
+
<div class="field">
|
14
|
+
<%= f.label t('message.receiver') -%><br />
|
15
|
+
<%= f.text_field :receiver_id -%>
|
16
|
+
</div>
|
17
|
+
<div class="field">
|
18
|
+
<%= f.label t('activerecord.models.message_template') -%><br />
|
19
|
+
<%= f.select(:message_template_id, @message_templates.collect{|m| [m.title, m.id]}) -%>
|
20
|
+
</div>
|
21
|
+
<div class="field">
|
22
|
+
<%= f.label t('activerecord.attributes.message.subject') -%><br />
|
23
|
+
<%= @message_request.subject -%>
|
24
|
+
</div>
|
25
|
+
<div class="field">
|
26
|
+
<%= f.label t('activerecord.attributes.message.body') -%><br />
|
27
|
+
<%= textilize(@message_request.body) -%>
|
28
|
+
</div>
|
29
|
+
<div class="actions">
|
30
|
+
<%= f.submit %>
|
31
|
+
</div>
|
32
|
+
<%- end -%>
|
33
|
+
</div>
|
34
|
+
</div>
|
35
|
+
|
36
|
+
<div id="submenu" class="ui-corner-all">
|
37
|
+
<ul>
|
38
|
+
<li><%= link_to t('page.back'), message_requests_path -%></li>
|
39
|
+
</ul>
|
40
|
+
</div>
|