123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- 'use strict';
- /**
- * Licensed Materials - Property of IBM IBM Cognos Products: BI Cloud (C)
- *
- * Copyright IBM Corp. 2016, 2020
- *
- * US Government Users Restricted Rights - Use, duplication or disclosure
- * restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['../../lib/@waca/dashboard-common/dist/ui/SearchableListView', '../../lib/@waca/core-client/js/core-client/utils/Deferred', '../../app/nls/StringResources', 'underscore', 'doT', 'text!./templates/CustomWidgetListItem.html', 'text!./templates/EmptyWidgetList.html'], function (BaseView, Deferred, stringResources, _, dot, itemTemplate, emptyTemplate) {
- var WidgetListView = BaseView.extend({
- itemTemplate: itemTemplate,
- events: {
- 'clicktap .listitem': 'onItemClick',
- 'mousedown .listitem': 'onItemStartDrag',
- 'drag .listitem': 'onItemStartDrag'
- },
- init: function init(options) {
- WidgetListView.inherited('init', this, arguments);
- this.options = options || {};
- this.glassContext = options.glassContext;
- this.services = options.services;
- this.dashboardApi = options.dashboardApi;
- this.whenIsReadyDfd = new Deferred();
- this._initialize();
- },
- whenIsReady: function whenIsReady() {
- return this.whenIsReadyDfd.promise;
- },
- accepts: function accepts() {
- return true;
- },
- remove: function remove() {
- if (this._dropZone) {
- this._dropZone.remove();
- this._dropZone = null;
- }
- WidgetListView.inherited('remove', this, arguments);
- },
- render: function render() {
- var dfd = WidgetListView.inherited('render', this);
- dfd.then(function () {
- if (!this.list || this.list.length === 0) {
- var empty = dot.template(emptyTemplate);
- this.$el.find('.list').append(empty({
- text: stringResources.get('noCustomWidgets')
- }));
- }
- }.bind(this));
- return dfd;
- },
- _initialize: function _initialize() {
- var DndManager = this.dashboardApi.getFeature('DashboardDnd.internal');
- this.whenIsReadyDfd.resolve();
- this._dropZone = DndManager.addDropTarget(this.$el[0], {
- accepts: this.accepts.bind(this)
- });
- },
- _getEntry: function _getEntry(ev) {
- var target = this.getTarget(ev.target, 'listitem');
- var dataId = target.getAttribute('data-id');
- // lookup with the id
- return this.widgetMap[dataId];
- },
- onItemClick: function onItemClick(ev) {
- if (this.options.onItemClick) {
- var entry = this._getEntry(ev);
- this.options.onItemClick(entry, ev);
- if (ev && ev.gesture) {
- ev.gesture.preventDefault();
- }
- }
- },
- onItemStartDrag: function onItemStartDrag(ev) {
- if (this.options.onItemStartDrag) {
- var entry = this._getEntry(ev);
- this.options.onItemStartDrag(entry, ev);
- }
- },
- /**
- * Override to provide the list of all custom widgets
- */
- getListItems: function getListItems() {
- var _this = this;
- this.$el.empty();
- return this.options.getEntries({ glassContext: this.options.glassContext }).then(function (content) {
- _this.list = content.list;
- // create the lookup map
- _this.widgetMap = _.object(_.map(content.list, function (item) {
- return [item.id, item];
- }));
- return _this.list;
- });
- },
- /**
- * Override to enable search
- */
- getCustomRenderProperties: function getCustomRenderProperties() {
- return {
- searchText: stringResources.get('find_label')
- };
- },
- /**
- * Override to provide the searchable custom widgets
- */
- _getSearchableItems: function _getSearchableItems() {
- return this.list;
- },
- /**
- * Override to provide the search property of a custom widget
- */
- _getSearchableFieldValue: function _getSearchableFieldValue(value) {
- return value.title;
- }
- });
- return WidgetListView;
- });
- //# sourceMappingURL=CustomWidgetListView.js.map
|