/** * The Property Rent page: each property world's rent from its template, and (with property_rent_manage) a price and * period to charge instead. */ (function () { 'use strict'; var canManage = false; function rate(r) { if (!r) return 'Free'; return esc(r.price) + ' coins / ' + esc(r.periodDays) + ' days'; } function row(w) { var o = w.override; var set = o ? esc(o.price) + ' coins' + (o.periodDays ? ' / ' + esc(o.periodDays) + ' days' : '') + '
' + esc(o.updated_by) + ', ' + esc(fmt.unix(o.updated_at)) + '
' : 'Template'; var edit = canManage ? '
' + '' + '' + '' + (o ? '' : '') + '
' : ''; return '' + esc(w.name) + ' ' + esc(w.mapId) + '' + rate(w.template) + '' + set + '' + rate(w.rent) + '' + edit + ''; } function load() { api.get('/api/property_rent').then(function (d) { if (!d.success) return; canManage = d.canManage; document.getElementById('offNote').classList.toggle('d-none', d.enabled); document.getElementById('rows').innerHTML = d.worlds.map(row).join('') || 'No property worlds found in the CDClient.'; }).catch(function () {}); } function done(d) { if (!d.success) { toast(d.error || 'Failed', 'danger'); return; } toast(d.message, 'success'); load(); } var rows = document.getElementById('rows'); rows.addEventListener('submit', function (e) { e.preventDefault(); var form = e.target; var price = parseInt(form.price.value, 10), days = parseInt(form.days.value || '0', 10); if (!(price >= 0)) { toast('Enter a price in coins (0: free)', 'warning'); return; } api.post('/api/property_rent', { mapId: parseInt(form.dataset.map, 10), price: price, periodDays: days >= 0 ? days : 0 }).then(done); }); rows.addEventListener('click', function (e) { var reset = e.target.closest('[data-reset]'); if (reset) api.post('/api/property_rent/delete', { mapId: parseInt(reset.dataset.reset, 10) }).then(done); }); load(); })();