feat: Refactor project and user selection handling in task edit to improve input parsing and checkbox management

This commit is contained in:
2025-08-08 00:01:10 +02:00
parent 24696a267d
commit 0b8c7c4780
2 changed files with 34 additions and 22 deletions

View File

@@ -452,8 +452,8 @@
},
"main_view.php": {
"type": "-",
"size": 31639,
"lmtime": 1745260051438,
"size": 31758,
"lmtime": 1754514238562,
"modified": false
},
"task_edit.php": {

View File

@@ -770,27 +770,39 @@
e.preventDefault();
var projects = $( this ).find( 'option:selected' ).attr( 'projects' );
var users = $( this ).find( 'option:selected' ).attr( 'users' );
if ( projects )
{
var projects = projects.split( "," ); console.log( projects );
// toggle checkboxes and prevent load ajax twice
$( '.projects_container input[name="projects"].g-checkbox' ).each( function() {
if ( $.inArray( $( this ).val(), projects ) !== -1 )
$( this ).attr( 'checked', 'checked' );
else
$( this ).removeAttr( 'checked' );
});
// parsowanie wejść (string "1,2,3" -> ['1','2','3'])
const projectsArr = String(projects || '')
.split(',')
.map(s => s.trim())
.filter(Boolean);
const usersArr = String(users || '')
.split(',')
.map(s => s.trim())
.filter(Boolean);
// UPEWNIJ SIĘ, jak brzmi nazwa pól w HTML: projects czy projects[]
const $projectInputs = $('.projects_container input[name="projects[]"].g-checkbox, .projects_container input[name="projects"].g-checkbox');
const $userInputs = $('.projects_container input[name="users[]"].g-checkbox, .projects_container input[name="users"].g-checkbox');
// najpierw czyścimy
$projectInputs.prop('checked', false);
$userInputs.prop('checked', false);
// ustawiamy zaznaczenia
$projectInputs.each(function () {
const val = String($(this).val()).trim();
if (projectsArr.includes(val)) $(this).prop('checked', true);
});
$userInputs.each(function () {
const val = String($(this).val()).trim();
if (usersArr.includes(val)) $(this).prop('checked', true);
});
// wywołuj z tablicami, nie ze stringami
reload_tasks(projectsArr, usersArr);
var users = users.split( "," ); console.log( users );
// toggle checkboxes and prevent load ajax twice
$( '.projects_container input[name="users"].g-checkbox' ).each( function() {
if ( $.inArray( $( this ).val(), users ) !== -1 )
$( this ).attr( 'checked', 'checked' );
else
$( this ).removeAttr( 'checked' );
});
reload_tasks( projects, users );
}
});
$( 'body' ).on( 'click', '.task_popup .task-delete', function(e) {