/** * 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; });