calendar: страница с 4 видами, личными событиями и источниками из системы
This commit is contained in:
+4
-42
@@ -77,44 +77,6 @@
|
||||
return String(s || '').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
|
||||
}
|
||||
|
||||
function tzOffsetMinutes(instant) {
|
||||
try {
|
||||
const d = new Date(instant);
|
||||
const parts = new Intl.DateTimeFormat('en-CA', {
|
||||
timeZone: DateTime.tz, year: 'numeric', month: '2-digit', day: '2-digit',
|
||||
hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false
|
||||
}).formatToParts(d);
|
||||
const get = name => Number(parts.find(p => p.type === name)?.value || 0);
|
||||
const asUtc = new Date(Date.UTC(get('year'), get('month') - 1, get('day'), get('hour'), get('minute'), get('second')));
|
||||
return -Math.round((d.getTime() - asUtc.getTime()) / 60000);
|
||||
} catch { return 0; }
|
||||
}
|
||||
|
||||
function toLocalInput(iso) {
|
||||
if (!iso) return '';
|
||||
try {
|
||||
const d = new Date(iso);
|
||||
const parts = new Intl.DateTimeFormat('en-CA', {
|
||||
timeZone: DateTime.tz, year: 'numeric', month: '2-digit', day: '2-digit',
|
||||
hour: '2-digit', minute: '2-digit', hour12: false
|
||||
}).formatToParts(d);
|
||||
const get = name => parts.find(p => p.type === name)?.value || '';
|
||||
return `${get('year')}-${get('month')}-${get('day')}T${get('hour')}:${get('minute')}`;
|
||||
} catch { return ''; }
|
||||
}
|
||||
|
||||
function inputToIso(localDt) {
|
||||
if (!localDt) return null;
|
||||
try {
|
||||
const [datePart, timePart] = String(localDt).split('T');
|
||||
const [y, mo, d] = datePart.split('-').map(Number);
|
||||
const [h, mi] = timePart.split(':').map(Number);
|
||||
const ref = new Date(Date.UTC(y, mo - 1, d, h, mi, 0, 0));
|
||||
const off = tzOffsetMinutes(ref);
|
||||
return new Date(ref.getTime() - off * 60000).toISOString();
|
||||
} catch { return null; }
|
||||
}
|
||||
|
||||
function digestInitial(name) {
|
||||
const s = String(name || '').trim();
|
||||
return s ? s.charAt(0).toUpperCase() : '?';
|
||||
@@ -448,8 +410,8 @@
|
||||
document.getElementById('digestModalTitle').textContent = d ? 'Редактирование сообщения' : 'Новое сообщение';
|
||||
document.getElementById('digestTitle').value = d ? d.title : '';
|
||||
document.getElementById('digestBody').value = d ? d.body : '';
|
||||
document.getElementById('digestPostAt').value = d ? toLocalInput(d.post_at) : '';
|
||||
document.getElementById('digestHideAt').value = d ? toLocalInput(d.hide_at) : '';
|
||||
document.getElementById('digestPostAt').value = d ? dtToLocalInput(d.post_at) : '';
|
||||
document.getElementById('digestHideAt').value = d ? dtToLocalInput(d.hide_at) : '';
|
||||
const pinRow = document.getElementById('digestPinned').closest('.settings-field');
|
||||
const pinInput = document.getElementById('digestPinned');
|
||||
pinInput.checked = d ? !!d.is_pinned : false;
|
||||
@@ -522,8 +484,8 @@
|
||||
const title = titleEl.value.trim();
|
||||
const body = bodyEl.value.trim();
|
||||
const isPinned = document.getElementById('digestPinned').checked;
|
||||
const postAt = inputToIso(document.getElementById('digestPostAt').value);
|
||||
const hideAt = inputToIso(document.getElementById('digestHideAt').value);
|
||||
const postAt = dtInputToIso(document.getElementById('digestPostAt').value);
|
||||
const hideAt = dtInputToIso(document.getElementById('digestHideAt').value);
|
||||
if (!title || !body) {
|
||||
setInvalid(titleEl, !title);
|
||||
setInvalid(bodyEl, !body);
|
||||
|
||||
Reference in New Issue
Block a user