summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base/htdocs/luci-static/resources
diff options
context:
space:
mode:
Diffstat (limited to 'modules/luci-base/htdocs/luci-static/resources')
-rw-r--r--modules/luci-base/htdocs/luci-static/resources/form.js31
-rw-r--r--modules/luci-base/htdocs/luci-static/resources/rpc.js11
-rw-r--r--modules/luci-base/htdocs/luci-static/resources/uci.js22
3 files changed, 45 insertions, 19 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/form.js b/modules/luci-base/htdocs/luci-static/resources/form.js
index 2b02066a40..5c324acc2e 100644
--- a/modules/luci-base/htdocs/luci-static/resources/form.js
+++ b/modules/luci-base/htdocs/luci-static/resources/form.js
@@ -564,11 +564,18 @@ var CBIMap = CBIAbstractElement.extend(/** @lends LuCI.form.Map.prototype */ {
.then(this.data.save.bind(this.data))
.then(this.load.bind(this))
.catch(function(e) {
- if (!silent)
- alert('Cannot save due to invalid values');
+ if (!silent) {
+ ui.showModal(_('Save error'), [
+ E('p', {}, [ _('An error occurred while saving the form:') ]),
+ E('p', {}, [ E('em', { 'style': 'white-space:pre' }, [ e.message ]) ]),
+ E('div', { 'class': 'right' }, [
+ E('button', { 'click': ui.hideModal }, [ _('Dismiss') ])
+ ])
+ ]);
+ }
- return Promise.reject();
- }).finally(this.renderContents.bind(this));
+ return Promise.reject(e);
+ }).then(this.renderContents.bind(this));
},
/**
@@ -1754,8 +1761,10 @@ var CBIAbstractValue = CBIAbstractElement.extend(/** @lends LuCI.form.AbstractVa
cval = this.cfgvalue(section_id),
fval = active ? this.formvalue(section_id) : null;
- if (active && !this.isValid(section_id))
- return Promise.reject();
+ if (active && !this.isValid(section_id)) {
+ var title = this.stripTags(this.title).trim();
+ return Promise.reject(new TypeError(_('Option "%s" contains an invalid input value.').format(title || this.option)));
+ }
if (fval != '' && fval != null) {
if (this.forcewrite || !isEqual(cval, fval))
@@ -1766,8 +1775,8 @@ var CBIAbstractValue = CBIAbstractElement.extend(/** @lends LuCI.form.AbstractVa
return Promise.resolve(this.remove(section_id));
}
else if (!isEqual(cval, fval)) {
- console.log('This should have been catched by isValid()');
- return Promise.reject();
+ var title = this.stripTags(this.title).trim();
+ return Promise.reject(new TypeError(_('Option "%s" must not be empty.').format(title || this.option)));
}
}
@@ -3366,8 +3375,10 @@ var CBIFlagValue = CBIValue.extend(/** @lends LuCI.form.FlagValue.prototype */ {
if (this.isActive(section_id)) {
var fval = this.formvalue(section_id);
- if (!this.isValid(section_id))
- return Promise.reject();
+ if (!this.isValid(section_id)) {
+ var title = this.stripTags(this.title).trim();
+ return Promise.reject(new TypeError(_('Option "%s" contains an invalid input value.').format(title || this.option)));
+ }
if (fval == this.default && (this.optional || this.rmempty))
return Promise.resolve(this.remove(section_id));
diff --git a/modules/luci-base/htdocs/luci-static/resources/rpc.js b/modules/luci-base/htdocs/luci-static/resources/rpc.js
index 20b77c18fc..7bfc913367 100644
--- a/modules/luci-base/htdocs/luci-static/resources/rpc.js
+++ b/modules/luci-base/htdocs/luci-static/resources/rpc.js
@@ -93,6 +93,10 @@ return baseclass.extend(/** @lends LuCI.rpc.prototype */ {
ret = msg.result;
}
else if (Array.isArray(msg.result)) {
+ if (req.raise && msg.result[0] !== 0)
+ L.raise('RPCError', 'RPC call to %s/%s failed with ubus code %d: %s',
+ req.object, req.method, msg.result[0], this.getStatusText(msg.result[0]));
+
ret = (msg.result.length > 1) ? msg.result[1] : msg.result[0];
}
@@ -228,6 +232,10 @@ return baseclass.extend(/** @lends LuCI.rpc.prototype */ {
* Specfies an optional filter function which is invoked to transform the
* received reply data before it is returned to the caller.
*
+ * @property {boolean} [reject=false]
+ * If set to `true`, non-zero ubus call status codes are treated as fatal
+ * error and lead to the rejection of the call promise. The default
+ * behaviour is to resolve with the call return code value instead.
*/
/**
@@ -316,7 +324,8 @@ return baseclass.extend(/** @lends LuCI.rpc.prototype */ {
params: params,
priv: priv,
object: options.object,
- method: options.method
+ method: options.method,
+ raise: options.reject
};
/* build message object */
diff --git a/modules/luci-base/htdocs/luci-static/resources/uci.js b/modules/luci-base/htdocs/luci-static/resources/uci.js
index f381e0b649..adec6fb88d 100644
--- a/modules/luci-base/htdocs/luci-static/resources/uci.js
+++ b/modules/luci-base/htdocs/luci-static/resources/uci.js
@@ -31,44 +31,50 @@ return baseclass.extend(/** @lends LuCI.uci.prototype */ {
object: 'uci',
method: 'get',
params: [ 'config' ],
- expect: { values: { } }
+ expect: { values: { } },
+ reject: true
}),
-
callOrder: rpc.declare({
object: 'uci',
method: 'order',
- params: [ 'config', 'sections' ]
+ params: [ 'config', 'sections' ],
+ reject: true
}),
callAdd: rpc.declare({
object: 'uci',
method: 'add',
params: [ 'config', 'type', 'name', 'values' ],
- expect: { section: '' }
+ expect: { section: '' },
+ reject: true
}),
callSet: rpc.declare({
object: 'uci',
method: 'set',
- params: [ 'config', 'section', 'values' ]
+ params: [ 'config', 'section', 'values' ],
+ reject: true
}),
callDelete: rpc.declare({
object: 'uci',
method: 'delete',
- params: [ 'config', 'section', 'options' ]
+ params: [ 'config', 'section', 'options' ],
+ reject: true
}),
callApply: rpc.declare({
object: 'uci',
method: 'apply',
- params: [ 'timeout', 'rollback' ]
+ params: [ 'timeout', 'rollback' ],
+ reject: true
}),
callConfirm: rpc.declare({
object: 'uci',
- method: 'confirm'
+ method: 'confirm',
+ reject: true
}),