mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-12-02 18:46:18 +00:00
Merge "Display extends warning message when editing a reference"
This commit is contained in:
commit
1f4175593b
|
@ -249,6 +249,7 @@ ve.ui.MWReferenceDialog.prototype.setReferenceForEditing = function ( ref ) {
|
||||||
|
|
||||||
this.setFormFieldsFromRef( this.referenceModel );
|
this.setFormFieldsFromRef( this.referenceModel );
|
||||||
this.updateReuseWarningFromRef( this.referenceModel );
|
this.updateReuseWarningFromRef( this.referenceModel );
|
||||||
|
this.updateExtendsWarningFromRef( this.referenceModel );
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
@ -284,6 +285,24 @@ ve.ui.MWReferenceDialog.prototype.updateReuseWarningFromRef = function ( ref ) {
|
||||||
.setLabel( mw.msg( 'cite-ve-dialog-reference-editing-reused-long', usages ) );
|
.setLabel( mw.msg( 'cite-ve-dialog-reference-editing-reused-long', usages ) );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @param {ve.dm.MWReferenceModel} ref
|
||||||
|
*/
|
||||||
|
ve.ui.MWReferenceDialog.prototype.updateExtendsWarningFromRef = function ( ref ) {
|
||||||
|
if ( ref.extendsRef ) {
|
||||||
|
const list = this.getFragment().getDocument().getInternalList();
|
||||||
|
const itemNode = list.getItemNode( list.keys.indexOf( ref.extendsRef ) );
|
||||||
|
const parentRefText = new ve.ui.MWPreviewElement( itemNode, { useView: true } ).$element.text();
|
||||||
|
// TODO extends i18n
|
||||||
|
this.extendsWarning.setLabel(
|
||||||
|
`This is an extension of another reference: ${ parentRefText }`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.extendsWarning.toggle( !!ref.extendsRef );
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
|
@ -304,8 +323,16 @@ ve.ui.MWReferenceDialog.prototype.initialize = function () {
|
||||||
classes: [ 've-ui-mwReferenceDialog-reuseWarning' ]
|
classes: [ 've-ui-mwReferenceDialog-reuseWarning' ]
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
// Icon message widget
|
||||||
|
this.extendsWarning = new OO.ui.MessageWidget( {
|
||||||
|
icon: 'alert',
|
||||||
|
inline: true,
|
||||||
|
classes: [ 've-ui-mwReferenceDialog-extendsWarning' ]
|
||||||
|
} );
|
||||||
|
|
||||||
const citeCommands = Object.keys( ve.init.target.getSurface().commandRegistry.registry )
|
const citeCommands = Object.keys( ve.init.target.getSurface().commandRegistry.registry )
|
||||||
.filter( ( command ) => command.indexOf( 'cite-' ) !== -1 );
|
.filter( ( command ) => command.indexOf( 'cite-' ) !== -1 );
|
||||||
|
|
||||||
this.referenceTarget = ve.init.target.createTargetWidget(
|
this.referenceTarget = ve.init.target.createTargetWidget(
|
||||||
{
|
{
|
||||||
includeCommands: this.constructor.static.includeCommands,
|
includeCommands: this.constructor.static.includeCommands,
|
||||||
|
@ -343,7 +370,7 @@ ve.ui.MWReferenceDialog.prototype.initialize = function () {
|
||||||
|
|
||||||
this.panels.addItems( [ this.editPanel, this.searchPanel ] );
|
this.panels.addItems( [ this.editPanel, this.searchPanel ] );
|
||||||
this.editPanel.$element.append(
|
this.editPanel.$element.append(
|
||||||
this.reuseWarning.$element, this.contentFieldset.$element, this.optionsFieldset.$element );
|
this.reuseWarning.$element, this.extendsWarning.$element, this.contentFieldset.$element, this.optionsFieldset.$element );
|
||||||
this.optionsFieldset.addItems( [ this.referenceGroupField ] );
|
this.optionsFieldset.addItems( [ this.referenceGroupField ] );
|
||||||
this.searchPanel.$element.append( this.search.$element );
|
this.searchPanel.$element.append( this.search.$element );
|
||||||
this.$body.append( this.panels.$element );
|
this.$body.append( this.panels.$element );
|
||||||
|
@ -402,7 +429,9 @@ ve.ui.MWReferenceDialog.prototype.getSetupProcess = function ( data ) {
|
||||||
.next( () => {
|
.next( () => {
|
||||||
this.panels.setItem( this.editPanel );
|
this.panels.setItem( this.editPanel );
|
||||||
if ( this.selectedNode instanceof ve.dm.MWReferenceNode ) {
|
if ( this.selectedNode instanceof ve.dm.MWReferenceNode ) {
|
||||||
this.setReferenceForEditing( ve.dm.MWReferenceModel.static.newFromReferenceNode( this.selectedNode ) );
|
this.setReferenceForEditing(
|
||||||
|
ve.dm.MWReferenceModel.static.newFromReferenceNode( this.selectedNode )
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
this.setReferenceForEditing( new ve.dm.MWReferenceModel( this.getFragment().getDocument() ) );
|
this.setReferenceForEditing( new ve.dm.MWReferenceModel( this.getFragment().getDocument() ) );
|
||||||
this.actions.setAbilities( { done: false, insert: false } );
|
this.actions.setAbilities( { done: false, insert: false } );
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
* @license MIT
|
* @license MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
.ve-ui-mwReferenceDialog-reuseWarning {
|
.ve-ui-mwReferenceDialog-reuseWarning,
|
||||||
|
.ve-ui-mwReferenceDialog-extendsWarning {
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
margin-bottom: 1em;
|
margin-bottom: 1em;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ QUnit.test( 'setReferenceForEditing', ( assert ) => {
|
||||||
|
|
||||||
dialog.referenceGroupInput = new ve.ui.MWReferenceGroupInputWidget( {} );
|
dialog.referenceGroupInput = new ve.ui.MWReferenceGroupInputWidget( {} );
|
||||||
dialog.reuseWarning = new OO.ui.MessageWidget();
|
dialog.reuseWarning = new OO.ui.MessageWidget();
|
||||||
|
dialog.extendsWarning = new OO.ui.MessageWidget();
|
||||||
|
|
||||||
// XXX: This is a regression test with a fragile setup. Please feel free to delete this test
|
// XXX: This is a regression test with a fragile setup. Please feel free to delete this test
|
||||||
// when you feel like it doesn't make sense to update it.
|
// when you feel like it doesn't make sense to update it.
|
||||||
|
|
Loading…
Reference in a new issue