Skip to content

Commit

Permalink
Campaign Members: UI improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
J. Payne committed Feb 13, 2020
1 parent e642a00 commit 9766bd4
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 34 deletions.
4 changes: 2 additions & 2 deletions app/Http/Controllers/CampaignInviteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function store(StoreCampaignInvite $request)

$invitation = CampaignInvite::create($request->only('email', 'role_id', 'type', 'validity'));

return redirect()->route('campaigns.index', ['#member'])
return redirect()->route('campaign_users.index')
->with(
'success_raw',
trans(
Expand All @@ -79,7 +79,7 @@ public function destroy(CampaignInvite $campaignInvite)
$this->authorize('delete', $campaignInvite);

$campaignInvite->delete();
return redirect()->route('campaigns.index', ['#member'])
return redirect()->route('campaign_users.index')
->with('success', trans('campaigns.invites.destroy.success'));
}
}
2 changes: 1 addition & 1 deletion app/Http/Requests/StoreCampaignInvite.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function rules()
$rules['email'] = 'required|email|unique:campaign_invites,email,NULL,id,campaign_id,'
. Auth::user()->campaign->id.',is_active,1';
} else {
$rules['validity'] = 'required|integer';
$rules['validity'] = 'nullable|integer';
}

return $rules;
Expand Down
13 changes: 13 additions & 0 deletions app/Models/CampaignInvite.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

namespace App\Models;

/**
* Class CampaignInvite
* @package App\Models
*
* @property int $id
* @property string $email
* @property int $role_id
* @property int $campaign_id
* @property string $token
* @property bool $is_active
* @property string $type
* @property int $validity
*/
class CampaignInvite extends MiscModel
{
/**
Expand Down
8 changes: 5 additions & 3 deletions app/Services/InviteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,11 @@ public function join(string $token = null)

// Check the type. Links have a number of usage (validity)
if ($invite->type == 'link') {
$invite->validity--;
if ($invite->validity <= 0) {
$invite->is_active = false;
if (!empty($invite->validity)) {
$invite->validity--;
if ($invite->validity <= 0) {
$invite->is_active = false;
}
}
} else {
$invite->is_active = false;
Expand Down
20 changes: 18 additions & 2 deletions public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -72616,7 +72616,8 @@ $(document).ready(function () {
sanitize: false
});
initSelect2();
initCheckboxSwitch(); // Open select2 dropdowns on focus. Don't add this in initSelect2 since we only need this
initCheckboxSwitch();
initCopyToClipboard(); // Open select2 dropdowns on focus. Don't add this in initSelect2 since we only need this
// binded once.

$(document).on('focus', '.select2.select2-container', function (e) {
Expand Down Expand Up @@ -72739,7 +72740,7 @@ $(document).ready(function () {
/*$.each($('.datagrid-search'), function(index) {
$(this).submit(function(event) {
event.preventDefault();
window.location.href =
window.location.href =
});
});*/

Expand Down Expand Up @@ -72981,6 +72982,21 @@ function refreshNotificationList() {
setTimeout(refreshNotificationList, notificationRefreshTimeout);
});
}
/**
* Handler for copying content to the clipboard
*/


function initCopyToClipboard() {
$('[data-clipboard]').click(function (e) {
e.preventDefault();
var $temp = $("<input>");
$("body").append($temp);
$temp.val($(this).data('clipboard')).select();
document.execCommand("copy");
$temp.remove();
});
}
/**
* Register the tooltip and tooltip-ajax helper
*/
Expand Down
2 changes: 1 addition & 1 deletion public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"/js/api.js": "/js/api.js?id=11839099e7f9f3e77ea8",
"/js/app.js": "/js/app.js?id=0e5fda3cf3d0c1d2fe9f",
"/js/app.js": "/js/app.js?id=f6ca13f4f69b3bd8b98f",
"/css/bootstrap.css": "/css/bootstrap.css?id=fb65dc6b3a03598dfbfe",
"/css/vendor.css": "/css/vendor.css?id=244d384e213ecef80399",
"/css/app.css": "/css/app.css?id=0350f8916771af60b722",
Expand Down
16 changes: 16 additions & 0 deletions resources/assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ $(document).ready(function() {
sanitize: false,
});


initSelect2();
initCheckboxSwitch();
initCopyToClipboard();

// Open select2 dropdowns on focus. Don't add this in initSelect2 since we only need this
// binded once.
Expand Down Expand Up @@ -415,6 +417,20 @@ function refreshNotificationList() {
);
}

/**
* Handler for copying content to the clipboard
*/
function initCopyToClipboard() {
$('[data-clipboard]').click(function (e) {
e.preventDefault();
var $temp = $("<input>");
$("body").append($temp);
$temp.val($(this).data('clipboard')).select();
document.execCommand("copy");
$temp.remove();
});
}

