123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: Cognos Analytics
- * Copyright IBM Corp. 2015, 2017
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- 'use strict'; //NOSONAR
- 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) {
- var SetCustomParameterValues = View.extend({
- init: function init(options) {
- SetCustomParameterValues.inherited('init', this, arguments);
- _.extend(this, options);
- },
- render: function render() {
- this.$el.empty();
- this.$el.addClass('gp-define-parameters-container');
- var sHtml = doT.template(ParametersTabTemplate)({
- 'isSlideout': this.isSlideout,
- 'newText': StringResource.get('new'),
- 'newButtonId': 'admin-add-parm-value',
- 'title': StringResource.get('setValues')
- });
- this.$el.html(sHtml);
- $('#admin-add-parm-value').on('primaryaction', this._addValue.bind(this));
- return this._renderListControl();
- },
- _renderListControl: function _renderListControl() {
- if (this.listControl) {
- this.listControl.remove();
- }
- var $container = this.$el.find('.ca-listContainer');
- this.listControl = new ListControl({
- contentView: this,
- columns: this.getColumnSpecs(),
- el: $container,
- showEmptyNewFolderButton: false,
- emptyFolderString: StringResource.get('noGlobalParameterValues'),
- accessibleLabel: StringResource.get('viewGlobalParameters'),
- disableColumnHeaders: true,
- glassContext: this.glassContext,
- getJSONDataCallback: function () {
- return Promise.resolve({
- data: this.values
- });
- }.bind(this)
- });
- return this.listControl.render().then(function () {
- this.listControl.widgetKeyController = new WidgetNavigator({
- $el: this.listControl.$el.find('.listControl'),
- focusClass: 'contentListFocusable'
- });
- this.$el.find('.nameColumnDiv').addClass('contentListFocusable');
- }.bind(this));
- },
- getColumnSpecs: function getColumnSpecs() {
- return [{
- 'type': 'Text',
- 'module': 'bacontentnav/common/ui/list_columns/Text',
- 'showAsActiveLink': false,
- 'propertyName': 'display',
- 'sortable': false,
- 'scope': 'row'
- }, {
- 'type': 'ClickableIcon',
- 'name': 'deleteLocale',
- 'icon': 'common-remove-delete',
- 'a11yLabel': StringResource.get('deleteValue'),
- 'clickCallback': this._removeValue.bind(this)
- }];
- },
- _addValue: function _addValue() {
- var addParameterAction = new AddParameterAction({
- 'oListControl': this.listControl,
- 'contentView': this,
- 'addCallback': function (value) {
- if (value !== '') {
- var newValue = {
- type: 'simpleParmValueItem',
- use: value,
- display: value,
- inclusive: true
- };
- this._addParameterValue(newValue);
- }
- }.bind(this)
- });
- addParameterAction.execute();
- },
- _addParameterValue: function _addParameterValue(newValue) {
- if (!this.values) {
- this.values = [];
- }
- var existingItem = _.find(this.values, function (existingValue) {
- return existingValue.use === newValue.use;
- });
- if (!existingItem) {
- this.values.push(newValue);
- }
- this.updateCallback(this.values);
- },
- _removeValue: function _removeValue(toRemove) {
- var foundItem = _.find(this.values, function (current) {
- return current.use === toRemove.use;
- });
- if (foundItem) {
- this.values.splice(this.values.indexOf(foundItem), 1);
- }
- this.updateCallback(this.values);
- this.listControl.updateDatatable();
- }
- });
- return SetCustomParameterValues;
- });
|