mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TemplateData
synced 2024-11-23 23:43:54 +00:00
Use type info instead of repeating individual field names
The data structure at the top of Model.js uses types like "string", "array" and so on. Fields that share a type behave identical. I find it odd to repeat parts of this data structure in the code. That's what the types are for. Change-Id: Iae55c18ececb809a56e40d3179d2cde357309d0a
This commit is contained in:
parent
260fdf76df
commit
7d0f0da623
|
@ -1009,11 +1009,12 @@ Model.prototype.outputTemplateData = function () {
|
|||
|
||||
// Go over all properties
|
||||
for ( var prop in allProps ) {
|
||||
switch ( prop ) {
|
||||
case 'deprecatedValue':
|
||||
case 'name':
|
||||
if ( prop === 'deprecatedValue' || prop === 'name' ) {
|
||||
continue;
|
||||
case 'type':
|
||||
}
|
||||
|
||||
switch ( allProps[ prop ].type ) {
|
||||
case 'select':
|
||||
// Only include type if the original included type
|
||||
// or if the current type is not undefined
|
||||
if (
|
||||
|
@ -1026,9 +1027,7 @@ Model.prototype.outputTemplateData = function () {
|
|||
result.params[ name ][ prop ] = this.params[ key ].type;
|
||||
}
|
||||
break;
|
||||
case 'deprecated':
|
||||
case 'required':
|
||||
case 'suggested':
|
||||
case 'boolean':
|
||||
if ( !this.params[ key ][ prop ] ) {
|
||||
// Only add a literal false value if there was a false
|
||||
// value before
|
||||
|
@ -1048,8 +1047,7 @@ Model.prototype.outputTemplateData = function () {
|
|||
}
|
||||
}
|
||||
break;
|
||||
case 'suggestedvalues':
|
||||
case 'aliases':
|
||||
case 'array':
|
||||
// Only update these if the new templatedata has an
|
||||
// array that isn't empty
|
||||
if (
|
||||
|
|
|
@ -875,8 +875,9 @@ Dialog.prototype.onParamPropertyInputChange = function ( property, value ) {
|
|||
propInput = this.propInputs[ property ],
|
||||
dependentField = allProps[ property ].textValue;
|
||||
|
||||
if ( property === 'type' ) {
|
||||
value = propInput.getMenu().findSelectedItem() ? propInput.getMenu().findSelectedItem().getData() : 'unknown';
|
||||
if ( allProps[ property ].type === 'select' ) {
|
||||
var selected = propInput.getMenu().findSelectedItem();
|
||||
value = selected ? selected.getData() : allProps[ property ].default;
|
||||
this.toggleSuggestedValues( value );
|
||||
}
|
||||
|
||||
|
@ -1080,32 +1081,30 @@ Dialog.prototype.repopulateParamSelectWidget = function () {
|
|||
* @param {string} [lang] Language
|
||||
*/
|
||||
Dialog.prototype.changeParamPropertyInput = function ( paramKey, propName, value, lang ) {
|
||||
var languageProps = Model.static.getPropertiesWithLanguage(),
|
||||
allProps = Model.static.getAllProperties( true ),
|
||||
var allProps = Model.static.getAllProperties( true ),
|
||||
prop = allProps[ propName ],
|
||||
propInput = typeof this.propInputs[ propName ].getMenu === 'function' ?
|
||||
this.propInputs[ propName ].getMenu() : this.propInputs[ propName ];
|
||||
propInput = this.propInputs[ propName ];
|
||||
|
||||
lang = lang || this.language;
|
||||
|
||||
if ( prop.type === 'select' ) {
|
||||
value = value || prop.default;
|
||||
propInput.selectItem( propInput.findItemFromData( value ) );
|
||||
} else if ( prop.type === 'boolean' ) {
|
||||
switch ( prop.type ) {
|
||||
case 'select':
|
||||
propInput = propInput.getMenu();
|
||||
propInput.selectItem( propInput.findItemFromData( value || prop.default ) );
|
||||
break;
|
||||
case 'boolean':
|
||||
propInput.setSelected( !!value );
|
||||
} else if ( prop.type === 'array' ) {
|
||||
break;
|
||||
case 'array':
|
||||
value = value || [];
|
||||
propInput.setValue( value.map( function ( v ) {
|
||||
// TagMultiselectWidget accepts nothing but strings or objects with a .data property
|
||||
return v && v.data ? v : String( v );
|
||||
} ) );
|
||||
} else {
|
||||
if ( languageProps.indexOf( propName ) !== -1 ) {
|
||||
propInput.setValue( value ? value[ lang ] : '' );
|
||||
} else {
|
||||
value = value || '';
|
||||
propInput.setValue( value );
|
||||
break;
|
||||
default:
|
||||
if ( typeof value === 'object' ) {
|
||||
value = value[ lang || this.language ];
|
||||
}
|
||||
propInput.setValue( value || '' );
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1232,7 +1231,7 @@ Dialog.prototype.createParamDetails = function () {
|
|||
} );
|
||||
|
||||
// Event
|
||||
if ( property === 'type' ) {
|
||||
if ( propInput instanceof OO.ui.DropdownWidget ) {
|
||||
propInput.getMenu().connect( this, { choose: [ 'onParamPropertyInputChange', property ] } );
|
||||
} else {
|
||||
propInput.connect( this, { change: [ 'onParamPropertyInputChange', property ] } );
|
||||
|
@ -1301,8 +1300,6 @@ Dialog.prototype.getBodyHeight = function () {
|
|||
* @param {jQuery|string|OO.ui.HtmlSnippet|Function|null} [noticeMessageLabel] The message to display
|
||||
*/
|
||||
Dialog.prototype.toggleNoticeMessage = function ( type, isShowing, noticeMessageType, noticeMessageLabel ) {
|
||||
type = type || 'list';
|
||||
|
||||
// Hide all
|
||||
this.noticeMessage.toggle( false );
|
||||
this.paramEditNoticeMessage.toggle( false );
|
||||
|
|
Loading…
Reference in a new issue