Integrate field visibility event handler
* src/client/Client.js (_hideField): Remove method (extracted into FieldVisibilityEventHandler). (handleEvent): Remove show/hide handling. (_handleClassMatch): Adjust to new class/API. * src/client/ClientDependencyFactory.js (createClientEventHandler): Add show/hide event handlers.master
parent
e26a7c3cac
commit
028606242a
|
@ -326,10 +326,6 @@ module.exports = Class( 'Client' )
|
|||
// used to communicate with the server
|
||||
this.dataProxy = this._createDataProxy( jQuery );
|
||||
|
||||
this._eventHandler = this._factory.createClientEventHandler(
|
||||
this, this.elementStyler, this.dataProxy, jQuery
|
||||
);
|
||||
|
||||
this.uiDialog = this._factory.createUiDialog();
|
||||
this.programId = this._getProgramId();
|
||||
this.program = this._createProgram();
|
||||
|
@ -347,6 +343,10 @@ module.exports = Class( 'Client' )
|
|||
|
||||
this.ui = this._createUi( this.nav );
|
||||
|
||||
this._eventHandler = this._factory.createClientEventHandler(
|
||||
this, this._dataValidator, this.elementStyler, this.dataProxy, jQuery
|
||||
);
|
||||
|
||||
this._classMatcher = this._factory.createFieldClassMatcher(
|
||||
this.program.whens
|
||||
);
|
||||
|
@ -699,7 +699,7 @@ module.exports = Class( 'Client' )
|
|||
.getExclusiveFieldNames();
|
||||
|
||||
|
||||
var showq = [], hideq = [];
|
||||
var visq = [];
|
||||
for ( var field in cmatch )
|
||||
{
|
||||
// ignore fields that are not on the current step
|
||||
|
@ -761,13 +761,14 @@ module.exports = Class( 'Client' )
|
|||
|
||||
if ( show.length )
|
||||
{
|
||||
showq[ field ] = show;
|
||||
_self._mergeCmatchHidden( field, show, false );
|
||||
visq[ field ] = { event_id: 'show', name: field, indexes: show };
|
||||
this._mergeCmatchHidden( field, show, false );
|
||||
}
|
||||
|
||||
if ( hide.length )
|
||||
{
|
||||
hideq[ field ] = hide;
|
||||
_self._mergeCmatchHidden( field, hide, true );
|
||||
visq[ field ] = { event_id: 'hide', name: field, indexes: hide };
|
||||
this._mergeCmatchHidden( field, hide, true );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -780,10 +781,19 @@ module.exports = Class( 'Client' )
|
|||
// manipulations on it (TODO: this is a workaround for group
|
||||
// show/hide issues; we need a better solution to guarantee
|
||||
// order
|
||||
setTimeout( function()
|
||||
setTimeout( () =>
|
||||
{
|
||||
_self._hideFields( showq, 'show' );
|
||||
_self._hideFields( hideq, 'hide' );
|
||||
Object.keys( visq ).forEach( field =>
|
||||
{
|
||||
const { event_id, name, indexes } = visq[ field ];
|
||||
|
||||
this.handleEvent( event_id, {
|
||||
elementName: name,
|
||||
indexes: indexes,
|
||||
} );
|
||||
|
||||
this._dapiTrigger( name );
|
||||
} );
|
||||
}, 25 );
|
||||
},
|
||||
|
||||
|
@ -2598,16 +2608,6 @@ module.exports = Class( 'Client' )
|
|||
// perform event (XXX: replace me; see above)
|
||||
switch ( event_name )
|
||||
{
|
||||
case 'enable':
|
||||
case 'disable':
|
||||
case 'hide':
|
||||
case 'show':
|
||||
var fdata = {};
|
||||
fdata[ data.elementName ] = data.indexes;
|
||||
|
||||
this._hideFields( fdata, event_name );
|
||||
break;
|
||||
|
||||
case 'set':
|
||||
var setdata = {};
|
||||
setdata[ data.elementName ] = [];
|
||||
|
@ -2644,73 +2644,6 @@ module.exports = Class( 'Client' )
|
|||
},
|
||||
|
||||
|
||||
'private _hideFields': function( fields, event_name )
|
||||
{
|
||||
var stepui = this.ui.getCurrentStep();
|
||||
|
||||
if ( !stepui )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for ( var field in fields )
|
||||
{
|
||||
var indexes = fields[ field ],
|
||||
indexes_len = indexes.length;
|
||||
|
||||
for ( var i = 0; i < indexes_len; i++ )
|
||||
{
|
||||
var index = indexes[ i ];
|
||||
|
||||
if ( index === undefined )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var group = stepui.getElementGroup( field );
|
||||
if ( group === null )
|
||||
{
|
||||
window.console && console.warn && console.warn(
|
||||
'No group found for %s event: %s[%s]',
|
||||
event_name,
|
||||
field,
|
||||
index
|
||||
);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
this._dapiTrigger( field );
|
||||
|
||||
if ( event_name === 'show' )
|
||||
{
|
||||
group.showField( field, index );
|
||||
}
|
||||
else if ( event_name === 'hide' )
|
||||
{
|
||||
group.hideField( field, index );
|
||||
}
|
||||
else
|
||||
{
|
||||
// locate the element within the group
|
||||
var $element = group.getElementByName(
|
||||
field, index
|
||||
);
|
||||
|
||||
if ( event_name === 'enable' )
|
||||
{
|
||||
$element.attr( 'readonly', false );
|
||||
}
|
||||
else if ( event_name === 'disable' )
|
||||
{
|
||||
$element.attr( 'readonly', true );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Trigger DataApi event for field FIELD
|
||||
*
|
||||
|
|
|
@ -103,12 +103,12 @@ var Step = require( '../step/Step' ),
|
|||
Class = require( 'easejs' ).Class;
|
||||
|
||||
|
||||
var event = require( '../event' );
|
||||
var liza_event = require( '../event' );
|
||||
|
||||
|
||||
function requireh( name )
|
||||
{
|
||||
return event[ name ];
|
||||
return liza_event[ name ];
|
||||
}
|
||||
|
||||
|
||||
|
@ -347,8 +347,15 @@ module.exports = Class( 'ClientDependencyFactory',
|
|||
createFieldClassMatcher: FieldClassMatcher,
|
||||
|
||||
|
||||
createClientEventHandler: function( client, styler, data_proxy, jquery )
|
||||
createClientEventHandler: function(
|
||||
client, data_validator, styler, data_proxy, jquery
|
||||
)
|
||||
{
|
||||
const field_vis_handler = requireh( 'FieldVisibilityEventHandler' )(
|
||||
client.getUi(),
|
||||
data_validator
|
||||
);
|
||||
|
||||
return DelegateEventHandler( {
|
||||
'indvRate': requireh( 'IndvRateEventHandler' )(
|
||||
client, data_proxy
|
||||
|
@ -358,6 +365,9 @@ module.exports = Class( 'ClientDependencyFactory',
|
|||
'kickBack': requireh( 'KickbackEventHandler' )( client ),
|
||||
'status': requireh( 'StatusEventHandler' )( styler ),
|
||||
|
||||
'show': field_vis_handler,
|
||||
'hide': field_vis_handler,
|
||||
|
||||
'action$cvv2Dialog': requireh( 'Cvv2DialogEventHandler' )( jquery )
|
||||
} );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue