Commit graph

92 commits

Author SHA1 Message Date
Jo-Philipp Wich
d8ed1e7b7d luci-base: form.js: add column sorting to TableSections and GridSections
Add ability to reorder TableSection and GridSection rows by clicking on
column headers.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2022-02-24 23:45:18 +01:00
Jo-Philipp Wich
993151504e luci-base: form.js: do not execute embedded script code in stripTags()
Instead of relying on .innerHTML which executes embedded script code to
parse a given HTML fragment, use dom.parse() which utilizies DOMParser()
internally in order to extract textContent in a safe manner.

Fixes: FS#4199
Ref: https://bugs.openwrt.org/index.php?do=details&task_id=4199
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-12-23 17:08:21 +01:00
Jo-Philipp Wich
f5fbecf132 luci-base: form.js: implement AbstractValue.retain property
The new `retain` boolean property controls whether the related option value
is purged from the configuration when the dependencies of the option are
not satisifed.

Ref: #5579
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-12-09 15:11:07 +01:00
Jo-Philipp Wich
1c798d1a08 luci-base: form.js: allow nesting Grid and Table sections
Implement a simple view stack within the modal overlay to allow the modal
edit dialog of a table or grid section to render another table or grid
section which recursively opens another modal edit dialog.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-11-22 09:43:29 +01:00
Lukas Voegl
735d949bfc luci-base: show validation message in error
Signed-off-by: Lukas Voegl <lvoegl@tdt.de>
2021-10-26 12:31:05 +02:00
Jo-Philipp Wich
df75163e68 luci-base: form.js: add drag-drop sorting support for mobile
Fixes: #5416
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-10-08 16:54:38 +02:00
Florian Eckert
1a2b7fef6c luci-base: do not add validation for named section if readonly is set
Signed-off-by: Florian Eckert <fe@dev.tdt.de>
2021-07-01 15:54:51 +02:00
Helge Mader
87215e3d1b luci-base: prevent empty field for adding new named section in JavaScript
Suggested-by: Helge Mader <ma@dev.tdt.de>
Signed-off-by: Florian Eckert <fe@dev.tdt.de>
2021-07-01 13:10:15 +02:00
Florian Eckert
80262bb9a7 luci-base: change css class btn to cbi-button
The css class btn is only a valid input element on lua rendered pages.
Use instead cbi-button for javascript rendered pages.

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
2021-07-01 13:10:15 +02:00
Florian Eckert
97e673b72c luci-base: use button tag instead of input tag on named section add
Signed-off-by: Florian Eckert <fe@dev.tdt.de>
2021-07-01 13:09:37 +02:00
Jo-Philipp Wich
1255c4832e
Merge pull request #4770 from nickberry17/update_DummyValue
luci-base: add new member 'hidden' to DummyValue
2021-06-02 08:23:45 +02:00
Jo-Philipp Wich
f3f74bd0fe luci-base: form.js: consider aliased options in AbstractValue.remove()
If different options point to the same underlying uci option, we must only
remove the uci value if none of the other alias options is active in order
to prevent inactive options (due to unsatisfied depends) removing the uci
value of active once on save.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-06-01 15:34:11 +02:00
Jo-Philipp Wich
5c792aefc7 luci-base: form.js: fix AbstractValue.textvalue() for uci list options
Serialize the uci list value into a space separated string before passing
it to String.format() for HTML escaping. Without that change, empty strings
were returned whenever the underlying uci get operation yieled an array.

