Namespace

cplace

cplace

A global object that provides utility methods for cplaceJS. This is available in every cplaceJS script.

Methods

static actions(pluginNameopt) → {Actions}

Gets actions provided by specified plugin

Parameters:
Name Type Attributes Description
pluginName string <optional>

plugin to get actions for. If plugin name is omitted then actions provided by platform are returned.

Actions provided by the plugin

Actions
Example
var platformActions = cplace.actions();
var platformActions = cplace.actions('cf.cplace.platform');

var myPluginActions = cplace.actions('my.awesome.plugin');

static each(input, callback)

Iterates over an array like object or a javascript native array and performs an operation on every item. The loop can be interrupted by returning false from the provided callback function.

Parameters:
Name Type Description
input ArrayLike.<*>

object to iterate over.

callback IteratingFunction

function to perform on each item.

Examples
cplace.each(input, function (i) {
    cplace.log(i)
});
var set = new HashSet();
set.add(1);
set.add(3);
set.add(4);
set.add(5);
cplace.each(set, function (i) {
     if(i % 2 === 0 ) {
       return false;
     }
     cplace.log(i);
});
// logs - 1 3
For javascript native arrays usage forEach method on the array object is also possible
 var arr = [1, 3, 4, 5];
 arr.forEach(function(i) {
     cplace.log(i);
 });
// logs - 1 3 4 5

static error(object)

Log an error message from cplaceJS script. Error message are also logged to log file. The logged messages are available from admin menu

Parameters:
Name Type Description
object *

an object to be logged. Non-string objects are converted to string.

static formatNumber(value, precisionopt) → {string}

Formats a number to the locale of the current session including decimal delimiters for both, thousands separators and fractions.

Formatting changes the type! The result cannot be used for calculations any longer.

Parameters:
Name Type Attributes Description
value number

number value to format

precision number <optional>

target precision of the formatted number, i.e. how many fractional digits are shown. The result is rounded. This parameter is optional.

  • the formatted number as a string
string
Example
cplace.formatNumber(2/3);    // 0.6666666666666666
cplace.formatNumber(2/3, 1); // 0.7
cplace.formatNumber(2/3, 3); // 0.667
cplace.formatNumber(2/3, 5); // 0.66667

static log(message)

Logs a message.

Parameters:
Name Type Description
message string

the message to log

Example
cplace.log('A simple log message');

static map(input, callback) → {ArrayLike.<*>}

Iterates over an array like object and performs a transformation operation on every item.

Parameters:
Name Type Description
input ArrayLike.<*>

object to iterate over containing items to transform

callback MappingFunction

transformation function to be performed on each item.

An iterable list containing the transformed objects.

ArrayLike.<*>
Example
var arr = [1, 2, 3, 4];
var arr2 = cplace.map(arr, function (i) {
     return i*2;
});
// arr2 - [2, 4, 6, 8]

static setLogName(logName)

Set a name for subsequent log messages. logName will be added to log messages to make it easier to find and filter logs

Parameters:
Name Type Description
logName string

name to be used for log messages

static utils(pluginNameopt) → {Utilities}

Gets utilities provided by specified plugin

Parameters:
Name Type Attributes Description
pluginName string <optional>

plugin to get utilities for. If plugin name is omitted then utilities provided by platform are returned.

Utilities provided by the plugin

Utilities
Example
var platformUtilities = cplace.utils();
var platformUtilities = cplace.utils('cf.cplace.platform');

var myPluginUtilities = cplace.utils('my.awesome.plugin');