2019-10-04 14:04:16 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* (c) Copyright Ascensio System SIA 2010-2019
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CreatePivotDialog.js
|
|
|
|
*
|
|
|
|
* Created by Julia Radzhabova on 04.10.2019
|
|
|
|
* Copyright (c) 2019 Ascensio System SIA. All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
define([
|
|
|
|
'common/main/lib/util/utils',
|
|
|
|
'common/main/lib/component/InputField',
|
|
|
|
'common/main/lib/component/ComboBox',
|
|
|
|
'common/main/lib/view/AdvancedSettingsWindow'
|
|
|
|
], function () { 'use strict';
|
|
|
|
|
|
|
|
SSE.Views.CreatePivotDialog = Common.Views.AdvancedSettingsWindow.extend(_.extend({
|
|
|
|
options: {
|
2020-04-06 14:46:22 +00:00
|
|
|
contentWidth: 310,
|
2022-11-16 19:12:04 +00:00
|
|
|
height: 250,
|
|
|
|
id: 'window-create-pivot'
|
2019-10-04 14:04:16 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
initialize : function(options) {
|
|
|
|
var me = this;
|
|
|
|
|
|
|
|
_.extend(this.options, {
|
|
|
|
title: this.textTitle,
|
|
|
|
template: [
|
|
|
|
'<div class="box" style="height:' + (me.options.height - 85) + 'px;">',
|
|
|
|
'<div class="content-panel" style="padding: 0 10px;"><div class="inner-content">',
|
|
|
|
'<div class="settings-panel active">',
|
|
|
|
'<table cols="1" style="width: 100%;">',
|
|
|
|
'<tr>',
|
|
|
|
'<td style="padding-bottom: 2px;">',
|
|
|
|
'<label class="input-label">' + me.textDataRange + '</label>',
|
|
|
|
'</td>',
|
|
|
|
'</tr>',
|
|
|
|
'<tr>',
|
|
|
|
'<td class="padding-large">',
|
2020-04-06 14:46:22 +00:00
|
|
|
'<div id="create-pivot-input-source" class="input-row" style=""></div>',
|
2019-10-04 14:04:16 +00:00
|
|
|
'</td>',
|
|
|
|
'</tr>',
|
|
|
|
'<tr>',
|
|
|
|
'<td class="padding-small">',
|
|
|
|
'<label class="input-label">' + me.textDestination + '</label>',
|
|
|
|
'</td>',
|
|
|
|
'</tr>',
|
|
|
|
'<tr>',
|
|
|
|
'<td class="padding-small">',
|
|
|
|
'<div id="create-pivot-radio-new"></div>',
|
|
|
|
'</td>',
|
|
|
|
'</tr>',
|
|
|
|
'<tr>',
|
|
|
|
'<td class="padding-small">',
|
|
|
|
'<div id="create-pivot-radio-exist"></div>',
|
|
|
|
'</td>',
|
|
|
|
'</tr>',
|
|
|
|
'<tr>',
|
2022-11-16 19:12:04 +00:00
|
|
|
'<td class="input-dest">',
|
2020-04-06 14:46:22 +00:00
|
|
|
'<div id="create-pivot-input-dest" class="input-row" style=""></div>',
|
2019-10-04 14:04:16 +00:00
|
|
|
'</td>',
|
|
|
|
'</tr>',
|
|
|
|
'</table>',
|
|
|
|
'</div></div>',
|
|
|
|
'</div>',
|
2019-10-04 15:01:56 +00:00
|
|
|
'</div>'
|
2019-10-04 14:04:16 +00:00
|
|
|
].join('')
|
|
|
|
}, options);
|
|
|
|
|
|
|
|
this.api = options.api;
|
|
|
|
this.props = options.props;
|
|
|
|
|
|
|
|
this.options.handler = function(result, value) {
|
|
|
|
if ( result != 'ok' || this.isRangeValid() ) {
|
|
|
|
if (options.handler)
|
|
|
|
options.handler.call(this, result, value);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.dataSourceValid = '';
|
|
|
|
this.dataDestValid = '';
|
|
|
|
|
|
|
|
Common.Views.AdvancedSettingsWindow.prototype.initialize.call(this, this.options);
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
Common.Views.AdvancedSettingsWindow.prototype.render.call(this);
|
|
|
|
var me = this;
|
|
|
|
|
2020-04-06 14:46:22 +00:00
|
|
|
this.txtSourceRange = new Common.UI.InputFieldBtn({
|
2019-10-04 14:04:16 +00:00
|
|
|
el : $('#create-pivot-input-source'),
|
|
|
|
name : 'range',
|
|
|
|
style : 'width: 100%;',
|
2020-04-06 14:46:22 +00:00
|
|
|
btnHint : this.textSelectData,
|
2019-10-04 14:04:16 +00:00
|
|
|
allowBlank : true,
|
|
|
|
validateOnChange: true
|
|
|
|
});
|
2020-04-06 14:46:22 +00:00
|
|
|
this.txtSourceRange.on('button:click', _.bind(this.onSelectData, this, 'source'));
|
2019-10-04 14:04:16 +00:00
|
|
|
|
2020-04-06 14:46:22 +00:00
|
|
|
this.txtDestRange = new Common.UI.InputFieldBtn({
|
2019-10-04 14:04:16 +00:00
|
|
|
el : $('#create-pivot-input-dest'),
|
|
|
|
name : 'range',
|
|
|
|
style : 'width: 100%;',
|
2020-04-06 14:46:22 +00:00
|
|
|
btnHint : this.textSelectData,
|
2019-10-04 14:04:16 +00:00
|
|
|
allowBlank : true,
|
|
|
|
validateOnChange: true,
|
2019-10-11 13:37:27 +00:00
|
|
|
validateOnBlur: false,
|
2019-10-04 14:04:16 +00:00
|
|
|
disabled: true
|
|
|
|
});
|
2020-04-06 14:46:22 +00:00
|
|
|
this.txtDestRange.on('button:click', _.bind(this.onSelectData, this, 'dest'));
|
2019-10-04 14:04:16 +00:00
|
|
|
|
|
|
|
this.radioNew = new Common.UI.RadioBox({
|
|
|
|
el: $('#create-pivot-radio-new'),
|
|
|
|
labelText: this.textNew,
|
|
|
|
name: 'asc-radio-pivot-dest',
|
|
|
|
checked: true
|
|
|
|
}).on('change', function(field, newValue) {
|
|
|
|
me.txtDestRange.setDisabled(newValue);
|
2019-10-11 13:37:27 +00:00
|
|
|
me.txtDestRange.showError();
|
2019-10-04 14:04:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.radioExist = new Common.UI.RadioBox({
|
|
|
|
el: $('#create-pivot-radio-exist'),
|
|
|
|
labelText: this.textExist,
|
|
|
|
name: 'asc-radio-pivot-dest'
|
|
|
|
}).on('change', function(field, newValue) {
|
|
|
|
me.txtDestRange.setDisabled(!newValue);
|
2019-10-11 13:37:27 +00:00
|
|
|
me.txtDestRange.cmpEl.find('input').focus();
|
2019-10-04 14:04:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.afterRender();
|
|
|
|
},
|
|
|
|
|
2020-10-13 11:30:52 +00:00
|
|
|
getFocusedComponents: function() {
|
2021-04-14 15:16:27 +00:00
|
|
|
return [this.txtSourceRange, this.radioNew, this.radioExist, this.txtDestRange];
|
2020-10-13 11:30:52 +00:00
|
|
|
},
|
|
|
|
|
2020-10-22 10:53:58 +00:00
|
|
|
getDefaultFocusableComponent: function () {
|
|
|
|
if (this._alreadyRendered) return; // focus only at first show
|
|
|
|
this._alreadyRendered = true;
|
|
|
|
return this.txtSourceRange;
|
2019-10-04 14:04:16 +00:00
|
|
|
},
|
|
|
|
|
2020-10-22 10:53:58 +00:00
|
|
|
afterRender: function() {
|
|
|
|
this._setDefaults(this.props);
|
2020-09-26 13:58:37 +00:00
|
|
|
},
|
|
|
|
|
2019-10-04 14:04:16 +00:00
|
|
|
_setDefaults: function (props) {
|
|
|
|
if (props) {
|
|
|
|
var value = props.asc_getRange();
|
|
|
|
this.txtSourceRange.setValue((value) ? value : '');
|
|
|
|
this.dataSourceValid = value;
|
|
|
|
|
2019-10-11 10:07:17 +00:00
|
|
|
var me = this;
|
2019-10-04 14:04:16 +00:00
|
|
|
this.txtSourceRange.validation = function(value) {
|
2019-10-11 10:07:17 +00:00
|
|
|
var isvalid = me.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.PivotTableData, value, false);
|
|
|
|
return (isvalid==Asc.c_oAscError.ID.DataRangeError) ? me.textInvalidRange : true;
|
2019-10-04 14:04:16 +00:00
|
|
|
};
|
|
|
|
this.txtDestRange.validation = function(value) {
|
2019-10-11 10:07:17 +00:00
|
|
|
var isvalid = me.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.PivotTableReport, value, false);
|
|
|
|
return (isvalid==Asc.c_oAscError.ID.DataRangeError) ? me.textInvalidRange : true;
|
2019-10-04 14:04:16 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
getSettings: function () {
|
|
|
|
var source = this.txtSourceRange.getValue(),
|
|
|
|
dest = this.radioExist.getValue() ? this.txtDestRange.getValue() : null;
|
|
|
|
|
|
|
|
return {source: source, destination: dest};
|
|
|
|
},
|
|
|
|
|
|
|
|
isRangeValid: function() {
|
|
|
|
var isvalid = true,
|
|
|
|
txtError = '';
|
|
|
|
|
|
|
|
if (_.isEmpty(this.txtSourceRange.getValue())) {
|
|
|
|
isvalid = false;
|
|
|
|
txtError = this.txtEmpty;
|
|
|
|
} else {
|
2019-10-11 10:07:17 +00:00
|
|
|
isvalid = this.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.PivotTableData, this.txtSourceRange.getValue());
|
|
|
|
isvalid = (isvalid == Asc.c_oAscError.ID.No);
|
2019-10-04 14:04:16 +00:00
|
|
|
!isvalid && (txtError = this.textInvalidRange);
|
|
|
|
}
|
|
|
|
if (!isvalid) {
|
|
|
|
this.txtSourceRange.showError([txtError]);
|
|
|
|
this.txtSourceRange.cmpEl.find('input').focus();
|
|
|
|
return isvalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.radioExist.getValue()) {
|
|
|
|
if (_.isEmpty(this.txtDestRange.getValue())) {
|
|
|
|
isvalid = false;
|
|
|
|
txtError = this.txtEmpty;
|
|
|
|
} else {
|
2019-10-11 10:07:17 +00:00
|
|
|
isvalid = this.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.PivotTableReport, this.txtDestRange.getValue());
|
|
|
|
isvalid = (isvalid == Asc.c_oAscError.ID.No);
|
2019-10-04 14:04:16 +00:00
|
|
|
!isvalid && (txtError = this.textInvalidRange);
|
|
|
|
}
|
|
|
|
if (!isvalid) {
|
|
|
|
this.txtDestRange.showError([txtError]);
|
|
|
|
this.txtDestRange.cmpEl.find('input').focus();
|
|
|
|
return isvalid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return isvalid;
|
|
|
|
},
|
|
|
|
|
|
|
|
onSelectData: function(type) {
|
|
|
|
var me = this,
|
|
|
|
txtRange = (type=='source') ? me.txtSourceRange : me.txtDestRange;
|
|
|
|
|
|
|
|
if (me.api) {
|
|
|
|
var handlerDlg = function(dlg, result) {
|
|
|
|
if (result == 'ok') {
|
|
|
|
var txt = dlg.getSettings();
|
|
|
|
(type=='source') ? (me.dataSourceValid = txt) : (me.dataDestValid = txt);
|
|
|
|
txtRange.setValue(txt);
|
|
|
|
txtRange.checkValidate();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var win = new SSE.Views.CellRangeDialog({
|
|
|
|
handler: handlerDlg
|
|
|
|
}).on('close', function() {
|
|
|
|
me.show();
|
2020-09-26 13:58:37 +00:00
|
|
|
_.delay(function(){
|
|
|
|
txtRange.focus();
|
|
|
|
},1);
|
2019-10-04 14:04:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
var xy = me.$window.offset();
|
|
|
|
me.hide();
|
|
|
|
win.show(xy.left + 160, xy.top + 125);
|
|
|
|
win.setSettings({
|
|
|
|
api : me.api,
|
|
|
|
range : (!_.isEmpty(txtRange.getValue()) && (txtRange.checkValidate()==true)) ? txtRange.getValue() : ((type=='source') ? me.dataSourceValid : me.dataDestValid),
|
2019-10-11 10:07:17 +00:00
|
|
|
type : (type=='source') ? Asc.c_oAscSelectionDialogType.PivotTableData : Asc.c_oAscSelectionDialogType.PivotTableReport
|
2019-10-04 14:04:16 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-09-07 13:54:48 +00:00
|
|
|
textTitle: 'Create Pivot Table',
|
2019-10-04 14:04:16 +00:00
|
|
|
textDataRange: 'Source data range',
|
2020-04-06 14:57:55 +00:00
|
|
|
textSelectData: 'Select data',
|
2019-10-04 14:04:16 +00:00
|
|
|
textDestination: 'Choose, where to place the table',
|
|
|
|
textNew: 'New worksheet',
|
|
|
|
textExist: 'Existing worksheet',
|
|
|
|
txtEmpty: 'This field is required',
|
|
|
|
textInvalidRange: 'Invalid cells range'
|
|
|
|
}, SSE.Views.CreatePivotDialog || {}))
|
|
|
|
});
|