From fb740f2c792696c64b3bd7115b25cdba32687003 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Wed, 25 Sep 2019 17:55:43 +0200 Subject: [PATCH] luci-mod-system: check for sysupgrade with backup possibility MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Some firmware images may not support preserving backup. In such cases display a warning and disable relevant checkbox. Signed-off-by: Rafał Miłecki --- .../resources/view/system/flash.js | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/modules/luci-mod-system/htdocs/luci-static/resources/view/system/flash.js b/modules/luci-mod-system/htdocs/luci-static/resources/view/system/flash.js index a1fcf7cbe..6f245533d 100644 --- a/modules/luci-mod-system/htdocs/luci-static/resources/view/system/flash.js +++ b/modules/luci-mod-system/htdocs/luci-static/resources/view/system/flash.js @@ -360,10 +360,11 @@ return L.view.extend({ .then(function(res) { reply.push(res); return reply; }); }, this, ev.target)) .then(L.bind(function(btn, res) { - var keep = document.querySelector('[data-name="keep"] input[type="checkbox"]'), + var keep = E('input', { type: 'checkbox' }), force = E('input', { type: 'checkbox' }), is_valid = res[1].valid, is_forceable = res[1].forceable, + allow_backup = res[1].allow_backup, is_too_big = (storage_size > 0 && res[0].size > storage_size), body = []; @@ -371,8 +372,7 @@ return L.view.extend({ body.push(E('ul', {}, [ res[0].size ? E('li', {}, '%s: %1024.2mB'.format(_('Size'), res[0].size)) : '', res[0].checksum ? E('li', {}, '%s: %s'.format(_('MD5'), res[0].checksum)) : '', - res[0].sha256sum ? E('li', {}, '%s: %s'.format(_('SHA256'), res[0].sha256sum)) : '', - E('li', {}, keep.checked ? _('Configuration files will be kept') : _('Caution: Configuration files will be erased')) + res[0].sha256sum ? E('li', {}, '%s: %s'.format(_('SHA256'), res[0].sha256sum)) : '' ])); if (!is_valid || is_too_big) @@ -391,6 +391,18 @@ return L.view.extend({ _('The uploaded image file does not contain a supported format. Make sure that you choose the generic image format for your platform.') ])); + if (!allow_backup) + body.push(E('p', { 'class': 'alert-message' }, [ + _('The uploaded firmware does not allow keeping current configuration.') + ])); + if (allow_backup) + keep.checked = true; + else + keep.disabled = true; + body.push(E('p', {}, E('label', { 'class': 'btn' }, [ + keep, ' ', _('Keep settings and retain the current configuration') + ]))); + if ((!is_valid || is_too_big) && is_forceable) body.push(E('p', {}, E('label', { 'class': 'btn alert-message danger' }, [ force, ' ', _('Force upgrade'), @@ -540,15 +552,12 @@ return L.view.extend({ o = s.option(form.SectionValue, 'actions', form.NamedSection, 'actions', 'actions', _('Flash new firmware image'), has_sysupgrade - ? _('Upload a sysupgrade-compatible image here to replace the running firmware. Check "Keep settings" to retain the current configuration (requires a compatible firmware image).') + ? _('Upload a sysupgrade-compatible image here to replace the running firmware.') : _('Sorry, there is no sysupgrade support present; a new firmware image must be flashed manually. Please refer to the wiki for device specific install instructions.')); ss = o.subsection; if (has_sysupgrade) { - o = ss.option(form.Flag, 'keep', _('Keep settings')); - o.default = o.enabled; - o = ss.option(form.Button, 'sysupgrade', _('Image')); o.inputstyle = 'action important'; o.inputtitle = _('Flash image...'); -- 2.25.1