2017-06-30 14:49:58 +00:00
|
|
|
/*
|
|
|
|
*
|
2019-01-17 13:05:03 +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
|
|
|
|
*
|
2019-01-17 13:00:34 +00:00
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* 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([
|
|
|
|
'core',
|
2019-10-04 11:44:42 +00:00
|
|
|
'spreadsheeteditor/main/app/view/PivotTable',
|
|
|
|
'spreadsheeteditor/main/app/view/CreatePivotDialog'
|
2017-06-30 14:49:58 +00:00
|
|
|
], function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
SSE.Controllers.PivotTable = Backbone.Controller.extend(_.extend({
|
|
|
|
models : [],
|
|
|
|
views : [
|
|
|
|
'PivotTable'
|
|
|
|
],
|
|
|
|
sdkViewName : '#id_main',
|
|
|
|
|
|
|
|
initialize: function () {
|
|
|
|
|
|
|
|
this.addListeners({
|
|
|
|
'PivotTable': {
|
|
|
|
// comments handlers
|
|
|
|
'pivottable:rowscolumns': _.bind(this.onCheckTemplateChange, this),
|
|
|
|
'pivottable:create': _.bind(this.onCreateClick, this),
|
2017-07-18 08:57:14 +00:00
|
|
|
'pivottable:refresh': _.bind(this.onRefreshClick, this),
|
2018-02-05 12:13:43 +00:00
|
|
|
'pivottable:select': _.bind(this.onSelectClick, this),
|
2017-07-17 10:17:30 +00:00
|
|
|
'pivottable:style': _.bind(this.onPivotStyleSelect, this),
|
|
|
|
'pivottable:layout': _.bind(this.onPivotLayout, this),
|
|
|
|
'pivottable:blankrows': _.bind(this.onPivotBlankRows, this),
|
|
|
|
'pivottable:subtotals': _.bind(this.onPivotSubtotals, this),
|
|
|
|
'pivottable:grandtotals': _.bind(this.onPivotGrandTotals, this)
|
2017-06-30 14:49:58 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onLaunch: function () {
|
|
|
|
this._state = {
|
|
|
|
TableName: '',
|
|
|
|
TemplateName: '',
|
|
|
|
RowHeader: undefined,
|
|
|
|
RowBanded: undefined,
|
|
|
|
ColHeader: undefined,
|
|
|
|
ColBanded: undefined,
|
|
|
|
DisabledControls: false
|
|
|
|
};
|
|
|
|
this._originalProps = null;
|
|
|
|
|
|
|
|
Common.NotificationCenter.on('app:ready', this.onAppReady.bind(this));
|
|
|
|
Common.NotificationCenter.on('api:disconnect', _.bind(this.SetDisabled, this));
|
|
|
|
},
|
|
|
|
|
|
|
|
setConfig: function (data, api) {
|
2019-10-04 15:01:56 +00:00
|
|
|
this.view = this.createView('PivotTable');
|
2017-06-30 14:49:58 +00:00
|
|
|
this.setApi(api);
|
|
|
|
if (data) {
|
|
|
|
this.sdkViewName = data['sdkviewname'] || this.sdkViewName;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setApi: function (api) {
|
|
|
|
if (api) {
|
|
|
|
this.api = api;
|
|
|
|
this.api.asc_registerCallback('asc_onCoAuthoringDisconnect',_.bind(this.SetDisabled, this));
|
2019-10-04 13:17:05 +00:00
|
|
|
Common.NotificationCenter.on('api:disconnect', _.bind(this.SetDisabled, this));
|
2017-06-30 14:49:58 +00:00
|
|
|
this.api.asc_registerCallback('asc_onSendThemeColors', _.bind(this.onSendThemeColors, this));
|
|
|
|
this.api.asc_registerCallback('asc_onSelectionChanged', _.bind(this.onSelectionChanged, this));
|
2019-10-04 13:17:05 +00:00
|
|
|
Common.NotificationCenter.on('cells:range', _.bind(this.onCellsRange, this));
|
2017-06-30 14:49:58 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setMode: function(mode) {
|
|
|
|
this.appConfig = mode;
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
SetDisabled: function() {
|
|
|
|
this.view && this.view.SetDisabled(true);
|
|
|
|
},
|
|
|
|
|
|
|
|
// helpers
|
|
|
|
|
|
|
|
onCheckTemplateChange: function(type, value) {
|
|
|
|
// this._state[stateName] = undefined;
|
|
|
|
// if (this.api)
|
|
|
|
// this.api.asc_changeFormatTableInfo(this._state.TableName, type, value=='checked');
|
|
|
|
// for test
|
|
|
|
switch (type) {
|
|
|
|
case 0:
|
2017-07-14 08:00:56 +00:00
|
|
|
this._originalProps.asc_getStyleInfo().asc_setShowRowHeaders(this.api, this._originalProps, value=='checked');
|
2017-06-30 14:49:58 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2017-07-14 08:00:56 +00:00
|
|
|
this._originalProps.asc_getStyleInfo().asc_setShowColHeaders(this.api, this._originalProps, value=='checked');
|
2017-06-30 14:49:58 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2017-07-14 08:00:56 +00:00
|
|
|
this._originalProps.asc_getStyleInfo().asc_setShowRowStripes(this.api, this._originalProps, value=='checked');
|
2017-06-30 14:49:58 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2017-07-14 08:00:56 +00:00
|
|
|
this._originalProps.asc_getStyleInfo().asc_setShowColStripes(this.api, this._originalProps, value=='checked');
|
2017-06-30 14:49:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
Common.NotificationCenter.trigger('edit:complete', this);
|
|
|
|
},
|
|
|
|
|
2019-09-30 15:54:37 +00:00
|
|
|
createSheetName: function() {
|
|
|
|
var items = [], wc = this.api.asc_getWorksheetsCount();
|
|
|
|
while (wc--) {
|
|
|
|
items.push(this.api.asc_getWorksheetName(wc).toLowerCase());
|
|
|
|
}
|
|
|
|
|
|
|
|
var index = 0, name;
|
|
|
|
while(++index < 1000) {
|
|
|
|
name = this.strSheet + index;
|
|
|
|
if (items.indexOf(name.toLowerCase()) < 0) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return name;
|
|
|
|
},
|
|
|
|
|
2017-06-30 14:49:58 +00:00
|
|
|
onCreateClick: function(btn, opts){
|
2019-09-30 15:54:37 +00:00
|
|
|
if (this.api) {
|
2019-10-03 12:30:43 +00:00
|
|
|
var options = this.api.asc_getAddPivotTableOptions();
|
|
|
|
if (options) {
|
2019-10-04 11:44:42 +00:00
|
|
|
var me = this;
|
|
|
|
(new SSE.Views.CreatePivotDialog(
|
|
|
|
{
|
|
|
|
props: options,
|
|
|
|
api: me.api,
|
|
|
|
handler: function(result, settings) {
|
|
|
|
if (result == 'ok' && settings) {
|
|
|
|
if (settings.destination)
|
|
|
|
me.api.asc_insertPivotExistingWorksheet(settings.source, settings.destination);
|
|
|
|
else
|
|
|
|
me.api.asc_insertPivotNewWorksheet(settings.source, me.createSheetName());
|
|
|
|
}
|
|
|
|
Common.NotificationCenter.trigger('edit:complete', me);
|
|
|
|
}
|
|
|
|
})).show();
|
2019-10-03 12:30:43 +00:00
|
|
|
}
|
2019-09-30 15:54:37 +00:00
|
|
|
}
|
2017-06-30 14:49:58 +00:00
|
|
|
Common.NotificationCenter.trigger('edit:complete', this);
|
|
|
|
},
|
|
|
|
|
2017-07-18 08:57:14 +00:00
|
|
|
onRefreshClick: function(btn, opts){
|
2019-09-30 15:54:37 +00:00
|
|
|
if (this.api) {
|
|
|
|
this._originalProps.asc_refresh(this.api);
|
|
|
|
}
|
2017-07-18 08:57:14 +00:00
|
|
|
Common.NotificationCenter.trigger('edit:complete', this);
|
|
|
|
},
|
|
|
|
|
2018-02-05 12:13:43 +00:00
|
|
|
onSelectClick: function(btn, opts){
|
2018-02-05 12:41:24 +00:00
|
|
|
if (this.api) {
|
|
|
|
this._originalProps.asc_select(this.api);
|
|
|
|
}
|
2018-02-05 12:13:43 +00:00
|
|
|
Common.NotificationCenter.trigger('edit:complete', this);
|
|
|
|
},
|
|
|
|
|
2017-07-14 12:40:48 +00:00
|
|
|
onPivotStyleSelect: function(record){
|
2017-07-17 10:17:30 +00:00
|
|
|
if (this.api) {
|
2017-07-14 12:40:48 +00:00
|
|
|
this._originalProps.asc_getStyleInfo().asc_setName(this.api, this._originalProps, record.get('name'));
|
2017-06-30 14:49:58 +00:00
|
|
|
}
|
|
|
|
Common.NotificationCenter.trigger('edit:complete', this);
|
|
|
|
},
|
|
|
|
|
2017-07-17 10:17:30 +00:00
|
|
|
onPivotBlankRows: function(type){
|
|
|
|
if (this.api) {
|
2019-09-30 15:54:37 +00:00
|
|
|
var props = new Asc.CT_pivotTableDefinition();
|
|
|
|
props.asc_setInsertBlankRow(type === 'insert');
|
|
|
|
this._originalProps.asc_set(this.api, props);
|
2017-07-17 10:17:30 +00:00
|
|
|
}
|
|
|
|
Common.NotificationCenter.trigger('edit:complete', this);
|
|
|
|
},
|
|
|
|
|
|
|
|
onPivotLayout: function(type){
|
|
|
|
if (this.api) {
|
2019-09-30 15:54:37 +00:00
|
|
|
var props = new Asc.CT_pivotTableDefinition();
|
2017-07-17 10:17:30 +00:00
|
|
|
switch (type){
|
|
|
|
case 0:
|
2019-09-30 15:54:37 +00:00
|
|
|
props.asc_setCompact(true);
|
|
|
|
props.asc_setOutline(true);
|
2017-07-17 10:17:30 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2019-09-30 15:54:37 +00:00
|
|
|
props.asc_setCompact(false);
|
|
|
|
props.asc_setOutline(true);
|
2017-07-17 10:17:30 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2019-09-30 15:54:37 +00:00
|
|
|
props.asc_setCompact(false);
|
|
|
|
props.asc_setOutline(false);
|
2017-07-17 10:17:30 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2019-09-30 15:54:37 +00:00
|
|
|
props.asc_setFillDownLabelsDefault(true);
|
2017-07-17 10:17:30 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2019-09-30 15:54:37 +00:00
|
|
|
props.asc_setFillDownLabelsDefault(false);
|
2017-07-17 10:17:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-09-30 15:54:37 +00:00
|
|
|
this._originalProps.asc_set(this.api, props);
|
2017-07-17 10:17:30 +00:00
|
|
|
}
|
|
|
|
Common.NotificationCenter.trigger('edit:complete', this);
|
|
|
|
},
|
|
|
|
|
|
|
|
onPivotGrandTotals: function(type){
|
|
|
|
if (this.api) {
|
2017-08-08 14:03:09 +00:00
|
|
|
var props = new Asc.CT_pivotTableDefinition();
|
2017-08-03 12:28:49 +00:00
|
|
|
props.asc_setColGrandTotals(type == 1 || type == 2);
|
|
|
|
props.asc_setRowGrandTotals(type == 1 || type == 3);
|
2017-07-21 07:35:19 +00:00
|
|
|
this._originalProps.asc_set(this.api, props);
|
2017-07-17 10:17:30 +00:00
|
|
|
}
|
|
|
|
Common.NotificationCenter.trigger('edit:complete', this);
|
|
|
|
},
|
|
|
|
|
|
|
|
onPivotSubtotals: function(type){
|
|
|
|
if (this.api) {
|
2019-09-30 15:54:37 +00:00
|
|
|
var props = new Asc.CT_pivotTableDefinition();
|
2017-07-17 10:17:30 +00:00
|
|
|
switch (type){
|
|
|
|
case 0:
|
2019-09-30 15:54:37 +00:00
|
|
|
props.asc_setDefaultSubtotal(false);
|
2017-07-17 10:17:30 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2019-09-30 15:54:37 +00:00
|
|
|
props.asc_setDefaultSubtotal(true);
|
|
|
|
props.asc_setSubtotalTop(false);
|
2017-07-17 10:17:30 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2019-09-30 15:54:37 +00:00
|
|
|
props.asc_setDefaultSubtotal(true);
|
|
|
|
props.asc_setSubtotalTop(true);
|
2017-07-17 10:17:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-09-30 15:54:37 +00:00
|
|
|
this._originalProps.asc_set(this.api, props);
|
2017-07-17 10:17:30 +00:00
|
|
|
}
|
|
|
|
Common.NotificationCenter.trigger('edit:complete', this);
|
|
|
|
},
|
|
|
|
|
2017-06-30 14:49:58 +00:00
|
|
|
ChangeSettings: function(props) {
|
|
|
|
if (props )
|
|
|
|
{
|
|
|
|
this._originalProps = props;
|
|
|
|
|
|
|
|
var view = this.view,
|
|
|
|
needTablePictures = false,
|
|
|
|
styleInfo = props.asc_getStyleInfo(),
|
|
|
|
value = styleInfo.asc_getShowRowHeaders();
|
|
|
|
if (this._state.RowHeader!==value) {
|
|
|
|
view.chRowHeader.setValue(value, true);
|
|
|
|
this._state.RowHeader=value;
|
|
|
|
needTablePictures = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
value = styleInfo.asc_getShowColHeaders();
|
2017-07-13 15:49:42 +00:00
|
|
|
if (this._state.ColHeader!==value) {
|
|
|
|
view.chColHeader.setValue(value, true);
|
|
|
|
this._state.ColHeader=value;
|
|
|
|
needTablePictures = true;
|
|
|
|
}
|
2017-06-30 14:49:58 +00:00
|
|
|
|
|
|
|
value = styleInfo.asc_getShowColStripes();
|
2017-07-13 15:49:42 +00:00
|
|
|
if (this._state.ColBanded!==value) {
|
|
|
|
view.chColBanded.setValue(value, true);
|
|
|
|
this._state.ColBanded=value;
|
|
|
|
needTablePictures = true;
|
|
|
|
}
|
2017-06-30 14:49:58 +00:00
|
|
|
|
|
|
|
value = styleInfo.asc_getShowRowStripes();
|
2017-07-13 15:49:42 +00:00
|
|
|
if (this._state.RowBanded!==value) {
|
|
|
|
view.chRowBanded.setValue(value, true);
|
|
|
|
this._state.RowBanded=value;
|
|
|
|
needTablePictures = true;
|
|
|
|
}
|
2017-06-30 14:49:58 +00:00
|
|
|
|
2017-08-03 09:53:07 +00:00
|
|
|
value = props.asc_getColGrandTotals();
|
|
|
|
if (this._state.ColGrandTotals!==value) {
|
|
|
|
this._state.ColGrandTotals=value;
|
|
|
|
needTablePictures = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
value = props.asc_getRowGrandTotals();
|
|
|
|
if (this._state.RowGrandTotals!==value) {
|
|
|
|
this._state.RowGrandTotals=value;
|
|
|
|
needTablePictures = true;
|
|
|
|
}
|
|
|
|
|
2017-06-30 14:49:58 +00:00
|
|
|
if (needTablePictures)
|
2017-07-14 11:17:16 +00:00
|
|
|
this.onApiInitPivotStyles(this.api.asc_getTablePictures(this._originalProps, true));
|
2017-06-30 14:49:58 +00:00
|
|
|
|
|
|
|
//for table-template
|
|
|
|
value = styleInfo.asc_getName();
|
|
|
|
if (this._state.TemplateName!==value || this._isTemplatesChanged) {
|
|
|
|
view.pivotStyles.suspendEvents();
|
|
|
|
var rec = view.pivotStyles.menuPicker.store.findWhere({
|
|
|
|
name: value
|
|
|
|
});
|
|
|
|
view.pivotStyles.menuPicker.selectRecord(rec);
|
|
|
|
view.pivotStyles.resumeEvents();
|
|
|
|
|
|
|
|
if (this._isTemplatesChanged) {
|
|
|
|
if (rec)
|
2019-06-27 11:18:01 +00:00
|
|
|
view.pivotStyles.fillComboView(view.pivotStyles.menuPicker.getSelectedRec(),true);
|
2017-06-30 14:49:58 +00:00
|
|
|
else
|
|
|
|
view.pivotStyles.fillComboView(view.pivotStyles.menuPicker.store.at(0), true);
|
|
|
|
}
|
|
|
|
this._state.TemplateName=value;
|
|
|
|
}
|
|
|
|
this._isTemplatesChanged = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onSendThemeColors: function() {
|
|
|
|
// get new table templates
|
|
|
|
if (this.view.pivotStyles && this._originalProps) {
|
2017-07-14 11:17:16 +00:00
|
|
|
this.onApiInitPivotStyles(this.api.asc_getTablePictures(this._originalProps, true));
|
2017-06-30 14:49:58 +00:00
|
|
|
this.view.pivotStyles.menuPicker.scroller.update({alwaysVisibleY: true});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onApiInitPivotStyles: function(Templates){
|
|
|
|
var self = this,
|
|
|
|
styles = this.view.pivotStyles;
|
|
|
|
this._isTemplatesChanged = true;
|
|
|
|
|
|
|
|
var count = styles.menuPicker.store.length;
|
|
|
|
if (count>0 && count==Templates.length) {
|
|
|
|
var data = styles.menuPicker.store.models;
|
|
|
|
_.each(Templates, function(template, index){
|
|
|
|
data[index].set('imageUrl', template.asc_getImage());
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
styles.menuPicker.store.reset([]);
|
|
|
|
var arr = [];
|
|
|
|
_.each(Templates, function(template){
|
|
|
|
arr.push({
|
|
|
|
id : Common.UI.getId(),
|
|
|
|
name : template.asc_getName(),
|
|
|
|
caption : template.asc_getDisplayName(),
|
|
|
|
type : template.asc_getType(),
|
|
|
|
imageUrl : template.asc_getImage(),
|
|
|
|
allowSelected : true,
|
|
|
|
selected : false,
|
|
|
|
tip : template.asc_getDisplayName()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
styles.menuPicker.store.add(arr);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onSelectionChanged: function(info) {
|
2019-10-04 13:17:05 +00:00
|
|
|
if (this.rangeSelectionMode || !this.appConfig.isEdit || !this.view) return;
|
2017-06-30 14:49:58 +00:00
|
|
|
|
|
|
|
var selectType = info.asc_getFlags().asc_getSelectionType(),
|
|
|
|
pivotInfo = info.asc_getPivotTableInfo();
|
|
|
|
|
2019-10-04 13:17:05 +00:00
|
|
|
Common.Utils.lockControls(SSE.enumLock.noPivot, !pivotInfo, {array: this.view.lockedControls});
|
|
|
|
Common.Utils.lockControls(SSE.enumLock.editPivot, !!pivotInfo, {array: [this.view.btnAddPivot]});
|
|
|
|
|
2017-06-30 14:49:58 +00:00
|
|
|
if (pivotInfo)
|
|
|
|
this.ChangeSettings(pivotInfo);
|
|
|
|
},
|
|
|
|
|
2019-10-04 13:17:05 +00:00
|
|
|
onCellsRange: function(status) {
|
|
|
|
this.rangeSelectionMode = (status != Asc.c_oAscSelectionDialogType.None);
|
|
|
|
},
|
|
|
|
|
2017-06-30 14:49:58 +00:00
|
|
|
createToolbarPanel: function() {
|
|
|
|
return this.view.getPanel();
|
|
|
|
},
|
|
|
|
|
|
|
|
getView: function(name) {
|
|
|
|
return !name && this.view ?
|
|
|
|
this.view : Backbone.Controller.prototype.getView.call(this, name);
|
|
|
|
},
|
|
|
|
|
|
|
|
onAppReady: function (config) {
|
|
|
|
var me = this;
|
|
|
|
(new Promise(function (resolve) {
|
|
|
|
resolve();
|
|
|
|
})).then(function () {
|
|
|
|
});
|
2019-09-30 15:54:37 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
strSheet : 'Sheet'
|
2017-06-30 14:49:58 +00:00
|
|
|
|
|
|
|
}, SSE.Controllers.PivotTable || {}));
|
|
|
|
});
|