2015-03-13 20:30:13 +00:00
|
|
|
/*
|
|
|
|
* VisualEditor user interface MWGeneralReferenceDialog class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dialog for inserting and editing MediaWiki references by type.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @abstract
|
|
|
|
* @extends ve.ui.NodeDialog
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
|
|
|
ve.ui.MWGeneralReferenceDialog = function VeUiMWGeneralReferenceDialog( config ) {
|
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWGeneralReferenceDialog.super.call( this, config );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWGeneralReferenceDialog, ve.ui.NodeDialog );
|
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.ui.MWGeneralReferenceDialog.static.name = 'generalreference';
|
|
|
|
|
|
|
|
ve.ui.MWGeneralReferenceDialog.static.title =
|
|
|
|
OO.ui.deferMsg( 'visualeditor-dialog-generalreference-title' );
|
|
|
|
|
|
|
|
ve.ui.MWGeneralReferenceDialog.static.icon = 'reference';
|
|
|
|
|
|
|
|
ve.ui.MWGeneralReferenceDialog.static.actions = [
|
|
|
|
{
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-action-cancel' ),
|
|
|
|
flags: 'safe'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWGeneralReferenceDialog.prototype.getBodyHeight = function () {
|
|
|
|
return 400;
|
|
|
|
};
|
|
|
|
|
2015-03-26 13:58:40 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWGeneralReferenceDialog.prototype.initialize = function () {
|
2015-05-05 15:10:32 +00:00
|
|
|
var sourceField;
|
2015-03-13 20:30:13 +00:00
|
|
|
|
|
|
|
// Parent method
|
2015-03-26 13:58:40 +00:00
|
|
|
ve.ui.MWGeneralReferenceDialog.super.prototype.initialize.apply( this, arguments );
|
2015-03-13 20:30:13 +00:00
|
|
|
|
|
|
|
this.panel = new OO.ui.PanelLayout( {
|
|
|
|
classes: [ 've-ui-mwGeneralReferenceDialog-panel' ],
|
|
|
|
padded: true,
|
|
|
|
expanded: false
|
|
|
|
} );
|
|
|
|
|
2015-05-05 15:10:32 +00:00
|
|
|
this.sourceSelect = new ve.ui.MWReferenceSourceSelectWidget( {
|
2015-03-26 13:58:40 +00:00
|
|
|
classes: [ 've-ui-mwGeneralReferenceDialog-select' ],
|
2015-05-05 15:10:32 +00:00
|
|
|
showExisting: true
|
2015-03-26 13:58:40 +00:00
|
|
|
} );
|
2015-05-05 15:10:32 +00:00
|
|
|
$( '<div>' ).addClass( 've-ui-mwGeneralReferenceDialog-spacer' ).insertBefore(
|
|
|
|
this.sourceSelect.getRefBasic().$element
|
|
|
|
);
|
2015-03-26 13:58:40 +00:00
|
|
|
sourceField = new OO.ui.FieldLayout( this.sourceSelect, {
|
|
|
|
align: 'top',
|
|
|
|
label: ve.msg( 'visualeditor-dialog-generalreference-intro' )
|
|
|
|
} );
|
|
|
|
|
2015-03-13 20:30:13 +00:00
|
|
|
// Events
|
2015-05-05 15:10:32 +00:00
|
|
|
this.sourceSelect.connect( this, { choose: 'onSourceSelectChoose' } );
|
2015-03-13 20:30:13 +00:00
|
|
|
|
2015-03-26 13:10:30 +00:00
|
|
|
// Assemble the panel
|
2015-05-05 15:10:32 +00:00
|
|
|
this.panel.$element.append( sourceField.$element );
|
2015-03-26 13:10:30 +00:00
|
|
|
|
2015-03-13 20:30:13 +00:00
|
|
|
this.$body
|
|
|
|
.addClass( 've-ui-mwGeneralReferenceDialog' )
|
|
|
|
.append( this.panel.$element );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWGeneralReferenceDialog.prototype.getSetupProcess = function ( data ) {
|
|
|
|
return ve.ui.MWGeneralReferenceDialog.super.prototype.getSetupProcess.call( this, data )
|
|
|
|
.next( function () {
|
2015-04-15 22:21:15 +00:00
|
|
|
if ( this.manager.surface.getInDialog() === 'reference' ) {
|
|
|
|
// Hide basic reference if we are already in the basic reference menu
|
2015-05-05 15:10:32 +00:00
|
|
|
this.sourceSelect.getRefBasic().setDisabled( true );
|
|
|
|
this.sourceSelect.getRefExisting().setDisabled( true );
|
2015-04-15 22:21:15 +00:00
|
|
|
} else {
|
|
|
|
// Check if the 'use existing' button should be enabled
|
2015-05-05 15:10:32 +00:00
|
|
|
this.sourceSelect.getRefExisting().setDisabled( !this.doReferencesExist() );
|
2015-04-15 22:21:15 +00:00
|
|
|
}
|
2015-03-13 20:30:13 +00:00
|
|
|
}, this );
|
|
|
|
};
|
|
|
|
|
2015-03-26 13:58:40 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWGeneralReferenceDialog.prototype.getTeardownProcess = function ( data ) {
|
|
|
|
return ve.ui.MWGeneralReferenceDialog.super.prototype.getTeardownProcess.call( this, data )
|
|
|
|
.next( function () {
|
2015-05-05 15:10:32 +00:00
|
|
|
// Clear selection
|
2015-03-26 13:58:40 +00:00
|
|
|
this.sourceSelect.selectItem();
|
|
|
|
}, this );
|
|
|
|
};
|
|
|
|
|
2015-03-13 20:30:13 +00:00
|
|
|
/**
|
|
|
|
* Check if there are any references in the current page.
|
2015-03-26 13:58:40 +00:00
|
|
|
*
|
2015-03-13 20:30:13 +00:00
|
|
|
* @return {boolean} There are references
|
|
|
|
*/
|
|
|
|
ve.ui.MWGeneralReferenceDialog.prototype.doReferencesExist = function () {
|
|
|
|
var groupName,
|
2015-03-26 13:38:39 +00:00
|
|
|
groups = this.getFragment().getDocument().getInternalList().getNodeGroups();
|
2015-03-13 20:30:13 +00:00
|
|
|
|
|
|
|
for ( groupName in groups ) {
|
|
|
|
if ( groupName.lastIndexOf( 'mwReference/' ) === 0 && groups[groupName].indexOrder.length ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2015-05-05 15:10:32 +00:00
|
|
|
* Handle source select widget choose events
|
2015-03-26 13:58:40 +00:00
|
|
|
*
|
|
|
|
* @param {OO.ui.OptionWidget} item Chosen item
|
2015-03-13 20:30:13 +00:00
|
|
|
*/
|
2015-05-05 15:10:32 +00:00
|
|
|
ve.ui.MWGeneralReferenceDialog.prototype.onSourceSelectChoose = function ( item ) {
|
2015-03-26 13:58:40 +00:00
|
|
|
var data = item.getData(),
|
|
|
|
// Closing the dialog may unset some properties, so cache the ones we want
|
|
|
|
fragment = this.getFragment(),
|
|
|
|
manager = this.getManager();
|
2015-03-13 20:30:13 +00:00
|
|
|
|
2015-03-26 13:58:40 +00:00
|
|
|
// Close this dialog then open the new dialog
|
2015-03-13 20:30:13 +00:00
|
|
|
this.close().then( function () {
|
2015-04-15 22:21:15 +00:00
|
|
|
manager.getSurface().execute( 'mwcite', 'open', data.windowName, $.extend( {
|
2015-03-13 20:30:13 +00:00
|
|
|
fragment: fragment
|
2015-03-26 13:58:40 +00:00
|
|
|
}, data.dialogData ) );
|
2015-03-13 20:30:13 +00:00
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.windowFactory.register( ve.ui.MWGeneralReferenceDialog );
|