Compare commits

...

2 commits

Author SHA1 Message Date
4a3410de81
Add a hook when sending a new conversation
This is still a work in progress, this hook has no actual effect on the recipients list yet.
2024-07-18 18:22:16 +02:00
48c129c812
Add the ability to select Customers Groups when starting a new Conversation
This is only a cosmetic addition for now, the selected groups are ignored when the form is submitted.
2024-07-18 16:18:10 +02:00
2 changed files with 74 additions and 2 deletions

View file

@ -6,8 +6,15 @@
namespace Modules\MMFCustomersGroups\Providers;
use Eventy;
use View;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\ServiceProvider;
use Modules\MMFCustomersGroups\Entities\CustomersGroup;
use Modules\MMFCustomersGroups\Entities\Mailbox;
class MMFCustomersGroupsServiceProvider extends ServiceProvider {
/**
* Indicates if loading of the provider is deferred.
@ -75,8 +82,37 @@ class MMFCustomersGroupsServiceProvider extends ServiceProvider {
*/
public function hooks() {
// Add a menu entry to manage the customer groups.
\Eventy::addAction('menu.manage.after_mailboxes', function() {
echo \View::make('mmfcustomersgroups::partials/menu', [])->render();
Eventy::addAction('menu.manage.after_mailboxes', function() {
echo View::make('mmfcustomersgroups::partials/menu', [])->render();
});
// Add a list of customer groups to select from when writing a new conversation.
Eventy::addAction('conversation.create_form.before_subject', function($conversation, $mailbox, $thread) {
// We must fetch a fresh Mailbox instance,
// as the one that has been passed does not have a "groups" relationship.
$mailbox = Mailbox::find($mailbox->id);
$groups = $mailbox->groups;
echo View::make(
'mmfcustomersgroups::conversations/partials/groups-selection',
[
'groups' => $groups,
],
)->render();
}, 20, 3);
// Update the list of recipients if some groups have been selected.
Eventy::addAction('conversation.send_reply_save', function($conversation, $request) {
$groups = $request->groups;
// Return early if no group has been selected.
if ( empty($groups) ) return;
// Get the list of e-mails included in the selected groups.
$emails = new Collection;
foreach ( $groups as $group_id ) {
$group = CustomersGroup::find($group_id);
$emails->concat($group->emails());
}
$emails = $emails->unique();
// TODO: Update $conversation to include this list of e-mails.
}, 20, 2);
}
}

View file

@ -0,0 +1,36 @@
<?php
/*
SPDX-License-Identifier: AGPL-3.0-only
SPDX-FileCopyrightText: © 2024 Millions Missing FRANCE <info@millionsmissing.fr>
*/
?>
@include('partials/flash_messages')
<!-- List of Customers Groups that should be included in this Conversation -->
<div class="form-group{{ $errors->has('groups') ? ' has-error' : '' }}">
<label for="groups" class="col-sm-2 control-label">{{ __('Groups selection') }}</label>
<div class="col-sm-9">
<div class="multi-container">
@foreach ( $groups as $group )
<div class="control-group">
<div class="controls">
<label
class="control-label checkbox"
for="group-{{ $group->id }}"
style="text-align: left;"
>
<input
type="checkbox"
name="groups[]"
id="group-{{ $group->id }}"
value="{{ $group->id }}"
>
{{ $group->name }}
</label>
</div>
</div>
@endforeach
</div>
</div>
</div>