define([
'layout/js/api/LayoutConstants',
'layout.dt/js/metadata/ElementMetadata'
], function(
LayoutConstants,
ElementMetadata
) {
'use strict';
/**
* Content map of a theme. It identifies specific element IDs within the
* theme's template that should have dynamic content inserted by ABCS.
*
* @AbcsExtension stable
* @version 17.1.5
*
* @exports layout.dt/js/api/ThemeComponentMap
* @constructor
*
* @see {@link layout.dt/js/spi/ThemeProvider#getComponentMap ThemeProvider.getComponentMap}
* theme provider SPI method to return a theme's component map
*/
var ThemeComponentMap = function() {
AbcsLib.checkParameterCount(arguments, 0);
AbcsLib.checkThis(this);
var self = this;
self._elements = [];
};
/**
* Adds a theme area. A theme area is an element that, when clicked by the
* user, will open the theme property inspector in the ABCS designer.
*
* @AbcsExtension stable
* @version 17.1.5
*
* @param {String} elementId The element ID within the theme template
* @returns {layout.dt/js/api/ThemeComponentMap} a reference to this object
* to allow method chaining
*/
ThemeComponentMap.prototype.addThemeArea = function(elementId) {
AbcsLib.checkParameterCount(arguments, 1);
AbcsLib.checkDataType(elementId, AbcsLib.Type.STRING);
this._elements.push(new ElementMetadata(elementId, undefined, ElementMetadata.Type.THEME_AREA, undefined, undefined, undefined));
return this;
};
/**
* Adds a title. A title element will be replaced by ABCS with an element
* containing the title configured for the application in the property
* inspector.
*
* @AbcsExtension stable
* @version 17.1.5
*
* @param {String} elementId The element ID within the theme
* @returns {layout.dt/js/api/ThemeComponentMap} a reference to this object
* to allow method chaining
*/
ThemeComponentMap.prototype.addTitle = function(elementId) {
AbcsLib.checkParameterCount(arguments, 1);
AbcsLib.checkDataType(elementId, AbcsLib.Type.STRING);
this._elements.push(new ElementMetadata(elementId, undefined, ElementMetadata.Type.LABEL, undefined, ElementMetadata.PropertyName.NAME, LayoutConstants.APP_TITLE_ID));
return this;
};
/**
* Adds a logo. A logo element will be replaced by ABCS with an image
* showing the logo configured for the application in the property
* inspector.
*
* @AbcsExtension stable
* @version 17.1.5
*
* @param {String} elementId The element ID within the theme
* @returns {layout.dt/js/api/ThemeComponentMap} a reference to this object
* to allow method chaining
*/
ThemeComponentMap.prototype.addLogo = function(elementId) {
AbcsLib.checkParameterCount(arguments, 1);
AbcsLib.checkDataType(elementId, AbcsLib.Type.STRING);
this._elements.push(new ElementMetadata(elementId, undefined, ElementMetadata.Type.IMAGE, undefined, ElementMetadata.PropertyName.LOGO, LayoutConstants.APP_LOGO_ID));
return this;
};
/**
* Adds a copyright message. The copyright element will be replaced by ABCS
* with the copyright message configured for the application in the
* property inspector.
*
* @AbcsExtension stable
* @version 17.1.5
*
* @param {String} elementId The element ID within the theme
* @returns {layout.dt/js/api/ThemeComponentMap} a reference to this object
* to allow method chaining
*/
ThemeComponentMap.prototype.addCopyright = function(elementId) {
AbcsLib.checkParameterCount(arguments, 1);
AbcsLib.checkDataType(elementId, AbcsLib.Type.STRING);
this._elements.push(new ElementMetadata(elementId, undefined, ElementMetadata.Type.LABEL, undefined, ElementMetadata.PropertyName.COPYRIGHT, LayoutConstants.APP_COPYRIGHT_ID));
return this;
};
/**
* Adds a language switcher area. A language switcher is an element that
* ABCS will apply knockout bindings to allow the access to the locales
* for which translations are available.
* @AbcsExtension stable
* @version 17.2.3
*
* @param {String} elementId The element ID within the theme
* @returns {layout.dt/js/api/ThemeComponentMap} a reference to this object
* to allow method chaining
*/
ThemeComponentMap.prototype.addLanguageSwitcher = function(elementId) {
AbcsLib.checkParameterCount(arguments, 1);
AbcsLib.checkDataType(elementId, AbcsLib.Type.STRING);
this._elements.push(new ElementMetadata(elementId, undefined, ElementMetadata.Type.LANGUAGE_SWITCHER, undefined, ElementMetadata.PropertyName.LANGUAGE_SWITCHER, LayoutConstants.APP_LANGUAGE_SWITCHER_ID));
return this;
};
/**
* Adds a user area. A user area is an element that ABCS will apply
* knockout bindings to to allow the current user and help link to be
* accessed.
*
* @AbcsExtension stable
* @version 17.1.5
*
* @param {String} elementId The element ID within the theme
* @returns {layout.dt/js/api/ThemeComponentMap} a reference to this object
* to allow method chaining
*/
ThemeComponentMap.prototype.addUserArea = function(elementId) {
AbcsLib.checkParameterCount(arguments, 1);
AbcsLib.checkDataType(elementId, AbcsLib.Type.STRING);
this._elements.push(new ElementMetadata(elementId, undefined, ElementMetadata.Type.USER_AREA, undefined, ElementMetadata.PropertyName.USER_AREA, LayoutConstants.APP_USER_AREA_ID));
return this;
};
/**
* Adds a menu area. A menu area is an element that ABCS will apply
* knockout bindings to to allow the structure of the main application
* menu to be accessed.
*
* @AbcsExtension stable
* @version 17.1.5
*
* @param {String} elementId The element ID within the theme
* @param {Object} [options] Structure for passing additional options, as follows:
* @param {String[]} options.boundIds Alternative IDs within the theme to
* bind the menu model to
* @param {String[]} options.alternateIds Alternative IDs within the theme
* used, for example, to display an alternative version of the menu
* for other device formats
* @param {number} options.maxDepth Maximum depth of menu that this theme
* can support
* @returns {layout.dt/js/api/ThemeComponentMap} a reference to this object
* to allow method chaining
*/
ThemeComponentMap.prototype.addMenuArea = function(elementId, options) {
AbcsLib.checkParameterCount(arguments, 1, 1);
AbcsLib.checkDataType(elementId, AbcsLib.Type.STRING);
if (options !== undefined) {
// Optional parameter. Check only if defined.
AbcsLib.checkDataType(options, AbcsLib.Type.OBJECT);
AbcsLib.checkObjectLiteral(options, ['boundIds', 'alternateIds', 'maxDepth']);
}
options = options || {};
var boundIds = options.boundIds;
var alternateIds = options.alternateIds;
var maxDepth = options.maxDepth;
var data = {};
this._setAlternateIds(data, alternateIds);
this._setBoundIds(data, boundIds);
if (maxDepth) {
data[ElementMetadata.DataConstant.MENU_MAX_DEPTH] = maxDepth;
}
this._elements.push(new ElementMetadata(elementId, undefined, ElementMetadata.Type.MAIN_MENU, data, ElementMetadata.PropertyName.MAIN_MENU, LayoutConstants.APP_MAIN_MENU_ID));
return this;
};
/**
* Adds a favicon. A favicon element will be replaced by ABCS with an image
* showing the favicon configured for the application in application
* settings.
*
* @AbcsExtension stable
* @version 17.1.5
*
* @param {String} elementId The element ID within the theme
* @returns {layout.dt/js/api/ThemeComponentMap} a reference to this object
* to allow method chaining
*/
ThemeComponentMap.prototype.addFavicon = function(elementId) {
AbcsLib.checkParameterCount(arguments, 1);
AbcsLib.checkDataType(elementId, AbcsLib.Type.STRING);
this._elements.push(new ElementMetadata(elementId, undefined, ElementMetadata.Type.FAVICON, undefined, ElementMetadata.PropertyName.FAVICON, LayoutConstants.APP_FAVICON_ID));
return this;
};
/**
* Adds a breadcrumbs to the layout shell DOM. The element found for given elementId
* will be fed by ABCS with template used for breadcrumbs navigation.
*
* @AbcsExtension unstable
* @version 17.2.5
*
* @param {String} elementId The element ID within the theme template
* @param {Object} [options] Structure for passing additional options, as follows:
* @param {RegExp[]} options.exclude List of RegExp which defines on which pages should
* be the breadcrumbs navigation excluded. Can be used in example for exlcusion
* on the home page of the application etc.
* @returns {layout.dt/js/api/ThemeComponentMap} a reference to this object
* to allow method chaining
*/
ThemeComponentMap.prototype.addBreadcrumbs = function(elementId, options) {
AbcsLib.checkParameterCount(arguments, 1, 1);
AbcsLib.checkDataType(elementId, AbcsLib.Type.STRING);
if (options !== undefined) {
// Optional parameter. Check only if defined.
AbcsLib.checkDataType(options, AbcsLib.Type.OBJECT);
AbcsLib.checkObjectLiteral(options, ['exclude']);
if (options.exclude) {
AbcsLib.checkDataType(options.exclude, AbcsLib.Type.ARRAY);
options.exclude.forEach(function(excludeEntry) {
AbcsLib.checkDataType(excludeEntry, AbcsLib.Type.REGEXP);
});
}
}
this._elements.push(new ElementMetadata(elementId, undefined, ElementMetadata.Type.BREADCRUMBS, options, undefined, LayoutConstants.APP_BREADCRUMBS_ID));
return this;
};
/**
* Build ElementMetadata data structure for alternate IDs.
*
* @param {Object} data Existing data object
* @param {String[]} alternateIds
* @returns {undefined}
*/
ThemeComponentMap.prototype._setAlternateIds = function(data, alternateIds) {
if (alternateIds) {
data[ElementMetadata.DataConstant.ALTERNATE_ID] = AbcsLib.isArray(alternateIds) ? alternateIds : [alternateIds];
}
};
/**
* Build ElementMetadata data structure for bound IDs.
*
* @param {Object} data Existing data object
* @param {String[]} boundIds
* @returns {undefined}
*/
ThemeComponentMap.prototype._setBoundIds = function(data, boundIds) {
if (boundIds) {
data[ElementMetadata.DataConstant.MENU_BOUND_ID] = AbcsLib.isArray(boundIds) ? boundIds : [boundIds];
}
};
/**
* Gets the content map as an array of ElementMetadata objects.
*
* @returns {ElementMetadata[]} list of elements
*/
ThemeComponentMap.prototype.getElements = function() {
AbcsLib.checkParameterCount(arguments, 0);
return this._elements;
};
return ThemeComponentMap;
});