/** * javascript/volumes.js * * Volumes panel: named-volume table + create/remove, backed by * ajax/volumes.php. Bind mounts are deliberately not shown here — see * that file's header comment. */ (function () { 'use strict'; const P = window.Podman; let volumes = []; function rowHtml(v) { return '' + '' + '' + P.escapeHtml(v.name) + '' + '' + P.escapeHtml(v.driver) + '' + '' + P.escapeHtml(v.mountpoint) + '' + '' + v.usedBy + '' + '' + ''; } function render() { const tbody = P.el('volumes-tbody'); tbody.innerHTML = volumes.length ? volumes.map(rowHtml).join('') : 'No named volumes.'; } function load() { const tbody = P.el('volumes-tbody'); tbody.innerHTML = P.loadingRow(5); return P.get('volumes', 'list').then(function (data) { volumes = data; render(); }).catch(function (err) { tbody.innerHTML = P.errorRow(5, err.message); }); } function init() { P.el('volumes-create-btn').addEventListener('click', function () { const name = prompt('New volume name:'); if (!name) return; P.post('volumes', 'create', { name: name }).then(load).catch(function (err) { alert('Create failed: ' + err.message); }); }); P.el('volumes-tbody').addEventListener('click', function (e) { const btn = e.target.closest('button[data-action="remove"]'); if (!btn || btn.disabled) return; const name = btn.closest('tr').dataset.name; if (!confirm('Remove volume "' + name + '"? This deletes its data.')) return; btn.disabled = true; P.post('volumes', 'remove', { name: name }).then(load).catch(function (err) { alert('Remove failed: ' + err.message); btn.disabled = false; }); }); return load(); } P.registerPanel('volumes', { init: init, refresh: load }); })();