2021-05-17 15:43:49 +00:00
|
|
|
/*!
|
|
|
|
* 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
|
2021-07-07 08:04:40 +00:00
|
|
|
* @param {Object} config
|
|
|
|
* @param {ve.dm.MWTransclusionModel} config.transclusionModel
|
2021-05-17 15:43:49 +00:00
|
|
|
* // TODO: document `items`
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionOutlineContainerWidget = function VeUiMWTransclusionOutlineContainerWidget( config ) {
|
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWTransclusionOutlineContainerWidget.super.call( this, config );
|
|
|
|
|
|
|
|
// Initialization
|
2021-06-17 11:20:50 +00:00
|
|
|
this.transclusionModel = config.transclusionModel;
|
|
|
|
|
|
|
|
// Events
|
|
|
|
this.transclusionModel.connect( this, {
|
|
|
|
replace: 'onReplacePart'
|
|
|
|
// TODO
|
|
|
|
// change: 'onTransclusionModelChange'
|
2021-05-17 15:43:49 +00:00
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWTransclusionOutlineContainerWidget, OO.ui.Widget );
|
2021-06-17 11:20:50 +00:00
|
|
|
|
|
|
|
/* Events */
|
|
|
|
|
|
|
|
/**
|
2021-07-07 08:04:40 +00:00
|
|
|
* @private
|
|
|
|
* @param {ve.dm.MWTransclusionPartModel|null} removed Removed part
|
|
|
|
* @param {ve.dm.MWTransclusionPartModel|null} added Added part
|
2021-06-17 11:20:50 +00:00
|
|
|
*/
|
|
|
|
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 );
|
2021-07-09 15:04:14 +00:00
|
|
|
} 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 );
|
2021-06-17 11:20:50 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
2021-07-07 08:04:40 +00:00
|
|
|
* @param {ve.dm.MWTemplateModel} template
|
2021-06-17 11:20:50 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionOutlineContainerWidget.prototype.addTemplate = function ( template ) {
|
|
|
|
// FIXME: Respect order
|
2021-07-09 15:04:14 +00:00
|
|
|
var container = new ve.ui.MWTransclusionOutlineTemplateWidget( {
|
2021-06-17 11:20:50 +00:00
|
|
|
templateModel: template
|
|
|
|
} );
|
|
|
|
|
2021-07-09 13:57:11 +00:00
|
|
|
this.$element
|
2021-06-17 11:20:50 +00:00
|
|
|
.append( container.$element );
|
|
|
|
};
|