/**
* Register the tooltip and tooltip-ajax helper
*/
Expand Down
4 changes: 3 additions & 1 deletion resources/lang/en/campaigns.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
'invites' => [
'actions' => [
'add' => 'Invite',
'copy' => 'Copy the link to your clipboard',
'link' => 'New Link',
],
'create' => [
Expand Down Expand Up @@ -113,7 +114,7 @@
'validity' => 'Validity',
],
'helpers' => [
'validity' => 'How many users can use this link before it is deactivated.',
'validity' => 'How many users can use this link before it is deactivated. Leave blank for unlimited',
],
'placeholders' => [
'email' => 'Email address of the person you wish to invite',
Expand All @@ -122,6 +123,7 @@
'email' => 'Email',
'link' => 'Link',
],
'unlimited_validity' => 'Unlimited',
],
'leave' => [
'confirm' => 'Are you sure you want to leave the :name campaign? You won\'t be able to access it anymore, unless an Admin of the campaign invites you again.',
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/fr/campaigns.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
'validity' => 'Validité',
],
'helpers' => [
'validity' => 'Nombre de fois que le lie peut être utilisé avant d\'être désactivé.',
'validity' => 'Nombre de fois que le lie peut être utilisé avant d\'être désactivé. Laisser vide pour illimité.',
],
'placeholders' => [
'email' => 'L\'adresse email de ton ami',
Expand Down
53 changes: 32 additions & 21 deletions resources/views/campaigns/_users.blade.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<div class="box box-solid">
<div class="box-body">
<h2 class="page-header with-border">
{{ trans('campaigns.show.tabs.members') }}
{{ __('campaigns.show.tabs.members') }}
</h2>

<p class="help-block">
{{ trans('campaigns.members.help') }}
{{ __('campaigns.members.help') }}
{!! __('campaigns.members.helpers.admin', ['link' => link_to_route('faq.show', __('front.menu.faq'), ['key' => 'user-switch'], ['target' => '_blank'])]) !!}
</p>

<table id="campaign-members" class="table table-hover table-striped">
<tbody><tr>
<th>{{ trans('campaigns.members.fields.name') }}</th>
<th>{{ trans('campaigns.members.fields.roles') }}</th>
<th class="hidden-xs hidden-md">{{ trans('campaigns.members.fields.joined') }}</th>
<th class="hidden-xs hidden-md">{{ trans('campaigns.members.fields.last_login') }}</th>
<th>{{ __('campaigns.members.fields.name') }}</th>
<th>{{ __('campaigns.members.fields.roles') }}</th>
<th class="hidden-xs hidden-md">{{ __('campaigns.members.fields.joined') }}</th>
<th class="hidden-xs hidden-md">{{ __('campaigns.members.fields.last_login') }}</th>
<th>&nbsp;</th>
</tr>
<?php /** @var \App\Models\CampaignUser $relation */?>
Expand Down Expand Up @@ -46,7 +46,7 @@
@can('delete', $relation)
{!! Form::open(['method' => 'DELETE','route' => ['campaign_users.destroy', $relation->id],'style'=>'display:inline']) !!}
<button class="btn btn-xs btn-danger">
<i class="fa fa-trash" aria-hidden="true"></i> <span class="hidden-xs hidden-md">{{ trans('crud.remove') }}</span>
<i class="fa fa-trash" aria-hidden="true"></i> <span class="hidden-xs hidden-md">{{ __('crud.remove') }}</span>
</button>
{!! Form::close() !!}
@endcan
Expand All @@ -62,9 +62,9 @@
@if (Auth::user()->can('invite', $campaign))
<div class="box box-solid">
<div class="box-body">
<h2 class="page-header with-border">{{ trans('campaigns.members.invite.title') }}</h2>
<h2 class="page-header with-border">{{ __('campaigns.members.invite.title') }}</h2>
<p class="help-block">
{{ trans('campaigns.members.invite.description') }}
{{ __('campaigns.members.invite.description') }}
{!! __('campaigns.members.invite.more', [
'link' =>
'<a href="' . route('campaign_roles.index') . '">'
Expand All @@ -74,45 +74,56 @@

<table id="campaign-invites" class="table table-hover table-striped">
<tbody><tr>
<th>{{ trans('campaigns.invites.fields.type') }}</th>
<th class="hidden-xs hidden-md">{{ trans('campaigns.invites.fields.email') }}</th>
<th>{{ trans('campaigns.invites.fields.validity') }}</th>
<th>{{ trans('campaigns.invites.fields.role') }}</th>
<th class="hidden-xs hidden-md">{{ trans('campaigns.invites.fields.created') }}</th>
<th>{{ __('campaigns.invites.fields.type') }}</th>
<th>{{ __('campaigns.invites.fields.email') }}</th>
<th>{{ __('campaigns.invites.fields.validity') }}</th>
<th>{{ __('campaigns.invites.fields.role') }}</th>
<th class="hidden-xs hidden-md">{{ __('campaigns.invites.fields.created') }}</th>
<th class="text-right">
<a href="{{ route('campaign_invites.create', ['type' => 'link']) }}" class="btn btn-primary btn-sm"
data-toggle="ajax-modal" data-target="#entity-modal" data-url="{{ route('campaign_invites.create', ['type' => 'link']) }}">
<i class="fa fa-link" aria-hidden="true"></i>
<span class="hidden-xs hidden-md">{{ trans('campaigns.invites.actions.link') }}</span>
<span class="hidden-xs hidden-md">{{ __('campaigns.invites.actions.link') }}</span>
</a>

<a href="{{ route('campaign_invites.create') }}" class="btn btn-primary btn-sm"
data-toggle="ajax-modal" data-target="#entity-modal" data-url="{{ route('campaign_invites.create') }}">
<i class="fa fa-plus" aria-hidden="true"></i>
<span class="hidden-xs hidden-md">{{ trans('campaigns.invites.actions.add') }}</span>
<span class="hidden-xs hidden-md">{{ __('campaigns.invites.actions.add') }}</span>
</a>
</th>
</tr>
@foreach ($r = $campaign->unusedInvites()->with('role')->paginate() as $relation)
<tr>
<td>{{ trans('campaigns.invites.types.' . $relation->type) }}</td>
<td class="hidden-xs hidden-md">@if($relation->type == 'email'){{ $relation->email }}@else<a href="{{ route('campaigns.join', ['token' => $relation->token]) }}">{{ substr($relation->token, 0, 12) . '...' }}</a>@endif</td>
<td>{{ $relation->validity }}</td>
<td>{{ __('campaigns.invites.types.' . $relation->type) }}</td>
<td>
@if($relation->type == 'email')<span class="hidden-sm hidden-xs">{{ $relation->email }}</span>
@else
<a href="{{ route('campaigns.join', ['token' => $relation->token]) }}" class="hidden-sm hidden-xs">
{{ substr($relation->token, 0, 6) . '...' }}
</a>
<a href="#" title="{{ __('campaigns.invites.actions.copy') }}" data-clipboard="{{ route('campaigns.join', ['token' => $relation->token]) }}" data-toggle="tooltip">
<i class="fa fa-copy"></i>
</a>
@endif
</td>
<td
<td>{{ $relation->validity !== null ? $relation->validity : __('campaigns.invites.unlimited_validity') }}</td>
<td>{{ $relation->role ? $relation->role->name : null }}</td>
<td class="hidden-xs hidden-md"><span title="{{ $relation->created_at }}+00:00">{{ $relation->created_at->diffForHumans() }}</span></td>

<td class="text-right">
{!! Form::open(['method' => 'DELETE','route' => ['campaign_invites.destroy', $relation->id],'style'=>'display:inline']) !!}
<button class="btn btn-xs btn-danger">
<i class="fa fa-trash" aria-hidden="true"></i> <span class="hidden-xs hidden-md">{{ trans('crud.remove') }}</span>
<i class="fa fa-trash" aria-hidden="true"></i> <span class="hidden-xs hidden-md">{{ __('crud.remove') }}</span>
</button>
{!! Form::close() !!}
</td>
</tr>
@endforeach
</tbody></table>

{{ $r->fragment('tab_member')->links() }}
{{ $r->links() }}
</div>
</div>
@endif
4 changes: 2 additions & 2 deletions resources/views/campaigns/invites/_form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
{!! Form::text('email', null, ['placeholder' => trans('campaigns.invites.placeholders.email'), 'class' => 'form-control']) !!}
@else
<label>{{ trans('campaigns.invites.fields.validity') }}</label>
{!! Form::select('validity', [1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 10 => 10], null, ['class' => 'form-control']) !!}
{!! Form::text('validity', null, ['class' => 'form-control', 'maxlength' => 3]) !!}
<p class="help-block">{{ trans('campaigns.invites.helpers.validity') }}</p>
@endif
</div>

<div class="form-group required">
<label>{{ trans('campaigns.invites.fields.role') }}</label>
{!! Form::select('role_id', Auth::user()->campaign->roles()->where('is_public', false)->pluck('name', 'id'), null, ['class' => 'select form-control']) !!}
{!! Form::select('role_id', Auth::user()->campaign->roles()->where(['is_public' => false, 'is_admin' => false])->pluck('name', 'id'), null, ['class' => 'select form-control']) !!}
</div>

<div class="form-group">
Expand Down

0 comments on commit 9766bd4

Please sign in to comment.