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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* global mw */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 () {
|
|
|
|
var sourceField, refBasic,
|
|
|
|
tools, i, len, item,
|
|
|
|
items = [],
|
2015-03-13 20:30:13 +00:00
|
|
|
limit = ve.init.mw.Target.static.citationToolsLimit;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Attach cite dialog tools
|
|
|
|
try {
|
|
|
|
// Must use mw.message to avoid JSON being parsed as Wikitext
|
|
|
|
tools = JSON.parse( mw.message( 'visualeditor-cite-tool-definition.json' ).plain() );
|
|
|
|
} catch ( e ) { }
|
|
|
|
|
|
|
|
// Go over available tools
|
|
|
|
if ( Array.isArray( tools ) ) {
|
|
|
|
for ( i = 0, len = Math.min( limit, tools.length ); i < len; i++ ) {
|
|
|
|
item = tools[i];
|
2015-03-26 13:58:40 +00:00
|
|
|
items.push( new OO.ui.DecoratedOptionWidget( {
|
2015-03-13 20:30:13 +00:00
|
|
|
icon: item.icon,
|
|
|
|
label: item.title,
|
2015-03-26 13:58:40 +00:00
|
|
|
data: {
|
|
|
|
windowName: 'transclusion',
|
|
|
|
dialogData: { template: item.template }
|
|
|
|
}
|
|
|
|
} ) );
|
2015-03-13 20:30:13 +00:00
|
|
|
}
|
|
|
|
}
|
2015-03-26 13:58:40 +00:00
|
|
|
// Basic tools
|
|
|
|
refBasic = new OO.ui.DecoratedOptionWidget( {
|
|
|
|
icon: 'reference',
|
|
|
|
label: ve.msg( 'visualeditor-dialogbutton-reference-full-label' ),
|
|
|
|
data: { windowName: 'reference' }
|
|
|
|
} );
|
|
|
|
this.refExisting = new OO.ui.DecoratedOptionWidget( {
|
|
|
|
icon: 'reference-existing',
|
|
|
|
label: ve.msg( 'visualeditor-dialog-reference-useexisting-full-label' ),
|
|
|
|
data: {
|
|
|
|
windowName: 'reference',
|
|
|
|
dialogData: { useExisting: true }
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
this.sourceSelect = new OO.ui.SelectWidget( {
|
|
|
|
classes: [ 've-ui-mwGeneralReferenceDialog-select' ],
|
|
|
|
items: items
|
|
|
|
} );
|
|
|
|
sourceField = new OO.ui.FieldLayout( this.sourceSelect, {
|
|
|
|
classes: [ 've-ui-mwGeneralReferenceDialog-source-field' ],
|
|
|
|
align: 'top',
|
|
|
|
label: ve.msg( 'visualeditor-dialog-generalreference-intro' )
|
|
|
|
} );
|
|
|
|
|
|
|
|
this.basicSelect = new OO.ui.SelectWidget( {
|
|
|
|
classes: [ 've-ui-mwGeneralReferenceDialog-select' ],
|
|
|
|
items: [ refBasic, this.refExisting ]
|
|
|
|
} );
|
2015-03-13 20:30:13 +00:00
|
|
|
|
|
|
|
// Events
|
2015-03-26 13:58:40 +00:00
|
|
|
this.sourceSelect.connect( this, { choose: 'onSelectChoose' } );
|
|
|
|
this.basicSelect.connect( this, { choose: 'onSelectChoose' } );
|
2015-03-13 20:30:13 +00:00
|
|
|
|
2015-03-26 13:10:30 +00:00
|
|
|
// Assemble the panel
|
|
|
|
this.panel.$element.append(
|
2015-03-26 13:58:40 +00:00
|
|
|
sourceField.$element,
|
|
|
|
this.basicSelect.$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 () {
|
|
|
|
// Check if the 'use existing' button should be enabled
|
|
|
|
this.refExisting.setDisabled( !this.doReferencesExist() );
|
|
|
|
}, 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 () {
|
|
|
|
// Clear selections
|
|
|
|
this.sourceSelect.selectItem();
|
|
|
|
this.basicSelect.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-03-26 13:58:40 +00:00
|
|
|
* Handle select widget choose events
|
|
|
|
*
|
|
|
|
* @param {OO.ui.OptionWidget} item Chosen item
|
2015-03-13 20:30:13 +00:00
|
|
|
*/
|
2015-03-26 13:58:40 +00:00
|
|
|
ve.ui.MWGeneralReferenceDialog.prototype.onSelectChoose = function ( item ) {
|
|
|
|
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-03-26 13:58:40 +00:00
|
|
|
manager.openWindow( 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 );
|