From 8baeec3d195079ca2ac2756c7279113d6465105d Mon Sep 17 00:00:00 2001 From: tfennelly Date: Fri, 5 Feb 2016 20:08:49 +0000 Subject: [PATCH] Give the row header (tr) to the ConfigSection instance --- .../js/widgets/config/model/ConfigSection.js | 7 ++-- .../config/model/ConfigTableMetaData.js | 34 ++++++++++++------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/war/src/main/js/widgets/config/model/ConfigSection.js b/war/src/main/js/widgets/config/model/ConfigSection.js index 580d0595b9..c6a1fbfe94 100644 --- a/war/src/main/js/widgets/config/model/ConfigSection.js +++ b/war/src/main/js/widgets/config/model/ConfigSection.js @@ -9,10 +9,11 @@ module.exports = ConfigSection; * Configuration table section. * ======================================================================================= */ -function ConfigSection(parentCMD, title) { +function ConfigSection(parentCMD, headerRow) { this.parentCMD = parentCMD; - this.title = title; - this.id = util.toId(title); + this.headerRow = headerRow; + this.title = headerRow.attr('title'); + this.id = util.toId(this.title); this.rows = []; this.rowSets = undefined; this.activator = undefined; diff --git a/war/src/main/js/widgets/config/model/ConfigTableMetaData.js b/war/src/main/js/widgets/config/model/ConfigTableMetaData.js index d55fd59754..15c54c9d8d 100644 --- a/war/src/main/js/widgets/config/model/ConfigTableMetaData.js +++ b/war/src/main/js/widgets/config/model/ConfigTableMetaData.js @@ -39,27 +39,33 @@ exports.fromConfigTable = function(configTable) { sectionRow.attr('title', sectionTitle); }); - // Go through the top level elements (immediately inside the ) - // and group the related s based on the "section-header-row", using a "normalized" - // version of the section title as the section id. var configTableMetadata = new ConfigTableMetaData(configForm, configTable); - var curSection = new ConfigSection(configTableMetadata, 'General'); + var topRows = configTableMetadata.getTopRows(); + var firstRow = configTableMetadata.getFirstRow(); + var curSection = undefined; - configTableMetadata.sections.push(curSection); - curSection.id = util.toId(curSection.title); + // The first set of rows don't have a 'section-header-row', so we manufacture one, + // calling it a "General" section. We do this by marking the first row in the table. + // See the next block of code. + firstRow.addClass('section-header-row'); + firstRow.attr('title', "General"); - var topRows = configTableMetadata.getTopRows(); + // Go through the top level elements (immediately inside the ) + // and group the related s based on the "section-header-row", using a "normalized" + // version of the section title as the section id. topRows.each(function () { var tr = $(this); if (tr.hasClass('section-header-row')) { // a new section - var title = tr.attr('title'); - curSection = new ConfigSection(configTableMetadata, title); + curSection = new ConfigSection(configTableMetadata, tr); configTableMetadata.sections.push(curSection); } - - curSection.rows.push(tr); - tr.addClass(curSection.id); + if (curSection) { + curSection.rows.push(tr); + tr.addClass(curSection.id); + } else { + throw 'Unexpected error. The first row in the config table is expected to be a "section-header-row".'; + } }); var buttonsRow = $('#bottom-sticker', configTable).closest('tr'); @@ -91,6 +97,10 @@ ConfigTableMetaData.prototype.getTopRows = function() { return this.configTableBody.children('tr'); }; +ConfigTableMetaData.prototype.getFirstRow = function() { + return this.getTopRows().first(); +}; + ConfigTableMetaData.prototype.addWidgetsContainer = function() { var $ = jQD.getJQuery(); this.configWidgets = $('
'); -- GitLab