| Server IP : 10.200.247.200 / Your IP : 216.73.217.19 Web Server : Apache System : Linux synergy-usa-sites 6.8.0-138-generic #138-Ubuntu SMP PREEMPT_DYNAMIC Fri Jul 31 22:41:49 UTC 2026 x86_64 User : jeremy ( 1001) PHP Version : 8.4.25 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/surf_sites/softphone.surfcrm.com/js/ |
Upload File : |
/* Holidays admin page */
(function () {
'use strict';
const API = '/bin/twilio/admin/api/holidays.php';
const lookups = window.TwAdminHolidayLookups || {};
function populateScopeTargets() {
const scope = document.getElementById('hf-scope').value;
const group = document.getElementById('hf-scope_id-group');
const sel = document.getElementById('hf-scope_id');
sel.innerHTML = '';
if (scope === 'global') {
group.classList.add('hide');
return;
}
group.classList.remove('hide');
const blank = document.createElement('option');
blank.value = '';
blank.textContent = '— select —';
sel.appendChild(blank);
const items = scope === 'ring_group' ? (lookups.ring_groups || []) : (lookups.phone_numbers || []);
items.forEach(function (it) {
const opt = document.createElement('option');
opt.value = String(it.id);
opt.textContent = scope === 'ring_group' ? it.name : (it.friendly_name + ' (' + it.e164 + ')');
sel.appendChild(opt);
});
}
function populateBehaviorTarget() {
const beh = document.getElementById('hf-behavior').value;
const group = document.getElementById('hf-custom_flow_sid-group');
const sel = document.getElementById('hf-custom_flow_sid');
sel.innerHTML = '';
if (beh !== 'custom_flow') { group.classList.add('hide'); return; }
group.classList.remove('hide');
const blank = document.createElement('option');
blank.value = '';
blank.textContent = '— select —';
sel.appendChild(blank);
(lookups.call_flows || []).forEach(function (f) {
const opt = document.createElement('option');
opt.value = f.studio_flow_sid;
opt.textContent = f.name;
sel.appendChild(opt);
});
}
function openModal(id) {
const form = document.getElementById('hol-form');
form.reset();
form.elements.timezone.value = 'America/New_York';
form.elements.scope.value = 'global';
form.elements.behavior.value = 'closed';
populateScopeTargets();
populateBehaviorTarget();
if (id) {
const tr = document.querySelector('#hol-table tr[data-id="' + id + '"]');
if (!tr) return;
const row = JSON.parse(tr.getAttribute('data-row'));
document.getElementById('hol-modal-title').textContent = 'Edit holiday';
form.elements.id.value = row.id;
form.elements.date.value = row.date || '';
form.elements.name.value = row.name || '';
form.elements.scope.value = row.scope || 'global';
form.elements.behavior.value = row.behavior || 'closed';
form.elements.timezone.value = row.timezone || 'America/New_York';
populateScopeTargets();
populateBehaviorTarget();
if (row.scope_id) form.elements.scope_id.value = String(row.scope_id);
if (row.custom_flow_sid) form.elements.custom_flow_sid.value = row.custom_flow_sid;
} else {
document.getElementById('hol-modal-title').textContent = 'Add holiday';
form.elements.id.value = '';
}
TwAdmin.openModal('hol-modal');
}
async function submitForm(ev) {
ev.preventDefault();
const form = document.getElementById('hol-form');
const submit = document.getElementById('hf-submit');
submit.disabled = true;
const data = TwAdmin.serializeForm(form);
const id = data.id ? parseInt(data.id, 10) : null;
delete data.id;
if (data.scope === 'global') data.scope_id = null;
else data.scope_id = data.scope_id ? parseInt(data.scope_id, 10) : null;
if (data.behavior !== 'custom_flow') data.custom_flow_sid = null;
try {
if (id) {
await TwAdmin.api(API + '?id=' + id, { method: 'PUT', body: data });
TwAdmin.flash('success', 'Holiday updated.');
} else {
await TwAdmin.api(API, { method: 'POST', body: data });
TwAdmin.flash('success', 'Holiday added.');
}
TwAdmin.closeModal('hol-modal');
setTimeout(function () { window.location.reload(); }, 350);
} catch (e) {
TwAdmin.flash('error', e.message || 'Save failed.');
submit.disabled = false;
}
return false;
}
async function deleteHoliday(id, label) {
if (!TwAdmin.confirmDelete(label)) return;
try {
await TwAdmin.api(API + '?id=' + id, { method: 'DELETE' });
TwAdmin.flash('success', 'Holiday deleted.');
setTimeout(function () { window.location.reload(); }, 350);
} catch (e) {
TwAdmin.flash('error', e.message || 'Delete failed.');
}
}
TwAdmin.openHolidayModal = openModal;
TwAdmin.submitHolidayForm = submitForm;
TwAdmin.deleteHoliday = deleteHoliday;
TwAdmin.refreshHolidayScopeTarget = populateScopeTargets;
TwAdmin.refreshHolidayBehaviorTarget = populateBehaviorTarget;
})();