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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Document dialog.
|
|
|
|
*
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog = function VeUiMWTemplateDialog( surface ) {
|
|
|
|
// Parent constructor
|
2013-05-15 20:39:34 +00:00
|
|
|
ve.ui.PagedDialog.call( this, surface );
|
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 */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle frame ready events.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.initialize = function () {
|
|
|
|
// Call parent method
|
2013-05-15 20:39:34 +00:00
|
|
|
ve.ui.PagedDialog.prototype.initialize.call( this );
|
2013-05-15 18:44:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle frame ready events.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.onOpen = function () {
|
2013-05-15 22:36:38 +00:00
|
|
|
var mwAttr = this.surface.view.focusedNode.model.getAttribute( 'mw' ),
|
|
|
|
templateData = this.getTemplateData( mwAttr.target.wt ),
|
2013-05-15 23:16:42 +00:00
|
|
|
param;
|
2013-05-15 21:36:44 +00:00
|
|
|
|
2013-05-16 00:17:06 +00:00
|
|
|
this.paramsKeys = [];
|
|
|
|
this.paramsToInputs = {};
|
|
|
|
|
2013-05-15 18:44:32 +00:00
|
|
|
// Parent method
|
2013-05-15 21:36:44 +00:00
|
|
|
ve.ui.PagedDialog.prototype.onOpen.call( this );
|
|
|
|
|
|
|
|
// Add template page
|
2013-05-15 22:36:38 +00:00
|
|
|
this.addPage( 'template', mwAttr.target.wt, 'template' );
|
2013-05-15 21:36:44 +00:00
|
|
|
|
2013-05-15 22:13:38 +00:00
|
|
|
// Loop through parameters
|
2013-05-15 22:36:38 +00:00
|
|
|
for ( param in mwAttr.params ) {
|
2013-05-15 23:16:42 +00:00
|
|
|
this.createPage(
|
|
|
|
param,
|
|
|
|
mwAttr.params[param],
|
|
|
|
templateData && templateData.params[param]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
2013-05-15 22:13:38 +00:00
|
|
|
|
2013-05-15 23:16:42 +00:00
|
|
|
/**
|
|
|
|
* Handle creating page for single parameter.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplateDialog.prototype.createPage = function( key, value, singleTemplateData ) {
|
|
|
|
var pageName = 'parameter_' + key,
|
|
|
|
label = singleTemplateData ? singleTemplateData.label.en : key,
|
|
|
|
fieldset, textInput, inputLabel;
|
|
|
|
|
|
|
|
fieldset = new ve.ui.FieldsetLayout( { '$$': this.$$, 'label': label, 'icon': 'parameter' } );
|
|
|
|
textInput = new ve.ui.TextInputWidget( { '$$': this.$$, 'multiline': true } );
|
|
|
|
textInput.$input.css('height', 100);
|
|
|
|
|
|
|
|
if ( singleTemplateData ) {
|
|
|
|
inputLabel = new ve.ui.InputLabelWidget( {
|
|
|
|
'$$': this.$$,
|
|
|
|
'input': textInput,
|
|
|
|
'label': singleTemplateData.description.en
|
2013-05-15 22:13:38 +00:00
|
|
|
} );
|
2013-05-15 23:16:42 +00:00
|
|
|
fieldset.$.append( inputLabel.$ );
|
2013-05-15 21:36:44 +00:00
|
|
|
}
|
|
|
|
|
2013-05-15 23:16:42 +00:00
|
|
|
fieldset.$.append( textInput.$ );
|
|
|
|
textInput.setValue( value.wt );
|
|
|
|
this.addPage( pageName, label, 'parameter', 1 );
|
|
|
|
this.pages[pageName].$.append( fieldset.$ );
|
2013-05-16 00:17:06 +00:00
|
|
|
|
|
|
|
this.paramsKeys.push( key );
|
|
|
|
this.paramsToInputs[key] = textInput;
|
2013-05-15 18:44:32 +00:00
|
|
|
};
|
|
|
|
|
2013-05-15 22:36:38 +00:00
|
|
|
ve.ui.MWTemplateDialog.prototype.getTemplateData = function ( /*templateName*/ ) {
|
|
|
|
var templateData = {
|
|
|
|
'title': 'Template:Unsigned',
|
|
|
|
'params': {
|
|
|
|
'user': {
|
|
|
|
'label': {
|
|
|
|
'en': 'User'
|
|
|
|
},
|
|
|
|
'description': {
|
|
|
|
'en': 'Name or IP of user who left the comment'
|
|
|
|
},
|
|
|
|
'required': true,
|
|
|
|
'type': 'string/wiki-user-name',
|
|
|
|
'aliases': [
|
|
|
|
'1'
|
|
|
|
],
|
|
|
|
'deprecated': false,
|
|
|
|
'default': ''
|
|
|
|
},
|
|
|
|
'param1': {
|
|
|
|
'label': {
|
|
|
|
'en': 'Time stamp'
|
|
|
|
},
|
|
|
|
'description': {
|
|
|
|
'en': 'datestamp from edit history (remember to label it UTC)'
|
|
|
|
},
|
|
|
|
'aliases': [
|
|
|
|
'2'
|
|
|
|
],
|
|
|
|
'required': false,
|
|
|
|
'deprecated': false,
|
|
|
|
'default': '',
|
|
|
|
'type': 'unknown'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return templateData;
|
|
|
|
};
|
|
|
|
|
2013-05-15 18:44:32 +00:00
|
|
|
/**
|
|
|
|
* Handle frame ready events.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {string} action Action that caused the window to be closed
|
|
|
|
*/
|
2013-05-16 00:17:06 +00:00
|
|
|
ve.ui.MWTemplateDialog.prototype.onClose = function ( action ) {
|
|
|
|
var mwAttr, i;
|
2013-05-15 18:44:32 +00:00
|
|
|
// Parent method
|
2013-05-15 21:36:44 +00:00
|
|
|
ve.ui.PagedDialog.prototype.onOpen.call( this );
|
2013-05-16 00:17:06 +00:00
|
|
|
|
|
|
|
if ( action === 'apply' ) {
|
|
|
|
mwAttr = ve.cloneObject( this.surface.view.focusedNode.model.getAttribute( 'mw' ) );
|
|
|
|
mwAttr.params = {};
|
|
|
|
for ( i = 0; i < this.paramsKeys.length; i++ ) {
|
|
|
|
mwAttr.params[this.paramsKeys[i]] = {
|
|
|
|
'wt': this.paramsToInputs[this.paramsKeys[i]].getValue()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
this.surface.model.change(
|
|
|
|
ve.dm.Transaction.newFromAttributeChange(
|
|
|
|
this.surface.model.documentModel,
|
|
|
|
this.surface.view.focusedNode.getOffset(),
|
|
|
|
'mw',
|
|
|
|
mwAttr
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-05-15 21:36:44 +00:00
|
|
|
this.clearPages();
|
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 );
|