From f894913007f2f747c5af7d673cd3a2adeae9e246 Mon Sep 17 00:00:00 2001 From: Paul Donald Date: Wed, 14 Jan 2026 21:21:46 +0100 Subject: [PATCH] luci-base: document delbtntitle clonebtntitle We also implement delbtntitle functionality for various *Table types. This means one can implement a table and rename its Delete button like so: s.delbtntitle = _('Kill it with fire!'); Signed-off-by: Paul Donald --- .../htdocs/luci-static/resources/form.js | 37 ++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/modules/luci-base/htdocs/luci-static/resources/form.js b/modules/luci-base/htdocs/luci-static/resources/form.js index 9c2ea4a184..b0d855c56f 100644 --- a/modules/luci-base/htdocs/luci-static/resources/form.js +++ b/modules/luci-base/htdocs/luci-static/resources/form.js @@ -2189,7 +2189,7 @@ const CBITypedSection = CBIAbstractSection.extend(/** @lends LuCI.form.TypedSect */ /** - * Override the caption used for the section add a button at the bottom of + * Override the caption used for the section add button at the bottom of * the section form element. Set to a string, it will be used as-is. * Set to a function, the function will be invoked and its return value * is used as a caption, after converting it to a string. If this property @@ -2200,6 +2200,18 @@ const CBITypedSection = CBIAbstractSection.extend(/** @lends LuCI.form.TypedSect * @default null */ + /** + * Override the caption used for the section delete button at the bottom of + * the section form element. Set to a string, it will be used as-is. + * Set to a function, the function will be invoked and its return value + * is used as a caption, after converting it to a string. If this property + * is not set, the default is `Delete`. + * + * @name LuCI.form.TypedSection.prototype#delbtntitle + * @type string|function + * @default null + */ + /** * Override the UCI configuration name to read the section IDs from. By * default, the configuration name is inherited from the parent `Map`. @@ -2319,6 +2331,7 @@ const CBITypedSection = CBIAbstractSection.extend(/** @lends LuCI.form.TypedSect for (let i = 0; i < nodes.length; i++) { if (this.addremove) { + const rem_btn_title = this.titleFn('delbtntitle', section_id); sectionEl.appendChild( E('div', { 'class': 'cbi-section-remove right' }, E('button', { @@ -2327,7 +2340,7 @@ const CBITypedSection = CBIAbstractSection.extend(/** @lends LuCI.form.TypedSect 'data-section-id': cfgsections[i], 'click': ui.createHandlerFn(this, 'handleRemove', cfgsections[i]), 'disabled': this.map.readonly || null - }, [ _('Delete') ]))); + }, [ rem_btn_title ?? _('Delete') ]))); } if (!this.anonymous) @@ -2459,6 +2472,18 @@ const CBITableSection = CBITypedSection.extend(/** @lends LuCI.form.TableSection * @default false */ + /** + * Override the caption used for the section clone button at the bottom of + * the section form element. Set to a string, it will be used as-is. + * Set to a function, the function will be invoked and its return value + * is used as a caption, after converting it to a string. If this property + * is not set, the default is `Clone`. + * + * @name LuCI.form.TypedSection.prototype#clonebtntitle + * @type string|function + * @default null + */ + /** * Enables a per-section instance row `Edit` button which triggers a certain * action when clicked. Set to a string, the string value is used @@ -2748,7 +2773,7 @@ const CBITableSection = CBITypedSection.extend(/** @lends LuCI.form.TableSection } if (this.addremove) { - const btn_title = this.titleFn('removebtntitle', section_id); + const btn_title = this.titleFn('delbtntitle', section_id); dom.append(tdEl.lastElementChild, E('button', { @@ -3598,13 +3623,14 @@ const CBINamedSection = CBIAbstractSection.extend(/** @lends LuCI.form.NamedSect if (ucidata) { if (this.addremove) { + const rem_btn_title = this.titleFn('delbtntitle', section_id); sectionEl.appendChild( E('div', { 'class': 'cbi-section-remove right' }, E('button', { 'class': 'cbi-button', 'click': ui.createHandlerFn(this, 'handleRemove'), 'disabled': this.map.readonly || null - }, [ _('Delete') ]))); + }, [ rem_btn_title ?? _('Delete') ]))); } sectionEl.appendChild(E('div', { @@ -3615,12 +3641,13 @@ const CBINamedSection = CBIAbstractSection.extend(/** @lends LuCI.form.NamedSect }, nodes)); } else if (this.addremove) { + const add_btn_title = this.titleFn('addbtntitle', section_id); sectionEl.appendChild( E('button', { 'class': 'cbi-button cbi-button-add', 'click': ui.createHandlerFn(this, 'handleAdd'), 'disabled': this.map.readonly || null - }, [ _('Add') ])); + }, [ add_btn_title ?? _('Add') ])); } dom.bindClassInstance(sectionEl, this); -- 2.30.2