2023-08-21 08:08:23 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-02-03 21:03:41 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor MWReferenceContextItem class.
|
|
|
|
*
|
2018-01-03 01:05:45 +00:00
|
|
|
* @copyright 2011-2018 VisualEditor Team's Cite sub-team and others; see AUTHORS.txt
|
2017-12-29 12:12:35 +00:00
|
|
|
* @license MIT
|
2016-02-03 21:03:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Context item for a MWReference.
|
|
|
|
*
|
|
|
|
* @constructor
|
2024-02-28 08:57:24 +00:00
|
|
|
* @extends ve.ui.LinearContextItem
|
2023-07-10 13:33:24 +00:00
|
|
|
* @param {ve.ui.LinearContext} context Context the item is in
|
|
|
|
* @param {ve.dm.Model} model Model the item is related to
|
2021-12-29 17:22:08 +00:00
|
|
|
* @param {Object} [config]
|
2016-02-03 21:03:41 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceContextItem = function VeUiMWReferenceContextItem() {
|
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWReferenceContextItem.super.apply( this, arguments );
|
|
|
|
this.view = null;
|
2024-09-03 10:44:28 +00:00
|
|
|
/** @member {ve.dm.MWGroupReferences} */
|
|
|
|
this.groupRefs = null;
|
2016-02-03 21:03:41 +00:00
|
|
|
// Initialization
|
|
|
|
this.$element.addClass( 've-ui-mwReferenceContextItem' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWReferenceContextItem, ve.ui.LinearContextItem );
|
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.ui.MWReferenceContextItem.static.name = 'reference';
|
|
|
|
|
|
|
|
ve.ui.MWReferenceContextItem.static.icon = 'reference';
|
|
|
|
|
|
|
|
ve.ui.MWReferenceContextItem.static.label = OO.ui.deferMsg( 'cite-ve-dialogbutton-reference-title' );
|
|
|
|
|
|
|
|
ve.ui.MWReferenceContextItem.static.modelClasses = [ ve.dm.MWReferenceNode ];
|
|
|
|
|
|
|
|
ve.ui.MWReferenceContextItem.static.commandName = 'reference';
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a DOM rendering of the reference.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @return {jQuery} DOM rendering of reference
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceContextItem.prototype.getRendering = function () {
|
2023-08-21 08:08:23 +00:00
|
|
|
const refNode = this.getReferenceNode();
|
2016-02-03 21:03:41 +00:00
|
|
|
if ( refNode ) {
|
|
|
|
this.view = new ve.ui.MWPreviewElement( refNode );
|
|
|
|
|
2024-01-30 11:18:52 +00:00
|
|
|
// The $element property may be rendered into asynchronously, update the
|
|
|
|
// context's size when the rendering is complete if that's the case
|
2016-02-03 21:03:41 +00:00
|
|
|
this.view.once( 'render', this.context.updateDimensions.bind( this.context ) );
|
|
|
|
|
|
|
|
return this.view.$element;
|
|
|
|
} else {
|
|
|
|
return $( '<div>' )
|
|
|
|
.addClass( 've-ui-mwReferenceContextItem-muted' )
|
|
|
|
.text( ve.msg( 'cite-ve-referenceslist-missingref' ) );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-01-03 20:06:12 +00:00
|
|
|
/**
|
|
|
|
* Get a DOM rendering of a warning if this reference is reused.
|
|
|
|
*
|
|
|
|
* @private
|
2024-05-31 14:27:11 +00:00
|
|
|
* @return {jQuery|undefined}
|
2019-01-03 20:06:12 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceContextItem.prototype.getReuseWarning = function () {
|
2024-09-05 11:44:11 +00:00
|
|
|
const listKey = this.model.getAttribute( 'listKey' );
|
|
|
|
const totalUsageCount = this.groupRefs.getTotalUsageCount( listKey );
|
|
|
|
|
|
|
|
if ( totalUsageCount > 1 ) {
|
2019-01-03 20:06:12 +00:00
|
|
|
return $( '<div>' )
|
|
|
|
.addClass( 've-ui-mwReferenceContextItem-muted' )
|
2024-09-27 20:28:08 +00:00
|
|
|
.text( ve.msg( 'cite-ve-dialog-reference-editing-reused', totalUsageCount ) );
|
2019-01-03 20:06:12 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-05-04 16:56:41 +00:00
|
|
|
/**
|
|
|
|
* Get a DOM rendering of a warning if this reference is an extension.
|
|
|
|
*
|
|
|
|
* @private
|
2024-05-31 14:27:11 +00:00
|
|
|
* @return {jQuery|undefined}
|
2023-05-04 16:56:41 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceContextItem.prototype.getExtendsWarning = function () {
|
2024-05-02 15:09:16 +00:00
|
|
|
if ( this.model.getAttribute( 'extendsRef' ) ) {
|
2023-05-04 16:56:41 +00:00
|
|
|
return $( '<div>' )
|
2024-10-01 11:58:33 +00:00
|
|
|
.addClass( [
|
|
|
|
've-ui-mwReferenceContextItem-muted',
|
|
|
|
've-ui-mwReferenceContextItemSubNote'
|
|
|
|
] )
|
2024-09-27 20:28:08 +00:00
|
|
|
.text( ve.msg( 'cite-ve-dialog-reference-contextitem-extends' ) );
|
2023-05-04 16:56:41 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-02-03 21:03:41 +00:00
|
|
|
/**
|
|
|
|
* Get the reference node in the containing document (not the internal list document)
|
|
|
|
*
|
2016-05-24 12:49:22 +00:00
|
|
|
* @return {ve.dm.InternalItemNode|null} Reference item node
|
2016-02-03 21:03:41 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceContextItem.prototype.getReferenceNode = function () {
|
|
|
|
if ( !this.model.isEditable() ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if ( !this.referenceNode ) {
|
2024-09-03 10:44:28 +00:00
|
|
|
this.referenceNode = this.groupRefs.getInternalModelNode( this.model.getAttribute( 'listKey' ) );
|
2016-02-03 21:03:41 +00:00
|
|
|
}
|
|
|
|
return this.referenceNode;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2024-02-28 08:57:24 +00:00
|
|
|
* @override
|
2016-02-03 21:03:41 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceContextItem.prototype.getDescription = function () {
|
|
|
|
return this.model.isEditable() ? this.getRendering().text() : ve.msg( 'cite-ve-referenceslist-missingref' );
|
|
|
|
};
|
|
|
|
|
2023-06-09 15:55:00 +00:00
|
|
|
/**
|
|
|
|
* Get the text of the parent reference.
|
|
|
|
*
|
|
|
|
* @private
|
2024-06-14 12:32:21 +00:00
|
|
|
* @return {jQuery|null}
|
2023-06-09 15:55:00 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceContextItem.prototype.getParentRef = function () {
|
2024-05-02 15:09:16 +00:00
|
|
|
const extendsRef = this.model.getAttribute( 'extendsRef' );
|
|
|
|
if ( !extendsRef ) {
|
2023-06-09 15:55:00 +00:00
|
|
|
return null;
|
|
|
|
}
|
2024-09-03 10:44:28 +00:00
|
|
|
const parentNode = this.groupRefs.getInternalModelNode( extendsRef );
|
2024-08-26 08:51:15 +00:00
|
|
|
return parentNode ? new ve.ui.MWPreviewElement( parentNode, { useView: true } ).$element :
|
2024-08-21 14:57:27 +00:00
|
|
|
$( '<div>' )
|
|
|
|
.addClass( 've-ui-mwReferenceContextItem-muted' )
|
|
|
|
.text( ve.msg( 'cite-ve-dialog-reference-missing-parent-ref' ) );
|
2023-06-09 15:55:00 +00:00
|
|
|
};
|
|
|
|
|
2024-09-03 10:44:28 +00:00
|
|
|
/**
|
|
|
|
* @override
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceContextItem.prototype.setup = function () {
|
|
|
|
this.groupRefs = ve.dm.MWDocumentReferences.static.refsForDoc( this.getFragment().getDocument() )
|
|
|
|
.getGroupRefs( this.model.getAttribute( 'listGroup' ) );
|
|
|
|
|
|
|
|
// Parent method
|
|
|
|
return ve.ui.MWReferenceContextItem.super.prototype.setup.apply( this, arguments );
|
|
|
|
};
|
|
|
|
|
2016-02-03 21:03:41 +00:00
|
|
|
/**
|
2024-02-28 08:57:24 +00:00
|
|
|
* @override
|
2016-02-03 21:03:41 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceContextItem.prototype.renderBody = function () {
|
2024-01-30 11:18:52 +00:00
|
|
|
this.$body.empty().append(
|
|
|
|
this.getParentRef(),
|
2024-10-01 11:58:33 +00:00
|
|
|
this.getExtendsWarning(),
|
2024-01-30 11:18:52 +00:00
|
|
|
this.getRendering(),
|
2024-10-01 11:58:33 +00:00
|
|
|
this.getReuseWarning()
|
2024-01-30 11:18:52 +00:00
|
|
|
);
|
2016-02-03 21:03:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2024-02-28 08:57:24 +00:00
|
|
|
* @override
|
2016-02-03 21:03:41 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceContextItem.prototype.teardown = function () {
|
|
|
|
if ( this.view ) {
|
|
|
|
this.view.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call parent
|
|
|
|
ve.ui.MWReferenceContextItem.super.prototype.teardown.call( this );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.contextItemFactory.register( ve.ui.MWReferenceContextItem );
|