Skip to content

Commit

Permalink
Improve user interface for creating new messages in messages plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
paroga committed Sep 30, 2017
1 parent 185f682 commit 558c37c
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 36 deletions.
7 changes: 0 additions & 7 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,6 @@ de:
orders: Bestellung
paid_on: Bezahlt am
supplier: Lieferant
message:
body: Inhalt
group_id: Gruppe
private: Privat
recipient_tokens: Empfänger_innen
send_to_all: An alle Mitglieder schicken
subject: Betreff
order:
boxfill: Kistenfüllen ab
closed_by: Abgerechnet von
Expand Down
7 changes: 0 additions & 7 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,6 @@ en:
orders: Order
paid_on: Paid on
supplier: Supplier
message:
body: Body
group_id: Group
private: Private
recipient_tokens: Recipients
send_to_all: Send to all members
subject: Subject
order:
boxfill: Fill boxes after
closed_by: Settled by
Expand Down
2 changes: 0 additions & 2 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,8 @@ fr:
supplier: Fournisseur-e
message:
body: Contenu
group_id: Cellule ou équipe
private: Privé
recipient_tokens: Destinataires
send_to_all: Envoyer à tous les membres
subject: Sujet
order:
boxfill:
Expand Down
2 changes: 0 additions & 2 deletions config/locales/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,8 @@ nl:
supplier: Leverancier
message:
body: Bericht
group_id: Groep
private: Privé
recipient_tokens: Geadresseerden
send_to_all: Aan alle leden sturen
subject: Onderwerp
order:
boxfill: Dozen vullen na
Expand Down
43 changes: 38 additions & 5 deletions plugins/messages/app/models/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Message < ActiveRecord::Base
belongs_to :reply_to_message, :class_name => "Message", :foreign_key => "reply_to"

serialize :recipients_ids, Array
attr_accessor :send_to_all, :recipient_tokens
attr_accessor :send_method, :recipient_tokens, :order_id

scope :pending, -> { where(:email_state => 0) }
scope :sent, -> { where(:email_state => 1) }
Expand All @@ -25,13 +25,18 @@ class Message < ActiveRecord::Base
validates_length_of :subject, :in => 1..255
validates_inclusion_of :email_state, :in => EMAIL_STATE.values

after_initialize do
@send_method ||= 'recipients'
end

before_create :create_salt
before_validation :clean_up_recipient_ids, :on => :create

def clean_up_recipient_ids
add_recipients Group.find(group_id).users unless group_id.blank?
add_recipients Order.find(order_id).users_ordered unless order_id.blank?
self.recipients_ids = recipients_ids.uniq.reject { |id| id.blank? } unless recipients_ids.nil?
self.recipients_ids = User.undeleted.collect(&:id) if send_to_all == "1"
self.recipients_ids = User.undeleted.collect(&:id) if send_method == 'all'
end

def add_recipients(users)
Expand All @@ -40,14 +45,42 @@ def add_recipients(users)
end

def group_id=(group_id)
@group_id = group_id
add_recipients Group.find(group_id).users unless group_id.blank?
group = Group.find(group_id) unless group_id.blank?
if group
@send_method = 'workgroup' if group.type == 'Workgroup'
@send_method = 'ordergroup' if group.type == 'Ordergroup'
@send_method = 'messagegroup' if group.type == 'Messagegroup'
end
super
end

def workgroup_id
@group_id if send_method == 'workgroup'
end

def ordergroup_id
@group_id if send_method == 'ordergroup'
end

def messagegroup_id
@group_id if send_method == 'messagegroup'
end

def workgroup_id=(workgroup_id)
@group_id = workgroup_id if send_method == 'workgroup'
end

def ordergroup_id=(ordergroup_id)
@group_id = ordergroup_id if send_method == 'ordergroup'
end

def messagegroup_id=(messagegroup_id)
@group_id = messagegroup_id if send_method == 'messagegroup'
end

def order_id=(order_id)
@order_id = order_id
add_recipients Order.find(order_id).users_ordered unless order_id.blank?
@send_method ||= 'order'
end

def recipient_tokens=(ids)
Expand Down
82 changes: 72 additions & 10 deletions plugins/messages/app/views/messages/new.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,68 @@
theme: 'facebook'
});

