SetCustomParameterValues.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /**
  2. * Licensed Materials - Property of IBM
  3. * IBM Cognos Products: Cognos Analytics
  4. * Copyright IBM Corp. 2015, 2017
  5. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. */
  7. 'use strict'; //NOSONAR
  8. define(['underscore', 'bi/admin/nls/StringResource', 'doT', 'bacontentnav/common/ContentListPageView', 'bacontentnav/common/ui/ListControl', 'bi/admin/common/ui/listview/actions/AddParameterAction', 'text!bi/admin/common/templates/ParametersTabTemplate.html', 'bacontentnav/utils/WidgetNavigator'], function (_, StringResource, doT, View, ListControl, AddParameterAction, ParametersTabTemplate, WidgetNavigator) {
  9. var SetCustomParameterValues = View.extend({
  10. init: function init(options) {
  11. SetCustomParameterValues.inherited('init', this, arguments);
  12. _.extend(this, options);
  13. },
  14. render: function render() {
  15. this.$el.empty();
  16. this.$el.addClass('gp-define-parameters-container');
  17. var sHtml = doT.template(ParametersTabTemplate)({
  18. 'isSlideout': this.isSlideout,
  19. 'newText': StringResource.get('new'),
  20. 'newButtonId': 'admin-add-parm-value',
  21. 'title': StringResource.get('setValues')
  22. });
  23. this.$el.html(sHtml);
  24. $('#admin-add-parm-value').on('primaryaction', this._addValue.bind(this));
  25. return this._renderListControl();
  26. },
  27. _renderListControl: function _renderListControl() {
  28. if (this.listControl) {
  29. this.listControl.remove();
  30. }
  31. var $container = this.$el.find('.ca-listContainer');
  32. this.listControl = new ListControl({
  33. contentView: this,
  34. columns: this.getColumnSpecs(),
  35. el: $container,
  36. showEmptyNewFolderButton: false,
  37. emptyFolderString: StringResource.get('noGlobalParameterValues'),
  38. accessibleLabel: StringResource.get('viewGlobalParameters'),
  39. disableColumnHeaders: true,
  40. glassContext: this.glassContext,
  41. getJSONDataCallback: function () {
  42. return Promise.resolve({
  43. data: this.values
  44. });
  45. }.bind(this)
  46. });
  47. return this.listControl.render().then(function () {
  48. this.listControl.widgetKeyController = new WidgetNavigator({
  49. $el: this.listControl.$el.find('.listControl'),
  50. focusClass: 'contentListFocusable'
  51. });
  52. this.$el.find('.nameColumnDiv').addClass('contentListFocusable');
  53. }.bind(this));
  54. },
  55. getColumnSpecs: function getColumnSpecs() {
  56. return [{
  57. 'type': 'Text',
  58. 'module': 'bacontentnav/common/ui/list_columns/Text',
  59. 'showAsActiveLink': false,
  60. 'propertyName': 'display',
  61. 'sortable': false,
  62. 'scope': 'row'
  63. }, {
  64. 'type': 'ClickableIcon',
  65. 'name': 'deleteLocale',
  66. 'icon': 'common-remove-delete',
  67. 'a11yLabel': StringResource.get('deleteValue'),
  68. 'clickCallback': this._removeValue.bind(this)
  69. }];
  70. },
  71. _addValue: function _addValue() {
  72. var addParameterAction = new AddParameterAction({
  73. 'oListControl': this.listControl,
  74. 'contentView': this,
  75. 'addCallback': function (value) {
  76. if (value !== '') {
  77. var newValue = {
  78. type: 'simpleParmValueItem',
  79. use: value,
  80. display: value,
  81. inclusive: true
  82. };
  83. this._addParameterValue(newValue);
  84. }
  85. }.bind(this)
  86. });
  87. addParameterAction.execute();
  88. },
  89. _addParameterValue: function _addParameterValue(newValue) {
  90. if (!this.values) {
  91. this.values = [];
  92. }
  93. var existingItem = _.find(this.values, function (existingValue) {
  94. return existingValue.use === newValue.use;
  95. });
  96. if (!existingItem) {
  97. this.values.push(newValue);
  98. }
  99. this.updateCallback(this.values);
  100. },
  101. _removeValue: function _removeValue(toRemove) {
  102. var foundItem = _.find(this.values, function (current) {
  103. return current.use === toRemove.use;
  104. });
  105. if (foundItem) {
  106. this.values.splice(this.values.indexOf(foundItem), 1);
  107. }
  108. this.updateCallback(this.values);
  109. this.listControl.updateDatatable();
  110. }
  111. });
  112. return SetCustomParameterValues;
  113. });