Module: alfresco/core/Core

alfresco/core/Core

This should be mixed into all Alfresco widgets and services as it provides the essential functions that they will undoubtedly required, e.g. logging, publication/subscription handling, i18n message handling, etc.
Author:
  • Dave Draper
Support:
  • This module is safe to be mixed into 3rd-party widgets and services (at least until the next major release).
License:
Source:

Members

alfSubscriptions :Array

Used to track of any subscriptions that are made. They will be all be unsubscribed when the destroy function is called.
Type:
  • Array
Default Value:
  • null
Source:

cssRequirements :object[]

An array of the CSS files to use with this widget.
Type:
  • object[]
Default Value:
  • [{cssFile:"./css/Core.css"}]
Source:

dataBindingCallbacks :function[]

This will be used to keep track of all the data event callbacks that are registered for the instance. These will be iterated over and removed when the instance is destroyed.
Type:
  • function[]
Default Value:
  • null
Source:

dataScope :object

This is the scope to use within the data model. If this is not initiated during instantiation then it will be assigned to the root scope of the data model the first time any of the data API functions are used.
Type:
  • object
Default Value:
  • null
Source:

excludeFromPubSubLog :boolean

This has been added purely to prevent any object that inherits from this mixin from being iterated over in the pub/sub log. It aims to prevent infinite loops (although there is protection for this in the SubscriptionLog) module). It should also ensure that only useful information is displayed in the log.
Type:
  • boolean
Default Value:
  • true
Source:

pubSubScope :string

A String that is used to prefix all pub/sub communications to ensure that only relevant publications are handled and issued.
Type:
  • string
Source:

servicesToDestroy :object[]

This will be used to keep track of all services that are created so that they can be destroyed when the current instance is destroyed.
Type:
  • object[]
Default Value:
  • null
Source:

widgetsToDestroy :object[]

This will be used to keep track of all widgets that are created so that they can be destroyed when the current instance is destroyed.
Type:
  • object[]
Default Value:
  • null
Source:

Methods

alfBindDataListener(dotNotation, scope, callback) → {object}

Binds a callback function to an entry in the data model so that when the data is changed the callback will be executed. This allows widgets to respond to data changes dynamically. A reference to the call back will be returned and it is important that these callbacks are deleted when the widget is destroyed to prevent memory leaks.
Parameters:
Name Type Description
dotNotation string A dot notation representation of the location with the data model to bind to
scope object The scope to look for the dot notated data at
callback function The function to call when the data is changed
Source:
Returns:
A reference to the callback so that it can be removed when the caller is destroyed
Type
object

alfCleanFrameworkAttributes(original, modifyOriginal, alsoDelete) → {object}

By default, clones the passed-in object and then deletes any automatically added attributes from the clone. These attributes are added automatically by alfPublish or are used only by the pub/sub framework (e.g. "responseScope"). The cleaned object is then returned. By passing in the "modifyOriginal" flag this will behave identically to the deprecated method it replaces, by removing the framework attributes directly from the passed-in object.
Parameters:
Name Type Argument Default Description
original object The object to clean the attributes from.
modifyOriginal boolean <optional>
false If true, will modify the original object, not a clone.
alsoDelete string[] <optional>
An optional array of strings denoting additional properties to remove from the object being cleaned. It's also possible to pass in properties prefixed with an exclamation mark, to denote that that property should NOT be removed by the default cleaning algorithm (e.g. ["url", "!alfTopic"]).
Since:
  • 1.0.45
Source:
Returns:
The cloned, cleaned object, or if "modifyOriginal" is true then the original, cleaned object.
Type
object

alfConditionalSubscribe(topic, rules, success, failure, global, parentScope, customScope) → {object}

Subscribe to a publication and then analyse the payload. Depending on whether it matches the provided rules object, apply the success or failure callback as appropriate. Please see the underlying method for more information.
Parameters:
Name Type Argument Description
topic string The topic on which to subscribe
rules module:alfresco/util/objectUtils#Rules The rules object to apply
success function The function to run if successful
failure function <optional>
The function to run if unsuccessful
global boolean <optional>
Indicates that the pub/sub scope should not be applied
parentScope boolean <optional>
Indicates that the pub/sub scope inherited from the parent should be applied
customScope string <optional>
A custom pub/sub scope that should be applied
Since:
  • 1.0.44
