Commit 60d769cf authored by Fares's avatar Fares

fix(sa): fix coach dropdown click bug and auto-create group on program creation

1. searchable-select.js: mouseover was calling renderList() which replaced
   innerHTML and destroyed the click target DOM node, making options unclickable.
   Now mouseover only toggles inline styles without re-rendering.

2. ProgramController: auto-creates a default group (code-G1) when a new program
   is created, using the first available coach for that discipline.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 7ff8ae2d
......@@ -167,7 +167,40 @@ class ProgramController extends Controller
'is_active' => 1,
]);
return $this->redirect('/sa/programs/' . $program->id)->withSuccess('تم إضافة البرنامج بنجاح');
$db = App::getInstance()->db();
$coach = $db->selectOne(
"SELECT c.id FROM sa_coaches c
INNER JOIN sa_coach_disciplines cd ON cd.coach_id = c.id
WHERE cd.discipline_id = ? AND c.is_active = 1 AND c.is_archived = 0
LIMIT 1",
[$disciplineId]
);
if (!$coach) {
$coach = $db->selectOne("SELECT id FROM sa_coaches WHERE is_active = 1 AND is_archived = 0 LIMIT 1");
}
if ($coach) {
$groupCode = $code . '-G1';
$existing = $db->selectOne("SELECT id FROM sa_groups WHERE code = ?", [$groupCode]);
if (!$existing) {
$db->insert('sa_groups', [
'code' => $groupCode,
'name_ar' => $nameAr . ' - مجموعة 1',
'name_en' => $nameEn ? $nameEn . ' - Group 1' : null,
'program_id' => (int) $program->id,
'coach_id' => (int) $coach['id'],
'min_capacity' => $minCapacity,
'max_capacity' => $maxCapacity,
'current_count' => 0,
'is_full' => 0,
'status' => 'active',
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
]);
}
}
return $this->redirect('/sa/programs/' . $program->id)->withSuccess('تم إضافة البرنامج بنجاح' . ($coach ? ' وتم إنشاء مجموعة افتراضية' : ''));
}
/**
......
......@@ -285,8 +285,13 @@ var SearchableSelect = (function() {
self.list.addEventListener('mouseover', function(e) {
var opt = e.target.closest('.ss-option');
if (opt) {
self.highlightIndex = parseInt(opt.getAttribute('data-idx'), 10);
self.renderList();
var idx = parseInt(opt.getAttribute('data-idx'), 10);
if (idx !== self.highlightIndex) {
var prev = self.list.querySelector('.ss-option[data-idx="' + self.highlightIndex + '"]');
if (prev) prev.style.background = (self.select.value === prev.getAttribute('data-value')) ? '#EFF6FF' : '';
self.highlightIndex = idx;
opt.style.background = '#F3F4F6';
}
}
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment