jenkins-bot has submitted this change and it was merged. Change subject: Move parameter adding to a placeholder page ......................................................................
Move parameter adding to a placeholder page Parameter placeholder pages are generated for parameter with empty string as their name. Change-Id: I56c3df1ada6c4f41ebf6466ca280a2333da60071 --- M VisualEditor.php M modules/ve-mw/dm/models/ve.dm.MWTemplateModel.js M modules/ve-mw/dm/models/ve.dm.MWTemplateSpecModel.js M modules/ve-mw/ui/dialogs/ve.ui.MWTransclusionDialog.js A modules/ve-mw/ui/pages/ve.ui.MWParameterPlaceholderPage.js M modules/ve-mw/ui/pages/ve.ui.MWTemplatePage.js 6 files changed, 109 insertions(+), 31 deletions(-) Approvals: Catrope: Looks good to me, approved jenkins-bot: Verified diff --git a/VisualEditor.php b/VisualEditor.php index fdf02aa..7b6c599 100644 --- a/VisualEditor.php +++ b/VisualEditor.php @@ -892,6 +892,7 @@ 'modules/ve-mw/ui/pages/ve.ui.MWTemplatePage.js', 'modules/ve-mw/ui/pages/ve.ui.MWParameterPage.js', + 'modules/ve-mw/ui/pages/ve.ui.MWParameterPlaceholderPage.js', 'modules/ve-mw/ui/pages/ve.ui.MWTemplatePlaceholderPage.js', 'modules/ve-mw/ui/pages/ve.ui.MWTransclusionContentPage.js', diff --git a/modules/ve-mw/dm/models/ve.dm.MWTemplateModel.js b/modules/ve-mw/dm/models/ve.dm.MWTemplateModel.js index dd00f76..31cb674 100644 --- a/modules/ve-mw/dm/models/ve.dm.MWTemplateModel.js +++ b/modules/ve-mw/dm/models/ve.dm.MWTemplateModel.js @@ -204,8 +204,14 @@ paramNames.splice( index, 1 ); } } - // Unknown parameters in alpha-numeric order second + // Unknown parameters in alpha-numeric order second, empty string at the very end paramNames.sort( function ( a, b ) { + if ( a === '' ) { + return 1; + } + if ( b === '' ) { + return -1; + } var aIsNaN = isNaN( a ), bIsNaN = isNaN( b ); if ( aIsNaN && bIsNaN ) { diff --git a/modules/ve-mw/dm/models/ve.dm.MWTemplateSpecModel.js b/modules/ve-mw/dm/models/ve.dm.MWTemplateSpecModel.js index 621e800..1ee46c0 100644 --- a/modules/ve-mw/dm/models/ve.dm.MWTemplateSpecModel.js +++ b/modules/ve-mw/dm/models/ve.dm.MWTemplateSpecModel.js @@ -85,7 +85,7 @@ var key; for ( key in this.template.getParameters() ) { - if ( !this.params[key] ) { + if ( key && !this.params[key] ) { this.params[key] = this.getDefaultParameterSpec( key ); } } diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWTransclusionDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWTransclusionDialog.js index 8c6fc9b..ff15920 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWTransclusionDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWTransclusionDialog.js @@ -108,7 +108,13 @@ * @param {ve.dm.MWParameterModel} param Added param */ ve.ui.MWTransclusionDialog.prototype.onAddParameter = function ( param ) { - var page = new ve.ui.MWParameterPage( param, param.getId(), { '$': this.$ } ); + var page; + + if ( param.getName() ) { + page = new ve.ui.MWParameterPage( param, param.getId(), { '$': this.$ } ); + } else { + page = new ve.ui.MWParameterPlaceholderPage( param, param.getId(), { '$': this.$ } ); + } this.bookletLayout.addPages( [ page ], this.transclusion.getIndex( param ) ); if ( this.loaded ) { this.setPageByName( param.getId() ); diff --git a/modules/ve-mw/ui/pages/ve.ui.MWParameterPlaceholderPage.js b/modules/ve-mw/ui/pages/ve.ui.MWParameterPlaceholderPage.js new file mode 100644 index 0000000..91a35e3 --- /dev/null +++ b/modules/ve-mw/ui/pages/ve.ui.MWParameterPlaceholderPage.js @@ -0,0 +1,88 @@ +/*! + * VisualEditor user interface MWParameterPlaceholderPage class. + * + * @copyright 2011-2014 VisualEditor Team and others; see AUTHORS.txt + * @license The MIT License (MIT); see LICENSE.txt + */ + +/** + * MediaWiki transclusion dialog parameter placeholder page. + * + * @class + * @extends OO.ui.PageLayout + * + * @constructor + * @param {ve.dm.MWTemplateModel} parameter Template + * @param {string} name Unique symbolic name of page + * @param {Object} [config] Configuration options + */ +ve.ui.MWParameterPlaceholderPage = function VeUiMWParameterPlaceholderPage( parameter, name, config ) { + // Parent constructor + OO.ui.PageLayout.call( this, name, config ); + + // Properties + this.parameter = parameter; + this.template = this.parameter.getTemplate(); + this.addParameterSearch = new ve.ui.MWParameterSearchWidget( this.template, { '$': this.$ } ) + .connect( this, { 'select': 'onParameterSelect' } ); + this.removeButton = new OO.ui.ButtonWidget( { + '$': this.$, + 'frameless': true, + 'icon': 'remove', + 'title': ve.msg( 'visualeditor-dialog-transclusion-remove-param' ), + 'classes': [ 've-ui-mwTransclusionDialog-removeButton' ] + } ) + .connect( this, { 'click': 'onRemoveButtonClick' } ); + this.addParameterFieldset = new OO.ui.FieldsetLayout( { + '$': this.$, + 'label': ve.msg( 'visualeditor-dialog-transclusion-add-param' ), + 'icon': 'parameter', + 'classes': [ 've-ui-mwTransclusionDialog-addParameterFieldset' ], + '$content': this.addParameterSearch.$element + } ); + + // Initialization + this.$element.append( + this.addParameterFieldset.$element, + this.removeButton.$element + ); +}; + +/* Inheritance */ + +OO.inheritClass( ve.ui.MWParameterPlaceholderPage, OO.ui.PageLayout ); + +/* Methods */ + +/** + * @inheritdoc + */ +ve.ui.MWParameterPlaceholderPage.prototype.setOutlineItem = function ( outlineItem ) { + // Parent method + OO.ui.PageLayout.prototype.setOutlineItem.call( this, outlineItem ); + + if ( this.outlineItem ) { + this.outlineItem + .setIcon( 'parameter' ) + .setMovable( false ) + .setRemovable( true ) + .setLevel( 1 ) + .setFlags( [ 'placeholder' ] ) + .setLabel( ve.msg( 'visualeditor-dialog-transclusion-add-param' ) ); + } +}; + +ve.ui.MWParameterPlaceholderPage.prototype.onParameterSelect = function ( name ) { + var param; + + if ( name ) { + param = new ve.dm.MWParameterModel( this.template, name ); + this.addParameterSearch.query.setValue( '' ); + this.parameter.remove(); + this.template.addParameter( param ); + } +}; + +ve.ui.MWParameterPlaceholderPage.prototype.onRemoveButtonClick = function () { + this.parameter.remove(); +}; diff --git a/modules/ve-mw/ui/pages/ve.ui.MWTemplatePage.js b/modules/ve-mw/ui/pages/ve.ui.MWTemplatePage.js index 2c5d4e7..59dec28 100644 --- a/modules/ve-mw/ui/pages/ve.ui.MWTemplatePage.js +++ b/modules/ve-mw/ui/pages/ve.ui.MWTemplatePage.js @@ -17,16 +17,12 @@ * @param {Object} [config] Configuration options */ ve.ui.MWTemplatePage = function VeUiMWTemplatePage( template, name, config ) { - var spec = template.getSpec(); - // Parent constructor OO.ui.PageLayout.call( this, name, config ); // Properties this.template = template; - this.spec = spec; - this.addParameterSearch = new ve.ui.MWParameterSearchWidget( this.template, { '$': this.$ } ) - .connect( this, { 'select': 'onParameterSelect' } ); + this.spec = template.getSpec(); this.removeButton = new OO.ui.ButtonWidget( { '$': this.$, 'frameless': true, @@ -40,22 +36,13 @@ '$': this.$, 'label': this.spec.getLabel(), 'icon': 'template', - '$content': this.$( '<div>' ).text( this.template.getSpec().getDescription() || '' ) - } ); - this.addParameterFieldset = new OO.ui.FieldsetLayout( { - '$': this.$, - 'label': ve.msg( 'visualeditor-dialog-transclusion-add-param' ), - 'icon': 'parameter', - 'classes': [ 've-ui-mwTransclusionDialog-addParameterFieldset' ], - '$content': this.addParameterSearch.$element + '$content': this.$( '<div>' ).text( this.spec.getDescription() || '' ) } ); // Initialization - this.$element.append( - this.infoFieldset.$element, - this.addParameterFieldset.$element, - this.removeButton.$element - ); + this.$element + .addClass( 've-ui-mwTemplatePage' ) + .append( this.infoFieldset.$element, this.removeButton.$element ); }; /* Inheritance */ @@ -77,16 +64,6 @@ .setMovable( true ) .setRemovable( true ) .setLabel( this.spec.getLabel() ); - } -}; - -ve.ui.MWTemplatePage.prototype.onParameterSelect = function ( name ) { - var param; - - if ( name ) { - param = new ve.dm.MWParameterModel( this.template, name ); - this.template.addParameter( param ); - this.addParameterSearch.query.setValue(); } }; -- To view, visit https://gerrit.wikimedia.org/r/116007 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I56c3df1ada6c4f41ebf6466ca280a2333da60071 Gerrit-PatchSet: 7 Gerrit-Project: mediawiki/extensions/VisualEditor Gerrit-Branch: master Gerrit-Owner: Trevor Parscal <tpars...@wikimedia.org> Gerrit-Reviewer: Catrope <roan.katt...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits