web-apps/apps/spreadsheeteditor/main/app/view/PivotTable.js

475 lines
23 KiB
JavaScript
Raw Normal View History

2017-06-30 14:49:58 +00:00
/*
*
* (c) Copyright Ascensio System SIA 2010-2019
2017-06-30 14:49:58 +00:00
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
2017-06-30 14:49:58 +00:00
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
/**
* PivotTable.js
*
* View
*
* Created by Julia.Radzhabova on 06.27.17
2018-03-01 12:16:38 +00:00
* Copyright (c) 2018 Ascensio System SIA. All rights reserved.
2017-06-30 14:49:58 +00:00
*
*/
define([
// 'text!spreadsheeteditor/main/app/template/PivotTableSettings.template',
'common/main/lib/util/utils',
'common/main/lib/component/Button',
'common/main/lib/component/ComboDataView',
'common/main/lib/component/Layout'
], function (menuTemplate) {
'use strict';
SSE.Views.PivotTable = Common.UI.BaseView.extend(_.extend((function(){
var template =
'<section id="pivot-table-panel" class="panel" data-tab="pivot">' +
'<div class="group">' +
'<span class="btn-slot text x-huge slot-add-pivot"></span>' +
'</div>' +
2020-06-05 13:10:48 +00:00
'<div class="separator long"></div>' +
'<div class="group">' +
'<span id="slot-btn-pivot-report-layout" class="btn-slot text x-huge"></span>' +
'<span id="slot-btn-pivot-blank-rows" class="btn-slot text x-huge"></span>' +
'<span id="slot-btn-pivot-subtotals" class="btn-slot text x-huge"></span>' +
'<span id="slot-btn-pivot-grand-totals" class="btn-slot text x-huge"></span>' +
'</div>' +
2020-06-05 13:10:48 +00:00
'<div class="separator long"></div>' +
'<div class="group">' +
'<span id="slot-btn-refresh-pivot" class="btn-slot text x-huge"></span>' +
'</div>' +
2020-06-05 13:10:48 +00:00
'<div class="separator long"></div>' +
'<div class="group">' +
'<span id="slot-btn-select-pivot" class="btn-slot text x-huge"></span>' +
'</div>' +
2020-06-05 13:10:48 +00:00
'<div class="separator long"></div>' +
2021-04-27 18:21:11 +00:00
'<div class="group small">' +
2017-06-30 14:49:58 +00:00
'<div class="elset">' +
'<span class="btn-slot text" id="slot-chk-header-row"></span>' +
'</div>' +
'<div class="elset">' +
'<span class="btn-slot text" id="slot-chk-header-column"></span>' +
'</div>' +
'</div>' +
2022-07-13 19:47:33 +00:00
'<div class="separator long invisible"></div>' +
2021-04-27 18:21:11 +00:00
'<div class="group small">' +
2017-06-30 14:49:58 +00:00
'<div class="elset">' +
'<span class="btn-slot text" id="slot-chk-banded-row"></span>' +
'</div>' +
'<div class="elset">' +
'<span class="btn-slot text" id="slot-chk-banded-column"></span>' +
'</div>' +
'</div>' +
2022-07-13 19:47:33 +00:00
'<div class="separator long invisible"></div>' +
'<div class="group flex small" id="slot-field-pivot-styles" style="width: 100%; min-width: 105px;" data-group-width="100%">' +
2017-06-30 14:49:58 +00:00
'</div>' +
'</section>';
function setEvents() {
var me = this;
this.btnsAddPivot.forEach(function(button) {
button.on('click', function (b, e) {
me.fireEvent('pivottable:create');
});
2017-06-30 14:49:58 +00:00
});
2017-07-17 10:17:30 +00:00
this.btnPivotLayout.menu.on('item:click', function (menu, item, e) {
me.fireEvent('pivottable:layout', [item.value]);
});
this.btnPivotBlankRows.menu.on('item:click', function (menu, item, e) {
me.fireEvent('pivottable:blankrows', [item.value]);
});
this.btnPivotSubtotals.menu.on('item:click', function (menu, item, e) {
me.fireEvent('pivottable:subtotals', [item.value]);
});
this.btnPivotGrandTotals.menu.on('item:click', function (menu, item, e) {
me.fireEvent('pivottable:grandtotals', [item.value]);
});
2017-07-18 08:57:14 +00:00
this.btnRefreshPivot.on('click', function (e) {
me.fireEvent('pivottable:refresh', ['current']);
});
this.btnRefreshPivot.menu.on('item:click', function (menu, item, e) {
me.fireEvent('pivottable:refresh', [item.value]);
2017-07-18 08:57:14 +00:00
});
this.btnSelectPivot.on('click', function (e) {
me.fireEvent('pivottable:select');
});
2017-06-30 14:49:58 +00:00
this.chRowHeader.on('change', function (field, value) {
me.fireEvent('pivottable:rowscolumns', [0, value]);
});
this.chColHeader.on('change', function (field, value) {
me.fireEvent('pivottable:rowscolumns', [1, value]);
});
this.chRowBanded.on('change', function (field, value) {
me.fireEvent('pivottable:rowscolumns', [2, value]);
});
this.chColBanded.on('change', function (field, value) {
me.fireEvent('pivottable:rowscolumns', [3, value]);
});
this.pivotStyles.on('click', function (combo, record) {
me.fireEvent('pivottable:style', [record]);
});
this.pivotStyles.openButton.menu.on('show:after', function () {
me.pivotStyles.menuPicker.scroller.update({alwaysVisibleY: true});
});
}
return {
options: {},
initialize: function (options) {
Common.UI.BaseView.prototype.initialize.call(this, options);
this.toolbar = options.toolbar;
2017-06-30 14:49:58 +00:00
this.lockedControls = [];
2021-12-29 16:41:15 +00:00
var _set = Common.enumLock;
this.btnsAddPivot = Common.Utils.injectButtons(this.toolbar.$el.find('.btn-slot.slot-add-pivot'), '', 'toolbar__icon btn-pivot-sum', this.txtPivotTable,
[_set.lostConnect, _set.coAuth, _set.editPivot, _set.selRangeEdit, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.selSlicer, _set.editCell, _set.wsLock], undefined, undefined, undefined, '1', 'bottom', 'small');
2017-06-30 14:49:58 +00:00
this.chRowHeader = new Common.UI.CheckBox({
labelText: this.textRowHeader,
lock : [_set.lostConnect, _set.coAuth, _set.noPivot, _set.selRangeEdit, _set.pivotLock, _set['FormatCells'], _set['PivotTables']],
dataHint : '1',
dataHintDirection: 'left',
dataHintOffset: 'small'
2017-06-30 14:49:58 +00:00
});
this.lockedControls.push(this.chRowHeader);
this.chColHeader = new Common.UI.CheckBox({
labelText: this.textColHeader,
lock : [_set.lostConnect, _set.coAuth, _set.noPivot, _set.selRangeEdit, _set.pivotLock, _set['FormatCells'], _set['PivotTables']],
dataHint : '1',
dataHintDirection: 'left',
dataHintOffset: 'small'
2017-06-30 14:49:58 +00:00
});
this.lockedControls.push(this.chColHeader);
this.chRowBanded = new Common.UI.CheckBox({
labelText: this.textRowBanded,
lock : [_set.lostConnect, _set.coAuth, _set.noPivot, _set.selRangeEdit, _set.pivotLock, _set['FormatCells'], _set['PivotTables']],
dataHint : '1',
dataHintDirection: 'left',
dataHintOffset: 'small'
2017-06-30 14:49:58 +00:00
});
this.lockedControls.push(this.chRowBanded);
this.chColBanded = new Common.UI.CheckBox({
labelText: this.textColBanded,
lock : [_set.lostConnect, _set.coAuth, _set.noPivot, _set.selRangeEdit, _set.pivotLock, _set['FormatCells'], _set['PivotTables']],
dataHint : '1',
dataHintDirection: 'left',
dataHintOffset: 'small'
2017-06-30 14:49:58 +00:00
});
this.lockedControls.push(this.chColBanded);
2017-07-17 10:17:30 +00:00
this.btnPivotLayout = new Common.UI.Button({
cls : 'btn-toolbar x-huge icon-top',
iconCls : 'toolbar__icon btn-pivot-layout',
2017-07-17 10:17:30 +00:00
caption : this.capLayout,
disabled : true,
2021-07-16 21:49:36 +00:00
lock : [_set.lostConnect, _set.coAuth, _set.noPivot, _set.selRangeEdit, _set.pivotLock, _set.wsLock],
menu : true,
dataHint : '1',
dataHintDirection: 'bottom',
dataHintOffset: 'small'
2017-07-17 10:17:30 +00:00
});
this.lockedControls.push(this.btnPivotLayout);
2017-07-17 10:17:30 +00:00
this.btnPivotBlankRows = new Common.UI.Button({
cls : 'btn-toolbar x-huge icon-top',
iconCls : 'toolbar__icon btn-blank-rows',
2017-07-17 10:17:30 +00:00
caption : this.capBlankRows,
disabled : true,
2021-07-16 21:49:36 +00:00
lock : [_set.lostConnect, _set.coAuth, _set.noPivot, _set.selRangeEdit, _set.pivotLock, _set.wsLock],
menu : true,
dataHint : '1',
dataHintDirection: 'bottom',
dataHintOffset: 'small'
2017-07-17 10:17:30 +00:00
});
this.lockedControls.push(this.btnPivotBlankRows);
2017-07-17 10:17:30 +00:00
this.btnPivotSubtotals = new Common.UI.Button({
cls : 'btn-toolbar x-huge icon-top',
iconCls : 'toolbar__icon btn-subtotals',
2017-07-17 10:17:30 +00:00
caption : this.capSubtotals,
disabled : true,
2021-07-16 21:49:36 +00:00
lock : [_set.lostConnect, _set.coAuth, _set.noPivot, _set.selRangeEdit, _set.pivotLock, _set.wsLock],
menu : true,
dataHint : '1',
dataHintDirection: 'bottom',
dataHintOffset: 'small'
2017-07-17 10:17:30 +00:00
});
this.lockedControls.push(this.btnPivotSubtotals);
2017-07-17 10:17:30 +00:00
this.btnPivotGrandTotals = new Common.UI.Button({
cls : 'btn-toolbar x-huge icon-top',
iconCls : 'toolbar__icon btn-grand-totals',
2017-07-17 10:17:30 +00:00
caption : this.capGrandTotals,
disabled : true,
2021-07-16 21:49:36 +00:00
lock : [_set.lostConnect, _set.coAuth, _set.noPivot, _set.selRangeEdit, _set.pivotLock, _set.wsLock],
menu : true,
dataHint : '1',
dataHintDirection: 'bottom',
dataHintOffset: 'small'
2017-07-17 10:17:30 +00:00
});
this.lockedControls.push(this.btnPivotGrandTotals);
2017-07-17 10:17:30 +00:00
2017-07-18 08:57:14 +00:00
this.btnRefreshPivot = new Common.UI.Button({
cls: 'btn-toolbar x-huge icon-top',
2020-04-21 17:35:58 +00:00
iconCls: 'toolbar__icon btn-update',
caption: this.txtRefresh,
disabled : true,
split : true,
lock : [_set.lostConnect, _set.coAuth, _set.noPivot, _set.selRangeEdit, _set.pivotLock, _set.wsLock],
dataHint : '1',
dataHintDirection: 'bottom',
dataHintOffset: 'small'
2017-07-18 08:57:14 +00:00
});
this.lockedControls.push(this.btnRefreshPivot);
2017-07-18 08:57:14 +00:00
this.btnSelectPivot = new Common.UI.Button({
cls: 'btn-toolbar x-huge icon-top',
iconCls: 'toolbar__icon btn-select-pivot',
caption: this.txtSelect,
lock: [_set.lostConnect, _set.coAuth, _set.noPivot, _set.selRangeEdit, _set['PivotTables']],
dataHint: '1',
dataHintDirection: 'bottom',
dataHintOffset: 'small'
});
this.lockedControls.push(this.btnSelectPivot);
2017-06-30 14:49:58 +00:00
this.pivotStyles = new Common.UI.ComboDataView({
cls : 'combo-pivot-template',
style : 'min-width: 103px; max-width: 517px;',
2017-06-30 14:49:58 +00:00
enableKeyEvents : true,
itemWidth : 61,
itemHeight : 49,
menuMaxHeight : 300,
2022-07-30 11:04:45 +00:00
groups : new Common.UI.DataViewGroupStore(),
autoWidth : true,
2021-07-16 21:49:36 +00:00
lock : [_set.lostConnect, _set.coAuth, _set.noPivot, _set.selRangeEdit, _set.pivotLock, _set['FormatCells'], _set['PivotTables']],
2020-04-13 17:12:50 +00:00
beforeOpenHandler: function(e) {
var cmp = this,
2022-07-13 18:35:11 +00:00
menu = cmp.openButton.menu,
columnCount = 7;
2022-07-13 18:35:11 +00:00
2020-04-13 17:12:50 +00:00
if (menu.cmpEl) {
2022-07-13 18:35:11 +00:00
var itemEl = $(cmp.cmpEl.find('.dataview.inner .style').get(0)).parent();
var itemMargin = 8;
var itemWidth = itemEl.is(':visible') ? parseFloat(itemEl.css('width')) :
(cmp.itemWidth + parseFloat(itemEl.css('padding-left')) + parseFloat(itemEl.css('padding-right')) +
parseFloat(itemEl.css('border-left-width')) + parseFloat(itemEl.css('border-right-width')));
menu.menuAlignEl = cmp.cmpEl;
menu.menuAlign = 'tl-tl';
var menuWidth = columnCount * (itemMargin + itemWidth) + 17, // for scroller
buttonOffsetLeft = cmp.openButton.$el.offset().left;
if (menuWidth>Common.Utils.innerWidth())
menuWidth = Math.max(Math.floor((Common.Utils.innerWidth()-17)/(itemMargin + itemWidth)), 2) * (itemMargin + itemWidth) + 17;
var offset = cmp.cmpEl.width() - cmp.openButton.$el.width() - Math.min(menuWidth, buttonOffsetLeft) - 1;
2020-04-13 17:12:50 +00:00
menu.setOffset(Math.min(offset, 0));
2022-07-13 18:35:11 +00:00
menu.cmpEl.css({
'width': menuWidth,
'min-height': cmp.cmpEl.height()
});
2020-04-13 17:12:50 +00:00
}
},
dataHint: '1',
dataHintDirection: 'bottom',
dataHintOffset: '-16, 0'
2017-06-30 14:49:58 +00:00
});
this.lockedControls.push(this.pivotStyles);
Common.NotificationCenter.on('app:ready', this.onAppReady.bind(this));
},
render: function (el) {
this.boxSdk = $('#editor_sdk');
if ( el ) el.html( this.getPanel() );
return this;
},
onAppReady: function (config) {
var me = this;
(new Promise(function (accept, reject) {
accept();
})).then(function(){
me.btnsAddPivot.forEach( function(btn) {
btn.updateHint(me.tipCreatePivot);
});
me.btnSelectPivot.updateHint(me.tipSelect);
2017-07-17 10:17:30 +00:00
me.btnPivotLayout.updateHint(me.capLayout);
2019-10-04 15:01:56 +00:00
me.btnPivotLayout.setMenu(new Common.UI.Menu({
items: [
{ caption: me.mniLayoutCompact, value: 0 },
{ caption: me.mniLayoutOutline, value: 1 },
{ caption: me.mniLayoutTabular, value: 2 },
{ caption: '--' },
{ caption: me.mniLayoutRepeat, value: 3 },
{ caption: me.mniLayoutNoRepeat, value: 4 }
]
}));
2017-07-17 10:17:30 +00:00
me.btnPivotBlankRows.updateHint(me.capBlankRows);
2019-10-04 15:01:56 +00:00
me.btnPivotBlankRows.setMenu( new Common.UI.Menu({
items: [
{ caption: me.mniInsertBlankLine, value: 'insert' },
{ caption: me.mniRemoveBlankLine, value: 'remove' }
]
}));
2017-07-18 08:57:14 +00:00
me.btnPivotSubtotals.updateHint(me.tipSubtotals);
2019-10-04 15:01:56 +00:00
me.btnPivotSubtotals.setMenu(new Common.UI.Menu({
items: [
{ caption: me.mniNoSubtotals, value: 0 },
{ caption: me.mniBottomSubtotals, value: 1 },
{ caption: me.mniTopSubtotals, value: 2 }
]
}));
2017-07-18 08:57:14 +00:00
me.btnPivotGrandTotals.updateHint(me.tipGrandTotals);
2019-10-04 15:01:56 +00:00
me.btnPivotGrandTotals.setMenu(new Common.UI.Menu({
items: [
{ caption: me.mniOffTotals, value: 0 },
{ caption: me.mniOnTotals, value: 1 },
{ caption: me.mniOnRowsTotals, value: 2 },
{ caption: me.mniOnColumnsTotals, value: 3 }
]
}));
2017-06-30 14:49:58 +00:00
me.btnRefreshPivot.setMenu(new Common.UI.Menu({
items: [
{ caption: me.txtRefresh, value: 'current'},
{ caption: me.txtRefreshAll, value: 'all'}
]
}));
me.btnRefreshPivot.updateHint([me.tipRefreshCurrent, me.tipRefresh]);
2017-06-30 14:49:58 +00:00
setEvents.call(me);
});
},
getPanel: function () {
this.$el = $(_.template(template)( {} ));
2021-12-29 16:41:15 +00:00
var _set = Common.enumLock;
this.btnsAddPivot = this.btnsAddPivot.concat(Common.Utils.injectButtons(this.$el.find('.btn-slot.slot-add-pivot'), '', 'toolbar__icon btn-pivot-sum', this.txtCreate,
[_set.lostConnect, _set.coAuth, _set.editPivot, _set.selRangeEdit, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.selSlicer, _set.editCell, _set.wsLock], undefined, undefined, undefined, '1', 'bottom', 'small'));
2017-06-30 14:49:58 +00:00
this.chRowHeader.render(this.$el.find('#slot-chk-header-row'));
this.chColHeader.render(this.$el.find('#slot-chk-header-column'));
this.chRowBanded.render(this.$el.find('#slot-chk-banded-row'));
this.chColBanded.render(this.$el.find('#slot-chk-banded-column'));
2017-07-18 08:57:14 +00:00
this.btnRefreshPivot.render(this.$el.find('#slot-btn-refresh-pivot'));
this.btnSelectPivot.render(this.$el.find('#slot-btn-select-pivot'));
2017-07-17 10:17:30 +00:00
this.btnPivotLayout.render(this.$el.find('#slot-btn-pivot-report-layout'));
this.btnPivotBlankRows.render(this.$el.find('#slot-btn-pivot-blank-rows'));
this.btnPivotSubtotals.render(this.$el.find('#slot-btn-pivot-subtotals'));
this.btnPivotGrandTotals.render(this.$el.find('#slot-btn-pivot-grand-totals'));
2017-06-30 14:49:58 +00:00
this.pivotStyles.render(this.$el.find('#slot-field-pivot-styles'));
return this.$el;
},
show: function () {
Common.UI.BaseView.prototype.show.call(this);
this.fireEvent('show', this);
},
getButtons: function(type) {
return this.btnsAddPivot.concat(this.lockedControls);
2017-06-30 14:49:58 +00:00
},
SetDisabled: function (state) {
this.btnsAddPivot.concat(this.lockedControls).forEach(function(button) {
2017-06-30 14:49:58 +00:00
if ( button ) {
button.setDisabled(state);
}
}, this);
},
txtCreate: 'Insert Table',
tipCreatePivot: 'Insert Pivot Table',
textRowHeader: 'Row Headers',
textColHeader: 'Column Headers',
textRowBanded: 'Banded Rows',
2017-07-17 10:17:30 +00:00
textColBanded: 'Banded Columns',
capBlankRows: 'Blank Rows',
mniInsertBlankLine: 'Insert Blank Line after Each Item',
mniRemoveBlankLine: 'Remove Blank Line after Each Item',
capGrandTotals: 'Grand Totals',
mniOffTotals: 'Off for Rows and Columns',
mniOnTotals: 'On for Rows and Columns',
mniOnRowsTotals: 'On for Rows Only',
mniOnColumnsTotals: 'On for Columns Only',
capLayout: 'Report Layout',
capSubtotals: 'Subtotals',
mniLayoutCompact: 'Show in Compact Form',
mniLayoutOutline: 'Show in Outline Form',
mniLayoutTabular: 'Show in Tabular Form',
mniLayoutRepeat: 'Repeat All Item Labels',
mniLayoutNoRepeat: 'Don\'t Repeat All Item Labels',
mniNoSubtotals: 'Don\'t Show Subtotals',
mniBottomSubtotals: 'Show all Subtotals at Bottom of Group',
2017-07-18 08:57:14 +00:00
mniTopSubtotals: 'Show all Subtotals at Top of Group',
txtRefresh: 'Refresh',
txtRefreshAll: 'Refresh All',
tipRefreshCurrent: 'Update the information from data source for the current table',
2017-07-18 08:57:14 +00:00
tipRefresh: 'Update the information from data source',
tipGrandTotals: 'Show or hide grand totals',
tipSubtotals: 'Show or hide subtotals',
txtSelect: 'Select',
tipSelect: 'Select entire pivot table',
2022-07-30 11:04:45 +00:00
txtPivotTable: 'Pivot Table',
txtTable_PivotStyleMedium: 'Pivot Table Style Medium',
txtTable_PivotStyleDark: 'Pivot Table Style Dark',
txtTable_PivotStyleLight: 'Pivot Table Style Light',
txtGroupPivot_Custom: 'Custom',
txtGroupPivot_Light: 'Light',
txtGroupPivot_Medium: 'Medium',
txtGroupPivot_Dark: 'Dark'
2017-06-30 14:49:58 +00:00
}
}()), SSE.Views.PivotTable || {}));
});