baja/comp/ControlPoint.js
/**
* @copyright 2015 Tridium, Inc. All Rights Reserved.
* @author Gareth Johnson
*/
/**
* Defines a BajaScript implementation of `control:ControlPoint` (not exposed
* on `baja` namespace).
* @module baja/comp/ControlPoint
*/
define(["bajaScript/sys",
"bajaScript/baja/comp/Component"], function (
baja,
Component) {
"use strict";
var subclass = baja.subclass,
callSuper = baja.callSuper,
slotRegex = /^(out|in([1-9]|1[0-6])|fallback|override|emergencyOverride|set)$/;
/** the slots for which we swap out the `facets` slot for `getSlotFacets` */
function matchesRegex(slot) { return slot && !!slot.getName().match(slotRegex); }
/**
* Represents a `control:ControlPoint` in BajaScript.
*
* @class
* @alias module:baja/comp/ControlPoint
* @extends baja.Component
* @private
*/
var ControlPoint = function ControlPoint() {
var that = this;
callSuper(ControlPoint, that, arguments);
that.attach('changed', function (slot, cx) {
if (slot.getName() === 'facets') {
that.getSlots().filter(matchesRegex).each(function (slot) {
that.fireHandlers('facetsChanged', baja.error, that, slot, cx);
});
}
});
};
// Set up the prototype chain
subclass(ControlPoint, Component);
/**
* Return the `Facets` for a Slot.
*
* If no arguments are provided and the `Complex` has a parent, the
* facets for the parent's Property will be returned.
*
* @private
* @inner
*
* @param {baja.Slot|String} [slot] the Slot or Slot name.
* @returns {baja.Facets} the Facets for the Slot (or null if Slot not found) or
* the parent's Property facets.
*/
ControlPoint.prototype.getFacets = function (slot) {
// Attempt to match Station Component's 'getSlotFacets' implementation...
if (slot && matchesRegex(this.getSlot(slot))) {
return this.get("facets");
}
// Call base class 'getFacets'
return callSuper("getFacets", ControlPoint, this, arguments);
};
return ControlPoint;
});