1
0
Fork 0

[DEV-3192] Simplified logic and corrected issue with bucket data

master
Jeffrey Fisher 2018-06-15 13:35:06 -04:00
parent b72fb4b2c7
commit e079a5eb0a
3 changed files with 51 additions and 39 deletions

View File

@ -56,44 +56,45 @@ module.exports = Class( 'ProgramInit',
{ {
const defaults = program.defaults || {}; const defaults = program.defaults || {};
var data = {}, let data = doc_data || {};
groups = program.meta.groups; let groups = program.meta.groups;
Object.keys( program.groupExclusiveFields ).forEach( function( group, index ) Object.keys( program.groupExclusiveFields ).forEach( group =>
{ {
var length = program.groupExclusiveFields[ group ].length; let length = program.groupExclusiveFields[ group ].length;
while ( length-- ) while ( length-- )
{ {
var field = program.groupExclusiveFields[ group ][ length ], let field = program.groupExclusiveFields[ group ][ length ];
defaultValue; let defaultValue;
if ( defaults.hasOwnProperty(field) ) if ( !defaults.hasOwnProperty( field ))
{ {
defaultValue = defaults[ field ]; continue;
// Initialize with existing document data if any }
data[ field ] = doc_data && doc_data[ field ] ? doc_data[ field ] : [];
// If no document data, initialize with default value defaultValue = defaults[ field ];
if ( !doc_data || !doc_data[ field ] ) // Initialize with existing document data if any
// If no document data, initialize with default value
if ( data[ field ] === undefined )
{
data[ field ] = [ defaultValue ];
}
// If min rows on the group is greater than the data
// currently in the bucket, then populate the rest
// of the data with the default data until the
// arrays are the same length
if ( groups.hasOwnProperty( group ) &&
data[ field ].length < groups[ group ].min )
{
let index = data[ field ].length;
while ( index < groups[ group ].min )
{ {
data[ field ][ 0 ] = defaultValue; data[ field ][ index ] = defaultValue;
} index++;
// If min rows on the group is greater than the data
// currently in the bucket, then populate the rest
// of the data with the default data until the
// arrays are the same length
if ( groups.hasOwnProperty( group ) &&
data[ field ].length < groups[ group ].min )
{
var index = data[ field ].length;
while ( index < groups[ group ].min )
{
data[ field ][ index ] = defaultValue;
index++;
}
} }
} }
} }

View File

@ -791,7 +791,12 @@ module.exports = Class( 'GroupUi' )
: $element; : $element;
}, },
/**
* Hides the field based on field name and index
*
* @param field
* @param index
*/
'virtual public hideField': function( field, index ) 'virtual public hideField': function( field, index )
{ {
if ( this.isFieldVisible( field, index ) === false ) if ( this.isFieldVisible( field, index ) === false )
@ -813,13 +818,25 @@ module.exports = Class( 'GroupUi' )
.applyStyle( this._naStyler ); .applyStyle( this._naStyler );
}, },
/**
* Returns a boolean depending on if there are visible fields
* based off of the visCount
*
* @param index
* @returns {boolean}
*/
'protected hasVisibleField'( index ) 'protected hasVisibleField'( index )
{ {
return this._visCount[ index ] > 0 ? true : false; return this._visCount[ index ] > 0 ? true : false;
}, },
/**
* Shows the field based on field name and index
*
* @param field
* @param index
*/
'virtual public showField': function( field, index ) 'virtual public showField': function( field, index )
{ {
if ( this.isFieldVisible( field, index ) === true ) if ( this.isFieldVisible( field, index ) === true )

View File

@ -115,11 +115,8 @@ module.exports = Class( 'StackedGroupUi' )
if ( !this.hasVisibleField( index ) ) if ( !this.hasVisibleField( index ) )
{ {
const header = this._$container.find( 'dl' )[ index ]; const header = this._$container.find( 'dl' )[ index ];
var attribute = header.getAttribute( 'class' );
attribute = attribute.includes( ' hidden ' ) ? attribute : attribute + ' hidden '; header.classList.add( 'hidden' );
header.setAttribute( 'class', attribute );
} }
}, },
@ -137,11 +134,8 @@ module.exports = Class( 'StackedGroupUi' )
if ( this.hasVisibleField( index ) ) if ( this.hasVisibleField( index ) )
{ {
const header = this._$container.find( 'dl' )[ index ]; const header = this._$container.find( 'dl' )[ index ];
var attribute = header.getAttribute( 'class' );
attribute = attribute.includes( ' hidden ' ) ? attribute.replace(' hidden ', '') : attribute; header.classList.remove( 'hidden' );
header.setAttribute( 'class', attribute );
} }
} }