mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-11 05:56:11 +00:00
Refactor onReplacePart in TemplateDialog
As preparation to introduce then new UI to add unknown parameters. This is a few things: - Merge the code paths when adding a MWTemplateModel - Put code adding parameters to the dialog next to each other so that preventing reselection happens around that block - Reduce duplicated code when re-focusing after addition - Move adding the placeholder page to the end - Add and clean up inline documentation Bug: T272487 Change-Id: Ic700edd42027a928a236ed11f2c257fffe994257
This commit is contained in:
parent
d41714f3a1
commit
eeda931f59
|
@ -98,7 +98,7 @@ ve.ui.MWTemplateDialog.prototype.onTransclusionModelChange = function () {
|
||||||
* @param {ve.dm.MWTransclusionPartModel|null} added Added part
|
* @param {ve.dm.MWTransclusionPartModel|null} added Added part
|
||||||
*/
|
*/
|
||||||
ve.ui.MWTemplateDialog.prototype.onReplacePart = function ( removed, added ) {
|
ve.ui.MWTemplateDialog.prototype.onReplacePart = function ( removed, added ) {
|
||||||
var names, reselect,
|
var reselect,
|
||||||
removePages = [];
|
removePages = [];
|
||||||
|
|
||||||
if ( removed ) {
|
if ( removed ) {
|
||||||
|
@ -127,32 +127,27 @@ ve.ui.MWTemplateDialog.prototype.onReplacePart = function ( removed, added ) {
|
||||||
// Use added page instead of closest page
|
// Use added page instead of closest page
|
||||||
this.transclusions.focusPart( added.getId() );
|
this.transclusions.focusPart( added.getId() );
|
||||||
}
|
}
|
||||||
// Add existing params to templates (the template might be being moved)
|
|
||||||
if ( added instanceof ve.dm.MWTemplateModel ) {
|
if ( added instanceof ve.dm.MWTemplateModel ) {
|
||||||
names = added.getOrderedParameterNames();
|
// Prevent selection changes while parameters are added
|
||||||
// Prevent selection changes
|
|
||||||
this.preventReselection = true;
|
this.preventReselection = true;
|
||||||
|
|
||||||
|
// Add existing params to templates (the template might be being moved)
|
||||||
|
var names = added.getOrderedParameterNames();
|
||||||
for ( var i = 0; i < names.length; i++ ) {
|
for ( var i = 0; i < names.length; i++ ) {
|
||||||
this.onAddParameter( added.getParameter( names[ i ] ) );
|
this.onAddParameter( added.getParameter( names[ i ] ) );
|
||||||
}
|
}
|
||||||
this.preventReselection = false;
|
|
||||||
added.connect( this, { add: 'onAddParameter', remove: 'onRemoveParameter' } );
|
added.connect( this, { add: 'onAddParameter', remove: 'onRemoveParameter' } );
|
||||||
if ( names.length ) {
|
|
||||||
this.transclusions.focusPart( added.getParameter( names[ 0 ] ).getId() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add required and suggested params to user created templates
|
// Add required and suggested params to user created templates
|
||||||
if ( added instanceof ve.dm.MWTemplateModel && this.loaded ) {
|
var shouldAddPlaceholder = this.loaded && added.addPromptedParameters() === 0;
|
||||||
// Prevent selection changes
|
|
||||||
this.preventReselection = true;
|
|
||||||
var addedCount = added.addPromptedParameters();
|
|
||||||
this.preventReselection = false;
|
this.preventReselection = false;
|
||||||
names = added.getOrderedParameterNames();
|
|
||||||
if ( names.length ) {
|
if ( names.length ) {
|
||||||
|
// Focus the first element when parameters are present
|
||||||
this.transclusions.focusPart( added.getParameter( names[ 0 ] ).getId() );
|
this.transclusions.focusPart( added.getParameter( names[ 0 ] ).getId() );
|
||||||
} else if ( addedCount === 0 && !this.isNewSidebar ) {
|
} else if ( shouldAddPlaceholder && !this.isNewSidebar ) {
|
||||||
// This adds a placeholder, i.e. the parameter search widget appears
|
|
||||||
page.addPlaceholderParameter();
|
page.addPlaceholderParameter();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue