2013-06-11 19:16:04 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor user interface MWTransclusionDialog class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @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
|
|
|
*
|
|
|
|
* See https://raw.github.com/wikimedia/mediawiki-extensions-TemplateData/master/spec.templatedata.json
|
|
|
|
* for the latest version of the TemplateData specification.
|
|
|
|
*
|
|
|
|
* @class
|
2013-07-03 01:30:10 +00:00
|
|
|
* @extends ve.ui.MWDialog
|
2013-06-11 19:16:04 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
2013-10-09 19:59:03 +00:00
|
|
|
* @param {ve.ui.SurfaceWindowSet} windowSet Window set this dialog is part of
|
2013-09-25 10:21:09 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
2013-10-09 19:59:03 +00:00
|
|
|
ve.ui.MWTransclusionDialog = function VeUiMWTransclusionDialog( windowSet, config ) {
|
2013-06-11 19:16:04 +00:00
|
|
|
// Parent constructor
|
2013-10-09 19:59:03 +00:00
|
|
|
ve.ui.MWDialog.call( this, windowSet, 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-06-28 21:38:40 +00:00
|
|
|
this.pending = [];
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-07-03 01:30:10 +00:00
|
|
|
ve.inheritClass( ve.ui.MWTransclusionDialog, ve.ui.MWDialog );
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/* Static Properties */
|
|
|
|
|
2013-08-27 23:28:29 +00:00
|
|
|
ve.ui.MWTransclusionDialog.static.name = 'transclusion';
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
ve.ui.MWTransclusionDialog.static.titleMessage = 'visualeditor-dialog-transclusion-title';
|
|
|
|
|
|
|
|
ve.ui.MWTransclusionDialog.static.icon = 'template';
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2013-07-31 22:53:29 +00:00
|
|
|
/** */
|
2013-06-14 00:46:45 +00:00
|
|
|
ve.ui.MWTransclusionDialog.prototype.initialize = function () {
|
2013-06-21 02:47:10 +00:00
|
|
|
// Parent method
|
2013-07-03 01:30:10 +00:00
|
|
|
ve.ui.MWDialog.prototype.initialize.call( this );
|
|
|
|
|
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
|
|
|
// Properties
|
2013-10-02 00:00:57 +00:00
|
|
|
this.applyButton = new ve.ui.PushButtonWidget( {
|
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
|
|
|
'$$': this.$$, 'label': ve.msg( 'visualeditor-dialog-action-apply' ), 'flags': ['primary']
|
|
|
|
} );
|
2013-10-04 01:05:49 +00:00
|
|
|
this.pagedOutlineLayout = new ve.ui.PagedOutlineLayout( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'editable': true,
|
|
|
|
'adders': [
|
|
|
|
{
|
|
|
|
'name': 'template',
|
|
|
|
'icon': 'template',
|
|
|
|
'title': ve.msg( 'visualeditor-dialog-transclusion-add-template' )
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'name': 'content',
|
|
|
|
'icon': 'source',
|
|
|
|
'title': ve.msg( 'visualeditor-dialog-transclusion-add-content' )
|
|
|
|
}
|
|
|
|
]
|
|
|
|
} );
|
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
|
|
|
|
2013-06-18 21:24:16 +00:00
|
|
|
// Events
|
2013-10-04 01:05:49 +00:00
|
|
|
this.pagedOutlineLayout.getOutlineControls().connect( this, {
|
2013-06-18 21:24:16 +00:00
|
|
|
'move': 'onOutlineControlsMove',
|
|
|
|
'add': 'onOutlineControlsAdd'
|
|
|
|
} );
|
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
|
|
|
this.applyButton.connect( this, { 'click': [ 'close', 'apply' ] } );
|
|
|
|
|
|
|
|
// Initialization
|
2013-10-04 01:05:49 +00:00
|
|
|
this.$body.append( this.pagedOutlineLayout.$ );
|
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
|
|
|
this.$foot.append( this.applyButton.$ );
|
2013-06-14 00:46:45 +00:00
|
|
|
};
|
|
|
|
|
2013-07-31 22:53:29 +00:00
|
|
|
/** */
|
2013-06-11 19:16:04 +00:00
|
|
|
ve.ui.MWTransclusionDialog.prototype.onOpen = function () {
|
|
|
|
// Parent method
|
2013-07-03 01:30:10 +00:00
|
|
|
ve.ui.MWDialog.prototype.onOpen.call( this );
|
2013-06-11 19:16:04 +00:00
|
|
|
|
|
|
|
// Sanity check
|
|
|
|
this.node = this.surface.getView().getFocusedNode();
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.transclusion = new ve.dm.MWTransclusionModel();
|
|
|
|
|
2013-06-29 02:37:42 +00:00
|
|
|
// Events
|
|
|
|
this.transclusion.connect( this, { 'add': 'onAddPart', 'remove': 'onRemovePart' } );
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
// Initialization
|
2013-06-18 22:09:01 +00:00
|
|
|
if ( this.node instanceof ve.ce.MWTransclusionNode ) {
|
2013-07-28 20:51:32 +00:00
|
|
|
this.transclusion.load( ve.copy( this.node.getModel().getAttribute( 'mw' ) ) );
|
2013-06-18 22:09:01 +00:00
|
|
|
} else {
|
2013-07-11 00:33:21 +00:00
|
|
|
this.transclusion.addPart(
|
|
|
|
new ve.dm.MWTemplatePlaceholderModel( this.transclusion, 'user' )
|
|
|
|
);
|
2013-06-18 22:09:01 +00:00
|
|
|
}
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
2013-07-31 22:53:29 +00:00
|
|
|
/** */
|
2013-06-11 19:16:04 +00:00
|
|
|
ve.ui.MWTransclusionDialog.prototype.onClose = function ( action ) {
|
2013-06-18 22:09:01 +00:00
|
|
|
var surfaceModel = this.surface.getModel(),
|
|
|
|
obj = this.transclusion.getPlainObject();
|
2013-06-11 19:16:04 +00:00
|
|
|
|
2013-06-19 15:21:38 +00:00
|
|
|
// Parent method
|
2013-07-03 01:30:10 +00:00
|
|
|
ve.ui.MWDialog.prototype.onClose.call( this );
|
2013-06-19 15:21:38 +00:00
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
// Save changes
|
|
|
|
if ( action === 'apply' ) {
|
2013-06-18 22:09:01 +00:00
|
|
|
if ( this.node instanceof ve.ce.MWTransclusionNode ) {
|
2013-06-20 16:23:29 +00:00
|
|
|
if ( obj !== null ) {
|
|
|
|
surfaceModel.getFragment().changeAttributes( { 'mw': obj } );
|
|
|
|
} else {
|
|
|
|
surfaceModel.getFragment().removeContent();
|
|
|
|
}
|
|
|
|
} else if ( obj !== null ) {
|
2013-06-18 22:09:01 +00:00
|
|
|
surfaceModel.getFragment().collapseRangeToEnd().insertContent( [
|
|
|
|
{
|
|
|
|
'type': 'mwTransclusionInline',
|
|
|
|
'attributes': {
|
|
|
|
'mw': obj
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{ 'type': '/mwTransclusionInline' }
|
|
|
|
] );
|
|
|
|
}
|
2013-06-11 19:16:04 +00:00
|
|
|
}
|
|
|
|
|
2013-06-28 21:38:40 +00:00
|
|
|
this.transclusion.disconnect( this );
|
|
|
|
this.transclusion.abortRequests();
|
|
|
|
this.transclusion = null;
|
2013-10-04 01:05:49 +00:00
|
|
|
this.pagedOutlineLayout.clearPages();
|
2013-06-11 19:16:04 +00:00
|
|
|
this.node = null;
|
|
|
|
this.content = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle add part events.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.dm.MWTransclusionPartModel} part Added part
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onAddPart = function ( part ) {
|
2013-07-11 00:33:21 +00:00
|
|
|
var i, len, page, params, names, pending, item, spec;
|
2013-06-11 19:16:04 +00:00
|
|
|
|
|
|
|
if ( part instanceof ve.dm.MWTemplateModel ) {
|
|
|
|
page = this.getTemplatePage( part );
|
|
|
|
} else if ( part instanceof ve.dm.MWTransclusionContentModel ) {
|
|
|
|
page = this.getContentPage( part );
|
2013-06-18 21:24:16 +00:00
|
|
|
} else if ( part instanceof ve.dm.MWTemplatePlaceholderModel ) {
|
|
|
|
page = this.getPlaceholderPage( part );
|
2013-06-11 19:16:04 +00:00
|
|
|
}
|
|
|
|
if ( page ) {
|
2013-06-18 21:24:16 +00:00
|
|
|
page.index = this.getPageIndex( part );
|
2013-10-04 01:05:49 +00:00
|
|
|
this.pagedOutlineLayout.addPage( part.getId(), page );
|
2013-07-11 00:33:21 +00:00
|
|
|
// Add existing params to templates
|
2013-06-14 00:46:45 +00:00
|
|
|
if ( part instanceof ve.dm.MWTemplateModel ) {
|
|
|
|
names = part.getParameterNames();
|
|
|
|
params = part.getParameters();
|
|
|
|
for ( i = 0, len = names.length; i < len; i++ ) {
|
2013-07-11 00:33:21 +00:00
|
|
|
this.onAddParameter( params[names[i]] );
|
2013-06-14 00:46:45 +00:00
|
|
|
}
|
|
|
|
part.connect( this, { 'add': 'onAddParameter', 'remove': 'onRemoveParameter' } );
|
|
|
|
}
|
2013-06-11 19:16:04 +00:00
|
|
|
}
|
2013-07-11 00:33:21 +00:00
|
|
|
|
|
|
|
// Add required params to user created templates
|
|
|
|
if ( part instanceof ve.dm.MWTemplateModel && part.getOrigin() === 'user' ) {
|
|
|
|
spec = part.getSpec();
|
|
|
|
names = spec.getParameterNames();
|
|
|
|
for ( i = 0, len = names.length; i < len; i++ ) {
|
|
|
|
// Only add required params
|
|
|
|
if ( spec.isParameterRequired( names[i] ) ) {
|
|
|
|
part.addParameter( new ve.dm.MWTemplateParameterModel( part, names[i] ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-28 21:38:40 +00:00
|
|
|
// Resolve pending placeholder
|
|
|
|
for ( i = 0, len = this.pending.length; i < len; i++ ) {
|
|
|
|
pending = this.pending[i];
|
|
|
|
if ( pending.part === part ) {
|
|
|
|
// Auto-select new part if placeholder is still selected
|
2013-10-04 01:05:49 +00:00
|
|
|
item = this.pagedOutlineLayout.getOutline().getSelectedItem();
|
2013-06-28 21:38:40 +00:00
|
|
|
if ( item.getData() === pending.placeholder.getId() ) {
|
|
|
|
this.setPageByName( part.getId() );
|
|
|
|
}
|
|
|
|
// Cleanup
|
|
|
|
pending.placeholder.remove();
|
|
|
|
this.pending.splice( i, 1 );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle remove part events.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.dm.MWTransclusionPartModel} part Removed part
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onRemovePart = function ( part ) {
|
|
|
|
var name, params;
|
|
|
|
|
|
|
|
if ( part instanceof ve.dm.MWTemplateModel ) {
|
|
|
|
params = part.getParameters();
|
|
|
|
for ( name in params ) {
|
2013-10-04 01:05:49 +00:00
|
|
|
this.pagedOutlineLayout.removePage( params[name].getId() );
|
2013-06-11 19:16:04 +00:00
|
|
|
}
|
|
|
|
part.disconnect( this );
|
|
|
|
}
|
2013-10-04 01:05:49 +00:00
|
|
|
this.pagedOutlineLayout.removePage( part.getId() );
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle add param events.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.dm.MWTemplateParameterModel} param Added param
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onAddParameter = function ( param ) {
|
|
|
|
var page = this.getParameterPage( param );
|
2013-06-14 00:46:45 +00:00
|
|
|
page.index = this.getPageIndex( param );
|
2013-10-04 01:05:49 +00:00
|
|
|
this.pagedOutlineLayout.addPage( param.getId(), page );
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle remove param events.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.dm.MWTemplateParameterModel} param Removed param
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onRemoveParameter = function ( param ) {
|
2013-10-04 01:05:49 +00:00
|
|
|
this.pagedOutlineLayout.removePage( param.getId() );
|
2013-06-11 19:16:04 +00:00
|
|
|
// Return to template page
|
|
|
|
this.setPageByName( param.getTemplate().getId() );
|
|
|
|
};
|
|
|
|
|
2013-06-14 00:46:45 +00:00
|
|
|
/**
|
|
|
|
* Handle outline controls move events.
|
|
|
|
*
|
|
|
|
* @method
|
2013-06-18 21:24:16 +00:00
|
|
|
* @param {number} places Number of places to move the selected item
|
2013-06-14 00:46:45 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onOutlineControlsMove = function ( places ) {
|
|
|
|
var part, index, name,
|
|
|
|
parts = this.transclusion.getParts(),
|
2013-10-04 01:05:49 +00:00
|
|
|
item = this.pagedOutlineLayout.getOutline().getSelectedItem();
|
2013-06-14 00:46:45 +00:00
|
|
|
|
|
|
|
if ( item ) {
|
|
|
|
name = item.getData();
|
|
|
|
part = this.transclusion.getPartFromId( name );
|
|
|
|
index = ve.indexOf( part, parts );
|
2013-07-12 01:23:52 +00:00
|
|
|
// Auto-removes part from old location
|
|
|
|
this.transclusion.addPart( part, index + places )
|
|
|
|
.done( ve.bind( this.setPageByName, this, part.getId() ) );
|
2013-06-14 00:46:45 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-18 21:24:16 +00:00
|
|
|
/**
|
|
|
|
* Handle outline controls add events.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {string} type Type of item to add
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.onOutlineControlsAdd = function ( type ) {
|
|
|
|
var part;
|
|
|
|
|
2013-07-12 01:23:52 +00:00
|
|
|
if ( type === 'content' ) {
|
|
|
|
part = new ve.dm.MWTransclusionContentModel( this.transclusion, '', 'user' );
|
|
|
|
} else if ( type === 'template' ) {
|
|
|
|
part = new ve.dm.MWTemplatePlaceholderModel( this.transclusion, 'user' );
|
|
|
|
}
|
|
|
|
if ( part ) {
|
|
|
|
this.transclusion.addPart( part, this.getPartInsertionIndex() )
|
|
|
|
.done( ve.bind( this.setPageByName, this, part.getId() ) );
|
2013-06-18 21:24:16 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get an index for part insertion.
|
|
|
|
*
|
|
|
|
* @method
|
2013-07-31 22:53:29 +00:00
|
|
|
* @returns {number} Index to insert new parts at
|
2013-06-18 21:24:16 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.getPartInsertionIndex = function () {
|
|
|
|
var parts = this.transclusion.getParts(),
|
2013-10-04 01:05:49 +00:00
|
|
|
item = this.pagedOutlineLayout.getOutline().getSelectedItem();
|
2013-06-18 21:24:16 +00:00
|
|
|
|
|
|
|
if ( item ) {
|
|
|
|
return ve.indexOf( this.transclusion.getPartFromId( item.getData() ), parts ) + 1;
|
|
|
|
}
|
|
|
|
return parts.length;
|
|
|
|
};
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/**
|
|
|
|
* Set the page by name.
|
|
|
|
*
|
|
|
|
* Page names are always the ID of the part or param they represent.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {string} name Page name
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.setPageByName = function ( name ) {
|
2013-10-04 01:05:49 +00:00
|
|
|
this.pagedOutlineLayout.getOutline().selectItem(
|
|
|
|
this.pagedOutlineLayout.getOutline().getItemFromData( name )
|
|
|
|
);
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the page index of an item.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.dm.MWTransclusionPartModel|ve.dm.MWTemplateParameterModel} item Part or parameter
|
2013-06-17 10:50:24 +00:00
|
|
|
* @returns {number} Page index of item
|
2013-06-11 19:16:04 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.getPageIndex = function ( item ) {
|
|
|
|
// Build pages from parts
|
|
|
|
var i, iLen, j, jLen, part, names,
|
|
|
|
parts = this.transclusion.getParts(),
|
|
|
|
index = 0;
|
|
|
|
|
|
|
|
// Populate pages
|
|
|
|
for ( i = 0, iLen = parts.length; i < iLen; i++ ) {
|
|
|
|
part = parts[i];
|
|
|
|
if ( part === item ) {
|
|
|
|
return index;
|
|
|
|
}
|
2013-06-14 00:46:45 +00:00
|
|
|
index++;
|
2013-06-11 19:16:04 +00:00
|
|
|
if ( part instanceof ve.dm.MWTemplateModel ) {
|
|
|
|
names = part.getParameterNames();
|
|
|
|
for ( j = 0, jLen = names.length; j < jLen; j++ ) {
|
|
|
|
if ( part.getParameter( names[j] ) === item ) {
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get page for transclusion content.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.dm.MWTransclusionContentModel} content Content model
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.getContentPage = function ( content ) {
|
|
|
|
var valueFieldset, textInput, optionsFieldset, removeButton;
|
|
|
|
|
|
|
|
valueFieldset = new ve.ui.FieldsetLayout( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-transclusion-content' ),
|
|
|
|
'icon': 'source'
|
|
|
|
} );
|
|
|
|
|
|
|
|
textInput = new ve.ui.TextInputWidget( { '$$': this.frame.$$, 'multiline': true } );
|
|
|
|
textInput.setValue( content.getValue() );
|
|
|
|
textInput.connect( this, { 'change': function () {
|
|
|
|
content.setValue( textInput.getValue() );
|
|
|
|
} } );
|
|
|
|
textInput.$.addClass( 've-ui-mwTransclusionDialog-input' );
|
|
|
|
valueFieldset.$.append( textInput.$ );
|
|
|
|
|
|
|
|
optionsFieldset = new ve.ui.FieldsetLayout( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-transclusion-options' ),
|
|
|
|
'icon': 'settings'
|
|
|
|
} );
|
|
|
|
|
2013-10-02 00:00:57 +00:00
|
|
|
removeButton = new ve.ui.PushButtonWidget( {
|
2013-06-11 19:16:04 +00:00
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-transclusion-remove-content' ),
|
|
|
|
'flags': ['destructive']
|
|
|
|
} );
|
|
|
|
removeButton.connect( this, { 'click': function () {
|
|
|
|
content.remove();
|
|
|
|
} } );
|
|
|
|
optionsFieldset.$.append( removeButton.$ );
|
|
|
|
|
|
|
|
return {
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-transclusion-content' ),
|
|
|
|
'icon': 'source',
|
2013-06-14 00:46:45 +00:00
|
|
|
'$content': valueFieldset.$.add( optionsFieldset.$ ),
|
|
|
|
'moveable': true
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get page for a template.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.dm.MWTemplateModel} template Template model
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.getTemplatePage = function ( template ) {
|
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
|
|
|
var infoFieldset, addParameterFieldset, addParameterSearch, optionsFieldset,
|
2013-06-18 21:24:16 +00:00
|
|
|
removeButton,
|
2013-06-11 19:16:04 +00:00
|
|
|
spec = template.getSpec(),
|
|
|
|
label = spec.getLabel(),
|
|
|
|
description = spec.getDescription();
|
|
|
|
|
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
|
|
|
function addParameter( name ) {
|
|
|
|
var param;
|
2013-07-02 20:40:54 +00:00
|
|
|
|
|
|
|
if ( name ) {
|
|
|
|
param = new ve.dm.MWTemplateParameterModel( template, name );
|
|
|
|
template.addParameter( param );
|
|
|
|
addParameterSearch.query.setValue();
|
|
|
|
this.setPageByName( param.getId() );
|
|
|
|
}
|
2013-06-18 21:24:16 +00:00
|
|
|
}
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
infoFieldset = new ve.ui.FieldsetLayout( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': label,
|
|
|
|
'icon': 'template'
|
|
|
|
} );
|
|
|
|
|
|
|
|
if ( description ) {
|
2013-07-02 20:40:54 +00:00
|
|
|
infoFieldset.$.append( this.frame.$$( '<div>' ).text( description ) );
|
2013-06-11 19:16:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
addParameterFieldset = new ve.ui.FieldsetLayout( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-transclusion-add-param' ),
|
|
|
|
'icon': 'parameter'
|
|
|
|
} );
|
|
|
|
addParameterFieldset.$.addClass( 've-ui-mwTransclusionDialog-addParameterFieldset' );
|
2013-07-02 20:40:54 +00:00
|
|
|
addParameterSearch = new ve.ui.MWParameterSearchWidget( template, { '$$': this.frame.$$ } );
|
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
|
|
|
addParameterSearch.connect( this, { 'select': addParameter } );
|
|
|
|
addParameterFieldset.$.append( addParameterSearch.$ );
|
2013-06-11 19:16:04 +00:00
|
|
|
|
|
|
|
optionsFieldset = new ve.ui.FieldsetLayout( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-transclusion-options' ),
|
|
|
|
'icon': 'settings'
|
|
|
|
} );
|
|
|
|
|
2013-10-02 00:00:57 +00:00
|
|
|
removeButton = new ve.ui.PushButtonWidget( {
|
2013-06-11 19:16:04 +00:00
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-transclusion-remove-template' ),
|
|
|
|
'flags': ['destructive']
|
|
|
|
} );
|
|
|
|
removeButton.connect( this, { 'click': function () {
|
|
|
|
template.remove();
|
|
|
|
} } );
|
|
|
|
optionsFieldset.$.append( removeButton.$ );
|
|
|
|
|
|
|
|
return {
|
|
|
|
'label': label,
|
|
|
|
'icon': 'template',
|
2013-06-14 00:46:45 +00:00
|
|
|
'$content': infoFieldset.$.add( addParameterFieldset.$ ).add( optionsFieldset.$ ),
|
|
|
|
'moveable': true
|
2013-06-11 19:16:04 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get page for a parameter.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.dm.MWTemplateParameterModel} parameter Parameter model
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.getParameterPage = function ( parameter ) {
|
|
|
|
var valueFieldset, optionsFieldset, textInput, inputLabel, removeButton,
|
|
|
|
spec = parameter.getTemplate().getSpec(),
|
|
|
|
name = parameter.getName(),
|
|
|
|
label = spec.getParameterLabel( name ),
|
|
|
|
description = spec.getParameterDescription( name );
|
|
|
|
|
|
|
|
valueFieldset = new ve.ui.FieldsetLayout( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': label,
|
|
|
|
'icon': 'parameter'
|
|
|
|
} );
|
|
|
|
|
|
|
|
if ( description ) {
|
|
|
|
inputLabel = new ve.ui.InputLabelWidget( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'input': textInput,
|
|
|
|
'label': description
|
|
|
|
} );
|
|
|
|
valueFieldset.$.append( inputLabel.$ );
|
|
|
|
}
|
|
|
|
|
|
|
|
textInput = new ve.ui.TextInputWidget( { '$$': this.frame.$$, 'multiline': true } );
|
|
|
|
textInput.setValue( parameter.getValue() );
|
|
|
|
textInput.connect( this, { 'change': function () {
|
|
|
|
parameter.setValue( textInput.getValue() );
|
|
|
|
} } );
|
|
|
|
textInput.$.addClass( 've-ui-mwTransclusionDialog-input' );
|
|
|
|
valueFieldset.$.append( textInput.$ );
|
|
|
|
|
|
|
|
optionsFieldset = new ve.ui.FieldsetLayout( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-transclusion-options' ),
|
|
|
|
'icon': 'settings'
|
|
|
|
} );
|
|
|
|
|
2013-10-02 00:00:57 +00:00
|
|
|
removeButton = new ve.ui.PushButtonWidget( {
|
2013-06-11 19:16:04 +00:00
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-transclusion-remove-param' ),
|
|
|
|
'flags': ['destructive']
|
|
|
|
} );
|
|
|
|
removeButton.connect( this, { 'click': function () {
|
|
|
|
parameter.remove();
|
|
|
|
} } );
|
|
|
|
optionsFieldset.$.append( removeButton.$ );
|
|
|
|
|
|
|
|
// TODO: Use spec.required
|
|
|
|
// TODO: Use spec.deprecation
|
|
|
|
// TODO: Use spec.default
|
|
|
|
// TODO: Use spec.type
|
|
|
|
|
|
|
|
return {
|
|
|
|
'label': label,
|
|
|
|
'icon': 'parameter',
|
|
|
|
'level': 1,
|
|
|
|
'$content': valueFieldset.$.add( optionsFieldset.$ )
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2013-06-18 21:24:16 +00:00
|
|
|
/**
|
|
|
|
* Get page for a parameter.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.dm.MWTemplateParameterModel} parameter Parameter model
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionDialog.prototype.getPlaceholderPage = function ( placeholder ) {
|
|
|
|
var addTemplateFieldset, addTemplateInput, addTemplateButton, optionsFieldset, removeButton,
|
|
|
|
label = ve.msg( 'visualeditor-dialog-transclusion-placeholder' );
|
|
|
|
|
|
|
|
function addTemplate() {
|
2013-07-12 00:23:33 +00:00
|
|
|
var parts = placeholder.getTransclusion().getParts(),
|
|
|
|
part = ve.dm.MWTemplateModel.newFromName(
|
|
|
|
this.transclusion, addTemplateInput.getValue()
|
|
|
|
);
|
2013-06-18 21:24:16 +00:00
|
|
|
|
2013-06-29 02:37:42 +00:00
|
|
|
this.transclusion.addPart( part, ve.indexOf( placeholder, parts ) );
|
2013-06-28 21:38:40 +00:00
|
|
|
this.pending.push( { 'part': part, 'placeholder': placeholder } );
|
|
|
|
addTemplateInput.pushPending();
|
|
|
|
addTemplateButton.setDisabled( true );
|
|
|
|
removeButton.setDisabled( true );
|
2013-06-18 21:24:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
addTemplateFieldset = new ve.ui.FieldsetLayout( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': label,
|
2013-07-15 22:43:39 +00:00
|
|
|
'icon': 'template'
|
2013-06-18 21:24:16 +00:00
|
|
|
} );
|
|
|
|
addTemplateFieldset.$.addClass( 've-ui-mwTransclusionDialog-addTemplateFieldset' );
|
|
|
|
|
|
|
|
addTemplateInput = new ve.ui.MWTitleInputWidget( {
|
|
|
|
'$$': this.frame.$$, '$overlay': this.$overlay, 'namespace': 10
|
|
|
|
} );
|
2013-10-02 00:00:57 +00:00
|
|
|
addTemplateButton = new ve.ui.PushButtonWidget( {
|
2013-06-18 21:24:16 +00:00
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-transclusion-add-template' ),
|
|
|
|
'flags': ['constructive'],
|
|
|
|
'disabled': true
|
|
|
|
} );
|
|
|
|
addTemplateInput.connect( this, {
|
|
|
|
'change': function () {
|
|
|
|
addTemplateButton.setDisabled( addTemplateInput.getValue() === '' );
|
|
|
|
},
|
|
|
|
'enter': addTemplate
|
|
|
|
} );
|
|
|
|
addTemplateButton.connect( this, { 'click': addTemplate } );
|
|
|
|
addTemplateFieldset.$.append( addTemplateInput.$, addTemplateButton.$ );
|
|
|
|
|
|
|
|
optionsFieldset = new ve.ui.FieldsetLayout( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-transclusion-options' ),
|
|
|
|
'icon': 'settings'
|
|
|
|
} );
|
|
|
|
|
2013-10-02 00:00:57 +00:00
|
|
|
removeButton = new ve.ui.PushButtonWidget( {
|
2013-06-18 21:24:16 +00:00
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-transclusion-remove-template' ),
|
|
|
|
'flags': ['destructive']
|
|
|
|
} );
|
|
|
|
removeButton.connect( this, { 'click': function () {
|
|
|
|
placeholder.remove();
|
|
|
|
} } );
|
|
|
|
optionsFieldset.$.append( removeButton.$ );
|
|
|
|
|
|
|
|
return {
|
2013-07-02 20:40:54 +00:00
|
|
|
'label': this.frame.$$( '<span>' )
|
2013-06-18 21:24:16 +00:00
|
|
|
.addClass( 've-ui-mwTransclusionDialog-placeholder-label' )
|
|
|
|
.text( label ),
|
|
|
|
'icon': 'template',
|
|
|
|
'$content': addTemplateFieldset.$.add( optionsFieldset.$ )
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
/* Registration */
|
|
|
|
|
2013-08-27 23:28:29 +00:00
|
|
|
ve.ui.dialogFactory.register( ve.ui.MWTransclusionDialog );
|