Skip to content

Commit 81e1311

Browse files
committed
[PRAC/cont] Add logic to fix "new" add/client
Organiz moving/fixing the newly added client/last line (highlighting). Worth noting: - thus improving the UX. core: B-3 / JS-BL
1 parent 5471ef5 commit 81e1311

File tree

2 files changed

+37
-3
lines changed
  • core-courses/3-js-basic-level/practicum-js-basic-level/sb-crm-client

2 files changed

+37
-3
lines changed

core-courses/3-js-basic-level/practicum-js-basic-level/sb-crm-client/css/page.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
html {
22
box-sizing: border-box;
3-
scroll-behavior: smooth;
43
/* плавная прокрутка */
4+
scroll-behavior: smooth;
55
}
66

77
*,

core-courses/3-js-basic-level/practicum-js-basic-level/sb-crm-client/js/index.js

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,8 +2233,7 @@
22332233

22342234
// и напоследок.. выделение/показ только что добавленного клиента/строки
22352235
setTimeout(() => {
2236-
// TODO:
2237-
// movingToLastNewTableRow();
2236+
movingToLastNewTableRow(); // перемещение фокуса
22382237
}, 300); // временная задержка, больше.. чтобы модальное окно успело закрыться
22392238
}, 200);
22402239
} catch (error) {
@@ -2296,4 +2295,39 @@
22962295
saveButton.style.opacity = saveButton.disabled ? '0.5' : '1';
22972296
saveButton.style.cursor = saveButton.disabled ? 'help' : 'pointer';
22982297
}
2298+
2299+
// ** перемещение/фиксация области просмотра на только что добавленном клиенте/на последней строке (выделение цветом)
2300+
function movingToLastNewTableRow() {
2301+
if (!outputTable) {
2302+
console.error('Таблица НЕ обнаружена!');
2303+
return;
2304+
}
2305+
2306+
const lastNewTableRow = outTableBody.lastElementChild;
2307+
const defaultRowCellColors = [];
2308+
2309+
if (lastNewTableRow) {
2310+
// перемещение к "новому" клиенту/к последней строке таблицы
2311+
lastNewTableRow.scrollIntoView({
2312+
behavior: 'smooth',
2313+
block: 'center',
2314+
});
2315+
2316+
// изменение цвета/выделение строки
2317+
lastNewTableRow.querySelectorAll('td').forEach((td) => {
2318+
defaultRowCellColors.push(td.style.color);
2319+
td.style.fontWeight = 'bold';
2320+
// td.style.color = '#e10c22'; // красный
2321+
td.style.color = '#198754'; // или.. зелёный
2322+
});
2323+
2324+
// возврат к default цвету, через несколько секунды
2325+
setTimeout(() => {
2326+
lastNewTableRow.querySelectorAll('td').forEach((td, index) => {
2327+
td.style.fontWeight = 'normal';
2328+
td.style.color = defaultRowCellColors[index];
2329+
});
2330+
}, 2000);
2331+
}
2332+
}
22992333
})();

0 commit comments

Comments
 (0)