web-apps/apps/presentationeditor/main/app/view/ImageSettingsAdvanced.js

366 lines
15 KiB
JavaScript
Raw Normal View History

2016-04-01 13:17:09 +00:00
/*
*
* (c) Copyright Ascensio System SIA 2010-2019
2016-04-01 13:17: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.
2016-04-01 13:17: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
*
*/
2016-03-11 00:48:53 +00:00
/**
* ImageSettingsAdvanced.js
*
* Created by Julia Radzhabova on 4/16/14
2018-03-01 12:16:38 +00:00
* Copyright (c) 2018 Ascensio System SIA. All rights reserved.
2016-03-11 00:48:53 +00:00
*
*/
define([ 'text!presentationeditor/main/app/template/ImageSettingsAdvanced.template',
'common/main/lib/view/AdvancedSettingsWindow',
2018-08-30 15:41:09 +00:00
'common/main/lib/component/MetricSpinner',
'common/main/lib/component/CheckBox'
2016-03-11 00:48:53 +00:00
], function (contentTemplate) {
'use strict';
PE.Views.ImageSettingsAdvanced = Common.Views.AdvancedSettingsWindow.extend(_.extend({
options: {
alias: 'ImageSettingsAdvanced',
contentWidth: 340,
height: 342,
2016-03-11 00:48:53 +00:00
sizeOriginal: {width: 0, height: 0},
2016-04-21 11:47:28 +00:00
sizeMax: {width: 55.88, height: 55.88},
storageName: 'pe-img-settings-adv-category'
2016-03-11 00:48:53 +00:00
},
initialize : function(options) {
_.extend(this.options, {
title: this.textTitle,
items: [
{panelId: 'id-adv-image-size', panelCaption: this.textPlacement},
2018-08-30 15:41:09 +00:00
{panelId: 'id-adv-image-rotate', panelCaption: this.textRotation},
{panelId: 'id-adv-image-alttext', panelCaption: this.textAlt}
],
contentTemplate: _.template(contentTemplate)({
scope: this
})
2016-03-11 00:48:53 +00:00
}, options);
2016-03-11 00:48:53 +00:00
Common.Views.AdvancedSettingsWindow.prototype.initialize.call(this, this.options);
this.spinners = [];
this._nRatio = 1;
2019-04-22 14:29:30 +00:00
this._isDefaultSize = false;
2016-03-11 00:48:53 +00:00
this._originalProps = this.options.imageProps;
},
render: function() {
Common.Views.AdvancedSettingsWindow.prototype.render.call(this);
var me = this;
this.spnWidth = new Common.UI.MetricSpinner({
el: $('#image-advanced-spin-width'),
step: .1,
width: 80,
defaultUnit : "cm",
value: '3 cm',
maxValue: 55.88,
minValue: 0
});
this.spnWidth.on('change', _.bind(function(field, newValue, oldValue, eOpts){
if (this.btnRatio.pressed) {
var w = field.getNumberValue();
var h = w/this._nRatio;
if (h>this.sizeMax.height) {
h = this.sizeMax.height;
w = h * this._nRatio;
this.spnWidth.setValue(w, true);
}
this.spnHeight.setValue(h, true);
}
2019-04-22 14:29:30 +00:00
this._isDefaultSize = false;
2016-03-11 00:48:53 +00:00
}, this));
this.spinners.push(this.spnWidth);
this.spnHeight = new Common.UI.MetricSpinner({
el: $('#image-advanced-spin-height'),
step: .1,
width: 80,
defaultUnit : "cm",
value: '3 cm',
maxValue: 55.88,
minValue: 0
});
this.spnHeight.on('change', _.bind(function(field, newValue, oldValue, eOpts){
var h = field.getNumberValue(), w = null;
if (this.btnRatio.pressed) {
w = h * this._nRatio;
if (w>this.sizeMax.width) {
w = this.sizeMax.width;
h = w/this._nRatio;
this.spnHeight.setValue(h, true);
}
this.spnWidth.setValue(w, true);
}
2019-04-22 14:29:30 +00:00
this._isDefaultSize = false;
2016-03-11 00:48:53 +00:00
}, this));
this.spinners.push(this.spnHeight);
this.btnOriginalSize = new Common.UI.Button({
el: $('#image-advanced-button-original-size')
});
this.btnOriginalSize.on('click', _.bind(function(btn, e) {
2021-06-22 12:42:21 +00:00
this.spnAngle.setValue(0);
2016-03-11 00:48:53 +00:00
this.spnWidth.setValue(this.sizeOriginal.width, true);
this.spnHeight.setValue(this.sizeOriginal.height, true);
this._nRatio = this.sizeOriginal.width/this.sizeOriginal.height;
2019-04-22 14:29:30 +00:00
this._isDefaultSize = true;
2016-03-11 00:48:53 +00:00
}, this));
this.btnRatio = new Common.UI.Button({
2020-04-29 07:36:53 +00:00
parentEl: $('#image-advanced-button-ratio'),
2016-03-11 00:48:53 +00:00
cls: 'btn-toolbar',
iconCls: 'toolbar__icon advanced-btn-ratio',
2016-03-11 00:48:53 +00:00
style: 'margin-bottom: 1px;',
enableToggle: true,
hint: this.textKeepRatio
});
this.btnRatio.on('click', _.bind(function(btn, e) {
if (btn.pressed && this.spnHeight.getNumberValue()>0) {
this._nRatio = this.spnWidth.getNumberValue()/this.spnHeight.getNumberValue();
}
}, this));
this.spnX = new Common.UI.MetricSpinner({
el: $('#image-advanced-spin-x'),
step: .1,
width: 85,
defaultUnit : "cm",
defaultValue : 0,
value: '0 cm',
maxValue: 55.87,
minValue: -55.87
});
this.spinners.push(this.spnX);
this.spnY = new Common.UI.MetricSpinner({
el: $('#image-advanced-spin-y'),
step: .1,
width: 85,
defaultUnit : "cm",
defaultValue : 0,
value: '0 cm',
maxValue: 55.87,
minValue: -55.87
});
this.spinners.push(this.spnY);
2018-08-30 15:41:09 +00:00
// Rotation
this.spnAngle = new Common.UI.MetricSpinner({
el: $('#image-advanced-spin-angle'),
step: 1,
width: 80,
defaultUnit : "°",
value: '0 °',
maxValue: 3600,
minValue: -3600
});
this.chFlipHor = new Common.UI.CheckBox({
el: $('#image-advanced-checkbox-hor'),
labelText: this.textHorizontally
});
this.chFlipVert = new Common.UI.CheckBox({
el: $('#image-advanced-checkbox-vert'),
labelText: this.textVertically
});
// Alt Text
this.inputAltTitle = new Common.UI.InputField({
el : $('#image-advanced-alt-title'),
allowBlank : true,
validateOnBlur: false,
style : 'width: 100%;'
}).on('changed:after', function() {
me.isAltTitleChanged = true;
});
this.textareaAltDescription = this.$window.find('textarea');
this.textareaAltDescription.keydown(function (event) {
if (event.keyCode == Common.UI.Keys.RETURN) {
event.stopPropagation();
}
me.isAltDescChanged = true;
});
2016-03-11 00:48:53 +00:00
this.afterRender();
},
getFocusedComponents: function() {
return [
2021-04-14 22:02:11 +00:00
this.spnWidth, this.spnHeight, this.btnOriginalSize, this.spnX, this.spnY,// 0 tab
2021-04-13 15:20:08 +00:00
this.spnAngle, this.chFlipHor, this.chFlipVert, // 1 tab
this.inputAltTitle, this.textareaAltDescription // 2 tab
];
},
onCategoryClick: function(btn, index) {
Common.Views.AdvancedSettingsWindow.prototype.onCategoryClick.call(this, btn, index);
var me = this;
setTimeout(function(){
switch (index) {
case 0:
me.spnWidth.focus();
break;
case 1:
me.spnAngle.focus();
break;
case 2:
me.inputAltTitle.focus();
break;
}
}, 10);
},
2016-03-11 00:48:53 +00:00
afterRender: function() {
this.updateMetricUnit();
this._setDefaults(this._originalProps);
2016-04-21 11:47:28 +00:00
if (this.storageName) {
var value = Common.localStorage.getItem(this.storageName);
this.setActiveCategory((value!==null) ? parseInt(value) : 0);
}
2016-03-11 00:48:53 +00:00
},
_setDefaults: function(props) {
if (props ){
this.spnWidth.setMaxValue(this.sizeMax.width);
this.spnHeight.setMaxValue(this.sizeMax.height);
this.spnWidth.setValue(Common.Utils.Metric.fnRecalcFromMM(props.get_Width()).toFixed(2), true);
this.spnHeight.setValue(Common.Utils.Metric.fnRecalcFromMM(props.get_Height()).toFixed(2), true);
this.btnOriginalSize.setDisabled(props.get_ImageUrl()===null || props.get_ImageUrl()===undefined);
2016-05-24 09:07:44 +00:00
var value = props.asc_getLockAspect();
this.btnRatio.toggle(value);
2016-09-08 12:04:31 +00:00
if (props.get_Height()>0)
this._nRatio = props.get_Width()/props.get_Height();
2016-03-11 00:48:53 +00:00
if (props.get_Position()) {
var Position = {X: props.get_Position().get_X(), Y: props.get_Position().get_Y()};
2016-12-01 14:29:44 +00:00
this.spnX.setValue((Position.X !== null && Position.X !== undefined) ? Common.Utils.Metric.fnRecalcFromMM(Position.X) : '', true);
this.spnY.setValue((Position.Y !== null && Position.Y !== undefined) ? Common.Utils.Metric.fnRecalcFromMM(Position.Y) : '', true);
2016-03-11 00:48:53 +00:00
} else {
this.spnX.setValue('', true);
this.spnY.setValue('', true);
}
2018-08-30 15:41:09 +00:00
value = props.asc_getRot();
this.spnAngle.setValue((value==undefined || value===null) ? '' : Math.floor(value*180/3.14159265358979+0.5), true);
this.chFlipHor.setValue(props.asc_getFlipH());
this.chFlipVert.setValue(props.asc_getFlipV());
value = props.asc_getTitle();
this.inputAltTitle.setValue(value ? value : '');
value = props.asc_getDescription();
this.textareaAltDescription.val(value ? value : '');
2019-06-14 07:53:20 +00:00
var pluginGuid = props.asc_getPluginGuid();
this.btnsCategory[1].setVisible(pluginGuid === null || pluginGuid === undefined); // Rotation
2016-03-11 00:48:53 +00:00
}
},
getSettings: function() {
2016-04-18 12:21:15 +00:00
var properties = new Asc.asc_CImgProperty();
2016-03-11 00:48:53 +00:00
if (this.spnHeight.getValue()!=='')
properties.put_Height(Common.Utils.Metric.fnRecalcToMM(this.spnHeight.getNumberValue()));
if (this.spnWidth.getValue()!=='')
properties.put_Width(Common.Utils.Metric.fnRecalcToMM(this.spnWidth.getNumberValue()));
2016-05-24 09:07:44 +00:00
properties.asc_putLockAspect(this.btnRatio.pressed);
2019-04-22 14:29:30 +00:00
properties.put_ResetCrop(this._isDefaultSize);
2016-03-11 00:48:53 +00:00
2016-04-05 12:57:51 +00:00
var Position = new Asc.CPosition();
2016-03-11 00:48:53 +00:00
if (this.spnX.getValue() !== '')
Position.put_X(Common.Utils.Metric.fnRecalcToMM(this.spnX.getNumberValue()));
if (this.spnY.getValue() !== '')
Position.put_Y(Common.Utils.Metric.fnRecalcToMM(this.spnY.getNumberValue()));
properties.put_Position(Position);
if (this.isAltTitleChanged)
properties.asc_putTitle(this.inputAltTitle.getValue());
if (this.isAltDescChanged)
properties.asc_putDescription(this.textareaAltDescription.val());
2018-08-30 15:41:09 +00:00
properties.asc_putRot(this.spnAngle.getNumberValue() * 3.14159265358979 / 180);
properties.asc_putFlipH(this.chFlipHor.getValue()=='checked');
properties.asc_putFlipV(this.chFlipVert.getValue()=='checked');
2016-03-11 00:48:53 +00:00
return { imageProps: properties };
},
updateMetricUnit: function() {
if (this.spinners) {
for (var i=0; i<this.spinners.length; i++) {
var spinner = this.spinners[i];
spinner.setDefaultUnit(Common.Utils.Metric.getCurrentMetricName());
spinner.setStep(Common.Utils.Metric.getCurrentMetric()==Common.Utils.Metric.c_MetricUnits.pt ? 1 : 0.1);
2016-03-11 00:48:53 +00:00
}
}
this.sizeMax = {
width: Common.Utils.Metric.fnRecalcFromMM(this.options.sizeMax.width*10),
height: Common.Utils.Metric.fnRecalcFromMM(this.options.sizeMax.height*10)
};
if (this.options.sizeOriginal)
this.sizeOriginal = {
width: Common.Utils.Metric.fnRecalcFromMM(this.options.sizeOriginal.width),
height: Common.Utils.Metric.fnRecalcFromMM(this.options.sizeOriginal.height)
};
},
2019-11-06 08:11:30 +00:00
textOriginalSize: 'Actual Size',
2016-03-11 00:48:53 +00:00
textPosition: 'Position',
textSize: 'Size',
textWidth: 'Width',
textHeight: 'Height',
textTitle: 'Image - Advanced Settings',
textKeepRatio: 'Constant Proportions',
textPlacement: 'Placement',
textAlt: 'Alternative Text',
textAltTitle: 'Title',
textAltDescription: 'Description',
2018-08-30 15:41:09 +00:00
textAltTip: 'The alternative text-based representation of the visual object information, which will be read to the people with vision or cognitive impairments to help them better understand what information there is in the image, autoshape, chart or table.',
textRotation: 'Rotation',
textAngle: 'Angle',
textFlipped: 'Flipped',
textHorizontally: 'Horizontally',
textVertically: 'Vertically'
2016-03-11 00:48:53 +00:00
}, PE.Views.ImageSettingsAdvanced || {}));
});