mediawiki-extensions-Visual.../modules/ve-mw/ui/inspectors/ve.ui.MWAlienExtensionInspector.js
Ed Sanders fdcd42f73a Split AlienExtensionNode into inline and block
MWExtensionNode:
* Inherit from LeafNode at the top level. Inline and block only
  differ in CE where inline has isContent set.

MWAlienExtensionNode:
* Inhert from MW(Inline|Block)ExtensionNode respectively. Both
  mixin MWAlienExtensionNode.

Bonus:
* Bring in paragraph unwrapping on inline nodes from MWMathNode

Bug: T93712
Change-Id: Ib04234f740cf1f27c861d8b3cfeea5e323b94678
2015-04-09 16:32:02 +01:00

116 lines
3 KiB
JavaScript

/*!
* VisualEditor UserInterface MWAlienExtensionInspector class.
*
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* Inspector for editing alienated MediaWiki extensions.
*
* @class
* @extends ve.ui.MWExtensionInspector
*
* @constructor
* @param {Object} [config] Configuration options
*/
ve.ui.MWAlienExtensionInspector = function VeUiMWAlienExtensionInspector() {
// Parent constructor
ve.ui.MWAlienExtensionInspector.super.apply( this, arguments );
// Properties
this.attributeInputs = {};
this.$attributes = null;
};
/* Inheritance */
OO.inheritClass( ve.ui.MWAlienExtensionInspector, ve.ui.MWExtensionInspector );
/* Static properties */
ve.ui.MWAlienExtensionInspector.static.name = 'alienExtension';
ve.ui.MWAlienExtensionInspector.static.icon = 'alienextension';
ve.ui.MWAlienExtensionInspector.static.modelClasses = [
ve.dm.MWAlienInlineExtensionNode,
ve.dm.MWAlienBlockExtensionNode
];
/* Methods */
/**
* @inheritdoc
*/
ve.ui.MWAlienExtensionInspector.prototype.initialize = function () {
// Parent method
ve.ui.MWExtensionInspector.prototype.initialize.apply( this, arguments );
this.$attributes = this.$( '<div>' ).addClass( 've-ui-mwAlienExtensionInspector-attributes' );
this.form.$element.append( this.$attributes );
};
/**
* @inheritdoc
*/
ve.ui.MWAlienExtensionInspector.prototype.getSetupProcess = function ( data ) {
return ve.ui.MWAlienExtensionInspector.super.prototype.getSetupProcess.call( this, data )
.next( function () {
var key, attributeInput, field,
attributes = this.selectedNode.getAttribute( 'mw' ).attrs;
if ( attributes && !ve.isEmptyObject( attributes ) ) {
for ( key in attributes ) {
attributeInput = new OO.ui.TextInputWidget( {
$: this.$,
value: attributes[key]
} );
this.attributeInputs[key] = attributeInput;
field = new OO.ui.FieldLayout(
attributeInput,
{
$: this.$,
align: 'left',
label: key
}
);
this.$attributes.append( field.$element );
}
}
this.title.setLabel( this.selectedNode.getExtensionName() );
}, this );
};
/**
* @inheritdoc
*/
ve.ui.MWAlienExtensionInspector.prototype.getTeardownProcess = function ( data ) {
return ve.ui.MWAlienExtensionInspector.super.prototype.getTeardownProcess.call( this, data )
.next( function () {
this.$attributes.empty();
this.attributeInputs = {};
}, this );
};
/** */
ve.ui.MWAlienExtensionInspector.prototype.updateMwData = function ( mwData ) {
// Parent method
ve.ui.MWAlienExtensionInspector.super.prototype.updateMwData.call( this, mwData );
var key;
if ( !ve.isEmptyObject( this.attributeInputs ) ) {
// Make sure we have an attrs object to populate
mwData.attrs = mwData.attrs || {};
for ( key in this.attributeInputs ) {
mwData.attrs[key] = this.attributeInputs[key].getValue();
}
}
};
/* Registration */
ve.ui.windowFactory.register( ve.ui.MWAlienExtensionInspector );