Skip to content

Commit 545de2a

Browse files
Alphixsystemcrash
authored andcommitted
luci-base: add ability to hide section titles
The rationale here is that tabbed CBIMaps were introduced in commit 082fd9f. With tabbed maps, code could typically look like this: m = new form.Map('foobar', _('FooBar')); m.tabbed = true; s = m.section(form.TypedSection, 'foo', _('foo Settings')); The problem is that the title of "s" will be used as the name of the tab rendered in "m", but also rendered as an <h3> right below the tab. IOW, the same information will be presented twice, which looks weird. Doing this instead... m = new form.Map('foobar', _('FooBar')); m.tabbed = true; s = m.section(form.TypedSection, 'foo'); ...means that the superfluous <h3> won't be rendered (since "s" has no title), but the tab will then simply have the name of the section ("foo"), which can't be translated (bad). After this change, the tabbed map can be written like this: m = new form.Map('foobar', _('FooBar')); m.tabbed = true; s = m.section(form.TypedSection, 'foo', _('foo Settings')); s.hidetitle = true; Which will give the Map tab the name "foo Settings", but won't add a title for the TypedSection right under the tab. Signed-off-by: David Härdeman <[email protected]>
1 parent 1b8564e commit 545de2a

File tree

1 file changed

+25
-3
lines changed
  • modules/luci-base/htdocs/luci-static/resources

1 file changed

+25
-3
lines changed

modules/luci-base/htdocs/luci-static/resources/form.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2155,6 +2155,17 @@ const CBITypedSection = CBIAbstractSection.extend(/** @lends LuCI.form.TypedSect
21552155
* @default false
21562156
*/
21572157

2158+
/**
2159+
* If set to true, the title caption of the form section element which
2160+
* is normally rendered before the start of the section content will
2161+
* not be rendered in the UI. The default is false, meaning that the
2162+
* title is rendered.
2163+
*
2164+
* @name LuCI.form.TypedSection.prototype#hidetitle
2165+
* @type boolean
2166+
* @default false
2167+
*/
2168+
21582169
/**
21592170
* If set to `true`, mapped section instances are treated as anonymous
21602171
* UCI sections, which means that section instance elements will be
@@ -2300,7 +2311,7 @@ const CBITypedSection = CBIAbstractSection.extend(/** @lends LuCI.form.TypedSect
23002311
'data-tab-title': (this.map.tabbed && !this.parentoption) ? this.title || this.sectiontype : null
23012312
});
23022313

2303-
if (this.title != null && this.title != '')
2314+
if (this.title != null && this.title != '' && !this.hidetitle)
23042315
sectionEl.appendChild(E('h3', {}, this.title));
23052316

23062317
if (this.description != null && this.description != '')
@@ -2530,7 +2541,7 @@ const CBITableSection = CBITypedSection.extend(/** @lends LuCI.form.TableSection
25302541
'class': 'table cbi-section-table'
25312542
});
25322543

2533-
if (this.title != null && this.title != '')
2544+
if (this.title != null && this.title != '' && !this.hidetitle)
25342545
sectionEl.appendChild(E('h3', {}, this.title));
25352546

25362547
if (this.description != null && this.description != '')
@@ -3513,6 +3524,17 @@ const CBINamedSection = CBIAbstractSection.extend(/** @lends LuCI.form.NamedSect
35133524
* @default false
35143525
*/
35153526

3527+
/**
3528+
* If set to true, the title caption of the form section element which
3529+
* is normally rendered before the start of the section content will
3530+
* not be rendered in the UI. The default is false, meaning that the
3531+
* title is rendered.
3532+
*
3533+
* @name LuCI.form.NamedSection.prototype#hidetitle
3534+
* @type boolean
3535+
* @default false
3536+
*/
3537+
35163538
/**
35173539
* Override the UCI configuration name to read the section IDs from. By
35183540
* default, the configuration name is inherited from the parent `Map`.
@@ -3568,7 +3590,7 @@ const CBINamedSection = CBIAbstractSection.extend(/** @lends LuCI.form.NamedSect
35683590
'data-tab-title': (this.map.tabbed && !this.parentoption) ? this.title || this.sectiontype : null
35693591
});
35703592

3571-
if (typeof(this.title) === 'string' && this.title !== '')
3593+
if (typeof(this.title) === 'string' && this.title !== '' && !this.hidetitle)
35723594
sectionEl.appendChild(E('h3', {}, this.title));
35733595

35743596
if (typeof(this.description) === 'string' && this.description !== '')

0 commit comments

Comments
 (0)