mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-11 16:49:26 +00:00
Merge "[refactor] groupInput takes narrower parameters"
This commit is contained in:
commit
179e12f4ec
|
@ -200,7 +200,8 @@ ve.ui.MWReferenceEditPanel.static.getImportRules = function () {
|
|||
*/
|
||||
ve.ui.MWReferenceEditPanel.prototype.setInternalList = function ( internalList ) {
|
||||
this.internalList = internalList;
|
||||
this.referenceGroupInput.populateMenu( this.internalList );
|
||||
const docRefs = ve.dm.MWDocumentReferences.static.refsForDoc( internalList.getDocument() );
|
||||
this.referenceGroupInput.populateMenu( docRefs.getAllGroupNames() );
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -38,18 +38,18 @@ OO.inheritClass( ve.ui.MWReferenceGroupInputWidget, OO.ui.ComboBoxInputWidget );
|
|||
/**
|
||||
* Populate the reference group menu
|
||||
*
|
||||
* @param {ve.dm.InternalList} internalList Internal list with which to populate the menu
|
||||
* @param {string[]} groups Group names
|
||||
*/
|
||||
ve.ui.MWReferenceGroupInputWidget.prototype.populateMenu = function ( internalList ) {
|
||||
ve.ui.MWReferenceGroupInputWidget.prototype.populateMenu = function ( groups ) {
|
||||
const items = [ new OO.ui.MenuOptionWidget( {
|
||||
data: '',
|
||||
label: this.emptyGroupName
|
||||
} ) ];
|
||||
for ( const groupName in internalList.getNodeGroups() ) {
|
||||
groups.forEach( ( groupName ) => {
|
||||
const match = groupName.match( /^mwReference\/(.+)/ );
|
||||
if ( match ) {
|
||||
items.push( new OO.ui.MenuOptionWidget( { data: match[ 1 ], label: match[ 1 ] } ) );
|
||||
}
|
||||
}
|
||||
} );
|
||||
this.menu.clearItems().addItems( items ).toggle( false );
|
||||
};
|
||||
|
|
|
@ -168,7 +168,8 @@ ve.ui.MWReferencesListDialog.prototype.getSetupProcess = function ( data ) {
|
|||
}
|
||||
|
||||
this.groupInput.setValue( this.selectedNode.getAttribute( 'refGroup' ) );
|
||||
this.groupInput.populateMenu( this.getFragment().getDocument().getInternalList() );
|
||||
const docRefs = ve.dm.MWDocumentReferences.static.refsForDoc( this.getFragment().getDocument() );
|
||||
this.groupInput.populateMenu( docRefs.getAllGroupNames() );
|
||||
|
||||
this.responsiveCheckbox.setSelected( this.selectedNode.getAttribute( 'isResponsive' ) );
|
||||
|
||||
|
|
|
@ -11,12 +11,10 @@ QUnit.test( 'Constructor', ( assert ) => {
|
|||
} );
|
||||
|
||||
QUnit.test( 'populateMenu', ( assert ) => {
|
||||
const doc = ve.dm.citeExample.createExampleDocument( 'references' );
|
||||
|
||||
const widget = new ve.ui.MWReferenceGroupInputWidget( {
|
||||
emptyGroupName: 'empty'
|
||||
} );
|
||||
widget.populateMenu( doc.getInternalList() );
|
||||
widget.populateMenu( [ 'mwReference/', 'mwReference/foo' ] );
|
||||
|
||||
assert.strictEqual( widget.getMenu().getItemCount(), 2 );
|
||||
|
||||
|
|
Loading…
Reference in a new issue