1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495 |
- /*
- *+------------------------------------------------------------------------+
- *| 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 = $('<div>', {
- '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 = $('<div>');
- $(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 = $('<div>');
- $(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 = $('<div>');
- 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 = $('<div></div>');
- $(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 = $('<div>', {
- '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(){});
|