[DEV-3192] Simplified logic and corrected issue with bucket data
parent
b72fb4b2c7
commit
e079a5eb0a
|
@ -56,44 +56,45 @@ module.exports = Class( 'ProgramInit',
|
|||
{
|
||||
const defaults = program.defaults || {};
|
||||
|
||||
var data = {},
|
||||
groups = program.meta.groups;
|
||||
let data = doc_data || {};
|
||||
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-- )
|
||||
{
|
||||
var field = program.groupExclusiveFields[ group ][ length ],
|
||||
defaultValue;
|
||||
let field = program.groupExclusiveFields[ group ][ length ];
|
||||
let defaultValue;
|
||||
|
||||
if ( defaults.hasOwnProperty(field) )
|
||||
if ( !defaults.hasOwnProperty( field ))
|
||||
{
|
||||
defaultValue = defaults[ field ];
|
||||
// Initialize with existing document data if any
|
||||
data[ field ] = doc_data && doc_data[ field ] ? doc_data[ field ] : [];
|
||||
continue;
|
||||
}
|
||||
|
||||
// If no document data, initialize with default value
|
||||
if ( !doc_data || !doc_data[ field ] )
|
||||
defaultValue = defaults[ 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;
|
||||
}
|
||||
|
||||
// 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++;
|
||||
}
|
||||
data[ field ][ index ] = defaultValue;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -791,7 +791,12 @@ module.exports = Class( 'GroupUi' )
|
|||
: $element;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Hides the field based on field name and index
|
||||
*
|
||||
* @param field
|
||||
* @param index
|
||||
*/
|
||||
'virtual public hideField': function( field, index )
|
||||
{
|
||||
if ( this.isFieldVisible( field, index ) === false )
|
||||
|
@ -813,13 +818,25 @@ module.exports = Class( 'GroupUi' )
|
|||
.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 )
|
||||
{
|
||||
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 )
|
||||
{
|
||||
if ( this.isFieldVisible( field, index ) === true )
|
||||
|
|
|
@ -115,11 +115,8 @@ module.exports = Class( 'StackedGroupUi' )
|
|||
if ( !this.hasVisibleField( index ) )
|
||||
{
|
||||
const header = this._$container.find( 'dl' )[ index ];
|
||||
var attribute = header.getAttribute( 'class' );
|
||||
|
||||
attribute = attribute.includes( ' hidden ' ) ? attribute : attribute + ' hidden ';
|
||||
|
||||
header.setAttribute( 'class', attribute );
|
||||
header.classList.add( 'hidden' );
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -137,11 +134,8 @@ module.exports = Class( 'StackedGroupUi' )
|
|||
if ( this.hasVisibleField( index ) )
|
||||
{
|
||||
const header = this._$container.find( 'dl' )[ index ];
|
||||
var attribute = header.getAttribute( 'class' );
|
||||
|
||||
attribute = attribute.includes( ' hidden ' ) ? attribute.replace(' hidden ', '') : attribute;
|
||||
|
||||
header.setAttribute( 'class', attribute );
|
||||
header.classList.remove( 'hidden' );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue