Class: Complex

baja. Complex


new Complex()

Complex is the Value which is defined by one or more
property slots. Complex is never used directly, rather
it is the base class for Struct and Component.

Since Complex relates to a abstract Type, this Constructor should
never be directly used to create a new object.

See:

Extends

Methods


equals(obj)

Indicates whether some other object is equal to this one.

Parameters:
Name Type Description
obj Object

the reference object with which to compare.

Inherited From:
Returns:

true if this object is the same as the obj argument; false otherwise.

Type
Boolean

equivalent(obj)

Compare if all of this object's properties are equal to the specified object.

Parameters:
Name Type Description
obj baja.Complex
Overrides:
Returns:

true if this object is equivalent to the specified object.

Type
Boolean

get(prop)

Return a Property's value.

Note that when an instance of a Complex is created, auto-generated
accessors are created to make accessing a frozen Property's value
convenient (see example).

Parameters:
Name Type Description
prop baja.Property | String

the Property or Property name.

Returns:

the value for the Property (null if the Property doesn't exist).

Type
baja.Value
Example

Note that when an instance of a Complex is created, auto-generated setters are created to make setting a frozen Property's value convenient. The auto-generated setter is in the format of set(first letter is capitalized)SlotName(...).

// myPoint has a frozen Property named out...
  var val = myPoint.getOut();
  val = myPoint.get('out'); //equivalent

getAgents( [is], batch)

Returns a promise that resolves to the agent list for this Object.

Parameters:
Name Type Argument Description
is Array.<String> <optional>

An optional array of filters to add to the
agent query.

batch baja.comm.Batch

An optional object used to batch network
calls together.

Inherited From:
See:
Returns:

A promise that will resolve with the Agent Info.

Type
Promise

getDisplay( [slot])

Return a display string.

If a Slot argument is defined, the display name for the Slot will be
returned. If a Slot argument is not defined, the display name for the
Complex will be returned.

Note that when an instance of a Complex is created, auto-generated
accessors are created to make accessing a frozen Slot's display string
convenient (see example).

Parameters:
Name Type Argument Description
slot baja.Slot | String <optional>

the Slot or Slot name.

Returns:

display (or null if none available).

Type
String
Example

The auto-generated accessor is in the format of get(first letter is capitalized)SlotNameDisplay(). If the name of an automatically generated method is already used in the Complex, a number will be added to the function name.

// myPoint has a Property named out...
  baja.outln("The display string of the out Property: " + myPoint.getOutDisplay());

getDisplayName( [slot])

Return a display name.

If a Slot is defined as an argument, the display name for the slot will
be returned. If no Slot is defined, the display name of the Complex
will be returned.

Parameters:
Name Type Argument Description
slot baja.Slot | String <optional>

the Slot or Slot name.

Returns:

the display name (or null if none available).

Type
String

getFacets( [slot])

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.

Parameters:
Name Type Argument Description
slot baja.Slot | String <optional>

the Slot or Slot name.

Returns:

the Facets for the Slot (or null if Slot not
found) or the parent's Property facets.

Type
baja.Facets

getFlags( [slot])

Return Flags for a slot or for the Complex's parent Property.

If no arguments are provided and the Complex has a parent, the
flags for the parent's Property will be returned.

Parameters:
Name Type Argument Description
slot baja.Slot | String <optional>

Slot or Slot name.

See:
Returns:

the flags for the Slot or the parent's Property flags.

Type
Number

getIcon()

Return the Object's Icon.

Inherited From:
Returns:
Type
baja.Icon

getName()

Return the name of the Component.

The name is taken from the parent Component's Property for this
Component instance.

Returns:

name (null if not mounted).

Type
String

getParent()

Return the parent.

Returns:

parent

Type
baja.Complex

getPropertyInParent()

Return the Property in the parent.

Returns:

the Property in the parent (null if not mounted).

Type
baja.Property

getSlot(slot)

Return the Slot.

This is useful method to ensure you have the Slot instance instead of the
Slot name String. If a Slot is passed in, it will simply be checked and
returned.

Parameters:
Name Type Description
slot baja.Slot | String

the Slot or Slot name.

Returns:

the Slot for the Component (or null if the
Slot doesn't exist).

Type
baja.Slot

getSlots( [filter])

Return a Cursor for accessing a Complex's Slots.

Please see module:baja/comp/SlotCursor for useful builder methods.

Parameters:
Name Type Argument Description
filter function <optional>

function to filter out the Slots we're not interested in.
The filter function will be passed each Slot to see if it should be
be included. The function must return false to filter out a value and true
to keep it.

Returns:

a Cursor for iterating through the Complex's Slots.

Type
module:baja/comp/SlotCursor
Example
// A Cursor for Dynamic Properties
  var frozenPropCursor = myComp.getSlots().dynamic().properties();

  // A Cursor for Frozen Actions
  var frozenPropCursor = myComp.getSlots().frozen().actions();

  // An Array of Control Points
  var valArray = myComp.getSlots().properties().is("control:ControlPoint").toValueArray();

  // An Array of Action Slots
  var actionArray = myComp.getSlots().actions().toArray();

  // An Object Map of slot name/value pairs
  var map = myComp.getSlots().properties().toMap();

  // The very first dynamic Property
  var firstProp = myComp.getSlots().dynamic().properties().first();

  // The very last dynamic Property
  var lastProp = myComp.getSlots().dynamic().properties().last();

  // The very first dynamic Property value
  var firstVal = myComp.getSlots().dynamic().properties().firstValue();

  // The very first dynamic Property value
  var lastVal = myComp.getSlots().dynamic().properties().lastValue();

  // All the Slots that start with the name 'foo'
  var slotNameCursor = myComp.getSlots().slotName(/^foo/);

  // Use a custom Cursor to find all of the Slots that have a particular facets key/value
  var custom = myComp.getSlots(function (slot) {
     return slot.isProperty() && (this.getFacets(slot).get("myKey", "def") === "foo");
  });

  // Same as above
  var custom2 = myComp.getSlots().filter(function (slot) {
     return slot.isProperty() && (this.getFacets(slot).get("myKey", "def") === "foo");
  });
  
  // All Slots marked summary on the Component
  var summarySlotCursor = myComp.getSlots().flags(baja.Flags.SUMMARY);

  // Call function for each Property that's a ControlPoint
  myComp.getSlots().is("control:ControlPoint").each(function (slot) {
    baja.outln("The Nav ORD for the ControlPoint: " + this.get(slot).getNavOrd();
  });

getType()

Get the type of this instance.

Inherited From:
Returns:
Type
Type

getValueOf(prop)

Return the result of valueOf on the specified Property's value.
If valueOf is not available then the Property's value is returned.

Parameters:
Name Type Description
prop baja.Property | String

the Property or Property name.

See:
Returns:

the valueOf for the Property's value or the Property's
value (null if the Property doesn't exist).


has(prop)

Return true if the Slot exists.

Parameters:
Name Type Description
prop baja.Property | String

the Property or Property name

Returns:
Type
Boolean

loadSlots( [obj])

Load all of the Slots on the Complex.

Parameters:
Name Type Argument Description
obj Object <optional>

the object literal for the method's arguments.

Properties
Name Type Argument Description
ok function <optional>

(Deprecated: use Promise) the ok function
callback. Called once network call has succeeded on the Server.

fail function <optional>

(Deprecated: use Promise) the fail function
callback. Called if this method has an error.

batch baja.comm.Batch <optional>

if defined, any network calls will be
batched into this object.

See:
Returns:

a promise to be resolved when the slots have been
loaded.

Type
Promise

newCopy( [exact])

Create a clone of this Complex.

If the exact argument is true and this Complex is a Component then
the defaultOnClone and removeOnClone flags will be ignored.

Parameters:
Name Type Argument Default Description
exact Boolean <optional>
false

flag to indicate whether to create an exact copy

Overrides:
Returns:

cloned Complex.

Type
baja.Complex

set(obj)

Set a Property's value.

If the Complex is mounted, this will asynchronously set the Property's
value on the Server.

Parameters:
Name Type Description
obj Object

the object literal for the method's arguments.

Properties
Name Type Argument Description
slot baja.Property | String

the Property or Property name
the value will be set on.

value

the value being set (Type must extend baja:Value).

ok function <optional>

(Deprecated: use Promise) the ok function
callback. Called once the network call has succeeded on the Server.

fail function <optional>

(Deprecated: use Promise) the fail function
callback. Called if this method has an error.

batch baja.comm.Batch <optional>

if defined, any network calls will be
batched into this object.

cx <optional>

the Context (used internally by BajaScript).

Returns:

a promise that will be resolved once the value has been
set on the Complex. If the complex is mounted, will be resolved once the
value has been saved to the server.

Type
Promise
Examples

An object literal is used to specify the method's arguments.

myObj.set({
    slot: "outsideAirTemp",
    value: 23.5,
    batch: myBatch // if defined, any network calls will be batched into this object (optional)
  })
    .then(function () {
      baja.outln('value has been set on the server');
    })
    .catch(function (err) {
      baja.error('value failed to set on the server: ' + err);
    });

Note that when an instance of a Complex is created, auto-generated setters are created to make setting a frozen Property's value convenient. The auto-generated setter is in the format of set(first letter is capitalized)SlotName(...).

// myPoint has a Property named outsideAirTemp...
  myObj.setOutsideAirTemp(23.5);
  
  // ... or via an Object Literal if more arguments are needed...
  
  myObj.setOutsideAirTemp({ value: 23.5, batch: myBatch })
    .then(function () {
      baja.outln('value has been set on the server');
    });

toString()

Return the String representation.

Overrides:
Returns:
Type
String

valueOf()

Return the inner value of the object.

By default the object's instance is returned.

Inherited From:
Returns:

the inner value of the object or just the object's instance.

Type
*