Added listmonk API call for published article
This commit is contained in:
parent
52065707df
commit
494f3c69a6
3 changed files with 351 additions and 76 deletions
52
admin.php
52
admin.php
|
|
@ -1141,6 +1141,7 @@ try {
|
|||
$dir = resolve_input_dir_from_request($config['uploads_dir'], $_POST['id'] ?? '', $_POST['dir'] ?? '', $articleIndex);
|
||||
$articleId = ensure_state_article_id($dir);
|
||||
$visibleNow = !empty($_POST['visible']);
|
||||
$sendImmediately = !empty($_POST['send_immediately']);
|
||||
$state = input_dir_state($dir);
|
||||
$output = basename((string)($state['output'] ?? ''));
|
||||
$canShow = $output !== '' && is_file($config['videos_dir'].'/'.$output) && !input_dir_preview($dir);
|
||||
|
|
@ -1153,7 +1154,7 @@ try {
|
|||
if ($visibleNow && $canShow) {
|
||||
if (is_file(__DIR__ . '/lib/send_push.php')) {
|
||||
include_once __DIR__ . '/lib/send_push.php';
|
||||
try_send_show_notification($articleId ?: basename($dir), $dir, __DIR__, '/var/log/mvlog_notify.log');
|
||||
try_send_show_notification($articleId ?: basename($dir), $dir, __DIR__, '/var/log/mvlog_notify.log', $sendImmediately);
|
||||
} else {
|
||||
error_log("[mvlog] send_push helper missing, cannot send notification for " . basename($dir) . "
|
||||
", 3, '/var/log/mvlog_notify.log');
|
||||
|
|
@ -1906,17 +1907,65 @@ function initSwitchForms(){
|
|||
});
|
||||
}
|
||||
|
||||
function ensureShowPromptStyles(){
|
||||
if(document.getElementById('show-prompt-styles')) return;
|
||||
const style = document.createElement('style');
|
||||
style.id = 'show-prompt-styles';
|
||||
style.textContent = '#show-prompt-overlay{position:fixed;inset:0;background:rgba(17,24,39,.48);backdrop-filter:blur(1px);display:flex;align-items:center;justify-content:center;z-index:2995;}' +
|
||||
'#show-prompt-overlay .panel{background:rgba(15,23,42,.96);color:#F3F4F6;border:1px solid rgba(255,255,255,.14);box-shadow:0 20px 60px rgba(0,0,0,.38);border-radius:16px;padding:22px 28px;min-width:min(360px,calc(100vw - 2rem));max-width:460px;}' +
|
||||
'#show-prompt-overlay h3{margin:.1rem 0 .65rem;font-size:1.1rem;}' +
|
||||
'#show-prompt-overlay p{margin:.45rem 0 .9rem;color:#A0A4AB;line-height:1.45;}' +
|
||||
'#show-prompt-overlay .prompt-check{display:flex;align-items:center;gap:.55rem;margin:.8rem 0 1rem;font-weight:600;}' +
|
||||
'#show-prompt-overlay .prompt-check input{display:inline-block;width:auto;margin:0;}' +
|
||||
'#show-prompt-overlay .actions{display:flex;justify-content:flex-end;gap:.55rem;margin-top:.8rem;}';
|
||||
document.head.appendChild(style);
|
||||
}
|
||||
|
||||
function promptSendEmailsImmediately(){
|
||||
ensureShowPromptStyles();
|
||||
return new Promise(function(resolve){
|
||||
const overlay = document.createElement('div');
|
||||
overlay.id = 'show-prompt-overlay';
|
||||
overlay.innerHTML = '<div class="panel" role="dialog" aria-modal="true" aria-labelledby="show-prompt-title">' +
|
||||
'<h3 id="show-prompt-title">Show article</h3>' +
|
||||
'<p>This will announce the article and create the journal campaign.</p>' +
|
||||
'<label class="prompt-check"><input type="checkbox" id="show-send-immediately"> <span>Send emails immediately</span></label>' +
|
||||
'<div class="actions"><button type="button" id="show-prompt-ok">OK</button></div>' +
|
||||
'</div>';
|
||||
document.body.appendChild(overlay);
|
||||
const checkbox = overlay.querySelector('#show-send-immediately');
|
||||
const ok = overlay.querySelector('#show-prompt-ok');
|
||||
ok.addEventListener('click', function(){
|
||||
const value = !!(checkbox && checkbox.checked);
|
||||
overlay.remove();
|
||||
resolve(value);
|
||||
});
|
||||
ok.focus();
|
||||
});
|
||||
}
|
||||
|
||||
async function handleSwitchToggle(form, checkbox){
|
||||
if(checkbox.disabled) return;
|
||||
const previousState = checkbox.dataset.state === '1';
|
||||
const data = new FormData(form);
|
||||
data.set('ajax', '1');
|
||||
const useBusyOverlay = form.dataset.switch === 'show';
|
||||
const isShowingNow = useBusyOverlay && checkbox.checked && !previousState;
|
||||
let sendImmediately = false;
|
||||
if(isShowingNow){
|
||||
sendImmediately = await promptSendEmailsImmediately();
|
||||
}
|
||||
if(checkbox.checked){
|
||||
data.set(checkbox.name, '1');
|
||||
}else{
|
||||
data.delete(checkbox.name);
|
||||
}
|
||||
if(sendImmediately){
|
||||
data.set('send_immediately', '1');
|
||||
}
|
||||
const busyLabel = checkbox.checked ? 'Showing article…' : 'Hiding article…';
|
||||
checkbox.disabled = true;
|
||||
if(useBusyOverlay) showThumbBusy(busyLabel);
|
||||
try{
|
||||
const res = await fetch('admin.php', { method: 'POST', body: data, credentials: 'same-origin', headers: { 'Accept': 'application/json' }});
|
||||
const json = await res.json().catch(() => ({}));
|
||||
|
|
@ -1929,6 +1978,7 @@ async function handleSwitchToggle(form, checkbox){
|
|||
showToast(e.message || 'Switch update failed', false);
|
||||
}finally{
|
||||
checkbox.disabled = false;
|
||||
if(useBusyOverlay) setTimeout(hideThumbBusy, 120);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue