2013-12-02 20:10:55 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor user interface MWTemplatePage class.
|
|
|
|
*
|
2015-01-08 23:54:03 +00:00
|
|
|
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
2013-12-02 20:10:55 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MediaWiki transclusion dialog template page.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends OO.ui.PageLayout
|
|
|
|
*
|
|
|
|
* @constructor
|
2015-08-19 18:33:59 +00:00
|
|
|
* @param {ve.dm.MWTemplateModel} template Template model
|
2013-12-02 20:10:55 +00:00
|
|
|
* @param {string} name Unique symbolic name of page
|
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplatePage = function VeUiMWTemplatePage( template, name, config ) {
|
2014-09-22 17:48:42 +00:00
|
|
|
var title;
|
2014-03-06 23:40:43 +00:00
|
|
|
|
2014-04-25 23:50:21 +00:00
|
|
|
// Configuration initialization
|
|
|
|
config = ve.extendObject( {
|
2014-08-22 20:50:48 +00:00
|
|
|
scrollable: false
|
2014-04-25 23:50:21 +00:00
|
|
|
}, config );
|
|
|
|
|
2013-12-02 20:10:55 +00:00
|
|
|
// Parent constructor
|
|
|
|
OO.ui.PageLayout.call( this, name, config );
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.template = template;
|
2014-02-27 23:58:37 +00:00
|
|
|
this.spec = template.getSpec();
|
2015-04-09 23:47:15 +00:00
|
|
|
this.$more = $( '<div>' );
|
|
|
|
this.$description = $( '<div>' );
|
2014-01-17 14:24:12 +00:00
|
|
|
this.removeButton = new OO.ui.ButtonWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
framed: false,
|
|
|
|
icon: 'remove',
|
|
|
|
title: ve.msg( 'visualeditor-dialog-transclusion-remove-template' ),
|
2015-07-22 22:13:09 +00:00
|
|
|
flags: [ 'destructive' ],
|
2014-08-22 20:50:48 +00:00
|
|
|
classes: [ 've-ui-mwTransclusionDialog-removeButton' ]
|
2014-06-26 10:41:18 +00:00
|
|
|
} )
|
2014-08-22 20:50:48 +00:00
|
|
|
.connect( this, { click: 'onRemoveButtonClick' } );
|
2013-12-02 20:10:55 +00:00
|
|
|
this.infoFieldset = new OO.ui.FieldsetLayout( {
|
2014-08-22 20:50:48 +00:00
|
|
|
label: this.spec.getLabel(),
|
|
|
|
icon: 'template'
|
2013-12-02 20:10:55 +00:00
|
|
|
} );
|
2014-03-04 22:56:14 +00:00
|
|
|
this.addButton = new OO.ui.ButtonWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
framed: false,
|
|
|
|
icon: 'parameter',
|
|
|
|
label: ve.msg( 'visualeditor-dialog-transclusion-add-param' ),
|
|
|
|
tabIndex: -1
|
2014-06-26 10:41:18 +00:00
|
|
|
} )
|
2014-08-22 20:50:48 +00:00
|
|
|
.connect( this, { click: 'onAddButtonFocus' } );
|
2013-12-02 20:10:55 +00:00
|
|
|
|
|
|
|
// Initialization
|
2014-03-06 23:40:43 +00:00
|
|
|
this.$description.addClass( 've-ui-mwTemplatePage-description' );
|
|
|
|
if ( this.spec.getDescription() ) {
|
|
|
|
this.$description.text( this.spec.getDescription() );
|
|
|
|
} else {
|
2014-07-09 20:09:05 +00:00
|
|
|
title = this.template.getTitle();
|
|
|
|
// The transcluded page may be dynamically generated or unspecified in the DOM
|
|
|
|
// for other reasons (bug 66724). In that case we can't tell the user what
|
|
|
|
// the template is called nor link to the template page.
|
|
|
|
if ( title ) {
|
|
|
|
title = mw.Title.newFromText( title );
|
|
|
|
}
|
|
|
|
if ( title ) {
|
|
|
|
this.$description
|
|
|
|
.addClass( 've-ui-mwTemplatePage-description-missing' )
|
|
|
|
.append( ve.msg(
|
|
|
|
'visualeditor-dialog-transclusion-no-template-description',
|
2014-09-22 17:48:42 +00:00
|
|
|
title.getRelativeText( 10 ),
|
2014-08-22 20:50:48 +00:00
|
|
|
ve.getHtmlAttributes( { target: '_blank', href: title.getUrl() } ),
|
2014-07-09 20:09:05 +00:00
|
|
|
mw.user
|
|
|
|
) );
|
2014-07-02 19:38:29 +00:00
|
|
|
}
|
2014-03-06 23:40:43 +00:00
|
|
|
}
|
2014-07-09 20:09:05 +00:00
|
|
|
|
2014-03-06 23:40:43 +00:00
|
|
|
this.infoFieldset.$element.append( this.$description );
|
2014-03-04 22:56:14 +00:00
|
|
|
this.$more
|
|
|
|
.addClass( 've-ui-mwTemplatePage-more' )
|
|
|
|
.append( this.addButton.$element );
|
2014-02-27 23:58:37 +00:00
|
|
|
this.$element
|
|
|
|
.addClass( 've-ui-mwTemplatePage' )
|
2014-03-04 22:56:14 +00:00
|
|
|
.append( this.infoFieldset.$element, this.removeButton.$element, this.$more );
|
2013-12-02 20:10:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWTemplatePage, OO.ui.PageLayout );
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2014-02-15 01:37:32 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplatePage.prototype.setOutlineItem = function ( outlineItem ) {
|
|
|
|
// Parent method
|
|
|
|
OO.ui.PageLayout.prototype.setOutlineItem.call( this, outlineItem );
|
|
|
|
|
|
|
|
if ( this.outlineItem ) {
|
|
|
|
this.outlineItem
|
|
|
|
.setIcon( 'template' )
|
|
|
|
.setMovable( true )
|
2014-03-01 00:39:02 +00:00
|
|
|
.setRemovable( true )
|
2014-02-15 01:37:32 +00:00
|
|
|
.setLabel( this.spec.getLabel() );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-12-02 20:10:55 +00:00
|
|
|
ve.ui.MWTemplatePage.prototype.onRemoveButtonClick = function () {
|
|
|
|
this.template.remove();
|
|
|
|
};
|
2014-03-04 22:56:14 +00:00
|
|
|
|
2014-07-21 21:06:54 +00:00
|
|
|
ve.ui.MWTemplatePage.prototype.onAddButtonFocus = function () {
|
2014-03-04 22:56:14 +00:00
|
|
|
this.template.addParameter( new ve.dm.MWParameterModel( this.template ) );
|
|
|
|
};
|