Source:
Returns:
A handle to the subscription
Type
object

alfDeleteFrameworkAttributes(object)

Deletes any automatically added publish attributes from the supplied object. These are attributes that will have been added to the object by the alfPublish function.
Parameters:
Name Type Description
object object The object to remove the attributes from.
Deprecated:
  • Since 1.0.45 - Use alfCleanFrameworkAttributes instead.
    Source:

    alfGetData(dotNotation, scope) → {object}

    This gets the data from the location in the model defined by the scope. If no explicit scope is provided then the instance scope will be used.
    Parameters:
    Name Type Description
    dotNotation string A dot notation representation of the location within the data model to get
    scope object The scope to get the data from. If null then then instance scope will be used.
    Source:
    Returns:
    The data at the supplied location
    Type
    object

    alfLog(severity, message)

    This function is intended to provide the entry point to all client-side logging from the application. By default it simply delegates to the standard browser console object but could optionally be overridden or extended to provide advanced capabilities like posting client-side logs back to the server, etc.
    Parameters:
    Name Type Description
    severity string The severity of the message to be logged
    message string The message to be logged
    Support:
    • This function is safe to call by extending or mixing modules (at least until the next major release).
    Source:

    alfProcessDataDotNotation(dotNotation) → {string}

    This function converts notation into an internal notation style.
    Parameters:
    Name Type Description
    dotNotation string A dot notation representation of the location within the data model to set.
    Source:
    Returns:
    The processed notation
    Type
    string

    alfPublish(topics, payload, global, parentScope, customScope)

    This function wraps the standard Dojo publish function. It should always be used rather than calling the Dojo implementation directly to allow us to make changes to the implementation or to introduce additional features (such as scoping) or updates to the payload.
    Parameters:
    Name Type Argument Description
    topics String | Array The topic(s) on which to publish
    payload object The payload to publish on the supplied topic
    Properties
    Name Type Argument Description
    responseScope string <optional>
    The scope to use when any response is published
    global boolean <optional>
    Indicates that the pub/sub scope should not be applied
    parentScope boolean <optional>
    Indicates that the pub/sub scope inherited from the parent should be applied
    customScope String <optional>
    A custom scope to use for this publish (will only be used if both global and parentScope are falsy)
    Support:
    • This function is safe to call by extending or mixing modules (at least until the next major release).
    Source:

    alfPublishDelayed(topic, payload, delay)

    Publish an event after waiting for the specified delay.
    Parameters:
    Name Type Description
    topic String topic to publish
    payload Object the payload to be pushed to the publish event
    delay Number ms delay in how long to wait before publishing the event
    Source:

    alfPublishToPromise(topic, payload, global, parentScope) → {object}

    Submit a pub-sub request (i.e. do a publish) and return a promise that will resolve to the returned subscription. This is specifically for occasions when doing a publish with a UUID, where the response (i.e. subsequent subscription) is only relevant for this one instance. The response topic is generated automatically, and does not need to be supplied in the payload.
    Parameters:
    Name Type Argument Description
    topic String The topic on which to publish
    payload object The payload to publish on the supplied topic
    global boolean <optional>
    Indicates that the pub/sub scope should not be applied
    parentScope boolean <optional>
    Indicates that the pub/sub scope inherited from the parent should be applied
    Source:
    Returns:
    A dojo/promise/Promise
    Type
    object

    alfRemoveDataListener(binding)

    Parameters:
    Name Type Description
    binding object The binding object
    Source:

    alfServicePublish(topics, payload, scope)

    Publishes to a service. This method calls alfPublish() behind the scenes. Will automatically scope the call to global to that the service will pick it up successfully (most services subscribe to topics with a global scope).
    Parameters:
    Name Type Argument Description
    topics string | Array.<string> The topic(s) on which to publish
    payload Object The payload to publish on the supplied topic
    Properties
    Name Type Argument Description
    responseScope string <optional>
    The scope to use when any response is published
    scope String <optional>
    Use this to scope the publish (only use with scoped services)
    Source:

    alfSetData(dotNotation, value, scope) → {object}

    This both sets data and registers the widget of as the owner of the data. This is done so that when the widget is destroyed the data it owned will be removed from the data model
    Parameters:
    Name Type Description
    dotNotation string A dot notation representation of the location within the data model to set.
    value object The value to set
    scope object The scope to set the data at. If null the instance scope will be used.
    Source:
    Returns:
    An object that the widget can use to remove the data when it is destroyed.
    Type
    object

    alfSubscribe(topic, callback, global, parentScope, customScope) → {object}

    This function wraps the standard Dojo subscribe function. It should always be used rather than calling the Dojo implementation directly to allow us to make changes to the implementation or to introduce additional features (such as scoping) or updates to the callback. The subscription handle that gets created is add to alfSubscriptions
    Parameters:
    Name Type Argument Description
    topic string The topic on which to subscribe
    callback function The callback function to call when the topic is published on.
    global boolean <optional>
    Indicates that the pub/sub scope should not be applied
    parentScope boolean <optional>
    Indicates that the pub/sub scope inherited from the parent should be applied
    customScope String <optional>
    A custom scope to use for this publish (will only be used if both global and parentScope are falsy)
    Support:
    • This function is safe to call by extending or mixing modules (at least until the next major release).
    Source:
    Returns:
    A handle to the subscription
    Type
    object

    alfUnsubscribe(handle)

    This function wraps the standard unsubscribe function. It should always be used rather than call the Dojo implementation directly.
    Parameters:
    Name Type Description
    handle object | array The subscription handle to unsubscribe
    Support:
    • This function is safe to call by extending or mixing modules (at least until the next major release).
    Source:

    alfUnsubscribeSaveHandles(handles)

    This is a helper function for unsubscribing from subscription handles that are set-up with unique topics to guarantee recipients.
    Parameters:
    Name Type Description
    handles array The handles to unsubscribe
    Support:
    • This function is safe to call by extending or mixing modules (at least until the next major release).
    Source:

    decodeHTML()

    This function can be called to decode strings that have previously been encoded using encodeHTML.
    Since:
    • 1.0.50
    Support:
    • This function is safe to call by extending or mixing modules (at least until the next major release).
    Source:
    Returns:
    The decoded input string

    destroy(preserveDom)

    This function will override a destroy method if available (e.g. if this has been mixed into a widget instance) so that any subscriptions that have been made can be removed. This is necessary because subscriptions are not automatically cleaned up when the widget is destroyed. This also removes any data binding listeners that have been registered.
    Parameters:
    Name Type Description
    preserveDom boolean
    Support:
    • This function is safe to call by extending or mixing modules (at least until the next major release).
    Source:

    encodeHTML()

    Use this function to ensure that all text added to the HTML page is encoded to prevent XSS style attacks. This wraps the dojox/html/entities encode function. It is intentionally wrapped so that if we need to make a change (e.g. change the encoding handling) we can make it in one place
    Support:
    • This function is safe to call by extending or mixing modules (at least until the next major release).
    Source:
    Returns:
    The encoded input string

    generateUuid() → {string}

    Creates and returns a new UUID (universally unique identifier). The UUID is generated using the dojox/uuid/generateRandomUuid module
    Source:
    Returns:
    A new UUID
    Type
    string

    message(p_messageId, messageArgs) → {string}

    This function is based on the version that can be found in alfresco.js. It searches through all of the available scopes for the widget and for all of the widgets inherited from.
    Parameters:
    Name Type Argument Description
    p_messageId string The id of the message to be displayed.
    messageArgs Object <optional>
    <repeatable>
    A single object with integer keys or multiple objects, either of which can be used to mix into a message string
    Support:
    • This function is safe to call by extending or mixing modules (at least until the next major release).
    Source:
    Returns:
    A localized form of the supplied message
    Type
    string