Fixes: #4993
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2021-04-16 17:32:22 +02:00
Nicholas Smith
936dde7422 luci-base: add new member 'hidden' to DummyValue
Signed-off-by: Nicholas Smith <nicholas@nbembedded.com>
2021-02-10 06:33:14 +10:00
Florian Eckert
df2a135a08 luci-base: make tooltip icon string configurable
Signed-off-by: Florian Eckert <fe@dev.tdt.de>
2021-01-13 12:29:02 +01:00
Florian Eckert
e951236e36 luci-base: add tooltip handling
Signed-off-by: Florian Eckert <fe@dev.tdt.de>
2021-01-13 11:59:02 +01:00
Jo-Philipp Wich
03c77dafe3 treewide: transition div tables to actual table markup
Modern browsers allow decomposing table markup equally well as nested div
constructs, therefor migrate our <div> table markup to actual <table> tags
but keep the old table/tr/th/td CSS classes for now to allow for a smooth
theme transition.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-11-27 21:36:40 +01:00
Jo-Philipp Wich
5a485f8c68
Merge pull request #4531 from oldium/add-widget-changed
luci-base: Fix using isActive in widget-change notification.
2020-10-30 21:29:38 +01:00
Oldřich Jedlička
ee9b3a4e94 luci-base: Fix using isActive in widget-change notification.
The `onchange` notification handler is called too early to be able to
evaluate other widget's `isActive()` status. Solve this by changing order
of event handling - first register/execute `map.checkDepends` and then
`onchange`.

Fixes: openwrt/luci#4516.

Signed-off-by: Oldřich Jedlička <oldium.pro@gmail.com>
2020-10-30 21:18:45 +01:00
Oldřich Jedlička
ebaa50ecd8 luci-base: Replace legend element with h3.
The legend HTML element is allowed only as first element in fieldset, so
use h3 instead, which is rendered the same within themes.

Fixes #3149.

Signed-off-by: Oldřich Jedlička <oldium.pro@gmail.com>
2020-10-24 19:18:50 +02:00
Jo-Philipp Wich
35e2735e2e luci-base: form.js: implement AbstractSection.getOption() helper
The `getOption()` function allows to easily obtain a reference to another
option object instance within the same section.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-08-06 17:56:34 +02:00
Jo-Philipp Wich
b8d381b677 luci-base: form.js: add cfgvalue(), formvalue() and getUIElement() helpers
This commit introduces new per-section cfgvalue(), formvalue() and
getUIElement() helper functions which complement the respective per-option
functions.

Their intent is to simplify querying input data or obtaining UI widget
instances from other options within the same section.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-08-05 13:51:16 +02:00
Jo-Philipp Wich
2d774c4973 luci-base: form.js: add AbstractValue.onchange property
Introduce a new, widget agnostic onchange property which allows setting
custom handler functions to react on element value changes.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-08-05 13:51:16 +02:00
Jo-Philipp Wich
572090101d luci-base: form.js: add ability to specify regular expression dependencies
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-08-05 13:51:16 +02:00
Jo-Philipp Wich
1c92d9f706 luci-base: form.js: add CSS class to invalid option dismiss button
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-07-28 20:57:04 +02:00
Jo-Philipp Wich
b0cd7ff705 luci-base: form.js: don't destroy modal form on invalid values when saving
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-07-28 20:57:04 +02:00
Jo-Philipp Wich
682f628ea6 luci-base: form.js: fix handling of array sections in JSONMap forms
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-06-14 16:41:49 +02:00
Jo-Philipp Wich
f0a0d28fdd luci-base: form.js: forward section ID in CBISectionValue methods
This is useful for custom subclasses that want to perform conditional
rendering of contents, depending on the parent section ID.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-05-04 21:34:12 +02:00
Jo-Philipp Wich
428e3bd6dc luci-base: form.js: toggle inactive CSS class on unsatisfied field cells
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-04-28 09:51:54 +02:00
Jo-Philipp Wich
daa318c1b2 luci-base: form.js: ListValue: support widget and orientation properties
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-04-28 09:50:28 +02:00
Jo-Philipp Wich
17ffc84a29 luci-base: form.js: allow secondary configs to fail loading
Ref: https://forum.openwrt.org/t/luci-rpc-error/61760
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-04-28 09:47:08 +02:00
Anton Kikin
7585e5c95a luci-base: form.js: allow to disable descriptions row in TableSection
Add 'nodescriptions' property to the TableSection class that allows
to disable displaying table header row with descriptions.

Signed-off-by: Anton Kikin <a.kikin@tano-systems.com>
2020-04-19 13:56:24 +03:00
Anton Kikin
da0e974db5 luci-base: form.js: fix TableSection descriptions row rendering
In some cases, a table cell at actions column of a descriptions row
may not be rendered. For example, this happens for GridSection when
sorting is disabled:

    s = m.section(form.GridSection, 'section_type');
    s.sortable = false;

