Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/views/pages/admin-media.ejs

    r156baa3 r2ab99c0  
    4141</div>
    4242
    43 <%# Het script staat in assets/js/mod/admin-media.js; de gegevens via partials/page-data.ejs (shaer-bqr). %>
    44 <%- include('../partials/page-data', { pageData: { copy: t('admin.media_copy'), delC: t('admin.media_del_confirm'), cleanC: t('admin.media_cleanup_confirm') } }) %>
     43<script>
     44(function () {
     45  if (window.__mediaWired) return; window.__mediaWired = true;
     46  var T = <%- JSON.stringify({ copy: t('admin.media_copy'), delC: t('admin.media_del_confirm'), cleanC: t('admin.media_cleanup_confirm') }) %>;
     47  document.addEventListener('click', function (e) {
     48    var c = e.target.closest('[data-copy]');
     49    if (c) {
     50      var u = location.origin + c.getAttribute('data-copy');
     51      var done = function () { var o = c.textContent; c.textContent = '✓'; setTimeout(function () { c.textContent = o === '✓' ? T.copy : o; }, 1200); };
     52      if (navigator.clipboard) navigator.clipboard.writeText(u).then(done).catch(function () { window.prompt('URL', u); });
     53      else window.prompt('URL', u);
     54      return;
     55    }
     56    var d = e.target.closest('[data-del]');
     57    if (d) {
     58      if (!window.confirm(T.delC)) return;
     59      fetch('/admin/media/delete', { method: 'POST', credentials: 'same-origin', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ file: d.getAttribute('data-del') }) })
     60        .then(function (r) { return r.json(); })
     61        .then(function (j) { if (j && j.ok) { var card = d.closest('.media-card'); if (card) card.remove(); } else window.alert((j && j.error) || 'Error'); })
     62        .catch(function () { window.alert('Error'); });
     63      return;
     64    }
     65    if (e.target.closest('#media-cleanup')) {
     66      if (!window.confirm(T.cleanC)) return;
     67      fetch('/admin/media/cleanup', { method: 'POST', credentials: 'same-origin' })
     68        .then(function (r) { return r.json(); })
     69        .then(function (j) { location.href = '/admin/media?success=' + encodeURIComponent(((j && j.removed) || 0) + ' file(s) removed'); })
     70        .catch(function () { window.alert('Error'); });
     71    }
     72  });
     73})();
     74</script>
Note: See TracChangeset for help on using the changeset viewer.