Add messagegroup
Messagegroups are a new kind of group. Every user can join and leave such a group on her own. They are useful to create topics for mails. E.g. if there is a weekly newsletter we can create a new messagegroup for it and every user which is interested in receiving the newsletter can join the corresponding group.
This commit is contained in:
parent
b30b4e46d8
commit
01cf6431a9
15 changed files with 172 additions and 9 deletions
|
@ -6,6 +6,7 @@
|
||||||
%dd=h group.contact
|
%dd=h group.contact
|
||||||
%dt= heading_helper(Ordergroup, :contact_address) + ':'
|
%dt= heading_helper(Ordergroup, :contact_address) + ':'
|
||||||
%dd= link_to_gmaps group.contact_address
|
%dd= link_to_gmaps group.contact_address
|
||||||
|
- if group.is_a?(Workgroup)
|
||||||
%dt= t('.access') + ':'
|
%dt= t('.access') + ':'
|
||||||
%dd= format_roles(group)
|
%dd= format_roles(group)
|
||||||
%dt= heading_helper(Ordergroup, :user_tokens) + ':'
|
%dt= heading_helper(Ordergroup, :user_tokens) + ':'
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
# encoding: utf-8
|
||||||
|
class Admin::MessagegroupsController < Admin::BaseController
|
||||||
|
inherit_resources
|
||||||
|
|
||||||
|
def index
|
||||||
|
@messagegroups = Messagegroup.order('name ASC')
|
||||||
|
# if somebody uses the search field:
|
||||||
|
@messagegroups = @messagegroups.where('name LIKE ?', "%#{params[:query]}%") unless params[:query].blank?
|
||||||
|
|
||||||
|
@messagegroups = @messagegroups.page(params[:page]).per(@per_page)
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@messagegroup = Messagegroup.find(params[:id])
|
||||||
|
@messagegroup.destroy
|
||||||
|
redirect_to admin_messagegroups_url, notice: t('admin.messagegroups.destroy.notice')
|
||||||
|
rescue => error
|
||||||
|
redirect_to admin_messagegroups_url, alert: t('admin.messagegroups.destroy.error', error: error.message)
|
||||||
|
end
|
||||||
|
end
|
18
plugins/messages/app/controllers/messagegroups_controller.rb
Normal file
18
plugins/messages/app/controllers/messagegroups_controller.rb
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
class MessagegroupsController < ApplicationController
|
||||||
|
|
||||||
|
def index
|
||||||
|
@messagegroups = Messagegroup.order("name")
|
||||||
|
end
|
||||||
|
|
||||||
|
def join
|
||||||
|
@messagegroup = Messagegroup.find(params[:id])
|
||||||
|
@messagegroup.users << current_user
|
||||||
|
redirect_to messagegroups_url, :notice => I18n.t('messagegroups.join.notice')
|
||||||
|
end
|
||||||
|
|
||||||
|
def leave
|
||||||
|
@messagegroup = Messagegroup.find(params[:id])
|
||||||
|
@messagegroup.users.destroy(current_user)
|
||||||
|
redirect_to messagegroups_url, :notice => I18n.t('messagegroups.leave.notice')
|
||||||
|
end
|
||||||
|
end
|
7
plugins/messages/app/models/messagegroup.rb
Normal file
7
plugins/messages/app/models/messagegroup.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# encoding: utf-8
|
||||||
|
class Messagegroup < Group
|
||||||
|
|
||||||
|
validates_uniqueness_of :name
|
||||||
|
|
||||||
|
protected
|
||||||
|
end
|
|
@ -0,0 +1,5 @@
|
||||||
|
= simple_form_for [:admin, @messagegroup] do |f|
|
||||||
|
= render 'shared/group_form_fields', :f => f
|
||||||
|
.form-actions
|
||||||
|
= f.button :submit
|
||||||
|
= link_to t('ui.or_cancel'), :back
|
|
@ -0,0 +1,18 @@
|
||||||
|
- if Messagegroup.count > 20
|
||||||
|
= items_per_page
|
||||||
|
= pagination_links_remote @messagegroups
|
||||||
|
%table.table.table-striped
|
||||||
|
%thead
|
||||||
|
%tr
|
||||||
|
%th= t '.name'
|
||||||
|
%th= t '.members'
|
||||||
|
%th= t 'ui.actions'
|
||||||
|
%tbody
|
||||||
|
- for messagegroup in @messagegroups
|
||||||
|
%tr
|
||||||
|
%td= link_to messagegroup.name, [:admin, messagegroup]
|
||||||
|
%td= messagegroup.users.size
|
||||||
|
%td
|
||||||
|
= link_to t('ui.edit'), edit_admin_messagegroup_path(messagegroup), class: 'btn btn-mini'
|
||||||
|
= link_to t('ui.delete'), [:admin, messagegroup], :data => {:confirm => t('admin.confirm', name: messagegroup.name)},
|
||||||
|
:method => :delete, class: 'btn btn-mini btn-danger'
|
|
@ -0,0 +1,3 @@
|
||||||
|
- title t '.title'
|
||||||
|
|
||||||
|
= render 'form'
|
|
@ -0,0 +1,14 @@
|
||||||
|
- title t '.title'
|
||||||
|
|
||||||
|
- content_for :actionbar do
|
||||||
|
= link_to t('.new_messagegroup'), new_admin_messagegroup_path, class: 'btn btn-primary'
|
||||||
|
|
||||||
|
- content_for :sidebar do
|
||||||
|
%p= t('.first_paragraph', url: link_to(t('.new_messagegroups'), new_admin_messagegroup_path)).html_safe
|
||||||
|
.well.well-small
|
||||||
|
= form_tag admin_messagegroups_path, :method => :get, :remote => true,
|
||||||
|
'data-submit-onchange' => true, class: 'form-search' do
|
||||||
|
= text_field_tag :query, params[:query], class: 'input-medium search-query',
|
||||||
|
placeholder: t('admin.search_placeholder')
|
||||||
|
#messagegroups
|
||||||
|
= render "messagegroups"
|
|
@ -0,0 +1 @@
|
||||||
|
$('#messagegroups').html('#{escape_javascript(render("messagegroups"))}');
|
|
@ -0,0 +1,3 @@
|
||||||
|
- title t '.title'
|
||||||
|
|
||||||
|
= render 'form'
|
|
@ -0,0 +1,6 @@
|
||||||
|
- title t '.title', name: @messagegroup.name
|
||||||
|
|
||||||
|
%section= render 'shared/group', group: @messagegroup
|
||||||
|
= link_to t('ui.edit'), edit_admin_messagegroup_path(@messagegroup), class: 'btn'
|
||||||
|
= link_to t('ui.delete'), [:admin, @messagegroup], :data => {:confirm => t('.confirm')}, :method => :delete, class: 'btn btn-danger'
|
||||||
|
= link_to t('.send_message'), new_message_path(:message => {:group_id => @messagegroup.id}), class: 'btn'
|
|
@ -0,0 +1,8 @@
|
||||||
|
%section.well
|
||||||
|
%h3= messagegroup.name
|
||||||
|
= render :partial => 'shared/group', :locals => { :group => messagegroup }
|
||||||
|
= link_to_new_message(message_params: {group_id: messagegroup.id})
|
||||||
|
- if messagegroup.member?(current_user)
|
||||||
|
= link_to t('.leave'), leave_messagegroup_path(messagegroup), class: 'btn', method: :post
|
||||||
|
- else
|
||||||
|
= link_to t('.join'), join_messagegroup_path(messagegroup), class: 'btn', method: :post
|
5
plugins/messages/app/views/messagegroups/index.html.haml
Normal file
5
plugins/messages/app/views/messagegroups/index.html.haml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
- title t('.title')
|
||||||
|
|
||||||
|
= t('.body').html_safe
|
||||||
|
|
||||||
|
= render :partial => "messagegroup", :collection => @messagegroups
|
|
@ -8,9 +8,35 @@ en:
|
||||||
recipient_tokens: Recipients
|
recipient_tokens: Recipients
|
||||||
sent_to_all: Send to all members
|
sent_to_all: Send to all members
|
||||||
subject: Subject
|
subject: Subject
|
||||||
|
messagegroup:
|
||||||
|
description: Description
|
||||||
|
name: Name
|
||||||
|
user_tokens: Members
|
||||||
models:
|
models:
|
||||||
message: Message
|
message: Message
|
||||||
|
messagegroup: Messagegroup
|
||||||
admin:
|
admin:
|
||||||
|
messagegroups:
|
||||||
|
destroy:
|
||||||
|
error: 'Messagegroup could not be deleted: %{error}'
|
||||||
|
notice: Messagegroup was deleted
|
||||||
|
edit:
|
||||||
|
title: Edit messagegroup
|
||||||
|
index:
|
||||||
|
first_paragraph: Here you can create %{url}, edit and delete them.
|
||||||
|
new_messagegroup: Create new messagegroup
|
||||||
|
new_messagegroups: new messagegroups
|
||||||
|
title: Messagegroups
|
||||||
|
new:
|
||||||
|
title: Create messagegroup
|
||||||
|
show:
|
||||||
|
confirm: Are you sure?
|
||||||
|
edit: Edit group/members
|
||||||
|
send_message: Send message
|
||||||
|
title: Messagegroup %{name}
|
||||||
|
messagegroups:
|
||||||
|
members: Members
|
||||||
|
name: Name
|
||||||
ordergroups:
|
ordergroups:
|
||||||
show:
|
show:
|
||||||
send_message: Send message
|
send_message: Send message
|
||||||
|
@ -39,6 +65,19 @@ en:
|
||||||
view_all: See all messages
|
view_all: See all messages
|
||||||
start_nav:
|
start_nav:
|
||||||
write_message: Write message
|
write_message: Write message
|
||||||
|
messagegroups:
|
||||||
|
index:
|
||||||
|
body: You can join or leave any of the messagegroups.
|
||||||
|
title: Messagegroups
|
||||||
|
join:
|
||||||
|
error: 'Messagegroup could not be joined: %{error}'
|
||||||
|
notice: Messagegroup was joined
|
||||||
|
leave:
|
||||||
|
error: 'Messagegroup could not be left: %{error}'
|
||||||
|
notice: Messagegroup was left
|
||||||
|
messagegroup:
|
||||||
|
join: Join messagegroup
|
||||||
|
leave: Leave messagegroup
|
||||||
messages:
|
messages:
|
||||||
create:
|
create:
|
||||||
notice: Message is saved and will be sent.
|
notice: Message is saved and will be sent.
|
||||||
|
@ -99,4 +138,7 @@ en:
|
||||||
|
|
||||||
'
|
'
|
||||||
navigation:
|
navigation:
|
||||||
|
admin:
|
||||||
|
messagegroups: Messagegroups
|
||||||
|
messagegroups: Messagegroups
|
||||||
messages: Messages
|
messages: Messages
|
||||||
|
|
|
@ -2,15 +2,27 @@ module FoodsoftMessages
|
||||||
class Engine < ::Rails::Engine
|
class Engine < ::Rails::Engine
|
||||||
def navigation(primary, context)
|
def navigation(primary, context)
|
||||||
return unless FoodsoftMessages.enabled?
|
return unless FoodsoftMessages.enabled?
|
||||||
return if primary[:foodcoop].nil?
|
unless primary[:foodcoop].nil?
|
||||||
sub_nav = primary[:foodcoop].sub_navigation
|
sub_nav = primary[:foodcoop].sub_navigation
|
||||||
sub_nav.items <<
|
sub_nav.items <<
|
||||||
SimpleNavigation::Item.new(primary, :message_threads, I18n.t('navigation.messages'), context.message_threads_path)
|
SimpleNavigation::Item.new(primary, :messagegroups, I18n.t('navigation.messagegroups'), context.messagegroups_path)
|
||||||
|
sub_nav.items <<
|
||||||
|
SimpleNavigation::Item.new(primary, :messages, I18n.t('navigation.messages'), context.messages_path)
|
||||||
# move to right before tasks item
|
# move to right before tasks item
|
||||||
if i = sub_nav.items.index(sub_nav[:tasks])
|
if i = sub_nav.items.index(sub_nav[:tasks])
|
||||||
sub_nav.items.insert(i, sub_nav.items.delete_at(-1))
|
sub_nav.items.insert(i, sub_nav.items.delete_at(-1))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
unless primary[:admin].nil?
|
||||||
|
sub_nav = primary[:admin].sub_navigation
|
||||||
|
sub_nav.items <<
|
||||||
|
SimpleNavigation::Item.new(primary, :messagegroups, I18n.t('navigation.admin.messagegroups'), context.admin_messagegroups_path)
|
||||||
|
# move to right before config item
|
||||||
|
if i = sub_nav.items.index(sub_nav[:config])
|
||||||
|
sub_nav.items.insert(i, sub_nav.items.delete_at(-1))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def default_foodsoft_config(cfg)
|
def default_foodsoft_config(cfg)
|
||||||
cfg[:use_messages] = true
|
cfg[:use_messages] = true
|
||||||
|
|
Loading…
Reference in a new issue