Signed-off-by: Anton Kikin <a.kikin@tano-systems.com>
2020-04-19 13:56:24 +03:00
Jo-Philipp Wich
5c22340f43 luci-base: form.js: make map readonly on insufficient uci permissions
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-04-14 17:13:19 +02:00
Jo-Philipp Wich
9279448148 luci-base: form.js: implement readonly property for forms and options
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-04-14 17:08:36 +02:00
Jo-Philipp Wich
2dfcca23e4 luci-base: form.js: improve save error handling
Fixes: #3552
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-04-10 20:38:58 +02:00
Jo-Philipp Wich
698c8ff843 luci-base: form.js: add documentation
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-04-07 16:35:15 +02:00
Jo-Philipp Wich
711f759278 luci-base: harmonize JS class naming and requesting
- Make builtin classes available via `require` to allow view code to
   request external and internal classes in a consistent manner without
   having to know which classes are builtin and which not

 - Make base classes request any used class explicitely instead of
   relying on implicitly set up L.{dom,view,Poll,Request,Class} aliases

 - Consistently convert class names to lower case in JSdoc to match
   the names used in `require` statements

 - Deprecate L.{dom,view,Poll,Request,Class} aliases

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-04-02 21:51:20 +02:00
Jo-Philipp Wich
82fb5a67d3 luci-base: form.js / ui.js: tie form labels to widgets
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(cherry picked from commit 22ba6fc40933bee02c3ea93bbda952bb44bf3af1)
2020-03-24 22:14:18 +01:00
Jo-Philipp Wich
5d8970d76c form.js: use CSS .btn class for drag handles
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-03-23 21:47:35 +01:00
Jo-Philipp Wich
c1aeb300f6 luci-base: form.js: pass section_id to Button onclick handler
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-02-13 19:26:33 +01:00
Jo-Philipp Wich
311bcd4b5c luci-base: form.js: ButtonValue: pass sid as first onclick argument
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-02-13 19:26:33 +01:00
Jo-Philipp Wich
9bb78b5cd8 luci-base: form.js: rendering fixes for grid sections
- Ensure that last header cell is rendered for grid sections without
   sorting or addremove actions
 - Don't skip header cells for optional options

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-02-12 11:59:41 +01:00
Jo-Philipp Wich
601c4ee01e luci-base: form.js: add a new "contains" dependency mode
By tagging option dependencies with `!contains`, dependencies are
considered satisfied when the value is contained in the value of
a related field, instead of being equal to it.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-01-19 16:15:22 +01:00
Jo-Philipp Wich
4670099a20 luci-base: form.js: don't stringify node arguments in CBIValue.value()
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-01-19 16:15:22 +01:00
Jo-Philipp Wich
77c2998f32 luci-base: form.js: fix immediate validation of activated options
When form options are activated because their dependencies are satisified,
ensure that an immediate validation is triggered to highlight potential
errors without having the user to activate another form control first.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-01-15 18:52:16 +01:00
Jo-Philipp Wich
9e25917432 luci-base: form.js: implement AbstractValue.getUIElement()
Introduce a new method `getUIElement()` which simplifies obtaining the
underlying per-section UI widget class instance for a from option object.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-12-30 14:51:40 +01:00
Jo-Philipp Wich
13e9e3e9e8 treewide: fix "Unhandled token" errors with Lua CBI maps
The `data-type` attribute is used to bind datatype validators to a widget
while some templates used the same attribute to denote the name of the
underlying widget.

Change the `data-type` attributes referring to the widget name to
`data-widget` in order to stop the JS token error spam.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-11-16 18:25:52 +01:00
Richard Yu
fa15370f0e
luci-base: form.js: fix GridSection not using user-input name when add
Signed-off-by: Richard Yu <yurichard3839@gmail.com>
2019-11-04 00:19:33 +08:00
Jo-Philipp Wich
e7ca163d7c luci-base: form.js: fix anonymous section table titles
When no section title is defined, the table renderer is supposed to use
the uci section id as fallback when the table section is not declared
to be anonymous.

Fixes: #3147
Fixes: a90bf384b ("luci-base: form.js: harmonize title property handling")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2019-10-07 19:49:58 +02:00