Class: Marley::Joints::Messages::Resources::PrivateMessage
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
- #actions(parent_instance = nil) ⇒ Object
- #after_save ⇒ Object
- #current_user_role ⇒ Object
- #reply ⇒ Object
- #reply_all ⇒ Object
- #rest_cols ⇒ Object
- #validate ⇒ Object
Methods inherited from Message
Instance Attribute Details
#recipients ⇒ Object
48 49 50 |
# File 'lib/marley/joints/messages.rb', line 48 def recipients users.map{|u|u.name}.join(',') end |
Class Method Details
.list_dataset(params = {}) ⇒ Object
38 39 40 |
# File 'lib/marley/joints/messages.rb', line 38 def self.list_dataset(params={}) super.filter(:messages__id => DB[:messages_users].filter(:user_id => current_user[:id]).select(:message_id)) end |
Instance Method Details
#actions(parent_instance = nil) ⇒ Object
44 45 46 47 |
# File 'lib/marley/joints/messages.rb', line 44 def actions(parent_instance=nil) return super if new? || ! recipients.to_s.match(/,/) {:get => [:reply, :reply_all]} end |
#after_save ⇒ Object
66 67 68 69 |
# File 'lib/marley/joints/messages.rb', line 66 def after_save super @recipients.each {|recipient| add_user recipient} end |
#current_user_role ⇒ Object
41 42 43 |
# File 'lib/marley/joints/messages.rb', line 41 def current_user_role super || (self.users.include?(self.class.current_user) && 'recipient') end |
#reply ⇒ Object
51 52 53 |
# File 'lib/marley/joints/messages.rb', line 51 def reply super.reggae_instance.set_values(:recipients => ) end |
#reply_all ⇒ Object
54 55 56 |
# File 'lib/marley/joints/messages.rb', line 54 def reply_all reply.set_values(:recipients => "#{},#{recipients}".sub(/\b#{self.class.current_user.name}\b,?/,'')) end |
#rest_cols ⇒ Object
34 35 36 |
# File 'lib/marley/joints/messages.rb', line 34 def rest_cols [:recipients] + super end |
#validate ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/marley/joints/messages.rb', line 57 def validate super errors[:recipients]='Recipients must be specified' unless @recipients @recipients=@recipients.split(',').map do |recipient_name| u=MR::User[:name => recipient_name] errors[:recipients] << "#{recipient_name} is not a valid message recipient" unless u u end end |