123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- "use strict";
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: admin
- * Copyright IBM Corp. 2015, 2018
- * US Government Users Restricted Rights
- * Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['jquery', 'doT', 'q', 'underscore', 'bi/commons/ui/View', 'bi/admin/common/ui/MagicWand', 'bi/admin/nls/StringResource', 'bacontentnav/utils/WidgetNavigator', 'text!bi/admin/common/templates/GroupListTemplate.html', 'bi/commons/utils/ContentFormatter'], function ($, dot, Q, _, View, MagicWand, StringResource, WidgetNavigator, listTemp, ContentFormatter) {
- //NOSONAR: needed for amd
- 'use strict'; //NOSONAR: meant to be strict
- var GroupListView = View.extend({
- items: null,
- simpleList: false,
- showListHeader: false,
- showGroupHeader: false,
- showFilter: true,
- showAddButton: false,
- filterTips: StringResource.get('filterTips'),
- listHeader: '',
- template: listTemp,
- /**
- * @constructor
- */
- init: function init(options) {
- GroupListView.inherited('init', this, arguments);
- _.extend(this, options);
- },
- /**
- Main entry point - will render the form view
- **/
- render: function render(items) {
- var htmlStr = dot.template(listTemp)({
- showFilter: this.showFilter,
- showAddButton: this.showAddButton,
- addButtonTip: this.addButtonTip
- });
- this.$el.html(htmlStr);
- var deferred = Q.defer();
- var self = this;
- if (this.showAddButton) {
- this.$el.find('#button_add').on('primaryaction', function () {
- this.trigger('addItem');
- }.bind(this));
- }
- this._renderListBody(items);
- if (this.showFilter) {
- MagicWand.searchInput(this.$el).done(function (widgets) {
- if (widgets.length === 1) {
- this._filterInput = widgets[0];
- this._filterInput.options.hint = self.filterTips;
- this._filterInput.on('changed', function (e) {
- var trimmed = e.text.trim();
- if (trimmed.length > 0 || e.text === '') {
- var filterStr = e.text;
- var filteredItems = _.filter(self.items, function (item) {
- var searchTerm = item.title ? item.title : item.defaultName;
- return searchTerm.toLowerCase().indexOf(trimmed.toLowerCase()) !== -1;
- });
- self._renderListBody(filteredItems);
- }
- });
- deferred.resolve();
- }
- }.bind(this));
- } else {
- deferred.resolve();
- }
- return deferred.promise;
- },
- _getTemplateOptions: function _getTemplateOptions(items) {
- var listItems = items || this.items;
- var groupedData;
- if (items && items.length) {
- groupedData = {};
- groupedData.simpleList = this.simpleList;
- groupedData.showGroupHeader = this.showGroupHeader;
- groupedData.showListHeader = this.showListHeader;
- groupedData.listHeader = this.listHeader;
- var lItems = {
- "group": listItems
- };
- groupedData.items = lItems;
- }
- return groupedData;
- },
- _renderListBody: function _renderListBody(items, bClearFilter) {
- var htmlStr;
- var groupedData = this._getTemplateOptions(items);
- if (groupedData) {
- htmlStr = dot.template(this.template)(groupedData);
- } else {
- htmlStr = '<span class="blank-content"><i class="wft_bee"></i><span class="msg">' + StringResource.get('nothingFound') + '</span></span>';
- }
- this.$el.find('div.bi-admin-listbody').html(htmlStr);
- if (bClearFilter) {
- this.$el.find('#filterInput').val('');
- }
- this._bindEvents();
- this.widgetKeyController = new WidgetNavigator({
- $el: this.$el.find(".groupList-table"),
- focusClass: "groupListFocusable",
- fCallBack: function fCallBack() {}
- });
- this._shortenLabelText();
- },
- _shortenLabelText: function _shortenLabelText() {
- $.each(this.$el.find(".admin-grouplist-title"), function (index, value) {
- ContentFormatter.middleShortenString(value);
- });
- this.$el.find(".list-item.bi-admin-hidden").removeClass("bi-admin-hidden");
- },
- _getItemById: function _getItemById(id) {
- var item = _.find(this.items, function (item) {
- return id === item.id;
- });
- return item;
- },
- _getItemByConnId: function _getItemByConnId(id) {
- var item = _.find(this.items, function (item) {
- return id === item.connId;
- });
- return item;
- },
- _bindEvents: function _bindEvents() {
- var $items = this.$el.find('tr.list-item');
- var self = this;
- $items.on('click', function () {
- if ($(this).data('dragging')) {
- return;
- }
- if ($(this).attr('id')) {
- var id = $(this).attr('id').trim();
- var item = self._getItemById(id);
- if (!item) {
- item = self._getItemByConnId(id);
- }
- }
- self.trigger('selected', item);
- }); // group accordion
- var $groupTitles = this.$el.find('a.group-header');
- $groupTitles.on('primaryaction', function (e) {
- if ($(this).is('.active')) {
- $(this).removeClass('active');
- $(this).find('.wft').removeClass('wfa_up').addClass('wfa_down');
- $(this).next().slideUp(300);
- } else {
- $(this).addClass('active');
- $(this).find('.wft').removeClass('wfa_down').addClass('wfa_up');
- $(this).next().slideDown(300);
- }
- e.preventDefault();
- }); // context menu
- var $contextMenus = this.$el.find('td .ellipsesButton');
- $contextMenus.on('primaryaction', function (e) {
- var id = $(this).closest('tr.list-item').attr('id').trim();
- var item = self._getItemById(id);
- var position = {};
- if (e.pageX === undefined || e.gesture === undefined || e.gesture.center === undefined || e.gesture.center.pageX === undefined) {
- position = $(e.target).offset();
- } else {
- position.left = e.pageX || e.gesture.center.pageX;
- position.top = e.pageY || e.gesture.center.pageY;
- }
- self.trigger('showContextMenu', {
- data: item,
- position: {
- "pageX": position.left,
- "pageY": position.top
- }
- });
- e.stopPropagation();
- return false;
- });
- },
- selectById: function selectById(id) {
- var item = this._getItemById(id) || this._getItemByConnId(id);
- this.trigger('selected', item);
- },
- selectByIndex: function selectByIndex(index) {
- var item = this.items[index];
- this.trigger('selected', item);
- },
- removeSelectedRowById: function removeSelectedRowById(id) {
- var item = _.find(this.$el.find('tr.list-item'), function (item) {
- if (item.id === id) {
- return item;
- }
- });
- try {
- item.removeNode(true);
- } catch (err) {
- item.remove();
- }
- if ($('#workPane').is(":visible")) {
- $('#workPane').addClass('hide');
- }
- },
- insertCopyRowById: function insertCopyRowById(copyRow, id) {
- var copySource = _.find(this.$el.find('tr.list-item'), function (item) {
- if (item.id === id) {
- return item;
- }
- });
- var targetSource = _.clone(copySource);
- targetSource.id = id;
- targetSource.insertAfter(copySource);
- }
- });
- return GroupListView;
- });
|