Add dropdown menu to autocomplete email field from project members

This commit is contained in:
Frederic Guillot 2017-06-03 16:53:40 -04:00
parent e27148dfd8
commit 9668723af4
8 changed files with 62 additions and 5 deletions

View File

@ -5,6 +5,7 @@ New features:
* Automatic action to assign tasks to its creator
* Add the possibility to create a comment when a task is sent by email
* Add dropdown menu to autocomplete email field from project members
Version 1.0.44 (May 28, 2017)
-----------------------------

View File

@ -20,6 +20,7 @@ class TaskMailController extends BaseController
'errors' => $errors,
'task' => $task,
'project' => $project,
'members' => $this->projectPermissionModel->getMembersWithEmail($project['id']),
)));
}

View File

@ -85,7 +85,13 @@ class ProjectGroupRoleModel extends Base
public function getUsers($project_id)
{
return $this->db->table(self::TABLE)
->columns(UserModel::TABLE.'.id', UserModel::TABLE.'.username', UserModel::TABLE.'.name', self::TABLE.'.role')
->columns(
UserModel::TABLE.'.id',
UserModel::TABLE.'.username',
UserModel::TABLE.'.name',
UserModel::TABLE.'.email',
self::TABLE.'.role'
)
->join(GroupMemberModel::TABLE, 'group_id', 'group_id', self::TABLE)
->join(UserModel::TABLE, 'id', 'user_id', GroupMemberModel::TABLE)
->eq(self::TABLE.'.project_id', $project_id)

View File

@ -93,6 +93,24 @@ class ProjectPermissionModel extends Base
return $members;
}
public function getMembers($project_id)
{
$userMembers = $this->projectUserRoleModel->getUsers($project_id);
$groupMembers = $this->projectGroupRoleModel->getUsers($project_id);
$userMembers = array_column_index_unique($userMembers, 'username');
$groupMembers = array_column_index_unique($groupMembers, 'username');
return array_merge($userMembers, $groupMembers);
}
public function getMembersWithEmail($project_id)
{
$members = $this->getMembers($project_id);
return array_filter($members, function (array $user) {
return ! empty($user['email']);
});
}
/**
* Return true if everybody is allowed for the project
*

View File

@ -98,7 +98,13 @@ class ProjectUserRoleModel extends Base
public function getUsers($project_id)
{
return $this->db->table(self::TABLE)
->columns(UserModel::TABLE.'.id', UserModel::TABLE.'.username', UserModel::TABLE.'.name', self::TABLE.'.role')
->columns(
UserModel::TABLE.'.id',
UserModel::TABLE.'.username',
UserModel::TABLE.'.name',
UserModel::TABLE.'.email',
self::TABLE.'.role'
)
->join(UserModel::TABLE, 'id', 'user_id')
->eq('project_id', $project_id)
->asc(UserModel::TABLE.'.username')

View File

@ -1,12 +1,25 @@
<div class="page-header">
<h2><?= $this->text->e($task['title']) ?> &gt; <?= t('Send by email') ?></h2>
</div>
<form method="post" action="<?= $this->url->href('TaskMailController', 'send', array('task_id' => $task['id'], 'project_id' => $task['project_id'])) ?>" autocomplete="off">
<form method="post" action="<?= $this->url->href('TaskMailController', 'send', array('task_id' => $task['id'], 'project_id' => $task['project_id'])) ?>" autocomplete="off" class="js-task-mail-form">
<?= $this->form->csrf() ?>
<?= $this->form->label(t('Email'), 'email') ?>
<?= $this->form->email('email', $values, $errors, array('autofocus', 'required', 'tabindex="1"')) ?>
<?php if (! empty($members)): ?>
<div class="dropdown">
<a href="#" class="dropdown-menu dropdown-menu-link-icon"><i class="fa fa-address-card-o"></i><i class="fa fa-caret-down"></i></a>
<ul>
<?php foreach ($members as $member): ?>
<li data-email="<?= $this->text->e($member['email']) ?>" class="js-autocomplete-email">
<?= $this->text->e($this->user->getFullname($member)) ?>
</li>
<?php endforeach ?>
</ul>
</div>
<?php endif ?>
<?= $this->form->label(t('Subject'), 'subject') ?>
<?= $this->form->text('subject', $values, $errors, array('required', 'tabindex="2"')) ?>

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,12 @@
KB.onClick('.js-autocomplete-email', function (e) {
var email = KB.dom(e.target).data('email');
if (email) {
var emailField = KB.find('.js-task-mail-form input[type="email"]');
if (emailField) {
emailField.attr('value', email);
_KB.controllers['Dropdown'].close();
}
}
});