Skip to content

Commit

Permalink
Label override
Browse files Browse the repository at this point in the history
Change-Id: I3e47e1c53d26ea85151b85d9df553284accb4269
  • Loading branch information
Richard Kennard committed Apr 14, 2014
1 parent 91f5ef5 commit 5a39c1e
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 12 deletions.
Expand Up @@ -469,19 +469,22 @@ var metawidget = metawidget || {};

if ( elementName !== 'action' ) {

var label = metawidget.util.createElement( mw, 'label' );
var labelString = this.getLabelString( attributes, mw );

if ( widget.hasAttribute( 'id' ) ) {
label.setAttribute( 'for', widget.getAttribute( 'id' ) );
}
if ( labelString !== '' ) {
var label = metawidget.util.createElement( mw, 'label' );

if ( idPrefix !== undefined ) {
label.setAttribute( 'id', idPrefix + '-label' );
}
if ( widget.hasAttribute( 'id' ) ) {
label.setAttribute( 'for', widget.getAttribute( 'id' ) );
}

label.innerHTML = metawidget.util.getLabelString( attributes, mw ) + ':';
if ( idPrefix !== undefined ) {
label.setAttribute( 'id', idPrefix + '-label' );
}

th.appendChild( label );
label.innerHTML = labelString;
th.appendChild( label );
}
}

tr.appendChild( th );
Expand All @@ -501,6 +504,21 @@ var metawidget = metawidget || {};

tr.appendChild( td );
};

/**
* @returns the label string, or a blank string if no label.
*/

this.getLabelString = function( attributes, mw ) {

var labelString = metawidget.util.getLabelString( attributes, mw );

if ( labelString === '' ) {
return labelString;
}

return labelString + ':';
};
};

//
Expand Down Expand Up @@ -590,7 +608,7 @@ var metawidget = metawidget || {};
decorator.layoutWidget = function( widget, elementName, attributes, container, mw ) {

var section;

// If our delegate is itself a NestedSectionLayoutDecorator, strip
// the section

Expand Down
Expand Up @@ -56,7 +56,6 @@ protected final void runScenarioRunner( String url ) {

new WebDriverWait( driver, TEST_TIMEOUT_IN_SECONDS ).until( new ExpectedCondition<Boolean>() {

@Override
public Boolean apply( WebDriver theDriver ) {

return applyExpectedCondition( theDriver );
Expand Down
40 changes: 39 additions & 1 deletion modules/js/corejs/src/test/js/metawidget-core-layout-tests.js
Expand Up @@ -330,7 +330,7 @@
expect( container.childNodes.length ).toBe( 1 );
} );

it( "allows label overrides", function() {
it( "supports label overrides", function() {

var layout = new metawidget.layout.DivLayout();
layout.getLabelString = function() {
Expand Down Expand Up @@ -937,6 +937,44 @@
expect( container.childNodes[0].childNodes.length ).toBe( 1 );
expect( container.childNodes.length ).toBe( 1 );
} );

it( "supports label overrides", function() {

var layout = new metawidget.layout.TableLayout();
layout.getLabelString = function() {

return "";
}

var widget1 = simpleDocument.createElement( 'input' );
widget1.setAttribute( 'id', 'widget1' );
var container = simpleDocument.createElement( 'metawidget' );
var mw = {
getElement: function() {

return container;
}
}

layout.startContainerLayout( container, mw );
layout.layoutWidget( widget1, "property", {
name: "widget1"
}, container, mw );

expect( container.childNodes[0].toString() ).toBe( 'table' );
expect( container.childNodes[0].childNodes[0].toString() ).toBe( 'tbody' );
expect( container.childNodes[0].childNodes[0].childNodes[0].toString() ).toBe( 'tr id="table-widget1-row"' );
expect( container.childNodes[0].childNodes[0].childNodes[0].childNodes[0].toString() ).toBe( 'th id="table-widget1-label-cell"' );
expect( container.childNodes[0].childNodes[0].childNodes[0].childNodes[0].innerHTML ).toBeUndefined();
expect( container.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes.length ).toBe( 0 );
expect( container.childNodes[0].childNodes[0].childNodes[0].childNodes[1].toString() ).toBe( 'td id="table-widget1-cell"' );
expect( container.childNodes[0].childNodes[0].childNodes[0].childNodes[1].childNodes[0] ).toBe( widget1 );
expect( container.childNodes[0].childNodes[0].childNodes[0].childNodes[2].toString() ).toBe( 'td' );
expect( container.childNodes[0].childNodes[0].childNodes[0].childNodes.length ).toBe( 3 );
expect( container.childNodes[0].childNodes[0].childNodes.length ).toBe( 1 );
expect( container.childNodes[0].childNodes.length ).toBe( 1 );
expect( container.childNodes.length ).toBe( 1 );
} );
} );

describe( "The HeadingTagLayoutDecorator", function() {
Expand Down

0 comments on commit 5a39c1e

Please sign in to comment.