diff mbox series

[OpenWrt-Devel,luci] luci-mod-system: check for sysupgrade with backup possibility

Message ID 20190925155543.9061-1-zajec5@gmail.com
State Accepted
Delegated to: Rafał Miłecki
Headers show
Series [OpenWrt-Devel,luci] luci-mod-system: check for sysupgrade with backup possibility | expand

Commit Message

Rafał Miłecki Sept. 25, 2019, 3:55 p.m. UTC
From: Rafał Miłecki <rafal@milecki.pl>

Some firmware images may not support preserving backup. In such cases
display a warning and disable relevant checkbox.
---
 .../resources/view/system/flash.js            | 23 +++++++++++++------
 1 file changed, 16 insertions(+), 7 deletions(-)

Comments

Rafał Miłecki Oct. 2, 2019, 7:59 a.m. UTC | #1
On Wed, 25 Sep 2019 at 17:55, Rafał Miłecki <zajec5@gmail.com> wrote:
> From: Rafał Miłecki <rafal@milecki.pl>
>
> Some firmware images may not support preserving backup. In such cases
> display a warning and disable relevant checkbox.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
diff mbox series

Patch

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 1349fecd4..544deb279 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
@@ -359,10 +359,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 = [];
 
@@ -370,8 +371,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)
@@ -390,6 +390,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'),
@@ -537,15 +549,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...');