123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- 'use strict';
- define(['underscore', '../../app/nls/StringResources', '../../lib/@waca/core-client/js/core-client/ui/core/Class'], function (_, stringResources, Class) {
-
- var WidgetRegistry = Class.extend({
- initialize: function initialize(dashboardApi) {
- var collectionId = dashboardApi.getCollectionConfig('widget').id;
- return dashboardApi.findGlassCollection(collectionId).then(function (collection) {
-
-
- return this._fnInitializeRegistryItems(collection).then(function () {
-
- return this;
- }.bind(this));
- }.bind(this)).fail(function () {
- throw stringResources.get('errorLoadingWidgetList');
- }.bind(this));
- },
-
- _fnInitializeRegistryItems: function _fnInitializeRegistryItems(collection) {
- if (!collection || !collection.length) {
-
- return Promise.resolve(collection);
- }
- var promises = [];
- _.each(collection, function (item) {
- promises.push(this._fnInitializeRegistryItem(item));
- }.bind(this));
- return Promise.all(promises);
- },
-
- _fnInitializeRegistryItem: function _fnInitializeRegistryItem(item) {
-
- if (item.builtin && item.id.indexOf('.') >= 0) {
- item.id = item.id.replace(/(\w+\.)/g, '');
- } else {
- this._fnInitCustomWidget(item);
- }
-
- _.defaults(item, {
- layoutAuthoringView: 'dashboard-core/js/dashboard/layout/authoring/views/Widget',
- disableTitle: false,
- ownTitle: true,
- createContentNode: true
- });
-
- this[item.id] = item;
- if (!item.modelClassPath || item.ModelClass) {
-
- return Promise.resolve(item);
- }
- return this._fnLoadWidgetModelClass(item.modelClassPath).then(function (ModelClass) {
- item.ModelClass = ModelClass;
- return item;
- });
- },
- _fnLoadWidgetModelClass: function _fnLoadWidgetModelClass(modelClassPath) {
- return new Promise(function (resolve, reject) {
- try {
- require([modelClassPath], resolve, reject);
- } catch (error) {
- reject(error);
- }
- });
- },
- _fnInitCustomWidget: function _fnInitCustomWidget(widget) {
-
- widget = _.defaults(widget, {
- ownTitle: false,
- title: stringResources.get('customWidget'),
- layoutConsumeView: 'dashboard-core/js/dashboard/layout/views/Widget',
- svgIcon: 'dashboard-default-custom-widget',
- scroll: 'scroll',
- propertyLayoutList: [{
- id: 'banner',
- value: widget.title,
- name: 'banner',
- type: 'Banner'
- }],
- propertyList: [{
- id: 'fillColor',
- defaultValue: 'transparent',
- editor: {
- sectionId: 'general.appearance',
- uiControl: {
- type: 'ColorPicker',
- label: stringResources.get('propFillColor'),
- showHexValue: true,
- addButton: true,
- open: false,
- ariaLabel: stringResources.get('propFillColor'),
- paletteType: 'DashboardColorSet'
- }
- }
- }, {
- id: 'borderColor',
- defaultValue: 'transparent',
- editor: {
- sectionId: 'general.appearance',
- uiControl: {
- type: 'ColorPicker',
- label: stringResources.get('propBorderColor'),
- showHexValue: true,
- addButton: true,
- open: false,
- ariaLabel: stringResources.get('propBorderColor'),
- paletteType: 'DashboardColorSet'
- }
- }
- }]
- });
-
- widget.defaultSpec = _.defaults(widget.defaultSpec || {}, {
- model: {
- type: widget.id,
- name: widget.ownTitle ? null : widget.title
- },
- layoutProperties: {
- style: {
- 'display': 'flex',
- 'border': '1px solid transparent',
- 'border-radius': '5px',
- 'flex-direction': 'column',
- 'width': '250px',
- 'height': '250px'
- }
- }
- });
- }
- });
- return WidgetRegistry;
- });
|