Refactored messages modul, but refactoring is still neccessary.
This commit is contained in:
parent
6ac04d5e19
commit
d5552059ce
13 changed files with 81 additions and 146 deletions
|
@ -7,7 +7,7 @@ class MessagesController < ApplicationController
|
||||||
|
|
||||||
# Creates a new message object.
|
# Creates a new message object.
|
||||||
def new
|
def new
|
||||||
@message = Message.new
|
@message = Message.new(params[:message])
|
||||||
end
|
end
|
||||||
|
|
||||||
# Creates a new message.
|
# Creates a new message.
|
||||||
|
@ -16,8 +16,7 @@ class MessagesController < ApplicationController
|
||||||
if @message.save
|
if @message.save
|
||||||
#FIXME: Send Mails wit ID instead of using message.state ...
|
#FIXME: Send Mails wit ID instead of using message.state ...
|
||||||
call_rake :send_emails
|
call_rake :send_emails
|
||||||
flash[:notice] = "Nachricht ist gespeichert und wird versendet."
|
redirect_to messages_url, :notice => "Nachricht ist gespeichert und wird versendet."
|
||||||
redirect_to messages_path
|
|
||||||
else
|
else
|
||||||
render :action => 'new'
|
render :action => 'new'
|
||||||
end
|
end
|
||||||
|
@ -27,50 +26,4 @@ class MessagesController < ApplicationController
|
||||||
def show
|
def show
|
||||||
@message = Message.find(params[:id])
|
@message = Message.find(params[:id])
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -1,16 +1,4 @@
|
||||||
module MessagesHelper
|
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)
|
def format_subject(message, length)
|
||||||
if message.subject.length > length
|
if message.subject.length > length
|
||||||
subject = truncate(message.subject, :length => length)
|
subject = truncate(message.subject, :length => length)
|
||||||
|
@ -19,6 +7,6 @@ module MessagesHelper
|
||||||
subject = message.subject
|
subject = message.subject
|
||||||
body = truncate(message.body, :length => length - subject.length)
|
body = truncate(message.body, :length => length - subject.length)
|
||||||
end
|
end
|
||||||
"<b>#{link_to(h(subject), message)}</b> <span style='color:grey'>#{h(body)}</span>"
|
"<b>#{link_to(h(subject), message)}</b> <span style='color:grey'>#{h(body)}</span>".html_safe
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,11 +2,11 @@ class Message < ActiveRecord::Base
|
||||||
belongs_to :sender, :class_name => "User", :foreign_key => "sender_id"
|
belongs_to :sender, :class_name => "User", :foreign_key => "sender_id"
|
||||||
|
|
||||||
serialize :recipients_ids, Array
|
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 :pending, where(:email_state => 0)
|
||||||
scope :sent, :conditions => { :email_state => 1 }
|
scope :sent, where(:email_state => 1)
|
||||||
scope :public, :conditions => {:private => false}
|
scope :public, where(:private => false)
|
||||||
|
|
||||||
# Values for the email_state attribute: :none, :pending, :sent, :failed
|
# Values for the email_state attribute: :none, :pending, :sent, :failed
|
||||||
EMAIL_STATE = {
|
EMAIL_STATE = {
|
||||||
|
@ -36,13 +36,22 @@ class Message < ActiveRecord::Base
|
||||||
add_recipients Group.find(group_id).users unless group_id.blank?
|
add_recipients Group.find(group_id).users unless group_id.blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
def recipients_nicks=(nicks)
|
def recipient_tokens=(ids)
|
||||||
@recipients_nicks = nicks
|
@recipient_tokens = ids
|
||||||
add_recipients nicks.split(",").collect { |nick| User.find_by_nick(nick) }
|
add_recipients ids.split(",").collect { |id| User.find(id) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def recipient=(user)
|
def reply_to=(message_id)
|
||||||
@recipients_nicks = user.nick
|
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
|
end
|
||||||
|
|
||||||
# Returns true if this message is a system message, i.e. was sent automatically by the FoodSoft itself.
|
# Returns true if this message is a system message, i.e. was sent automatically by the FoodSoft itself.
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
<p style="clear:both">
|
<p style="clear:both">
|
||||||
<%= link_to 'Bearbeiten', edit_admin_user_path(@user) %>
|
<%= 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 '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}) %>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="box_title"><h2>Gruppenabos</h2></div>
|
<div class="box_title"><h2>Gruppenabos</h2></div>
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
%tbody
|
%tbody
|
||||||
- for ordergroup in @ordergroups
|
- for ordergroup in @ordergroups
|
||||||
%tr{:class => cycle('even','odd', :name => 'ordergroup')}
|
%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=h ordergroup.users.collect { |u| u.nick }.join(", ")
|
||||||
%td
|
%td
|
||||||
- order = ordergroup.orders.first(:order => 'starts DESC')
|
- order = ordergroup.orders.first(:order => 'starts DESC')
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
- users = params[:sort_by_ordergroups] ? @users.sort { |a,b| a.ordergroup.name <=> b.ordergroup.name } : @users
|
- users = params[:sort_by_ordergroups] ? @users.sort { |a,b| a.ordergroup.name <=> b.ordergroup.name } : @users
|
||||||
- for user in users
|
- for user in users
|
||||||
%tr{:class => cycle('even','odd', :name => '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.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.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'
|
%td=h user.phone if @current_user.role_admin? || user.settings["profile.phoneIsPublic"] == '1'
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
%p
|
%p
|
||||||
= link_to "Alle Aufgaben zeigen", :controller => "/tasks", :action => "workgroup", :id => workgroup
|
= 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)
|
- if workgroup.member?(@current_user)
|
||||||
|
|
|
|
||||||
= link_to "Gruppe bearbeiten", edit_foodcoop_workgroup_path(workgroup)
|
= link_to "Gruppe bearbeiten", edit_foodcoop_workgroup_path(workgroup)
|
||||||
|
|
|
@ -6,5 +6,5 @@
|
||||||
%td= format_subject(message, subject_length)
|
%td= format_subject(message, subject_length)
|
||||||
%td= h(message.sender_name)
|
%td= h(message.sender_name)
|
||||||
%td= format_time(message.created_at)
|
%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}))
|
||||||
|
|
|
@ -5,4 +5,4 @@
|
||||||
%div{:style => "text-align:right"}= will_paginate @messages
|
%div{:style => "text-align:right"}= will_paginate @messages
|
||||||
|
|
||||||
#messages
|
#messages
|
||||||
= render :partial => 'messages', :locals => { :subject_length => 130 }
|
= render :partial => 'messages', :locals => { :messages => @messages, :subject_length => 130 }
|
|
@ -1,14 +1,25 @@
|
||||||
%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|
|
$('#message_sent_to_all').click(function() {
|
||||||
= f.error_messages
|
if ($(this).is(':checked')) {
|
||||||
|
$('#recipients').slideUp();
|
||||||
|
} else {
|
||||||
|
$('#recipients').slideDown();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
%p
|
- title "Neue Nachricht"
|
||||||
Empfängerinnen
|
|
||||||
%fieldset
|
= simple_form_for @message do |f|
|
||||||
- if Foodsoft.config[:mailing_list].blank?
|
- if Foodsoft.config[:mailing_list].blank?
|
||||||
= f.check_box :sent_to_all, :onchange => "Element.toggle('recipients')"
|
= f.input :sent_to_all, :as => :boolean
|
||||||
gesamte Foodcoop
|
|
||||||
- else
|
- else
|
||||||
%b Nachrichten an alle
|
%b Nachrichten an alle
|
||||||
verschickst Du bitte über den Verteiler:
|
verschickst Du bitte über den Verteiler:
|
||||||
|
@ -19,43 +30,11 @@
|
||||||
%br/
|
%br/
|
||||||
z.b. mit einer Mail an
|
z.b. mit einer Mail an
|
||||||
= mail_to Foodsoft.config[:mailing_list_subscribe]
|
= 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 --"
|
|
||||||
|
|
||||||
%p
|
#recipients
|
||||||
Privat
|
= f.input :recipient_tokens, :input_html => { 'data-pre' => User.find_all_by_id(@message.recipients_ids).map { |u| u.token_attributes }.to_json }
|
||||||
= f.check_box :private
|
= f.input :group_id, :as => :select, :collection => Group.order(:type.desc, :name.desc).all.reject { |g| g.memberships.empty? }
|
||||||
%small{:style => "color:grey"} (Nachricht taucht nicht im Foodsoft-Nachrichteneingang auf)
|
= f.input :private
|
||||||
|
= f.input :subject
|
||||||
%p
|
= f.input :body
|
||||||
Betreff
|
= f.submit
|
||||||
%br/
|
|
||||||
= f.text_field :subject
|
|
||||||
|
|
||||||
%p
|
|
||||||
Nachricht
|
|
||||||
%br/
|
|
||||||
~ f.text_area :body, :cols => '80', :rows => '20'
|
|
||||||
|
|
||||||
= submit_tag "Senden"
|
|
|
@ -16,6 +16,6 @@
|
||||||
%p= simple_format(h(@message.body))
|
%p= simple_format(h(@message.body))
|
||||||
%hr/
|
%hr/
|
||||||
%p
|
%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
|
= link_to 'Nachricht im Überblick', messages_path
|
|
@ -1,4 +1,6 @@
|
||||||
de:
|
de:
|
||||||
|
groups:
|
||||||
|
|
||||||
home:
|
home:
|
||||||
index:
|
index:
|
||||||
title: Startseite
|
title: Startseite
|
||||||
|
@ -156,6 +158,7 @@ de:
|
||||||
workgroup: Arbeitsgruppe
|
workgroup: Arbeitsgruppe
|
||||||
ordergroup: Bestellgruppe
|
ordergroup: Bestellgruppe
|
||||||
task: Aufgabe
|
task: Aufgabe
|
||||||
|
message: Nachricht
|
||||||
attributes:
|
attributes:
|
||||||
article:
|
article:
|
||||||
price: Nettopreis
|
price: Nettopreis
|
||||||
|
@ -174,6 +177,8 @@ de:
|
||||||
submit:
|
submit:
|
||||||
create: "%{model} speichern"
|
create: "%{model} speichern"
|
||||||
update: "Änderungen speichern"
|
update: "Änderungen speichern"
|
||||||
|
message:
|
||||||
|
create: 'Nachricht verschicken'
|
||||||
|
|
||||||
# Simple form i18n is used to build the forms
|
# Simple form i18n is used to build the forms
|
||||||
simple_form:
|
simple_form:
|
||||||
|
@ -215,6 +220,13 @@ de:
|
||||||
required_users: 'Anzahl'
|
required_users: 'Anzahl'
|
||||||
due_date: 'Wann erledigen?'
|
due_date: 'Wann erledigen?'
|
||||||
workgroup: 'Arbeitsgruppe'
|
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:
|
hints:
|
||||||
task:
|
task:
|
||||||
duration: 'Wie lange dauert die Aufgabe, 1-3 Stunden'
|
duration: 'Wie lange dauert die Aufgabe, 1-3 Stunden'
|
||||||
|
|
|
@ -57,13 +57,7 @@ Foodsoft::Application.routes.draw do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :messages, :only => [:index, :show, :new, :create] do
|
resources :messages, :only => [:index, :show, :new, :create]
|
||||||
member do
|
|
||||||
get :reply
|
|
||||||
get :user
|
|
||||||
get :group
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
namespace :foodcoop do
|
namespace :foodcoop do
|
||||||
root :to => 'users#index'
|
root :to => 'users#index'
|
||||||
|
|
Loading…
Reference in a new issue