[DEV-3192] Simplified logic and corrected issue with bucket data
parent
b72fb4b2c7
commit
e079a5eb0a
|
@ -56,28 +56,30 @@ 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 ))
|
||||||
{
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
defaultValue = defaults[ field ];
|
defaultValue = defaults[ field ];
|
||||||
// Initialize with existing document data if any
|
// 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
|
// If no document data, initialize with default value
|
||||||
if ( !doc_data || !doc_data[ field ] )
|
if ( data[ field ] === undefined )
|
||||||
{
|
{
|
||||||
data[ field ][ 0 ] = defaultValue;
|
data[ field ] = [ defaultValue ];
|
||||||
}
|
}
|
||||||
|
|
||||||
// If min rows on the group is greater than the data
|
// If min rows on the group is greater than the data
|
||||||
|
@ -87,7 +89,7 @@ module.exports = Class( 'ProgramInit',
|
||||||
if ( groups.hasOwnProperty( group ) &&
|
if ( groups.hasOwnProperty( group ) &&
|
||||||
data[ field ].length < groups[ group ].min )
|
data[ field ].length < groups[ group ].min )
|
||||||
{
|
{
|
||||||
var index = data[ field ].length;
|
let index = data[ field ].length;
|
||||||
|
|
||||||
while ( index < groups[ group ].min )
|
while ( index < groups[ group ].min )
|
||||||
{
|
{
|
||||||
|
@ -96,7 +98,6 @@ module.exports = Class( 'ProgramInit',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return Promise.resolve( data );
|
return Promise.resolve( data );
|
||||||
|
|
|
@ -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 )
|
||||||
|
|
|
@ -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 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue