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
|
orders: Bestellung
|
||||||
paid_on: Bezahlt am
|
paid_on: Bezahlt am
|
||||||
supplier: Lieferant
|
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:
|
order:
|
||||||
boxfill: Kistenfüllen ab
|
boxfill: Kistenfüllen ab
|
||||||
closed_by: Abgerechnet von
|
closed_by: Abgerechnet von
|
||||||
|
|
|
@ -74,13 +74,6 @@ en:
|
||||||
orders: Order
|
orders: Order
|
||||||
paid_on: Paid on
|
paid_on: Paid on
|
||||||
supplier: Supplier
|
supplier: Supplier
|
||||||
message:
|
|
||||||
body: Body
|
|
||||||
group_id: Group
|
|
||||||
private: Private
|
|
||||||
recipient_tokens: Recipients
|
|
||||||
send_to_all: Send to all members
|
|
||||||
subject: Subject
|
|
||||||
order:
|
order:
|
||||||
boxfill: Fill boxes after
|
boxfill: Fill boxes after
|
||||||
closed_by: Settled by
|
closed_by: Settled by
|
||||||
|
|
|
@ -76,10 +76,8 @@ fr:
|
||||||
supplier: Fournisseur-e
|
supplier: Fournisseur-e
|
||||||
message:
|
message:
|
||||||
body: Contenu
|
body: Contenu
|
||||||
group_id: Cellule ou équipe
|
|
||||||
private: Privé
|
private: Privé
|
||||||
recipient_tokens: Destinataires
|
recipient_tokens: Destinataires
|
||||||
send_to_all: Envoyer à tous les membres
|
|
||||||
subject: Sujet
|
subject: Sujet
|
||||||
order:
|
order:
|
||||||
boxfill:
|
boxfill:
|
||||||
|
|
|
@ -76,10 +76,8 @@ nl:
|
||||||
supplier: Leverancier
|
supplier: Leverancier
|
||||||
message:
|
message:
|
||||||
body: Bericht
|
body: Bericht
|
||||||
group_id: Groep
|
|
||||||
private: Privé
|
private: Privé
|
||||||
recipient_tokens: Geadresseerden
|
recipient_tokens: Geadresseerden
|
||||||
send_to_all: Aan alle leden sturen
|
|
||||||
subject: Onderwerp
|
subject: Onderwerp
|
||||||
order:
|
order:
|
||||||
boxfill: Dozen vullen na
|
boxfill: Dozen vullen na
|
||||||
|
|
|
@ -6,7 +6,7 @@ class Message < ActiveRecord::Base
|
||||||
belongs_to :reply_to_message, :class_name => "Message", :foreign_key => "reply_to"
|
belongs_to :reply_to_message, :class_name => "Message", :foreign_key => "reply_to"
|
||||||
|
|
||||||
serialize :recipients_ids, Array
|
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 :pending, -> { where(:email_state => 0) }
|
||||||
scope :sent, -> { where(:email_state => 1) }
|
scope :sent, -> { where(:email_state => 1) }
|
||||||
|
@ -25,13 +25,18 @@ class Message < ActiveRecord::Base
|
||||||
validates_length_of :subject, :in => 1..255
|
validates_length_of :subject, :in => 1..255
|
||||||
validates_inclusion_of :email_state, :in => EMAIL_STATE.values
|
validates_inclusion_of :email_state, :in => EMAIL_STATE.values
|
||||||
|
|
||||||
|
after_initialize do
|
||||||
|
@send_method ||= 'recipients'
|
||||||
|
end
|
||||||
|
|
||||||
before_create :create_salt
|
before_create :create_salt
|
||||||
before_validation :clean_up_recipient_ids, :on => :create
|
before_validation :clean_up_recipient_ids, :on => :create
|
||||||
|
|
||||||
def clean_up_recipient_ids
|
def clean_up_recipient_ids
|
||||||
add_recipients Group.find(group_id).users unless group_id.blank?
|
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 = 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
|
end
|
||||||
|
|
||||||
def add_recipients(users)
|
def add_recipients(users)
|
||||||
|
@ -40,14 +45,42 @@ class Message < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def group_id=(group_id)
|
def group_id=(group_id)
|
||||||
@group_id = group_id
|
group = Group.find(group_id) unless group_id.blank?
|
||||||
add_recipients Group.find(group_id).users 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
|
super
|
||||||
end
|
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)
|
def order_id=(order_id)
|
||||||
@order_id = order_id
|
@order_id = order_id
|
||||||
add_recipients Order.find(order_id).users_ordered unless order_id.blank?
|
@send_method ||= 'order'
|
||||||
end
|
end
|
||||||
|
|
||||||
def recipient_tokens=(ids)
|
def recipient_tokens=(ids)
|
||||||
|
|
|
@ -10,15 +10,68 @@
|
||||||
theme: 'facebook'
|
theme: 'facebook'
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#message_send_to_all').on('change', function() {
|
function slideRecipients() {
|
||||||
if ($(this).is(':checked')) {
|
if ($('#message_send_to_all').is(':checked')) {
|
||||||
$('#recipients').slideUp();
|
|
||||||
} else {
|
|
||||||
$('#recipients').slideDown();
|
$('#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')
|
- title t('.title')
|
||||||
|
@ -29,9 +82,7 @@
|
||||||
- if @message.reply_to
|
- if @message.reply_to
|
||||||
%p= t('.reply_to', link: link_to(t('.message'), message_path(@message.reply_to))).html_safe
|
%p= t('.reply_to', link: link_to(t('.message'), message_path(@message.reply_to))).html_safe
|
||||||
|
|
||||||
- if FoodsoftConfig[:mailing_list].blank?
|
- unless FoodsoftConfig[:mailing_list].blank?
|
||||||
= f.input :send_to_all, :as => :boolean
|
|
||||||
- else
|
|
||||||
%b= t('.list.desc', list: mail_to(FoodsoftConfig[:mailing_list])).html_safe
|
%b= t('.list.desc', list: mail_to(FoodsoftConfig[:mailing_list])).html_safe
|
||||||
%br/
|
%br/
|
||||||
%small{:style => "color:grey"}
|
%small{:style => "color:grey"}
|
||||||
|
@ -42,9 +93,20 @@
|
||||||
- else
|
- else
|
||||||
= t('.list.mail', email: mail_to(FoodsoftConfig[:mailing_list_subscribe])).html_safe
|
= 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
|
#recipients
|
||||||
= f.input :recipient_tokens, :input_html => { 'data-pre' => User.where(id: @message.recipients_ids).map(&:token_attributes).to_json }
|
= 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 :private, inline_label: t('.hint_private')
|
||||||
= f.input :subject, input_html: {class: 'input-xxlarge'}
|
= f.input :subject, input_html: {class: 'input-xxlarge'}
|
||||||
= f.input :body, input_html: {class: 'input-xxlarge', rows: 13}
|
= f.input :body, input_html: {class: 'input-xxlarge', rows: 13}
|
||||||
|
|
|
@ -1,6 +1,22 @@
|
||||||
de:
|
de:
|
||||||
activerecord:
|
activerecord:
|
||||||
attributes:
|
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:
|
messagegroup:
|
||||||
description: Beschreibung
|
description: Beschreibung
|
||||||
name: Name
|
name: Name
|
||||||
|
|
|
@ -3,11 +3,20 @@ en:
|
||||||
attributes:
|
attributes:
|
||||||
message:
|
message:
|
||||||
body: Body
|
body: Body
|
||||||
group_id: Group
|
messagegroup_id: Messagegroup
|
||||||
|
order_id: Order
|
||||||
|
ordergroup_id: Ordergroup
|
||||||
private: Private
|
private: Private
|
||||||
recipient_tokens: Recipients
|
recipient_tokens: (Additional) recipients
|
||||||
send_to_all: Send to all members
|
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
|
subject: Subject
|
||||||
|
workgroup_id: Workgroup
|
||||||
messagegroup:
|
messagegroup:
|
||||||
description: Description
|
description: Description
|
||||||
name: Name
|
name: Name
|
||||||
|
|
Loading…
Reference in a new issue