2023-08-21 08:08:23 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-02-03 21:03:41 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface MediaWiki MWReferenceDialog 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
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dialog for editing MediaWiki references.
|
|
|
|
*
|
|
|
|
* @constructor
|
2024-02-28 08:57:24 +00:00
|
|
|
* @extends ve.ui.NodeDialog
|
2016-02-03 21:03:41 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceDialog = function VeUiMWReferenceDialog( config ) {
|
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWReferenceDialog.super.call( this, config );
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.referenceModel = null;
|
|
|
|
this.useExisting = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWReferenceDialog, ve.ui.NodeDialog );
|
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.ui.MWReferenceDialog.static.name = 'reference';
|
|
|
|
|
|
|
|
ve.ui.MWReferenceDialog.static.title =
|
|
|
|
OO.ui.deferMsg( 'cite-ve-dialog-reference-title' );
|
|
|
|
|
|
|
|
ve.ui.MWReferenceDialog.static.actions = [
|
|
|
|
{
|
2019-02-21 21:56:51 +00:00
|
|
|
action: 'done',
|
2016-02-03 21:03:41 +00:00
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-action-apply' ),
|
|
|
|
flags: [ 'progressive', 'primary' ],
|
|
|
|
modes: 'edit'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
action: 'insert',
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-action-insert' ),
|
2017-09-26 19:35:55 +00:00
|
|
|
flags: [ 'progressive', 'primary' ],
|
2016-02-03 21:03:41 +00:00
|
|
|
modes: 'insert'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-action-cancel' ),
|
2019-06-10 15:00:38 +00:00
|
|
|
flags: [ 'safe', 'close' ],
|
2019-02-15 14:53:54 +00:00
|
|
|
modes: [ 'readonly', 'insert', 'edit', 'insert-select' ]
|
2016-02-03 21:03:41 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
ve.ui.MWReferenceDialog.static.modelClasses = [ ve.dm.MWReferenceNode ];
|
|
|
|
|
|
|
|
ve.ui.MWReferenceDialog.static.includeCommands = null;
|
|
|
|
|
|
|
|
ve.ui.MWReferenceDialog.static.excludeCommands = [
|
|
|
|
// No formatting
|
|
|
|
'paragraph',
|
|
|
|
'heading1',
|
|
|
|
'heading2',
|
|
|
|
'heading3',
|
|
|
|
'heading4',
|
|
|
|
'heading5',
|
|
|
|
'heading6',
|
|
|
|
'preformatted',
|
|
|
|
'blockquote',
|
|
|
|
// No tables
|
|
|
|
'insertTable',
|
|
|
|
'deleteTable',
|
|
|
|
'mergeCells',
|
|
|
|
'tableCaption',
|
|
|
|
'tableCellHeader',
|
|
|
|
'tableCellData',
|
|
|
|
// No structure
|
|
|
|
'bullet',
|
|
|
|
'bulletWrapOnce',
|
|
|
|
'number',
|
|
|
|
'numberWrapOnce',
|
|
|
|
'indent',
|
|
|
|
'outdent',
|
|
|
|
// References
|
|
|
|
'reference',
|
|
|
|
'reference/existing',
|
2019-04-02 20:59:00 +00:00
|
|
|
'citoid',
|
2016-02-03 21:03:41 +00:00
|
|
|
'referencesList'
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the import rules for the surface widget in the dialog.
|
|
|
|
*
|
|
|
|
* @see ve.dm.ElementLinearData#sanitize
|
|
|
|
* @return {Object} Import rules
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceDialog.static.getImportRules = function () {
|
2023-08-21 08:08:23 +00:00
|
|
|
const rules = ve.copy( ve.init.target.constructor.static.importRules );
|
2016-02-03 21:03:41 +00:00
|
|
|
return ve.extendObject(
|
2019-04-09 17:56:58 +00:00
|
|
|
rules,
|
2016-02-03 21:03:41 +00:00
|
|
|
{
|
|
|
|
all: {
|
2019-04-09 17:56:58 +00:00
|
|
|
blacklist: ve.extendObject(
|
|
|
|
{
|
2016-02-03 21:03:41 +00:00
|
|
|
// Nested references are impossible
|
2019-04-09 17:56:58 +00:00
|
|
|
mwReference: true,
|
|
|
|
mwReferencesList: true,
|
2016-02-03 21:03:41 +00:00
|
|
|
// Lists and tables are actually possible in wikitext with a leading
|
|
|
|
// line break but we prevent creating these with the UI
|
2019-04-09 17:56:58 +00:00
|
|
|
list: true,
|
|
|
|
listItem: true,
|
|
|
|
definitionList: true,
|
|
|
|
definitionListItem: true,
|
|
|
|
table: true,
|
|
|
|
tableCaption: true,
|
|
|
|
tableSection: true,
|
|
|
|
tableRow: true,
|
|
|
|
tableCell: true,
|
|
|
|
mwTable: true,
|
|
|
|
mwTransclusionTableCell: true
|
|
|
|
},
|
|
|
|
ve.getProp( rules, 'all', 'blacklist' )
|
2016-02-03 21:03:41 +00:00
|
|
|
),
|
|
|
|
// Headings are not possible in wikitext without HTML
|
2019-04-09 17:56:58 +00:00
|
|
|
conversions: ve.extendObject(
|
|
|
|
{
|
|
|
|
mwHeading: 'paragraph'
|
|
|
|
},
|
|
|
|
ve.getProp( rules, 'all', 'conversions' )
|
|
|
|
)
|
2016-02-03 21:03:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether the reference document we're editing has any content.
|
|
|
|
*
|
|
|
|
* @return {boolean} Document has content
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceDialog.prototype.documentHasContent = function () {
|
|
|
|
// TODO: Check for other types of empty, e.g. only whitespace?
|
2019-11-28 18:49:16 +00:00
|
|
|
return this.referenceModel && this.referenceModel.getDocument().data.hasContent();
|
2016-02-03 21:03:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine whether any changes have been made (and haven't been undone).
|
|
|
|
*
|
2019-02-21 21:56:51 +00:00
|
|
|
* @return {boolean} Changes have been made
|
2016-02-03 21:03:41 +00:00
|
|
|
*/
|
2019-02-21 21:56:51 +00:00
|
|
|
ve.ui.MWReferenceDialog.prototype.isModified = function () {
|
2016-02-03 21:03:41 +00:00
|
|
|
return this.documentHasContent() &&
|
2016-11-20 22:55:14 +00:00
|
|
|
( this.referenceTarget.hasBeenModified() ||
|
2016-11-10 23:22:40 +00:00
|
|
|
this.referenceGroupInput.getValue() !== this.originalGroup );
|
2016-02-03 21:03:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-11-20 22:55:14 +00:00
|
|
|
* Handle reference target widget change events
|
2016-02-03 21:03:41 +00:00
|
|
|
*/
|
2016-11-20 22:55:14 +00:00
|
|
|
ve.ui.MWReferenceDialog.prototype.onTargetChange = function () {
|
2023-08-21 08:08:23 +00:00
|
|
|
const hasContent = this.documentHasContent();
|
2016-02-03 21:03:41 +00:00
|
|
|
|
|
|
|
this.actions.setAbilities( {
|
2019-02-21 21:56:51 +00:00
|
|
|
done: this.isModified(),
|
2019-01-03 19:42:44 +00:00
|
|
|
insert: hasContent
|
2016-02-03 21:03:41 +00:00
|
|
|
} );
|
2019-07-08 16:04:22 +00:00
|
|
|
|
|
|
|
if ( !this.trackedInputChange ) {
|
|
|
|
ve.track( 'activity.' + this.constructor.static.name, { action: 'input' } );
|
|
|
|
this.trackedInputChange = true;
|
|
|
|
}
|
2016-02-03 21:03:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle reference group input change events.
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceDialog.prototype.onReferenceGroupInputChange = function () {
|
|
|
|
this.actions.setAbilities( {
|
2019-02-21 21:56:51 +00:00
|
|
|
done: this.isModified()
|
2016-02-03 21:03:41 +00:00
|
|
|
} );
|
2019-07-08 16:04:22 +00:00
|
|
|
|
|
|
|
if ( !this.trackedInputChange ) {
|
|
|
|
ve.track( 'activity.' + this.constructor.static.name, { action: 'input' } );
|
|
|
|
this.trackedInputChange = true;
|
|
|
|
}
|
2016-02-03 21:03:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle search results choose events.
|
|
|
|
*
|
|
|
|
* @param {ve.ui.MWReferenceResultWidget} item Chosen item
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceDialog.prototype.onSearchResultsChoose = function ( item ) {
|
2024-02-16 03:54:34 +00:00
|
|
|
const ref = item.getData();
|
2016-02-03 21:03:41 +00:00
|
|
|
|
|
|
|
if ( this.selectedNode instanceof ve.dm.MWReferenceNode ) {
|
|
|
|
this.getFragment().removeContent();
|
|
|
|
this.selectedNode = null;
|
|
|
|
}
|
2024-06-06 12:54:05 +00:00
|
|
|
|
|
|
|
this.setFormFieldsFromRef( ref );
|
|
|
|
this.referenceModel = ref;
|
2016-02-03 21:03:41 +00:00
|
|
|
this.executeAction( 'insert' );
|
2019-07-08 16:04:22 +00:00
|
|
|
|
|
|
|
ve.track( 'activity.' + this.constructor.static.name, { action: 'reuse-choose' } );
|
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.MWReferenceDialog.prototype.getReadyProcess = function ( data ) {
|
|
|
|
return ve.ui.MWReferenceDialog.super.prototype.getReadyProcess.call( this, data )
|
2024-05-31 14:27:11 +00:00
|
|
|
.next( () => {
|
2016-02-03 21:03:41 +00:00
|
|
|
if ( this.useExisting ) {
|
|
|
|
this.search.getQuery().focus().select();
|
|
|
|
} else {
|
|
|
|
this.referenceTarget.focus();
|
|
|
|
}
|
2024-05-31 14:27:11 +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.MWReferenceDialog.prototype.getBodyHeight = function () {
|
|
|
|
// Clamp value to between 300 and 400px height, preferring the actual height if available
|
|
|
|
return Math.min(
|
|
|
|
400,
|
|
|
|
Math.max(
|
|
|
|
300,
|
|
|
|
Math.ceil( this.panels.getCurrentItem().$element[ 0 ].scrollHeight )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Work on a specific reference.
|
|
|
|
*
|
2024-06-06 12:09:33 +00:00
|
|
|
* @param {ve.dm.MWReferenceModel} ref
|
2021-11-03 12:28:17 +00:00
|
|
|
* @return {ve.ui.MWReferenceDialog}
|
2016-02-03 21:03:41 +00:00
|
|
|
* @chainable
|
|
|
|
*/
|
2024-06-06 12:09:33 +00:00
|
|
|
ve.ui.MWReferenceDialog.prototype.setReferenceForEditing = function ( ref ) {
|
|
|
|
this.referenceModel = ref;
|
2016-02-03 21:03:41 +00:00
|
|
|
|
2024-06-06 12:09:33 +00:00
|
|
|
this.setFormFieldsFromRef( this.referenceModel );
|
|
|
|
this.updateReuseWarningFromRef( this.referenceModel );
|
2016-02-03 21:03:41 +00:00
|
|
|
|
2024-06-06 12:09:33 +00:00
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @param {ve.dm.MWReferenceModel} ref
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceDialog.prototype.setFormFieldsFromRef = function ( ref ) {
|
|
|
|
this.referenceTarget.setDocument( ref.getDocument() );
|
|
|
|
|
|
|
|
this.originalGroup = ref.getGroup();
|
2016-04-26 16:08:14 +00:00
|
|
|
// Set the group input while it's disabled, so this doesn't pop up the group-picker menu
|
|
|
|
this.referenceGroupInput.setDisabled( true );
|
2016-11-10 23:22:40 +00:00
|
|
|
this.referenceGroupInput.setValue( this.originalGroup );
|
2016-04-26 16:08:14 +00:00
|
|
|
this.referenceGroupInput.setDisabled( false );
|
2024-06-06 12:09:33 +00:00
|
|
|
};
|
2016-02-03 21:03:41 +00:00
|
|
|
|
2024-06-06 12:09:33 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @param {ve.dm.MWReferenceModel} ref
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceDialog.prototype.updateReuseWarningFromRef = function ( ref ) {
|
2023-08-21 08:08:23 +00:00
|
|
|
const group = this.getFragment().getDocument().getInternalList()
|
2024-06-06 12:09:33 +00:00
|
|
|
.getNodeGroup( ref.getListGroup() );
|
|
|
|
const nodes = ve.getProp( group, 'keyedNodes', ref.getListKey() );
|
|
|
|
const usages = nodes ? nodes.filter(
|
|
|
|
( node ) => !node.findParent( ve.dm.MWReferencesListNode )
|
|
|
|
).length : 0;
|
|
|
|
|
|
|
|
this.reuseWarning
|
|
|
|
.toggle( usages > 1 )
|
2023-06-05 13:26:16 +00:00
|
|
|
.setLabel( mw.msg( 'cite-ve-dialog-reference-editing-reused-long', usages ) );
|
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.MWReferenceDialog.prototype.initialize = function () {
|
|
|
|
// Parent method
|
|
|
|
ve.ui.MWReferenceDialog.super.prototype.initialize.call( this );
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.panels = new OO.ui.StackLayout();
|
|
|
|
this.editPanel = new OO.ui.PanelLayout( {
|
|
|
|
scrollable: true, padded: true
|
|
|
|
} );
|
|
|
|
this.searchPanel = new OO.ui.PanelLayout();
|
|
|
|
|
2023-06-05 13:26:16 +00:00
|
|
|
this.reuseWarning = new OO.ui.MessageWidget( {
|
|
|
|
inline: true,
|
|
|
|
icon: 'alert',
|
2023-06-29 15:38:30 +00:00
|
|
|
classes: [ 've-ui-mwReferenceDialog-reuseWarning' ]
|
2023-06-05 13:26:16 +00:00
|
|
|
} );
|
2016-02-03 21:03:41 +00:00
|
|
|
|
2024-01-30 11:18:52 +00:00
|
|
|
const citeCommands = Object.keys( ve.init.target.getSurface().commandRegistry.registry )
|
|
|
|
.filter( ( command ) => command.indexOf( 'cite-' ) !== -1 );
|
2016-11-20 22:55:14 +00:00
|
|
|
this.referenceTarget = ve.init.target.createTargetWidget(
|
|
|
|
{
|
|
|
|
includeCommands: this.constructor.static.includeCommands,
|
|
|
|
excludeCommands: this.constructor.static.excludeCommands.concat( citeCommands ),
|
|
|
|
importRules: this.constructor.static.getImportRules(),
|
2017-05-24 16:12:54 +00:00
|
|
|
inDialog: this.constructor.static.name,
|
|
|
|
placeholder: ve.msg( 'cite-ve-dialog-reference-placeholder' )
|
2016-11-20 22:55:14 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2016-02-03 21:03:41 +00:00
|
|
|
this.contentFieldset = new OO.ui.FieldsetLayout();
|
|
|
|
this.optionsFieldset = new OO.ui.FieldsetLayout( {
|
|
|
|
label: ve.msg( 'cite-ve-dialog-reference-options-section' ),
|
2018-09-08 02:59:40 +00:00
|
|
|
icon: 'settings'
|
2016-02-03 21:03:41 +00:00
|
|
|
} );
|
2016-11-20 22:55:14 +00:00
|
|
|
this.contentFieldset.$element.append( this.referenceTarget.$element );
|
|
|
|
|
2016-02-03 21:03:41 +00:00
|
|
|
this.referenceGroupInput = new ve.ui.MWReferenceGroupInputWidget( {
|
|
|
|
$overlay: this.$overlay,
|
|
|
|
emptyGroupName: ve.msg( 'cite-ve-dialog-reference-options-group-placeholder' )
|
|
|
|
} );
|
2016-11-10 23:22:40 +00:00
|
|
|
this.referenceGroupInput.connect( this, { change: 'onReferenceGroupInputChange' } );
|
2016-02-03 21:03:41 +00:00
|
|
|
this.referenceGroupField = new OO.ui.FieldLayout( this.referenceGroupInput, {
|
|
|
|
align: 'top',
|
|
|
|
label: ve.msg( 'cite-ve-dialog-reference-options-group-label' )
|
|
|
|
} );
|
|
|
|
this.search = new ve.ui.MWReferenceSearchWidget();
|
|
|
|
|
|
|
|
// Events
|
|
|
|
this.search.getResults().connect( this, { choose: 'onSearchResultsChoose' } );
|
2016-11-20 22:55:14 +00:00
|
|
|
this.referenceTarget.connect( this, { change: 'onTargetChange' } );
|
2016-02-03 21:03:41 +00:00
|
|
|
|
|
|
|
// Initialization
|
2024-03-15 18:36:42 +00:00
|
|
|
this.$content.addClass( 've-ui-mwReferenceDialog' );
|
|
|
|
|
2016-02-03 21:03:41 +00:00
|
|
|
this.panels.addItems( [ this.editPanel, this.searchPanel ] );
|
2024-01-30 11:18:52 +00:00
|
|
|
this.editPanel.$element.append(
|
|
|
|
this.reuseWarning.$element, this.contentFieldset.$element, this.optionsFieldset.$element );
|
2016-02-03 21:03:41 +00:00
|
|
|
this.optionsFieldset.addItems( [ this.referenceGroupField ] );
|
|
|
|
this.searchPanel.$element.append( this.search.$element );
|
|
|
|
this.$body.append( this.panels.$element );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Switches dialog to use existing reference mode.
|
|
|
|
*/
|
2019-01-03 19:42:44 +00:00
|
|
|
ve.ui.MWReferenceDialog.prototype.useExistingReference = function () {
|
|
|
|
this.actions.setMode( 'insert-select' );
|
2016-02-03 21:03:41 +00:00
|
|
|
this.search.buildIndex();
|
|
|
|
this.panels.setItem( this.searchPanel );
|
|
|
|
this.search.getQuery().focus().select();
|
2024-04-22 09:34:46 +00:00
|
|
|
|
|
|
|
// https://phabricator.wikimedia.org/T362347
|
|
|
|
ve.track( 'activity.' + this.constructor.static.name, { action: 'dialog-open-reuse' } );
|
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.MWReferenceDialog.prototype.getActionProcess = function ( action ) {
|
2019-02-21 21:56:51 +00:00
|
|
|
if ( action === 'insert' || action === 'done' ) {
|
2024-05-31 14:27:11 +00:00
|
|
|
return new OO.ui.Process( () => {
|
2023-08-21 08:08:23 +00:00
|
|
|
const surfaceModel = this.getFragment().getSurface();
|
2016-02-03 21:03:41 +00:00
|
|
|
|
2016-11-10 23:22:40 +00:00
|
|
|
this.referenceModel.setGroup( this.referenceGroupInput.getValue() );
|
2016-02-03 21:03:41 +00:00
|
|
|
|
|
|
|
// Insert reference (will auto-create an internal item if needed)
|
|
|
|
if ( !( this.selectedNode instanceof ve.dm.MWReferenceNode ) ) {
|
|
|
|
if ( !this.referenceModel.findInternalItem( surfaceModel ) ) {
|
|
|
|
this.referenceModel.insertInternalItem( surfaceModel );
|
|
|
|
}
|
|
|
|
// Collapse returns a new fragment, so update this.fragment
|
|
|
|
this.fragment = this.getFragment().collapseToEnd();
|
|
|
|
this.referenceModel.insertReferenceNode( this.getFragment() );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update internal item
|
|
|
|
this.referenceModel.updateInternalItem( surfaceModel );
|
|
|
|
|
|
|
|
this.close( { action: action } );
|
2024-05-31 14:27:11 +00:00
|
|
|
} );
|
2016-02-03 21:03:41 +00:00
|
|
|
}
|
|
|
|
return ve.ui.MWReferenceDialog.super.prototype.getActionProcess.call( this, action );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2024-02-28 08:57:24 +00:00
|
|
|
* @override
|
2016-02-03 21:03:41 +00:00
|
|
|
* @param {Object} [data] Setup data
|
|
|
|
* @param {boolean} [data.useExistingReference] Open the dialog in "use existing reference" mode
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceDialog.prototype.getSetupProcess = function ( data ) {
|
|
|
|
data = data || {};
|
|
|
|
return ve.ui.MWReferenceDialog.super.prototype.getSetupProcess.call( this, data )
|
2024-05-31 14:27:11 +00:00
|
|
|
.next( () => {
|
2016-02-03 21:03:41 +00:00
|
|
|
this.panels.setItem( this.editPanel );
|
|
|
|
if ( this.selectedNode instanceof ve.dm.MWReferenceNode ) {
|
2024-06-06 12:09:33 +00:00
|
|
|
this.setReferenceForEditing( ve.dm.MWReferenceModel.static.newFromReferenceNode( this.selectedNode ) );
|
2016-02-03 21:03:41 +00:00
|
|
|
} else {
|
2024-06-06 12:09:33 +00:00
|
|
|
this.setReferenceForEditing( new ve.dm.MWReferenceModel( this.getFragment().getDocument() ) );
|
2019-02-21 21:56:51 +00:00
|
|
|
this.actions.setAbilities( { done: false, insert: false } );
|
2016-02-03 21:03:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.search.setInternalList( this.getFragment().getDocument().getInternalList() );
|
2019-02-15 14:53:54 +00:00
|
|
|
|
2023-08-21 08:08:23 +00:00
|
|
|
const isReadOnly = this.isReadOnly();
|
2019-02-15 14:53:54 +00:00
|
|
|
this.referenceTarget.setReadOnly( isReadOnly );
|
|
|
|
this.referenceGroupInput.setReadOnly( isReadOnly );
|
2016-02-03 21:03:41 +00:00
|
|
|
|
|
|
|
if ( data.useExisting ) {
|
2019-01-03 19:42:44 +00:00
|
|
|
this.useExistingReference();
|
2016-02-03 21:03:41 +00:00
|
|
|
}
|
|
|
|
this.useExisting = !!data.useExisting;
|
|
|
|
this.actions.setAbilities( {
|
2019-02-21 21:56:51 +00:00
|
|
|
done: false
|
2016-02-03 21:03:41 +00:00
|
|
|
} );
|
|
|
|
|
2024-01-30 11:18:52 +00:00
|
|
|
this.referenceGroupInput.populateMenu(
|
|
|
|
this.getFragment().getDocument().getInternalList() );
|
2019-07-08 16:04:22 +00:00
|
|
|
|
|
|
|
this.trackedInputChange = false;
|
2024-05-31 14:27:11 +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.MWReferenceDialog.prototype.getTeardownProcess = function ( data ) {
|
|
|
|
return ve.ui.MWReferenceDialog.super.prototype.getTeardownProcess.call( this, data )
|
2024-05-31 14:27:11 +00:00
|
|
|
.first( () => {
|
2016-02-03 21:03:41 +00:00
|
|
|
this.referenceTarget.getSurface().getModel().disconnect( this );
|
|
|
|
this.search.getQuery().setValue( '' );
|
2016-11-20 22:55:14 +00:00
|
|
|
this.referenceTarget.clear();
|
2016-02-03 21:03:41 +00:00
|
|
|
this.referenceModel = null;
|
2024-05-31 14:27:11 +00:00
|
|
|
} );
|
2016-02-03 21:03:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.windowFactory.register( ve.ui.MWReferenceDialog );
|