preferencesBundle.debug.js 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| IBM Cognos Products: Content Explorer
  5. *| (C) Copyright IBM Corp. 2016, 2018
  6. *|
  7. *| US Government Users Restricted Rights - Use, duplication or disclosure
  8. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  9. *+------------------------------------------------------------------------+
  10. */
  11. define('bi/content_apps/CapabilitiesView',[
  12. 'jquery',
  13. 'underscore',
  14. 'bi/glass/app/ContentView',
  15. 'bi/content_apps/nls/StringResource',
  16. 'bacontentnav/lib/@waca/core-client/js/core-client/ui/properties/PropertyUIControl',
  17. 'bacontentnav/utils/GlassContextHelper'
  18. ],
  19. function($, _, ContentView, StringResource, PropertyUIControl, GlassContextHelper) {
  20. 'use strict';
  21. var CapabilitiesView = ContentView.extend({
  22. init: function(options) {
  23. CapabilitiesView.inherited('init', this, arguments);
  24. _.extend(this, options);
  25. },
  26. render: function() {
  27. this._containerElement = $('<div>', {
  28. 'class': 'propertyUIControl capabilitiesView'
  29. });
  30. this.$el.append(this._containerElement);
  31. return this._getCapabilityInformation().then(function(allCapabilities) {
  32. var parents = [];
  33. var children = [];
  34. this._translateUserCapabilityNames(allCapabilities, parents, children);
  35. var hierarchicalList = this._createHierarchicalList(parents, children);
  36. this._oPropertyUIControl = this._getPropertyUIControl({
  37. 'el': this.$el,
  38. 'glassContext': this.glassContext,
  39. 'items': [{
  40. 'type': 'Banner',
  41. 'name': 'detailsBanner',
  42. 'value': StringResource.get('preferencesMyCapabilities'),
  43. 'centerLabel': true,
  44. 'hintText': StringResource.get('preferencesCapabilitiesHintText'),
  45. 'backButton': true,
  46. 'editable': false,
  47. 'readOnly': true,
  48. 'onClose': function() {
  49. this.slideout.hide();
  50. }.bind(this)
  51. }, {
  52. 'type': 'HierarchicalList',
  53. 'name': 'capabilities',
  54. 'data': _.sortBy(hierarchicalList, 'defaultName')
  55. }]
  56. });
  57. return this._oPropertyUIControl.render();
  58. }.bind(this), function() {
  59. this.slideout.hide();
  60. return Promise.reject();
  61. }.bind(this));
  62. },
  63. _getPropertyUIControl: function(options) {
  64. return new PropertyUIControl(options);
  65. },
  66. _getCapabilityInformation: function() {
  67. return this.glassContext.services.ajax.ajax({
  68. dataType: 'json',
  69. type: 'GET',
  70. url: 'v1/capabilities'
  71. }).then(function(response) {
  72. if (response.data) {
  73. return response.data;
  74. } else {
  75. return Promise.reject();
  76. }
  77. }.bind(this), this._handleError.bind(this));
  78. },
  79. /**
  80. * Creates a hierarchical list - an array of parentobjects with array of children objects
  81. * @private
  82. *
  83. */
  84. _createHierarchicalList: function(parents, children) {
  85. var listData = [];
  86. for (var j = 0; j < parents.length; j += 1) {
  87. var childCapabilities = [];
  88. for (var k = 0; k < children.length; k += 1) {
  89. if (children[k].parent[0].userCapability === parents[j].userCapability) {
  90. childCapabilities.push({
  91. defaultName: children[k].defaultName
  92. });
  93. }
  94. }
  95. listData.push({
  96. 'defaultName': parents[j].defaultName,
  97. 'children': _.sortBy(childCapabilities, 'defaultName')
  98. });
  99. }
  100. return listData;
  101. },
  102. /**
  103. * Combines the userCapabilities with the list of all capabilities so
  104. * that the translated user friendly capability name is available
  105. * @private
  106. *
  107. */
  108. _translateUserCapabilityNames: function(allCapabilities, parents, children) {
  109. var userCapabilities = this.glassContext.getCoreSvc('.UserProfile').capabilities;
  110. for (var i = 0; i < allCapabilities.length; i += 1) {
  111. var index = _.indexOf(userCapabilities, allCapabilities[i].userCapability);
  112. if (index !== -1) {
  113. // parent capability
  114. if (this._isParentCapability(allCapabilities[i])) {
  115. parents.push(allCapabilities[i]);
  116. } else {
  117. // child capability
  118. children.push(allCapabilities[i]);
  119. }
  120. }
  121. }
  122. },
  123. _isParentCapability: function (capability) {
  124. if (!capability || !capability.parent) {
  125. return false;
  126. }
  127. var parent = capability.parent[0];
  128. if (parent && parent.userCapability) {
  129. return false;
  130. }
  131. return true;
  132. },
  133. /**
  134. * Handles an Ajax error
  135. * @private
  136. */
  137. _handleError: function(dfd, jqXHR) {
  138. GlassContextHelper.showAjaxServiceErrorMessage(this.glassContext, jqXHR);
  139. return Promise.reject();
  140. }
  141. });
  142. return CapabilitiesView;
  143. });
  144. /*
  145. *+------------------------------------------------------------------------+
  146. *| Licensed Materials - Property of IBM
  147. *| IBM Cognos Products: Content Explorer
  148. *| (C) Copyright IBM Corp. 2015, 2018
  149. *|
  150. *| US Government Users Restricted Rights - Use, duplication or disclosure
  151. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  152. *+------------------------------------------------------------------------+
  153. */
  154. define('bi/content_apps/AccountPickerSlideoutView',[
  155. 'bacontentnav/common/ContentListPageView',
  156. 'bi/content_apps/nls/StringResource',
  157. 'bacontentnav/utils/ContentServiceUrls',
  158. 'bacontentnav/utils/ContentStoreObject',
  159. 'bacontentnav/lib/@waca/core-client/js/core-client/ui/properties/PropertyUIControl',
  160. 'bacontentnav/common/ui/BreadcrumbDropDown',
  161. 'bacontentnav/utils/GlassContextHelper',
  162. 'bi/commons/ui/KeyCodes',
  163. 'underscore'
  164. ],
  165. function(ContentListPageView, StringResource, ContentServiceUrls, ContentStoreObject, PropertyUIControl, DropDownMenu, GlassContextHelper, KeyCodes, _) {
  166. 'use strict';
  167. var AccountPickerSlideoutView = ContentListPageView.extend({
  168. stateId: 'AccountPickerSlideoutView',
  169. disabledActions: ['DeleteAction', 'ManageContentAction'],
  170. init: function(options) {
  171. this.namespaceMap = {};
  172. this.searchMode = 'find';
  173. this.events = {};
  174. this.events['keydown .l_findUser2'] = '_handleSearchMenuButtonDown';
  175. AccountPickerSlideoutView.inherited('init', this, arguments);
  176. _.extend(this, options);
  177. },
  178. getRootAncestor: function() {
  179. return ContentStoreObject.getRootNamespacesAncestors();
  180. },
  181. _createDropDown: function($row) {
  182. var menuItems = [{
  183. 'label': StringResource.get('policiesFindMode'),
  184. 'icon': 'common-grant_perm',
  185. 'onSelect': this._onMenuSelect.bind(this, 'find')
  186. }, {
  187. 'label': StringResource.get('policiesTypeInMode'),
  188. 'icon': '',
  189. 'onSelect': this._onMenuSelect.bind(this, 'typein')
  190. }];
  191. this.ddMenu = this._getDropDownMenu({
  192. dropDownMenuSpec: {
  193. 'title': StringResource.get('optionsMenuLabel'),
  194. 'id': 'find',
  195. 'label': 'find',
  196. 'icon': '',
  197. 'items': menuItems,
  198. 'actionElement': $row,
  199. 'ddMenuPlacement': 'bottom'
  200. }
  201. });
  202. this.ddMenu.render().then(function(el) {
  203. $row.appendChild(el);
  204. });
  205. },
  206. _getDropDownMenu: function(options) {
  207. return new DropDownMenu(options);
  208. },
  209. _onMenuSelect: function(mode) {
  210. // check mode and switch if required
  211. this.searchMode = mode;
  212. if (mode === 'find') {
  213. // reset search results list when returning from "Type in" mode
  214. this.getListControl().updateDatatable(this._getDefaultRequestURL());
  215. this.ancestors = [];
  216. this.initializeAncestors();
  217. this.contentBar.getAddedItem('breadcrumbs').then(function(breadcrumbsView) {
  218. breadcrumbsView.updateBreadcrumb(this.ancestors);
  219. }.bind(this));
  220. // Show a check icon next to the first drop down item
  221. this.ddMenu.items[0].icon = 'common-grant_perm';
  222. this.ddMenu.items[1].icon = '';
  223. this._oPropertyUIControl.getProperty('TypeInHintText').setVisibility('hidden');
  224. } else {
  225. // Show a check icon next to the second drop down item
  226. this.ddMenu.items[0].icon = '';
  227. this.ddMenu.items[1].icon = 'common-grant_perm';
  228. this._oPropertyUIControl.getProperty('TypeInHintText').setVisibility('visible');
  229. }
  230. this.setFocus();
  231. },
  232. _getSearchData: function() {
  233. return {
  234. currentNamespaceId: this.ancestors[this.ancestors.length - 1].id,
  235. currentNamespaceType: this.ancestors[this.ancestors.length - 1].type,
  236. searchValue: this._oPropertyUIControl.getProperty('searchValue').getValue()
  237. };
  238. },
  239. _doSearch: function() {
  240. var data = this._getSearchData();
  241. if (!data.searchValue || data.searchValue === '') {
  242. return;
  243. }
  244. //***************************************
  245. // Search (Find mode)
  246. //***************************************
  247. if (this.searchMode === 'find' && data.currentNamespaceType !== 'namespace' && data.currentNamespaceType !== 'namespaceFolder') {
  248. GlassContextHelper.displayToast(this.glassContext,
  249. StringResource.get('policyToastMessageNamespace'), {
  250. 'type': 'warning'
  251. });
  252. return;
  253. }
  254. var dataTable = this.getListControl().getDatatable();
  255. var tableApi = dataTable.api();
  256. var requestURLs = [];
  257. if (this.searchMode === 'find') {
  258. tableApi.clear();
  259. this.getListControl().setShowWorking(true);
  260. tableApi.draw();
  261. requestURLs = [
  262. 'v1/users?pid=' + data.currentNamespaceId + '&&search=keyword|' + encodeURIComponent(data.searchValue),
  263. 'v1/groups?pid=' + data.currentNamespaceId + '&&search=keyword|' + encodeURIComponent(data.searchValue),
  264. 'v1/roles?pid=' + data.currentNamespaceId + '&&search=keyword|' + encodeURIComponent(data.searchValue)
  265. ];
  266. this._sendSearchRequests(requestURLs);
  267. } else if (this.searchMode === 'typein') {
  268. //***************************************
  269. // Search (Type-in) mode)
  270. //***************************************
  271. if (data.searchValue.indexOf('/') === -1) {
  272. GlassContextHelper.displayToast(this.glassContext,
  273. StringResource.get('policyToastMessageSyntax'), {
  274. 'type': 'warning'
  275. });
  276. return;
  277. }
  278. // trim off trailing semi-colon
  279. data.searchValue = data.searchValue.replace(/;$/, '');
  280. tableApi.clear();
  281. this.getListControl().setShowWorking(true);
  282. tableApi.draw();
  283. var searchItems = data.searchValue.split(';');
  284. // parse the search expressiom
  285. searchItems.forEach(function(si) {
  286. var search = si.split('/');
  287. var namespace = search[0].toLowerCase();
  288. var namespaceId = this.namespaceMap[namespace];
  289. // check for valid namespaceId
  290. if (namespaceId && search[1] !== undefined) {
  291. var user = search[1];
  292. requestURLs.push('v1/users?pid=' + namespaceId + '&searchFilter=' + encodeURIComponent('defaultName="' + user + '"|userName="' + user + '"'));
  293. requestURLs.push('v1/groups?pid=' + namespaceId + '&searchFilter=' + encodeURIComponent('defaultName="' + user + '"|userName="' + user + '"'));
  294. requestURLs.push('v1/roles?pid=' + namespaceId + '&searchFilter=' + encodeURIComponent('defaultName="' + user + '"|userName="' + user + '"'));
  295. }
  296. }.bind(this));
  297. this._sendSearchRequests(requestURLs);
  298. }
  299. this.setFocus();
  300. return;
  301. },
  302. _sendSearchRequests: function(requestURLs) {
  303. var aPromises = [];
  304. var bHasResults = false;
  305. requestURLs.forEach(function(requestURL) {
  306. aPromises.push(this.glassContext.getCoreSvc('.Ajax').ajax({
  307. headers: {
  308. Accept: 'application/json',
  309. 'Content-Type': 'application/json'
  310. },
  311. type: 'GET',
  312. url: requestURL
  313. })
  314. .then(function(oResponse) {
  315. if (oResponse.data && oResponse.data.data && oResponse.data.data.length > 0) {
  316. bHasResults = true;
  317. this.getListControl().addRowData(oResponse.data.data);
  318. }
  319. }.bind(this))
  320. .catch(function(err) {
  321. if (err.message) { //TODO: revisit
  322. GlassContextHelper.displayToast(this.glassContext, err.message, {
  323. 'type': 'error'
  324. });
  325. }
  326. }.bind(this)));
  327. }.bind(this));
  328. return Promise.all(aPromises)
  329. .then(function() {
  330. if (!bHasResults) {
  331. this.getListControl().showEmptyTableMessage();
  332. }
  333. }.bind(this));
  334. },
  335. renderContent: function() {
  336. // The content bars get rendered first, detach them here so we can re-attach them to the DOM when just above the list control
  337. this.$contentBars = this.$el.children().detach();
  338. this._oPropertyUIControl = new PropertyUIControl({
  339. 'el': this.$el,
  340. 'glassContext': this.glassContext,
  341. 'closeCallback': this._onCancelClick.bind(this),
  342. 'items': [{
  343. 'name': 'AccountPicker',
  344. 'type': 'Banner',
  345. 'value': StringResource.get('selectAccountGroupOrRole'),
  346. 'backButton': this.slideout.overlay ? true : false,
  347. 'centerLabel': this.slideout.overlay ? true : false
  348. }, {
  349. 'type': 'HintText',
  350. 'name': 'TypeInHintText',
  351. 'visibility': 'hidden',
  352. 'label': StringResource.get('typeInHintText')
  353. }, {
  354. 'name': 'findUser',
  355. 'type': 'SingleLineLinks',
  356. 'items': [{
  357. 'align': 'left',
  358. 'items': [{
  359. 'styles': 'width: 80%',
  360. 'type': 'Input',
  361. 'inputClass': 'policyFindUser',
  362. 'handleReturnKey': true,
  363. 'enterKeyCallback': this._doSearch.bind(this),
  364. 'value': '',
  365. 'placeHolderText': StringResource.get('policiesFindAUserHint'),
  366. 'ariaLabel': StringResource.get('policiesFindAUserHint'),
  367. 'ellipses': false,
  368. 'name': 'searchValue',
  369. 'editable': true,
  370. 'highlightTextOnFocus': true
  371. }, {
  372. 'type': 'icon',
  373. 'svgIcon': 'common-search',
  374. 'clickCallback': this._doSearch.bind(this),
  375. 'value': StringResource.get('policiesFindAUserHint'),
  376. 'iconTooltip': StringResource.get('policiesFindAUserHint')
  377. }, {
  378. 'type': 'icon',
  379. 'svgIcon': 'common-titan-arrow-down',
  380. 'value': StringResource.get('policiesFindModeMenuTip'),
  381. 'iconTooltip': StringResource.get('policiesFindModeMenuTip'),
  382. 'role': 'button'
  383. }]
  384. }]
  385. }, {
  386. 'module': 'bi/content_apps/ui/RenderCallback',
  387. 'renderCallback': this._renderListControl.bind(this)
  388. }, {
  389. 'type': 'Footer',
  390. 'items': [{
  391. 'type': 'Button',
  392. 'label': StringResource.get('policesAddMemberButtonLabel'),
  393. 'onSelect': this._onAddClick.bind(this),
  394. 'primary': true
  395. }]
  396. }]
  397. });
  398. return this._oPropertyUIControl.render().then(function() {
  399. this._renderPostListControls();
  400. return this;
  401. }.bind(this));
  402. },
  403. setFocus: function() {
  404. var searchInput = this.$el.find('input.policyFindUser');
  405. if (searchInput) {
  406. searchInput.focus();
  407. }
  408. },
  409. _closeCallback: function() {
  410. this.close();
  411. },
  412. _renderListControl: function(container) {
  413. var $wrapper = $('<div>');
  414. $(container).append($wrapper);
  415. $wrapper.append(this.$contentBars);
  416. return this.renderContentList({
  417. 'el': $wrapper,
  418. 'columns': this._getColumnSpecification(),
  419. '$container': this.$el,
  420. 'url': (this.url || this._getDefaultRequestURL()),
  421. 'dataManipulationCallback': function(response) {
  422. if (response && response.data) {
  423. response.data = _.filter(response.data, function(namespace){ return _.contains(namespace.permissions, 'traverse'); });
  424. }
  425. }
  426. })
  427. .then(function() {
  428. this.getListControl().setIsAccountPickerSlideout();
  429. this.setFocus();
  430. }.bind(this));
  431. },
  432. _onCancelClick: function() {
  433. this.slideout.hide();
  434. },
  435. _onAddClick: function() {
  436. var oSelected = this.getListControl().getSelectedObjects();
  437. if (typeof (this.addCallback) === 'function') {
  438. this.addCallback(oSelected);
  439. }
  440. this.setFocus();
  441. },
  442. _renderPostListControls: function() {
  443. // add dropdown menu to search input
  444. var $searchTypeButton = this.$el.find('.l_findUser2');
  445. $searchTypeButton.attr('tabindex', '0');
  446. this._createDropDown($searchTypeButton);
  447. // create the MAP for valid namespaces. Used by the type-in search
  448. var dataTable = this.getListControl().getDatatable();
  449. var oData = dataTable.fnGetData();
  450. oData.forEach(function(namespaceItem) {
  451. if (namespaceItem.type === 'namespace') {
  452. this.namespaceMap[namespaceItem.defaultName.toLowerCase()] = namespaceItem.id;
  453. }
  454. }.bind(this));
  455. },
  456. _getDefaultRequestURL: function() {
  457. return ContentServiceUrls.getBaseNamespaceURL();
  458. },
  459. _getDefaultSelfURL: function() {
  460. return ContentServiceUrls.getBaseNamespaceURL();
  461. },
  462. _getModuleName: function() {
  463. return 'bi/content_apps/AccountPickerSlideoutView';
  464. },
  465. contentbarItems: function() {
  466. var filterMenuNamePrefix = 'ACCOUNTPICKER_FILTER_';
  467. var filterString = window.localStorage.getItem('filterString_' + this.stateId);
  468. return [{
  469. 'name': 'nameLabel',
  470. 'position': 'leading',
  471. 'style': 'nameLabel',
  472. 'module': 'bacontentnav/common/ui/contentbar_components/HiddenLabel',
  473. 'label': StringResource.get('policiesTableLable')
  474. }, {
  475. 'name': filterMenuNamePrefix + 'typeMenu',
  476. 'label': StringResource.get('type'),
  477. 'labelOnly': true,
  478. 'hcLabel': false,
  479. 'position': 'trailing',
  480. 'supportCustomCollapse': true,
  481. 'showTitle': false,
  482. 'updateLabel': true,
  483. 'icon': 'common-filter',
  484. 'bSVG': true,
  485. 'module': 'bacontentnav/common/ui/contentbar_components/ToggleMenuBar',
  486. 'items': [{
  487. 'name': filterMenuNamePrefix + 'allContent',
  488. 'icon': 'wft_checkmark',
  489. 'label': StringResource.get('allGenericItems'),
  490. 'checked': (filterString === ''),
  491. 'action': function() {
  492. this._filter('');
  493. }.bind(this)
  494. }, {
  495. 'name': filterMenuNamePrefix + 'accounts',
  496. 'icon': 'wft_checkmark',
  497. 'label': StringResource.get('policyFilterAccounts'),
  498. 'checked': (filterString === 'account'),
  499. 'action': function() {
  500. this._filter('account');
  501. }.bind(this)
  502. }, {
  503. 'name': filterMenuNamePrefix + 'groups',
  504. 'icon': 'wft_checkmark',
  505. 'label': StringResource.get('policyFilterGroups'),
  506. 'checked': (filterString === 'group'),
  507. 'action': function() {
  508. this._filter('group');
  509. }.bind(this)
  510. }, {
  511. 'name': filterMenuNamePrefix + 'roles',
  512. 'icon': 'wft_checkmark',
  513. 'label': StringResource.get('policyFilterRoles'),
  514. 'checked': (filterString === 'role'),
  515. 'action': function() {
  516. this._filter('role');
  517. }.bind(this)
  518. }]
  519. }];
  520. },
  521. getListControlOptions: function() {
  522. return {
  523. 'ajaxProp': 'data',
  524. 'emptyFolderString': StringResource.get('emptyPolicyList'),
  525. 'showEmptyNewFolderButton': false,
  526. 'rightClickContextMenu': false
  527. };
  528. },
  529. getDefaultSort: function() {
  530. return [1, 'asc'];
  531. },
  532. _handleSearchMenuButtonDown: function(evt) {
  533. if (evt.keyCode === KeyCodes.SPACE || evt.keyCode === KeyCodes.ENTER || evt.keyCode === KeyCodes.DOWN_ARROW) {
  534. if ($(evt.currentTarget).click) {
  535. $(evt.currentTarget).click();
  536. evt.stopPropagation();
  537. return false;
  538. }
  539. }
  540. return true;
  541. },
  542. _getColumnSpecification: function() {
  543. return [{
  544. 'type': 'Icon'
  545. }, {
  546. 'type': 'Name',
  547. 'navigateOnly': true
  548. }, {
  549. 'type': 'Time',
  550. 'propertyName': 'modificationTime'
  551. }];
  552. },
  553. _adjustWidth: function() {
  554. this.$el.addClass('pageview-small');
  555. },
  556. _navigate: function(oData) {
  557. void(oData);
  558. AccountPickerSlideoutView.inherited('navigate', this, arguments);
  559. this.setFocus();
  560. }
  561. });
  562. return AccountPickerSlideoutView;
  563. });
  564. /*
  565. *+------------------------------------------------------------------------+
  566. *| Licensed Materials - Property of IBM
  567. *| IBM Cognos Products: content-apps
  568. *| (C) Copyright IBM Corp. 2016, 2018
  569. *|
  570. *| US Government Users Restricted Rights - Use, duplication or disclosure
  571. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  572. *+------------------------------------------------------------------------+
  573. */
  574. define('bi/content_apps/CredentialsView',[
  575. 'bacontentnav/common/ContentListPageView',
  576. 'bi/content_apps/common/ui/permissions/Policy',
  577. 'bi/content_apps/nls/StringResource',
  578. 'bacontentnav/utils/ContentStoreObject',
  579. 'bi/commons/ui/Slideout',
  580. 'bacontentnav/utils/GlassContextHelper',
  581. 'bacontentnav/lib/@waca/core-client/js/core-client/ui/properties/PropertyUIControl',
  582. 'bi/content_apps/AccountPickerSlideoutView',
  583. 'underscore'
  584. ],
  585. function(ContentListPageView, Policy, StringResource, ContentStoreObject, Slideout, GlassContextHelper, PropertyUIControl, AccountPickerSlideoutView, _) {
  586. 'use strict';
  587. var CredentialsView = ContentListPageView.extend({
  588. init: function(options) {
  589. CredentialsView.inherited('init', this, arguments);
  590. _.extend(this, options);
  591. //contentListFacets is used by _filter logic of its base class (ie. ContentListPageView), need to populated by subclasses;
  592. //it consists of key/value pairs, values are used for ListControl filtering.
  593. this.contentListFacets = {
  594. 'accounts': 'account',
  595. 'groups': 'group',
  596. 'roles': 'role'
  597. };
  598. },
  599. renderContent: function() {
  600. this.$el.addClass('policies');
  601. // The content bars get rendered first, detach them here so we can re-attach them to the DOM when just above the list control
  602. this.$contentBars = this.$el.children().detach();
  603. var aControls = [{
  604. 'module': 'bi/content_apps/ui/RenderCallback',
  605. 'renderCallback': this._renderListControl.bind(this)
  606. }, {
  607. 'type': 'Banner',
  608. 'name': 'credentialsBanner',
  609. 'value': StringResource.get('preferencesMyCredentials'),
  610. 'centerLabel': true,
  611. 'hintText': StringResource.get('preferencesCredentialsHintText'),
  612. 'backButton': true,
  613. 'editable': false,
  614. 'readOnly': true,
  615. 'onClose': this._onClose.bind(this)
  616. }, {
  617. 'type': 'Footer',
  618. 'items': [{
  619. 'type': 'Button',
  620. 'label': StringResource.get('applyLabel'),
  621. 'onSelect': this._onApplyClick.bind(this),
  622. 'primary': true
  623. }, {
  624. 'type': 'Button',
  625. 'label': StringResource.get('cancel'),
  626. 'onSelect': this._onCancelClick.bind(this),
  627. 'primary': false
  628. }]
  629. }];
  630. this._oPropertyUIControl = this._getPropertyUIControl({
  631. 'el': this.$el,
  632. 'glassContext': this.glassContext,
  633. 'items': aControls
  634. });
  635. return this._oPropertyUIControl.render();
  636. },
  637. _getPropertyUIControl: function(options) {
  638. return new PropertyUIControl(options);
  639. },
  640. _renderListControl: function(container) {
  641. var $wrapper = $('<div>');
  642. $(container).append($wrapper);
  643. $wrapper.append(this.$contentBars);
  644. return this.renderContentList({
  645. 'el': $wrapper,
  646. 'columns': this._getColumnSpecification(),
  647. '$container': this.$el,
  648. 'getJSONDataCallback': this._getCredentialData.bind(this)
  649. })
  650. .then(function() {
  651. this.getListControl().setIsAccountPickerSlideout();
  652. }.bind(this));
  653. },
  654. // credential data
  655. _getCredentialData: function() {
  656. return this._getUserCredentials()
  657. .then(function() {
  658. return this._getPolicies(this.credentialId)
  659. .then(function() {
  660. return {
  661. data: this.policyArray.data[0].policies
  662. };
  663. }.bind(this));
  664. }.bind(this))
  665. .catch(function(err) {
  666. this.slideout.hide();
  667. return Promise.reject(err);
  668. }.bind(this));
  669. },
  670. // query to retrieve credential id
  671. _getUserCredentials: function() {
  672. return this._sendRequest({
  673. dataType: 'json',
  674. type: 'GET',
  675. url: 'v1/users/~/credentials'
  676. }, function(response) {
  677. if (response.data && response.data.id) {
  678. this.credentialId = response.data.id;
  679. } else {
  680. return Promise.reject(new Error());
  681. }
  682. }.bind(this));
  683. },
  684. // query to retrieve policies of current credential
  685. _getPolicies: function(id) {
  686. return this._sendRequest({
  687. dataType: 'json',
  688. type: 'GET',
  689. url: 'v1/objects/' + id + '?fields=policies{defaultName,id,searchPath}'
  690. }, function(response) {
  691. if (response.data && response.data.data[0].policies) {
  692. this.policyArray = response.data;
  693. return this.policyArray;
  694. } else {
  695. return Promise.reject(new Error());
  696. }
  697. }.bind(this));
  698. },
  699. _onApplyClick: function() {
  700. var data = {};
  701. data.policies = this.policyArray.data[0].policies;
  702. data.type = 'credential';
  703. var jsonData = JSON.stringify(data);
  704. var url = 'v1/objects/' + this.credentialId;
  705. var options = {
  706. 'headers': {
  707. 'Accept': 'application/json',
  708. 'Content-Type': 'application/json'
  709. },
  710. 'type': 'PUT',
  711. 'url': url,
  712. 'data': jsonData
  713. };
  714. return this._sendRequest(options, function() {});
  715. },
  716. _onCancelClick: function() {
  717. this.slideout.hide();
  718. },
  719. _sendRequest: function(options, successHandler) {
  720. return this.glassContext.getCoreSvc('.Ajax').ajax(options)
  721. .then(successHandler.bind(this))
  722. .catch(function(err) {
  723. if (err.message) {
  724. this.glassContext.appController.showErrorMessage(err.message, 'Error');
  725. }
  726. return Promise.reject(err);
  727. }.bind(this));
  728. },
  729. _getDefaultRequestURL: function() {
  730. return this.itemURL;
  731. },
  732. _getModuleName: function() {
  733. return 'bi/content_apps/CredentialsView';
  734. },
  735. getDefaultSort: function() {
  736. return [1, 'asc'];
  737. },
  738. setFocus: function() {
  739. var $tabs = this.$el.find(':tabbable');
  740. if ($tabs.length > 0) {
  741. $tabs.get(0).focus();
  742. }
  743. },
  744. _isDuplicate: function(oData, matchId) {
  745. var isDuplicate = false;
  746. oData.forEach(function(arrayElem) {
  747. var id = arrayElem.securityObject.id;
  748. if (id === matchId) {
  749. isDuplicate = true;
  750. return false;
  751. }
  752. });
  753. return isDuplicate;
  754. },
  755. removeSelection: function() {
  756. setTimeout(function() {
  757. var selectedPolicies = this.getListControl().getSelectedObjects();
  758. var currentPolicies = this.policyArray.data[0].policies;
  759. var updatedPolicies = _.reject(currentPolicies, function(policy) {
  760. return _.find(selectedPolicies, function(selPol) {
  761. return policy.securityObject.defaultName === selPol.securityObject.defaultName;
  762. });
  763. });
  764. this.policyArray.data[0].policies = updatedPolicies;
  765. var numberDeleted = this.getListControl().getSelectedRows().length;
  766. if (numberDeleted > 0) {
  767. var sToastMessage = (numberDeleted === 1)? StringResource.get('toastItemsWereDeletedSingular', {
  768. 'noOfItems': numberDeleted
  769. }) : StringResource.get('toastItemsWereDeleted', {
  770. 'noOfItems': numberDeleted
  771. });
  772. this.getListControl().removeSelectedRows();
  773. this.glassContext.appController.showToast(sToastMessage);
  774. }
  775. this.setFocus();
  776. }.bind(this), 100);
  777. },
  778. addSelection: function(selectedItems) {
  779. var itemCount = 0;
  780. var numberAdded = 0;
  781. var dataTable = this.getListControl().getDatatable();
  782. var tableApi = dataTable.api();
  783. var oData = dataTable.fnGetData();
  784. selectedItems.forEach(function(item) {
  785. var itemId = item.id;
  786. var itemType = item.type;
  787. var itemName = item.defaultName;
  788. var itemPath = item.searchPath;
  789. var foundDuplicate = this._isDuplicate(oData, itemId);
  790. itemCount = itemCount + 1;
  791. if (!foundDuplicate) {
  792. numberAdded = numberAdded + 1;
  793. var policy = new Policy(itemName, itemId, itemType, itemPath);
  794. this.policyArray.data[0].policies.push(policy);
  795. tableApi.row.add(policy).draw(true);
  796. }
  797. }.bind(this));
  798. var sToastMessage;
  799. if (numberAdded === 1) {
  800. sToastMessage = StringResource.get('toastItemsWereAddedSingular', {
  801. 'noOfItems': numberAdded
  802. });
  803. } else if (numberAdded === 0 && itemCount === 1) {
  804. sToastMessage = StringResource.get('toastItemsAlreadyAddedSingular');
  805. } else if (numberAdded === 0 && itemCount > 1) {
  806. sToastMessage = StringResource.get('toastItemsAlreadyAdded');
  807. } else {
  808. sToastMessage = StringResource.get('toastItemsWereAdded', {
  809. 'noOfItems': numberAdded
  810. });
  811. }
  812. this.glassContext.appController.showToast(sToastMessage);
  813. },
  814. _onClose: function() {
  815. this.slideout.hide();
  816. },
  817. _openAddMembersSlideout: function(oData) {
  818. var overlaySlideoutEl = $('<div>');
  819. this.slideout.$el.append(overlaySlideoutEl);
  820. var overlaySlideout = this._getSlideout({
  821. 'glassContext': this.glassContext,
  822. 'position': this.position || 'right',
  823. 'el': overlaySlideoutEl,
  824. 'overlay': true,
  825. 'width': this.slideout.$el.width(),
  826. 'enableTabLooping': true,
  827. 'content': {
  828. 'module': AccountPickerSlideoutView,
  829. 'showBreadcrumbs': true,
  830. 'navigateOnRowSelect': true,
  831. 'addCallback': function(selectedItems) {
  832. this.addSelection(selectedItems);
  833. }.bind(this),
  834. 'objectInformation': oData,
  835. 'glassContext': this.glassContext
  836. }
  837. });
  838. overlaySlideout.render()
  839. .then(function() {
  840. overlaySlideout.show();
  841. });
  842. },
  843. _getSlideout: function(options) {
  844. return new Slideout(options);
  845. },
  846. contentbarItems: function() {
  847. var filterString = window.localStorage.getItem('filterString_' + this.stateId);
  848. return [{
  849. 'name': 'nameLabel',
  850. 'position': 'leading',
  851. 'label': StringResource.get('preferencesCredentialsLabel'),
  852. 'style': 'nameLabel',
  853. 'module': 'bacontentnav/common/ui/contentbar_components/HiddenLabel'
  854. }, {
  855. 'name': 'typeMenu',
  856. 'label': StringResource.get('type'),
  857. 'labelOnly': true,
  858. 'hcLabel': false,
  859. 'position': 'trailing',
  860. 'supportCustomCollapse': true,
  861. 'showTitle': false,
  862. 'updateLabel': true,
  863. 'icon': 'common-filter',
  864. 'bSVG': true,
  865. 'module': 'bacontentnav/common/ui/contentbar_components/ToggleMenuBar',
  866. 'items': [{
  867. 'name': 'allContent',
  868. 'icon': 'wft_checkmark',
  869. 'label': StringResource.get('allGenericItems'),
  870. 'checked': (filterString === 'allContent'),
  871. 'action': function() {
  872. this._filter('allContent');
  873. }.bind(this)
  874. }, {
  875. 'name': 'accounts',
  876. 'icon': 'wft_checkmark',
  877. 'label': StringResource.get('policyFilterAccounts'),
  878. 'checked': (filterString === 'accounts'),
  879. 'action': function() {
  880. this._filter('accounts');
  881. }.bind(this)
  882. }, {
  883. 'name': 'groups',
  884. 'icon': 'wft_checkmark',
  885. 'label': StringResource.get('policyFilterGroups'),
  886. 'checked': (filterString === 'groups'),
  887. 'action': function() {
  888. this._filter('groups');
  889. }.bind(this)
  890. }, {
  891. 'name': 'roles',
  892. 'icon': 'wft_checkmark',
  893. 'label': StringResource.get('policyFilterRoles'),
  894. 'checked': (filterString === 'roles'),
  895. 'action': function() {
  896. this._filter('roles');
  897. }.bind(this)
  898. }]
  899. }, {
  900. 'name': 'separator',
  901. 'type': 'Separator',
  902. 'position': 'trailing'
  903. }, {
  904. 'name': 'add',
  905. 'position': 'trailing',
  906. 'displayLabel': false,
  907. 'label': StringResource.get('policesAddMemberButtonLabel'),
  908. 'module': 'bacontentnav/common/ui/contentbar_components/Button',
  909. 'className': 'addNewFolder',
  910. 'icon': 'common-add',
  911. '_handleClick': function() {
  912. this._openAddMembersSlideout();
  913. }.bind(this)
  914. }];
  915. },
  916. getListControlOptions: function() {
  917. return {
  918. 'ajaxProp': 'data',
  919. 'emptyFolderString': StringResource.get('emptyPolicyList'),
  920. 'showEmptyNewFolderButton': true,
  921. 'multiSelect': true,
  922. 'rightClickContextMenu': false
  923. };
  924. },
  925. _getColumnSpecification: function() {
  926. return [{
  927. 'type': 'Icon',
  928. 'getDataFn': function(oRowData) {
  929. if (oRowData.securityObject[ContentStoreObject.TYPE] === 'nil') {
  930. return StringResource.get('unknown');
  931. } else {
  932. return oRowData.securityObject[ContentStoreObject.TYPE];
  933. }
  934. }
  935. }, {
  936. 'type': 'Name',
  937. 'scope': 'row',
  938. 'getDataFn': function(oRowData) {
  939. if (oRowData.securityObject[ContentStoreObject.DEFAULT_NAME] === undefined) {
  940. return StringResource.get('unavailable');
  941. } else {
  942. return _.escape(oRowData.securityObject[ContentStoreObject.DEFAULT_NAME]);
  943. }
  944. }
  945. }, {
  946. 'type': 'ClickableIcon',
  947. 'name': StringResource.get('policesRemove'),
  948. 'icon': 'common-remove-delete',
  949. 'clickCallback': this.removeSelection.bind(this)
  950. }];
  951. },
  952. _adjustWidth: function() {
  953. this.$el.addClass('pageview-small');
  954. },
  955. _multiselectbarItems: function() {
  956. return Promise.resolve([{
  957. 'name': 'removeButton',
  958. 'position': 'leading',
  959. 'icon': 'common-remove-delete',
  960. 'module': 'bacontentnav/common/ui/contentbar_components/Button',
  961. 'className': 'policyMulSel',
  962. 'action': this.removeSelection.bind(this)
  963. }, {
  964. 'name': 'selectedLabel',
  965. 'position': 'leading',
  966. 'module': '../../lib/gemini/app/ui/toolbar_components/Label',
  967. 'style': 'selectedLabel'
  968. }, {
  969. 'position': 'leading',
  970. 'type': 'Separator'
  971. }, {
  972. 'name': 'cancelButton',
  973. 'position': 'trailing',
  974. 'label': StringResource.get('cancel'),
  975. 'text': StringResource.get('cancel'),
  976. 'labelOnly': true,
  977. 'module': 'bacontentnav/common/ui/contentbar_components/Button',
  978. 'className': 'cancelButton',
  979. '_handleClick': function() {
  980. this.getListControl()._clearRows();
  981. this.multiselectBar.hide();
  982. this.contentBar.show();
  983. }.bind(this)
  984. }]);
  985. },
  986. getFilterSpec: function() {
  987. return [{
  988. 'name': 'allContent',
  989. 'label': StringResource.get('allContent'),
  990. 'value': 'allContent'
  991. }, {
  992. 'name': 'accounts',
  993. 'label': StringResource.get('policyFilterAccounts'),
  994. 'value': 'accounts'
  995. }, {
  996. 'name': 'groups',
  997. 'label': StringResource.get('policyFilterGroups'),
  998. 'value': 'groups'
  999. }, {
  1000. 'name': 'roles',
  1001. 'label': StringResource.get('policyFilterRoles'),
  1002. 'value': 'roles'
  1003. }];
  1004. }
  1005. });
  1006. return CredentialsView;
  1007. });
  1008. /*
  1009. *+------------------------------------------------------------------------+
  1010. *| Licensed Materials - Property of IBM
  1011. *| IBM Cognos Products: Content Explorer
  1012. *| (C) Copyright IBM Corp. 2016, 2018
  1013. *|
  1014. *| US Government Users Restricted Rights - Use, duplication or disclosure
  1015. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  1016. *+------------------------------------------------------------------------+
  1017. */
  1018. define('bi/content_apps/DataSourceCredentialsView',[
  1019. 'q',
  1020. 'jquery',
  1021. 'underscore',
  1022. 'bacontentnav/common/ContentListPageView',
  1023. 'bi/content_apps/nls/StringResource',
  1024. 'bacontentnav/utils/GlassContextHelper',
  1025. 'bacontentnav/lib/@waca/core-client/js/core-client/ui/properties/PropertyUIControl'
  1026. ],
  1027. function(Q, $, _, ContentListPageView, StringResource, GlassContextHelper, PropertyUIControl) {
  1028. 'use strict';
  1029. var DataSourceCredentialsView = ContentListPageView.extend({
  1030. init: function(options) {
  1031. this.itemURL = options.itemURL;
  1032. DataSourceCredentialsView.inherited('init', this, arguments);
  1033. _.extend(this, options);
  1034. },
  1035. renderContent: function() {
  1036. // The content bars get rendered first, detach them here so we can re-attach them to the DOM when just above the list control
  1037. this.$contentBars = this.$el.children().detach();
  1038. var aControls = [];
  1039. aControls.push({
  1040. 'module': 'bi/content_apps/ui/RenderCallback',
  1041. 'renderCallback': this._renderListControl.bind(this)
  1042. }, {
  1043. 'type': 'Banner',
  1044. 'name': 'credentialsBanner',
  1045. 'value': StringResource.get('preferencesDatasourceTitle'),
  1046. 'centerLabel': true,
  1047. 'hintText': StringResource.get('preferencesDataSourceCredentialsHintText'),
  1048. 'backButton': true,
  1049. 'editable': false,
  1050. 'readOnly': true,
  1051. 'onClose': this._onClose.bind(this)
  1052. });
  1053. this._oPropertyUIControl = new PropertyUIControl({
  1054. 'el': this.$el,
  1055. 'glassContext': this.glassContext,
  1056. 'items': aControls
  1057. });
  1058. this._oPropertyUIControl.render().then(function() {
  1059. return this;
  1060. });
  1061. },
  1062. _renderListControl: function(container) {
  1063. var $wrapper = $('<div></div>');
  1064. $(container).append($wrapper);
  1065. $wrapper.append(this.$contentBars);
  1066. return this.renderContentList({
  1067. 'el': $wrapper,
  1068. 'columns': this._getColumnSpecification(),
  1069. '$container': this.$el,
  1070. 'url': this._getRequestURL()
  1071. }).then(function() {
  1072. this.setFocus();
  1073. }.bind(this));
  1074. },
  1075. _getRequestURL: function() {
  1076. return 'v1/objects/' + this.glassContext.profile.account.id + '/items?types=dataSourceCredential&fields=dataSourceName,dataSourceConnectionName,defaultName';
  1077. },
  1078. _getDefaultRequestURL: function() {
  1079. return this.itemURL;
  1080. },
  1081. _getModuleName: function() {
  1082. return 'bi/content_apps/DataSourceCredentialsView';
  1083. },
  1084. _sendRequest: function(options, successHandler) {
  1085. var deferred = Q.defer();
  1086. if (!successHandler) {
  1087. successHandler = this._handleSuccess;
  1088. }
  1089. this.glassContext.services.ajax.ajax(options)
  1090. .then(successHandler.bind(this, deferred), this._handleError.bind(this, deferred));
  1091. return deferred.promise;
  1092. },
  1093. _handleSuccess: function(deferred) {
  1094. deferred.resolve();
  1095. },
  1096. _handleError: function(deferred, dfd, jqXHR) {
  1097. GlassContextHelper.showAjaxServiceErrorMessage(this.glassContext, jqXHR);
  1098. deferred.reject();
  1099. },
  1100. contentbarItems: function() {
  1101. return [{
  1102. 'name': 'nameLabel',
  1103. 'position': 'leading',
  1104. 'style': 'nameLabel',
  1105. 'label': StringResource.get('preferencesDataSourceCredentialsLabel'),
  1106. 'module': 'bacontentnav/common/ui/contentbar_components/HiddenLabel'
  1107. }];
  1108. },
  1109. getListControlOptions: function() {
  1110. return {
  1111. 'ajaxProp': 'data',
  1112. 'emptyFolderString': StringResource.get('emptyPolicyList'),
  1113. 'showEmptyNewFolderButton': false,
  1114. 'multiSelect': true,
  1115. 'rightClickContextMenu': false
  1116. };
  1117. },
  1118. setFocus: function() {
  1119. var $tabs = this.$el.find(':tabbable');
  1120. if ($tabs.length > 0) {
  1121. $tabs.get(0).focus();
  1122. }
  1123. },
  1124. _onClose: function() {
  1125. this.slideout.hide();
  1126. },
  1127. getDefaultSort: function() {
  1128. return [1, 'asc'];
  1129. },
  1130. removeSelection: function() {
  1131. var deferred = Q.defer();
  1132. setTimeout(function() {
  1133. var selectedRows = this.getListControl().getSelectedObjects();
  1134. for (var i = 0; i < selectedRows.length; i += 1) {
  1135. var url = 'v1/objects/' + selectedRows[i].id;
  1136. var options = {
  1137. 'headers': {
  1138. 'Accept': 'application/json',
  1139. 'Content-Type': 'application/json'
  1140. },
  1141. 'type': 'DELETE',
  1142. 'url': url
  1143. };
  1144. this._sendRequest(options);
  1145. }
  1146. this.getListControl().removeSelectedRows();
  1147. this.setFocus();
  1148. deferred.resolve();
  1149. }.bind(this), 100);
  1150. return deferred.promise;
  1151. },
  1152. getListControl: function() {
  1153. return this._listControl;
  1154. },
  1155. _getColumnSpecification: function() {
  1156. return [{
  1157. 'type': 'Icon'
  1158. }, {
  1159. 'type': 'Text',
  1160. 'propertyName': 'dataSourceName',
  1161. 'label': StringResource.get('preferencesDatasourceHeader')
  1162. }, {
  1163. 'type': 'ClickableIcon',
  1164. 'name': StringResource.get('policesRemove'),
  1165. 'icon': 'common-remove-delete',
  1166. 'clickCallback': this.removeSelection.bind(this)
  1167. }];
  1168. },
  1169. _adjustWidth: function() {
  1170. this.$el.addClass('pageview-small');
  1171. },
  1172. _multiselectbarItems: function() {
  1173. var items = [{
  1174. 'name': 'removeButton',
  1175. 'position': 'leading',
  1176. 'icon': 'common-remove-delete',
  1177. 'module': 'bacontentnav/common/ui/contentbar_components/Button',
  1178. 'className': 'policyMulSel',
  1179. 'action': this.removeSelection.bind(this)
  1180. }, {
  1181. 'name': 'selectedLabel',
  1182. 'position': 'leading',
  1183. 'label': StringResource.get('selected'),
  1184. 'module': '../../lib/gemini/app/ui/toolbar_components/Label',
  1185. 'style': 'selectedLabel'
  1186. }, {
  1187. 'name': 'cancelButton',
  1188. 'position': 'trailing',
  1189. 'label': StringResource.get('cancel'),
  1190. 'text': StringResource.get('cancel'),
  1191. 'labelOnly': true,
  1192. 'module': 'bacontentnav/common/ui/contentbar_components/Button',
  1193. 'className': 'cancelButton',
  1194. '_handleClick': function() {
  1195. this._listControl._clearRows();
  1196. this.multiselectBar.hide();
  1197. this.contentBar.show();
  1198. }.bind(this)
  1199. }];
  1200. return Q.when(items);
  1201. }
  1202. });
  1203. return DataSourceCredentialsView;
  1204. });
  1205. /*
  1206. *+------------------------------------------------------------------------+
  1207. *| Licensed Materials - Property of IBM
  1208. *| IBM Cognos Products: Content Explorer
  1209. *| (C) Copyright IBM Corp. 2016, 2018
  1210. *|
  1211. *| US Government Users Restricted Rights - Use, duplication or disclosure
  1212. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  1213. *+------------------------------------------------------------------------+
  1214. */
  1215. define('bi/content_apps/GroupsAndRolesView',[
  1216. 'q',
  1217. 'jquery',
  1218. 'underscore',
  1219. 'bi/glass/app/ContentView',
  1220. 'bi/content_apps/nls/StringResource',
  1221. 'bacontentnav/lib/@waca/core-client/js/core-client/ui/properties/PropertyUIControl',
  1222. 'bacontentnav/utils/GlassContextHelper'
  1223. ],
  1224. function(Q, $, _, ContentView, StringResource, PropertyUIControl, GlassContextHelper) {
  1225. 'use strict';
  1226. var GroupsAndRolesView = ContentView.extend({
  1227. init: function(options) {
  1228. GroupsAndRolesView.inherited('init', this, arguments);
  1229. _.extend(this, options);
  1230. },
  1231. render: function() {
  1232. var deferred = Q.defer();
  1233. this._containerElement = $('<div>', {
  1234. 'class': 'propertyUIControl'
  1235. });
  1236. this.$el.append(this._containerElement);
  1237. this._getGroupsAndRoles().then(function() {
  1238. var hierarchicalList = this._createHierarchicalList();
  1239. this._oPropertyUIControl = new PropertyUIControl({
  1240. 'el': this.$el,
  1241. 'glassContext': this.glassContext,
  1242. 'items': [{
  1243. 'type': 'Banner',
  1244. 'name': 'GroupsAndRolesBanner',
  1245. 'value': StringResource.get('preferencesGroupsAndRoles'),
  1246. 'centerLabel': true,
  1247. 'hintText': StringResource.get('preferencesGroupsAndRolesHintText'),
  1248. 'backButton': true,
  1249. 'editable': false,
  1250. 'readOnly': true,
  1251. 'onClose': function() {
  1252. this.slideout.hide();
  1253. }.bind(this)
  1254. }, {
  1255. 'type': 'HierarchicalList',
  1256. 'name': 'groups_and_roles',
  1257. 'data': hierarchicalList
  1258. }]
  1259. });
  1260. this._oPropertyUIControl.render().done(deferred.resolve);
  1261. }.bind(this), function() {
  1262. this.slideout.hide();
  1263. }.bind(this));
  1264. return deferred.promise;
  1265. },
  1266. _getGroupsAndRoles: function() {
  1267. var deferred = Q.defer();
  1268. var url = 'v1/users/~/identity';
  1269. this.glassContext.services.ajax.ajax({
  1270. dataType: 'json',
  1271. type: 'GET',
  1272. url: url
  1273. }).then(function(response) {
  1274. var roles = [];
  1275. var groups = [];
  1276. response.data.forEach(function(anEl) {
  1277. if (anEl.type === 'role') {
  1278. roles.push(anEl);
  1279. } else if (anEl.type === 'group') {
  1280. groups.push(anEl);
  1281. }
  1282. }.bind(this));
  1283. if (groups.length > 0 || roles.length > 0) {
  1284. if (groups.length > 0) {
  1285. this.groups = groups;
  1286. }
  1287. if (roles.length > 0) {
  1288. this.roles = roles;
  1289. }
  1290. deferred.resolve();
  1291. } else {
  1292. deferred.reject();
  1293. }
  1294. }.bind(this), this._handleError.bind(this, deferred));
  1295. return deferred.promise;
  1296. },
  1297. /**
  1298. * Creates a hierarchical list - an array of parentobjects with array of chldren objects
  1299. * @private
  1300. *
  1301. */
  1302. _createHierarchicalList: function() {
  1303. var listData = [];
  1304. // create the groups parent and children
  1305. var groupInfo = {
  1306. 'defaultName': StringResource.get('policyFilterGroups')
  1307. };
  1308. var childInfo = [];
  1309. if (this.groups) {
  1310. for (var i = 0; i < this.groups.length; i += 1) {
  1311. childInfo.push({
  1312. 'defaultName': this.groups[i].defaultName
  1313. });
  1314. }
  1315. groupInfo.children = _.sortBy(childInfo, 'defaultName');
  1316. listData.push(groupInfo);
  1317. }
  1318. // create the roles parent and children
  1319. var roleInfo = {
  1320. 'defaultName': StringResource.get('policyFilterRoles')
  1321. };
  1322. if (this.roles) {
  1323. childInfo = [];
  1324. for (var j = 0; j < this.roles.length; j += 1) {
  1325. childInfo.push({
  1326. 'defaultName': this.roles[j].defaultName
  1327. });
  1328. }
  1329. roleInfo.children = _.sortBy(childInfo, 'defaultName');
  1330. listData.push(roleInfo);
  1331. }
  1332. return listData;
  1333. },
  1334. /**
  1335. * Handles an Ajax error
  1336. * @private
  1337. *
  1338. */
  1339. _handleError: function(deferred, dfd, jqXHR) {
  1340. GlassContextHelper.showAjaxServiceErrorMessage(this.glassContext, jqXHR);
  1341. deferred.reject();
  1342. }
  1343. });
  1344. return GroupsAndRolesView;
  1345. });
  1346. define("js/content_apps/preferencesBundle", function(){});