Improve user interface for creating new messages in messages plugin
This commit is contained in:
parent
185f682f6c
commit
a10aa75f49
8 changed files with 139 additions and 37 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) }
|
||||
|
@ -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 if send_method == 'order'
|
||||
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)
|
||||
|
@ -40,14 +45,42 @@ class Message < ActiveRecord::Base
|
|||
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)
|
||||
self.group_id = workgroup_id if send_method == 'workgroup'
|
||||
end
|
||||
|
||||
def ordergroup_id=(ordergroup_id)
|
||||
self.group_id = ordergroup_id if send_method == 'ordergroup'
|
||||
end
|
||||
|
||||
def messagegroup_id=(messagegroup_id)
|
||||
self.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)
|
||||
|
|
|
@ -10,15 +10,68 @@
|
|||
theme: 'facebook'
|
||||
});
|
||||
|
||||
$('#message_send_to_all').on('change', function() {
|
||||
if ($(this).is(':checked')) {
|
||||
$('#recipients').slideUp();
|
||||
} else {
|
||||
function slideRecipients() {
|
||||
if ($('#message_send_to_all').is(':checked')) {
|
||||
$('#recipients').slideDown();
|
||||
} else {
|
||||
$('#recipients').slideUp();
|
||||
}
|
||||
});
|
||||
// make sure state is correct when loading
|
||||
$('#recipients').toggle(!$('#message_send_to_all').is(':checked'));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
$('input[name="message[send_method]"]').on('click', updateSlideState);
|
||||
updateSlideState();
|
||||
});
|
||||
|
||||
- title t('.title')
|
||||
|
@ -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"}
|
||||
|
@ -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}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 specific members
|
||||
order: Send to members, 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
|
||||
|
|
Loading…
Reference in a new issue