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

306 lines
14 KiB
JavaScript
Raw Normal View History

2017-07-14 14:10:09 +00:00
/*
*
* (c) Copyright Ascensio System SIA 2010-2019
2017-07-14 14:10:09 +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-07-14 14:10:09 +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
*
*/
/**
* ValueFieldSettingsDialog.js
*
* Created by Julia Radzhabova on 14.07.2017
2018-03-01 12:16:38 +00:00
* Copyright (c) 2018 Ascensio System SIA. All rights reserved.
2017-07-14 14:10:09 +00:00
*
*/
define([
'common/main/lib/util/utils',
2017-07-17 14:18:52 +00:00
'common/main/lib/component/InputField',
2017-07-14 14:10:09 +00:00
'common/main/lib/component/ComboBox',
'common/main/lib/view/AdvancedSettingsWindow'
], function () { 'use strict';
SSE.Views.ValueFieldSettingsDialog = Common.Views.AdvancedSettingsWindow.extend(_.extend({
options: {
contentWidth: 284,
2020-10-13 11:30:52 +00:00
height: 220
2017-07-14 14:10:09 +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="2" style="width: 100%;">',
'<tr>',
'<td colspan="2" class="padding-small" style="white-space: nowrap;">',
'<label class="header" style="vertical-align: middle; margin-right: 4px;">' + me.txtSourceName + '</label>',
'<label id="value-field-settings-source" style="vertical-align: middle; max-width: 220px; overflow: hidden; text-overflow: ellipsis;"></label>',
'</td>',
'</tr>',
'<tr>',
'<td colspan="2" class="padding-large">',
'<label class="header">', me.txtCustomName,'</label>',
'<div id="value-field-settings-custom" style="width:264px;"></div>',
'</td>',
'</tr>',
'<tr>',
'<td colspan="2" class="padding-large">',
'<label class="header">', me.txtSummarize,'</label>',
'<div id="value-field-settings-summarize" class="input-group-nr" style="width:264px;"></div>',
'</td>',
'</tr>',
// '<tr>',
// '<td colspan="2" class="padding-large">',
// '<label class="header">', me.txtShowAs,'</label>',
// '<div id="value-field-settings-showas" class="input-group-nr" style="width:264px;"></div>',
// '</td>',
// '</tr>',
// '<tr class="format-code">',
// '<td>',
// '<label class="header">', me.txtBaseField,'</label>',
// '<div id="value-field-settings-field" class="input-group-nr" style="width:128px;"></div>',
// '</td>',
// '<td style="float: right;">',
// '<label class="header">', me.txtBaseItem,'</label>',
// '<div id="value-field-settings-item" class="input-group-nr" style="width:128px;"></div>',
// '</td>',
// '</tr>',
2017-07-14 14:10:09 +00:00
'</table>',
'</div></div>',
'</div>',
'</div>'
2017-07-14 14:10:09 +00:00
].join('')
}, options);
this.api = options.api;
this.handler = options.handler;
this.props = options.props;
2017-07-19 11:29:21 +00:00
this.field = options.field || 0;
2017-07-14 14:10:09 +00:00
this.names = options.names || [];
Common.Views.AdvancedSettingsWindow.prototype.initialize.call(this, this.options);
},
render: function() {
Common.Views.AdvancedSettingsWindow.prototype.render.call(this);
var me = this;
this.inputCustomName = new Common.UI.InputField({
el : $('#value-field-settings-custom'),
allowBlank : true,
validateOnBlur: false,
style : 'width: 100%;'
});
this.cmbSummarize = new Common.UI.ComboBox({
el: $('#value-field-settings-summarize'),
cls: 'input-group-nr',
menuStyle: 'min-width: 264px;max-height:160px;',
scrollAlwaysVisible: true,
2017-07-14 14:10:09 +00:00
editable: false,
takeFocusOnClose: true,
2017-07-14 14:10:09 +00:00
data: [
{ value: Asc.c_oAscDataConsolidateFunction.Sum, displayValue: this.txtSum },
{ value: Asc.c_oAscDataConsolidateFunction.Count, displayValue: this.txtCount },
{ value: Asc.c_oAscDataConsolidateFunction.Average, displayValue: this.txtAverage },
{ value: Asc.c_oAscDataConsolidateFunction.Max, displayValue: this.txtMax },
{ value: Asc.c_oAscDataConsolidateFunction.Min, displayValue: this.txtMin },
{ value: Asc.c_oAscDataConsolidateFunction.Product, displayValue: this.txtProduct },
{ value: Asc.c_oAscDataConsolidateFunction.CountNums,displayValue: this.txtCountNums },
{ value: Asc.c_oAscDataConsolidateFunction.StdDev, displayValue: this.txtStdDev },
{ value: Asc.c_oAscDataConsolidateFunction.StdDevp, displayValue: this.txtStdDevp },
{ value: Asc.c_oAscDataConsolidateFunction.Var, displayValue: this.txtVar },
{ value: Asc.c_oAscDataConsolidateFunction.Varp, displayValue: this.txtVarp }
]
});
this.cmbSummarize.setValue(Asc.c_oAscDataConsolidateFunction.Sum);
this.cmbSummarize.on('selected', _.bind(this.onSummarizeSelect, this));
/*
2017-07-14 14:10:09 +00:00
this.cmbShowAs = new Common.UI.ComboBox({
el: $('#value-field-settings-showas'),
cls: 'input-group-nr',
menuStyle: 'min-width: 264px;max-height:160px;',
2017-07-14 14:10:09 +00:00
editable: false,
data: [
{ value: Asc.c_oAscShowDataAs.Normal, displayValue: this.txtNormal },
{ value: Asc.c_oAscShowDataAs.PercentOfRow, displayValue: this.txtPercentOfRow },
{ value: Asc.c_oAscShowDataAs.PercentOfCol, displayValue: this.txtPercentOfCol },
{ value: Asc.c_oAscShowDataAs.PercentOfTotal, displayValue: this.txtPercentOfTotal },
{ value: Asc.c_oAscShowDataAs.Percent, displayValue: this.txtPercent },
{ value: Asc.c_oAscShowDataAs.Difference, displayValue: this.txtDifference },
{ value: Asc.c_oAscShowDataAs.PercentDiff, displayValue: this.txtPercentDiff },
{ value: Asc.c_oAscShowDataAs.RunTotal, displayValue: this.txtRunTotal },
{ value: Asc.c_oAscShowDataAs.Index, displayValue: this.txtIndex }
]
});
this.cmbShowAs.setValue(Asc.c_oAscDataConsolidateFunction.Normal);
this.cmbShowAs.on('selected', _.bind(this.onShowAsSelect, this));
this.cmbBaseField = new Common.UI.ComboBox({
el: $('#value-field-settings-field'),
cls: 'input-group-nr',
menuStyle: 'min-width: 100%;max-height:160px;',
2017-07-14 14:10:09 +00:00
editable: false,
data: [],
scrollAlwaysVisible: true
});
this.cmbBaseField.on('selected', _.bind(this.onBaseFieldSelect, this));
this.cmbBaseItem = new Common.UI.ComboBox({
el: $('#value-field-settings-item'),
cls: 'input-group-nr',
menuStyle: 'min-width: 100%;max-height:160px;',
2017-07-14 14:10:09 +00:00
editable: false,
data: [],
scrollAlwaysVisible: true
});
this.cmbBaseItem.on('selected', _.bind(this.onBaseItemSelect, this));
*/
2017-07-14 14:10:09 +00:00
this.lblSourceName = this.$window.find('#value-field-settings-source');
this.afterRender();
2020-10-13 11:30:52 +00:00
},
getFocusedComponents: function() {
return [this.inputCustomName, this.cmbSummarize];
2017-07-14 14:10:09 +00:00
},
2020-10-22 10:53:58 +00:00
getDefaultFocusableComponent: function () {
return this.inputCustomName;
2017-07-14 14:10:09 +00:00
},
2020-10-22 10:53:58 +00:00
afterRender: function() {
this._setDefaults(this.props);
2017-07-14 14:10:09 +00:00
},
_setDefaults: function (props) {
if (props) {
2017-07-19 11:29:21 +00:00
var field = this.field,
cache_names = props.asc_getCacheFields();
2017-07-14 14:10:09 +00:00
this.lblSourceName.html(Common.Utils.String.htmlEncode(cache_names[field.asc_getIndex()].asc_getName()));
this.inputCustomName.setValue(Common.Utils.String.htmlEncode(field.asc_getName()));
this.cmbSummarize.setValue(field.asc_getSubtotal());
/*
var show_as = field.asc_getShowDataAs();
this.cmbShowAs.setValue(show_as);
2017-07-14 14:10:09 +00:00
var data = [];
this.names.forEach(function(item){
data.push({value: item, displayValue: item});
});
this.cmbBaseField.setData(data);
this.cmbBaseField.setValue(this.names[0]);
this.cmbBaseField.setDisabled(show_as != c_oAscShowDataAs.Difference && show_as != c_oAscShowDataAs.Percent &&
show_as != c_oAscShowDataAs.PercentDiff && show_as != c_oAscShowDataAs.RunTotal);
// this.cmbBaseItem.setData(data);
this.cmbBaseItem.setDisabled(show_as != c_oAscShowDataAs.Difference && show_as != c_oAscShowDataAs.Percent &&
show_as != c_oAscShowDataAs.PercentDiff);
*/
2017-07-14 14:10:09 +00:00
}
},
getSettings: function () {
2017-08-08 14:03:09 +00:00
var field = new Asc.CT_DataField();
2017-07-19 11:29:21 +00:00
field.asc_setName(this.inputCustomName.getValue());
field.asc_setSubtotal(this.cmbSummarize.getValue());
return field;
2017-07-14 14:10:09 +00:00
},
onDlgBtnClick: function(event) {
var me = this;
var state = (typeof(event) == 'object') ? event.currentTarget.attributes['result'].value : event;
if (state == 'ok') {
this.handler && this.handler.call(this, state, (state == 'ok') ? this.getSettings() : undefined);
}
this.close();
},
onPrimary: function() {
this.onDlgBtnClick('ok');
return false;
},
onSummarizeSelect: function(combo, record) {
2020-03-12 12:54:57 +00:00
this.inputCustomName.setValue(this.txtByField.replace('%1', record.displayValue).replace('%2', this.lblSourceName.text()));
2017-07-14 14:10:09 +00:00
},
onShowAsSelect: function(combo, record) {
// var show_as = record.value;
// this.cmbBaseField.setDisabled(show_as != c_oAscShowDataAs.Difference && show_as != c_oAscShowDataAs.Percent &&
// show_as != c_oAscShowDataAs.PercentDiff && show_as != c_oAscShowDataAs.RunTotal);
2017-07-14 14:10:09 +00:00
},
onBaseFieldSelect: function(combo, record) {
},
onBaseItemSelect: function(combo, record) {
},
textTitle: 'Value Field Settings',
2019-10-15 07:44:33 +00:00
txtSourceName: 'Source name:',
2017-07-14 14:10:09 +00:00
txtCustomName: 'Custom name',
txtSummarize: 'Summarize value field by',
txtShowAs: 'Show values as',
txtBaseField: 'Base field',
txtBaseItem: 'Base item',
txtAverage: 'Average',
txtCount: 'Count',
txtCountNums: 'Count Numbers',
txtMax: 'Max',
txtMin: 'Min',
txtProduct: 'Product',
txtStdDev: 'StdDev',
txtStdDevp: 'StdDevp',
txtSum: 'Sum',
txtVar: 'Var',
txtVarp: 'Varp',
txtNormal: 'No Calculation',
txtDifference: 'The Difference From',
txtPercent: 'Percent of',
txtPercentDiff: 'Percent Difference From',
txtRunTotal: 'Running Total In',
txtPercentOfRow: 'Percent of Total',
txtPercentOfCol: 'Percent of Column',
txtPercentOfTotal: 'Percent of Row',
txtIndex: 'Index',
2020-03-12 12:54:57 +00:00
txtByField: '%1 of %2'
2017-07-14 14:10:09 +00:00
}, SSE.Views.ValueFieldSettingsDialog || {}))
});