All files / src/ui ve.ui.NodeWindow.js

95.23% Statements 20/21
62.5% Branches 5/8
100% Functions 8/8
95.23% Lines 20/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96                                      1x   1x         1x                     1x                     1x 8x                       1x 16x 16x   16x     16x     16x               1x 4x 4x 4x             1x 4x 4x 4x      
/*!
 * VisualEditor user interface NodeWindow class.
 *
 * @copyright See AUTHORS.txt
 */
 
/**
 * Mixin for window for working with a node.
 *
 * Conceptually this extends a FragmentWindow, but as this and FragmentWindow
 * are both are mixins, we don't need to set up actual inheritance here,
 * that is handled by the concrete classes NodeDialog & NodeInspector. T264690
 *
 * @class
 * @abstract
 *
 * @constructor
 * @param {Object} [config] Configuration options
 */
ve.ui.NodeWindow = function VeUiNodeWindow() {
	// Properties
	this.selectedNode = null;
};
 
/* Inheritance */
 
OO.initClass( ve.ui.NodeWindow );
 
/* Static Properties */
 
/**
 * Node classes compatible with this dialog.
 *
 * @static
 * @property {Function}
 * @inheritable
 */
ve.ui.NodeWindow.static.modelClasses = [];
 
/* Methods */
 
/**
 * Check if the current node is editable by this window.
 *
 * @localdoc Returns true if the node being edited selects at least one model,
 *
 * @return {boolean} Node is editable by this window
 */
ve.ui.NodeWindow.prototype.isEditing = function () {
	return !!this.getSelectedNode();
};
 
/**
 * Get the selected node.
 *
 * Should only be called after setup and before teardown.
 * If no node is selected or the selected node is incompatible, null will be returned.
 *
 * @param {Object} [data] Window opening data
 * @return {ve.dm.Node|null} Selected node
 */
ve.ui.NodeWindow.prototype.getSelectedNode = function () {
	var modelClasses = this.constructor.static.modelClasses,
		selectedNode = this.getFragment().getSelectedNode();
 
	Eif (
		selectedNode &&
		modelClasses.some( function ( modelClass ) {
			return selectedNode instanceof modelClass;
		} )
	) {
		return selectedNode;
	}
	return null;
};
 
/**
 * @inheritdoc OO.ui.Window
 */
ve.ui.NodeWindow.prototype.getSetupProcess = function ( data, process ) {
	data = data || {};
	return process.next( function () {
		this.selectedNode = this.getSelectedNode( data );
	}, this );
};
 
/**
 * @inheritdoc OO.ui.Window
 */
ve.ui.NodeWindow.prototype.getTeardownProcess = function ( data, process ) {
	data = data || {};
	return process.next( function () {
		this.selectedNode = null;
	}, this );
};