2020-03-17 12:06:40 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* (c) Copyright Ascensio System SIA 2010-2020
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PrintTitlesDialog.js
|
|
|
|
*
|
|
|
|
* Created by Julia Radzhabova on 17.03.2020
|
|
|
|
* Copyright (c) 2020 Ascensio System SIA. All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
define([
|
|
|
|
'common/main/lib/component/Window',
|
|
|
|
'common/main/lib/component/MetricSpinner'
|
|
|
|
], function () { 'use strict';
|
|
|
|
|
|
|
|
SSE.Views.PrintTitlesDialog = Common.UI.Window.extend(_.extend({
|
|
|
|
options: {
|
|
|
|
width: 300,
|
|
|
|
header: true,
|
|
|
|
style: 'min-width: 216px;',
|
|
|
|
cls: 'modal-dlg',
|
|
|
|
id: 'window-page-margins',
|
2020-10-13 11:30:52 +00:00
|
|
|
buttons: ['ok', 'cancel']
|
2020-03-17 12:06:40 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
initialize : function(options) {
|
|
|
|
_.extend(this.options, {
|
|
|
|
title: this.textTitle
|
|
|
|
}, options || {});
|
|
|
|
|
|
|
|
this.template = [
|
|
|
|
'<div class="box" style="height: 100px;">',
|
|
|
|
'<table cols="2" style="width: 100%;margin-bottom: 10px;">',
|
|
|
|
'<tr>',
|
|
|
|
'<td colspan="2" style="padding-right: 10px;">',
|
|
|
|
'<label class="input-label">' + this.textTop + '</label>',
|
|
|
|
'</td>',
|
|
|
|
'</tr>',
|
|
|
|
'<tr>',
|
|
|
|
'<td style="padding-right: 10px;padding-bottom: 16px;">',
|
|
|
|
'<div id="print-titles-txt-top"></div>',
|
|
|
|
'</td>',
|
|
|
|
'<td style="padding-bottom: 16px;">',
|
|
|
|
'<div id="print-titles-presets-top"></div>',
|
|
|
|
'</td>',
|
|
|
|
'</tr>',
|
|
|
|
'<tr>',
|
|
|
|
'<td colspan="2" style="padding-right: 10px;">',
|
|
|
|
'<label class="input-label">' + this.textLeft + '</label>',
|
|
|
|
'</td>',
|
|
|
|
'</tr>',
|
|
|
|
'<tr>',
|
|
|
|
'<td style="padding-right: 10px;">',
|
|
|
|
'<div id="print-titles-txt-left"></div>',
|
|
|
|
'</td>',
|
|
|
|
'<td>',
|
|
|
|
'<div id="print-titles-presets-left"></div>',
|
|
|
|
'</td>',
|
|
|
|
'</tr>',
|
|
|
|
'</table>',
|
|
|
|
'</div>',
|
2020-06-05 13:10:48 +00:00
|
|
|
'<div class="separator horizontal"></div>'
|
2020-03-17 12:06:40 +00:00
|
|
|
].join('');
|
|
|
|
|
|
|
|
this.options.tpl = _.template(this.template)(this.options);
|
|
|
|
this.api = this.options.api;
|
2020-03-17 15:03:42 +00:00
|
|
|
this.sheet = this.options.sheet;
|
2020-03-17 12:06:40 +00:00
|
|
|
Common.UI.Window.prototype.initialize.call(this, this.options);
|
|
|
|
this.dataRangeTop = '';
|
|
|
|
this.dataRangeLeft = '';
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
Common.UI.Window.prototype.render.call(this);
|
|
|
|
|
|
|
|
var me = this;
|
|
|
|
|
2020-04-06 14:46:22 +00:00
|
|
|
this.txtRangeTop = new Common.UI.InputFieldBtn({
|
2020-03-17 12:06:40 +00:00
|
|
|
el : $('#print-titles-txt-top'),
|
|
|
|
style : 'width: 100%;',
|
2020-04-06 14:46:22 +00:00
|
|
|
btnHint : this.textSelectRange,
|
2020-03-17 12:06:40 +00:00
|
|
|
allowBlank : true,
|
|
|
|
validateOnChange: true,
|
|
|
|
validation : function(value) {
|
|
|
|
if (_.isEmpty(value)) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-03-18 12:09:39 +00:00
|
|
|
var isvalid = me.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.PrintTitles, value, false);
|
2020-03-17 12:06:40 +00:00
|
|
|
return (isvalid==Asc.c_oAscError.ID.DataRangeError) ? me.textInvalidRange : true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-03-18 10:06:18 +00:00
|
|
|
var frozen = this.api.asc_getPrintTitlesRange(Asc.c_oAscPrintTitlesRangeType.frozen, false, this.sheet);
|
2020-03-17 12:06:40 +00:00
|
|
|
this.btnPresetsTop = new Common.UI.Button({
|
2020-04-29 07:36:53 +00:00
|
|
|
parentEl: $('#print-titles-presets-top'),
|
2020-03-17 12:06:40 +00:00
|
|
|
cls: 'btn-text-menu-default',
|
|
|
|
caption: this.textRepeat,
|
|
|
|
style: 'width: 95px;',
|
|
|
|
menu: new Common.UI.Menu({
|
|
|
|
style: 'min-width: 100px;',
|
|
|
|
maxHeight: 200,
|
|
|
|
additionalAlign: this.menuAddAlign,
|
|
|
|
items: [
|
2020-04-06 14:57:55 +00:00
|
|
|
{caption: this.textSelectRange + '...', value: 'select'},
|
2020-03-18 10:06:18 +00:00
|
|
|
{caption: this.textFrozenRows, value: 'frozen', range: frozen, disabled: !frozen},
|
|
|
|
{caption: this.textFirstRow, value: 'first', range: this.api.asc_getPrintTitlesRange(Asc.c_oAscPrintTitlesRangeType.first, false, this.sheet)},
|
2020-03-17 12:06:40 +00:00
|
|
|
{caption: '--'},
|
2020-03-18 10:06:18 +00:00
|
|
|
{caption: this.textNoRepeat, value: 'empty', range: ''}
|
2020-03-17 12:06:40 +00:00
|
|
|
]
|
|
|
|
})
|
|
|
|
});
|
|
|
|
this.btnPresetsTop.menu.on('item:click', _.bind(this.onPresetSelect, this, 'top'));
|
2020-04-06 14:46:22 +00:00
|
|
|
this.txtRangeTop.on('button:click', _.bind(this.onPresetSelect, this, 'top', this.btnPresetsTop.menu, {value: 'select'}));
|
2020-03-17 12:06:40 +00:00
|
|
|
|
2020-04-06 14:46:22 +00:00
|
|
|
this.txtRangeLeft = new Common.UI.InputFieldBtn({
|
2020-03-17 12:06:40 +00:00
|
|
|
el : $('#print-titles-txt-left'),
|
|
|
|
style : 'width: 100%;',
|
2020-04-06 14:46:22 +00:00
|
|
|
btnHint : this.textSelectRange,
|
2020-03-17 12:06:40 +00:00
|
|
|
allowBlank : true,
|
|
|
|
validateOnChange: true,
|
|
|
|
validation : function(value) {
|
|
|
|
if (_.isEmpty(value)) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-03-18 12:09:39 +00:00
|
|
|
var isvalid = me.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.PrintTitles, value, false);
|
2020-03-17 12:06:40 +00:00
|
|
|
return (isvalid==Asc.c_oAscError.ID.DataRangeError) ? me.textInvalidRange : true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-03-18 10:06:18 +00:00
|
|
|
frozen = this.api.asc_getPrintTitlesRange(Asc.c_oAscPrintTitlesRangeType.frozen, true, this.sheet);
|
2020-03-17 12:06:40 +00:00
|
|
|
this.btnPresetsLeft = new Common.UI.Button({
|
2020-04-29 07:36:53 +00:00
|
|
|
parentEl: $('#print-titles-presets-left'),
|
2020-03-17 12:06:40 +00:00
|
|
|
cls: 'btn-text-menu-default',
|
|
|
|
caption: this.textRepeat,
|
|
|
|
style: 'width: 95px;',
|
|
|
|
menu: new Common.UI.Menu({
|
|
|
|
style: 'min-width: 100px;',
|
|
|
|
maxHeight: 200,
|
|
|
|
additionalAlign: this.menuAddAlign,
|
|
|
|
items: [
|
2020-04-06 14:57:55 +00:00
|
|
|
{caption: this.textSelectRange + '...', value: 'select'},
|
2020-03-18 10:06:18 +00:00
|
|
|
{caption: this.textFrozenCols, value: 'frozen', range: frozen, disabled: !frozen},
|
|
|
|
{caption: this.textFirstCol, value: 'first', range: this.api.asc_getPrintTitlesRange(Asc.c_oAscPrintTitlesRangeType.first, true, this.sheet)},
|
2020-03-17 12:06:40 +00:00
|
|
|
{caption: '--'},
|
2020-03-18 10:06:18 +00:00
|
|
|
{caption: this.textNoRepeat, value: 'empty', range: ''}
|
2020-03-17 12:06:40 +00:00
|
|
|
]
|
|
|
|
})
|
|
|
|
});
|
|
|
|
this.btnPresetsLeft.menu.on('item:click', _.bind(this.onPresetSelect, this, 'left'));
|
2020-04-06 14:46:22 +00:00
|
|
|
this.txtRangeLeft.on('button:click', _.bind(this.onPresetSelect, this, 'left', this.btnPresetsLeft.menu, {value: 'select'}));
|
2020-03-17 12:06:40 +00:00
|
|
|
|
|
|
|
var $window = this.getChild();
|
|
|
|
$window.find('.dlg-btn').on('click', _.bind(this.onBtnClick, this));
|
|
|
|
$window.find('input').on('keypress', _.bind(this.onKeyPress, this));
|
2020-03-18 07:08:47 +00:00
|
|
|
|
|
|
|
this.setSettings();
|
2020-03-17 12:06:40 +00:00
|
|
|
},
|
|
|
|
|
2020-10-13 11:30:52 +00:00
|
|
|
getFocusedComponents: function() {
|
|
|
|
return [this.txtRangeTop, this.txtRangeLeft];
|
|
|
|
},
|
|
|
|
|
2020-10-22 10:53:58 +00:00
|
|
|
getDefaultFocusableComponent: function () {
|
|
|
|
if (this._alreadyRendered) return; // focus only at first show
|
|
|
|
this._alreadyRendered = true;
|
|
|
|
return this.txtRangeTop;
|
|
|
|
},
|
|
|
|
|
2020-03-18 10:06:18 +00:00
|
|
|
isRangeValid: function() {
|
2020-03-18 12:09:39 +00:00
|
|
|
if (this.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.PrintTitles, this.txtRangeTop.getValue(), false) == Asc.c_oAscError.ID.DataRangeError) {
|
2020-09-26 14:01:53 +00:00
|
|
|
this.txtRangeTop.focus();
|
2020-03-18 10:06:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-03-18 12:09:39 +00:00
|
|
|
if (this.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.PrintTitles, this.txtRangeLeft.getValue(), false) == Asc.c_oAscError.ID.DataRangeError) {
|
2020-09-26 14:01:53 +00:00
|
|
|
this.txtRangeLeft.focus();
|
2020-03-18 10:06:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2020-03-17 12:06:40 +00:00
|
|
|
_handleInput: function(state) {
|
2020-03-18 10:06:18 +00:00
|
|
|
if (this.options.handler) {
|
|
|
|
if (state == 'ok') {
|
|
|
|
if (!this.isRangeValid())
|
|
|
|
return;
|
|
|
|
}
|
2020-03-17 12:06:40 +00:00
|
|
|
this.options.handler.call(this, this, state);
|
2020-03-18 10:06:18 +00:00
|
|
|
}
|
2020-03-17 12:06:40 +00:00
|
|
|
|
|
|
|
this.close();
|
|
|
|
},
|
|
|
|
|
|
|
|
onBtnClick: function(event) {
|
|
|
|
this._handleInput(event.currentTarget.attributes['result'].value);
|
|
|
|
},
|
|
|
|
|
|
|
|
onKeyPress: function(event) {
|
|
|
|
if (event.keyCode == Common.UI.Keys.RETURN) {
|
|
|
|
this._handleInput('ok');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setSettings: function (props) {
|
2020-03-18 07:08:47 +00:00
|
|
|
if (this.api) {
|
|
|
|
var value = this.api.asc_getPrintTitlesRange(Asc.c_oAscPrintTitlesRangeType.current, false, this.sheet);
|
|
|
|
this.txtRangeTop.setValue((value) ? value : '');
|
|
|
|
this.dataRangeTop = value;
|
|
|
|
|
|
|
|
value = this.api.asc_getPrintTitlesRange(Asc.c_oAscPrintTitlesRangeType.current, true, this.sheet);
|
|
|
|
this.txtRangeLeft.setValue((value) ? value : '');
|
|
|
|
this.dataRangeLeft = value;
|
2020-03-17 12:06:40 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
getSettings: function() {
|
2020-03-18 12:09:39 +00:00
|
|
|
return {width: this.txtRangeLeft.getValue(), height: this.txtRangeTop.getValue()};
|
2020-03-17 12:06:40 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onPresetSelect: function(type, menu, item) {
|
2020-03-17 12:37:59 +00:00
|
|
|
var txtRange = (type=='top') ? this.txtRangeTop : this.txtRangeLeft;
|
2020-03-17 12:06:40 +00:00
|
|
|
if (item.value == 'select') {
|
|
|
|
var me = this;
|
|
|
|
if (me.api) {
|
2020-04-09 14:14:42 +00:00
|
|
|
me.btnPresetsTop.menu.options.additionalAlign = me.menuAddAlign;
|
|
|
|
me.btnPresetsLeft.menu.options.additionalAlign = me.menuAddAlign;
|
|
|
|
|
2020-03-17 12:06:40 +00:00
|
|
|
var handlerDlg = function(dlg, result) {
|
|
|
|
if (result == 'ok') {
|
|
|
|
var valid = dlg.getSettings();
|
|
|
|
if (type=='top')
|
|
|
|
me.dataRangeTop = valid;
|
|
|
|
else
|
|
|
|
me.dataRangeLeft = valid;
|
|
|
|
txtRange.setValue(valid);
|
|
|
|
txtRange.checkValidate();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var win = new SSE.Views.CellRangeDialog({
|
|
|
|
handler: handlerDlg
|
|
|
|
}).on('close', function() {
|
|
|
|
me.show();
|
2020-09-26 14:01:53 +00:00
|
|
|
_.delay(function(){
|
|
|
|
txtRange.focus();
|
|
|
|
},1);
|
2020-03-17 12:06:40 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
var xy = me.$window.offset();
|
|
|
|
me.hide();
|
|
|
|
win.show(xy.left + 160, xy.top + 125);
|
|
|
|
win.setSettings({
|
|
|
|
api : me.api,
|
2020-03-17 12:37:59 +00:00
|
|
|
range : (!_.isEmpty(txtRange.getValue()) && (txtRange.checkValidate()==true)) ? txtRange.getValue() : ((type=='top') ? me.dataRangeTop : me.dataRangeLeft),
|
2020-03-18 12:09:39 +00:00
|
|
|
type : Asc.c_oAscSelectionDialogType.PrintTitles
|
2020-03-17 12:06:40 +00:00
|
|
|
});
|
|
|
|
}
|
2020-03-17 12:37:59 +00:00
|
|
|
} else {
|
2020-03-18 10:06:18 +00:00
|
|
|
var value = item.options.range || '';
|
2020-03-17 12:37:59 +00:00
|
|
|
txtRange.setValue(value);
|
|
|
|
txtRange.checkValidate();
|
2020-03-17 12:06:40 +00:00
|
|
|
if (type=='top')
|
2020-03-17 12:37:59 +00:00
|
|
|
this.dataRangeTop = value;
|
2020-03-17 12:06:40 +00:00
|
|
|
else
|
2020-03-17 12:37:59 +00:00
|
|
|
this.dataRangeLeft = value;
|
2020-09-26 14:01:53 +00:00
|
|
|
_.delay(function(){
|
|
|
|
txtRange.focus();
|
|
|
|
},1);
|
2020-03-17 12:06:40 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
textTitle: 'Print Titles',
|
|
|
|
textTop: 'Repeat rows at top',
|
|
|
|
textLeft: 'Repeat columns at left',
|
|
|
|
textRepeat: 'Repeat...',
|
|
|
|
textNoRepeat: 'Not repeat',
|
2020-04-06 14:57:55 +00:00
|
|
|
textSelectRange: 'Select range',
|
2020-03-17 12:06:40 +00:00
|
|
|
textFrozenRows: 'Frozen rows',
|
|
|
|
textFrozenCols: 'Frozen columns',
|
|
|
|
textFirstRow: 'First row',
|
|
|
|
textFirstCol: 'First column',
|
|
|
|
textInvalidRange: 'ERROR! Invalid cells range'
|
|
|
|
|
|
|
|
}, SSE.Views.PrintTitlesDialog || {}))
|
|
|
|
});
|