Prevent a dependent property from updating on infinite loops

A dependent and dependee properties should only update one another
once in the model, and the UI should be responsible for resetting
the input when it is toggled.

Bug: T92558
Change-Id: I944aaf9c44d0f305a34458f0b8009a98c9570661
This commit is contained in:
Moriel Schottlender 2015-03-12 13:51:59 -07:00
parent ffbc8e1520
commit 4141bed38b
3 changed files with 22 additions and 30 deletions

View file

@ -748,7 +748,6 @@ mw.TemplateData.Model.prototype.setParamProperty = function ( paramKey, prop, va
status = false;
language = language || this.getDefaultLanguage();
if ( !allProps[prop] ) {
// The property isn't supported yet
return status;
@ -780,9 +779,9 @@ mw.TemplateData.Model.prototype.setParamProperty = function ( paramKey, prop, va
}
}
if ( allProps[prop].changesBooleanValue ) {
// Also change the property this depends on
status = this.setParamProperty( paramKey, allProps[prop].changesBooleanValue, !!value, language );
if ( allProps[ prop ].textValue && value === false ) {
// Unset the text value if the boolean it depends on is false
status = this.setParamProperty( paramKey, allProps[prop].textValue, null, language );
}
return status;

View file

@ -256,30 +256,6 @@ mw.TemplateData.Dialog.prototype.onAddParamInputChange = function ( value ) {
}
};
/**
* Respond to model change property
* @param {string} paramKey Parameter key
* @param {string} property Property name
* @param {string} value Property value
* @param {string} [language] Language
*/
mw.TemplateData.Dialog.prototype.onModelChangeProperty = function ( paramKey, property, value, language ) {
var allProps = mw.TemplateData.Model.static.getAllProperties( true );
// Only update the input if it is the visible parameter key
// and we are in the edit parameters panel
if (
this.selectedParamKey === paramKey &&
this.panels.getCurrentItem() === this.editParamPanel
) {
if ( allProps[ property ].textValue ) {
// The textValue property depends on this property
// toggle its view
this.propFieldLayout[ allProps[ property ].textValue ].toggle( !!value );
}
this.changeParamPropertyInput( paramKey, property, value, language );
}
};
/**
* Respond to change of paramOrder from the model
* @param {string[]} paramOrderArray The array of keys in order
@ -469,12 +445,21 @@ mw.TemplateData.Dialog.prototype.onParamPropertyInputChange = function ( propert
this.propInputs[property].$element.toggleClass( 'tdg-editscreen-input-error', err );
// Check if there is a dependent input to activate
if ( allProps[ property ].textValue && this.propFieldLayout[ allProps[ property ].textValue ] ) {
// The textValue property depends on this property
// toggle its view
this.propFieldLayout[ allProps[ property ].textValue ].toggle( !!value );
this.propInputs[ allProps[ property ].textValue ].setValue( this.model.getParamProperty( this.selectedParamKey, allProps[ property ].textValue ) );
}
// Validate
$( '.tdg-TemplateDataDialog-paramInput' ).each( function () {
if ( $( this ).hasClass( 'tdg-editscreen-input-error' ) ) {
anyInputError = true;
}
} );
// Disable the 'back' button if there are any errors in the inputs
this.actions.setAbilities( { back: !anyInputError } );
if ( !err ) {
@ -806,7 +791,6 @@ mw.TemplateData.Dialog.prototype.getSetupProcess = function ( data ) {
// Events
this.model.connect( this, {
'change-description': 'onModelChangeDescription',
'change-property': 'onModelChangeProperty',
'change-paramOrder': 'onModelChangeParamOrder',
'add-paramOrder': 'onModelAddKeyParamOrder'
} );

View file

@ -483,6 +483,15 @@
} ),
msg: 'Adding empty description in mock language.'
},
{
key: 'newParam3',
property: 'deprecated',
value: true,
result: $.extend( {}, paramAddTest[2].result, {
deprecated: true
} ),
msg: 'Adding deprecated property (boolean).'
},
{
key: 'newParam3',
property: 'deprecatedValue',
@ -491,7 +500,7 @@
deprecated: true,
deprecatedValue: 'This is deprecated.'
} ),
msg: 'Adding empty description in mock language.'
msg: 'Adding deprecated property (string).'
}
];