2013-12-02 20:10:55 +00:00
|
|
|
/*
|
2013-06-11 19:16:04 +00:00
|
|
|
* VisualEditor user interface MWTransclusionDialog class.
|
|
|
|
*
|
2014-01-05 12:05:05 +00:00
|
|
|
* @copyright 2011-2014 VisualEditor Team and others; see AUTHORS.txt
|
2013-06-11 19:16:04 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
Single-click insertion
Objectives:
* Reduce the number of clicks and mouse maneuvers required to insert
media, references or template parameters
* Make use of highlighting with mouse movement or arrow key presses,
similar to menus, to suggest action when clicked
* Improve the way media search results look and feel
Changes:
ve.ui.SelectWidget.js
* Add mouseleave handler to un-highlight when the mouse exits the widget
* Document highlight events (already being emitted)
ve.ui.SearchWidget.js
* Propagate both select and highlight events from results widget
* Make arrow keys change highlight instead of selection
* Get rid of enter event, make enter key select highlighted item instead
* Provide direct access to results widget through getResults method
ve.ui.MenuWidget.js
* Use the selected item as a starting point if nothing is currently
highlighted when adjusting the highlight position
ve.ui.Dialog.js
* Add footless option to hide the foot element and make the body extend
all the way down to the bottom
* Remove applyButton, which only some dialogs need, and should be creating
themselves, along with other buttons as needed
ve.ui.Widget.css
* Change highlight and selected colors of option widgets to match other
selection colors used elsewhere
* Leave selected and highlighted widget looking selected
ve.ui.Frame.css
* Add background color to combat any color that might have been applied to
the frame body in the imported CSS from the parent frame
ve.ui.Dialog.css
* Add rules for footless mode
ve.ui.MWReferenceResultWidget.js,
ve.ui.MWParameterResultWidget.js,
ve.ui.MWMediaResultWidget.js
* Allow highlighting
ve.ui.MWParamterSearchWidget.js
* Switch from selecting the first item when filtering to highlighting
ve-mw/ve.ui.Widget.js
* Adjust media result widget styling to better match other elements
ve.ui.MWTransclusionDialog.js,
ve.ui.MWReferenceListDialog.js,
ve.ui.MWReferenceEditDialog.js,
ve.ui.MWMetaDialog.js
ve.ui.MWMediaEditDialog.js
* Add apply button, as per it being removed from parent class
ve.ui.MWTransclusionDialog.js,
ve.ui.MWReferenceInsertDialog.js,
ve.ui.MWMediaInsertDialog.js
* Insert parameter/reference/media on select, instead of clicking an
insert button
* Use 'insert' instead of 'apply' as argument for close method
Bug: 50774
Bug: 51143
Change-Id: Ia18e79f1f8df2540f465468edb01f5ce989bf843
2013-07-15 21:07:53 +00:00
|
|
|
* Dialog for inserting and editing MediaWiki transclusions.
|
2013-06-11 19:16:04 +00:00
|
|
|
*
|
|
|
|
* @class
|
2013-07-03 01:30:10 +00:00
|
|
|
* @extends ve.ui.MWDialog
|
2013-06-11 19:16:04 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
2014-03-06 01:07:20 +00:00
|
|
|
* @param {ve.ui.Surface} surface Surface inspector is for
|
2013-09-25 10:21:09 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
2014-03-06 01:07:20 +00:00
|
|
|
ve.ui.MWTransclusionDialog = function VeUiMWTransclusionDialog( surface, config ) {
|
2013-06-11 19:16:04 +00:00
|
|
|
// Parent constructor
|
2014-03-06 01:07:20 +00:00
|
|
|
ve.ui.MWDialog.call( this, surface, config );
|
2013-07-03 01:30:10 +00:00
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
// Properties
|
|
|
|
this.node = null;
|
|
|
|
this.transclusion = null;
|
2013-12-02 20:10:55 +00:00
|
|
|
this.loaded = false;
|
2014-02-28 00:06:34 +00:00
|
|
|
this.preventReselection = false;
|
2014-03-04 22:56:14 +00:00
|
|
|
this.mode = null;
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-10-11 21:44:09 +00:00
|
|
|
OO.inheritClass( ve.ui.MWTransclusionDialog, ve.ui.MWDialog );
|
2013-07-03 01:30:10 +00:00
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/* Static Properties */
|
|
|
|
|
2014-03-04 22:56:14 +00:00
|
|
|
ve.ui.MWTransclusionDialog.static.name = 'transclusion';
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
ve.ui.MWTransclusionDialog.static.icon = 'template';
|
|
|
|
|
2014-03-04 22:56:14 +00:00
|
|
|
ve.ui.MWTransclusionDialog.static.title =
|
|
|
|
OO.ui.deferMsg( 'visualeditor-dialog-transclusion-title' );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Map of symbolic mode names and CSS classes.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @property {Object}
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.static.modeCssClasses = {
|
|
|
|
'single': 've-ui-mwTransclusionDialog-single',
|
|
|
|
'multiple': 've-ui-mwTransclusionDialog-multiple'
|
|
|
|
};
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/* Methods */
|
|
|
|
|
2014-03-04 22:56:14 +00:00
|
|
|
/**
|
|
|
|
* Handle outline controls move events.
|
|
|
|
*
|
|
|
|
* @param {number} places Number of places to move the selected item
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onOutlineControlsMove = function ( places ) {
|
|
|
|
var part, promise,
|
|
|
|
parts = this.transclusion.getParts(),
|
|
|
|
item = this.bookletLayout.getOutline().getSelectedItem();
|
|
|
|
|
|
|
|
if ( item ) {
|
|
|
|
part = this.transclusion.getPartFromId( item.getData() );
|
|
|
|
// Move part to new location, and if dialog is loaded switch to new part page
|
|
|
|
promise = this.transclusion.addPart( part, ve.indexOf( part, parts ) + places );
|
|
|
|
if ( this.loaded && !this.preventReselection ) {
|
|
|
|
promise.done( ve.bind( this.setPageByName, this, part.getId() ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle outline controls remove events.
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onOutlineControlsRemove = function () {
|
|
|
|
var id, part, param,
|
|
|
|
item = this.bookletLayout.getOutline().getSelectedItem();
|
|
|
|
|
|
|
|
if ( item ) {
|
|
|
|
id = item.getData();
|
|
|
|
part = this.transclusion.getPartFromId( id );
|
|
|
|
// Check if the part is the actual template, or one of its parameters
|
|
|
|
if ( part instanceof ve.dm.MWTemplateModel && id !== part.getId() ) {
|
|
|
|
param = part.getParameterFromId( id );
|
|
|
|
if ( param instanceof ve.dm.MWParameterModel ) {
|
|
|
|
part.removeParameter( param );
|
|
|
|
}
|
|
|
|
} else if ( part instanceof ve.dm.MWTransclusionPartModel ) {
|
|
|
|
this.transclusion.removePart( part );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle add template button click events.
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onAddTemplateButtonClick = function () {
|
|
|
|
this.addPart( new ve.dm.MWTemplatePlaceholderModel( this.transclusion ) );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle add content button click events.
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onAddContentButtonClick = function () {
|
|
|
|
this.addPart( new ve.dm.MWTransclusionContentModel( this.transclusion, '' ) );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle add parameter button click events.
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onAddParameterButtonClick = function () {
|
|
|
|
var part, param,
|
|
|
|
item = this.bookletLayout.getOutline().getSelectedItem();
|
|
|
|
|
|
|
|
if ( item ) {
|
|
|
|
part = this.transclusion.getPartFromId( item.getData() );
|
|
|
|
if ( part instanceof ve.dm.MWTemplateModel ) {
|
|
|
|
param = new ve.dm.MWParameterModel( part, '', null );
|
|
|
|
part.addParameter( param );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle mode button click events.
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onModeButtonClick = function () {
|
|
|
|
this.setMode( this.mode === 'single' ? 'multiple' : 'single' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle booklet layout page set events.
|
|
|
|
*
|
|
|
|
* @param {OO.ui.PageLayout} page Active page
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onBookletLayoutSet = function ( page ) {
|
|
|
|
this.addParameterButton.setDisabled(
|
|
|
|
!( page instanceof ve.ui.MWTemplatePage || page instanceof ve.ui.MWParameterPage )
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/**
|
2013-12-02 20:10:55 +00:00
|
|
|
* Handle parts being replaced.
|
2013-06-11 19:16:04 +00:00
|
|
|
*
|
2013-12-02 20:10:55 +00:00
|
|
|
* @param {ve.dm.MWTransclusionPartModel} removed Removed part
|
|
|
|
* @param {ve.dm.MWTransclusionPartModel} added Added part
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
2013-12-02 20:10:55 +00:00
|
|
|
ve.ui.MWTransclusionDialog.prototype.onReplacePart = function ( removed, added ) {
|
2014-02-28 00:06:34 +00:00
|
|
|
var i, len, page, name, names, params, partPage, reselect,
|
|
|
|
removePages = [];
|
2013-06-11 19:16:04 +00:00
|
|
|
|
2013-12-02 20:10:55 +00:00
|
|
|
if ( removed ) {
|
|
|
|
// Remove parameter pages of removed templates
|
2014-02-28 00:06:34 +00:00
|
|
|
partPage = this.bookletLayout.getPage( removed.getId() );
|
2013-12-02 20:10:55 +00:00
|
|
|
if ( removed instanceof ve.dm.MWTemplateModel ) {
|
|
|
|
params = removed.getParameters();
|
|
|
|
for ( name in params ) {
|
|
|
|
removePages.push( this.bookletLayout.getPage( params[name].getId() ) );
|
2013-06-14 00:46:45 +00:00
|
|
|
}
|
2013-12-02 20:10:55 +00:00
|
|
|
removed.disconnect( this );
|
2013-06-14 00:46:45 +00:00
|
|
|
}
|
2014-02-28 00:06:34 +00:00
|
|
|
if ( this.loaded && !this.preventReselection && partPage.isActive() ) {
|
|
|
|
reselect = this.bookletLayout.getClosestPage( partPage );
|
2013-06-28 21:38:40 +00:00
|
|
|
}
|
2014-02-28 00:06:34 +00:00
|
|
|
removePages.push( partPage );
|
2013-12-02 20:10:55 +00:00
|
|
|
this.bookletLayout.removePages( removePages );
|
2013-06-28 21:38:40 +00:00
|
|
|
}
|
2013-06-11 19:16:04 +00:00
|
|
|
|
2013-12-02 20:10:55 +00:00
|
|
|
if ( added ) {
|
|
|
|
if ( added instanceof ve.dm.MWTemplateModel ) {
|
|
|
|
page = new ve.ui.MWTemplatePage( added, added.getId(), { '$': this.$ } );
|
|
|
|
} else if ( added instanceof ve.dm.MWTransclusionContentModel ) {
|
|
|
|
page = new ve.ui.MWTransclusionContentPage( added, added.getId(), { '$': this.$ } );
|
|
|
|
} else if ( added instanceof ve.dm.MWTemplatePlaceholderModel ) {
|
|
|
|
page = new ve.ui.MWTemplatePlaceholderPage( added, added.getId(), { '$': this.$ } );
|
|
|
|
}
|
|
|
|
if ( page ) {
|
|
|
|
this.bookletLayout.addPages( [ page ], this.transclusion.getIndex( added ) );
|
2014-02-28 00:06:34 +00:00
|
|
|
if ( reselect ) {
|
|
|
|
// Use added page instead of closest page
|
2013-12-02 20:10:55 +00:00
|
|
|
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();
|
2014-02-28 00:06:34 +00:00
|
|
|
// Prevent selection changes
|
|
|
|
this.preventReselection = true;
|
2013-12-02 20:10:55 +00:00
|
|
|
for ( i = 0, len = names.length; i < len; i++ ) {
|
|
|
|
this.onAddParameter( params[names[i]] );
|
|
|
|
}
|
2014-02-28 00:06:34 +00:00
|
|
|
this.preventReselection = false;
|
2013-12-02 20:10:55 +00:00
|
|
|
added.connect( this, { 'add': 'onAddParameter', 'remove': 'onRemoveParameter' } );
|
2014-02-28 00:06:34 +00:00
|
|
|
if ( names.length ) {
|
|
|
|
this.setPageByName( params[names[0]].getId() );
|
|
|
|
}
|
2013-12-02 20:10:55 +00:00
|
|
|
}
|
2013-06-11 19:16:04 +00:00
|
|
|
|
2013-12-02 20:10:55 +00:00
|
|
|
// Add required params to user created templates
|
|
|
|
if ( added instanceof ve.dm.MWTemplateModel && this.loaded ) {
|
2014-02-28 00:06:34 +00:00
|
|
|
// Prevent selection changes
|
|
|
|
this.preventReselection = true;
|
2013-12-02 20:10:55 +00:00
|
|
|
added.addRequiredParameters();
|
2014-02-28 00:06:34 +00:00
|
|
|
this.preventReselection = false;
|
2014-02-05 19:11:41 +00:00
|
|
|
names = added.getParameterNames();
|
|
|
|
params = added.getParameters();
|
|
|
|
if ( names.length ) {
|
|
|
|
this.setPageByName( params[names[0]].getId() );
|
|
|
|
}
|
2013-12-02 20:10:55 +00:00
|
|
|
}
|
2013-06-11 19:16:04 +00:00
|
|
|
}
|
2014-02-28 00:06:34 +00:00
|
|
|
} else if ( reselect ) {
|
|
|
|
this.setPageByName( reselect.getName() );
|
2013-06-11 19:16:04 +00:00
|
|
|
}
|
2014-03-04 22:56:14 +00:00
|
|
|
this.modeButton.setDisabled( !this.isSingleTemplateTransclusion( this.transclusion ) );
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle add param events.
|
|
|
|
*
|
2014-02-24 21:49:48 +00:00
|
|
|
* @param {ve.dm.MWParameterModel} param Added param
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onAddParameter = function ( param ) {
|
2014-02-27 23:58:37 +00:00
|
|
|
var page;
|
|
|
|
|
|
|
|
if ( param.getName() ) {
|
|
|
|
page = new ve.ui.MWParameterPage( param, param.getId(), { '$': this.$ } );
|
|
|
|
} else {
|
|
|
|
page = new ve.ui.MWParameterPlaceholderPage( param, param.getId(), { '$': this.$ } );
|
|
|
|
}
|
2013-12-02 20:10:55 +00:00
|
|
|
this.bookletLayout.addPages( [ page ], this.transclusion.getIndex( param ) );
|
2014-02-28 00:06:34 +00:00
|
|
|
if ( this.loaded && !this.preventReselection ) {
|
2013-12-02 20:10:55 +00:00
|
|
|
this.setPageByName( param.getId() );
|
|
|
|
}
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle remove param events.
|
|
|
|
*
|
2014-02-24 21:49:48 +00:00
|
|
|
* @param {ve.dm.MWParameterModel} param Removed param
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onRemoveParameter = function ( param ) {
|
2014-02-28 00:06:34 +00:00
|
|
|
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() );
|
2013-06-11 19:16:04 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-18 21:24:16 +00:00
|
|
|
/**
|
2014-03-04 22:56:14 +00:00
|
|
|
* Checks if transclusion only contains a single template or template placeholder.
|
2013-06-18 21:24:16 +00:00
|
|
|
*
|
2014-03-04 22:56:14 +00:00
|
|
|
* @returns {boolean} Transclusion only contains a single template or template placeholder.
|
2013-06-18 21:24:16 +00:00
|
|
|
*/
|
2014-03-04 22:56:14 +00:00
|
|
|
ve.ui.MWTransclusionDialog.prototype.isSingleTemplateTransclusion = function ( transclusion ) {
|
|
|
|
var parts = transclusion && transclusion.getParts();
|
|
|
|
|
|
|
|
return parts && parts.length === 1 && (
|
|
|
|
parts[0] instanceof ve.dm.MWTemplateModel ||
|
|
|
|
parts[0] instanceof ve.dm.MWTemplatePlaceholderModel
|
2014-02-26 00:22:26 +00:00
|
|
|
);
|
2013-06-18 21:24:16 +00:00
|
|
|
};
|
|
|
|
|
2014-03-04 22:56:14 +00:00
|
|
|
/**
|
|
|
|
* 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.MWTransclusionDialog.prototype.getTemplatePartLabel = function ( part ) {
|
|
|
|
return part instanceof ve.dm.MWTemplateModel ?
|
|
|
|
part.getSpec().getLabel() : ve.msg( 'visualeditor-dialog-transclusion-placeholder' );
|
|
|
|
};
|
|
|
|
|
2013-11-05 00:29:50 +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.MWTransclusionDialog.prototype.setPageByName = function ( name ) {
|
2013-12-06 20:24:36 +00:00
|
|
|
if ( this.bookletLayout.isOutlined() ) {
|
2013-12-02 20:10:55 +00:00
|
|
|
this.bookletLayout.getOutline().selectItem(
|
|
|
|
this.bookletLayout.getOutline().getItemFromData( name )
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
this.bookletLayout.setPage( name );
|
|
|
|
}
|
2013-11-05 00:29:50 +00:00
|
|
|
};
|
|
|
|
|
2014-03-04 22:56:14 +00:00
|
|
|
/**
|
|
|
|
* Set dialog mode.
|
|
|
|
*
|
|
|
|
* Auto mode will choose single if possible.
|
|
|
|
*
|
|
|
|
* @param {string} [mode='multiple'] Symbolic name of dialog mode, `multiple`, `single` or 'auto'
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.setMode = function ( mode ) {
|
|
|
|
var name, parts, part, single,
|
|
|
|
modeCssClasses = ve.ui.MWTransclusionDialog.static.modeCssClasses;
|
|
|
|
|
|
|
|
if ( this.transclusion ) {
|
|
|
|
parts = this.transclusion.getParts();
|
|
|
|
part = parts.length && parts[0];
|
|
|
|
if ( mode === 'auto' ) {
|
|
|
|
mode = this.isSingleTemplateTransclusion( this.transclusion ) ? 'single' : 'multiple';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( !modeCssClasses[mode] ) {
|
|
|
|
mode = 'multiple';
|
|
|
|
}
|
|
|
|
this.mode = mode;
|
|
|
|
single = mode === 'single';
|
|
|
|
if ( this.frame.$content ) {
|
|
|
|
for ( name in modeCssClasses ) {
|
|
|
|
this.frame.$content.toggleClass( modeCssClasses[name], name === mode );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.setSize( single ? 'medium' : 'large' );
|
|
|
|
this.bookletLayout.toggleOutline( !single );
|
|
|
|
this.setTitle(
|
|
|
|
single && part ?
|
|
|
|
this.getTemplatePartLabel( part ) :
|
|
|
|
this.constructor.static.title
|
|
|
|
);
|
|
|
|
this.modeButton.setLabel( ve.msg(
|
|
|
|
single ?
|
|
|
|
'visualeditor-dialog-transclusion-multiple-mode' :
|
|
|
|
'visualeditor-dialog-transclusion-single-mode'
|
|
|
|
) );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a part to the transclusion.
|
|
|
|
*
|
|
|
|
* @param {ve.dm.MWTransclusionPartModel} part Part to add
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.addPart = function ( part ) {
|
|
|
|
var index, promise,
|
|
|
|
parts = this.transclusion.getParts(),
|
|
|
|
item = this.bookletLayout.getOutline().getSelectedItem();
|
|
|
|
|
|
|
|
if ( part ) {
|
|
|
|
// Insert after selected part, or at the end if nothing is selected
|
|
|
|
index = item ?
|
|
|
|
ve.indexOf( this.transclusion.getPartFromId( item.getData() ), parts ) + 1 :
|
|
|
|
parts.length;
|
|
|
|
// Add the part, and if dialog is loaded switch to part page
|
|
|
|
promise = this.transclusion.addPart( part, index );
|
|
|
|
if ( this.loaded && !this.preventReselection ) {
|
|
|
|
promise.done( ve.bind( this.setPageByName, this, part.getId() ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.initialize = function () {
|
|
|
|
// Parent method
|
|
|
|
ve.ui.MWDialog.prototype.initialize.call( this );
|
|
|
|
|
|
|
|
// Properties
|
2014-01-17 14:24:12 +00:00
|
|
|
this.applyButton = new OO.ui.ButtonWidget( {
|
2013-11-05 00:29:50 +00:00
|
|
|
'$': this.$,
|
2013-12-02 20:10:55 +00:00
|
|
|
'label': ve.msg( 'visualeditor-dialog-action-apply' ),
|
|
|
|
'flags': ['primary']
|
2013-11-05 00:29:50 +00:00
|
|
|
} );
|
2014-03-04 22:56:14 +00:00
|
|
|
this.modeButton = new OO.ui.ButtonWidget( { '$': this.$ } );
|
|
|
|
this.bookletLayout = new OO.ui.BookletLayout( {
|
|
|
|
'$': this.$,
|
|
|
|
'continuous': true,
|
|
|
|
'autoFocus': true,
|
|
|
|
'outlined': true,
|
|
|
|
'editable': true
|
|
|
|
} );
|
|
|
|
this.addTemplateButton = new OO.ui.ButtonWidget( {
|
|
|
|
'$': this.$,
|
|
|
|
'frameless': true,
|
|
|
|
'icon': 'template',
|
|
|
|
'title': ve.msg( 'visualeditor-dialog-transclusion-add-template' )
|
|
|
|
} );
|
|
|
|
this.addContentButton = new OO.ui.ButtonWidget( {
|
|
|
|
'$': this.$,
|
|
|
|
'frameless': true,
|
|
|
|
'icon': 'source',
|
|
|
|
'title': ve.msg( 'visualeditor-dialog-transclusion-add-content' )
|
|
|
|
} );
|
|
|
|
this.addParameterButton = new OO.ui.ButtonWidget( {
|
|
|
|
'$': this.$,
|
|
|
|
'frameless': true,
|
|
|
|
'icon': 'parameter',
|
|
|
|
'title': ve.msg( 'visualeditor-dialog-transclusion-add-param' )
|
|
|
|
} );
|
2013-11-05 00:29:50 +00:00
|
|
|
|
|
|
|
// Events
|
|
|
|
this.applyButton.connect( this, { 'click': [ 'close', { 'action': 'apply' } ] } );
|
2014-03-04 22:56:14 +00:00
|
|
|
this.modeButton.connect( this, { 'click': 'onModeButtonClick' } );
|
|
|
|
this.bookletLayout.connect( this, { 'set': 'onBookletLayoutSet' } );
|
|
|
|
this.addTemplateButton.connect( this, { 'click': 'onAddTemplateButtonClick' } );
|
|
|
|
this.addContentButton.connect( this, { 'click': 'onAddContentButtonClick' } );
|
|
|
|
this.addParameterButton.connect( this, { 'click': 'onAddParameterButtonClick' } );
|
|
|
|
this.bookletLayout.getOutlineControls()
|
|
|
|
.addItems( [ this.addTemplateButton, this.addContentButton, this.addParameterButton ] )
|
|
|
|
.connect( this, {
|
|
|
|
'move': 'onOutlineControlsMove',
|
|
|
|
'remove': 'onOutlineControlsRemove'
|
|
|
|
} );
|
2013-11-05 00:29:50 +00:00
|
|
|
|
|
|
|
// Initialization
|
2014-03-04 22:56:14 +00:00
|
|
|
this.frame.$content.addClass( 've-ui-mwTransclusionDialog' );
|
2013-12-02 20:10:55 +00:00
|
|
|
this.$body.append( this.bookletLayout.$element );
|
2014-03-04 22:56:14 +00:00
|
|
|
this.$foot.append( this.applyButton.$element, this.modeButton.$element );
|
|
|
|
this.setMode( 'single' );
|
2013-11-05 00:29:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.setup = function ( data ) {
|
2014-03-04 22:56:14 +00:00
|
|
|
var promise;
|
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
// Parent method
|
|
|
|
ve.ui.MWDialog.prototype.setup.call( this, data );
|
|
|
|
|
|
|
|
// Properties
|
2014-01-16 17:35:22 +00:00
|
|
|
this.node = this.surface.getView().getFocusedNode();
|
2013-11-05 00:29:50 +00:00
|
|
|
this.transclusion = new ve.dm.MWTransclusionModel();
|
2013-12-02 20:10:55 +00:00
|
|
|
this.loaded = false;
|
2013-11-05 00:29:50 +00:00
|
|
|
|
|
|
|
// Events
|
2013-12-02 20:10:55 +00:00
|
|
|
this.transclusion.connect( this, { 'replace': 'onReplacePart' } );
|
2013-11-05 00:29:50 +00:00
|
|
|
|
|
|
|
// Initialization
|
|
|
|
if ( this.node instanceof ve.ce.MWTransclusionNode ) {
|
2014-03-04 22:56:14 +00:00
|
|
|
promise = this.transclusion
|
|
|
|
.load( ve.copy( this.node.getModel().getAttribute( 'mw' ) ) );
|
2013-11-05 00:29:50 +00:00
|
|
|
} else {
|
2014-03-04 22:56:14 +00:00
|
|
|
promise = this.transclusion
|
|
|
|
.addPart( new ve.dm.MWTemplatePlaceholderModel( this.transclusion ) );
|
2013-11-05 00:29:50 +00:00
|
|
|
}
|
2014-03-04 22:56:14 +00:00
|
|
|
promise.always( ve.bind( function () {
|
|
|
|
this.loaded = true;
|
|
|
|
this.setMode( 'auto' );
|
|
|
|
}, this ) );
|
2013-11-05 00:29:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.teardown = function ( data ) {
|
|
|
|
var surfaceModel = this.surface.getModel(),
|
|
|
|
obj = this.transclusion.getPlainObject();
|
|
|
|
|
|
|
|
// Data initialization
|
|
|
|
data = data || {};
|
|
|
|
|
|
|
|
// Save changes
|
|
|
|
if ( data.action === 'apply' ) {
|
|
|
|
if ( this.node instanceof ve.ce.MWTransclusionNode ) {
|
|
|
|
if ( obj !== null ) {
|
|
|
|
surfaceModel.getFragment().changeAttributes( { 'mw': obj } );
|
|
|
|
} else {
|
|
|
|
surfaceModel.getFragment().removeContent();
|
|
|
|
}
|
|
|
|
} else if ( obj !== null ) {
|
|
|
|
surfaceModel.getFragment().collapseRangeToEnd().insertContent( [
|
|
|
|
{
|
|
|
|
'type': 'mwTransclusionInline',
|
|
|
|
'attributes': {
|
|
|
|
'mw': obj
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{ 'type': '/mwTransclusionInline' }
|
2013-12-10 02:02:18 +00:00
|
|
|
] ).collapseRangeToEnd().select();
|
2013-11-05 00:29:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.transclusion.disconnect( this );
|
|
|
|
this.transclusion.abortRequests();
|
|
|
|
this.transclusion = null;
|
2013-12-02 20:10:55 +00:00
|
|
|
this.bookletLayout.clearPages();
|
2013-11-05 00:29:50 +00:00
|
|
|
this.node = null;
|
|
|
|
this.content = null;
|
|
|
|
|
2014-03-04 22:56:14 +00:00
|
|
|
this.setMode( 'single' );
|
|
|
|
|
2013-11-05 00:29:50 +00:00
|
|
|
// Parent method
|
|
|
|
ve.ui.MWDialog.prototype.teardown.call( this, data );
|
|
|
|
};
|
2014-03-04 22:56:14 +00:00
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.dialogFactory.register( ve.ui.MWTransclusionDialog );
|