mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-16 02:51:50 +00:00
a1384f34f3
The two new widgets are pretty trivial now, thanks to the base class. Note there is still no code to delete the widgets. That's also why you will always see a placeholder widget at the top. This will be fixed with the next patches. This patch also renames most of the "…TemplateOutline…" classes to "…TransclusionOutline…" The reason is that these widgets are not for a single template, but part of the container widget for a more complex transclusion (i.e. a sequence of multiple templates and wikitext snippets). Bug: T274544 Change-Id: If4219b0b8ad4d1969ab1ec5ec4db0728811bab35
78 lines
2.1 KiB
JavaScript
78 lines
2.1 KiB
JavaScript
/*!
|
|
* VisualEditor user interface MWTransclusionOutlineContainerWidget class.
|
|
*
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* Container for transclusion, may contain a single or multiple templates.
|
|
*
|
|
* @class
|
|
* @extends OO.ui.Widget
|
|
*
|
|
* @constructor
|
|
* @param {Object} config
|
|
* @param {ve.dm.MWTransclusionModel} config.transclusionModel
|
|
* // TODO: document `items`
|
|
*/
|
|
ve.ui.MWTransclusionOutlineContainerWidget = function VeUiMWTransclusionOutlineContainerWidget( config ) {
|
|
// Parent constructor
|
|
ve.ui.MWTransclusionOutlineContainerWidget.super.call( this, config );
|
|
|
|
// Initialization
|
|
this.transclusionModel = config.transclusionModel;
|
|
|
|
// Events
|
|
this.transclusionModel.connect( this, {
|
|
replace: 'onReplacePart'
|
|
// TODO
|
|
// change: 'onTransclusionModelChange'
|
|
} );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
OO.inheritClass( ve.ui.MWTransclusionOutlineContainerWidget, OO.ui.Widget );
|
|
|
|
/* Events */
|
|
|
|
/**
|
|
* @private
|
|
* @param {ve.dm.MWTransclusionPartModel|null} removed Removed part
|
|
* @param {ve.dm.MWTransclusionPartModel|null} added Added part
|
|
*/
|
|
ve.ui.MWTransclusionOutlineContainerWidget.prototype.onReplacePart = function ( removed, added ) {
|
|
if ( removed instanceof ve.dm.MWTemplateModel ) {
|
|
// TODO
|
|
// this.removeTemplate( removed );
|
|
}
|
|
// TODO: and for wikitext snippets?
|
|
// TODO: reselect if active part was in a removed template
|
|
|
|
if ( added instanceof ve.dm.MWTemplateModel ) {
|
|
this.addTemplate( added );
|
|
} else if ( added instanceof ve.dm.MWTemplatePlaceholderModel ) {
|
|
var placeholder = new ve.ui.MWTransclusionOutlinePlaceholderWidget();
|
|
this.$element.append( placeholder.$element );
|
|
} else if ( added instanceof ve.dm.MWTransclusionContentModel ) {
|
|
var wikitextItem = new ve.ui.MWTransclusionOutlineWikitextWidget();
|
|
this.$element.append( wikitextItem.$element );
|
|
}
|
|
};
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* @private
|
|
* @param {ve.dm.MWTemplateModel} template
|
|
*/
|
|
ve.ui.MWTransclusionOutlineContainerWidget.prototype.addTemplate = function ( template ) {
|
|
// FIXME: Respect order
|
|
var container = new ve.ui.MWTransclusionOutlineTemplateWidget( {
|
|
templateModel: template
|
|
} );
|
|
|
|
this.$element
|
|
.append( container.$element );
|
|
};
|