2014-04-10 19:07:40 +00:00
|
|
|
/*
|
|
|
|
* VisualEditor user interface MWTemplateDialog class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2014 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2014-10-07 00:06:02 +00:00
|
|
|
/* global mw */
|
|
|
|
|
2014-04-10 19:07:40 +00:00
|
|
|
/**
|
|
|
|
* Dialog for inserting and editing MediaWiki transclusions.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @abstract
|
2014-04-24 00:22:45 +00:00
|
|
|
* @extends ve.ui.NodeDialog
|
2014-04-10 19:07:40 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
2014-08-21 00:50:54 +00:00
|
|
|
ve.ui.MWTemplateDialog = function VeUiMWTemplateDialog( config ) {
|
2014-04-10 19:07:40 +00:00
|
|
|
// Parent constructor
|
2014-08-21 00:50:54 +00:00
|
|
|
ve.ui.MWTemplateDialog.super.call( this, config );
|
2014-04-10 19:07:40 +00:00
|
|
|
|
|
|
|
// Properties
|
2014-04-24 00:22:45 +00:00
|
|
|
this.transclusionModel = null;
|
2014-04-10 19:07:40 +00:00
|
|
|
this.loaded = false;
|
|
|
|
this.preventReselection = false;
|
2014-08-27 15:44:07 +00:00
|
|
|
|
|
|
|
this.confirmOverlay = new ve.ui.Overlay( { classes: ['ve-ui-overlay-global'] } );
|
2014-11-21 21:58:53 +00:00
|
|
|
this.confirmDialogs = new ve.ui.WindowManager( { factory: ve.ui.windowFactory, isolate: true } );
|
2014-08-27 15:44:07 +00:00
|
|
|
this.confirmOverlay.$element.append( this.confirmDialogs.$element );
|
|
|
|
$( 'body' ).append( this.confirmOverlay.$element );
|
2014-04-10 19:07:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2014-04-24 00:22:45 +00:00
|
|
|
OO.inheritClass( ve.ui.MWTemplateDialog, ve.ui.NodeDialog );
|
2014-04-10 19:07:40 +00:00
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.ui.MWTemplateDialog.static.icon = 'template';
|
|
|
|
|
2014-04-24 00:22:45 +00:00
|
|
|
ve.ui.MWTemplateDialog.static.modelClasses = [ ve.dm.MWTransclusionNode ];
|
2014-04-10 19:07:40 +00:00
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
ve.ui.MWTemplateDialog.static.actions = [
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
action: 'apply',
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-action-apply' ),
|
|
|
|
flags: 'primary',
|
|
|
|
modes: 'edit'
|
2014-07-14 21:32:49 +00:00
|
|
|
},
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
action: 'insert',
|
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-action-insert' ),
|
|
|
|
flags: [ 'primary', 'constructive' ],
|
|
|
|
modes: 'insert'
|
2014-07-14 21:32:49 +00:00
|
|
|
},
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
label: OO.ui.deferMsg( 'visualeditor-dialog-action-cancel' ),
|
|
|
|
flags: 'safe',
|
|
|
|
modes: [ 'insert', 'edit' ]
|
2014-07-14 21:32:49 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2014-04-24 00:22:45 +00:00
|
|
|
/**
|
|
|
|
* Configuration for booklet layout.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @property {Object}
|
|
|
|
* @inheritable
|
|
|
|
*/
|
2014-04-10 19:07:40 +00:00
|
|
|
ve.ui.MWTemplateDialog.static.bookletLayoutConfig = {
|
2014-08-22 20:50:48 +00:00
|
|
|
continuous: true,
|
|
|
|
outlined: false
|
2014-04-10 19:07:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the transclusion being ready to use.
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.onTransclusionReady = function () {
|
|
|
|
this.loaded = true;
|
2014-04-17 22:06:11 +00:00
|
|
|
this.$element.addClass( 've-ui-mwTemplateDialog-ready' );
|
|
|
|
this.popPending();
|
2014-04-10 19:07:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle parts being replaced.
|
|
|
|
*
|
|
|
|
* @param {ve.dm.MWTransclusionPartModel} removed Removed part
|
|
|
|
* @param {ve.dm.MWTransclusionPartModel} added Added part
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.onReplacePart = function ( removed, added ) {
|
2014-10-24 22:14:01 +00:00
|
|
|
var i, len, page, name, names, params, partPage, reselect, addedCount,
|
2014-04-10 19:07:40 +00:00
|
|
|
removePages = [];
|
|
|
|
|
|
|
|
if ( removed ) {
|
|
|
|
// Remove parameter pages of removed templates
|
|
|
|
partPage = this.bookletLayout.getPage( removed.getId() );
|
|
|
|
if ( removed instanceof ve.dm.MWTemplateModel ) {
|
|
|
|
params = removed.getParameters();
|
|
|
|
for ( name in params ) {
|
|
|
|
removePages.push( this.bookletLayout.getPage( params[name].getId() ) );
|
|
|
|
}
|
|
|
|
removed.disconnect( this );
|
|
|
|
}
|
|
|
|
if ( this.loaded && !this.preventReselection && partPage.isActive() ) {
|
|
|
|
reselect = this.bookletLayout.getClosestPage( partPage );
|
|
|
|
}
|
|
|
|
removePages.push( partPage );
|
|
|
|
this.bookletLayout.removePages( removePages );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( added ) {
|
|
|
|
page = this.getPageFromPart( added );
|
|
|
|
if ( page ) {
|
2014-04-24 00:22:45 +00:00
|
|
|
this.bookletLayout.addPages( [ page ], this.transclusionModel.getIndex( added ) );
|
2014-04-10 19:07:40 +00:00
|
|
|
if ( reselect ) {
|
|
|
|
// Use added page instead of closest page
|
|
|
|
this.setPageByName( added.getId() );
|
|
|
|
}
|
|
|
|
// Add existing params to templates (the template might be being moved)
|
|
|
|
if ( added instanceof ve.dm.MWTemplateModel ) {
|
|
|
|
names = added.getParameterNames();
|
|
|
|
params = added.getParameters();
|
|
|
|
// Prevent selection changes
|
|
|
|
this.preventReselection = true;
|
|
|
|
for ( i = 0, len = names.length; i < len; i++ ) {
|
|
|
|
this.onAddParameter( params[names[i]] );
|
|
|
|
}
|
|
|
|
this.preventReselection = false;
|
2014-08-22 20:50:48 +00:00
|
|
|
added.connect( this, { add: 'onAddParameter', remove: 'onRemoveParameter' } );
|
2014-04-10 19:07:40 +00:00
|
|
|
if ( names.length ) {
|
|
|
|
this.setPageByName( params[names[0]].getId() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-28 19:10:31 +00:00
|
|
|
// Add required and suggested params to user created templates
|
2014-04-10 19:07:40 +00:00
|
|
|
if ( added instanceof ve.dm.MWTemplateModel && this.loaded ) {
|
|
|
|
// Prevent selection changes
|
|
|
|
this.preventReselection = true;
|
2014-07-21 21:06:54 +00:00
|
|
|
addedCount = added.addPromptedParameters();
|
2014-04-10 19:07:40 +00:00
|
|
|
this.preventReselection = false;
|
|
|
|
names = added.getParameterNames();
|
|
|
|
params = added.getParameters();
|
|
|
|
if ( names.length ) {
|
|
|
|
this.setPageByName( params[names[0]].getId() );
|
2014-07-21 21:06:54 +00:00
|
|
|
} else if ( addedCount === 0 ) {
|
|
|
|
page.onAddButtonFocus();
|
2014-04-10 19:07:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if ( reselect ) {
|
|
|
|
this.setPageByName( reselect.getName() );
|
|
|
|
}
|
2014-07-14 21:32:49 +00:00
|
|
|
|
2014-10-24 22:14:01 +00:00
|
|
|
this.setApplicableStatus();
|
2014-07-14 21:32:49 +00:00
|
|
|
|
2014-04-10 19:07:40 +00:00
|
|
|
this.updateTitle();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle add param events.
|
|
|
|
*
|
|
|
|
* @param {ve.dm.MWParameterModel} param Added param
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.onAddParameter = function ( param ) {
|
|
|
|
var page;
|
|
|
|
|
|
|
|
if ( param.getName() ) {
|
2014-08-22 20:50:48 +00:00
|
|
|
page = new ve.ui.MWParameterPage( param, param.getId(), { $: this.$ } );
|
2014-04-10 19:07:40 +00:00
|
|
|
} else {
|
2014-08-22 20:50:48 +00:00
|
|
|
page = new ve.ui.MWParameterPlaceholderPage( param, param.getId(), { $: this.$ } );
|
2014-04-10 19:07:40 +00:00
|
|
|
}
|
2014-04-24 00:22:45 +00:00
|
|
|
this.bookletLayout.addPages( [ page ], this.transclusionModel.getIndex( param ) );
|
2014-04-10 19:07:40 +00:00
|
|
|
if ( this.loaded && !this.preventReselection ) {
|
|
|
|
this.setPageByName( param.getId() );
|
2014-05-30 19:34:23 +00:00
|
|
|
} else {
|
|
|
|
this.onAddParameterBeforeLoad( page );
|
2014-04-10 19:07:40 +00:00
|
|
|
}
|
2014-06-03 19:38:09 +00:00
|
|
|
|
|
|
|
// Recalculate tab indexes
|
|
|
|
this.$body.find( '.ve-ui-mwParameterPage' ).each( function ( index ) {
|
|
|
|
$( this )
|
|
|
|
.find( '.ve-ui-mwParameterPage-field > .oo-ui-textInputWidget > textarea' )
|
|
|
|
.attr( 'tabindex', index * 3 + 1 )
|
|
|
|
.end()
|
2014-06-27 20:48:59 +00:00
|
|
|
.find( '.ve-ui-mwParameterPage-infoButton' )
|
2014-06-03 19:38:09 +00:00
|
|
|
.attr( 'tabindex', index * 3 + 2 )
|
|
|
|
.end()
|
2014-06-27 20:48:59 +00:00
|
|
|
.find( '.ve-ui-mwParameterPage-removeButton' )
|
2014-07-21 21:06:54 +00:00
|
|
|
.attr( 'tabindex', index * 3 + 3 )
|
|
|
|
.end()
|
|
|
|
.find( '.ve-ui-mwParameterPage-more' )
|
|
|
|
.attr( 'tabindex', index * 3 + 4 );
|
2014-06-03 19:38:09 +00:00
|
|
|
} );
|
2014-04-10 19:07:40 +00:00
|
|
|
};
|
|
|
|
|
2014-05-30 19:34:23 +00:00
|
|
|
/**
|
|
|
|
* Additional handling of parameter addition events before loading.
|
|
|
|
*
|
|
|
|
* @param {ve.ui.MWParameterPage} page Parameter page object
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.onAddParameterBeforeLoad = function () {};
|
|
|
|
|
2014-04-10 19:07:40 +00:00
|
|
|
/**
|
|
|
|
* Handle remove param events.
|
|
|
|
*
|
|
|
|
* @param {ve.dm.MWParameterModel} param Removed param
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.onRemoveParameter = function ( param ) {
|
|
|
|
var page = this.bookletLayout.getPage( param.getId() ),
|
|
|
|
reselect = this.bookletLayout.getClosestPage( page );
|
|
|
|
|
|
|
|
this.bookletLayout.removePages( [ page ] );
|
|
|
|
if ( this.loaded && !this.preventReselection ) {
|
|
|
|
this.setPageByName( reselect.getName() );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-10-24 22:14:01 +00:00
|
|
|
* Sets transclusion applicable status
|
2014-04-10 19:07:40 +00:00
|
|
|
*
|
|
|
|
* If the transclusion is empty or only contains a placeholder it will not be insertable.
|
2014-10-24 22:14:01 +00:00
|
|
|
* If the transclusion only contains a placeholder it will not be editable.
|
2014-04-10 19:07:40 +00:00
|
|
|
*/
|
2014-10-24 22:14:01 +00:00
|
|
|
ve.ui.MWTemplateDialog.prototype.setApplicableStatus = function () {
|
2014-04-24 00:22:45 +00:00
|
|
|
var parts = this.transclusionModel && this.transclusionModel.getParts();
|
2014-04-10 19:07:40 +00:00
|
|
|
|
2014-10-24 22:14:01 +00:00
|
|
|
if ( this.loading.state() !== 'resolved' ) {
|
|
|
|
this.actions.setAbilities( { apply: false, insert: false } );
|
|
|
|
} else if ( parts.length && !( parts[0] instanceof ve.dm.MWTemplatePlaceholderModel ) ) {
|
|
|
|
this.actions.setAbilities( { apply: true, insert: true } );
|
|
|
|
} else {
|
|
|
|
this.actions.setAbilities( { apply: parts.length === 0, insert: false } );
|
|
|
|
}
|
2014-04-10 19:07:40 +00:00
|
|
|
};
|
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.getBodyHeight = function () {
|
2014-07-19 02:14:30 +00:00
|
|
|
return 400;
|
2014-07-14 21:32:49 +00:00
|
|
|
};
|
|
|
|
|
2014-04-10 19:07:40 +00:00
|
|
|
/**
|
|
|
|
* Get a page for a transclusion part.
|
|
|
|
*
|
|
|
|
* @param {ve.dm.MWTransclusionModel} part Part to get page for
|
|
|
|
* @return {OO.ui.PageLayout|null} Page for part, null if no matching page could be found
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.getPageFromPart = function ( part ) {
|
|
|
|
if ( part instanceof ve.dm.MWTemplateModel ) {
|
2014-08-22 20:50:48 +00:00
|
|
|
return new ve.ui.MWTemplatePage( part, part.getId(), { $: this.$ } );
|
2014-04-10 19:07:40 +00:00
|
|
|
} else if ( part instanceof ve.dm.MWTemplatePlaceholderModel ) {
|
2014-10-28 00:36:19 +00:00
|
|
|
return new ve.ui.MWTemplatePlaceholderPage(
|
|
|
|
part,
|
|
|
|
part.getId(),
|
|
|
|
{ $: this.$, $overlay: this.$overlay }
|
|
|
|
);
|
2014-04-10 19:07:40 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the label of a template or template placeholder.
|
|
|
|
*
|
|
|
|
* @param {ve.dm.MWTemplateModel|ve.dm.MWTemplatePlaceholderModel} part Part to check
|
|
|
|
* @returns {string} Label of template or template placeholder
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.getTemplatePartLabel = function ( part ) {
|
|
|
|
return part instanceof ve.dm.MWTemplateModel ?
|
|
|
|
part.getSpec().getLabel() : ve.msg( 'visualeditor-dialog-transclusion-placeholder' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-04-24 00:22:45 +00:00
|
|
|
* @inheritdoc
|
2014-04-10 19:07:40 +00:00
|
|
|
*/
|
2014-04-24 00:22:45 +00:00
|
|
|
ve.ui.MWTemplateDialog.prototype.getSelectedNode = function ( data ) {
|
|
|
|
var selectedNode = ve.ui.MWTemplateDialog.super.prototype.getSelectedNode.call( this );
|
|
|
|
|
|
|
|
// Data initialization
|
|
|
|
data = data || {};
|
|
|
|
|
|
|
|
// Require template to match if specified
|
|
|
|
if ( selectedNode && data.template && !selectedNode.isSingleTemplate( data.template ) ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return selectedNode;
|
2014-04-10 19:07:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the page by name.
|
|
|
|
*
|
|
|
|
* Page names are always the ID of the part or param they represent.
|
|
|
|
*
|
|
|
|
* @param {string} name Page name
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.setPageByName = function ( name ) {
|
|
|
|
if ( this.bookletLayout.isOutlined() ) {
|
|
|
|
this.bookletLayout.getOutline().selectItem(
|
|
|
|
this.bookletLayout.getOutline().getItemFromData( name )
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
this.bookletLayout.setPage( name );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the dialog title.
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.updateTitle = function () {
|
2014-04-24 00:22:45 +00:00
|
|
|
var parts = this.transclusionModel && this.transclusionModel.getParts();
|
2014-04-10 19:07:40 +00:00
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
this.title.setLabel(
|
2014-04-10 19:07:40 +00:00
|
|
|
parts && parts.length === 1 && parts[0] ?
|
|
|
|
this.getTemplatePartLabel( parts[0] ) :
|
2014-04-24 00:22:45 +00:00
|
|
|
ve.msg( 'visualeditor-dialog-transclusion-loading' )
|
2014-04-10 19:07:40 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.initialize = function () {
|
|
|
|
// Parent method
|
|
|
|
ve.ui.MWTemplateDialog.super.prototype.initialize.call( this );
|
|
|
|
|
|
|
|
// Properties
|
2014-08-22 20:50:48 +00:00
|
|
|
this.panels = new OO.ui.StackLayout( { $: this.$ } );
|
2014-04-10 19:07:40 +00:00
|
|
|
this.bookletLayout = new OO.ui.BookletLayout(
|
|
|
|
ve.extendObject(
|
2014-08-22 20:50:48 +00:00
|
|
|
{ $: this.$ },
|
2014-04-10 19:07:40 +00:00
|
|
|
this.constructor.static.bookletLayoutConfig
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Initialization
|
2014-08-21 00:50:54 +00:00
|
|
|
this.$content.addClass( 've-ui-mwTemplateDialog' );
|
2014-07-14 21:32:49 +00:00
|
|
|
this.$body.append( this.panels.$element );
|
2014-04-24 00:22:45 +00:00
|
|
|
this.panels.addItems( [ this.bookletLayout ] );
|
2014-04-10 19:07:40 +00:00
|
|
|
};
|
|
|
|
|
2014-08-27 15:44:07 +00:00
|
|
|
/**
|
|
|
|
* If the user has left blank required parameters, confirm that they actually want to do this.
|
|
|
|
* If no required parameters were left blank, or if they were but the user decided to go ahead
|
|
|
|
* anyway, the returned deferred will be resolved.
|
|
|
|
* Otherwise, the returned deferred will be rejected.
|
|
|
|
* @returns {jQuery.Deferred}
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.checkRequiredParameters = function () {
|
|
|
|
var blankRequired = [], deferred = $.Deferred();
|
|
|
|
$.each( this.bookletLayout.pages, function () {
|
|
|
|
if ( !( this instanceof ve.ui.MWParameterPage ) ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if ( this.parameter.isRequired() && !this.valueInput.getValue() ) {
|
|
|
|
blankRequired.push( mw.msg(
|
|
|
|
'quotation-marks',
|
|
|
|
this.parameter.template.getSpec().getParameterLabel( this.parameter.getName() )
|
|
|
|
) );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
if ( blankRequired.length ) {
|
|
|
|
this.confirmDialogs.openWindow( 'requiredparamblankconfirm', {
|
|
|
|
message: mw.msg(
|
|
|
|
'visualeditor-dialog-transclusion-required-parameter-is-blank',
|
|
|
|
mw.language.listToText( blankRequired ),
|
|
|
|
blankRequired.length
|
|
|
|
),
|
|
|
|
title: mw.msg(
|
|
|
|
'visualeditor-dialog-transclusion-required-parameter-dialog-title',
|
|
|
|
blankRequired.length
|
|
|
|
)
|
|
|
|
} ).then( function ( opened ) {
|
|
|
|
opened.then( function ( closing ) {
|
|
|
|
closing.then( function ( data ) {
|
|
|
|
if ( data.action === 'ok' ) {
|
|
|
|
deferred.resolve();
|
|
|
|
} else {
|
|
|
|
deferred.reject();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} else {
|
|
|
|
deferred.resolve();
|
|
|
|
}
|
|
|
|
return deferred.promise();
|
|
|
|
};
|
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.getActionProcess = function ( action ) {
|
|
|
|
if ( action === 'apply' || action === 'insert' ) {
|
|
|
|
return new OO.ui.Process( function () {
|
2014-08-27 15:44:07 +00:00
|
|
|
var deferred = $.Deferred();
|
|
|
|
this.checkRequiredParameters().done( function () {
|
|
|
|
var surfaceModel = this.getFragment().getSurface(),
|
|
|
|
obj = this.transclusionModel.getPlainObject();
|
|
|
|
|
|
|
|
if ( this.selectedNode instanceof ve.dm.MWTransclusionNode ) {
|
|
|
|
this.transclusionModel.updateTransclusionNode( surfaceModel, this.selectedNode );
|
|
|
|
} else if ( obj !== null ) {
|
|
|
|
// Collapse returns a new fragment, so update this.fragment
|
2014-09-30 16:34:33 +00:00
|
|
|
this.fragment = this.getFragment().collapseToEnd();
|
2014-08-27 15:44:07 +00:00
|
|
|
this.transclusionModel.insertTransclusionNode( this.getFragment() );
|
|
|
|
}
|
|
|
|
|
|
|
|
this.close( { action: action } );
|
|
|
|
}.bind( this ) ).always( function () {
|
|
|
|
deferred.resolve();
|
|
|
|
} );
|
2014-07-14 21:32:49 +00:00
|
|
|
|
2014-08-27 15:44:07 +00:00
|
|
|
return deferred;
|
2014-07-14 21:32:49 +00:00
|
|
|
}, this );
|
|
|
|
}
|
|
|
|
|
|
|
|
return ve.ui.MWTemplateDialog.super.prototype.getActionProcess.call( this, action );
|
|
|
|
};
|
|
|
|
|
2014-04-10 19:07:40 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2014-05-31 04:47:08 +00:00
|
|
|
ve.ui.MWTemplateDialog.prototype.getSetupProcess = function ( data ) {
|
2014-07-15 22:49:51 +00:00
|
|
|
data = data || {};
|
2014-05-31 04:47:08 +00:00
|
|
|
return ve.ui.MWTemplateDialog.super.prototype.getSetupProcess.call( this, data )
|
|
|
|
.next( function () {
|
|
|
|
var template, promise;
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.loaded = false;
|
|
|
|
this.transclusionModel = new ve.dm.MWTransclusionModel();
|
|
|
|
|
|
|
|
// Events
|
2014-08-22 20:50:48 +00:00
|
|
|
this.transclusionModel.connect( this, { replace: 'onReplacePart' } );
|
2014-05-31 04:47:08 +00:00
|
|
|
|
|
|
|
// Initialization
|
|
|
|
if ( !this.selectedNode ) {
|
2014-07-14 21:32:49 +00:00
|
|
|
this.actions.setMode( 'insert' );
|
2014-05-31 04:47:08 +00:00
|
|
|
if ( data.template ) {
|
|
|
|
// New specified template
|
|
|
|
template = ve.dm.MWTemplateModel.newFromName(
|
|
|
|
this.transclusionModel, data.template
|
|
|
|
);
|
2014-10-14 19:27:26 +00:00
|
|
|
promise = this.transclusionModel.addPart( template ).done(
|
2014-10-29 01:43:03 +00:00
|
|
|
this.initializeNewTemplateParameters.bind( this )
|
2014-10-14 19:27:26 +00:00
|
|
|
);
|
2014-05-31 04:47:08 +00:00
|
|
|
} else {
|
|
|
|
// New template placeholder
|
|
|
|
promise = this.transclusionModel.addPart(
|
|
|
|
new ve.dm.MWTemplatePlaceholderModel( this.transclusionModel )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
2014-07-14 21:32:49 +00:00
|
|
|
this.actions.setMode( 'edit' );
|
2014-05-31 04:47:08 +00:00
|
|
|
// Load existing template
|
|
|
|
promise = this.transclusionModel
|
2014-10-07 00:06:02 +00:00
|
|
|
.load( ve.copy( this.selectedNode.getAttribute( 'mw' ) ) )
|
2014-10-29 01:43:03 +00:00
|
|
|
.done( this.initializeTemplateParameters.bind( this ) );
|
2014-05-31 04:47:08 +00:00
|
|
|
}
|
2014-08-22 20:50:48 +00:00
|
|
|
this.actions.setAbilities( { apply: false, insert: false } );
|
2014-05-31 04:47:08 +00:00
|
|
|
this.pushPending();
|
2014-07-08 22:33:32 +00:00
|
|
|
promise.always( this.onTransclusionReady.bind( this ) );
|
2014-05-31 04:47:08 +00:00
|
|
|
}, this );
|
2014-04-10 19:07:40 +00:00
|
|
|
};
|
|
|
|
|
2014-10-07 00:06:02 +00:00
|
|
|
/**
|
|
|
|
* Initialize parameters for new template insertion
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.initializeNewTemplateParameters = function () {
|
|
|
|
var i, parts = this.transclusionModel.getParts();
|
|
|
|
for ( i = 0; i < parts.length; i++ ) {
|
|
|
|
if ( parts[i] instanceof ve.dm.MWTemplateModel ) {
|
|
|
|
parts[i].addPromptedParameters();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Intentionally empty. This is provided for Wikia extensibility.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.initializeTemplateParameters = function () {};
|
|
|
|
|
2014-04-10 19:07:40 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2014-05-31 04:47:08 +00:00
|
|
|
ve.ui.MWTemplateDialog.prototype.getTeardownProcess = function ( data ) {
|
|
|
|
return ve.ui.MWTemplateDialog.super.prototype.getTeardownProcess.call( this, data )
|
|
|
|
.first( function () {
|
|
|
|
// Cleanup
|
|
|
|
this.$element.removeClass( 've-ui-mwTemplateDialog-ready' );
|
|
|
|
this.transclusionModel.disconnect( this );
|
|
|
|
this.transclusionModel.abortRequests();
|
|
|
|
this.transclusionModel = null;
|
|
|
|
this.bookletLayout.clearPages();
|
|
|
|
this.content = null;
|
|
|
|
}, this );
|
2014-04-10 19:07:40 +00:00
|
|
|
};
|