diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb
index 8e5f38e1..1787a2ff 100644
--- a/app/controllers/messages_controller.rb
+++ b/app/controllers/messages_controller.rb
@@ -1,76 +1,29 @@
class MessagesController < ApplicationController
-
+
# Renders the "inbox" action.
def index
@messages = Message.public.paginate :page => params[:page], :per_page => 20, :order => 'created_at DESC'
end
-
+
# Creates a new message object.
def new
- @message = Message.new
+ @message = Message.new(params[:message])
end
-
+
# Creates a new message.
def create
@message = @current_user.send_messages.new(params[:message])
if @message.save
#FIXME: Send Mails wit ID instead of using message.state ...
call_rake :send_emails
- flash[:notice] = "Nachricht ist gespeichert und wird versendet."
- redirect_to messages_path
+ redirect_to messages_url, :notice => "Nachricht ist gespeichert und wird versendet."
else
render :action => 'new'
end
end
-
+
# Shows a single message.
def show
@message = Message.find(params[:id])
end
-
- # Replys to the message specified through :id.
- def reply
- message = Message.find(params[:id])
- @message = Message.new(:recipient => message.sender, :subject => "Re: #{message.subject}")
- @message.body = "#{message.sender.nick} schrieb am #{I18n.l(message.created_at.to_date)} um #{I18n.l(message.created_at, :format => :time)}:\n"
- message.body.each_line{|l| @message.body += "> #{l}"}
- render :action => 'new'
- end
-
- # Shows new-message form with the recipient user specified through :id.
- def user
- if (recipient = User.find(params[:id]))
- @message = Message.new(:recipient => recipient)
- render :action => 'new'
- else
- flash[:error] = 'Unbekannte_r EmpfängerIn.'
- redirect_to :action=> 'index'
- end
- end
-
- # Shows new-message form with the recipient user specified through :id.
- def group
- group = Group.find(params[:id], :include => :memberships)
- if (group && !group.memberships.empty?)
- @message = Message.new(:group_id => group.id)
- render :action => 'new'
- else
- flash[:error] = 'Empfängergruppe ist unbekannt oder hat keine Mitglieder.'
- redirect_to :action=> 'index'
- end
- end
-
- # Auto-complete for recipient user list.
- def auto_complete_for_message_recipients_nicks
- @users = User.find(:all,
- :conditions => ['LOWER(nick) LIKE ?', '%' + params[:message][:recipients_nicks].downcase + '%'],
- :order => :nick, :limit => 8)
- render :partial => '/shared/auto_complete_users'
- end
-
- # Returns list of all users as auto-completion hint.
- def user_list
- @users = User.find(:all, :order => :nick)
- render :partial => '/shared/auto_complete_users'
- end
end
diff --git a/app/helpers/messages_helper.rb b/app/helpers/messages_helper.rb
index 1ced0806..e672107c 100644
--- a/app/helpers/messages_helper.rb
+++ b/app/helpers/messages_helper.rb
@@ -1,16 +1,4 @@
module MessagesHelper
- def groups_for_select
- groups = [[" -- Arbeitsgruppen -- ", ""]]
- groups += Workgroup.find(:all, :order => 'name', :include => :memberships).reject{ |g| g.memberships.empty? }.collect do |g|
- [g.name, g.id]
- end
- groups += [[" -- Bestellgruppen -- ", ""]]
- groups += Ordergroup.without_deleted(:order => 'name', :include => :memberships).reject{ |g| g.memberships.empty? }.collect do |g|
- [g.name, g.id]
- end
- groups
- end
-
def format_subject(message, length)
if message.subject.length > length
subject = truncate(message.subject, :length => length)
@@ -19,6 +7,6 @@ module MessagesHelper
subject = message.subject
body = truncate(message.body, :length => length - subject.length)
end
- "#{link_to(h(subject), message)} #{h(body)}"
+ "#{link_to(h(subject), message)} #{h(body)}".html_safe
end
end
diff --git a/app/models/message.rb b/app/models/message.rb
index ea0012cd..85682ad6 100644
--- a/app/models/message.rb
+++ b/app/models/message.rb
@@ -2,11 +2,11 @@ class Message < ActiveRecord::Base
belongs_to :sender, :class_name => "User", :foreign_key => "sender_id"
serialize :recipients_ids, Array
- attr_accessor :sent_to_all, :group_id, :recipients_nicks
+ attr_accessor :sent_to_all, :group_id, :recipient_tokens
- scope :pending, :conditions => { :email_state => 0 }
- scope :sent, :conditions => { :email_state => 1 }
- scope :public, :conditions => {:private => false}
+ scope :pending, where(:email_state => 0)
+ scope :sent, where(:email_state => 1)
+ scope :public, where(:private => false)
# Values for the email_state attribute: :none, :pending, :sent, :failed
EMAIL_STATE = {
@@ -36,15 +36,24 @@ class Message < ActiveRecord::Base
add_recipients Group.find(group_id).users unless group_id.blank?
end
- def recipients_nicks=(nicks)
- @recipients_nicks = nicks
- add_recipients nicks.split(",").collect { |nick| User.find_by_nick(nick) }
+ def recipient_tokens=(ids)
+ @recipient_tokens = ids
+ add_recipients ids.split(",").collect { |id| User.find(id) }
end
- def recipient=(user)
- @recipients_nicks = user.nick
+ def reply_to=(message_id)
+ message = Message.find(message_id)
+ add_recipients(message.sender.to_a)
+ self.subject = "Re: #{message.subject}"
+ self.body = "#{message.sender.nick} schrieb am #{I18n.l(message.created_at.to_date)} um #{I18n.l(message.created_at, :format => :time)}:\n"
+ message.body.each_line{ |l| self.body += "> #{l}" }
end
-
+
+ def mail_to=(user_id)
+ user = User.find(user_id)
+ add_recipients(user.to_a)
+ end
+
# Returns true if this message is a system message, i.e. was sent automatically by the FoodSoft itself.
def system_message?
self.sender_id.nil?
diff --git a/app/views/admin/users/show.html.erb b/app/views/admin/users/show.html.erb
index 447b0cca..8af5edc5 100644
--- a/app/views/admin/users/show.html.erb
+++ b/app/views/admin/users/show.html.erb
@@ -38,7 +38,7 @@
<%= link_to 'Bearbeiten', edit_admin_user_path(@user) %>
| <%= link_to 'Löschen', [:admin, @user], :confirm => "Willst du #{@user.first_name} wirklich rausschmeißen?", :method => :delete %>
- | <%= link_to "Nachricht senden", user_message_path(@user.id) %>
+ | <%= link_to "Nachricht senden", new_message_path(:message => {:mail_to => @user.id}) %>
Gruppenabos
diff --git a/app/views/foodcoop/ordergroups/_ordergroups.html.haml b/app/views/foodcoop/ordergroups/_ordergroups.html.haml
index 51137299..9e51bc0e 100644
--- a/app/views/foodcoop/ordergroups/_ordergroups.html.haml
+++ b/app/views/foodcoop/ordergroups/_ordergroups.html.haml
@@ -17,7 +17,7 @@
%tbody
- for ordergroup in @ordergroups
%tr{:class => cycle('even','odd', :name => 'ordergroup')}
- %td= link_to h(ordergroup.name), group_message_path(ordergroup), :title => "Bestellgruppe eine Nachricht schicken"
+ %td= link_to h(ordergroup.name), new_message_path(:message => {:group_id => ordergroup.id}), :title => "Bestellgruppe eine Nachricht schicken"
%td=h ordergroup.users.collect { |u| u.nick }.join(", ")
%td
- order = ordergroup.orders.first(:order => 'starts DESC')
diff --git a/app/views/foodcoop/users/_users.html.haml b/app/views/foodcoop/users/_users.html.haml
index ac84c6a1..c814a7c0 100644
--- a/app/views/foodcoop/users/_users.html.haml
+++ b/app/views/foodcoop/users/_users.html.haml
@@ -20,7 +20,7 @@
- users = params[:sort_by_ordergroups] ? @users.sort { |a,b| a.ordergroup.name <=> b.ordergroup.name } : @users
- for user in users
%tr{:class => cycle('even','odd', :name => 'users')}
- %td= link_to user.nick, user_message_path(user), :title => _('Send user an email')
+ %td= link_to user.nick, new_message_path(:message => {:mail_to => user.id}), :title => _('Send user an email')
%td=h user.name if @current_user.role_admin? || user.settings["profile.nameIsPublic"] == '1'
%td=h user.email if @current_user.role_admin? || user.settings["profile.emailIsPublic"] == '1'
%td=h user.phone if @current_user.role_admin? || user.settings["profile.phoneIsPublic"] == '1'
diff --git a/app/views/foodcoop/workgroups/_workgroup.html.haml b/app/views/foodcoop/workgroups/_workgroup.html.haml
index d117fbd7..8f060606 100644
--- a/app/views/foodcoop/workgroups/_workgroup.html.haml
+++ b/app/views/foodcoop/workgroups/_workgroup.html.haml
@@ -6,7 +6,7 @@
%p
= link_to "Alle Aufgaben zeigen", :controller => "/tasks", :action => "workgroup", :id => workgroup
|
- = link_to "Mitgliedern eine Nachricht schicken", :controller => '/messages', :action => 'group', :id => workgroup
+ = link_to "Mitgliedern eine Nachricht schicken", new_message_path(:message => {:group_id => workgroup.id})
- if workgroup.member?(@current_user)
|
= link_to "Gruppe bearbeiten", edit_foodcoop_workgroup_path(workgroup)
diff --git a/app/views/messages/_messages.html.haml b/app/views/messages/_messages.html.haml
index 5cadd9d4..639972bd 100644
--- a/app/views/messages/_messages.html.haml
+++ b/app/views/messages/_messages.html.haml
@@ -6,5 +6,5 @@
%td= format_subject(message, subject_length)
%td= h(message.sender_name)
%td= format_time(message.created_at)
- %td= link_to('Antworten', reply_message_path(message))
+ %td= link_to('Antworten', new_message_path(:message => {:reply_to => message.id}))
\ No newline at end of file
diff --git a/app/views/messages/index.html.haml b/app/views/messages/index.html.haml
index 3ce8fa1e..74e90918 100644
--- a/app/views/messages/index.html.haml
+++ b/app/views/messages/index.html.haml
@@ -5,4 +5,4 @@
%div{:style => "text-align:right"}= will_paginate @messages
#messages
- = render :partial => 'messages', :locals => { :subject_length => 130 }
\ No newline at end of file
+ = render :partial => 'messages', :locals => { :messages => @messages, :subject_length => 130 }
\ No newline at end of file
diff --git a/app/views/messages/new.haml b/app/views/messages/new.haml
index 72939eea..97975cbc 100644
--- a/app/views/messages/new.haml
+++ b/app/views/messages/new.haml
@@ -1,61 +1,40 @@
-%h1 Neue Nachricht
+- content_for :head do
+ :javascript
+ $(function() {
+ $('#message_recipient_tokens').tokenInput("#{users_path(:format => :json)}", {
+ crossDomain: false,
+ prePopulate: $('#message_recipient_tokens').data('pre')
+ });
-- form_for @message do |f|
- = f.error_messages
+ $('#message_sent_to_all').click(function() {
+ if ($(this).is(':checked')) {
+ $('#recipients').slideUp();
+ } else {
+ $('#recipients').slideDown();
+ }
+ });
+ });
- %p
- Empfängerinnen
- %fieldset
- - if Foodsoft.config[:mailing_list].blank?
- = f.check_box :sent_to_all, :onchange => "Element.toggle('recipients')"
- gesamte Foodcoop
- - else
- %b Nachrichten an alle
- verschickst Du bitte über den Verteiler:
- = mail_to Foodsoft.config[:mailing_list]
- %br/
- %small{:style => "color:grey"}
- Eventuell musst Du Dich dem Verteiler erst bekannt machen.
- %br/
- z.b. mit einer Mail an
- = mail_to Foodsoft.config[:mailing_list_subscribe]
- %table#recipients
- %tr
- %td
- %b BenutzerInnen:
- %br/
- %small{:style => "color:grey"} (Mehrere Benutzerinnen mit Komma trennen)
- %br/
- = text_field_with_auto_complete(:message, :recipients_nicks, {:value => @message.recipients_nicks}, {:tokens => ","})
- :javascript
- var userListLoaded = false;
- function checkUserList() {
- if (userListLoaded) {
- $('user-list').toggle();
- }
- return !userListLoaded;
- }
- = link_to_remote('Liste', :update => 'user-list', :url => {:action => 'user_list'}, :complete => 'userListLoaded = true', :condition => 'checkUserList()')
- #user-list.auto_complete
- %tr
- %td
- %b Gruppe:
- %br/
- = f.select :group_id, groups_for_select, :prompt => " -- Gruppe auswählen --"
+- title "Neue Nachricht"
- %p
- Privat
- = f.check_box :private
- %small{:style => "color:grey"} (Nachricht taucht nicht im Foodsoft-Nachrichteneingang auf)
-
- %p
- Betreff
+= simple_form_for @message do |f|
+ - if Foodsoft.config[:mailing_list].blank?
+ = f.input :sent_to_all, :as => :boolean
+ - else
+ %b Nachrichten an alle
+ verschickst Du bitte über den Verteiler:
+ = mail_to Foodsoft.config[:mailing_list]
%br/
- = f.text_field :subject
+ %small{:style => "color:grey"}
+ Eventuell musst Du Dich dem Verteiler erst bekannt machen.
+ %br/
+ z.b. mit einer Mail an
+ = mail_to Foodsoft.config[:mailing_list_subscribe]
- %p
- Nachricht
- %br/
- ~ f.text_area :body, :cols => '80', :rows => '20'
-
- = submit_tag "Senden"
\ No newline at end of file
+ #recipients
+ = f.input :recipient_tokens, :input_html => { 'data-pre' => User.find_all_by_id(@message.recipients_ids).map { |u| u.token_attributes }.to_json }
+ = f.input :group_id, :as => :select, :collection => Group.order(:type.desc, :name.desc).all.reject { |g| g.memberships.empty? }
+ = f.input :private
+ = f.input :subject
+ = f.input :body
+ = f.submit
\ No newline at end of file
diff --git a/app/views/messages/show.haml b/app/views/messages/show.haml
index 322d5247..0ca92ab4 100644
--- a/app/views/messages/show.haml
+++ b/app/views/messages/show.haml
@@ -16,6 +16,6 @@
%p= simple_format(h(@message.body))
%hr/
%p
- = link_to('Antworten', reply_message_path(@message))
+ = link_to('Antworten', new_message_path(:message => {:reply_to => @message.id}))
|
= link_to 'Nachricht im Überblick', messages_path
\ No newline at end of file
diff --git a/config/locales/de.yml b/config/locales/de.yml
index 913c8cb3..0d1cbfc3 100644
--- a/config/locales/de.yml
+++ b/config/locales/de.yml
@@ -1,4 +1,6 @@
de:
+ groups:
+
home:
index:
title: Startseite
@@ -156,6 +158,7 @@ de:
workgroup: Arbeitsgruppe
ordergroup: Bestellgruppe
task: Aufgabe
+ message: Nachricht
attributes:
article:
price: Nettopreis
@@ -174,6 +177,8 @@ de:
submit:
create: "%{model} speichern"
update: "Änderungen speichern"
+ message:
+ create: 'Nachricht verschicken'
# Simple form i18n is used to build the forms
simple_form:
@@ -215,6 +220,13 @@ de:
required_users: 'Anzahl'
due_date: 'Wann erledigen?'
workgroup: 'Arbeitsgruppe'
+ message:
+ sent_to_all: 'An alle Mitglieder schicken'
+ recipient_tokens: 'Empfänger_innen'
+ group_id: 'Gruppe'
+ subject: 'Betreff'
+ body: 'Inhalt'
+ private: 'privat verschicken, Nachricht erscheint nicht im Foodsoft Posteingang'
hints:
task:
duration: 'Wie lange dauert die Aufgabe, 1-3 Stunden'
diff --git a/config/routes.rb b/config/routes.rb
index 86aef29b..ee7df381 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -57,13 +57,7 @@ Foodsoft::Application.routes.draw do
end
end
- resources :messages, :only => [:index, :show, :new, :create] do
- member do
- get :reply
- get :user
- get :group
- end
- end
+ resources :messages, :only => [:index, :show, :new, :create]
namespace :foodcoop do
root :to => 'users#index'