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
|
@ -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
|
||||
|
|
|
@ -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
|
||||
"<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
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
<p style="clear:both">
|
||||
<%= 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}) %>
|
||||
</p>
|
||||
</div>
|
||||
<div class="box_title"><h2>Gruppenabos</h2></div>
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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}))
|
||||
|
|
@ -5,4 +5,4 @@
|
|||
%div{:style => "text-align:right"}= will_paginate @messages
|
||||
|
||||
#messages
|
||||
= render :partial => 'messages', :locals => { :subject_length => 130 }
|
||||
= render :partial => 'messages', :locals => { :messages => @messages, :subject_length => 130 }
|
|
@ -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"
|
||||
#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
|
|
@ -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
|
|
@ -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'
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in a new issue