$('#message_send_to_all').on('change', function() {
if ($(this).is(':checked')) {
$('#recipients').slideUp();
function slideRecipients() {
if ($('#message_send_to_all').is(':checked')) {
$('#recipients').slideDown();
} else {
$('#recipients').slideUp();
}
}

function updateSlideState() {
switch($('input[name="message[send_method]"]:checked').val()) {
case 'all':
$('#workgroup').slideUp();
$('#ordergroup').slideUp();
$('#messagegroup').slideUp();
$('#order').slideUp();
$('#recipients').slideUp();
break;

case 'workgroup':
$('#workgroup').slideDown();
$('#ordergroup').slideUp();
$('#messagegroup').slideUp();
$('#order').slideUp();
$('#recipients').slideDown();
break;

case 'ordergroup':
$('#workgroup').slideUp();
$('#ordergroup').slideDown();
$('#messagegroup').slideUp();
$('#order').slideUp();
$('#recipients').slideDown();
break;

case 'messagegroup':
$('#workgroup').slideUp();
$('#ordergroup').slideUp();
$('#messagegroup').slideDown();
$('#order').slideUp();
$('#recipients').slideDown();
break;

case 'order':
$('#workgroup').slideUp();
$('#ordergroup').slideUp();
$('#messagegroup').slideUp();
$('#order').slideDown();
$('#recipients').slideDown();
break;

case 'recipients':
$('#workgroup').slideUp();
$('#ordergroup').slideUp();
$('#messagegroup').slideUp();
$('#order').slideUp();
$('#recipients').slideDown();
break;
}
});
// make sure state is correct when loading
$('#recipients').toggle(!$('#message_send_to_all').is(':checked'));
}

$('input[name="message[send_method]"]').on('click', updateSlideState);
updateSlideState();
});

- title t('.title')
Expand All @@ -29,9 +82,7 @@
- if @message.reply_to
%p= t('.reply_to', link: link_to(t('.message'), message_path(@message.reply_to))).html_safe

- if FoodsoftConfig[:mailing_list].blank?
= f.input :send_to_all, :as => :boolean
- else
- unless FoodsoftConfig[:mailing_list].blank?
%b= t('.list.desc', list: mail_to(FoodsoftConfig[:mailing_list])).html_safe
%br/
%small{:style => "color:grey"}
Expand All @@ -42,9 +93,20 @@
- else
= t('.list.mail', email: mail_to(FoodsoftConfig[:mailing_list_subscribe])).html_safe

- send_method_collection = [:workgroup, :ordergroup, :messagegroup, :order, :recipients]
- send_method_collection.unshift :all if FoodsoftConfig[:mailing_list].blank?
= f.input :send_method, :as => :radio_buttons, :collection => send_method_collection, :label => false, :label_method => ->(obj){ t("activerecord.attributes.message.send_method.#{obj}") }

#workgroup
= f.input :workgroup_id, :as => :select, include_blank: false, :collection => Workgroup.undeleted.order(:name).includes(:memberships).reject { |g| g.memberships.empty? }
#ordergroup
= f.input :ordergroup_id, :as => :select, include_blank: false, :collection => Ordergroup.undeleted.order(:name).includes(:memberships).reject { |g| g.memberships.empty? }
#messagegroup
= f.input :messagegroup_id, :as => :select, include_blank: false, :collection => Messagegroup.undeleted.order(:name)
#order
= f.input :order_id, :as => :select, include_blank: false, :collection => Order.finished_not_closed.order('pickup DESC').includes(:supplier).limit(25)
#recipients
= f.input :recipient_tokens, :input_html => { 'data-pre' => User.where(id: @message.recipients_ids).map(&:token_attributes).to_json }
= f.input :group_id, :as => :select, :collection => Group.undeleted.order('type DESC', 'name ASC').reject { |g| g.memberships.empty? }
= f.input :private, inline_label: t('.hint_private')
= f.input :subject, input_html: {class: 'input-xxlarge'}
= f.input :body, input_html: {class: 'input-xxlarge', rows: 13}
Expand Down
16 changes: 16 additions & 0 deletions plugins/messages/config/locales/de.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
de:
activerecord:
attributes:
message:
body: Inhalt
messagegroup_id: Nachrichtengruppe
order_id: Bestellung
ordergroup_id: Bestellgruppe
private: Privat
recipient_tokens: (Zusätzliche) Empfänger_innen
send_method:
all: An alle Mitglieder schicken
recipients: An ausgewählte Mitglieder schicken
order: An die Mitglieder schicken, die bei einer Bestellung etwas bestellt haben
ordergroup: An die Mitglieder einer Bestellgruppe schicken
messagegroup: An die Mitglieder einer Nachrichtengruppe schicken
workgroup: An die Mitglieder einer Arbeitsgruppe schicken
subject: Betreff
workgroup_id: Arbeitsgruppe
messagegroup:
description: Beschreibung
name: Name
Expand Down
15 changes: 12 additions & 3 deletions plugins/messages/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@ en:
attributes:
message:
body: Body
group_id: Group
messagegroup_id: Messagegroup
order_id: Order
ordergroup_id: Ordergroup
private: Private
recipient_tokens: Recipients
send_to_all: Send to all members
recipient_tokens: (Additional) recipients
send_method:
all: Send to all members
recipients: Send to sepcific members
order: Send to memebers, who participated at an order
ordergroup: Send to members of a ordergroup
messagegroup: Send to members of a messagegroup
workgroup: Send to members of a workgroup
subject: Subject
workgroup_id: Workgroup
messagegroup:
description: Description
name: Name
Expand Down

0 comments on commit 558c37c

Please sign in to comment.