Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <gerwitzm@lovullo.com>2017-02-08 10:36:06 -0500
committerMike Gerwitz <gerwitzm@lovullo.com>2017-02-08 11:24:56 -0500
commit028606242a2f8ebbd558cf4752309054fdee427e (patch)
tree13719c3414ace6a9636336239db1600fd9fb2ce9
parente26a7c3cac34ae498800e8835f9312d4e717e51f (diff)
downloadliza-028606242a2f8ebbd558cf4752309054fdee427e.tar.gz
liza-028606242a2f8ebbd558cf4752309054fdee427e.tar.bz2
liza-028606242a2f8ebbd558cf4752309054fdee427e.zip
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.
-rw-r--r--src/client/Client.js111
-rw-r--r--src/client/ClientDependencyFactory.js16
2 files changed, 35 insertions, 92 deletions
diff --git a/src/client/Client.js b/src/client/Client.js
index b6e6cd5..ea8aa78 100644
--- a/src/client/Client.js
+++ b/src/client/Client.js
@@ -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
*
diff --git a/src/client/ClientDependencyFactory.js b/src/client/ClientDependencyFactory.js
index 1a8c0da..bdf711d 100644
--- a/src/client/ClientDependencyFactory.js
+++ b/src/client/ClientDependencyFactory.js
@@ -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 )
} );
}