Auto-select first auto-added required param and fix param order

Symptoms:
* When adding a template with required parameters, the last parameter
  is initially focused
* Parameters and parts appear out of order, and adding/remove/moving
  them shows them in almost random placement

Diagnoses:
* Parameters are auto-focused when added, and parameters are auto-added
  in forward order
* TransclusionModel's process method had a bug in which the code to
  derive an offset from the item being removed would not be reachable
  due to an inverted logic statement

Prognosis:
* Fatal, with a 10% chance of survival

Treatment:
* Set focus on the first parameter after auto-adding required
  parameters to a template
* Invert the logic in TransclusionModel's process method, so that if
  the index IS undefined we will proceed to define it

Change-Id: I299053b63045ec933747831f1b4aa63493760f8b
This commit is contained in:
Trevor Parscal 2014-02-05 11:11:41 -08:00
parent 8e4fe35f87
commit d487b44dd0
3 changed files with 11 additions and 4 deletions

View file

@ -114,17 +114,20 @@ ve.dm.MWTransclusionModel.prototype.process = function ( queue ) {
// Auto-remove if already existing
this.removePart( item.add );
// Add at index, or end if none was given
// Use specified index
index = item.index;
if ( index !== undefined && item.remove ) {
// Derive index from removal if given
if ( index === undefined && item.remove ) {
index = ve.indexOf( item.remove, this.parts );
if ( index !== -1 ) {
remove = 1;
}
}
// Use last index as a last resort
if ( index === undefined || index === -1 ) {
index = this.parts.length;
}
this.parts.splice( index, remove, item.add );
if ( item.add ) {
item.add.connect( this, { 'change': [ 'emit', 'change' ] } );

View file

@ -92,6 +92,11 @@ ve.ui.MWTransclusionDialog.prototype.onReplacePart = function ( removed, added )
// Add required params to user created templates
if ( added instanceof ve.dm.MWTemplateModel && this.loaded ) {
added.addRequiredParameters();
names = added.getParameterNames();
params = added.getParameters();
if ( names.length ) {
this.setPageByName( params[names[0]].getId() );
}
}
}
}

View file

@ -71,10 +71,9 @@ OO.inheritClass( ve.ui.MWTemplatePlaceholderPage, OO.ui.PageLayout );
ve.ui.MWTemplatePlaceholderPage.prototype.onAddTemplate = function () {
var transclusion = this.placeholder.getTransclusion(),
parts = this.placeholder.getTransclusion().getParts(),
part = ve.dm.MWTemplateModel.newFromName( transclusion, this.addTemplateInput.getValue() );
transclusion.replacePart( this.placeholder, part, ve.indexOf( this.placeholder, parts ) );
transclusion.replacePart( this.placeholder, part );
this.addTemplateInput.pushPending();
this.addTemplateButton.setDisabled( true );
this.removeButton.setDisabled( true );