123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- 'use strict';
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2016, 2017
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['../../lib/@waca/core-client/js/core-client/ui/AccessibleView', '../../util/DashboardFormatter', '../../lib/@waca/dashboard-common/dist/ui/Slider', '../../widgets/livewidget/nls/StringResources', 'text!./templates/BasePromptView.html', 'text!./templates/RangePromptViewContent.html', 'jquery', 'underscore', 'doT'], function (View, Formatter, RangeSlider, stringResources, BasePromptViewTemplate, RangePromptViewContent, $, _, dot) {
- 'use strict';
- var RangePromptView = View.extend({
- events: {
- 'primaryaction .tooltip-inner': '_enableOk',
- 'primaryaction .postAggregate': '_onAggregateTypeChange',
- 'primaryaction .preAggregate': '_onAggregateTypeChange'
- },
- init: function init(options) {
- options.height = '150px';
- options.width = '500px';
- RangePromptView.inherited('init', this, arguments);
- _.extend(this, options);
- _.defaults(options, {
- style: 'dual',
- sliderId: 'slider_filter'
- });
- this.minimized = options.minimized;
- this.enabled = options.enabled;
- this.sliderStyle = options.style;
- this.sliderId = options.sliderId;
- this.postAutoAggregation = options.postAutoAggregation;
- // Used to preserve saved prompt values at re-prompt, and while the aggregation type is changed.
- this._initialDefault = {
- 'postAggregate': this.postAutoAggregation,
- 'defaultValues': this.defaultValues
- };
- },
- render: function render() {
- var sBasePromptViewHtml = dot.template(BasePromptViewTemplate)({
- promptModuleName: this.promptModuleName,
- postAggregate: this.postAutoAggregation,
- isMultiPrompt: this.isMultiPrompt,
- preAggregateLabel: stringResources.get('preAggregateLabel'),
- postAggregateLabel: stringResources.get('postAggregateLabel'),
- preAggregateText: stringResources.get('preAggregateText')
- });
- this.$el.addClass('promptDialogContainer rangeDialog').height(this.height).width(this.width).append(sBasePromptViewHtml);
- this.$el.attr('role', 'region');
- this.$el.attr('aria-label', this.viewTitle);
- this.$postAggregateNode = this.$el.find('.postAggregate svg');
- this.$preAggregateNode = this.$el.find('.preAggregate svg');
- this.$content = this.$('.content');
- this.$content.html(RangePromptViewContent);
- // Search Field
- this.$('.search').attr('placeholder', stringResources.get('search')).attr('aria-label', stringResources.get('search'));
- this.$('.clearCaption').text(stringResources.get('clearTextFilterValue'));
- this.$('.rowButton.invertButton').text(stringResources.get('invertFilterSelection'));
- // Content
- return this._populateContent();
- },
- _populateContent: function _populateContent() {
- var _this = this;
- this._slideContent = this.$('.sliderContent');
- this._slideContent.empty();
- if (!this.minimized) {
- this._showLoading();
- }
- return this._updateMinMax().then(function () {
- return _this._renderSlider();
- });
- },
- setFocus: function setFocus() {
- if (this._rangeSlider) {
- this._rangeSlider.setFocus();
- }
- },
- _renderSlider: function _renderSlider() {
- // Remove everything from slider content, including the loading indicator.
- this._slideContent.empty();
- this.trigger('change:state', {
- state: 'loaded'
- });
- var min = this.minMax[0].u;
- var max = this.minMax[1].u;
- var value = [min, max];
- var model = {
- el: this._slideContent,
- sliderId: this.sliderId,
- min: min,
- max: max,
- value: value,
- showMinMax: false,
- inverted: false,
- minimized: this.minimized,
- enabled: this.enabled,
- style: this.sliderStyle,
- prettyValue: this._formatValues.bind({
- category: this.category
- })
- };
- if (!this.minimized) {
- model.tooltipTemplate = ['<span>≥</span><input aria-label="≥" type="text"></input>', '<span>≤</span><input aria-label="≤" type="text"></input>'];
- model.invertedTooltipTemplate = ['<span><</span><input aria-label="<" type="text"></input>', '<span>></span><input aria-label =">" type="text"></input>'];
- }
- if (this.defaultValues) {
- model.value = [this.defaultValues[0].d, this.defaultValues[1].d];
- }
- this._rangeSlider = new RangeSlider(model);
- this._rangeSlider.on('action:slidestop', function () {
- this.trigger('action:slidestop');
- }.bind(this));
- this._rangeSlider.on('action:change', function () {
- this._enableOk();
- }.bind(this));
- return this._rangeSlider.render();
- },
- _showLoading: function _showLoading() {
- this.trigger('change:state', {
- state: 'loading'
- });
- var indicator = $('<div></div>');
- indicator.addClass('loading');
- indicator.text(stringResources.get('modellingLoading'));
- // Remove everything, including the slider.
- this._slideContent.html(indicator);
- },
- _updateMinMax: function _updateMinMax() {
- var _this2 = this;
- var result = void 0;
- // Request the min and max.
- if (this.whenColumnsMinMaxQueryReady) {
- result = Promise.resolve().then(function () {
- return _this2.whenColumnsMinMaxQueryReady({
- column: {
- columnId: _this2.columnId
- },
- nativeQuery: true,
- promptName: _this2.name
- }).then(function (result) {
- var minValue = result.getCellValue(0, 0);
- var maxValue = result.getCellValue(0, 1);
- _this2.minMax = [minValue, maxValue];
- return _this2.minMax;
- });
- });
- } else {
- result = Promise.resolve();
- }
- return result;
- },
- getPromptValues: function getPromptValues() {
- return this._rangeSlider.getValue();
- },
- getAdditionalOptions: function getAdditionalOptions() {
- return {
- postAutoAggregation: this.postAutoAggregation
- };
- },
- _formatValues: function _formatValues(values) {
- var ret = [];
- var spec = {
- type: 'number'
- };
- if (this.category === 'time') {
- spec.useGrouping = false;
- }
- _.each(values, function (val) {
- ret.push(Formatter.format(val, spec));
- });
- return ret;
- },
- _enableOk: function _enableOk() {
- if (this.enableOk) {
- this.enableOk(true);
- }
- },
- _onAggregateTypeChange: function _onAggregateTypeChange(event) {
- this._onClickRadioButton(event);
- return this._populateContent();
- },
- _onClickRadioButton: function _onClickRadioButton(event) {
- this.postAutoAggregation = $(event.currentTarget).hasClass('postAggregate');
- if (this.postAutoAggregation) {
- this.$postAggregateNode.attr('class', 'checked');
- this.$preAggregateNode.attr('class', '');
- if (this._initialDefault.postAggregate) {
- this.defaultValues = this._initialDefault.defaultValues;
- } else {
- this.defaultValues = null;
- }
- } else {
- this.$postAggregateNode.attr('class', '');
- this.$preAggregateNode.attr('class', 'checked');
- if (this._initialDefault.postAggregate) {
- this.defaultValues = null;
- } else {
- this.defaultValues = this._initialDefault.defaultValues;
- }
- }
- }
- });
- return RangePromptView;
- });
- //# sourceMappingURL=RangePromptView.js.map
|