123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- "use strict";
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: admin
- * Copyright IBM Corp. 2016, 2021
- * US Government Users Restricted Rights
- * Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['jquery', 'doT', 'q', 'bi/glass/app/util/View', 'underscore', 'bi/admin/nls/StringResource', 'bi/admin/datasource/App', 'bi/commons/ui/content/views/GroupListView', 'bi/commons/ui/content/views/SearchView', 'bi/commons/ui/properties/PropertyUIControl', 'text!bi/admin/datasource/templates/TableListViewTemplate.html'], function ($, dot, Q, View, _, StringResource, App, GroupListView, SearchView, PropertyUIControl, TableListViewTemplate) {
- //NOSONAR: needed for amd
- 'use strict'; //NOSONAR: meant to be strict
- var TableListView = View.extend({
- items: null,
- groupListView: null,
- _state: null,
- updateState: function updateState(key, value) {
- var obj = {};
- if ($.type(key) !== 'string') {
- obj = key;
- } else {
- obj[key] = value;
- }
- $.extend(this._state, obj);
- this.parentView.updateState(this._state);
- },
- /**
- * @constructor
- */
- init: function init(options) {
- TableListView.inherited('init', this, arguments);
- _.extend(this, options);
- this._state = {};
- $.extend(this._state, this.prop);
- this.$el.html(dot.template(TableListViewTemplate));
- this.groupListView = new GroupListView({
- 'el': this.$el.find('.schemaTablesSection'),
- 'selectable': true,
- 'groupSelection': true,
- 'navigable': true,
- 'showFilter': true,
- 'glassContext': this.glassContext,
- 'searchView': new SearchView({})
- });
- this.groupListView.on('checkbox:primaryaction', this._itemOnCheck.bind(this));
- this.includeExcludeRadioButtons = [{
- 'type': 'HorizontalRadioButtonGroup',
- 'name': 'includeExcludeRadioButton',
- 'value': this._getInitialIncludeExcludeSelection(),
- //Need to check what we get back and set this properly
- 'items': [{
- 'label': StringResource.get('include'),
- 'value': 'include'
- }, {
- 'label': StringResource.get('exclude'),
- 'value': 'exclude'
- }],
- 'onChange': this._onChangeIncludeExclude.bind(this),
- 'ariaLabel': StringResource.get('includeExcludeTables')
- }];
- },
- _onChangeIncludeExclude: function _onChangeIncludeExclude(group, value) {
- this.updateState('includeOrExcludeSelection', value);
- this._updateLoadButtonState();
- },
- _updateLoadButtonState: function _updateLoadButtonState() {
- if (this._state.includeOrExcludeSelection === 'exclude') {
- this.updateState('loadBtnDisabled', this._state.selectedTables.length === this.items.length);
- } else if (this._state.includeOrExcludeSelection === 'include') {
- this.updateState('loadBtnDisabled', this._state.selectedTables.length === 0);
- }
- },
- _getInitialIncludeExcludeSelection: function _getInitialIncludeExcludeSelection() {
- if (this._state.includeOrExcludeSelection === 'exclude') {
- return 'exclude';
- }
- return 'include';
- },
- //for the best performance, do not change the loop to _.each
- _itemOnCheck: function _itemOnCheck(items) {
- for (var i = 0; i < items.length; i++) {
- this._changeTables(items[i].id, items[i].checked);
- }
- this.updateState('selectedTables', this._state.selectedTables);
- this._updateLoadButtonState();
- },
- //for the best performance, do not change to _.different or union
- _changeTables: function _changeTables(id, isChecked) {
- if (isChecked) {
- this._state.selectedTables.push(id);
- } else {
- this._state.selectedTables.splice(this._state.selectedTables.indexOf(id), 1);
- }
- },
- _setHeights: function _setHeights() {
- var windowHeight = $(window).height();
- var toggleElement = this.$el.find(".listGroupSelection");
- var tableCont = this.$el.find(".listbody");
- var headerElementsHeight = tableCont.offset().top;
- var footerElHeight = $(this.$el.parents(".flyoutPane")[0]).find("footer").height();
- var updatedListHeight = windowHeight - toggleElement.height() - headerElementsHeight - footerElHeight - 80;
- tableCont.height(updatedListHeight);
- },
- _getCheckedValue: function _getCheckedValue(table) {
- return this._state.selectedTables.indexOf(table) != -1;
- },
- /**
- Main entry point - will render the table list view.
- **/
- render: function render() {
- var deferred = Q.defer();
- this._oPropertyUIControl = new PropertyUIControl({
- 'glassContext': this.glassContext,
- 'el': this.$el.find('.includeExcludeRadioButtons'),
- 'items': this.includeExcludeRadioButtons
- });
- this._oPropertyUIControl.render().then(function () {
- var signonInfo;
- if (this.parentView && this.parentView.signonAndConnection) {
- signonInfo = this.parentView.signonAndConnection;
- }
- App.getTables(this.schemaId, signonInfo).done(function (tables) {
- this.items = _.map(tables.data, function (table) {
- return {
- 'id': table,
- 'value': table,
- 'label': table,
- 'toolTip': table,
- 'checked': this._getCheckedValue(table),
- 'svgHref': '#modeller-querySubject'
- };
- }.bind(this));
- this.groupListView.setItems(this.items);
- this.groupListView.render().done(function () {
- this._setHeights();
- deferred.resolve();
- }.bind(this));
- }.bind(this));
- }.bind(this));
- return deferred.promise;
- }
- });
- return TableListView;
- });
|