From c2723e98d0d407ea43664e5fc8dafde60c17133e Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Wed, 10 Jun 2020 11:05:49 +0300 Subject: [PATCH] [SSE] Set pivot sorting --- .../main/app/view/AutoFilterDialog.js | 177 +++++++++++++++++- 1 file changed, 176 insertions(+), 1 deletion(-) diff --git a/apps/spreadsheeteditor/main/app/view/AutoFilterDialog.js b/apps/spreadsheeteditor/main/app/view/AutoFilterDialog.js index 67f5d086b..4e3e365dd 100644 --- a/apps/spreadsheeteditor/main/app/view/AutoFilterDialog.js +++ b/apps/spreadsheeteditor/main/app/view/AutoFilterDialog.js @@ -782,6 +782,160 @@ define([ }, SSE.Views.PivotDigitalFilterDialog || {})); + SSE.Views.SortFilterDialog = Common.UI.Window.extend(_.extend({ + + initialize: function (options) { + var t = this, _options = {}; + + this.type = options.type; + + _.extend(_options, { + width : 215, + height : 215, + contentWidth : 180, + header : true, + cls : 'filter-dlg', + contentTemplate : '', + title : t.txtTitle, + items : [], + buttons: ['ok', 'cancel'] + }, options); + + this.template = options.template || [ + '
', + '
', + '
', + '
', + '
', + '
', + '
', + '
', + '
' + ].join(''); + + this.api = options.api; + this.handler = options.handler; + + _options.tpl = _.template(this.template)(_options); + + Common.UI.Window.prototype.initialize.call(this, _options); + }, + render: function () { + Common.UI.Window.prototype.render.call(this); + + this.radioAsc = new Common.UI.RadioBox({ + el: $('#id-sort-filter-radio-asc'), + labelText: this.textAsc, + name: 'asc-radio-sort', + checked: true + }); + this.radioAsc.on('change', _.bind(function(field, newValue) { + newValue && this.cmbFieldsAsc.setDisabled(false); + newValue && this.cmbFieldsDesc.setDisabled(true); + }, this)); + + this.radioDesc = new Common.UI.RadioBox({ + el: $('#id-sort-filter-radio-desc'), + labelText: this.textDesc, + name: 'asc-radio-sort' + }); + this.radioDesc.on('change', _.bind(function(field, newValue) { + newValue && this.cmbFieldsAsc.setDisabled(true); + newValue && this.cmbFieldsDesc.setDisabled(false); + }, this)); + + this.cmbFieldsAsc = new Common.UI.ComboBox({ + el : $('#id-sort-filter-fields-asc', this.$window), + menuStyle : 'min-width: 100%;max-height: 135px;', + style : 'width:100%;', + cls : 'input-group-nr', + data : [], + scrollAlwaysVisible: true, + editable : false + }); + + this.cmbFieldsDesc = new Common.UI.ComboBox({ + el : $('#id-sort-filter-fields-desc', this.$window), + menuStyle : 'min-width: 100%;max-height: 135px;', + style : 'width:100%;', + cls : 'input-group-nr', + data : [], + scrollAlwaysVisible: true, + editable : false, + disabled: true + }); + + this.$window.find('.dlg-btn').on('click', _.bind(this.onBtnClick, this)); + + this.loadDefaults(); + }, + show: function () { + Common.UI.Window.prototype.show.call(this); + }, + + close: function () { + if (this.api) { + this.api.asc_enableKeyEvents(true); + } + Common.UI.Window.prototype.close.call(this); + }, + + onBtnClick: function (event) { + if (event.currentTarget.attributes && event.currentTarget.attributes.result) { + if ('ok' === event.currentTarget.attributes.result.value) { + this.save(); + } + + this.close(); + } + }, + + setSettings: function (properties) { + this.properties = properties; + }, + + loadDefaults: function () { + if (this.properties) { + var pivotObj = this.properties.asc_getPivotObj(), + idx = pivotObj.asc_getDataFieldIndexSorting(), + fields = pivotObj.asc_getDataFields(), + sort = this.properties.asc_getSortState(); + + this.setTitle(this.txtTitle + ' (' + fields[0] + ')'); + var arr = []; + fields && fields.forEach(function (item, index) { + item && arr.push({value: index, displayValue: item}); + }); + this.cmbFieldsAsc.setData(arr); + this.cmbFieldsAsc.setValue((idx>=0) ? idx : 0); + this.cmbFieldsDesc.setData(arr); + this.cmbFieldsDesc.setValue((idx>=0) ? idx : 0); + + this.radioDesc.setValue(sort == Asc.c_oAscSortOptions.Descending, true); + this.cmbFieldsDesc.setDisabled(sort !== Asc.c_oAscSortOptions.Descending); + } + }, + save: function () { + if (this.api && this.properties) { + var combo = this.radioAsc.getValue() ? this.cmbFieldsAsc : this.cmbFieldsDesc; + var pivotObj = this.properties.asc_getPivotObj(); + pivotObj.asc_setDataFieldIndexSorting(combo.getValue()); + this.properties.asc_setSortState(this.radioAsc.getValue() ? Asc.c_oAscSortOptions.Ascending : Asc.c_oAscSortOptions.Descending); + this.api.asc_applyAutoFilter(this.properties); + } + }, + + onPrimary: function() { + this.save(); + this.close(); + return false; + }, + + txtTitle: "Sort", + textAsc: 'Ascenging (A to Z) by', + textDesc: 'Descending (Z to A) by' + + }, SSE.Views.SortFilterDialog || {})); SSE.Views.AutoFilterDialog = Common.UI.Window.extend(_.extend({ @@ -884,6 +1038,11 @@ define([ }); this.miSortHigh2Low.on('click', _.bind(this.onSortType, this, Asc.c_oAscSortOptions.Descending)); + this.miSortOptions = new Common.UI.MenuItem({ + caption : this.txtSortOption + }); + this.miSortOptions.on('click', _.bind(this.onSortOptions, this)); + this.miSortCellColor = new Common.UI.MenuItem({ caption : this.txtSortCellColor, toggleGroup : 'menufiltersort', @@ -1059,6 +1218,7 @@ define([ items: [ this.miSortLow2High, this.miSortHigh2Low, + this.miSortOptions, this.miSortCellColor, this.miSortFontColor, {caption : '--'}, @@ -1219,6 +1379,19 @@ define([ this.close(); }, + onSortOptions: function () { + var me = this, + dlgSort = new SSE.Views.SortFilterDialog({api:this.api}).on({ + 'close': function() { + me.close(); + } + }); + this.close(); + + dlgSort.setSettings(this.configTo); + dlgSort.show(); + }, + onNumCustomFilterItemClick: function(item) { var filterObj = this.configTo.asc_getFilterObj(), value1 = '', value2 = '', @@ -1533,6 +1706,7 @@ define([ this.miValueFilter.setVisible(isPivot); this.miLabelFilter.setVisible(isPivot); + this.miSortOptions.setVisible(isPivot); if (isPivot) { if (pivotObj.asc_getIsPageFilter()) { @@ -1895,7 +2069,8 @@ define([ txtValueFilter: 'Value filter', txtLabelFilter: 'Label filter', warnFilterError: 'You need at least one field in the Values area in order to apply a value filter.', - txtNotBetween: 'Not between...' + txtNotBetween: 'Not between...', + txtSortOption: 'More sort options...' }, SSE.Views.AutoFilterDialog || {})); }); \ No newline at end of file