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

Rafał Miłecki zajec5 at gmail.com
Wed Sep 25 11:55:43 EDT 2019


From: Rafał Miłecki <rafal at 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(-)

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...');
-- 
2.21.0


_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list