2013-06-11 19:16:04 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor user interface MWTransclusionDialog class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2013-06-19 01:33:58 +00:00
|
|
|
/*global mw */
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/**
|
2013-06-19 20:00:11 +00:00
|
|
|
* Dialog for editing a MediaWiki transclusion.
|
2013-06-11 19:16:04 +00:00
|
|
|
*
|
|
|
|
* See https://raw.github.com/wikimedia/mediawiki-extensions-TemplateData/master/spec.templatedata.json
|
|
|
|
* for the latest version of the TemplateData specification.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.ui.PagedDialog
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {ve.ui.Surface} surface
|
|
|
|
* @param {Object} [config] Config options
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog = function VeUiMWTransclusionDialog( surface, config ) {
|
2013-06-14 00:46:45 +00:00
|
|
|
// Configuration initialization
|
2013-06-18 21:24:16 +00:00
|
|
|
config = ve.extendObject( {}, config, {
|
|
|
|
'editable': true,
|
|
|
|
'adders': [
|
|
|
|
{
|
|
|
|
'name': 'template',
|
|
|
|
'icon': 'template',
|
|
|
|
'title': ve.msg( 'visualeditor-dialog-transclusion-add-template' )
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'name': 'content',
|
|
|
|
'icon': 'source',
|
|
|
|
'title': ve.msg( 'visualeditor-dialog-transclusion-add-content' )
|
|
|
|
}
|
|
|
|
]
|
|
|
|
} );
|
2013-06-14 00:46:45 +00:00
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
// Parent constructor
|
|
|
|
ve.ui.PagedDialog.call( this, surface, config );
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.node = null;
|
|
|
|
this.transclusion = null;
|
2013-06-28 21:38:40 +00:00
|
|
|
this.pending = [];
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
ve.inheritClass( ve.ui.MWTransclusionDialog, ve.ui.PagedDialog );
|
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.ui.MWTransclusionDialog.static.titleMessage = 'visualeditor-dialog-transclusion-title';
|
|
|
|
|
|
|
|
ve.ui.MWTransclusionDialog.static.icon = 'template';
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2013-06-14 00:46:45 +00:00
|
|
|
ve.ui.MWTransclusionDialog.prototype.initialize = function () {
|
2013-06-21 02:47:10 +00:00
|
|
|
// Parent method
|
2013-06-14 00:46:45 +00:00
|
|
|
ve.ui.PagedDialog.prototype.initialize.call( this );
|
|
|
|
|
2013-06-18 21:24:16 +00:00
|
|
|
// Events
|
|
|
|
this.outlineControlsWidget.connect( this, {
|
|
|
|
'move': 'onOutlineControlsMove',
|
|
|
|
'add': 'onOutlineControlsAdd'
|
|
|
|
} );
|
2013-06-14 00:46:45 +00:00
|
|
|
};
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
ve.ui.MWTransclusionDialog.prototype.onOpen = function () {
|
|
|
|
// Parent method
|
|
|
|
ve.ui.PagedDialog.prototype.onOpen.call( this );
|
|
|
|
|
|
|
|
// Sanity check
|
|
|
|
this.node = this.surface.getView().getFocusedNode();
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.transclusion = new ve.dm.MWTransclusionModel();
|
|
|
|
|
2013-06-29 02:37:42 +00:00
|
|
|
// Events
|
|
|
|
this.transclusion.connect( this, { 'add': 'onAddPart', 'remove': 'onRemovePart' } );
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
// Initialization
|
2013-06-18 22:09:01 +00:00
|
|
|
if ( this.node instanceof ve.ce.MWTransclusionNode ) {
|
2013-06-29 02:37:42 +00:00
|
|
|
this.transclusion.load( ve.copyObject( this.node.getModel().getAttribute( 'mw' ) ) );
|
2013-06-18 22:09:01 +00:00
|
|
|
} else {
|
2013-06-29 02:37:42 +00:00
|
|
|
this.transclusion.addPart( new ve.dm.MWTemplatePlaceholderModel( this.transclusion ) );
|
2013-06-18 22:09:01 +00:00
|
|
|
}
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onClose = function ( action ) {
|
2013-06-18 22:09:01 +00:00
|
|
|
var surfaceModel = this.surface.getModel(),
|
|
|
|
obj = this.transclusion.getPlainObject();
|
2013-06-11 19:16:04 +00:00
|
|
|
|
2013-06-19 15:21:38 +00:00
|
|
|
// Parent method
|
|
|
|
ve.ui.PagedDialog.prototype.onClose.call( this );
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
// Save changes
|
|
|
|
if ( action === 'apply' ) {
|
2013-06-18 22:09:01 +00:00
|
|
|
if ( this.node instanceof ve.ce.MWTransclusionNode ) {
|
2013-06-20 16:23:29 +00:00
|
|
|
if ( obj !== null ) {
|
|
|
|
surfaceModel.getFragment().changeAttributes( { 'mw': obj } );
|
|
|
|
} else {
|
|
|
|
surfaceModel.getFragment().removeContent();
|
|
|
|
}
|
|
|
|
} else if ( obj !== null ) {
|
2013-06-18 22:09:01 +00:00
|
|
|
surfaceModel.getFragment().collapseRangeToEnd().insertContent( [
|
|
|
|
{
|
|
|
|
'type': 'mwTransclusionInline',
|
|
|
|
'attributes': {
|
|
|
|
'mw': obj
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{ 'type': '/mwTransclusionInline' }
|
|
|
|
] );
|
|
|
|
}
|
2013-06-11 19:16:04 +00:00
|
|
|
}
|
|
|
|
|
2013-06-28 21:38:40 +00:00
|
|
|
this.transclusion.disconnect( this );
|
|
|
|
this.transclusion.abortRequests();
|
|
|
|
this.transclusion = null;
|
2013-06-11 19:16:04 +00:00
|
|
|
this.clearPages();
|
|
|
|
this.node = null;
|
|
|
|
this.content = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle add part events.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.dm.MWTransclusionPartModel} part Added part
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onAddPart = function ( part ) {
|
2013-06-28 21:38:40 +00:00
|
|
|
var i, len, page, params, param, names, pending, item;
|
2013-06-11 19:16:04 +00:00
|
|
|
|
|
|
|
if ( part instanceof ve.dm.MWTemplateModel ) {
|
|
|
|
page = this.getTemplatePage( part );
|
|
|
|
} else if ( part instanceof ve.dm.MWTransclusionContentModel ) {
|
|
|
|
page = this.getContentPage( part );
|
2013-06-18 21:24:16 +00:00
|
|
|
} else if ( part instanceof ve.dm.MWTemplatePlaceholderModel ) {
|
|
|
|
page = this.getPlaceholderPage( part );
|
2013-06-11 19:16:04 +00:00
|
|
|
}
|
|
|
|
if ( page ) {
|
2013-06-18 21:24:16 +00:00
|
|
|
page.index = this.getPageIndex( part );
|
2013-06-11 19:16:04 +00:00
|
|
|
this.addPage( part.getId(), page );
|
2013-06-14 00:46:45 +00:00
|
|
|
if ( part instanceof ve.dm.MWTemplateModel ) {
|
|
|
|
names = part.getParameterNames();
|
|
|
|
params = part.getParameters();
|
|
|
|
for ( i = 0, len = names.length; i < len; i++ ) {
|
|
|
|
param = params[names[i]];
|
|
|
|
page = this.getParameterPage( param );
|
|
|
|
page.index = this.getPageIndex( param );
|
|
|
|
this.addPage( param.getId(), page );
|
|
|
|
}
|
|
|
|
part.connect( this, { 'add': 'onAddParameter', 'remove': 'onRemoveParameter' } );
|
|
|
|
}
|
2013-06-11 19:16:04 +00:00
|
|
|
}
|
2013-06-28 21:38:40 +00:00
|
|
|
// Resolve pending placeholder
|
|
|
|
for ( i = 0, len = this.pending.length; i < len; i++ ) {
|
|
|
|
pending = this.pending[i];
|
|
|
|
if ( pending.part === part ) {
|
|
|
|
// Auto-select new part if placeholder is still selected
|
|
|
|
item = this.outlineWidget.getSelectedItem();
|
|
|
|
if ( item.getData() === pending.placeholder.getId() ) {
|
|
|
|
this.setPageByName( part.getId() );
|
|
|
|
}
|
|
|
|
// Cleanup
|
|
|
|
pending.placeholder.remove();
|
|
|
|
this.pending.splice( i, 1 );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle remove part events.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.dm.MWTransclusionPartModel} part Removed part
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onRemovePart = function ( part ) {
|
|
|
|
var name, params;
|
|
|
|
|
|
|
|
if ( part instanceof ve.dm.MWTemplateModel ) {
|
|
|
|
params = part.getParameters();
|
|
|
|
for ( name in params ) {
|
|
|
|
this.removePage( params[name].getId() );
|
|
|
|
}
|
|
|
|
part.disconnect( this );
|
|
|
|
}
|
|
|
|
this.removePage( part.getId() );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle add param events.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.dm.MWTemplateParameterModel} param Added param
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onAddParameter = function ( param ) {
|
|
|
|
var page = this.getParameterPage( param );
|
2013-06-14 00:46:45 +00:00
|
|
|
page.index = this.getPageIndex( param );
|
2013-06-11 19:16:04 +00:00
|
|
|
this.addPage( param.getId(), page );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle remove param events.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.dm.MWTemplateParameterModel} param Removed param
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onRemoveParameter = function ( param ) {
|
|
|
|
this.removePage( param.getId() );
|
|
|
|
// Return to template page
|
|
|
|
this.setPageByName( param.getTemplate().getId() );
|
|
|
|
};
|
|
|
|
|
2013-06-14 00:46:45 +00:00
|
|
|
/**
|
|
|
|
* Handle outline controls move events.
|
|
|
|
*
|
|
|
|
* @method
|
2013-06-18 21:24:16 +00:00
|
|
|
* @param {number} places Number of places to move the selected item
|
2013-06-14 00:46:45 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onOutlineControlsMove = function ( places ) {
|
|
|
|
var part, index, name,
|
|
|
|
parts = this.transclusion.getParts(),
|
|
|
|
item = this.outlineWidget.getSelectedItem();
|
|
|
|
|
|
|
|
if ( item ) {
|
|
|
|
name = item.getData();
|
|
|
|
part = this.transclusion.getPartFromId( name );
|
|
|
|
index = ve.indexOf( part, parts );
|
|
|
|
this.transclusion.removePart( part );
|
|
|
|
this.transclusion.addPart( part, index + places );
|
|
|
|
this.setPageByName( name );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-18 21:24:16 +00:00
|
|
|
/**
|
|
|
|
* Handle outline controls add events.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {string} type Type of item to add
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onOutlineControlsAdd = function ( type ) {
|
|
|
|
var part;
|
|
|
|
|
|
|
|
switch ( type ) {
|
|
|
|
case 'content':
|
2013-06-29 02:37:42 +00:00
|
|
|
part = new ve.dm.MWTransclusionContentModel( this.transclusion, '' );
|
|
|
|
this.transclusion.addPart( part, this.getPartInsertionIndex() );
|
2013-06-18 21:24:16 +00:00
|
|
|
this.setPageByName( part.getId() );
|
|
|
|
break;
|
|
|
|
case 'template':
|
2013-06-29 02:37:42 +00:00
|
|
|
part = new ve.dm.MWTemplatePlaceholderModel( this.transclusion );
|
|
|
|
this.transclusion.addPart( part, this.getPartInsertionIndex() );
|
2013-06-18 21:24:16 +00:00
|
|
|
this.setPageByName( part.getId() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get an index for part insertion.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @return {number} Index to insert new parts at
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.getPartInsertionIndex = function () {
|
|
|
|
var parts = this.transclusion.getParts(),
|
|
|
|
item = this.outlineWidget.getSelectedItem();
|
|
|
|
|
|
|
|
if ( item ) {
|
|
|
|
return ve.indexOf( this.transclusion.getPartFromId( item.getData() ), parts ) + 1;
|
|
|
|
}
|
|
|
|
return parts.length;
|
|
|
|
};
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/**
|
|
|
|
* Set the page by name.
|
|
|
|
*
|
|
|
|
* Page names are always the ID of the part or param they represent.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {string} name Page name
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.setPageByName = function ( name ) {
|
|
|
|
this.outlineWidget.selectItem( this.outlineWidget.getItemFromData( name ) );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the page index of an item.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.dm.MWTransclusionPartModel|ve.dm.MWTemplateParameterModel} item Part or parameter
|
2013-06-17 10:50:24 +00:00
|
|
|
* @returns {number} Page index of item
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.getPageIndex = function ( item ) {
|
|
|
|
// Build pages from parts
|
|
|
|
var i, iLen, j, jLen, part, names,
|
|
|
|
parts = this.transclusion.getParts(),
|
|
|
|
index = 0;
|
|
|
|
|
|
|
|
// Populate pages
|
|
|
|
for ( i = 0, iLen = parts.length; i < iLen; i++ ) {
|
|
|
|
part = parts[i];
|
|
|
|
if ( part === item ) {
|
|
|
|
return index;
|
|
|
|
}
|
2013-06-14 00:46:45 +00:00
|
|
|
index++;
|
2013-06-11 19:16:04 +00:00
|
|
|
if ( part instanceof ve.dm.MWTemplateModel ) {
|
|
|
|
names = part.getParameterNames();
|
|
|
|
for ( j = 0, jLen = names.length; j < jLen; j++ ) {
|
|
|
|
if ( part.getParameter( names[j] ) === item ) {
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get page for transclusion content.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.dm.MWTransclusionContentModel} content Content model
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.getContentPage = function ( content ) {
|
|
|
|
var valueFieldset, textInput, optionsFieldset, removeButton;
|
|
|
|
|
|
|
|
valueFieldset = new ve.ui.FieldsetLayout( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-transclusion-content' ),
|
|
|
|
'icon': 'source'
|
|
|
|
} );
|
|
|
|
|
|
|
|
textInput = new ve.ui.TextInputWidget( { '$$': this.frame.$$, 'multiline': true } );
|
|
|
|
textInput.setValue( content.getValue() );
|
|
|
|
textInput.connect( this, { 'change': function () {
|
|
|
|
content.setValue( textInput.getValue() );
|
|
|
|
} } );
|
|
|
|
textInput.$.addClass( 've-ui-mwTransclusionDialog-input' );
|
|
|
|
valueFieldset.$.append( textInput.$ );
|
|
|
|
|
|
|
|
optionsFieldset = new ve.ui.FieldsetLayout( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-transclusion-options' ),
|
|
|
|
'icon': 'settings'
|
|
|
|
} );
|
|
|
|
|
|
|
|
removeButton = new ve.ui.ButtonWidget( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-transclusion-remove-content' ),
|
|
|
|
'flags': ['destructive']
|
|
|
|
} );
|
|
|
|
removeButton.connect( this, { 'click': function () {
|
|
|
|
content.remove();
|
|
|
|
} } );
|
|
|
|
optionsFieldset.$.append( removeButton.$ );
|
|
|
|
|
|
|
|
return {
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-transclusion-content' ),
|
|
|
|
'icon': 'source',
|
2013-06-14 00:46:45 +00:00
|
|
|
'$content': valueFieldset.$.add( optionsFieldset.$ ),
|
|
|
|
'moveable': true
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get page for a template.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.dm.MWTemplateModel} template Template model
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.getTemplatePage = function ( template ) {
|
|
|
|
var infoFieldset, addParameterFieldset, addParameterInput, addParameterButton, optionsFieldset,
|
2013-06-18 21:24:16 +00:00
|
|
|
removeButton,
|
2013-06-11 19:16:04 +00:00
|
|
|
spec = template.getSpec(),
|
|
|
|
label = spec.getLabel(),
|
|
|
|
description = spec.getDescription();
|
|
|
|
|
2013-06-18 21:24:16 +00:00
|
|
|
function addParameter() {
|
2013-06-29 02:37:42 +00:00
|
|
|
var param = new ve.dm.MWTemplateParameterModel( template, addParameterInput.getValue() );
|
|
|
|
template.addParameter( param );
|
2013-06-18 21:24:16 +00:00
|
|
|
addParameterInput.setValue();
|
|
|
|
this.setPageByName( param.getId() );
|
|
|
|
}
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
infoFieldset = new ve.ui.FieldsetLayout( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': label,
|
|
|
|
'icon': 'template'
|
|
|
|
} );
|
|
|
|
|
|
|
|
if ( description ) {
|
|
|
|
infoFieldset.$.append( $( '<div>' ).text( description ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
addParameterFieldset = new ve.ui.FieldsetLayout( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-transclusion-add-param' ),
|
|
|
|
'icon': 'parameter'
|
|
|
|
} );
|
|
|
|
addParameterFieldset.$.addClass( 've-ui-mwTransclusionDialog-addParameterFieldset' );
|
|
|
|
addParameterInput = new ve.ui.TextInputWidget( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'placeholder': ve.msg( 'visualeditor-dialog-transclusion-param-name' )
|
|
|
|
} );
|
|
|
|
addParameterButton = new ve.ui.ButtonWidget( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-transclusion-add-param' ),
|
|
|
|
'disabled': true
|
|
|
|
} );
|
|
|
|
addParameterButton.connect( this, { 'click': addParameter } );
|
|
|
|
addParameterInput.connect( this, {
|
|
|
|
'enter': addParameter,
|
|
|
|
'change': function ( value ) {
|
|
|
|
var names = template.getParameterNames();
|
|
|
|
addParameterButton.setDisabled( value === '' || names.indexOf( value ) !== -1 );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
addParameterFieldset.$.append( addParameterInput.$, addParameterButton.$ );
|
|
|
|
|
|
|
|
optionsFieldset = new ve.ui.FieldsetLayout( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-transclusion-options' ),
|
|
|
|
'icon': 'settings'
|
|
|
|
} );
|
|
|
|
|
|
|
|
removeButton = new ve.ui.ButtonWidget( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-transclusion-remove-template' ),
|
|
|
|
'flags': ['destructive']
|
|
|
|
} );
|
|
|
|
removeButton.connect( this, { 'click': function () {
|
|
|
|
template.remove();
|
|
|
|
} } );
|
|
|
|
optionsFieldset.$.append( removeButton.$ );
|
|
|
|
|
|
|
|
return {
|
|
|
|
'label': label,
|
|
|
|
'icon': 'template',
|
2013-06-14 00:46:45 +00:00
|
|
|
'$content': infoFieldset.$.add( addParameterFieldset.$ ).add( optionsFieldset.$ ),
|
|
|
|
'moveable': true
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get page for a parameter.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.dm.MWTemplateParameterModel} parameter Parameter model
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.getParameterPage = function ( parameter ) {
|
|
|
|
var valueFieldset, optionsFieldset, textInput, inputLabel, removeButton,
|
|
|
|
spec = parameter.getTemplate().getSpec(),
|
|
|
|
name = parameter.getName(),
|
|
|
|
label = spec.getParameterLabel( name ),
|
|
|
|
description = spec.getParameterDescription( name );
|
|
|
|
|
|
|
|
valueFieldset = new ve.ui.FieldsetLayout( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': label,
|
|
|
|
'icon': 'parameter'
|
|
|
|
} );
|
|
|
|
|
|
|
|
if ( description ) {
|
|
|
|
inputLabel = new ve.ui.InputLabelWidget( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'input': textInput,
|
|
|
|
'label': description
|
|
|
|
} );
|
|
|
|
valueFieldset.$.append( inputLabel.$ );
|
|
|
|
}
|
|
|
|
|
|
|
|
textInput = new ve.ui.TextInputWidget( { '$$': this.frame.$$, 'multiline': true } );
|
|
|
|
textInput.setValue( parameter.getValue() );
|
|
|
|
textInput.connect( this, { 'change': function () {
|
|
|
|
parameter.setValue( textInput.getValue() );
|
|
|
|
} } );
|
|
|
|
textInput.$.addClass( 've-ui-mwTransclusionDialog-input' );
|
|
|
|
valueFieldset.$.append( textInput.$ );
|
|
|
|
|
|
|
|
optionsFieldset = new ve.ui.FieldsetLayout( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-transclusion-options' ),
|
|
|
|
'icon': 'settings'
|
|
|
|
} );
|
|
|
|
|
|
|
|
removeButton = new ve.ui.ButtonWidget( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-transclusion-remove-param' ),
|
|
|
|
'flags': ['destructive']
|
|
|
|
} );
|
|
|
|
removeButton.connect( this, { 'click': function () {
|
|
|
|
parameter.remove();
|
|
|
|
} } );
|
|
|
|
optionsFieldset.$.append( removeButton.$ );
|
|
|
|
|
|
|
|
// TODO: Use spec.required
|
|
|
|
// TODO: Use spec.deprecation
|
|
|
|
// TODO: Use spec.default
|
|
|
|
// TODO: Use spec.type
|
|
|
|
|
|
|
|
return {
|
|
|
|
'label': label,
|
|
|
|
'icon': 'parameter',
|
|
|
|
'level': 1,
|
|
|
|
'$content': valueFieldset.$.add( optionsFieldset.$ )
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2013-06-18 21:24:16 +00:00
|
|
|
/**
|
|
|
|
* Get page for a parameter.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.dm.MWTemplateParameterModel} parameter Parameter model
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.getPlaceholderPage = function ( placeholder ) {
|
|
|
|
var addTemplateFieldset, addTemplateInput, addTemplateButton, optionsFieldset, removeButton,
|
|
|
|
label = ve.msg( 'visualeditor-dialog-transclusion-placeholder' );
|
|
|
|
|
|
|
|
function addTemplate() {
|
|
|
|
var target, part,
|
|
|
|
parts = placeholder.getTransclusion().getParts(),
|
2013-06-19 01:33:58 +00:00
|
|
|
value = addTemplateInput.getValue(),
|
|
|
|
href = value;
|
|
|
|
|
|
|
|
if ( href.charAt( 0 ) !== ':' ) {
|
|
|
|
href = mw.config.get( 'wgFormattedNamespaces' )[10] + ':' + href;
|
|
|
|
}
|
2013-06-18 21:24:16 +00:00
|
|
|
|
2013-06-19 01:33:58 +00:00
|
|
|
target = { 'href': new mw.Title( href ).getPrefixedText(), 'wt': value };
|
2013-06-29 02:37:42 +00:00
|
|
|
part = new ve.dm.MWTemplateModel( this.transclusion, target );
|
|
|
|
this.transclusion.addPart( part, ve.indexOf( placeholder, parts ) );
|
2013-06-28 21:38:40 +00:00
|
|
|
this.pending.push( { 'part': part, 'placeholder': placeholder } );
|
|
|
|
addTemplateInput.pushPending();
|
|
|
|
addTemplateButton.setDisabled( true );
|
|
|
|
removeButton.setDisabled( true );
|
2013-06-18 21:24:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
addTemplateFieldset = new ve.ui.FieldsetLayout( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': label,
|
|
|
|
'icon': 'parameter'
|
|
|
|
} );
|
|
|
|
addTemplateFieldset.$.addClass( 've-ui-mwTransclusionDialog-addTemplateFieldset' );
|
|
|
|
|
|
|
|
addTemplateInput = new ve.ui.MWTitleInputWidget( {
|
|
|
|
'$$': this.frame.$$, '$overlay': this.$overlay, 'namespace': 10
|
|
|
|
} );
|
|
|
|
addTemplateButton = new ve.ui.ButtonWidget( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-transclusion-add-template' ),
|
|
|
|
'flags': ['constructive'],
|
|
|
|
'disabled': true
|
|
|
|
} );
|
|
|
|
addTemplateInput.connect( this, {
|
|
|
|
'change': function () {
|
|
|
|
addTemplateButton.setDisabled( addTemplateInput.getValue() === '' );
|
|
|
|
},
|
|
|
|
'enter': addTemplate
|
|
|
|
} );
|
|
|
|
addTemplateButton.connect( this, { 'click': addTemplate } );
|
|
|
|
addTemplateFieldset.$.append( addTemplateInput.$, addTemplateButton.$ );
|
|
|
|
|
|
|
|
optionsFieldset = new ve.ui.FieldsetLayout( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-transclusion-options' ),
|
|
|
|
'icon': 'settings'
|
|
|
|
} );
|
|
|
|
|
|
|
|
removeButton = new ve.ui.ButtonWidget( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-transclusion-remove-template' ),
|
|
|
|
'flags': ['destructive']
|
|
|
|
} );
|
|
|
|
removeButton.connect( this, { 'click': function () {
|
|
|
|
placeholder.remove();
|
|
|
|
} } );
|
|
|
|
optionsFieldset.$.append( removeButton.$ );
|
|
|
|
|
|
|
|
return {
|
|
|
|
'label': $( '<span>' )
|
|
|
|
.addClass( 've-ui-mwTransclusionDialog-placeholder-label' )
|
|
|
|
.text( label ),
|
|
|
|
'icon': 'template',
|
|
|
|
'$content': addTemplateFieldset.$.add( optionsFieldset.$ )
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.dialogFactory.register( 'mwTransclusion', ve.ui.MWTransclusionDialog );
|