all files / src/ui/contextitems/ ve.ui.TableContextItem.js

84.21% Statements 16/19
100% Branches 3/3
75% Functions 3/4
84.21% Lines 16/19
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75                                                                          23×                                            
/*!
 * VisualEditor TableContextItem class.
 *
 * @copyright 2011-2019 VisualEditor Team and others; see http://ve.mit-license.org
 */
 
/**
 * Context item for tables.
 *
 * @class
 * @extends ve.ui.LinearContextItem
 *
 * @param {ve.ui.Context} context Context item is in
 * @param {ve.dm.Model} model Model item is related to
 * @param {Object} config Configuration options
 */
ve.ui.TableContextItem = function VeUiTableContextItem( context, model, config ) {
	// Parent constructor
	ve.ui.TableContextItem.super.call( this, context, model, config );
 
	// Initialization
	this.$element.addClass( 've-ui-tableContextItem' );
 
	this.editButton.setLabel( ve.msg( 'visualeditor-table-contextitem-properties' ) );
};
 
/* Inheritance */
 
OO.inheritClass( ve.ui.TableContextItem, ve.ui.LinearContextItem );
 
/* Static Properties */
 
ve.ui.TableContextItem.static.name = 'table';
 
ve.ui.TableContextItem.static.icon = 'table';
 
ve.ui.TableContextItem.static.label = OO.ui.deferMsg( 'visualeditor-toolbar-table' );
 
ve.ui.TableContextItem.static.commandName = 'table';
 
ve.ui.TableContextItem.static.embeddable = false;
 
/* Methods */
 
/**
 * @inheritdoc
 */
ve.ui.TableContextItem.static.isCompatibleWith = function ( model ) {
	return model instanceof ve.dm.Node && model.isCellable() && !OO.ui.isMobile();
};
 
/**
 * @inheritdoc
 */
ve.ui.TableContextItem.prototype.isDeletable = function () {
	return !this.isReadOnly();
};
 
/**
 * @inheritdoc
 */
ve.ui.TableContextItem.prototype.onDeleteButtonClick = function () {
	var surfaceModel = this.getFragment().getSurface();
 
	surfaceModel.getLinearFragment(
		surfaceModel.getSelectedNode().findParent( ve.dm.TableNode ).getOuterRange()
	).delete();
 
	ve.track( 'activity.table', { action: 'context-delete' } );
};
 
/* Registration */
 
ve.ui.contextItemFactory.register( ve.ui.TableContextItem );