2016-01-31 13:38:48 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface MWTableDialog class.
|
|
|
|
*
|
2018-01-03 00:54:47 +00:00
|
|
|
* @copyright 2011-2018 VisualEditor Team and others; see http://ve.mit-license.org
|
2016-01-31 13:38:48 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dialog for table properties.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.ui.TableDialog
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
|
|
|
ve.ui.MWTableDialog = function VeUiMWTableDialog( config ) {
|
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWTableDialog.super.call( this, config );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWTableDialog, ve.ui.TableDialog );
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2017-02-12 17:58:12 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWTableDialog.prototype.getValues = function () {
|
|
|
|
// Parent method
|
|
|
|
var values = ve.ui.MWTableDialog.super.prototype.getValues.call( this );
|
|
|
|
return ve.extendObject( values, {
|
|
|
|
wikitable: this.wikitableToggle.getValue(),
|
2017-02-03 21:36:52 +00:00
|
|
|
sortable: this.sortableToggle.getValue(),
|
|
|
|
collapsible: this.collapsibleToggle.getValue(),
|
|
|
|
collapsed: this.collapsedToggle.getValue()
|
2017-02-12 17:58:12 +00:00
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2016-01-31 13:38:48 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWTableDialog.prototype.initialize = function () {
|
2017-02-03 21:36:52 +00:00
|
|
|
var wikitableField, sortableField, collapsibleField, collapsedField;
|
2016-01-31 13:38:48 +00:00
|
|
|
// Parent method
|
|
|
|
ve.ui.MWTableDialog.super.prototype.initialize.call( this );
|
|
|
|
|
|
|
|
this.wikitableToggle = new OO.ui.ToggleSwitchWidget();
|
2017-02-03 21:36:52 +00:00
|
|
|
wikitableField = new OO.ui.FieldLayout( this.wikitableToggle, {
|
2016-01-31 13:38:48 +00:00
|
|
|
align: 'left',
|
|
|
|
label: ve.msg( 'visualeditor-dialog-table-wikitable' )
|
|
|
|
} );
|
|
|
|
|
|
|
|
this.sortableToggle = new OO.ui.ToggleSwitchWidget();
|
2017-02-03 21:36:52 +00:00
|
|
|
sortableField = new OO.ui.FieldLayout( this.sortableToggle, {
|
2016-01-31 13:38:48 +00:00
|
|
|
align: 'left',
|
|
|
|
label: ve.msg( 'visualeditor-dialog-table-sortable' )
|
|
|
|
} );
|
|
|
|
|
2017-02-03 21:36:52 +00:00
|
|
|
this.collapsibleToggle = new OO.ui.ToggleSwitchWidget();
|
|
|
|
collapsibleField = new OO.ui.FieldLayout( this.collapsibleToggle, {
|
|
|
|
align: 'left',
|
|
|
|
label: ve.msg( 'visualeditor-dialog-table-collapsible' )
|
|
|
|
} );
|
|
|
|
|
|
|
|
this.collapsedToggle = new OO.ui.ToggleSwitchWidget();
|
|
|
|
collapsedField = new OO.ui.FieldLayout( this.collapsedToggle, {
|
|
|
|
align: 'left',
|
|
|
|
label: ve.msg( 'visualeditor-dialog-table-collapsed' )
|
|
|
|
} );
|
|
|
|
|
|
|
|
this.wikitableToggle.connect( this, { change: 'updateActions' } );
|
2017-02-12 17:58:12 +00:00
|
|
|
this.sortableToggle.connect( this, { change: 'updateActions' } );
|
2017-02-03 21:36:52 +00:00
|
|
|
this.collapsibleToggle.connect( this, { change: 'onCollapsibleChange' } );
|
|
|
|
this.collapsedToggle.connect( this, { change: 'updateActions' } );
|
2017-02-12 17:58:12 +00:00
|
|
|
|
2017-02-03 21:36:52 +00:00
|
|
|
this.panel.$element.append( wikitableField.$element, sortableField.$element, collapsibleField.$element, collapsedField.$element );
|
2016-01-31 13:38:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWTableDialog.prototype.getSetupProcess = function ( data ) {
|
|
|
|
return ve.ui.MWTableDialog.super.prototype.getSetupProcess.call( this, data )
|
|
|
|
.next( function () {
|
2017-02-12 17:58:12 +00:00
|
|
|
var tableNode = this.getFragment().getSelection().getTableNode(),
|
|
|
|
wikitable = !!tableNode.getAttribute( 'wikitable' ),
|
2017-02-03 21:36:52 +00:00
|
|
|
sortable = !!tableNode.getAttribute( 'sortable' ),
|
|
|
|
collapsible = !!tableNode.getAttribute( 'collapsible' ),
|
|
|
|
collapsed = !!tableNode.getAttribute( 'collapsed' );
|
2017-02-12 17:58:12 +00:00
|
|
|
|
|
|
|
this.wikitableToggle.setValue( wikitable );
|
|
|
|
this.sortableToggle.setValue( sortable );
|
2017-02-03 21:36:52 +00:00
|
|
|
this.collapsibleToggle.setValue( collapsible );
|
|
|
|
this.collapsedToggle.setValue( collapsed );
|
2017-02-12 17:58:12 +00:00
|
|
|
|
|
|
|
ve.extendObject( this.initialValues, {
|
|
|
|
wikitable: wikitable,
|
2017-02-03 21:36:52 +00:00
|
|
|
sortable: sortable,
|
|
|
|
collapsible: collapsible,
|
|
|
|
collapsed: collapsed
|
2017-02-12 17:58:12 +00:00
|
|
|
} );
|
2016-01-31 13:38:48 +00:00
|
|
|
|
2017-02-03 21:36:52 +00:00
|
|
|
this.onCollapsibleChange( collapsible );
|
2016-01-31 13:38:48 +00:00
|
|
|
}, this );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWTableDialog.prototype.getActionProcess = function ( action ) {
|
|
|
|
return ve.ui.MWTableDialog.super.prototype.getActionProcess.call( this, action )
|
|
|
|
.next( function () {
|
|
|
|
var surfaceModel, fragment;
|
|
|
|
if ( action === 'done' ) {
|
|
|
|
surfaceModel = this.getFragment().getSurface();
|
|
|
|
fragment = surfaceModel.getLinearFragment( this.getFragment().getSelection().tableRange, true );
|
|
|
|
fragment.changeAttributes( {
|
|
|
|
wikitable: this.wikitableToggle.getValue(),
|
2017-02-03 21:36:52 +00:00
|
|
|
sortable: this.sortableToggle.getValue(),
|
|
|
|
collapsible: this.collapsibleToggle.getValue(),
|
|
|
|
collapsed: this.collapsedToggle.getValue()
|
2016-01-31 13:38:48 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
}, this );
|
|
|
|
};
|
|
|
|
|
2017-02-03 21:36:52 +00:00
|
|
|
/**
|
|
|
|
* Handle change events from the collapsible toggle
|
|
|
|
*
|
|
|
|
* @param {boolean} New toggle value
|
|
|
|
*/
|
|
|
|
ve.ui.MWTableDialog.prototype.onCollapsibleChange = function ( collapsible ) {
|
|
|
|
this.collapsedToggle.setDisabled( !collapsible );
|
|
|
|
if ( !collapsible ) {
|
|
|
|
this.collapsedToggle.setValue( false );
|
|
|
|
}
|
|
|
|
this.updateActions();
|
|
|
|
};
|
|
|
|
|
2016-01-31 13:38:48 +00:00
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.windowFactory.register( ve.ui.MWTableDialog );
|