/* *+------------------------------------------------------------------------+ *| Licensed Materials - Property of IBM *| IBM Cognos Products: Content Explorer *| (C) Copyright IBM Corp. 2016, 2018 *| *| US Government Users Restricted Rights - Use, duplication or disclosure *| restricted by GSA ADP Schedule Contract with IBM Corp. *+------------------------------------------------------------------------+ */ define('bi/content_apps/CapabilitiesView',[ 'jquery', 'underscore', 'bi/glass/app/ContentView', 'bi/content_apps/nls/StringResource', 'bacontentnav/lib/@waca/core-client/js/core-client/ui/properties/PropertyUIControl', 'bacontentnav/utils/GlassContextHelper' ], function($, _, ContentView, StringResource, PropertyUIControl, GlassContextHelper) { 'use strict'; var CapabilitiesView = ContentView.extend({ init: function(options) { CapabilitiesView.inherited('init', this, arguments); _.extend(this, options); }, render: function() { this._containerElement = $('
', { 'class': 'propertyUIControl capabilitiesView' }); this.$el.append(this._containerElement); return this._getCapabilityInformation().then(function(allCapabilities) { var parents = []; var children = []; this._translateUserCapabilityNames(allCapabilities, parents, children); var hierarchicalList = this._createHierarchicalList(parents, children); this._oPropertyUIControl = this._getPropertyUIControl({ 'el': this.$el, 'glassContext': this.glassContext, 'items': [{ 'type': 'Banner', 'name': 'detailsBanner', 'value': StringResource.get('preferencesMyCapabilities'), 'centerLabel': true, 'hintText': StringResource.get('preferencesCapabilitiesHintText'), 'backButton': true, 'editable': false, 'readOnly': true, 'onClose': function() { this.slideout.hide(); }.bind(this) }, { 'type': 'HierarchicalList', 'name': 'capabilities', 'data': _.sortBy(hierarchicalList, 'defaultName') }] }); return this._oPropertyUIControl.render(); }.bind(this), function() { this.slideout.hide(); return Promise.reject(); }.bind(this)); }, _getPropertyUIControl: function(options) { return new PropertyUIControl(options); }, _getCapabilityInformation: function() { return this.glassContext.services.ajax.ajax({ dataType: 'json', type: 'GET', url: 'v1/capabilities' }).then(function(response) { if (response.data) { return response.data; } else { return Promise.reject(); } }.bind(this), this._handleError.bind(this)); }, /** * Creates a hierarchical list - an array of parentobjects with array of children objects * @private * */ _createHierarchicalList: function(parents, children) { var listData = []; for (var j = 0; j < parents.length; j += 1) { var childCapabilities = []; for (var k = 0; k < children.length; k += 1) { if (children[k].parent[0].userCapability === parents[j].userCapability) { childCapabilities.push({ defaultName: children[k].defaultName }); } } listData.push({ 'defaultName': parents[j].defaultName, 'children': _.sortBy(childCapabilities, 'defaultName') }); } return listData; }, /** * Combines the userCapabilities with the list of all capabilities so * that the translated user friendly capability name is available * @private * */ _translateUserCapabilityNames: function(allCapabilities, parents, children) { var userCapabilities = this.glassContext.getCoreSvc('.UserProfile').capabilities; for (var i = 0; i < allCapabilities.length; i += 1) { var index = _.indexOf(userCapabilities, allCapabilities[i].userCapability); if (index !== -1) { // parent capability if (this._isParentCapability(allCapabilities[i])) { parents.push(allCapabilities[i]); } else { // child capability children.push(allCapabilities[i]); } } } }, _isParentCapability: function (capability) { if (!capability || !capability.parent) { return false; } var parent = capability.parent[0]; if (parent && parent.userCapability) { return false; } return true; }, /** * Handles an Ajax error * @private */ _handleError: function(dfd, jqXHR) { GlassContextHelper.showAjaxServiceErrorMessage(this.glassContext, jqXHR); return Promise.reject(); } }); return CapabilitiesView; }); /* *+------------------------------------------------------------------------+ *| Licensed Materials - Property of IBM *| IBM Cognos Products: Content Explorer *| (C) Copyright IBM Corp. 2015, 2018 *| *| US Government Users Restricted Rights - Use, duplication or disclosure *| restricted by GSA ADP Schedule Contract with IBM Corp. *+------------------------------------------------------------------------+ */ define('bi/content_apps/AccountPickerSlideoutView',[ 'bacontentnav/common/ContentListPageView', 'bi/content_apps/nls/StringResource', 'bacontentnav/utils/ContentServiceUrls', 'bacontentnav/utils/ContentStoreObject', 'bacontentnav/lib/@waca/core-client/js/core-client/ui/properties/PropertyUIControl', 'bacontentnav/common/ui/BreadcrumbDropDown', 'bacontentnav/utils/GlassContextHelper', 'bi/commons/ui/KeyCodes', 'underscore' ], function(ContentListPageView, StringResource, ContentServiceUrls, ContentStoreObject, PropertyUIControl, DropDownMenu, GlassContextHelper, KeyCodes, _) { 'use strict'; var AccountPickerSlideoutView = ContentListPageView.extend({ stateId: 'AccountPickerSlideoutView', disabledActions: ['DeleteAction', 'ManageContentAction'], init: function(options) { this.namespaceMap = {}; this.searchMode = 'find'; this.events = {}; this.events['keydown .l_findUser2'] = '_handleSearchMenuButtonDown'; AccountPickerSlideoutView.inherited('init', this, arguments); _.extend(this, options); }, getRootAncestor: function() { return ContentStoreObject.getRootNamespacesAncestors(); }, _createDropDown: function($row) { var menuItems = [{ 'label': StringResource.get('policiesFindMode'), 'icon': 'common-grant_perm', 'onSelect': this._onMenuSelect.bind(this, 'find') }, { 'label': StringResource.get('policiesTypeInMode'), 'icon': '', 'onSelect': this._onMenuSelect.bind(this, 'typein') }]; this.ddMenu = this._getDropDownMenu({ dropDownMenuSpec: { 'title': StringResource.get('optionsMenuLabel'), 'id': 'find', 'label': 'find', 'icon': '', 'items': menuItems, 'actionElement': $row, 'ddMenuPlacement': 'bottom' } }); this.ddMenu.render().then(function(el) { $row.appendChild(el); }); }, _getDropDownMenu: function(options) { return new DropDownMenu(options); }, _onMenuSelect: function(mode) { // check mode and switch if required this.searchMode = mode; if (mode === 'find') { // reset search results list when returning from "Type in" mode this.getListControl().updateDatatable(this._getDefaultRequestURL()); this.ancestors = []; this.initializeAncestors(); this.contentBar.getAddedItem('breadcrumbs').then(function(breadcrumbsView) { breadcrumbsView.updateBreadcrumb(this.ancestors); }.bind(this)); // Show a check icon next to the first drop down item this.ddMenu.items[0].icon = 'common-grant_perm'; this.ddMenu.items[1].icon = ''; this._oPropertyUIControl.getProperty('TypeInHintText').setVisibility('hidden'); } else { // Show a check icon next to the second drop down item this.ddMenu.items[0].icon = ''; this.ddMenu.items[1].icon = 'common-grant_perm'; this._oPropertyUIControl.getProperty('TypeInHintText').setVisibility('visible'); } this.setFocus(); }, _getSearchData: function() { return { currentNamespaceId: this.ancestors[this.ancestors.length - 1].id, currentNamespaceType: this.ancestors[this.ancestors.length - 1].type, searchValue: this._oPropertyUIControl.getProperty('searchValue').getValue() }; }, _doSearch: function() { var data = this._getSearchData(); if (!data.searchValue || data.searchValue === '') { return; } //*************************************** // Search (Find mode) //*************************************** if (this.searchMode === 'find' && data.currentNamespaceType !== 'namespace' && data.currentNamespaceType !== 'namespaceFolder') { GlassContextHelper.displayToast(this.glassContext, StringResource.get('policyToastMessageNamespace'), { 'type': 'warning' }); return; } var dataTable = this.getListControl().getDatatable(); var tableApi = dataTable.api(); var requestURLs = []; if (this.searchMode === 'find') { tableApi.clear(); this.getListControl().setShowWorking(true); tableApi.draw(); requestURLs = [ 'v1/users?pid=' + data.currentNamespaceId + '&&search=keyword|' + encodeURIComponent(data.searchValue), 'v1/groups?pid=' + data.currentNamespaceId + '&&search=keyword|' + encodeURIComponent(data.searchValue), 'v1/roles?pid=' + data.currentNamespaceId + '&&search=keyword|' + encodeURIComponent(data.searchValue) ]; this._sendSearchRequests(requestURLs); } else if (this.searchMode === 'typein') { //*************************************** // Search (Type-in) mode) //*************************************** if (data.searchValue.indexOf('/') === -1) { GlassContextHelper.displayToast(this.glassContext, StringResource.get('policyToastMessageSyntax'), { 'type': 'warning' }); return; } // trim off trailing semi-colon data.searchValue = data.searchValue.replace(/;$/, ''); tableApi.clear(); this.getListControl().setShowWorking(true); tableApi.draw(); var searchItems = data.searchValue.split(';'); // parse the search expressiom searchItems.forEach(function(si) { var search = si.split('/'); var namespace = search[0].toLowerCase(); var namespaceId = this.namespaceMap[namespace]; // check for valid namespaceId if (namespaceId && search[1] !== undefined) { var user = search[1]; requestURLs.push('v1/users?pid=' + namespaceId + '&searchFilter=' + encodeURIComponent('defaultName="' + user + '"|userName="' + user + '"')); requestURLs.push('v1/groups?pid=' + namespaceId + '&searchFilter=' + encodeURIComponent('defaultName="' + user + '"|userName="' + user + '"')); requestURLs.push('v1/roles?pid=' + namespaceId + '&searchFilter=' + encodeURIComponent('defaultName="' + user + '"|userName="' + user + '"')); } }.bind(this)); this._sendSearchRequests(requestURLs); } this.setFocus(); return; }, _sendSearchRequests: function(requestURLs) { var aPromises = []; var bHasResults = false; requestURLs.forEach(function(requestURL) { aPromises.push(this.glassContext.getCoreSvc('.Ajax').ajax({ headers: { Accept: 'application/json', 'Content-Type': 'application/json' }, type: 'GET', url: requestURL }) .then(function(oResponse) { if (oResponse.data && oResponse.data.data && oResponse.data.data.length > 0) { bHasResults = true; this.getListControl().addRowData(oResponse.data.data); } }.bind(this)) .catch(function(err) { if (err.message) { //TODO: revisit GlassContextHelper.displayToast(this.glassContext, err.message, { 'type': 'error' }); } }.bind(this))); }.bind(this)); return Promise.all(aPromises) .then(function() { if (!bHasResults) { this.getListControl().showEmptyTableMessage(); } }.bind(this)); }, renderContent: function() { // The content bars get rendered first, detach them here so we can re-attach them to the DOM when just above the list control this.$contentBars = this.$el.children().detach(); this._oPropertyUIControl = new PropertyUIControl({ 'el': this.$el, 'glassContext': this.glassContext, 'closeCallback': this._onCancelClick.bind(this), 'items': [{ 'name': 'AccountPicker', 'type': 'Banner', 'value': StringResource.get('selectAccountGroupOrRole'), 'backButton': this.slideout.overlay ? true : false, 'centerLabel': this.slideout.overlay ? true : false }, { 'type': 'HintText', 'name': 'TypeInHintText', 'visibility': 'hidden', 'label': StringResource.get('typeInHintText') }, { 'name': 'findUser', 'type': 'SingleLineLinks', 'items': [{ 'align': 'left', 'items': [{ 'styles': 'width: 80%', 'type': 'Input', 'inputClass': 'policyFindUser', 'handleReturnKey': true, 'enterKeyCallback': this._doSearch.bind(this), 'value': '', 'placeHolderText': StringResource.get('policiesFindAUserHint'), 'ariaLabel': StringResource.get('policiesFindAUserHint'), 'ellipses': false, 'name': 'searchValue', 'editable': true, 'highlightTextOnFocus': true }, { 'type': 'icon', 'svgIcon': 'common-search', 'clickCallback': this._doSearch.bind(this), 'value': StringResource.get('policiesFindAUserHint'), 'iconTooltip': StringResource.get('policiesFindAUserHint') }, { 'type': 'icon', 'svgIcon': 'common-titan-arrow-down', 'value': StringResource.get('policiesFindModeMenuTip'), 'iconTooltip': StringResource.get('policiesFindModeMenuTip'), 'role': 'button' }] }] }, { 'module': 'bi/content_apps/ui/RenderCallback', 'renderCallback': this._renderListControl.bind(this) }, { 'type': 'Footer', 'items': [{ 'type': 'Button', 'label': StringResource.get('policesAddMemberButtonLabel'), 'onSelect': this._onAddClick.bind(this), 'primary': true }] }] }); return this._oPropertyUIControl.render().then(function() { this._renderPostListControls(); return this; }.bind(this)); }, setFocus: function() { var searchInput = this.$el.find('input.policyFindUser'); if (searchInput) { searchInput.focus(); } }, _closeCallback: function() { this.close(); }, _renderListControl: function(container) { var $wrapper = $('
'); $(container).append($wrapper); $wrapper.append(this.$contentBars); return this.renderContentList({ 'el': $wrapper, 'columns': this._getColumnSpecification(), '$container': this.$el, 'url': (this.url || this._getDefaultRequestURL()), 'dataManipulationCallback': function(response) { if (response && response.data) { response.data = _.filter(response.data, function(namespace){ return _.contains(namespace.permissions, 'traverse'); }); } } }) .then(function() { this.getListControl().setIsAccountPickerSlideout(); this.setFocus(); }.bind(this)); }, _onCancelClick: function() { this.slideout.hide(); }, _onAddClick: function() { var oSelected = this.getListControl().getSelectedObjects(); if (typeof (this.addCallback) === 'function') { this.addCallback(oSelected); } this.setFocus(); }, _renderPostListControls: function() { // add dropdown menu to search input var $searchTypeButton = this.$el.find('.l_findUser2'); $searchTypeButton.attr('tabindex', '0'); this._createDropDown($searchTypeButton); // create the MAP for valid namespaces. Used by the type-in search var dataTable = this.getListControl().getDatatable(); var oData = dataTable.fnGetData(); oData.forEach(function(namespaceItem) { if (namespaceItem.type === 'namespace') { this.namespaceMap[namespaceItem.defaultName.toLowerCase()] = namespaceItem.id; } }.bind(this)); }, _getDefaultRequestURL: function() { return ContentServiceUrls.getBaseNamespaceURL(); }, _getDefaultSelfURL: function() { return ContentServiceUrls.getBaseNamespaceURL(); }, _getModuleName: function() { return 'bi/content_apps/AccountPickerSlideoutView'; }, contentbarItems: function() { var filterMenuNamePrefix = 'ACCOUNTPICKER_FILTER_'; var filterString = window.localStorage.getItem('filterString_' + this.stateId); return [{ 'name': 'nameLabel', 'position': 'leading', 'style': 'nameLabel', 'module': 'bacontentnav/common/ui/contentbar_components/HiddenLabel', 'label': StringResource.get('policiesTableLable') }, { 'name': filterMenuNamePrefix + 'typeMenu', 'label': StringResource.get('type'), 'labelOnly': true, 'hcLabel': false, 'position': 'trailing', 'supportCustomCollapse': true, 'showTitle': false, 'updateLabel': true, 'icon': 'common-filter', 'bSVG': true, 'module': 'bacontentnav/common/ui/contentbar_components/ToggleMenuBar', 'items': [{ 'name': filterMenuNamePrefix + 'allContent', 'icon': 'wft_checkmark', 'label': StringResource.get('allGenericItems'), 'checked': (filterString === ''), 'action': function() { this._filter(''); }.bind(this) }, { 'name': filterMenuNamePrefix + 'accounts', 'icon': 'wft_checkmark', 'label': StringResource.get('policyFilterAccounts'), 'checked': (filterString === 'account'), 'action': function() { this._filter('account'); }.bind(this) }, { 'name': filterMenuNamePrefix + 'groups', 'icon': 'wft_checkmark', 'label': StringResource.get('policyFilterGroups'), 'checked': (filterString === 'group'), 'action': function() { this._filter('group'); }.bind(this) }, { 'name': filterMenuNamePrefix + 'roles', 'icon': 'wft_checkmark', 'label': StringResource.get('policyFilterRoles'), 'checked': (filterString === 'role'), 'action': function() { this._filter('role'); }.bind(this) }] }]; }, getListControlOptions: function() { return { 'ajaxProp': 'data', 'emptyFolderString': StringResource.get('emptyPolicyList'), 'showEmptyNewFolderButton': false, 'rightClickContextMenu': false }; }, getDefaultSort: function() { return [1, 'asc']; }, _handleSearchMenuButtonDown: function(evt) { if (evt.keyCode === KeyCodes.SPACE || evt.keyCode === KeyCodes.ENTER || evt.keyCode === KeyCodes.DOWN_ARROW) { if ($(evt.currentTarget).click) { $(evt.currentTarget).click(); evt.stopPropagation(); return false; } } return true; }, _getColumnSpecification: function() { return [{ 'type': 'Icon' }, { 'type': 'Name', 'navigateOnly': true }, { 'type': 'Time', 'propertyName': 'modificationTime' }]; }, _adjustWidth: function() { this.$el.addClass('pageview-small'); }, _navigate: function(oData) { void(oData); AccountPickerSlideoutView.inherited('navigate', this, arguments); this.setFocus(); } }); return AccountPickerSlideoutView; }); /* *+------------------------------------------------------------------------+ *| Licensed Materials - Property of IBM *| IBM Cognos Products: content-apps *| (C) Copyright IBM Corp. 2016, 2018 *| *| US Government Users Restricted Rights - Use, duplication or disclosure *| restricted by GSA ADP Schedule Contract with IBM Corp. *+------------------------------------------------------------------------+ */ define('bi/content_apps/CredentialsView',[ 'bacontentnav/common/ContentListPageView', 'bi/content_apps/common/ui/permissions/Policy', 'bi/content_apps/nls/StringResource', 'bacontentnav/utils/ContentStoreObject', 'bi/commons/ui/Slideout', 'bacontentnav/utils/GlassContextHelper', 'bacontentnav/lib/@waca/core-client/js/core-client/ui/properties/PropertyUIControl', 'bi/content_apps/AccountPickerSlideoutView', 'underscore' ], function(ContentListPageView, Policy, StringResource, ContentStoreObject, Slideout, GlassContextHelper, PropertyUIControl, AccountPickerSlideoutView, _) { 'use strict'; var CredentialsView = ContentListPageView.extend({ init: function(options) { CredentialsView.inherited('init', this, arguments); _.extend(this, options); //contentListFacets is used by _filter logic of its base class (ie. ContentListPageView), need to populated by subclasses; //it consists of key/value pairs, values are used for ListControl filtering. this.contentListFacets = { 'accounts': 'account', 'groups': 'group', 'roles': 'role' }; }, renderContent: function() { this.$el.addClass('policies'); // The content bars get rendered first, detach them here so we can re-attach them to the DOM when just above the list control this.$contentBars = this.$el.children().detach(); var aControls = [{ 'module': 'bi/content_apps/ui/RenderCallback', 'renderCallback': this._renderListControl.bind(this) }, { 'type': 'Banner', 'name': 'credentialsBanner', 'value': StringResource.get('preferencesMyCredentials'), 'centerLabel': true, 'hintText': StringResource.get('preferencesCredentialsHintText'), 'backButton': true, 'editable': false, 'readOnly': true, 'onClose': this._onClose.bind(this) }, { 'type': 'Footer', 'items': [{ 'type': 'Button', 'label': StringResource.get('applyLabel'), 'onSelect': this._onApplyClick.bind(this), 'primary': true }, { 'type': 'Button', 'label': StringResource.get('cancel'), 'onSelect': this._onCancelClick.bind(this), 'primary': false }] }]; this._oPropertyUIControl = this._getPropertyUIControl({ 'el': this.$el, 'glassContext': this.glassContext, 'items': aControls }); return this._oPropertyUIControl.render(); }, _getPropertyUIControl: function(options) { return new PropertyUIControl(options); }, _renderListControl: function(container) { var $wrapper = $('
'); $(container).append($wrapper); $wrapper.append(this.$contentBars); return this.renderContentList({ 'el': $wrapper, 'columns': this._getColumnSpecification(), '$container': this.$el, 'getJSONDataCallback': this._getCredentialData.bind(this) }) .then(function() { this.getListControl().setIsAccountPickerSlideout(); }.bind(this)); }, // credential data _getCredentialData: function() { return this._getUserCredentials() .then(function() { return this._getPolicies(this.credentialId) .then(function() { return { data: this.policyArray.data[0].policies }; }.bind(this)); }.bind(this)) .catch(function(err) { this.slideout.hide(); return Promise.reject(err); }.bind(this)); }, // query to retrieve credential id _getUserCredentials: function() { return this._sendRequest({ dataType: 'json', type: 'GET', url: 'v1/users/~/credentials' }, function(response) { if (response.data && response.data.id) { this.credentialId = response.data.id; } else { return Promise.reject(new Error()); } }.bind(this)); }, // query to retrieve policies of current credential _getPolicies: function(id) { return this._sendRequest({ dataType: 'json', type: 'GET', url: 'v1/objects/' + id + '?fields=policies{defaultName,id,searchPath}' }, function(response) { if (response.data && response.data.data[0].policies) { this.policyArray = response.data; return this.policyArray; } else { return Promise.reject(new Error()); } }.bind(this)); }, _onApplyClick: function() { var data = {}; data.policies = this.policyArray.data[0].policies; data.type = 'credential'; var jsonData = JSON.stringify(data); var url = 'v1/objects/' + this.credentialId; var options = { 'headers': { 'Accept': 'application/json', 'Content-Type': 'application/json' }, 'type': 'PUT', 'url': url, 'data': jsonData }; return this._sendRequest(options, function() {}); }, _onCancelClick: function() { this.slideout.hide(); }, _sendRequest: function(options, successHandler) { return this.glassContext.getCoreSvc('.Ajax').ajax(options) .then(successHandler.bind(this)) .catch(function(err) { if (err.message) { this.glassContext.appController.showErrorMessage(err.message, 'Error'); } return Promise.reject(err); }.bind(this)); }, _getDefaultRequestURL: function() { return this.itemURL; }, _getModuleName: function() { return 'bi/content_apps/CredentialsView'; }, getDefaultSort: function() { return [1, 'asc']; }, setFocus: function() { var $tabs = this.$el.find(':tabbable'); if ($tabs.length > 0) { $tabs.get(0).focus(); } }, _isDuplicate: function(oData, matchId) { var isDuplicate = false; oData.forEach(function(arrayElem) { var id = arrayElem.securityObject.id; if (id === matchId) { isDuplicate = true; return false; } }); return isDuplicate; }, removeSelection: function() { setTimeout(function() { var selectedPolicies = this.getListControl().getSelectedObjects(); var currentPolicies = this.policyArray.data[0].policies; var updatedPolicies = _.reject(currentPolicies, function(policy) { return _.find(selectedPolicies, function(selPol) { return policy.securityObject.defaultName === selPol.securityObject.defaultName; }); }); this.policyArray.data[0].policies = updatedPolicies; var numberDeleted = this.getListControl().getSelectedRows().length; if (numberDeleted > 0) { var sToastMessage = (numberDeleted === 1)? StringResource.get('toastItemsWereDeletedSingular', { 'noOfItems': numberDeleted }) : StringResource.get('toastItemsWereDeleted', { 'noOfItems': numberDeleted }); this.getListControl().removeSelectedRows(); this.glassContext.appController.showToast(sToastMessage); } this.setFocus(); }.bind(this), 100); }, addSelection: function(selectedItems) { var itemCount = 0; var numberAdded = 0; var dataTable = this.getListControl().getDatatable(); var tableApi = dataTable.api(); var oData = dataTable.fnGetData(); selectedItems.forEach(function(item) { var itemId = item.id; var itemType = item.type; var itemName = item.defaultName; var itemPath = item.searchPath; var foundDuplicate = this._isDuplicate(oData, itemId); itemCount = itemCount + 1; if (!foundDuplicate) { numberAdded = numberAdded + 1; var policy = new Policy(itemName, itemId, itemType, itemPath); this.policyArray.data[0].policies.push(policy); tableApi.row.add(policy).draw(true); } }.bind(this)); var sToastMessage; if (numberAdded === 1) { sToastMessage = StringResource.get('toastItemsWereAddedSingular', { 'noOfItems': numberAdded }); } else if (numberAdded === 0 && itemCount === 1) { sToastMessage = StringResource.get('toastItemsAlreadyAddedSingular'); } else if (numberAdded === 0 && itemCount > 1) { sToastMessage = StringResource.get('toastItemsAlreadyAdded'); } else { sToastMessage = StringResource.get('toastItemsWereAdded', { 'noOfItems': numberAdded }); } this.glassContext.appController.showToast(sToastMessage); }, _onClose: function() { this.slideout.hide(); }, _openAddMembersSlideout: function(oData) { var overlaySlideoutEl = $('
'); this.slideout.$el.append(overlaySlideoutEl); var overlaySlideout = this._getSlideout({ 'glassContext': this.glassContext, 'position': this.position || 'right', 'el': overlaySlideoutEl, 'overlay': true, 'width': this.slideout.$el.width(), 'enableTabLooping': true, 'content': { 'module': AccountPickerSlideoutView, 'showBreadcrumbs': true, 'navigateOnRowSelect': true, 'addCallback': function(selectedItems) { this.addSelection(selectedItems); }.bind(this), 'objectInformation': oData, 'glassContext': this.glassContext } }); overlaySlideout.render() .then(function() { overlaySlideout.show(); }); }, _getSlideout: function(options) { return new Slideout(options); }, contentbarItems: function() { var filterString = window.localStorage.getItem('filterString_' + this.stateId); return [{ 'name': 'nameLabel', 'position': 'leading', 'label': StringResource.get('preferencesCredentialsLabel'), 'style': 'nameLabel', 'module': 'bacontentnav/common/ui/contentbar_components/HiddenLabel' }, { 'name': 'typeMenu', 'label': StringResource.get('type'), 'labelOnly': true, 'hcLabel': false, 'position': 'trailing', 'supportCustomCollapse': true, 'showTitle': false, 'updateLabel': true, 'icon': 'common-filter', 'bSVG': true, 'module': 'bacontentnav/common/ui/contentbar_components/ToggleMenuBar', 'items': [{ 'name': 'allContent', 'icon': 'wft_checkmark', 'label': StringResource.get('allGenericItems'), 'checked': (filterString === 'allContent'), 'action': function() { this._filter('allContent'); }.bind(this) }, { 'name': 'accounts', 'icon': 'wft_checkmark', 'label': StringResource.get('policyFilterAccounts'), 'checked': (filterString === 'accounts'), 'action': function() { this._filter('accounts'); }.bind(this) }, { 'name': 'groups', 'icon': 'wft_checkmark', 'label': StringResource.get('policyFilterGroups'), 'checked': (filterString === 'groups'), 'action': function() { this._filter('groups'); }.bind(this) }, { 'name': 'roles', 'icon': 'wft_checkmark', 'label': StringResource.get('policyFilterRoles'), 'checked': (filterString === 'roles'), 'action': function() { this._filter('roles'); }.bind(this) }] }, { 'name': 'separator', 'type': 'Separator', 'position': 'trailing' }, { 'name': 'add', 'position': 'trailing', 'displayLabel': false, 'label': StringResource.get('policesAddMemberButtonLabel'), 'module': 'bacontentnav/common/ui/contentbar_components/Button', 'className': 'addNewFolder', 'icon': 'common-add', '_handleClick': function() { this._openAddMembersSlideout(); }.bind(this) }]; }, getListControlOptions: function() { return { 'ajaxProp': 'data', 'emptyFolderString': StringResource.get('emptyPolicyList'), 'showEmptyNewFolderButton': true, 'multiSelect': true, 'rightClickContextMenu': false }; }, _getColumnSpecification: function() { return [{ 'type': 'Icon', 'getDataFn': function(oRowData) { if (oRowData.securityObject[ContentStoreObject.TYPE] === 'nil') { return StringResource.get('unknown'); } else { return oRowData.securityObject[ContentStoreObject.TYPE]; } } }, { 'type': 'Name', 'scope': 'row', 'getDataFn': function(oRowData) { if (oRowData.securityObject[ContentStoreObject.DEFAULT_NAME] === undefined) { return StringResource.get('unavailable'); } else { return _.escape(oRowData.securityObject[ContentStoreObject.DEFAULT_NAME]); } } }, { 'type': 'ClickableIcon', 'name': StringResource.get('policesRemove'), 'icon': 'common-remove-delete', 'clickCallback': this.removeSelection.bind(this) }]; }, _adjustWidth: function() { this.$el.addClass('pageview-small'); }, _multiselectbarItems: function() { return Promise.resolve([{ 'name': 'removeButton', 'position': 'leading', 'icon': 'common-remove-delete', 'module': 'bacontentnav/common/ui/contentbar_components/Button', 'className': 'policyMulSel', 'action': this.removeSelection.bind(this) }, { 'name': 'selectedLabel', 'position': 'leading', 'module': '../../lib/gemini/app/ui/toolbar_components/Label', 'style': 'selectedLabel' }, { 'position': 'leading', 'type': 'Separator' }, { 'name': 'cancelButton', 'position': 'trailing', 'label': StringResource.get('cancel'), 'text': StringResource.get('cancel'), 'labelOnly': true, 'module': 'bacontentnav/common/ui/contentbar_components/Button', 'className': 'cancelButton', '_handleClick': function() { this.getListControl()._clearRows(); this.multiselectBar.hide(); this.contentBar.show(); }.bind(this) }]); }, getFilterSpec: function() { return [{ 'name': 'allContent', 'label': StringResource.get('allContent'), 'value': 'allContent' }, { 'name': 'accounts', 'label': StringResource.get('policyFilterAccounts'), 'value': 'accounts' }, { 'name': 'groups', 'label': StringResource.get('policyFilterGroups'), 'value': 'groups' }, { 'name': 'roles', 'label': StringResource.get('policyFilterRoles'), 'value': 'roles' }]; } }); return CredentialsView; }); /* *+------------------------------------------------------------------------+ *| Licensed Materials - Property of IBM *| IBM Cognos Products: Content Explorer *| (C) Copyright IBM Corp. 2016, 2018 *| *| US Government Users Restricted Rights - Use, duplication or disclosure *| restricted by GSA ADP Schedule Contract with IBM Corp. *+------------------------------------------------------------------------+ */ define('bi/content_apps/DataSourceCredentialsView',[ 'q', 'jquery', 'underscore', 'bacontentnav/common/ContentListPageView', 'bi/content_apps/nls/StringResource', 'bacontentnav/utils/GlassContextHelper', 'bacontentnav/lib/@waca/core-client/js/core-client/ui/properties/PropertyUIControl' ], function(Q, $, _, ContentListPageView, StringResource, GlassContextHelper, PropertyUIControl) { 'use strict'; var DataSourceCredentialsView = ContentListPageView.extend({ init: function(options) { this.itemURL = options.itemURL; DataSourceCredentialsView.inherited('init', this, arguments); _.extend(this, options); }, renderContent: function() { // The content bars get rendered first, detach them here so we can re-attach them to the DOM when just above the list control this.$contentBars = this.$el.children().detach(); var aControls = []; aControls.push({ 'module': 'bi/content_apps/ui/RenderCallback', 'renderCallback': this._renderListControl.bind(this) }, { 'type': 'Banner', 'name': 'credentialsBanner', 'value': StringResource.get('preferencesDatasourceTitle'), 'centerLabel': true, 'hintText': StringResource.get('preferencesDataSourceCredentialsHintText'), 'backButton': true, 'editable': false, 'readOnly': true, 'onClose': this._onClose.bind(this) }); this._oPropertyUIControl = new PropertyUIControl({ 'el': this.$el, 'glassContext': this.glassContext, 'items': aControls }); this._oPropertyUIControl.render().then(function() { return this; }); }, _renderListControl: function(container) { var $wrapper = $('
'); $(container).append($wrapper); $wrapper.append(this.$contentBars); return this.renderContentList({ 'el': $wrapper, 'columns': this._getColumnSpecification(), '$container': this.$el, 'url': this._getRequestURL() }).then(function() { this.setFocus(); }.bind(this)); }, _getRequestURL: function() { return 'v1/objects/' + this.glassContext.profile.account.id + '/items?types=dataSourceCredential&fields=dataSourceName,dataSourceConnectionName,defaultName'; }, _getDefaultRequestURL: function() { return this.itemURL; }, _getModuleName: function() { return 'bi/content_apps/DataSourceCredentialsView'; }, _sendRequest: function(options, successHandler) { var deferred = Q.defer(); if (!successHandler) { successHandler = this._handleSuccess; } this.glassContext.services.ajax.ajax(options) .then(successHandler.bind(this, deferred), this._handleError.bind(this, deferred)); return deferred.promise; }, _handleSuccess: function(deferred) { deferred.resolve(); }, _handleError: function(deferred, dfd, jqXHR) { GlassContextHelper.showAjaxServiceErrorMessage(this.glassContext, jqXHR); deferred.reject(); }, contentbarItems: function() { return [{ 'name': 'nameLabel', 'position': 'leading', 'style': 'nameLabel', 'label': StringResource.get('preferencesDataSourceCredentialsLabel'), 'module': 'bacontentnav/common/ui/contentbar_components/HiddenLabel' }]; }, getListControlOptions: function() { return { 'ajaxProp': 'data', 'emptyFolderString': StringResource.get('emptyPolicyList'), 'showEmptyNewFolderButton': false, 'multiSelect': true, 'rightClickContextMenu': false }; }, setFocus: function() { var $tabs = this.$el.find(':tabbable'); if ($tabs.length > 0) { $tabs.get(0).focus(); } }, _onClose: function() { this.slideout.hide(); }, getDefaultSort: function() { return [1, 'asc']; }, removeSelection: function() { var deferred = Q.defer(); setTimeout(function() { var selectedRows = this.getListControl().getSelectedObjects(); for (var i = 0; i < selectedRows.length; i += 1) { var url = 'v1/objects/' + selectedRows[i].id; var options = { 'headers': { 'Accept': 'application/json', 'Content-Type': 'application/json' }, 'type': 'DELETE', 'url': url }; this._sendRequest(options); } this.getListControl().removeSelectedRows(); this.setFocus(); deferred.resolve(); }.bind(this), 100); return deferred.promise; }, getListControl: function() { return this._listControl; }, _getColumnSpecification: function() { return [{ 'type': 'Icon' }, { 'type': 'Text', 'propertyName': 'dataSourceName', 'label': StringResource.get('preferencesDatasourceHeader') }, { 'type': 'ClickableIcon', 'name': StringResource.get('policesRemove'), 'icon': 'common-remove-delete', 'clickCallback': this.removeSelection.bind(this) }]; }, _adjustWidth: function() { this.$el.addClass('pageview-small'); }, _multiselectbarItems: function() { var items = [{ 'name': 'removeButton', 'position': 'leading', 'icon': 'common-remove-delete', 'module': 'bacontentnav/common/ui/contentbar_components/Button', 'className': 'policyMulSel', 'action': this.removeSelection.bind(this) }, { 'name': 'selectedLabel', 'position': 'leading', 'label': StringResource.get('selected'), 'module': '../../lib/gemini/app/ui/toolbar_components/Label', 'style': 'selectedLabel' }, { 'name': 'cancelButton', 'position': 'trailing', 'label': StringResource.get('cancel'), 'text': StringResource.get('cancel'), 'labelOnly': true, 'module': 'bacontentnav/common/ui/contentbar_components/Button', 'className': 'cancelButton', '_handleClick': function() { this._listControl._clearRows(); this.multiselectBar.hide(); this.contentBar.show(); }.bind(this) }]; return Q.when(items); } }); return DataSourceCredentialsView; }); /* *+------------------------------------------------------------------------+ *| Licensed Materials - Property of IBM *| IBM Cognos Products: Content Explorer *| (C) Copyright IBM Corp. 2016, 2018 *| *| US Government Users Restricted Rights - Use, duplication or disclosure *| restricted by GSA ADP Schedule Contract with IBM Corp. *+------------------------------------------------------------------------+ */ define('bi/content_apps/GroupsAndRolesView',[ 'q', 'jquery', 'underscore', 'bi/glass/app/ContentView', 'bi/content_apps/nls/StringResource', 'bacontentnav/lib/@waca/core-client/js/core-client/ui/properties/PropertyUIControl', 'bacontentnav/utils/GlassContextHelper' ], function(Q, $, _, ContentView, StringResource, PropertyUIControl, GlassContextHelper) { 'use strict'; var GroupsAndRolesView = ContentView.extend({ init: function(options) { GroupsAndRolesView.inherited('init', this, arguments); _.extend(this, options); }, render: function() { var deferred = Q.defer(); this._containerElement = $('
', { 'class': 'propertyUIControl' }); this.$el.append(this._containerElement); this._getGroupsAndRoles().then(function() { var hierarchicalList = this._createHierarchicalList(); this._oPropertyUIControl = new PropertyUIControl({ 'el': this.$el, 'glassContext': this.glassContext, 'items': [{ 'type': 'Banner', 'name': 'GroupsAndRolesBanner', 'value': StringResource.get('preferencesGroupsAndRoles'), 'centerLabel': true, 'hintText': StringResource.get('preferencesGroupsAndRolesHintText'), 'backButton': true, 'editable': false, 'readOnly': true, 'onClose': function() { this.slideout.hide(); }.bind(this) }, { 'type': 'HierarchicalList', 'name': 'groups_and_roles', 'data': hierarchicalList }] }); this._oPropertyUIControl.render().done(deferred.resolve); }.bind(this), function() { this.slideout.hide(); }.bind(this)); return deferred.promise; }, _getGroupsAndRoles: function() { var deferred = Q.defer(); var url = 'v1/users/~/identity'; this.glassContext.services.ajax.ajax({ dataType: 'json', type: 'GET', url: url }).then(function(response) { var roles = []; var groups = []; response.data.forEach(function(anEl) { if (anEl.type === 'role') { roles.push(anEl); } else if (anEl.type === 'group') { groups.push(anEl); } }.bind(this)); if (groups.length > 0 || roles.length > 0) { if (groups.length > 0) { this.groups = groups; } if (roles.length > 0) { this.roles = roles; } deferred.resolve(); } else { deferred.reject(); } }.bind(this), this._handleError.bind(this, deferred)); return deferred.promise; }, /** * Creates a hierarchical list - an array of parentobjects with array of chldren objects * @private * */ _createHierarchicalList: function() { var listData = []; // create the groups parent and children var groupInfo = { 'defaultName': StringResource.get('policyFilterGroups') }; var childInfo = []; if (this.groups) { for (var i = 0; i < this.groups.length; i += 1) { childInfo.push({ 'defaultName': this.groups[i].defaultName }); } groupInfo.children = _.sortBy(childInfo, 'defaultName'); listData.push(groupInfo); } // create the roles parent and children var roleInfo = { 'defaultName': StringResource.get('policyFilterRoles') }; if (this.roles) { childInfo = []; for (var j = 0; j < this.roles.length; j += 1) { childInfo.push({ 'defaultName': this.roles[j].defaultName }); } roleInfo.children = _.sortBy(childInfo, 'defaultName'); listData.push(roleInfo); } return listData; }, /** * Handles an Ajax error * @private * */ _handleError: function(deferred, dfd, jqXHR) { GlassContextHelper.showAjaxServiceErrorMessage(this.glassContext, jqXHR); deferred.reject(); } }); return GroupsAndRolesView; }); define("js/content_apps/preferencesBundle", function(){});