/** * javascript/images.js * * Images panel: table + a "Pull Image" action, backed by ajax/images.php. */ (function () { 'use strict'; const P = window.Podman; let images = []; function rowHtml(img) { const created = img.createdAt ? P.formatRelativeTime(img.createdAt) : '—'; return '' + '' + '' + P.escapeHtml(img.repository) + '' + '' + P.escapeHtml(img.tag) + '' + '' + P.escapeHtml(img.shortId) + '' + '' + P.escapeHtml(img.sizeFormatted) + '' + '' + created + '' + '' + img.usedBy + '' + '' + ''; } function render() { const tbody = P.el('images-tbody'); tbody.innerHTML = images.length ? images.map(rowHtml).join('') : 'No images.'; } function load() { const tbody = P.el('images-tbody'); tbody.innerHTML = P.loadingRow(7); return P.get('images', 'list').then(function (data) { images = data; render(); }).catch(function (err) { tbody.innerHTML = P.errorRow(7, err.message); }); } function init() { P.el('images-pull-btn').addEventListener('click', function () { const reference = prompt('Image to pull (e.g. docker.io/library/postgres:16):'); if (!reference) return; P.post('images', 'pull', { reference: reference }).then(load).catch(function (err) { alert('Pull failed: ' + err.message); }); }); P.el('images-tbody').addEventListener('click', function (e) { const btn = e.target.closest('button[data-action="remove"]'); if (!btn || btn.disabled) return; const id = btn.closest('tr').dataset.id; if (!confirm('Remove this image?')) return; btn.disabled = true; P.post('images', 'remove', { id: id }).then(load).catch(function (err) { alert('Remove failed: ' + err.message); btn.disabled = false; }); }); return load(); } P.registerPanel('images', { init: init, refresh: load }); })();