diff --git a/autoload/controls/class.Tasks.php b/autoload/controls/class.Tasks.php index 1030a81..664e124 100644 --- a/autoload/controls/class.Tasks.php +++ b/autoload/controls/class.Tasks.php @@ -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; } diff --git a/templates/tasks/task_popup.php b/templates/tasks/task_popup.php index 726d2f9..b57f989 100644 --- a/templates/tasks/task_popup.php +++ b/templates/tasks/task_popup.php @@ -23,6 +23,9 @@ Lista kontrolna () Komentarze () Załączniki () + user['id'] == 1 ):?> + Uczestnicy +
task['users'] ) ): foreach ( $this -> task['users'] as $user_tmp_id ):?> @@ -109,6 +112,22 @@
+ user['id'] == 1 ):?> +
+
+

Uczestnicy

+
+ all_users ) ): foreach ( $this -> all_users as $u ):?> + + +
+ Zapisz +
+
+
@@ -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 += '
' + initials + '
' + names[i] + '
'; + } + 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 ) ) ) {