From b8e437a38dde27d6310c26cd2656a270fce6ca99 Mon Sep 17 00:00:00 2001 From: thiemowmde Date: Tue, 7 Nov 2023 11:48:08 +0100 Subject: [PATCH] Introduce prop var to reduce code duplication in Dialog.js Most of the code is already using a "prop" variable for the same purpose. I hope that following the same pattern everywhere makes the code easier to read. Change-Id: I00e344b9041e1cb7e2dee129b17549959f32e4d9 --- .../Dialog.js | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/modules/ext.templateDataGenerator.editTemplatePage/Dialog.js b/modules/ext.templateDataGenerator.editTemplatePage/Dialog.js index 96c0e5dc..9140858a 100644 --- a/modules/ext.templateDataGenerator.editTemplatePage/Dialog.js +++ b/modules/ext.templateDataGenerator.editTemplatePage/Dialog.js @@ -856,12 +856,13 @@ Dialog.prototype.onTemplateFormatInputWidgetEnter = function () { Dialog.prototype.onParamPropertyInputChange = function ( propName, value ) { var $errors = $( [] ), allProps = Model.static.getAllProperties( true ), + prop = allProps[ propName ], propInput = this.propInputs[ propName ], - dependentField = allProps[ propName ].textValue; + dependentField = prop.textValue; - if ( allProps[ propName ].type === 'select' ) { + if ( prop.type === 'select' ) { var selected = propInput.getMenu().findSelectedItem(); - value = selected ? selected.getData() : allProps[ propName ].default; + value = selected ? selected.getData() : prop.default; this.toggleSuggestedValues( value ); } @@ -875,12 +876,12 @@ Dialog.prototype.onParamPropertyInputChange = function ( propName, value ) { } } - if ( allProps[ propName ].type === 'array' ) { + if ( prop.type === 'array' ) { value = propInput.getValue(); } - if ( allProps[ propName ].restrict ) { - if ( value.match( allProps[ propName ].restrict ) ) { + if ( prop.restrict ) { + if ( value.match( prop.restrict ) ) { // Error! Don't fix the model $errors = $errors.add( $( '

' ).text( mw.msg( 'templatedata-modal-errormsg', '|', '=', '}}' ) ) ); } @@ -1122,16 +1123,17 @@ Dialog.prototype.createParamDetails = function () { var paramFieldset = new OO.ui.FieldsetLayout(); for ( var propName in paramProperties ) { + var prop = paramProperties[ propName ]; var propInput; var config = {}; // Create the property inputs - switch ( paramProperties[ propName ].type ) { + switch ( prop.type ) { case 'select': propInput = new OO.ui.DropdownWidget( config ); var items = []; - for ( var i in paramProperties[ propName ].children ) { + for ( var i in prop.children ) { items.push( new OO.ui.MenuOptionWidget( { - data: paramProperties[ propName ].children[ i ], + data: prop.children[ i ], // The following messages are used here: // * templatedata-doc-param-type-boolean, templatedata-doc-param-type-content, @@ -1141,7 +1143,7 @@ Dialog.prototype.createParamDetails = function () { // * templatedata-doc-param-type-url, templatedata-doc-param-type-wiki-file-name, // * templatedata-doc-param-type-wiki-page-name, templatedata-doc-param-type-wiki-template-name, // * templatedata-doc-param-type-wiki-user-name - label: mw.msg( 'templatedata-doc-param-' + propName + '-' + paramProperties[ propName ].children[ i ] ) + label: mw.msg( 'templatedata-doc-param-' + propName + '-' + prop.children[ i ] ) } ) ); } propInput.getMenu().addItems( items ); @@ -1156,7 +1158,7 @@ Dialog.prototype.createParamDetails = function () { break; default: config.autosize = true; - if ( !paramProperties[ propName ].multiline ) { + if ( !prop.multiline ) { config.rows = 1; config.allowLinebreaks = false; }