2019-08-21 10:55:40 +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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* ScaleDialog.js
|
|
|
|
*
|
|
|
|
* Created by Julia Svinareva on 21/08/19
|
|
|
|
* Copyright (c) 2019 Ascensio System SIA. All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
define([
|
|
|
|
'common/main/lib/component/Window',
|
2019-09-02 07:20:17 +00:00
|
|
|
'common/main/lib/component/MetricSpinner'
|
2019-08-21 10:55:40 +00:00
|
|
|
], function () { 'use strict';
|
|
|
|
|
|
|
|
SSE.Views.ScaleDialog = Common.UI.Window.extend(_.extend({
|
|
|
|
options: {
|
2019-08-22 07:47:08 +00:00
|
|
|
width: 215,
|
2019-08-21 10:55:40 +00:00
|
|
|
header: true,
|
2019-08-22 07:47:08 +00:00
|
|
|
style: 'min-width: 215px;',
|
2019-09-18 14:54:16 +00:00
|
|
|
cls: 'modal-dlg',
|
|
|
|
buttons: ['ok', 'cancel']
|
2019-08-21 10:55:40 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
initialize : function(options) {
|
|
|
|
_.extend(this.options, {
|
|
|
|
title: this.textTitle
|
|
|
|
}, options || {});
|
|
|
|
|
2019-08-26 13:38:08 +00:00
|
|
|
this._state = {
|
2019-09-02 07:20:17 +00:00
|
|
|
width: null,
|
|
|
|
height: null
|
2019-08-26 13:38:08 +00:00
|
|
|
};
|
|
|
|
|
2019-08-21 10:55:40 +00:00
|
|
|
this.template = [
|
|
|
|
'<div class="box">',
|
2019-09-13 10:36:22 +00:00
|
|
|
'<div id="radio-fit-to" style="margin-bottom: 4px;"></div>',
|
2019-09-13 06:57:57 +00:00
|
|
|
'<div style="padding-left: 22px;">',
|
|
|
|
'<div>',
|
|
|
|
'<label style="height: 22px;width: 45px;padding-top: 4px;display: inline-block;margin-bottom: 4px;">' + this.textWidth + '</label>',
|
|
|
|
'<div id="scale-width" style="display: inline-block;margin-bottom: 4px;"></div>',
|
|
|
|
'</div>',
|
|
|
|
'<div>',
|
2019-09-13 10:36:22 +00:00
|
|
|
'<label style="height: 22px;width: 45px;padding-top: 4px;display: inline-block;margin-bottom: 16px;">' + this.textHeight + '</label>',
|
|
|
|
'<div id="scale-height" style="display: inline-block;margin-bottom: 16px;"></div>',
|
2019-09-13 06:57:57 +00:00
|
|
|
'</div>',
|
|
|
|
'</div>',
|
2019-09-13 10:36:22 +00:00
|
|
|
'<div id="radio-scale-to" style="margin-bottom: 6px;"></div>',
|
|
|
|
'<div id="scale" style="padding-left: 22px; margin-bottom: 6px;"></div>',
|
2019-08-21 10:55:40 +00:00
|
|
|
'</div>'
|
|
|
|
].join('');
|
|
|
|
|
|
|
|
this.options.tpl = _.template(this.template)(this.options);
|
|
|
|
|
2019-08-28 10:12:52 +00:00
|
|
|
this.api = this.options.api;
|
2019-09-05 07:52:49 +00:00
|
|
|
this._originalProps = this.options.props;
|
2019-08-28 10:12:52 +00:00
|
|
|
|
2019-09-13 06:57:57 +00:00
|
|
|
this.arrDataScale = [
|
|
|
|
{displayValue: this.textAuto, value: 0},
|
|
|
|
{displayValue: '1 ' + this.textOnePage, value: 1},
|
|
|
|
{displayValue: '2 ' + this.textFewPages, value: 2},
|
|
|
|
{displayValue: '3 ' + this.textFewPages, value: 3},
|
|
|
|
{displayValue: '4 ' + this.textFewPages, value: 4},
|
|
|
|
{displayValue: '5 ' + this.textManyPages, value: 5},
|
|
|
|
{displayValue: '6 ' + this.textManyPages, value: 6},
|
|
|
|
{displayValue: '7 ' + this.textManyPages, value: 7},
|
|
|
|
{displayValue: '8 ' + this.textManyPages, value: 8},
|
|
|
|
{displayValue: '9 ' + this.textManyPages, value: 9}
|
|
|
|
];
|
|
|
|
|
2019-08-21 10:55:40 +00:00
|
|
|
Common.UI.Window.prototype.initialize.call(this, this.options);
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
Common.UI.Window.prototype.render.call(this);
|
|
|
|
|
2019-09-13 06:57:57 +00:00
|
|
|
this.radioFitTo = new Common.UI.RadioBox({
|
|
|
|
el: $('#radio-fit-to'),
|
|
|
|
labelText: this.textFitTo,
|
|
|
|
name: 'asc-radio-scale'
|
2019-08-22 07:47:08 +00:00
|
|
|
});
|
2019-09-13 06:57:57 +00:00
|
|
|
this.radioFitTo.on('change', _.bind(this.onRadioScale, this, 'fitto'));
|
2019-08-22 07:47:08 +00:00
|
|
|
|
2019-09-13 06:57:57 +00:00
|
|
|
this.radioScaleTo = new Common.UI.RadioBox({
|
|
|
|
el: $('#radio-scale-to'),
|
|
|
|
labelText: this.textScaleTo,
|
|
|
|
name: 'asc-radio-scale'
|
2019-08-22 07:47:08 +00:00
|
|
|
});
|
2019-09-13 06:57:57 +00:00
|
|
|
this.radioScaleTo.on('change', _.bind(this.onRadioScale, this, 'scaleto'));
|
|
|
|
|
|
|
|
this.cmbScaleWidth = new Common.UI.ComboBox({
|
|
|
|
el: $('#scale-width'),
|
|
|
|
cls: 'input-group-nr',
|
|
|
|
style: 'width: 90px;',
|
|
|
|
menuStyle : 'min-width: 90px;',
|
|
|
|
editable: true,
|
|
|
|
data: this.arrDataScale,
|
|
|
|
scrollAlwaysVisible: true
|
2019-09-18 10:13:22 +00:00
|
|
|
}).on('selected', _.bind(this.changeWidthHeight, this, 'width'))
|
|
|
|
.on('changed:after', _.bind(this.changeWidthHeight, this, 'width'))
|
|
|
|
.on('changed:before', _.bind(this.onChangeComboScale, this, 'width'));
|
2019-09-13 06:57:57 +00:00
|
|
|
|
|
|
|
this.cmbScaleHeight = new Common.UI.ComboBox({
|
|
|
|
el: $('#scale-height'),
|
|
|
|
cls: 'input-group-nr',
|
|
|
|
style: 'width: 90px;',
|
|
|
|
menuStyle : 'min-width: 90px;',
|
|
|
|
editable: true,
|
|
|
|
data: this.arrDataScale,
|
|
|
|
scrollAlwaysVisible: true
|
2019-09-18 10:13:22 +00:00
|
|
|
}).on('selected', _.bind(this.changeWidthHeight, this, 'height'))
|
|
|
|
.on('changed:after', _.bind(this.changeWidthHeight, this, 'height'))
|
|
|
|
.on('changed:before', _.bind(this.onChangeComboScale, this, 'height'));
|
2019-08-22 07:47:08 +00:00
|
|
|
|
|
|
|
this.spnScale = new Common.UI.MetricSpinner({
|
|
|
|
el : $('#scale'),
|
2019-09-02 11:10:56 +00:00
|
|
|
step : 1,
|
2019-09-13 06:57:57 +00:00
|
|
|
width : 75,
|
2019-08-22 07:47:08 +00:00
|
|
|
defaultUnit : "%",
|
|
|
|
maxValue : 400,
|
2019-09-02 07:20:17 +00:00
|
|
|
minValue : 10,
|
|
|
|
defaultValue: '100 %'
|
2019-09-13 06:57:57 +00:00
|
|
|
}).on('change', _.bind(function (field) {
|
|
|
|
this.radioScaleTo.setValue(true, true);
|
|
|
|
this.cmbScaleHeight.setValue(0,true);
|
|
|
|
this.cmbScaleWidth.setValue(0,true);
|
|
|
|
this._state.width = 0;
|
|
|
|
this._state.height = 0;
|
|
|
|
}, this));
|
2019-08-22 07:47:08 +00:00
|
|
|
|
|
|
|
var $window = this.getChild();
|
|
|
|
$window.find('.dlg-btn').on('click', _.bind(this.onBtnClick, this));
|
2019-08-21 10:55:40 +00:00
|
|
|
|
2019-08-28 10:12:52 +00:00
|
|
|
this.afterRender();
|
2019-08-21 10:55:40 +00:00
|
|
|
},
|
|
|
|
|
2019-08-28 10:12:52 +00:00
|
|
|
afterRender: function() {
|
2019-09-05 07:52:49 +00:00
|
|
|
this._setDefaults(this._originalProps);
|
2019-08-22 07:47:08 +00:00
|
|
|
},
|
|
|
|
|
2019-08-28 11:05:31 +00:00
|
|
|
_handleInput: function(state) {
|
2019-08-28 10:12:52 +00:00
|
|
|
if (this.options.handler) {
|
|
|
|
this.options.handler.call(this, state, (state == 'ok') ? this.getSettings() : undefined);
|
|
|
|
}
|
|
|
|
this.close();
|
2019-08-22 07:47:08 +00:00
|
|
|
},
|
|
|
|
|
2019-08-28 11:05:31 +00:00
|
|
|
onBtnClick: function(event) {
|
|
|
|
this._handleInput(event.currentTarget.attributes['result'].value);
|
|
|
|
},
|
|
|
|
|
|
|
|
onPrimary: function() {
|
|
|
|
this._handleInput('ok');
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2019-09-18 10:13:22 +00:00
|
|
|
changeWidthHeight: function (type, field) {
|
|
|
|
var value = field.getValue();
|
|
|
|
if (typeof(value) === 'string') {
|
|
|
|
value = parseInt(value);
|
|
|
|
if (isNaN(value)) {
|
|
|
|
value = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (type === 'width') {
|
|
|
|
this._state.width = value;
|
|
|
|
} else {
|
|
|
|
this._state.height = value;
|
|
|
|
}
|
|
|
|
if ((this._state.width === 0 || this._state.width === null) && (this._state.height === 0 || this._state.height === null)) {
|
|
|
|
this.radioScaleTo.setValue(true, true);
|
|
|
|
} else {
|
|
|
|
this.radioFitTo.setValue(true, true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-09-13 06:57:57 +00:00
|
|
|
onRadioScale: function(type, field, newValue) {
|
|
|
|
if (type === 'scaleto') {
|
|
|
|
this.cmbScaleHeight.setValue(0,true);
|
|
|
|
this._state.height = 0;
|
|
|
|
this.cmbScaleWidth.setValue(0,true);
|
|
|
|
this._state.width = 0;
|
2019-09-02 07:20:17 +00:00
|
|
|
} else {
|
2019-09-13 06:57:57 +00:00
|
|
|
this.cmbScaleHeight.setValue(0,true);
|
|
|
|
this._state.height = 0;
|
|
|
|
this.cmbScaleWidth.setValue(1,true);
|
|
|
|
this._state.width = 1;
|
2019-08-26 13:38:08 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-09-05 07:52:49 +00:00
|
|
|
_setDefaults: function (props) {
|
2019-08-28 10:12:52 +00:00
|
|
|
if (this.api) {
|
2019-09-05 07:52:49 +00:00
|
|
|
var pageProps = props ? props : this.api.asc_getPageOptions();
|
|
|
|
var pageSetup = pageProps.asc_getPageSetup(),
|
2019-08-28 10:12:52 +00:00
|
|
|
width = pageSetup.asc_getFitToWidth(),
|
|
|
|
height = pageSetup.asc_getFitToHeight(),
|
|
|
|
scale = pageSetup.asc_getScale();
|
2019-09-02 07:20:17 +00:00
|
|
|
this._state.width = (width !== null && width !== 0) ? width : null;
|
|
|
|
this._state.height = (height !== null && height !== 0) ? height : null;
|
2019-08-28 10:12:52 +00:00
|
|
|
|
2019-09-13 06:57:57 +00:00
|
|
|
width = (width !== null) ? width : 0;
|
|
|
|
height = (height !== null) ? height : 0;
|
|
|
|
|
|
|
|
if (width === 0 && height === 0) {
|
|
|
|
this.radioScaleTo.setValue(true,true);
|
|
|
|
} else {
|
|
|
|
this.radioFitTo.setValue(true,true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_.findWhere(this.arrDataScale, {value: width})) {
|
|
|
|
this.cmbScaleWidth.setValue(width);
|
|
|
|
} else {
|
|
|
|
this.cmbScaleWidth.setRawValue(width.toString() + ' ' + this.getTextPages(width));
|
|
|
|
}
|
|
|
|
if (_.findWhere(this.arrDataScale, {value: height})) {
|
|
|
|
this.cmbScaleHeight.setValue(height);
|
|
|
|
} else {
|
|
|
|
this.cmbScaleHeight.setRawValue(height.toString() + ' ' + this.getTextPages(height));
|
|
|
|
}
|
|
|
|
|
|
|
|
this.spnScale.setValue((scale !== null) ? scale : '', true);
|
2019-08-28 10:12:52 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
getSettings: function () {
|
|
|
|
var props = {};
|
2019-09-13 06:57:57 +00:00
|
|
|
props.width = (this._state.width === null) ? null : this._state.width;
|
|
|
|
props.height = (this._state.height === null) ? null : this._state.height;
|
2019-09-02 07:20:17 +00:00
|
|
|
props.scale = this.spnScale.getNumberValue();
|
2019-08-28 10:12:52 +00:00
|
|
|
return props;
|
|
|
|
},
|
|
|
|
|
2019-09-13 06:57:57 +00:00
|
|
|
getTextPages: function (val) {
|
|
|
|
var lastNum = val % 10,
|
|
|
|
textPage;
|
|
|
|
if (lastNum > 0 && lastNum < 1.001) {
|
|
|
|
textPage = this.textOnePage;
|
|
|
|
} else if (lastNum > 0 && lastNum < 4.001) {
|
|
|
|
textPage = this.textFewPages;
|
|
|
|
} else {
|
|
|
|
textPage = this.textManyPages;
|
|
|
|
}
|
|
|
|
return textPage;
|
|
|
|
},
|
|
|
|
|
|
|
|
onChangeComboScale: function(type, combo, record, e) {
|
2019-09-13 10:36:22 +00:00
|
|
|
var me = this,
|
|
|
|
textPage,
|
|
|
|
value = record.value.toLowerCase();
|
|
|
|
var exprAuto = new RegExp('^\\s*(' + me.textAuto.toLowerCase() + ')\\s*$');
|
|
|
|
if (exprAuto.exec(value)) {
|
|
|
|
value = 0;
|
|
|
|
} else {
|
|
|
|
value = parseInt(value);
|
|
|
|
!isNaN(value) && (textPage = me.getTextPages(value));
|
|
|
|
}
|
|
|
|
if (isNaN(value) || value < 0 || value > 32767) {
|
2019-09-13 06:57:57 +00:00
|
|
|
Common.UI.error({
|
|
|
|
msg: me.textError,
|
|
|
|
callback: function() {
|
|
|
|
_.defer(function(btn) {
|
|
|
|
Common.NotificationCenter.trigger('edit:complete', me);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
});
|
|
|
|
value = (type === 'width') ? me._state.width : me._state.height;
|
|
|
|
textPage = me.getTextPages(value);
|
|
|
|
}
|
|
|
|
if (value === null) value = 0;
|
|
|
|
if (type === 'width') {
|
|
|
|
if (_.findWhere(me.arrDataScale, {value: value})) {
|
|
|
|
me.cmbScaleWidth.setValue(value);
|
|
|
|
} else {
|
|
|
|
me.cmbScaleWidth.setValue('');
|
|
|
|
me.cmbScaleWidth.setRawValue(value.toString() + ' ' + textPage);
|
|
|
|
}
|
|
|
|
me._state.width = value;
|
|
|
|
} else if (type === 'height') {
|
|
|
|
if (_.findWhere(me.arrDataScale, {value: value})) {
|
|
|
|
me.cmbScaleHeight.setValue(value);
|
|
|
|
} else {
|
|
|
|
me.cmbScaleHeight.setValue('');
|
|
|
|
me.cmbScaleHeight.setRawValue(value.toString() + ' ' + textPage);
|
|
|
|
}
|
|
|
|
me._state.height = value;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-08-22 07:47:08 +00:00
|
|
|
textTitle: 'Scale Settings',
|
|
|
|
textWidth: 'Width',
|
|
|
|
textHeight: 'Height',
|
2019-09-13 10:36:22 +00:00
|
|
|
textAuto: 'Auto',
|
2019-09-13 06:57:57 +00:00
|
|
|
textOnePage: 'page',
|
|
|
|
textFewPages: 'pages',
|
|
|
|
textManyPages: 'pages',
|
|
|
|
textError: 'The entered value is incorrect.',
|
|
|
|
textScaleTo: 'Scale To',
|
|
|
|
textFitTo: 'Fit To'
|
2019-08-22 07:47:08 +00:00
|
|
|
|
2019-08-21 10:55:40 +00:00
|
|
|
}, SSE.Views.ScaleDialog || {}))
|
|
|
|
});
|