2017-01-18 14:53:56 +00:00
/ *
*
2019-01-17 13:05:03 +00:00
* ( c ) Copyright Ascensio System SIA 2010 - 2019
2017-01-18 14:53:56 +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
*
2019-01-17 13:00:34 +00:00
* You can contact Ascensio System SIA at 20 A - 12 Ernesta Birznieka - Upisha
* street , Riga , Latvia , EU , LV - 1050.
2017-01-18 14:53:56 +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
*
* /
/ * *
* ChartSettingsAdvanced . js
*
* Created by Julia Radzhabova on 1 / 18 / 17
2018-03-01 12:16:38 +00:00
* Copyright ( c ) 2018 Ascensio System SIA . All rights reserved .
2017-01-18 14:53:56 +00:00
*
* /
define ( [ 'text!presentationeditor/main/app/template/ChartSettingsAdvanced.template' ,
'common/main/lib/view/AdvancedSettingsWindow' ,
'common/main/lib/component/InputField'
] , function ( contentTemplate ) {
'use strict' ;
PE . Views . ChartSettingsAdvanced = Common . Views . AdvancedSettingsWindow . extend ( _ . extend ( {
options : {
contentWidth : 300 ,
height : 342 ,
toggleGroup : 'chart-adv-settings-group' ,
properties : null ,
2022-01-28 17:47:56 +00:00
storageName : 'pe-chart-settings-adv-category' ,
sizeMax : { width : 55.88 , height : 55.88 } ,
2017-01-18 14:53:56 +00:00
} ,
initialize : function ( options ) {
_ . extend ( this . options , {
title : this . textTitle ,
items : [
2022-01-28 17:47:56 +00:00
{ panelId : 'id-adv-chart-placement' , panelCaption : this . textPlacement } ,
2017-01-18 14:53:56 +00:00
{ panelId : 'id-adv-chart-alttext' , panelCaption : this . textAlt }
] ,
contentTemplate : _ . template ( contentTemplate ) ( {
scope : this
} )
} , options ) ;
Common . Views . AdvancedSettingsWindow . prototype . initialize . call ( this , this . options ) ;
2022-01-28 17:47:56 +00:00
this . spinners = [ ] ;
2017-01-18 14:53:56 +00:00
this . _originalProps = this . options . chartProps ;
2022-01-28 17:47:56 +00:00
this . slideSize = this . options . slideSize ;
2017-01-18 14:53:56 +00:00
this . _changedProps = null ;
} ,
render : function ( ) {
Common . Views . AdvancedSettingsWindow . prototype . render . call ( this ) ;
var me = this ;
2022-01-28 17:47:56 +00:00
// Placement
this . spnWidth = new Common . UI . MetricSpinner ( {
el : $ ( '#chart-advanced-spin-width' ) ,
step : . 1 ,
width : 100 ,
defaultUnit : "cm" ,
value : '3 cm' ,
maxValue : 55.88 ,
minValue : 0
} ) ;
this . spnWidth . on ( 'change' , _ . bind ( function ( field ) {
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 ) ;
}
if ( this . _changedProps ) {
this . _changedProps . put _Width ( Common . Utils . Metric . fnRecalcToMM ( field . getNumberValue ( ) ) ) ;
this . _changedProps . put _Height ( Common . Utils . Metric . fnRecalcToMM ( this . spnHeight . getNumberValue ( ) ) ) ;
}
} , this ) ) ;
this . spinners . push ( this . spnWidth ) ;
this . spnHeight = new Common . UI . MetricSpinner ( {
el : $ ( '#chart-advanced-spin-height' ) ,
step : . 1 ,
width : 100 ,
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 ) ;
}
if ( this . _changedProps ) {
this . _changedProps . put _Height ( Common . Utils . Metric . fnRecalcToMM ( field . getNumberValue ( ) ) ) ;
this . _changedProps . put _Width ( Common . Utils . Metric . fnRecalcToMM ( this . spnWidth . getNumberValue ( ) ) ) ;
}
} , this ) ) ;
this . spinners . push ( this . spnHeight ) ;
this . btnRatio = new Common . UI . Button ( {
parentEl : $ ( '#chart-advanced-button-ratio' ) ,
cls : 'btn-toolbar' ,
iconCls : 'toolbar__icon advanced-btn-ratio' ,
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 ( ) ;
}
if ( this . _changedProps ) {
this . _changedProps . asc _putLockAspect ( btn . pressed ) ;
}
} , this ) ) ;
this . spnX = new Common . UI . MetricSpinner ( {
el : $ ( '#chart-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 : $ ( '#chart-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 ) ;
this . cmbFromX = new Common . UI . ComboBox ( {
el : $ ( '#chart-advanced-combo-from-x' ) ,
cls : 'input-group-nr' ,
style : "width: 100px;" ,
menuStyle : 'min-width: 100px;' ,
data : [
{ value : 'left' , displayValue : this . textTopLeftCorner } ,
{ value : 'center' , displayValue : this . textCenter }
]
} ) ;
this . cmbFromY = new Common . UI . ComboBox ( {
el : $ ( '#chart-advanced-combo-from-y' ) ,
cls : 'input-group-nr' ,
style : "width: 100px;" ,
menuStyle : 'min-width: 100px;' ,
data : [
{ value : 'left' , displayValue : this . textTopLeftCorner } ,
{ value : 'center' , displayValue : this . textCenter }
]
} ) ;
2017-01-18 14:53:56 +00:00
// Alt Text
this . inputAltTitle = new Common . UI . InputField ( {
el : $ ( '#chart-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 ;
} ) ;
this . afterRender ( ) ;
} ,
afterRender : function ( ) {
2022-01-28 17:47:56 +00:00
this . updateMetricUnit ( ) ;
2017-01-18 14:53:56 +00:00
this . _setDefaults ( this . _originalProps ) ;
if ( this . storageName ) {
var value = Common . localStorage . getItem ( this . storageName ) ;
this . setActiveCategory ( ( value !== null ) ? parseInt ( value ) : 0 ) ;
}
} ,
2020-10-13 19:49:04 +00:00
getFocusedComponents : function ( ) {
return [
this . inputAltTitle , this . textareaAltDescription // 0 tab
] ;
} ,
onCategoryClick : function ( btn , index ) {
Common . Views . AdvancedSettingsWindow . prototype . onCategoryClick . call ( this , btn , index ) ;
var me = this ;
setTimeout ( function ( ) {
switch ( index ) {
case 0 :
me . inputAltTitle . focus ( ) ;
break ;
}
} , 10 ) ;
} ,
2017-01-18 14:53:56 +00:00
_setDefaults : function ( props ) {
if ( props ) {
2022-01-28 17:47:56 +00:00
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 ) ;
var value = props . asc _getLockAspect ( ) ;
this . btnRatio . toggle ( value ) ;
if ( props . get _Height ( ) > 0 )
this . _nRatio = props . get _Width ( ) / props . get _Height ( ) ;
this . cmbFromX . setValue ( 'left' ) ;
this . cmbFromY . setValue ( 'left' ) ;
/ * i f ( p r o p s . g e t _ P o s i t i o n ( ) ) {
var Position = { X : props . get _Position ( ) . get _X ( ) , Y : props . get _Position ( ) . get _Y ( ) } ;
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 ) ;
} else { * /
this . spnX . setValue ( '' , true ) ;
this . spnY . setValue ( '' , true ) ;
/*}*/
2017-01-18 14:53:56 +00:00
var value = props . asc _getTitle ( ) ;
this . inputAltTitle . setValue ( value ? value : '' ) ;
value = props . asc _getDescription ( ) ;
this . textareaAltDescription . val ( value ? value : '' ) ;
this . _changedProps = new Asc . CAscChartProp ( ) ;
}
} ,
getSettings : function ( ) {
2022-01-28 17:47:56 +00:00
/ * v a r P o s i t i o n = n e w A s c . C P o s i t i o n ( ) ;
if ( this . spnX . getValue ( ) !== '' ) {
var x = Common . Utils . Metric . fnRecalcToMM ( this . spnX . getNumberValue ( ) ) ;
if ( this . cmbFromX . getValue ( ) === 'center' ) {
x = ( this . slideSize . width / 36000 ) / 2 + x ;
}
Position . put _X ( x ) ;
}
if ( this . spnY . getValue ( ) !== '' ) {
var y = Common . Utils . Metric . fnRecalcToMM ( this . spnY . getNumberValue ( ) ) ;
if ( this . cmbFromY . getValue ( ) === 'center' ) {
y = ( this . slideSize . height / 36000 ) / 2 + y ;
}
Position . put _Y ( y ) ;
}
this . _changedProps . put _Position ( Position ) ; * /
2017-01-18 14:53:56 +00:00
if ( this . isAltTitleChanged )
this . _changedProps . asc _putTitle ( this . inputAltTitle . getValue ( ) ) ;
if ( this . isAltDescChanged )
this . _changedProps . asc _putDescription ( this . textareaAltDescription . val ( ) ) ;
return { chartProps : this . _changedProps } ;
} ,
2022-01-28 17:47:56 +00:00
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 ) ;
}
}
this . sizeMax = {
width : Common . Utils . Metric . fnRecalcFromMM ( this . options . sizeMax . width * 10 ) ,
height : Common . Utils . Metric . fnRecalcFromMM ( this . options . sizeMax . height * 10 )
} ;
} ,
2017-01-18 14:53:56 +00:00
textTitle : 'Chart - Advanced Settings' ,
textAlt : 'Alternative Text' ,
textAltTitle : 'Title' ,
textAltDescription : 'Description' ,
2022-01-28 17:47:56 +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.' ,
textPlacement : 'Placement' ,
textSize : 'Size' ,
textWidth : 'Width' ,
textHeight : 'Height' ,
textPosition : 'Position' ,
textHorizontal : 'Horizontal' ,
textVertical : 'Vertical' ,
textFrom : 'From' ,
textTopLeftCorner : 'Top Left Corner' ,
textCenter : 'Center' ,
textKeepRatio : 'Constant Proportions' ,
2017-01-18 14:53:56 +00:00
} , PE . Views . ChartSettingsAdvanced || { } ) ) ;
} ) ;