mediawiki-extensions-Visual.../modules/ve-mw/ui/pages/ve.ui.MWTemplateParameterPage.js
Trevor Parscal 51e096d6f2 Refactor Transclusion and Meta dialogs to use BookletLayout
Use OOJS-UI's newly-extended paged dialogs (in e08eb2a03b) to refactor
how the Transclusion and Meta dialogs work, splitting out the code for
each of the panels into its own file and simplifying extensibility.

The Meta dialog (ve.ui.MWMetaDialog) now has two self-managing panels:
* ve.ui.MWCategoriesPage for categories and the default sort key
* ve.ui.MWLanguagesPage for language links

The Transclusion dialog (ve.ui.MWTransclusionDialog) now has four:
* ve.ui.MWTemplatePage for a template's primary panel
* ve.ui.MWTemplateParameterPage for each parameter of a template
* ve.ui.MWTemplatePlaceholderPage for a placeholder to insert a template
* ve.ui.MWTransclusionContentPage for non-template transclusion

Additionally, the Transclusion dialog has been slightly cleaned up:
* Replace add/remove events with replace events in transclusion model
* Actually return and resolve a promise (as documented)
* Get rid of "origin" info in template models
* Add method for adding required parts

TODO:

* Decide how and when we will choose between advanced transclusion and
  template dialogs
* Work out design issues with how template descriptions will be visible
  and how adding parameters will work if only showing parameters in
  outline
* Add preview to template dialog
* Consider ways to further improve pages for use in continuous mode

WARNING:

* Right now the template dialog gets overridden by the advanced
  transclusion dialog because they have the same symbolic name and the
  latter is registered later than the former. To test the template
  dialog, just change the symbolic name of the advanced transclusion
  dialog.

Change-Id: I51e74b322aec9a4c3918e6f792bdb3d318060979
2013-12-05 16:26:26 -08:00

78 lines
2.4 KiB
JavaScript

/*!
* VisualEditor user interface MWTemplateParameterPage class.
*
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* MediaWiki transclusion dialog template page.
*
* @class
* @extends OO.ui.PageLayout
*
* @constructor
* @param {ve.dm.MWTemplateParameterModel} parameter Template parameter
* @param {string} name Unique symbolic name of page
* @param {Object} [config] Configuration options
*/
ve.ui.MWTemplateParameterPage = function VeUiMWTemplateParameter( parameter, name, config ) {
// Configuration initialization
config = ve.extendObject( config, { 'icon': 'parameter', 'moveable': false, 'level': 1 } );
// Parent constructor
OO.ui.PageLayout.call( this, name, config );
// Properties
this.parameter = parameter;
this.spec = parameter.getTemplate().getSpec();
this.label = this.spec.getParameterLabel( this.parameter.getName() );
this.textInput = new OO.ui.TextInputWidget( {
'$': this.$,
'multiline': true,
'classes': [ 've-ui-mwTransclusionDialog-input' ]
} )
.setValue( this.parameter.getValue() )
.connect( this, { 'change': 'onTextInputChange' } );
this.inputLabel = new OO.ui.InputLabelWidget( {
'$': this.$,
'input': this.textInput,
'label': this.spec.getParameterDescription( this.parameter.getName() ) || ''
} );
this.removeButton = new OO.ui.PushButtonWidget( {
'$': this.$,
'label': ve.msg( 'visualeditor-dialog-transclusion-remove-param' ),
'flags': ['destructive'],
'classes': [ 've-ui-mwTransclusionDialog-removeButton' ]
} )
.connect( this, { 'click': 'onRemoveButtonClick' } );
this.valueFieldset = new OO.ui.FieldsetLayout( {
'$': this.$,
'label': this.spec.getParameterLabel( this.parameter.getName() ),
'icon': 'parameter',
'$content': this.inputLabel.$element.add( this.textInput.$element )
} );
// TODO: Use spec.required
// TODO: Use spec.deprecation
// TODO: Use spec.default
// TODO: Use spec.type
// Initialization
this.$element.append( this.valueFieldset.$element, this.removeButton.$element );
};
/* Inheritance */
OO.inheritClass( ve.ui.MWTemplateParameterPage, OO.ui.PageLayout );
/* Methods */
ve.ui.MWTemplateParameterPage.prototype.onTextInputChange = function () {
this.parameter.setValue( this.textInput.getValue() );
};
ve.ui.MWTemplateParameterPage.prototype.onRemoveButtonClick = function () {
this.parameter.remove();
};