diff options
Diffstat (limited to 'docs/jsapi/form.js.html')
-rw-r--r-- | docs/jsapi/form.js.html | 236 |
1 files changed, 204 insertions, 32 deletions
diff --git a/docs/jsapi/form.js.html b/docs/jsapi/form.js.html index 258b4897c..4b90165db 100644 --- a/docs/jsapi/form.js.html +++ b/docs/jsapi/form.js.html @@ -74,12 +74,16 @@ <li data-name="LuCI#error"><a href="LuCI.html#error">error</a></li> + <li data-name="LuCI#fspath"><a href="LuCI.html#fspath">fspath</a></li> + <li data-name="LuCI#get"><a href="LuCI.html#get">get</a></li> <li data-name="LuCI#halt"><a href="LuCI.html#halt">halt</a></li> <li data-name="LuCI#hasSystemFeature"><a href="LuCI.html#hasSystemFeature">hasSystemFeature</a></li> + <li data-name="LuCI#hasViewPermission"><a href="LuCI.html#hasViewPermission">hasViewPermission</a></li> + <li data-name="LuCI#isObject"><a href="LuCI.html#isObject">isObject</a></li> <li data-name="LuCI#location"><a href="LuCI.html#location">location</a></li> @@ -331,6 +335,8 @@ <li data-name="LuCI.form.AbstractValue##optional"><a href="LuCI.form.AbstractValue.html#optional">optional</a></li> + <li data-name="LuCI.form.AbstractValue##readonly"><a href="LuCI.form.AbstractValue.html#readonly">readonly</a></li> + <li data-name="LuCI.form.AbstractValue##rmempty"><a href="LuCI.form.AbstractValue.html#rmempty">rmempty</a></li> <li data-name="LuCI.form.AbstractValue##uciconfig"><a href="LuCI.form.AbstractValue.html#uciconfig">uciconfig</a></li> @@ -423,6 +429,8 @@ <li data-name="LuCI.form.ButtonValue#placeholder"><a href="LuCI.form.ButtonValue.html#placeholder">placeholder</a></li> + <li data-name="LuCI.form.ButtonValue#readonly"><a href="LuCI.form.ButtonValue.html#readonly">readonly</a></li> + <li data-name="LuCI.form.ButtonValue#rmempty"><a href="LuCI.form.ButtonValue.html#rmempty">rmempty</a></li> <li data-name="LuCI.form.ButtonValue#uciconfig"><a href="LuCI.form.ButtonValue.html#uciconfig">uciconfig</a></li> @@ -511,6 +519,8 @@ <li data-name="LuCI.form.DummyValue#placeholder"><a href="LuCI.form.DummyValue.html#placeholder">placeholder</a></li> + <li data-name="LuCI.form.DummyValue#readonly"><a href="LuCI.form.DummyValue.html#readonly">readonly</a></li> + <li data-name="LuCI.form.DummyValue#rmempty"><a href="LuCI.form.DummyValue.html#rmempty">rmempty</a></li> <li data-name="LuCI.form.DummyValue#uciconfig"><a href="LuCI.form.DummyValue.html#uciconfig">uciconfig</a></li> @@ -595,6 +605,8 @@ <li data-name="LuCI.form.DynamicList#placeholder"><a href="LuCI.form.DynamicList.html#placeholder">placeholder</a></li> + <li data-name="LuCI.form.DynamicList#readonly"><a href="LuCI.form.DynamicList.html#readonly">readonly</a></li> + <li data-name="LuCI.form.DynamicList#rmempty"><a href="LuCI.form.DynamicList.html#rmempty">rmempty</a></li> <li data-name="LuCI.form.DynamicList#uciconfig"><a href="LuCI.form.DynamicList.html#uciconfig">uciconfig</a></li> @@ -687,6 +699,8 @@ <li data-name="LuCI.form.FileUpload#placeholder"><a href="LuCI.form.FileUpload.html#placeholder">placeholder</a></li> + <li data-name="LuCI.form.FileUpload#readonly"><a href="LuCI.form.FileUpload.html#readonly">readonly</a></li> + <li data-name="LuCI.form.FileUpload#rmempty"><a href="LuCI.form.FileUpload.html#rmempty">rmempty</a></li> <li data-name="LuCI.form.FileUpload#uciconfig"><a href="LuCI.form.FileUpload.html#uciconfig">uciconfig</a></li> @@ -775,6 +789,8 @@ <li data-name="LuCI.form.FlagValue#placeholder"><a href="LuCI.form.FlagValue.html#placeholder">placeholder</a></li> + <li data-name="LuCI.form.FlagValue#readonly"><a href="LuCI.form.FlagValue.html#readonly">readonly</a></li> + <li data-name="LuCI.form.FlagValue#rmempty"><a href="LuCI.form.FlagValue.html#rmempty">rmempty</a></li> <li data-name="LuCI.form.FlagValue#uciconfig"><a href="LuCI.form.FlagValue.html#uciconfig">uciconfig</a></li> @@ -929,6 +945,8 @@ <li data-name="LuCI.form.HiddenValue#placeholder"><a href="LuCI.form.HiddenValue.html#placeholder">placeholder</a></li> + <li data-name="LuCI.form.HiddenValue#readonly"><a href="LuCI.form.HiddenValue.html#readonly">readonly</a></li> + <li data-name="LuCI.form.HiddenValue#rmempty"><a href="LuCI.form.HiddenValue.html#rmempty">rmempty</a></li> <li data-name="LuCI.form.HiddenValue#uciconfig"><a href="LuCI.form.HiddenValue.html#uciconfig">uciconfig</a></li> @@ -997,6 +1015,10 @@ </span> <ul class="members itemMembers"> + <span class="subtitle">Members</span> + + <li data-name="LuCI.form.JSONMap#readonly"><a href="LuCI.form.JSONMap.html#readonly">readonly</a></li> + </ul> <ul class="typedefs itemMembers"> @@ -1065,6 +1087,8 @@ <li data-name="LuCI.form.ListValue#placeholder"><a href="LuCI.form.ListValue.html#placeholder">placeholder</a></li> + <li data-name="LuCI.form.ListValue#readonly"><a href="LuCI.form.ListValue.html#readonly">readonly</a></li> + <li data-name="LuCI.form.ListValue#rmempty"><a href="LuCI.form.ListValue.html#rmempty">rmempty</a></li> <li data-name="LuCI.form.ListValue#uciconfig"><a href="LuCI.form.ListValue.html#uciconfig">uciconfig</a></li> @@ -1133,6 +1157,10 @@ </span> <ul class="members itemMembers"> + <span class="subtitle">Members</span> + + <li data-name="LuCI.form.Map##readonly"><a href="LuCI.form.Map.html#readonly">readonly</a></li> + </ul> <ul class="typedefs itemMembers"> @@ -1203,6 +1231,8 @@ <li data-name="LuCI.form.MultiValue#placeholder"><a href="LuCI.form.MultiValue.html#placeholder">placeholder</a></li> + <li data-name="LuCI.form.MultiValue#readonly"><a href="LuCI.form.MultiValue.html#readonly">readonly</a></li> + <li data-name="LuCI.form.MultiValue#rmempty"><a href="LuCI.form.MultiValue.html#rmempty">rmempty</a></li> <li data-name="LuCI.form.MultiValue#uciconfig"><a href="LuCI.form.MultiValue.html#uciconfig">uciconfig</a></li> @@ -1343,6 +1373,8 @@ <li data-name="LuCI.form.SectionValue#placeholder"><a href="LuCI.form.SectionValue.html#placeholder">placeholder</a></li> + <li data-name="LuCI.form.SectionValue#readonly"><a href="LuCI.form.SectionValue.html#readonly">readonly</a></li> + <li data-name="LuCI.form.SectionValue#rmempty"><a href="LuCI.form.SectionValue.html#rmempty">rmempty</a></li> <li data-name="LuCI.form.SectionValue#uciconfig"><a href="LuCI.form.SectionValue.html#uciconfig">uciconfig</a></li> @@ -1513,6 +1545,8 @@ <li data-name="LuCI.form.TextValue#placeholder"><a href="LuCI.form.TextValue.html#placeholder">placeholder</a></li> + <li data-name="LuCI.form.TextValue#readonly"><a href="LuCI.form.TextValue.html#readonly">readonly</a></li> + <li data-name="LuCI.form.TextValue#rmempty"><a href="LuCI.form.TextValue.html#rmempty">rmempty</a></li> <li data-name="LuCI.form.TextValue#uciconfig"><a href="LuCI.form.TextValue.html#uciconfig">uciconfig</a></li> @@ -1655,6 +1689,8 @@ <li data-name="LuCI.form.Value#optional"><a href="LuCI.form.Value.html#optional">optional</a></li> + <li data-name="LuCI.form.Value#readonly"><a href="LuCI.form.Value.html#readonly">readonly</a></li> + <li data-name="LuCI.form.Value#rmempty"><a href="LuCI.form.Value.html#rmempty">rmempty</a></li> <li data-name="LuCI.form.Value#uciconfig"><a href="LuCI.form.Value.html#uciconfig">uciconfig</a></li> @@ -2462,6 +2498,36 @@ </ul> </li> + <li class="item" data-name="LuCI.session"> + <span class="title"> + <a href="LuCI.session.html">LuCI.session</a> + + </span> + <ul class="members itemMembers"> + + </ul> + <ul class="typedefs itemMembers"> + + </ul> + <ul class="typedefs itemMembers"> + + </ul> + <ul class="methods itemMembers"> + + <span class="subtitle">Methods</span> + + <li data-name="LuCI.session#getID"><a href="LuCI.session.html#getID">getID</a></li> + + <li data-name="LuCI.session#getLocalData"><a href="LuCI.session.html#getLocalData">getLocalData</a></li> + + <li data-name="LuCI.session#setLocalData"><a href="LuCI.session.html#setLocalData">setLocalData</a></li> + + </ul> + <ul class="events itemMembers"> + + </ul> + </li> + <li class="item" data-name="LuCI.uci"> <span class="title"> <a href="LuCI.uci.html">LuCI.uci</a> @@ -2974,6 +3040,38 @@ </ul> </li> + <li class="item" data-name="LuCI.ui.menu"> + <span class="title"> + <a href="LuCI.ui.menu.html">LuCI.ui.menu</a> + + </span> + <ul class="members itemMembers"> + + </ul> + <ul class="typedefs itemMembers"> + + <span class="subtitle">Typedefs</span> + + <li data-name="LuCI.ui.menu.MenuNode"><a href="LuCI.ui.menu.html#.MenuNode">MenuNode</a></li> + + </ul> + <ul class="typedefs itemMembers"> + + </ul> + <ul class="methods itemMembers"> + + <span class="subtitle">Methods</span> + + <li data-name="LuCI.ui.menu#getChildren"><a href="LuCI.ui.menu.html#getChildren">getChildren</a></li> + + <li data-name="LuCI.ui.menu#load"><a href="LuCI.ui.menu.html#load">load</a></li> + + </ul> + <ul class="events itemMembers"> + + </ul> + </li> + <li class="item" data-name="LuCI.ui.Select"> <span class="title"> <a href="LuCI.ui.Select.html">LuCI.ui.Select</a> @@ -3219,11 +3317,19 @@ <pre id="source-code" class="prettyprint source "><code>'use strict'; 'require ui'; 'require uci'; +'require rpc'; 'require dom'; 'require baseclass'; var scope = this; +var callSessionAccess = rpc.declare({ + object: 'session', + method: 'access', + params: [ 'scope', 'object', 'function' ], + expect: { 'access': false } +}); + var CBIJSONConfig = baseclass.extend({ __init__: function(data) { data = Object.assign({}, data); @@ -3582,6 +3688,20 @@ var CBIMap = CBIAbstractElement.extend(/** @lends LuCI.form.Map.prototype */ { }, /** + * Toggle readonly state of the form. + * + * If set to `true`, the Map instance is marked readonly and any form + * option elements added to it will inherit the readonly state. + * + * If left unset, the Map will test the access permission of the primary + * uci configuration upon loading and mark the form readonly if no write + * permissions are granted. + * + * @name LuCI.form.Map.prototype#readonly + * @type boolean + */ + + /** * Find all DOM nodes within this Map which match the given search * parameters. This function is essentially a convenience wrapper around * `querySelectorAll()`. @@ -3727,8 +3847,17 @@ var CBIMap = CBIAbstractElement.extend(/** @lends LuCI.form.Map.prototype */ { * an error. */ load: function() { - return this.data.load(this.parsechain || [ this.config ]) - .then(this.loadChildren.bind(this)); + var doCheckACL = (!(this instanceof CBIJSONMap) && this.readonly == null); + + return Promise.all([ + doCheckACL ? callSessionAccess('uci', this.config, 'write') : true, + this.data.load(this.parsechain || [ this.config ]) + ]).then(L.bind(function(res) { + if (res[0] === false) + this.readonly = true; + + return this.loadChildren(); + }, this)); }, /** @@ -3782,11 +3911,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)); }, /** @@ -4520,6 +4656,19 @@ var CBIAbstractValue = CBIAbstractElement.extend(/** @lends LuCI.form.AbstractVa */ /** + * Make option element readonly. + * + * This property defaults to the readonly state of the parent form element. + * When set to `true`, the underlying widget is rendered in disabled state, + * means its contents cannot be changed and the widget cannot be interacted + * with. + * + * @name LuCI.form.AbstractValue.prototype#readonly + * @type boolean + * @default false + */ + + /** * Override the cell width of a table or grid section child option. * * If the property is set to a numeric value, it is treated as pixel width @@ -4972,8 +5121,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)) @@ -4984,8 +5135,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))); } } @@ -5169,13 +5320,15 @@ var CBITypedSection = CBIAbstractSection.extend(/** @lends LuCI.form.TypedSectio createEl.appendChild(E('button', { 'class': 'cbi-button cbi-button-add', 'title': btn_title || _('Add'), - 'click': ui.createHandlerFn(this, 'handleAdd') + 'click': ui.createHandlerFn(this, 'handleAdd'), + 'disabled': this.map.readonly || null }, [ btn_title || _('Add') ])); } else { var nameEl = E('input', { 'type': 'text', - 'class': 'cbi-section-create-name' + 'class': 'cbi-section-create-name', + 'disabled': this.map.readonly || null }); dom.append(createEl, [ @@ -5190,7 +5343,8 @@ var CBITypedSection = CBIAbstractSection.extend(/** @lends LuCI.form.TypedSectio return; return this.handleAdd(ev, nameEl.value); - }) + }), + 'disabled': this.map.readonly || null }) ]); @@ -5233,7 +5387,8 @@ var CBITypedSection = CBIAbstractSection.extend(/** @lends LuCI.form.TypedSectio 'class': 'cbi-button', 'name': 'cbi.rts.%s.%s'.format(config_name, cfgsections[i]), 'data-section-id': cfgsections[i], - 'click': ui.createHandlerFn(this, 'handleRemove', cfgsections[i]) + 'click': ui.createHandlerFn(this, 'handleRemove', cfgsections[i]), + 'disabled': this.map.readonly || null }, [ _('Delete') ]))); } @@ -5609,7 +5764,8 @@ var CBITableSection = CBITypedSection.extend(/** @lends LuCI.form.TableSection.p E('div', { 'title': _('Drag to reorder'), 'class': 'btn cbi-button drag-handle center', - 'style': 'cursor:move' + 'style': 'cursor:move', + 'disabled': this.map.readonly || null }, '☰') ]); } @@ -5650,7 +5806,8 @@ var CBITableSection = CBITypedSection.extend(/** @lends LuCI.form.TableSection.p E('button', { 'title': btn_title || _('Delete'), 'class': 'cbi-button cbi-button-remove', - 'click': ui.createHandlerFn(this, 'handleRemove', section_id) + 'click': ui.createHandlerFn(this, 'handleRemove', section_id), + 'disabled': this.map.readonly || null }, [ btn_title || _('Delete') ]) ); } @@ -5801,6 +5958,7 @@ var CBITableSection = CBITypedSection.extend(/** @lends LuCI.form.TableSection.p s = m.section(CBINamedSection, section_id, this.sectiontype); m.parent = parent; + m.readonly = parent.readonly; s.tabs = this.tabs; s.tab_names = this.tab_names; @@ -5848,7 +6006,8 @@ var CBITableSection = CBITypedSection.extend(/** @lends LuCI.form.TableSection.p }, [ _('Dismiss') ]), ' ', E('button', { 'class': 'cbi-button cbi-button-positive important', - 'click': ui.createHandlerFn(this, 'handleModalSave', m) + 'click': ui.createHandlerFn(this, 'handleModalSave', m), + 'disabled': m.readonly || null }, [ _('Save') ]) ]) ], 'cbi-modal'); @@ -6135,7 +6294,8 @@ var CBINamedSection = CBIAbstractSection.extend(/** @lends LuCI.form.NamedSectio E('div', { 'class': 'cbi-section-remove right' }, E('button', { 'class': 'cbi-button', - 'click': ui.createHandlerFn(this, 'handleRemove') + 'click': ui.createHandlerFn(this, 'handleRemove'), + 'disabled': this.map.readonly || null }, [ _('Delete') ]))); } @@ -6150,7 +6310,8 @@ var CBINamedSection = CBIAbstractSection.extend(/** @lends LuCI.form.NamedSectio sectionEl.appendChild( E('button', { 'class': 'cbi-button cbi-button-add', - 'click': ui.createHandlerFn(this, 'handleAdd') + 'click': ui.createHandlerFn(this, 'handleAdd'), + 'disabled': this.map.readonly || null }, [ _('Add') ])); } @@ -6344,7 +6505,8 @@ var CBIValue = CBIAbstractValue.extend(/** @lends LuCI.form.Value.prototype */ { optional: this.optional || this.rmempty, datatype: this.datatype, select_placeholder: this.placeholder || placeholder, - validate: L.bind(this.validate, this, section_id) + validate: L.bind(this.validate, this, section_id), + disabled: (this.readonly != null) ? this.readonly : this.map.readonly }); } else { @@ -6354,7 +6516,8 @@ var CBIValue = CBIAbstractValue.extend(/** @lends LuCI.form.Value.prototype */ { optional: this.optional || this.rmempty, datatype: this.datatype, placeholder: this.placeholder, - validate: L.bind(this.validate, this, section_id) + validate: L.bind(this.validate, this, section_id), + disabled: (this.readonly != null) ? this.readonly : this.map.readonly }); } @@ -6409,7 +6572,8 @@ var CBIDynamicList = CBIValue.extend(/** @lends LuCI.form.DynamicList.prototype optional: this.optional || this.rmempty, datatype: this.datatype, placeholder: this.placeholder, - validate: L.bind(this.validate, this, section_id) + validate: L.bind(this.validate, this, section_id), + disabled: (this.readonly != null) ? this.readonly : this.map.readonly }); return widget.render(); @@ -6474,7 +6638,8 @@ var CBIListValue = CBIValue.extend(/** @lends LuCI.form.ListValue.prototype */ { sort: this.keylist, optional: this.optional, placeholder: this.placeholder, - validate: L.bind(this.validate, this, section_id) + validate: L.bind(this.validate, this, section_id), + disabled: (this.readonly != null) ? this.readonly : this.map.readonly }); return widget.render(); @@ -6545,7 +6710,8 @@ var CBIFlagValue = CBIValue.extend(/** @lends LuCI.form.FlagValue.prototype */ { id: this.cbid(section_id), value_enabled: this.enabled, value_disabled: this.disabled, - validate: L.bind(this.validate, this, section_id) + validate: L.bind(this.validate, this, section_id), + disabled: (this.readonly != null) ? this.readonly : this.map.readonly }); return widget.render(); @@ -6584,8 +6750,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)); @@ -6671,7 +6839,8 @@ var CBIMultiValue = CBIDynamicList.extend(/** @lends LuCI.form.MultiValue.protot select_placeholder: this.placeholder, display_items: this.display_size || this.size || 3, dropdown_items: this.dropdown_size || this.size || -1, - validate: L.bind(this.validate, this, section_id) + validate: L.bind(this.validate, this, section_id), + disabled: (this.readonly != null) ? this.readonly : this.map.readonly }); return widget.render(); @@ -6763,7 +6932,8 @@ var CBITextValue = CBIValue.extend(/** @lends LuCI.form.TextValue.prototype */ { cols: this.cols, rows: this.rows, wrap: this.wrap, - validate: L.bind(this.validate, this, section_id) + validate: L.bind(this.validate, this, section_id), + disabled: (this.readonly != null) ? this.readonly : this.map.readonly }); return widget.render(); @@ -6833,7 +7003,7 @@ var CBIDummyValue = CBIValue.extend(/** @lends LuCI.form.DummyValue.prototype */ hiddenEl = new ui.Hiddenfield(value, { id: this.cbid(section_id) }), outputEl = E('div'); - if (this.href) + if (this.href && !((this.readonly != null) ? this.readonly : this.map.readonly)) outputEl.appendChild(E('a', { 'href': this.href })); dom.append(outputEl.lastChild || outputEl, @@ -6954,7 +7124,8 @@ var CBIButtonValue = CBIValue.extend(/** @lends LuCI.form.ButtonValue.prototype ev.currentTarget.parentNode.nextElementSibling.value = value; return this.map.save(); - }, section_id) + }, section_id), + 'disabled': ((this.readonly != null) ? this.readonly : this.map.readonly) || null }, [ btn_title ]) ]); else @@ -7129,7 +7300,8 @@ var CBIFileUpload = CBIValue.extend(/** @lends LuCI.form.FileUpload.prototype */ show_hidden: this.show_hidden, enable_upload: this.enable_upload, enable_remove: this.enable_remove, - root_directory: this.root_directory + root_directory: this.root_directory, + disabled: (this.readonly != null) ? this.readonly : this.map.readonly }); return browserEl.render(); @@ -7338,7 +7510,7 @@ return baseclass.extend(/** @lends LuCI.form.prototype */ { <footer> - Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Tue Apr 07 2020 16:33:40 GMT+0200 (Central European Summer Time) + Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Thu Apr 16 2020 13:30:42 GMT+0200 (Central European Summer Time) </footer> </div> </div> |