2013-05-15 18:44:32 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor user interface MWTemplateDialog class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2013-05-21 01:27:38 +00:00
|
|
|
/*global mw */
|
|
|
|
|
2013-05-15 18:44:32 +00:00
|
|
|
/**
|
|
|
|
* Document dialog.
|
|
|
|
*
|
2013-05-21 01:27:38 +00:00
|
|
|
* See https://raw.github.com/wikimedia/mediawiki-extensions-TemplateData/master/spec.templatedata.json
|
|
|
|
* for the latest version of the TemplateData specification.
|
|
|
|
*
|
2013-05-15 18:44:32 +00:00
|
|
|
* @class
|
2013-05-15 20:39:34 +00:00
|
|
|
* @extends ve.ui.PagedDialog
|
2013-05-15 18:44:32 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {ve.ui.Surface} surface
|
The Great ve.ui.Surface refactor of 2013
Prologue:
Farewell ve.Editor my good chap… Oh, hey there HTML frames - I didn't
see you there! In a world where iframes are outlaws, and symbols like
document and window are global, there were more than a few assumptions
about which document or window was being used. But fear not - for this
commit (probably) tracks them all down, leaving a trail of
iframe-compatible awesomeness in its wake. With the great ve.ui.Surface
now able to be used inside of iframes, let the reference editing
commence. But there, lurking in the darkness is a DM issue so fierce it
may take Roan and/or Ed up to 3 whole hours to sort it out.
Note to Roan and/or Ed:
Editing references seems to work fine, but when saving the page there
are "no changes" which is a reasonable indication to the contrary.
Objectives:
* Make it possible to have multiple surfaces be instantiated, get along
nicely, and be embedded inside of iframes if needed.
* Make reference content editable within a dialog
Approach:
* Move what's left of ve.Editor to ve.ui.Surface and essentially
obliterate all use of it
* Make even more stuff inherit from ve.Element (long live this.$$)
* Use the correct document or window anywhere it was being assumed to be
the top level one
* Resolve stacking order issues by removing the excessive use of z-index
and introducing global and local overlay elements for each editor
* Add a surface to the reference dialog, load up the reference contents
and save them back on apply
* Actually destroy what we create in ce and ui surfaces
* Add recursive frame offset calculation method to ve.Element
* Moved ve.ce.Surface's getSelectionRect method to the prototype
Bonus:
* Move ve.ce.DocumentNode.css contents to ve.ce.Node.css (not sure why it
was separate in the first place, but I'm likely the one to blame)
* Fix blatant lies in documentation
* Whitespace cleanup here and there
* Get rid of ve.ui.Window overlays - not used or needed
Change-Id: Iede83e7d24f7cb249b6ba3dc45d770445b862e08
2013-05-20 22:45:50 +00:00
|
|
|
* @param {Object} [config] Config options
|
2013-05-15 18:44:32 +00:00
|
|
|
*/
|
The Great ve.ui.Surface refactor of 2013
Prologue:
Farewell ve.Editor my good chap… Oh, hey there HTML frames - I didn't
see you there! In a world where iframes are outlaws, and symbols like
document and window are global, there were more than a few assumptions
about which document or window was being used. But fear not - for this
commit (probably) tracks them all down, leaving a trail of
iframe-compatible awesomeness in its wake. With the great ve.ui.Surface
now able to be used inside of iframes, let the reference editing
commence. But there, lurking in the darkness is a DM issue so fierce it
may take Roan and/or Ed up to 3 whole hours to sort it out.
Note to Roan and/or Ed:
Editing references seems to work fine, but when saving the page there
are "no changes" which is a reasonable indication to the contrary.
Objectives:
* Make it possible to have multiple surfaces be instantiated, get along
nicely, and be embedded inside of iframes if needed.
* Make reference content editable within a dialog
Approach:
* Move what's left of ve.Editor to ve.ui.Surface and essentially
obliterate all use of it
* Make even more stuff inherit from ve.Element (long live this.$$)
* Use the correct document or window anywhere it was being assumed to be
the top level one
* Resolve stacking order issues by removing the excessive use of z-index
and introducing global and local overlay elements for each editor
* Add a surface to the reference dialog, load up the reference contents
and save them back on apply
* Actually destroy what we create in ce and ui surfaces
* Add recursive frame offset calculation method to ve.Element
* Moved ve.ce.Surface's getSelectionRect method to the prototype
Bonus:
* Move ve.ce.DocumentNode.css contents to ve.ce.Node.css (not sure why it
was separate in the first place, but I'm likely the one to blame)
* Fix blatant lies in documentation
* Whitespace cleanup here and there
* Get rid of ve.ui.Window overlays - not used or needed
Change-Id: Iede83e7d24f7cb249b6ba3dc45d770445b862e08
2013-05-20 22:45:50 +00:00
|
|
|
ve.ui.MWTemplateDialog = function VeUiMWTemplateDialog( surface, config ) {
|
2013-05-15 18:44:32 +00:00
|
|
|
// Parent constructor
|
The Great ve.ui.Surface refactor of 2013
Prologue:
Farewell ve.Editor my good chap… Oh, hey there HTML frames - I didn't
see you there! In a world where iframes are outlaws, and symbols like
document and window are global, there were more than a few assumptions
about which document or window was being used. But fear not - for this
commit (probably) tracks them all down, leaving a trail of
iframe-compatible awesomeness in its wake. With the great ve.ui.Surface
now able to be used inside of iframes, let the reference editing
commence. But there, lurking in the darkness is a DM issue so fierce it
may take Roan and/or Ed up to 3 whole hours to sort it out.
Note to Roan and/or Ed:
Editing references seems to work fine, but when saving the page there
are "no changes" which is a reasonable indication to the contrary.
Objectives:
* Make it possible to have multiple surfaces be instantiated, get along
nicely, and be embedded inside of iframes if needed.
* Make reference content editable within a dialog
Approach:
* Move what's left of ve.Editor to ve.ui.Surface and essentially
obliterate all use of it
* Make even more stuff inherit from ve.Element (long live this.$$)
* Use the correct document or window anywhere it was being assumed to be
the top level one
* Resolve stacking order issues by removing the excessive use of z-index
and introducing global and local overlay elements for each editor
* Add a surface to the reference dialog, load up the reference contents
and save them back on apply
* Actually destroy what we create in ce and ui surfaces
* Add recursive frame offset calculation method to ve.Element
* Moved ve.ce.Surface's getSelectionRect method to the prototype
Bonus:
* Move ve.ce.DocumentNode.css contents to ve.ce.Node.css (not sure why it
was separate in the first place, but I'm likely the one to blame)
* Fix blatant lies in documentation
* Whitespace cleanup here and there
* Get rid of ve.ui.Window overlays - not used or needed
Change-Id: Iede83e7d24f7cb249b6ba3dc45d770445b862e08
2013-05-20 22:45:50 +00:00
|
|
|
ve.ui.PagedDialog.call( this, surface, config );
|
2013-05-28 23:14:43 +00:00
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.node = null;
|
|
|
|
this.content = null;
|
2013-05-29 17:35:12 +00:00
|
|
|
// Buffer for getTemplateSpecs
|
|
|
|
this.fetchQueue = [];
|
|
|
|
this.fetchCallbacks = $.Callbacks();
|
2013-05-15 18:44:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-05-15 20:39:34 +00:00
|
|
|
ve.inheritClass( ve.ui.MWTemplateDialog, ve.ui.PagedDialog );
|
2013-05-15 18:44:32 +00:00
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.ui.MWTemplateDialog.static.titleMessage = 'visualeditor-dialog-template-title';
|
|
|
|
|
|
|
|
ve.ui.MWTemplateDialog.static.icon = 'template';
|
|
|
|
|
|
|
|
ve.ui.MWTemplateDialog.static.modelClasses = [ ve.dm.MWTemplateNode ];
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
2013-05-28 23:14:43 +00:00
|
|
|
* Handle frame open events.
|
|
|
|
*
|
|
|
|
* @method
|
2013-05-15 18:44:32 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.onOpen = function () {
|
2013-05-29 17:35:12 +00:00
|
|
|
var i, progress, len, template,
|
|
|
|
dialog = this;
|
2013-05-17 03:35:06 +00:00
|
|
|
|
2013-05-29 17:35:12 +00:00
|
|
|
function increaseProgress() {
|
|
|
|
progress++;
|
|
|
|
if ( progress === len ) {
|
|
|
|
dialog.setupPages();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function makeStoreTemplateSpec( template ) {
|
|
|
|
return function ( specs ) {
|
|
|
|
template.spec = specs[template.specId];
|
|
|
|
increaseProgress();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog.node = dialog.surface.getView().getFocusedNode();
|
|
|
|
if ( !dialog.node ) {
|
2013-05-28 23:14:43 +00:00
|
|
|
throw new Error( 'No focused node to edit' );
|
|
|
|
}
|
2013-05-17 03:35:06 +00:00
|
|
|
|
2013-05-29 17:35:12 +00:00
|
|
|
// Get content values and copy it so we can safely change it to our liking
|
|
|
|
dialog.content = ve.copyObject( dialog.node.getModel().getAttribute( 'mw' ) );
|
|
|
|
|
2013-05-28 23:14:43 +00:00
|
|
|
// Convert single template format to multiple template format
|
2013-05-29 17:35:12 +00:00
|
|
|
if ( dialog.content.params ) {
|
|
|
|
dialog.content = {
|
|
|
|
'parts': [
|
|
|
|
{
|
|
|
|
'template': dialog.content
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
2013-05-28 23:14:43 +00:00
|
|
|
}
|
2013-05-29 17:35:12 +00:00
|
|
|
|
|
|
|
progress = -1;
|
|
|
|
len = dialog.content.parts.length;
|
|
|
|
|
|
|
|
// Get all template specs asynchronously
|
|
|
|
for ( i = 0; i < len; i++ ) {
|
|
|
|
template = dialog.content.parts[i].template;
|
2013-05-28 23:14:43 +00:00
|
|
|
if ( template ) {
|
2013-05-29 17:35:12 +00:00
|
|
|
// Method #getTemplateSpecs will use the part id instead of `target.url`
|
|
|
|
// if the target has no url property (which Parsoid omits if the target is
|
|
|
|
// dynamically generated from wikitext). In that case we want each template
|
|
|
|
// invocation to have its own inferred template spec.
|
|
|
|
template.specId = template.target.url || ( '#!/part/' + i );
|
|
|
|
dialog.getTemplateSpecs( template, makeStoreTemplateSpec( template ) );
|
2013-05-28 23:14:43 +00:00
|
|
|
} else {
|
2013-05-29 17:35:12 +00:00
|
|
|
// This is a raw wikitext part (between two associated template invocations),
|
|
|
|
// wrap in object so editor has something to reference
|
|
|
|
dialog.content.parts[i] = { 'wt': dialog.content.parts[i] };
|
|
|
|
increaseProgress();
|
2013-05-17 03:35:06 +00:00
|
|
|
}
|
2013-05-21 01:27:38 +00:00
|
|
|
}
|
2013-05-29 17:35:12 +00:00
|
|
|
|
|
|
|
increaseProgress();
|
2013-05-15 23:16:42 +00:00
|
|
|
};
|
2013-05-15 22:13:38 +00:00
|
|
|
|
2013-05-15 23:16:42 +00:00
|
|
|
/**
|
2013-05-28 23:14:43 +00:00
|
|
|
* Handle window close events.
|
2013-05-15 23:16:42 +00:00
|
|
|
*
|
2013-05-28 23:14:43 +00:00
|
|
|
* @param {string} action Action that caused the window to be closed
|
2013-05-15 23:16:42 +00:00
|
|
|
*/
|
2013-05-28 23:14:43 +00:00
|
|
|
ve.ui.MWTemplateDialog.prototype.onClose = function ( action ) {
|
2013-05-29 17:35:12 +00:00
|
|
|
var i, len, parts,
|
2013-05-28 23:14:43 +00:00
|
|
|
surfaceModel = this.surface.getModel();
|
2013-05-21 01:27:38 +00:00
|
|
|
|
2013-05-28 23:14:43 +00:00
|
|
|
// Save changes
|
|
|
|
if ( action === 'apply' ) {
|
2013-05-29 17:35:12 +00:00
|
|
|
|
|
|
|
// Undo non-standard changes we made to the content model in #onOpen
|
|
|
|
parts = this.content.parts;
|
|
|
|
|
|
|
|
for ( i = 0, len = parts.length; i < len; i++ ) {
|
|
|
|
|
|
|
|
// Convert object part with wt property back to string part
|
|
|
|
if ( typeof parts[i].wt === 'string' ) {
|
|
|
|
parts[i] = parts[i].wt;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the properties #onOpen put here
|
|
|
|
if ( parts[i].template ) {
|
|
|
|
if ( parts[i].template.spec ) {
|
|
|
|
delete parts[i].template.spec;
|
|
|
|
}
|
|
|
|
if ( parts[i].template.specId ) {
|
|
|
|
delete parts[i].template.specId;
|
|
|
|
}
|
2013-05-28 23:14:43 +00:00
|
|
|
}
|
|
|
|
}
|
2013-05-29 17:35:12 +00:00
|
|
|
|
2013-05-28 23:14:43 +00:00
|
|
|
// Restore single template format
|
|
|
|
if ( this.content.parts.length === 1 ) {
|
|
|
|
this.content = this.content.parts[0].template;
|
|
|
|
}
|
2013-05-29 17:35:12 +00:00
|
|
|
|
2013-05-28 23:14:43 +00:00
|
|
|
// TODO: Wrap attribute changes in ve.dm.SurfaceFragment
|
|
|
|
surfaceModel.change(
|
|
|
|
ve.dm.Transaction.newFromAttributeChange(
|
2013-05-29 17:35:12 +00:00
|
|
|
surfaceModel.getDocument(),
|
|
|
|
this.node.getOffset(),
|
|
|
|
'mw',
|
|
|
|
this.content
|
2013-05-28 23:14:43 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2013-05-15 23:16:42 +00:00
|
|
|
|
2013-05-28 23:14:43 +00:00
|
|
|
this.clearPages();
|
|
|
|
this.node = null;
|
|
|
|
this.content = null;
|
2013-05-15 23:16:42 +00:00
|
|
|
|
2013-05-28 23:14:43 +00:00
|
|
|
// Parent method
|
|
|
|
ve.ui.PagedDialog.prototype.onClose.call( this );
|
|
|
|
};
|
2013-05-15 21:36:44 +00:00
|
|
|
|
2013-05-28 23:14:43 +00:00
|
|
|
/**
|
|
|
|
* Handle template data load events.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.setupPages = function () {
|
|
|
|
// Build pages from parts
|
|
|
|
var i, len, template, spec, param,
|
2013-05-29 17:35:12 +00:00
|
|
|
parts = this.content.parts;
|
2013-05-21 01:27:38 +00:00
|
|
|
|
2013-05-28 23:14:43 +00:00
|
|
|
// Parent method
|
|
|
|
ve.ui.PagedDialog.prototype.onOpen.call( this );
|
2013-05-16 00:17:06 +00:00
|
|
|
|
2013-05-28 23:14:43 +00:00
|
|
|
// Populate pages
|
|
|
|
for ( i = 0, len = parts.length; i < len; i++ ) {
|
|
|
|
if ( parts[i].template ) {
|
|
|
|
template = parts[i].template;
|
2013-05-29 17:35:12 +00:00
|
|
|
spec = template.spec;
|
2013-05-28 23:14:43 +00:00
|
|
|
// Add template page
|
2013-05-29 10:03:52 +00:00
|
|
|
this.addTemplatePage( 'part_' + i, template );
|
2013-05-28 23:14:43 +00:00
|
|
|
// Add parameter pages
|
|
|
|
for ( param in template.params ) {
|
|
|
|
this.addParameterPage(
|
|
|
|
'part_' + i + '_param_' + param,
|
|
|
|
param,
|
|
|
|
template.params[param],
|
|
|
|
spec.params[param]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else if ( parts[i].wt ) {
|
|
|
|
// Add wikitext page
|
|
|
|
this.addWikitextPage( 'part_' + i, parts[i] );
|
|
|
|
}
|
|
|
|
}
|
2013-05-15 18:44:32 +00:00
|
|
|
};
|
|
|
|
|
2013-05-21 01:27:38 +00:00
|
|
|
/**
|
2013-05-29 17:35:12 +00:00
|
|
|
* Backfill missing template data based on template invocation.
|
|
|
|
* @param {Object} template Template invocation description
|
|
|
|
* @return {Object} Template data blob
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.static.makeTemplateSpec = function ( params ) {
|
|
|
|
var key, blob;
|
|
|
|
|
|
|
|
blob = {
|
|
|
|
description: null,
|
|
|
|
params: {},
|
|
|
|
sets: []
|
|
|
|
};
|
|
|
|
for ( key in params ) {
|
|
|
|
blob.params[key] = {
|
|
|
|
'label': {
|
|
|
|
en: key
|
|
|
|
},
|
|
|
|
'required': false,
|
|
|
|
'description': null,
|
|
|
|
'deprecated': false,
|
|
|
|
'aliases': [],
|
|
|
|
'default': '',
|
|
|
|
'type': 'string'
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return blob;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get template specs for one or more templates in the content model.
|
2013-05-28 23:14:43 +00:00
|
|
|
*
|
2013-05-29 17:35:12 +00:00
|
|
|
* @param {Object[]|undefined} templates List of template invocation descriptions. Contains `title` and
|
|
|
|
* `params` properties. Or undefined to handle the queue built so far.
|
|
|
|
* @param {Function} callback
|
|
|
|
* @param {Object} callback.blobs Object containing template data blobs keyed by page title.
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.getTemplateSpecs = function ( templates, callback ) {
|
|
|
|
var fillTemplateSpecs,
|
|
|
|
dialog = this;
|
|
|
|
|
|
|
|
// Yield once with setTimeout before fetching to allow batching
|
|
|
|
if ( callback ) {
|
|
|
|
dialog.fetchCallbacks.add( callback );
|
|
|
|
}
|
|
|
|
if ( templates ) {
|
|
|
|
templates = ve.isArray( templates ) ? templates : [ templates ];
|
|
|
|
// Push into the queue
|
|
|
|
dialog.fetchQueue.push.apply( dialog.fetchQueue, templates );
|
|
|
|
setTimeout( function () {
|
|
|
|
dialog.getTemplateSpecs();
|
|
|
|
} );
|
|
|
|
return;
|
|
|
|
} else if ( dialog.fetchQueue.length ) {
|
|
|
|
// Handle batch queue
|
|
|
|
templates = dialog.fetchQueue.slice();
|
|
|
|
dialog.fetchQueue.length = 0;
|
|
|
|
} else {
|
|
|
|
// This a delayed call but a previous delayed call already
|
|
|
|
// cleared the queue for us. This call has become redundant.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fillTemplateSpecs = function ( specs ) {
|
|
|
|
var i, len, template, specId;
|
|
|
|
for ( i = 0, len = templates.length; i < len; i++ ) {
|
|
|
|
template = templates[i];
|
|
|
|
specId = template.specId;
|
|
|
|
if ( !specs[specId] ) {
|
|
|
|
specs[specId] = dialog.constructor.static.makeTemplateSpec( template );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dialog.fetchCallbacks.fireWith( null, [ specs ] );
|
|
|
|
};
|
|
|
|
|
|
|
|
dialog.fetchTemplateSpecs( templates )
|
|
|
|
.done( fillTemplateSpecs )
|
|
|
|
.fail( function () {
|
|
|
|
fillTemplateSpecs( {} );
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch template data from the TemplateData API.
|
2013-05-28 23:14:43 +00:00
|
|
|
*
|
2013-05-29 17:35:12 +00:00
|
|
|
* @param {Object[]} templates List of template invocation descriptions
|
|
|
|
* @return {jQuery.Promise}
|
2013-05-21 01:27:38 +00:00
|
|
|
*/
|
2013-05-29 17:35:12 +00:00
|
|
|
ve.ui.MWTemplateDialog.prototype.fetchTemplateSpecs = function ( templates ) {
|
2013-05-28 23:14:43 +00:00
|
|
|
var i, len,
|
2013-05-29 17:35:12 +00:00
|
|
|
d = $.Deferred(),
|
2013-05-28 23:14:43 +00:00
|
|
|
titles = [],
|
2013-05-29 17:35:12 +00:00
|
|
|
specs = {};
|
2013-05-28 23:14:43 +00:00
|
|
|
|
|
|
|
// Collect all titles
|
|
|
|
for ( i = 0, len = templates.length; i < len; i++ ) {
|
2013-05-29 17:35:12 +00:00
|
|
|
if ( templates[i].target.url ) {
|
|
|
|
titles.push( templates[i].target.url );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Optimise for empty lists
|
|
|
|
if ( !templates.length ) {
|
|
|
|
setTimeout( d.reject );
|
|
|
|
return d.promise();
|
2013-05-21 01:27:38 +00:00
|
|
|
}
|
2013-05-28 23:14:43 +00:00
|
|
|
|
|
|
|
// Request template data from server
|
2013-05-21 01:27:38 +00:00
|
|
|
$.ajax( {
|
|
|
|
'url': mw.util.wikiScript( 'api' ),
|
|
|
|
'dataType': 'json',
|
|
|
|
'data': {
|
|
|
|
'format': 'json',
|
|
|
|
'action': 'templatedata',
|
2013-05-28 23:14:43 +00:00
|
|
|
'titles': titles.join( '|' )
|
2013-05-21 01:27:38 +00:00
|
|
|
}
|
2013-05-28 23:14:43 +00:00
|
|
|
} )
|
|
|
|
.done( function ( data ) {
|
2013-05-29 17:35:12 +00:00
|
|
|
var i, len, id;
|
2013-05-28 23:14:43 +00:00
|
|
|
if ( data && data.pages ) {
|
|
|
|
for ( id in data.pages ) {
|
|
|
|
specs[data.pages[id].title] = data.pages[id];
|
2013-05-17 03:35:06 +00:00
|
|
|
}
|
2013-05-29 17:35:12 +00:00
|
|
|
if ( data.normalized ) {
|
|
|
|
for ( i = 0, len = data.normalized.length; i < len; i++ ) {
|
|
|
|
specs[ data.normalized[i].from ] = specs[ data.normalized[i].to ];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
d.resolve( specs );
|
|
|
|
} else {
|
|
|
|
d.reject( 'unavailable', arguments );
|
2013-05-15 22:36:38 +00:00
|
|
|
}
|
2013-05-28 23:14:43 +00:00
|
|
|
} )
|
|
|
|
.fail( function () {
|
2013-05-29 17:35:12 +00:00
|
|
|
d.reject( 'http', arguments );
|
2013-05-28 23:14:43 +00:00
|
|
|
} );
|
|
|
|
|
2013-05-29 17:35:12 +00:00
|
|
|
return d.promise();
|
2013-05-28 23:14:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add page for wikitext.
|
|
|
|
*
|
|
|
|
* @param {string} page Unique page name
|
|
|
|
* @param {Object} value Parameter value
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.addWikitextPage = function ( page, value ) {
|
|
|
|
var fieldset, textInput;
|
|
|
|
|
|
|
|
fieldset = new ve.ui.FieldsetLayout( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': 'Content',
|
|
|
|
'icon': 'source'
|
2013-05-21 01:27:38 +00:00
|
|
|
} );
|
|
|
|
|
2013-05-28 23:14:43 +00:00
|
|
|
textInput = new ve.ui.TextInputWidget( { '$$': this.frame.$$, 'multiline': true } );
|
|
|
|
textInput.setValue( value.wt );
|
|
|
|
textInput.on( 'change', function () {
|
|
|
|
value.wt = textInput.getValue();
|
|
|
|
} );
|
2013-05-29 10:03:52 +00:00
|
|
|
textInput.$.addClass( 've-ui-mwTemplateDialog-input' );
|
|
|
|
fieldset.$.append( textInput.$ );
|
2013-05-28 23:14:43 +00:00
|
|
|
|
|
|
|
this.addPage( page, { 'label': 'Content', 'icon': 'source' } );
|
2013-05-29 10:03:52 +00:00
|
|
|
this.pages[page].$.append( fieldset.$ );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add page for a template.
|
|
|
|
*
|
|
|
|
* @param {string} page Unique page name
|
|
|
|
* @param {Object} template Template info
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.addTemplatePage = function ( page, template ) {
|
|
|
|
var fieldset,
|
|
|
|
label = template.target.url || template.target.wt;
|
|
|
|
|
|
|
|
fieldset = new ve.ui.FieldsetLayout( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': label,
|
|
|
|
'icon': 'template'
|
|
|
|
} );
|
|
|
|
|
|
|
|
this.addPage( page, { 'label': label, 'icon': 'template' } );
|
|
|
|
this.pages[page].$.append( fieldset.$ );
|
2013-05-15 22:36:38 +00:00
|
|
|
};
|
|
|
|
|
2013-05-15 18:44:32 +00:00
|
|
|
/**
|
2013-05-28 23:14:43 +00:00
|
|
|
* Add page for a parameter.
|
2013-05-15 18:44:32 +00:00
|
|
|
*
|
2013-05-28 23:14:43 +00:00
|
|
|
* @param {string} page Unique page name
|
|
|
|
* @param {string} name Parameter name
|
|
|
|
* @param {Object} value Parameter value
|
|
|
|
* @param {Object} spec Parameter specification
|
2013-05-15 18:44:32 +00:00
|
|
|
*/
|
2013-05-28 23:14:43 +00:00
|
|
|
ve.ui.MWTemplateDialog.prototype.addParameterPage = function ( page, name, value, spec ) {
|
|
|
|
var fieldset, textInput, inputLabel,
|
|
|
|
label = spec && spec.label ? spec.label.en : name,
|
|
|
|
description = spec && spec.description && spec.description.en;
|
2013-05-16 00:17:06 +00:00
|
|
|
|
2013-05-28 23:14:43 +00:00
|
|
|
fieldset = new ve.ui.FieldsetLayout( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': label,
|
|
|
|
'icon': 'parameter'
|
|
|
|
} );
|
|
|
|
|
|
|
|
textInput = new ve.ui.TextInputWidget( { '$$': this.frame.$$, 'multiline': true } );
|
|
|
|
textInput.setValue( value.wt );
|
|
|
|
textInput.on( 'change', function () {
|
|
|
|
value.wt = textInput.getValue();
|
|
|
|
} );
|
2013-05-29 10:03:52 +00:00
|
|
|
textInput.$.addClass( 've-ui-mwTemplateDialog-input' );
|
|
|
|
fieldset.$.append( textInput.$ );
|
2013-05-28 23:14:43 +00:00
|
|
|
|
|
|
|
if ( description ) {
|
|
|
|
inputLabel = new ve.ui.InputLabelWidget( {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'input': textInput,
|
|
|
|
'label': description
|
|
|
|
} );
|
|
|
|
fieldset.$.append( inputLabel.$ );
|
2013-05-16 00:17:06 +00:00
|
|
|
}
|
|
|
|
|
2013-05-28 23:14:43 +00:00
|
|
|
// TODO: Use spec.required
|
|
|
|
// TODO: Use spec.deprecation
|
|
|
|
// TODO: Use spec.default
|
|
|
|
// TODO: Use spec.type
|
|
|
|
|
|
|
|
this.addPage( page, { 'label': label, 'icon': 'parameter', 'level': 1 } );
|
2013-05-29 10:03:52 +00:00
|
|
|
this.pages[page].$.append( fieldset.$ );
|
2013-05-15 18:44:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.dialogFactory.register( 'mwTemplate', ve.ui.MWTemplateDialog );
|
|
|
|
|
|
|
|
ve.ui.viewRegistry.register( 'mwTemplate', ve.ui.MWTemplateDialog );
|