feat: Add user management to task popup and implement task user assignment
This commit is contained in:
@@ -342,6 +342,34 @@ class Tasks
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function task_change_users() {
|
||||
global $mdb, $user;
|
||||
|
||||
if ( !$user or $user['id'] != 1 ) {
|
||||
echo json_encode( [ 'status' => 'error' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
$task_id = (int)\S::get( 'task_id' );
|
||||
$users = \S::get( 'users' );
|
||||
|
||||
if ( !$task_id ) {
|
||||
echo json_encode( [ 'status' => 'error' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
$mdb -> delete( 'task_user', [ 'task_id' => $task_id ] );
|
||||
|
||||
if ( is_array( $users ) and !empty( $users ) ) {
|
||||
foreach ( $users as $uid ) {
|
||||
$mdb -> insert( 'task_user', [ 'task_id' => $task_id, 'user_id' => (int)$uid ] );
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode( [ 'status' => 'success' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use \Controllers\TasksController::taskChangeStatus() instead.
|
||||
*/
|
||||
@@ -450,7 +478,8 @@ class Tasks
|
||||
'clients' => \factory\Crm::get_client_list(),
|
||||
'user' => $user,
|
||||
'statuses' => \factory\Tasks::get_statuses(),
|
||||
'projects' => \factory\Projects::user_projects( $user['id'] )
|
||||
'projects' => \factory\Projects::user_projects( $user['id'] ),
|
||||
'all_users' => \factory\Users::users_list()
|
||||
] );
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,9 @@
|
||||
<a href="#" class="js-task-tab-btn" data-tab="checklist" role="tab" aria-selected="false">Lista kontrolna (<?= (int)$checklist_count;?>)</a>
|
||||
<a href="#" class="js-task-tab-btn" data-tab="comments" role="tab" aria-selected="false">Komentarze (<?= (int)$comments_count;?>)</a>
|
||||
<a href="#" class="js-task-tab-btn" data-tab="attachments" role="tab" aria-selected="false">Załączniki (<?= (int)$attachments_count;?>)</a>
|
||||
<? if ( $this -> user['id'] == 1 ):?>
|
||||
<a href="#" class="js-task-tab-btn" data-tab="users" role="tab" aria-selected="false">Uczestnicy</a>
|
||||
<? endif;?>
|
||||
</div>
|
||||
<div class="users box">
|
||||
<? if ( is_array( $this -> task['users'] ) ): foreach ( $this -> task['users'] as $user_tmp_id ):?>
|
||||
@@ -109,6 +112,22 @@
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<? if ( $this -> user['id'] == 1 ):?>
|
||||
<div class="task-tab-panel" data-tab="users">
|
||||
<div class="task-users-edit">
|
||||
<h3>Uczestnicy</h3>
|
||||
<div class="task-users-checkboxes">
|
||||
<? if ( is_array( $this -> all_users ) ): foreach ( $this -> all_users as $u ):?>
|
||||
<label class="task-user-label">
|
||||
<input type="checkbox" class="task-user-checkbox" value="<?= $u['id'];?>" <? if ( is_array( $this -> task['users'] ) and in_array( $u['id'], $this -> task['users'] ) ):?>checked="checked"<? endif;?>>
|
||||
<?= $u['name'] . ' ' . $u['surname'];?>
|
||||
</label>
|
||||
<? endforeach; endif;?>
|
||||
</div>
|
||||
<a href="#" class="btn btn-primary btn-sm js-save-task-users" task_id="<?= $this -> task['id'];?>" style="margin-top: 10px;">Zapisz</a>
|
||||
</div>
|
||||
</div>
|
||||
<? endif;?>
|
||||
</div>
|
||||
<div class="right">
|
||||
<div class="status box">
|
||||
@@ -285,6 +304,23 @@
|
||||
border-color: #6690f4;
|
||||
}
|
||||
|
||||
.task_popup .task_details .task-users-checkboxes {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
.task_popup .task_details .task-user-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
cursor: pointer;
|
||||
padding: 4px 0;
|
||||
font-size: 13px;
|
||||
}
|
||||
.task_popup .task_details .task-user-label input[type="checkbox"] {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* Lightbox - powiększanie zdjęć w opisie */
|
||||
.task_popup .task_details .description img {
|
||||
cursor: zoom-in;
|
||||
@@ -342,7 +378,7 @@
|
||||
if ( !tab_panels.length )
|
||||
return;
|
||||
|
||||
var allowed_tabs = [ 'description', 'checklist', 'comments', 'attachments' ];
|
||||
var allowed_tabs = [ 'description', 'checklist', 'comments', 'attachments', 'users' ];
|
||||
var selected_tab = allowed_tabs.indexOf( tab_name ) >= 0 ? tab_name : 'description';
|
||||
|
||||
tab_panels.each( function() {
|
||||
@@ -429,6 +465,41 @@
|
||||
});
|
||||
});
|
||||
|
||||
popup.on( 'click', '.js-save-task-users', function( e ) {
|
||||
e.preventDefault();
|
||||
var btn = $( this );
|
||||
var task_id = btn.attr( 'task_id' );
|
||||
var users = [];
|
||||
popup.find( '.task-user-checkbox:checked' ).each( function() {
|
||||
users.push( $( this ).val() );
|
||||
});
|
||||
btn.text( 'Zapisywanie...' ).addClass( 'disabled' );
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/tasks/task_change_users/',
|
||||
data: { task_id: task_id, users: users },
|
||||
success: function( response ) {
|
||||
var res = typeof response === 'string' ? JSON.parse( response ) : response;
|
||||
if ( res.status === 'success' ) {
|
||||
var names = [];
|
||||
popup.find( '.task-user-checkbox:checked' ).each( function() {
|
||||
names.push( $( this ).parent().text().trim() );
|
||||
});
|
||||
var html = '';
|
||||
for ( var i = 0; i < names.length; i++ ) {
|
||||
var initials = names[i].split( ' ' ).map( function( w ) { return w[0]; } ).join( '' );
|
||||
html += '<div class="user"><div class="avatar" title="' + names[i] + '">' + initials + '</div>' + names[i] + '</div>';
|
||||
}
|
||||
popup.find( '.users.box' ).html( html );
|
||||
btn.text( 'Zapisano!' );
|
||||
} else {
|
||||
btn.text( 'Błąd' );
|
||||
}
|
||||
setTimeout( function() { btn.text( 'Zapisz' ).removeClass( 'disabled' ); }, 1500 );
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var interval_id = setInterval( function() {
|
||||
if ( !document.body.contains( popup.get( 0 ) ) )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user