diff options
Diffstat (limited to 'docs/jsapi/ui.js.html')
-rw-r--r-- | docs/jsapi/ui.js.html | 256 |
1 files changed, 216 insertions, 40 deletions
diff --git a/docs/jsapi/ui.js.html b/docs/jsapi/ui.js.html index 3734562794..d20fe4056b 100644 --- a/docs/jsapi/ui.js.html +++ b/docs/jsapi/ui.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> @@ -3220,6 +3318,7 @@ 'require validation'; 'require baseclass'; 'require request'; +'require session'; 'require poll'; 'require dom'; 'require rpc'; @@ -3277,6 +3376,11 @@ var UIElement = baseclass.extend(/** @lends LuCI.ui.AbstractElement.prototype */ * standard validation constraints are checked. The function should return * `true` to accept the given input value. Any other return value type is * converted to a string and treated as validation error message. + * + * @property {boolean} [disabled=false] + * Specifies whether the widget should be rendered in disabled state + * (`true`) or not (`false`). Disabled widgets cannot be interacted with + * and are displayed in a slightly faded style. */ /** @@ -3540,6 +3644,7 @@ var UITextfield = UIElement.extend(/** @lends LuCI.ui.Textfield.prototype */ { 'type': this.options.password ? 'password' : 'text', 'class': this.options.password ? 'cbi-input-password' : 'cbi-input-text', 'readonly': this.options.readonly ? '' : null, + 'disabled': this.options.disabled ? '' : null, 'maxlength': this.options.maxlength, 'placeholder': this.options.placeholder, 'value': this.value, @@ -3663,6 +3768,7 @@ var UITextarea = UIElement.extend(/** @lends LuCI.ui.Textarea.prototype */ { 'name': this.options.name, 'class': 'cbi-input-textarea', 'readonly': this.options.readonly ? '' : null, + 'disabled': this.options.disabled ? '' : null, 'placeholder': this.options.placeholder, 'style': !this.options.cols ? 'width:100%' : null, 'cols': this.options.cols, @@ -3775,6 +3881,7 @@ var UICheckbox = UIElement.extend(/** @lends LuCI.ui.Checkbox.prototype */ { 'type': 'checkbox', 'value': this.options.value_enabled, 'checked': (this.value == this.options.value_enabled) ? '' : null, + 'disabled': this.options.disabled ? '' : null, 'data-widget-id': this.options.id ? 'widget.' + this.options.id : null })); @@ -3926,7 +4033,8 @@ var UISelect = UIElement.extend(/** @lends LuCI.ui.Select.prototype */ { 'name': this.options.name, 'size': this.options.size, 'class': 'cbi-input-select', - 'multiple': this.options.multiple ? '' : null + 'multiple': this.options.multiple ? '' : null, + 'disabled': this.options.disabled ? '' : null })); if (this.options.optional) @@ -3956,7 +4064,8 @@ var UISelect = UIElement.extend(/** @lends LuCI.ui.Select.prototype */ { 'type': this.options.multiple ? 'checkbox' : 'radio', 'class': this.options.multiple ? 'cbi-input-checkbox' : 'cbi-input-radio', 'value': keys[i], - 'checked': (this.values.indexOf(keys[i]) > -1) ? '' : null + 'checked': (this.values.indexOf(keys[i]) > -1) ? '' : null, + 'disabled': this.options.disabled ? '' : null }), this.choices[keys[i]] || keys[i] ])); @@ -4181,6 +4290,7 @@ var UIDropdown = UIElement.extend(/** @lends LuCI.ui.Dropdown.prototype */ { 'class': 'cbi-dropdown', 'multiple': this.options.multiple ? '' : null, 'optional': this.options.optional ? '' : null, + 'disabled': this.options.disabled ? '' : null }, E('ul')); var keys = Object.keys(this.choices); @@ -5332,7 +5442,8 @@ var UIDynamicList = UIElement.extend(/** @lends LuCI.ui.DynamicList.prototype */ render: function() { var dl = E('div', { 'id': this.options.id, - 'class': 'cbi-dynlist' + 'class': 'cbi-dynlist', + 'disabled': this.options.disabled ? '' : null }, E('div', { 'class': 'add-item' })); if (this.choices) { @@ -5348,7 +5459,8 @@ var UIDynamicList = UIElement.extend(/** @lends LuCI.ui.DynamicList.prototype */ 'id': this.options.id ? 'widget.' + this.options.id : null, 'type': 'text', 'class': 'cbi-input-text', - 'placeholder': this.options.placeholder + 'placeholder': this.options.placeholder, + 'disabled': this.options.disabled ? '' : null }); dl.lastElementChild.appendChild(inputEl); @@ -5458,6 +5570,9 @@ var UIDynamicList = UIElement.extend(/** @lends LuCI.ui.DynamicList.prototype */ var dl = ev.currentTarget, item = findParent(ev.target, '.item'); + if (this.options.disabled) + return; + if (item) { this.removeItem(dl, item); } @@ -5780,7 +5895,8 @@ var UIFileUpload = UIElement.extend(/** @lends LuCI.ui.FileUpload.prototype */ { return this.bind(E('div', { 'id': this.options.id }, [ E('button', { 'class': 'btn', - 'click': UI.prototype.createHandlerFn(this, 'handleFileBrowser') + 'click': UI.prototype.createHandlerFn(this, 'handleFileBrowser'), + 'disabled': this.options.disabled ? '' : null }, label), E('div', { 'class': 'cbi-filebrowser' @@ -6145,6 +6261,84 @@ var UIFileUpload = UIElement.extend(/** @lends LuCI.ui.FileUpload.prototype */ { }); /** + * Handle menu. + * + * @constructor menu + * @memberof LuCI.ui + * + * @classdesc + * + * Handles menus. + */ +var UIMenu = baseclass.singleton(/** @lends LuCI.ui.menu.prototype */ { + /** + * @typedef {Object} MenuNode + * @memberof LuCI.ui.menu + + * @property {string} name - The internal name of the node, as used in the URL + * @property {number} order - The sort index of the menu node + * @property {string} [title] - The title of the menu node, `null` if the node should be hidden + * @property {satisified} boolean - Boolean indicating whether the menu enries dependencies are satisfied + * @property {readonly} [boolean] - Boolean indicating whether the menu entries underlying ACLs are readonly + * @property {LuCI.ui.menu.MenuNode[]} [children] - Array of child menu nodes. + */ + + /** + * Load and cache current menu tree. + * + * @returns {Promise<LuCI.ui.menu.MenuNode>} + * Returns a promise resolving to the root element of the menu tree. + */ + load: function() { + if (this.menu == null) + this.menu = session.getLocalData('menu'); + + if (!L.isObject(this.menu)) { + this.menu = request.get(L.url('admin/menu')).then(L.bind(function(menu) { + this.menu = menu.json(); + session.setLocalData('menu', this.menu); + + return this.menu; + }, this)); + } + + return Promise.resolve(this.menu); + }, + + /** + * @param {LuCI.ui.menu.MenuNode} [node] + * The menu node to retrieve the children for. Defaults to the menu's + * internal root node if omitted. + * + * @returns {LuCI.ui.menu.MenuNode[]} + * Returns an array of child menu nodes. + */ + getChildren: function(node) { + var children = []; + + if (node == null) + node = this.menu; + + for (var k in node.children) { + if (!node.children.hasOwnProperty(k)) + continue; + + if (!node.children[k].satisfied) + continue; + + if (!node.children[k].hasOwnProperty('title')) + continue; + + children.push(Object.assign(node.children[k], { name: k })); + } + + return children.sort(function(a, b) { + return ((a.order || 1000) - (b.order || 1000)); + }); + } +}); + +/** * @class ui * @memberof LuCI * @hideconstructor @@ -6665,16 +6859,14 @@ var UI = baseclass.extend(/** @lends LuCI.ui.prototype */ { /** @private */ getActiveTabState: function() { - var page = document.body.getAttribute('data-page'); + var page = document.body.getAttribute('data-page'), + state = session.getLocalData('tab'); - try { - var val = JSON.parse(window.sessionStorage.getItem('tab')); - if (val.page === page && L.isObject(val.paths)) - return val; - } - catch(e) {} + if (L.isObject(state) && state.page === page && L.isObject(state.paths)) + return state; + + session.setLocalData('tab', null); - window.sessionStorage.removeItem('tab'); return { page: page, paths: {} }; }, @@ -6686,17 +6878,12 @@ var UI = baseclass.extend(/** @lends LuCI.ui.prototype */ { /** @private */ setActiveTabId: function(pane, tabIndex) { - var path = this.getPathForPane(pane); - - try { - var state = this.getActiveTabState(); - state.paths[path] = tabIndex; + var path = this.getPathForPane(pane), + state = this.getActiveTabState(); - window.sessionStorage.setItem('tab', JSON.stringify(state)); - } - catch (e) { return false; } + state.paths[path] = tabIndex; - return true; + return session.setLocalData('tab', state); }, /** @private */ @@ -7002,26 +7189,13 @@ var UI = baseclass.extend(/** @lends LuCI.ui.prototype */ { * The number of changes to indicate. */ setIndicator: function(n) { - var i = document.querySelector('.uci_change_indicator'); - if (i == null) { - var poll = document.getElementById('xhr_poll_status'); - i = poll.parentNode.insertBefore(E('a', { - 'href': '#', - 'class': 'uci_change_indicator label notice', - 'click': L.bind(this.displayChanges, this) - }), poll); - } - if (n > 0) { - dom.content(i, [ _('Unsaved Changes'), ': ', n ]); - i.classList.add('flash'); - i.style.display = ''; - document.dispatchEvent(new CustomEvent('uci-new-changes')); + UI.prototype.showIndicator('uci-changes', + '%s: %d'.format(_('Unsaved Changes'), n), + L.bind(this.displayChanges, this)); } else { - i.classList.remove('flash'); - i.style.display = 'none'; - document.dispatchEvent(new CustomEvent('uci-clear-changes')); + UI.prototype.hideIndicator('uci-changes'); } }, @@ -7518,6 +7692,8 @@ var UI = baseclass.extend(/** @lends LuCI.ui.prototype */ { }); }, + menu: UIMenu, + AbstractElement: UIElement, /* Widgets */ @@ -7546,7 +7722,7 @@ return UI; <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> |