/*
*+------------------------------------------------------------------------+
*| 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/common/ui/permissions/Policy',[],function() {
'use strict';
/**
* Represents a Policy (account, group or role) that is found in the policy of an item
*/
function Policy(name, id, type, path) {
// Ensures that the callee has invoked our Class' constructor function
// with the `new` keyword
if (!(this instanceof Policy)) {
throw new TypeError('Policy constructor cannot be called as a function.');
}
this.permissions = [{
name: 'read',
access: 'grant'
}, {
name: 'traverse',
access: 'grant'
}];
this.securityObject = {
defaultName: name,
id: id,
type: type,
searchPath: path
};
}
Policy.prototype = {
constructor: Policy
};
return Policy;
});
define('text!bi/content_apps/common/policyfacets.json',[],function () { return '{\n\t"copyright": "Licensed Materials - Property of IBM. IBM Cognos Products: BI Cloud(C) Copyright IBM Corp.2014, 2017. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.",\n\t"facets": {\n "accounts": "account",\n "groups": "group",\n "roles": "role"\n\t},\n\t"columns": []\n}';});
/*
*+------------------------------------------------------------------------+
*| Licensed Materials - Property of IBM
*| IBM Cognos Products: BI Content Explorer
*| (C) Copyright IBM Corp. 2015, 2020
*|
*| US Government Users Restricted Rights - Use, duplication or disclosure
*| restricted by GSA ADP Schedule Contract with IBM Corp.
*+------------------------------------------------------------------------+
*/
define('bi/content_apps/common/PolicyPropertyView',[
'bacontentnav/common/ContentListPageView',
'bi/content_apps/common/ui/permissions/Policy',
'text!./policyfacets.json',
'bi/content_apps/nls/StringResource',
'bacontentnav/lib/@waca/core-client/js/core-client/ui/properties/CheckBox',
'bacontentnav/utils/ContentStoreObject',
'bi/commons/ui/Button',
'bacontentnav/utils/PolicyHelper',
'bacontentnav/common/ui/BreadcrumbDropDown',
'bacontentnav/utils/GlassContextHelper',
'bacontentnav/lib/@waca/core-client/js/core-client/ui/properties/PropertyUIControl',
'underscore'
], function(ContentListPageView, Policy, policyFacets, StringResource, CheckBox, ContentStoreObject, CommonButton, PolicyHelper, DropDownMenu, GlassContextHelper, PropertyUIControl, _) {
'use strict';
var PolicyPropertyView = ContentListPageView.extend({
init: function(options) {
this.itemURL = options.itemURL;
this.showUnavailablePolicies = false;
PolicyPropertyView.inherited('init', this, arguments);
_.extend(this, options);
this.addURLParameters({
'schemaInfo': 'true',
'fields': 'surname,givenName,userName,defaultName,policies.defaultName,policies.id,policies.ancestors,permissions'
});
this.contentListFacets = JSON.parse(policyFacets).facets;
},
getPoliciesData: function() {
return Promise.resolve(this.permissionsData);
},
_canModifyPolicies: function(canModify) {
if (canModify === undefined) {
this.canModifyPolicies = ContentStoreObject.hasPermissions(this.oData.data[0], ['setPolicy']) && !(ContentStoreObject.isPoliciesAcquired(this.oData.data[0]));
} else {
this.canModifyPolicies = canModify;
}
},
_getObject: function() {
var urlParms = this.getURLParameters();
var reqUrl = this._getDefaultRequestURL();
$.each(urlParms, function(name, value) {
if (reqUrl === this.itemURL) {
reqUrl += '?';
} else {
reqUrl += '&';
}
reqUrl += name + '=' + value;
}.bind(this));
// Query for the information we need to open the view
var options = {
dataType: 'json',
type: 'GET',
data: {},
url: reqUrl,
cache: false
};
return this.glassContext.getCoreSvc('.Ajax').ajax(options)
.then(function(response) {
return response && response.data;
});
},
_setOData: function(oData) {
var updatedPolicies = [];
this.rejectedPolicies = [];
if (oData.data[0].policies) {
oData.data[0].policies.forEach(function(policy) {
if (policy.securityObject.type === 'nil') {
this.rejectedPolicies.push(policy);
} else {
updatedPolicies.push(policy);
}
}.bind(this));
oData.data[0].policies = updatedPolicies;
}
this.oData = oData;
},
_showHideAddMemberButton: function(isShown) {
var buttonTabIndex = '0';
if ((isShown) && (this.canModifyPolicies)) {
this.contentBar.itemMap.add.show();
} else {
this.contentBar.itemMap.add.hide();
buttonTabIndex = '-1';
}
$(this.contentBar.itemMap.add.el).find('button').attr('tabindex', buttonTabIndex);
},
_updateUIForEdit: function() {
var isRoot = ContentStoreObject.isTeamContent(this.oData.data[0]);
var listControl = this.getListControl();
this.applyToChildren = this._oPropertyUIControl.getProperty('applyToAllChildren');
if (isRoot) {
if (this.contentBar.itemMap.add) {
this._showHideAddMemberButton(true);
}
} else {
var overrideParent = this._oPropertyUIControl.getProperty('overrideParent');
var isChecked = overrideParent.isChecked();
this._canModifyPolicies(isChecked);
if (!isChecked) {
// If we are turning off multi select we should clear selections
listControl._clearRows();
this.multiselectBar.hide();
this.contentBar.show();
this.applyToChildren.uncheck();
this.applyToChildren.disable();
} else {
this.applyToChildren.enable();
}
listControl.multiSelect = isChecked;
this.$el.removeClass('policyCanNotModify');
if (!(this.canModifyPolicies && isChecked)) {
this.$el.addClass('policyCanNotModify');
}
if (this.contentBar.itemMap.add) {
this._showHideAddMemberButton(isChecked);
}
}
},
render: function() {
return this._getObject().then(function(oData) {
this._setOData(oData);
this.permissionsData = {};
this.permissionsData.data = oData.data[0].policies ? oData.data[0].policies : [];
this._canModifyPolicies();
return PolicyPropertyView.inherited('render', this, arguments).then(function() {
this._updateUIForEdit();
return Promise.resolve();
}.bind(this));
}.bind(this));
},
_overrideParentChanged: function() {
this._updateUIForEdit();
this._enableApplyItems();
},
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 = [];
if ((this.rejectedPolicies) && (this.rejectedPolicies.length > 0)) {
aControls.push({
'type': 'SingleLineLinks',
'name': 'hidePolicies',
'items': [{
'align': 'left',
'items': [{
'type': 'text',
'class': 'versionStatusText',
'value': StringResource.get('missingPolicies'),
'svgIcon': 'common-warning'
}]
}]
},{
'type': 'CheckBox',
'name': 'showUnavailablePolicies',
'label': StringResource.get('showUnavailablePolicies'),
'controlOnLeft': true,
'checked': this.showUnavailablePolicies,
'onChange': this._toggleShowUnavailablePolicies.bind(this)
});
}
var isRoot = ContentStoreObject.isTeamContent(this.oData.data[0]);
if (!isRoot) {
aControls.push({
'type': 'CheckBox',
'name': 'overrideParent',
'label': StringResource.get('overrideParentPermissions'),
'controlOnLeft': true,
'checked': !(ContentStoreObject.isPoliciesAcquired(this.oData.data[0])),
'onChange': this._overrideParentChanged.bind(this)
});
}
aControls.push({
'module': 'bi/content_apps/ui/RenderCallback',
'renderCallback': this._renderListControl.bind(this)
}, {
'type': 'CheckBox',
'name': 'applyToAllChildren',
'label': StringResource.get('applyToAllChildren'),
'controlOnLeft': true,
'onChange': this._enableApplyItems.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 = new PropertyUIControl({
'el': this.$el,
'glassContext': this.glassContext,
'items': aControls
});
return this._oPropertyUIControl.render().then(function() {
var footer = this._getFooter();
var footerProps;
footerProps = footer._oPropertyUIControl.getProperties();
this.applyButton = footerProps[0];
this.applyButton.disable();
return Promise.resolve();
}.bind(this));
},
_getFooter: function() {
var propList = this._oPropertyUIControl.getProperties();
var footer;
propList.forEach(function(prop) {
if (prop.type === 'Footer') {
footer = prop;
}
});
return footer;
},
_renderListControl: function(container) {
var $wrapper = $('
');
$(container).append($wrapper);
$wrapper.append(this.$contentBars);
return this.renderContentList({
'el': $wrapper,
'columns': this._getColumnSpecification(),
'$container': this.$el.closest('.propertiesUIControlPageView'),
'minHeight': 50,
'url': (this.url || this._getDefaultRequestURL())
});
},
_onCancelClick: function() {
this.slideout.hide();
},
_onApplyClick: function() {
var data = {};
data.policies = this.oData.data[0].policies;
data.type = this.oData.data[0].type;
var overrideParent = this._oPropertyUIControl.getProperty('overrideParent');
var overrideChecked = (!overrideParent || overrideParent.isChecked());
if (overrideChecked) {
// Add back in the policies the user can not see
if ((this.rejectedPolicies) && (this.rejectedPolicies.length > 0)) {
this.rejectedPolicies.forEach(function(policy) {
data.policies.push(policy);
});
}
// Setup the search path for the security objects
data.policies.forEach(function(policy) {
var currentSO = policy.securityObject;
currentSO.searchPath = 'storeID("' + currentSO.id + '")';
});
} else {
// If the override parent permission is not checked then clear out the permissions
data.policies = [];
}
// Set the apply to all children
if (this.applyToChildren.isChecked()) {
data._meta = {
'schemaInfo': {
'policies': {
'applyUpdateToDescendants': true
}
}
};
}
var jsonData = JSON.stringify(data);
var options = {
'headers': {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
'type': 'PUT',
'url': ContentStoreObject.getSelfLink(this.oData.data[0]),
'data': jsonData
};
// Reset the ui after apply
this.applyButton.disable();
return this._sendRequest(options).then(function(response) {
// After updating , refetch policies and render them
// especially after deselecting override and overrides were previously applied
// default policies need to be rendered instead
if (!overrideChecked) {
this._getObject().then(function(oData) {
this._setOData(oData);
this.permissionsData = {};
this.permissionsData.data = oData.data[0].policies ? oData.data[0].policies : [];
this._canModifyPolicies();
this.refresh(this.itemURL);
this._updateUIForEdit();
return Promise.resolve(response);
}.bind(this));
} else {
this._updateUIForEdit();
return Promise.resolve(response);
}
}.bind(this));
},
_sendRequest: function(options, successHandler) {
successHandler = successHandler || function() {
return Promise.resolve();
};
return this.glassContext.getCoreSvc('.Ajax').ajax(options)
.then(successHandler.bind(this))
.catch(function(err) {
GlassContextHelper.showAjaxServiceError(this.glassContext, err);
return Promise.reject(err);
}.bind(this));
},
_getDefaultRequestURL: function() {
return this.itemURL;
},
_getModuleName: function() {
return 'bi/content_apps/common/ui/PolicyPropertyView';
},
getFilterSpec: function() {
return [{
'name': 'allContent',
'label': StringResource.get('allGenericItems'),
'value': 'allContent'
}, {
'name': 'accounts',
'label': StringResource.get('policyFilterAccounts'),
'value': 'account'
}, {
'name': 'groups',
'label': StringResource.get('policyFilterGroups'),
'value': 'group'
}, {
'name': 'roles',
'label': StringResource.get('policyFilterRoles'),
'value': 'role'
}];
},
_getFilterItems: function(filterSpec, filterMenuPrefix, defaultFilterValue, doFilter) {
return _.map(filterSpec, function(item) {
return {
'name': filterMenuPrefix + item.name,
'icon': 'wft_checkmark',
'label': item.label,
'checked': item.value === defaultFilterValue,
'action': function() {
doFilter(item.name);
}
};
});
},
contentbarItems: function() {
var filterMenuNamePrefix = 'POLICY_FILTER_';
var filterString = window.localStorage.getItem('filterString_' + this.stateId) || '';
var filterSpec = this.getFilterSpec();
var filterItems = this._getFilterItems(filterSpec, filterMenuNamePrefix, filterString, this._filter.bind(this));
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'),
'hcLabel': false,
'position': 'trailing',
'supportCustomCollapse': true,
'showTitle': false,
'updateLabel': true,
'icon': 'common-filter',
'bSVG': true,
'module': 'bacontentnav/common/ui/contentbar_components/ToggleMenuBar',
'items': filterItems
}, {
'name': 'add',
'position': 'trailing',
'displayLabel': false,
'label': StringResource.get('policesAddMemberButtonLabel'),
'module': 'bacontentnav/common/ui/contentbar_components/Button',
'className': 'addNewFolder',
'supportCustomCollapse': true,
'icon': 'common-add',
'hiddenOnRender': true,
'_handleClick': function() {
this._openAddMembersSlideout();
}.bind(this)
}];
},
getListControlOptions: function() {
return {
'ajaxProp': 'data',
'emptyFolderString': StringResource.get('emptyPolicyList'),
'showEmptyNewFolderButton': false,
'getJSONDataCallback': this.getPoliciesData.bind(this),
'url': '',
'multiSelect': this.canModifyPolicies,
'rightClickContextMenu': false
};
},
getDefaultSort: function() {
return [1, 'asc'];
},
_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 overrideParent = this._oPropertyUIControl.getProperty('overrideParent');
var canOverride = overrideParent === null || overrideParent.isChecked();
if (canOverride) {
var selectedPolicies = this.getListControl().getSelectedObjects();
var updatedPolicies = _.reject(this.oData.data[0].policies, function(policy) {
return _.find(selectedPolicies, function(selPol) {
return policy.securityObject.defaultName === selPol.securityObject.defaultName;
});
});
this.getListControl().removeSelectedRows();
this.oData.data[0].policies = updatedPolicies;
if (updatedPolicies && updatedPolicies.length > 0) {
this._enableApplyItems();
this.setFocus();
} else {
this._disableApplyItems();
}
}
}.bind(this), 100);
},
addSelection: function(selectedItems) { //NOSONAR
var itemCount = 0;
var numberAdded = 0;
var dataTable = this.getListControl().getDatatable();
var tableApi = dataTable.api();
// need to check for duplicates and simply ignore them
var oData = dataTable.fnGetData();
selectedItems.forEach(function(item) {
var itemId = item.id;
var itemType = item.type;
var itemName = item.defaultName;
var foundDuplicate = this._isDuplicate(oData, itemId);
itemCount = itemCount + 1;
if ((!foundDuplicate) && (itemType !== 'namespaceFolder')) {
numberAdded = numberAdded + 1;
var policy = new Policy(itemName, itemId, itemType);
tableApi.row.add(policy).draw(true);
if(this.oData.data[0].policies !== null ) {
this.oData.data[0].policies.push(policy);
} else {
this.oData.data[0].policies = [];
this.oData.data[0].policies.push(policy);
}
}
}.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);
this._enableApplyItems();
},
_openAddMembersSlideout: function(oData) {
this.glassContext.appController.showSlideOut({
'parent': this.slideout,
'width': '450', // temporary adjustment for R10 until panel size is unified
'content': {
'module': 'bi/admin/account/slideout/SecurityObjectSelectorPane',
'parentView': this,
'objectInfo': oData,
'title': StringResource.get('selectAccountGroupOrRole'),
'allowedSelectionTypes': ['group', 'role', 'account', 'namespace'],
'multiSelectCallback': this.addSelection.bind(this)
}
});
},
_birdBeakMenuItems: function() {
return [{
'label': StringResource.get('permissionRead'),
'icon': '',
'onSelect': function() {
var listCon = this.getListControl();
if (listCon) {
this._updatePermission(PolicyHelper.simplePermEnum.read, listCon.getSelectedObjects(), listCon.getSelectedRows());
}
}.bind(this)
}, {
'label': StringResource.get('permissionRun'),
'icon': '',
'onSelect': function() {
var listCon = this.getListControl();
if (listCon) {
this._updatePermission(PolicyHelper.simplePermEnum.run, listCon.getSelectedObjects(), listCon.getSelectedRows());
}
}.bind(this)
}, {
'label': StringResource.get('permissionWrite'),
'icon': '',
'onSelect': function() {
var listCon = this.getListControl();
if (listCon) {
this._updatePermission(PolicyHelper.simplePermEnum.write, listCon.getSelectedObjects(), listCon.getSelectedRows());
}
}.bind(this)
}, {
'label': StringResource.get('permissionFull'),
'icon': '',
'onSelect': function() {
var listCon = this.getListControl();
if (listCon) {
this._updatePermission(PolicyHelper.simplePermEnum.full, listCon.getSelectedObjects(), listCon.getSelectedRows());
}
}.bind(this)
}];
},
_updatePermission: function(newPerm, selectedObjects, selectedRows) {
var pos = 0;
selectedObjects.forEach(function(policyObj) {
policyObj.permissions = PolicyHelper.clonePermissionArray(newPerm);
var currentRow = selectedRows[pos];
if (currentRow) {
this.getListControl().updateCell(policyObj, selectedRows[pos], 2);
}
pos += 1;
}.bind(this));
this.applyButton.enable();
},
_getColumnSpecification: function() {
var columns = [];
columns.push({
'type': 'Icon',
'getDataFn': function(oRowData) {
if (oRowData.securityObject[ContentStoreObject.TYPE] === 'nil') {
return 'unknown';
} else {
return oRowData.securityObject[ContentStoreObject.TYPE];
}
}
});
var multiPropItems = [];
multiPropItems.push({
'type': 'Text',
'scope': 'row',
'label': StringResource.get('name'),
'getDataFn': function(oRowData) {
if (oRowData.securityObject[ContentStoreObject.DEFAULT_NAME] === undefined) {
return StringResource.get('unavailable');
} else {
var userData = this.oData.data[0];
// check if the givenName, surName, and userName are available, otherwise display the defaultName
return this._getUserName(userData, oRowData);
}
}.bind(this)
});
multiPropItems.push({
'type': 'Text',
'getDataFn': function(oRowData) {
return this._getPath(oRowData);
}.bind(this)
});
columns.push({
'type': 'MultipleProperties',
'items': multiPropItems
});
columns.push({
'type': 'MultipleProperties',
'orientation': 'horizontal',
'weight': 10,
'items': [{
'type': 'Permission',
'clickCallback': this._openPolicyDetailSlideoutView.bind(this)
}, {
'type': 'BirdBeakMenu',
'name': StringResource.get('permissionSetAccess'),
'menuItems': this._birdBeakMenuItems()
}]
});
columns.push({
'type': 'ClickableIcon',
'name': StringResource.get('policesRemove'),
'icon': 'common-remove-delete',
'clickCallback': this.removeSelection.bind(this),
'a11yLabel': StringResource.get('removeSelectedItem')
});
return columns;
},
_adjustWidth: function() {
this.$el.addClass('pageview-small');
},
_refreshTable: function() {
var selectedRow = this.getListControl().getSelectedRows();
if (selectedRow.length > 0) {
var selectedObject = this.getListControl().getSelectedObjects();
this.getListControl().updateCell(selectedObject[0], selectedRow[0], 2);
}
},
_getUserName: function(userData, oRowData){
if(userData.userName && (userData.givenName && userData.surname) && (_.escape(userData.defaultName) === _.escape(oRowData.securityObject[ContentStoreObject.DEFAULT_NAME]))){
return userData.givenName + ' ' + userData.surname + ' (' + userData.userName + ')';
} else if(userData.userName && !(userData.givenName && userData.surname) && (_.escape(userData.defaultName) === _.escape(oRowData.securityObject[ContentStoreObject.DEFAULT_NAME]))){
return _.escape(oRowData.securityObject[ContentStoreObject.DEFAULT_NAME]) + ' (' + userData.userName + ')';
} else{
return _.escape(oRowData.securityObject[ContentStoreObject.DEFAULT_NAME]);
}
},
_getPath: function(oRowData) {
var path = '';
if (oRowData.securityObject[ContentStoreObject.ANCESTORS] && oRowData.securityObject[ContentStoreObject.ANCESTORS].length) {
var ancestorsArray = oRowData.securityObject[ContentStoreObject.ANCESTORS];
ancestorsArray.shift(); // remove 'Directory'
for (var i=0; i< ancestorsArray.length; i++) {
path += (path === '') ? ('') : (' > ');
path += ancestorsArray[i].defaultName;
}
}
return path;
},
_openPolicyDetailSlideoutView: function(oData) {
this.slideout.addChild({
'width': '400',
'onHide': this._refreshTable.bind(this),
'enableTabLooping': true,
'content': {
'module': 'bi/content_apps/common/PolicyDetailsView',
'enableParentApplyButton': function() {
this.applyButton.enable();
}.bind(this),
'objectInformation': oData,
'ownerData': this.oData.data[0],
'canModify': this.canModifyPolicies
}
});
},
getListControl: function() {
return this._listControl;
},
_showUnavailablePolicies: function() {
var dataTable = this.getListControl().getDatatable();
var tableApi = dataTable.api();
this.rejectedPolicies.forEach(function(rejPol) {
this.oData.data[0].policies.push(rejPol);
tableApi.row.add(rejPol).draw(true);
}.bind(this));
this.rejectedPolicies = [];
},
_hideUnavailablePolicies: function() {
var updatedPolicies = [];
var index = 0;
var rowsToRemove = [];
this.oData.data[0].policies.forEach(function(pol) {
if (pol.securityObject.type === 'nil') {
this.rejectedPolicies.push(pol);
rowsToRemove.push(index);
} else {
updatedPolicies.push(pol);
}
index += 1;
}.bind(this));
this.getListControl().removeIndexRows(rowsToRemove);
this.oData.data[0].policies = updatedPolicies;
},
_toggleShowUnavailablePolicies: function() {
var showUnavailablePolicies = this._oPropertyUIControl.getProperty('showUnavailablePolicies');
var isChecked = showUnavailablePolicies.isChecked();
if (isChecked) {
this._showUnavailablePolicies();
} else {
this._hideUnavailablePolicies();
}
this.showUnavailablePolicies = !this.showUnavailablePolicies;
},
_createMultiSelectBar: function() {
return (PolicyPropertyView.inherited('_createMultiSelectBar', this, arguments)).then(function() {
var $actionEl = this.$el.find('.multiselectbar .policyMulSel');
this.msddMenu = new DropDownMenu({
dropDownMenuSpec: {
'title': StringResource.get('permissionSetAccess'),
'id': 'birdBeakIdms',
'label': 'BirdBeakMS',
'items': this._birdBeakMenuItems(),
'actionElement': $actionEl[0],
'ddMenuPlacement': 'bottom'
}
});
this.msddMenu.render().then(function(el) {
$actionEl.append(el);
});
return Promise.resolve(this);
}.bind(this));
},
_multiselectbarItems: function() {
return Promise.resolve([{
'name': 'SetLabel',
'position': 'leading',
'module': '../../lib/gemini/app/ui/toolbar_components/Label',
'label': 'Set',
'style': 'policyMultiSelectLabel'
}, {
'name': 'birdBeakButton',
'position': 'leading',
'displayLabel': false,
'label': StringResource.get('permissionSetAccess'),
'icon': 'common-titan-arrow-down',
'module': './contentbar_components/Button',
'className': 'policyMulSel'
}, {
'position': 'leading',
'type': 'Separator'
}, {
'name': 'removeButton',
'position': 'leading',
'displayLabel': false,
'label': StringResource.get('removeSelectedItem'),
'icon': 'common-remove-delete',
'module': './contentbar_components/Button',
'className': 'policyMulSel',
'action': this.removeSelection.bind(this)
}, {
'name': 'selectedLabel',
'position': 'center',
'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': './contentbar_components/Button',
'className': 'cancelButton',
'_handleClick': function() {
this._listControl._clearRows();
this.multiselectBar.hide();
this.contentBar.show();
}.bind(this)
}]);
},
_enableApplyItems: function() {
this.applyToChildren.enable();
this.applyButton.enable();
},
_disableApplyItems: function() {
this.applyToChildren.disable();
this.applyButton.disable();
}
});
return PolicyPropertyView;
});
/*
*+------------------------------------------------------------------------+
*| 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/PropertiesPermissionsTab',['q',
'bi/glass/app/ContentView',
'bacontentnav/utils/UIHelper',
'bacontentnav/lib/@waca/core-client/js/core-client/ui/properties/PropertyUIControl',
'bi/content_apps/common/PolicyPropertyView',
'bacontentnav/utils/ContentStoreObject',
'underscore'
], function(Q, View, UIHelper, PropertyUIControl, PolicyPropertyView, ContentStoreObject, _) {
'use strict';
var PropertiesPermissionsTab = View.extend({
/**
@paran options.el {node} - container dom node
**/
init: function(options) {
PropertiesPermissionsTab.inherited('init', this, arguments);
_.extend(this, options);
this.policyView = null;
},
render: function() {
this.policyView = this._getPolicyPropertyView({
'el': this.$el,
'id': 'policyPropertyView',
'slideout': this.slideout,
'glassContext': this.glassContext,
'itemURL': ContentStoreObject.getSelfLink(this.objectInfo)
});
return this.policyView.render();
},
_getPolicyPropertyView: function(options) {
return new PolicyPropertyView(options);
}
});
return PropertiesPermissionsTab;
});
/*
*+------------------------------------------------------------------------+
*| 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/PropertiesTab',['q',
'bacontentnav/lib/@waca/core-client/js/core-client/ui/properties/PropertyTabView',
'bacontentnav/utils/ContentStoreObject',
'underscore'
], function(Q, PropertyTabView, ContentStoreObject, _) {
'use strict';
var PropertiesTab = PropertyTabView.extend({
/**
* @paran options.el {node} - container dom node
*/
init: function(options) {
PropertiesTab.inherited('init', this, arguments);
_.extend(this, options);
},
_setReportOption: function(optionBlob, option, bDefault) {
for (var i = 0; i < optionBlob.length; i++) {
//if options exists, either modify or remove it
if (optionBlob[i].name === option.name) {
if (bDefault) {
optionBlob.splice(i, 1);
} else {
optionBlob[i].value = option.value;
}
return;
}
}
if (!bDefault) {
optionBlob.push(option);
}
},
_setAdvancedOption: function(optionBlob, optionName, optionType, optionValue, defaultValue) {
var option = {};
option.name = optionName;
option.type = optionType;
option.value = optionValue;
this._setReportOption(optionBlob, option, option.value === defaultValue);
},
_getRetentionValue: function(objectClass) {
var retention = null;
if (objectClass === 'history') {
retention = ContentStoreObject.getRunHistoryConfig(this.objectInfo);
} else if (objectClass === 'reportVersion') {
retention = ContentStoreObject.getReportOutputVersionsConfig(this.objectInfo);
}
if (retention) {
if (retention.maxDuration === undefined || !retention.maxDuration) {
return retention.maxObjects;
} else {
return parseInt(retention.maxDuration.match(/\d+/), 10);
}
}
return 1;
},
_getRetentionUnit: function(objectClass) {
var retention = null;
if (objectClass === 'history') {
retention = ContentStoreObject.getRunHistoryConfig(this.objectInfo);
} else if (objectClass === 'reportVersion') {
retention = ContentStoreObject.getReportOutputVersionsConfig(this.objectInfo);
}
if (retention) {
if (retention.maxDuration === undefined || !retention.maxDuration) {
return 'occurrences';
} else {
var list = retention.maxDuration.split(/\d+/);
return list[1] === 'D' ? 'days' : 'months';
}
}
return 'occurrences';
},
_getReportRetentions: function() {
return ContentStoreObject.getReportRetentions(this.objectInfo);
},
_setReportRetention: function(retentionBlob, value, unit, ojbectClass) {
var retention = {
'prop': 'creationTime',
'objectClass': ojbectClass
};
if (retentionBlob) {
for (var i = 0; i < retentionBlob.length; i++) {
if (retentionBlob[i].objectClass === ojbectClass) {
retention = retentionBlob[i];
break;
}
}
}
this._setRetentionValue(retention, value, unit);
},
_getModifiedRetentions: function(modifiedProperties, modifiedPropertiesUI) {
var retentionBlob = this._getReportRetentions();
var retentionModified = false;
if (modifiedPropertiesUI.hasOwnProperty('runHistory') || modifiedPropertiesUI.hasOwnProperty('runHistoryUnit')) {
retentionModified = true;
this._setReportRetention(retentionBlob, modifiedPropertiesUI.runHistory, modifiedPropertiesUI.runHistoryUnit, 'history');
delete modifiedPropertiesUI.runHistory;
delete modifiedPropertiesUI.runHistoryUnit;
}
if (modifiedPropertiesUI.hasOwnProperty('reportVersion') || modifiedPropertiesUI.hasOwnProperty('reportVersionUnit')) {
retentionModified = true;
this._setReportRetention(retentionBlob, modifiedPropertiesUI.reportVersion, modifiedPropertiesUI.reportVersionUnit, 'reportVersion');
delete modifiedPropertiesUI.reportVersion;
delete modifiedPropertiesUI.reportVersionUnit;
}
if (retentionModified) {
_.extend(modifiedProperties, {
'retentions': retentionBlob
});
}
},
_setRetentionValue: function(retention, value, unit) {
if (value >= 0) {
if (unit) {
//both modified
if (unit === 'occurrences') {
retention.maxObjects = value;
delete retention.maxDuration;
} else {
retention.maxObjects = 0;
retention.maxDuration = 'P' + value + (unit === 'days' ? 'D' : 'M');
}
} else {
//only value modified
if (retention.maxDuration) {
retention.maxDuration = retention.maxDuration.replace(/\d+/, value);
} else {
retention.maxObjects = value;
}
}
} else {
if (unit) {
//only unit modified
if (unit === 'occurrences') {
if (retention.maxDuration) {
retention.maxObjects = parseInt(retention.maxDuration.match(/\d+/), 10);
delete retention.maxDuration;
}
} else {
if (retention.maxDuration) {
retention.maxDuration = retention.maxDuration.replace(/(\w+)(\d+)(\w+)/, '$1$2' + (unit === 'days' ? 'D' : 'M'));
} else {
retention.maxDuration = 'P' + retention.maxObjects + (unit === 'days' ? 'D' : 'M');
retention.maxObjects = 0;
}
}
}
}
}
});
return PropertiesTab;
});
/*
*+------------------------------------------------------------------------+
*| 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/PromptValuesView',[
'jquery',
'bi/glass/app/ContentView',
'bi/content_apps/nls/StringResource',
'bacontentnav/utils/ContentStoreObject',
'bacontentnav/lib/@waca/core-client/js/core-client/ui/properties/PropertyUIControl',
'bi/schedule/views/PromptPickerView',
'bacontentnav/utils/UIHelper',
'underscore'
],
function($, ContentView, StringResource, ContentStoreObject, PropertyUIControl, PromptPicker, UIHelper, _) {
'use strict';
var PromptValuesView = ContentView.extend({
init: function(options) {
PromptValuesView.inherited('init', this, arguments);
_.extend(this, options);
this.showClickables = (typeof this.isEditMode === 'undefined') ? true : this.isEditMode;
},
render: function() {
var _clickables = [{}];
if (this.showClickables) {
_clickables = [{
'type': 'text',
'name': 'editPromptValues',
'value': this._getBannerEditSetText()
}, {
'type': 'text',
'value': StringResource.get('clear'),
'name': 'clearPromptValues',
'clickCallback': function() {
this.promptDisplayValues = [];
this._getPromptValuesSection().refreshProperties([]);
if (this.clearCallback) {
this.clearCallback();
}
}.bind(this)
}];
}
this._oPropertyUIControl = new PropertyUIControl({
'el': this.$el,
'glassContext': this.glassContext,
'slideout': this.slideout,
'items': [{
'type': 'Banner',
'name': 'promptValuesBanner',
'id': this.viewId,
'value': StringResource.get('currentValues'),
'centerLabel': true,
'backButton': this.slideout.overlay,
'editable': false,
'readOnly': true,
'onClose': function() {
this.slideout.hide();
}.bind(this),
'clickables': _clickables
}, {
'type': 'CollapsibleSection',
'name': 'SectionPromptValues',
'styleAsSimpleRow': true,
'hideSectionTitle': true,
'open': true,
'items': this._getPromptItems(this.promptDisplayValues)
}]
});
if (!this._areValueSet()) {
this._renderEmptyPaneInfoMessage(this.$el);
}
return this._oPropertyUIControl.render().then(function() {
this._renderPromptPicker();
}.bind(this));
},
_areValueSet: function() {
return (this._getPromptItems(this.promptDisplayValues).length !== 0) ? true : false;
},
_getBannerEditSetText: function() {
var str = (this._areValueSet()) ? 'edit' : 'set';
return StringResource.get(str);
},
_renderEmptyPaneInfoMessage: function($node) {
UIHelper.renderInfoMessage($node, StringResource.get('noPromptsValuesSet'));
},
_removeEmptyPaneInfoMessage: function($node) {
$node.find('div.contentApps_comingSoon').remove();
},
_renderPromptPicker: function() {
this.promptPicker = new PromptPicker({
$toggler: this.$el.find('div[class^="editPromptValues' + this.viewId + ' "]'),
reportId: this.parentView && this.parentView.objectInfo.id,
values: this.parameters,
useValues: this.useParameters !== false,
glassContext: this.glassContext,
onFinish: function() {
this._onEditFinish();
}.bind(this)
});
this.promptPicker.render();
},
_onEditFinish: function() {
this.parameters = this.promptPicker.getParameterValues();
this.promptDisplayValues = ContentStoreObject.getPromptsDisplayValues(this.parameters);
var items = this._getPromptItems(this.promptDisplayValues);
this._getPromptValuesSection().refreshProperties(items);
if (this.editCallback) {
this.editCallback(this.parameters);
}
this._removeEmptyPaneInfoMessage(this.$el);
},
_getPromptValuesSection: function() {
return this._oPropertyUIControl.getProperty('SectionPromptValues');
},
_getPromptItems: function(promptDisplayValues) {
var items = [];
if (promptDisplayValues) {
for (var i = 0; i < promptDisplayValues.length; i = i + 1) {
items.push({
'type': 'Separator'
});
var label = _.escape(promptDisplayValues[i].name),
display = promptDisplayValues[i].display;
var singleLine = {
'type': 'SingleLineValue',
'name': label,
'label': label,
'value': display
};
items.push(singleLine);
}
}
return items;
},
setFocus: function() {
this._oPropertyUIControl.setFocus('promptValuesBanner');
}
});
return PromptValuesView;
});
/*
*+------------------------------------------------------------------------+
*| Licensed Materials - Property of IBM
*|
*| IBM Cognos Products: content-apps
*|
*| (C) Copyright IBM Corp. 2018
*|
*| US Government Users Restricted Rights - Use, duplication or disclosure
*| restricted by GSA ADP Schedule Contract with IBM Corp.
*+------------------------------------------------------------------------+
*/
define('bi/content_apps/utils/Utils',[], function() {
'use strict';
var reHtmlEncode = /[<>&]/g;
var htmlEncode = {
'&': '&',
'<': '<',
'>': '>'
};
var reXmlEncode = /[<>&'"]/g;
var xmlEncode = {
'&': '&',
'<': '<',
'>': '>',
'\'': ''',
'"': '"'
};
return {
/**
* Returns the html encoded version of the given text
* @param {string} text
* @return {string}
*/
htmlEncode: function(text) {
return (text || '').replace(reHtmlEncode, function(m) {
return htmlEncode[m];
});
},
/**
* Returns the xml encoded version of the given text
* ... according to https://www.ibm.com/support/knowledgecenter/en/SSEP7J_10.2.2/com.ibm.swg.ba.cognos.dg_sdk.10.2.2.doc/r_d15e1241850.html#bibus_xmlEncodedXML
* @param {string} text
* @return {string}
*/
xmlEncode: function(text) {
if (text || text === 0) {
return String(text).replace(reXmlEncode, function(m) {
return xmlEncode[m];
});
} else {
return '';
}
}
};
});
/*
*+------------------------------------------------------------------------+
*| 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/PdfOptionsView',[
'jquery',
'underscore',
'bi/content_apps/nls/StringResource',
'bi/content_apps/utils/Utils',
'bacontentnav/lib/@waca/core-client/js/core-client/ui/properties/PropertyPageView',
'bacontentnav/lib/@waca/core-client/js/core-client/ui/properties/PropertyUIControl',
'bacontentnav/utils/GlassContextHelper'
], function($, _, StringResource, Utils, PropertyPageView, PropertyUIControl, GlassContextHelper) {
'use strict';
var PdfOptionsView = PropertyPageView.extend({
/**
@param options.el {node} - container dom node
@param options.pdfOptions {array} - PDF options in format same as Content Rest API
@param options.glassContext {object} - Glass context
@param options.closeCallback {function} - callback when the view is closed, pass current option values in format same as Content Rest API.
[{ name :