2016-02-03 21:03:41 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor user interface MWReferencesListDialog 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 lists.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.ui.NodeDialog
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferencesListDialog = function VeUiMWReferencesListDialog( config ) {
|
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWReferencesListDialog.super.call( this, config );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWReferencesListDialog, ve.ui.NodeDialog );
|
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.ui.MWReferencesListDialog.static.name = 'referencesList';
|
|
|
|
|
|
|
|
ve.ui.MWReferencesListDialog.static.title =
|
|
|
|
OO.ui.deferMsg( 'cite-ve-dialog-referenceslist-title' );
|
|
|
|
|
|
|
|
ve.ui.MWReferencesListDialog.static.modelClasses = [ ve.dm.MWReferencesListNode ];
|
|
|
|
|
|
|
|
ve.ui.MWReferencesListDialog.static.size = 'medium';
|
|
|
|
|
|
|
|
ve.ui.MWReferencesListDialog.static.actions = [
|
|
|
|
{
|
|
|
|
action: 'apply',
|
2016-02-10 00:32:18 +00:00
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-action-apply' ),
|
2016-02-03 21:03:41 +00:00
|
|
|
flags: [ 'progressive', 'primary' ],
|
|
|
|
modes: 'edit'
|
|
|
|
},
|
|
|
|
{
|
2016-02-10 00:32:18 +00:00
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-action-cancel' ),
|
2016-02-03 21:03:41 +00:00
|
|
|
flags: [ 'safe', 'back' ],
|
|
|
|
modes: 'edit'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferencesListDialog.prototype.getBodyHeight = function () {
|
|
|
|
return Math.max( 150, Math.ceil( this.editPanel.$element[ 0 ].scrollHeight ) );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferencesListDialog.prototype.initialize = function () {
|
2017-09-19 15:35:27 +00:00
|
|
|
var groupField, responsiveField;
|
|
|
|
|
2016-02-03 21:03:41 +00:00
|
|
|
// Parent method
|
|
|
|
ve.ui.MWReferencesListDialog.super.prototype.initialize.call( this );
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.panels = new OO.ui.StackLayout();
|
|
|
|
this.editPanel = new OO.ui.PanelLayout( {
|
|
|
|
scrollable: true, padded: true
|
|
|
|
} );
|
|
|
|
this.optionsFieldset = new OO.ui.FieldsetLayout();
|
|
|
|
|
|
|
|
this.groupInput = new ve.ui.MWReferenceGroupInputWidget( {
|
|
|
|
$overlay: this.$overlay,
|
|
|
|
emptyGroupName: ve.msg( 'cite-ve-dialog-reference-options-group-placeholder' )
|
|
|
|
} );
|
2017-09-19 15:35:27 +00:00
|
|
|
groupField = new OO.ui.FieldLayout( this.groupInput, {
|
2016-02-03 21:03:41 +00:00
|
|
|
align: 'top',
|
|
|
|
label: ve.msg( 'cite-ve-dialog-reference-options-group-label' )
|
|
|
|
} );
|
|
|
|
|
2017-09-19 15:35:27 +00:00
|
|
|
this.responsiveCheckbox = new OO.ui.CheckboxInputWidget();
|
|
|
|
responsiveField = new OO.ui.FieldLayout( this.responsiveCheckbox, {
|
|
|
|
align: 'inline',
|
|
|
|
label: ve.msg( 'cite-ve-dialog-reference-options-responsive-label' )
|
|
|
|
} );
|
|
|
|
|
2016-02-03 21:03:41 +00:00
|
|
|
// Initialization
|
2017-09-19 15:35:27 +00:00
|
|
|
this.optionsFieldset.addItems( [ groupField, responsiveField ] );
|
2016-02-03 21:03:41 +00:00
|
|
|
this.editPanel.$element.append( this.optionsFieldset.$element );
|
|
|
|
this.panels.addItems( [ this.editPanel ] );
|
|
|
|
this.$body.append( this.panels.$element );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferencesListDialog.prototype.getActionProcess = function ( action ) {
|
|
|
|
if ( action === 'apply' ) {
|
|
|
|
return new OO.ui.Process( function () {
|
2017-10-17 19:21:36 +00:00
|
|
|
var refGroup, listGroup, oldListGroup, isResponsive, oldResponsive, mwData, attrChanges, doc,
|
2016-02-03 21:03:41 +00:00
|
|
|
surfaceModel = this.getFragment().getSurface();
|
|
|
|
|
|
|
|
// Save changes
|
2016-11-15 17:28:49 +00:00
|
|
|
refGroup = this.groupInput.getValue();
|
2016-02-03 21:03:41 +00:00
|
|
|
listGroup = 'mwReference/' + refGroup;
|
2017-09-19 15:35:27 +00:00
|
|
|
isResponsive = this.responsiveCheckbox.isSelected();
|
2016-02-03 21:03:41 +00:00
|
|
|
|
|
|
|
if ( this.selectedNode ) {
|
|
|
|
// Edit existing model
|
|
|
|
doc = surfaceModel.getDocument();
|
|
|
|
oldListGroup = this.selectedNode.getAttribute( 'listGroup' );
|
2017-09-19 15:35:27 +00:00
|
|
|
oldResponsive = this.selectedNode.getAttribute( 'isResponsive' );
|
2016-02-03 21:03:41 +00:00
|
|
|
|
2017-09-19 15:35:27 +00:00
|
|
|
if ( listGroup !== oldListGroup || isResponsive !== oldResponsive ) {
|
2017-10-17 19:21:36 +00:00
|
|
|
// newFromAttributeChanges doesn't do the smart-replacing
|
|
|
|
// for nested attributes, so make a copy of the mw
|
|
|
|
// attribute so we can disable autoGenerated now we've
|
|
|
|
// changed it.
|
|
|
|
mwData = ve.copy( this.selectedNode.getAttribute( 'mw' ) ) || {};
|
|
|
|
delete mwData.autoGenerated;
|
|
|
|
|
2016-02-03 21:03:41 +00:00
|
|
|
attrChanges = {
|
|
|
|
listGroup: listGroup,
|
2017-09-19 15:35:27 +00:00
|
|
|
refGroup: refGroup,
|
2017-10-17 19:21:36 +00:00
|
|
|
isResponsive: isResponsive,
|
|
|
|
mw: mwData
|
2016-02-03 21:03:41 +00:00
|
|
|
};
|
|
|
|
surfaceModel.change(
|
2016-11-30 19:06:13 +00:00
|
|
|
ve.dm.TransactionBuilder.static.newFromAttributeChanges(
|
2016-02-03 21:03:41 +00:00
|
|
|
doc, this.selectedNode.getOuterRange().start, attrChanges
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.close( { action: action } );
|
|
|
|
}, this );
|
|
|
|
}
|
|
|
|
// Parent method
|
|
|
|
return ve.ui.MWReferencesListDialog.super.prototype.getActionProcess.call( this, action );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferencesListDialog.prototype.getSetupProcess = function ( data ) {
|
|
|
|
return ve.ui.MWReferencesListDialog.super.prototype.getSetupProcess.call( this, data )
|
|
|
|
.next( function () {
|
|
|
|
if ( !( this.selectedNode instanceof ve.dm.MWReferencesListNode ) ) {
|
|
|
|
throw new Error( 'Cannot open dialog: references list must be selected' );
|
|
|
|
}
|
|
|
|
|
|
|
|
this.actions.setMode( 'edit' );
|
|
|
|
|
2016-11-15 17:28:49 +00:00
|
|
|
this.groupInput.setValue( this.selectedNode.getAttribute( 'refGroup' ) );
|
2016-02-03 21:03:41 +00:00
|
|
|
this.groupInput.populateMenu( this.getFragment().getDocument().getInternalList() );
|
2017-09-19 15:35:27 +00:00
|
|
|
|
|
|
|
this.responsiveCheckbox.setSelected( this.selectedNode.getAttribute( 'isResponsive' ) );
|
2016-02-03 21:03:41 +00:00
|
|
|
}, this );
|
|
|
|
};
|
|
|
|
|
2018-02-06 20:58:27 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferencesListDialog.prototype.getReadyProcess = function ( data ) {
|
|
|
|
return ve.ui.MWReferencesListDialog.super.prototype.getReadyProcess.call( this, data )
|
|
|
|
.next( function () {
|
|
|
|
this.groupInput.focus();
|
|
|
|
}, this );
|
|
|
|
};
|
|
|
|
|
2016-02-03 21:03:41 +00:00
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.windowFactory.register( ve.ui.MWReferencesListDialog );
|