2017-01-16 08:48:21 +00:00
/ *
*
2019-01-17 13:05:03 +00:00
* ( c ) Copyright Ascensio System SIA 2010 - 2019
2017-01-16 08:48:21 +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-16 08:48:21 +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
*
* /
/ * *
* FormatSettingsDialog . js
*
* Created by Julia Radzhabova on 13.01 . 2017
2018-03-01 12:16:38 +00:00
* Copyright ( c ) 2018 Ascensio System SIA . All rights reserved .
2017-01-16 08:48:21 +00:00
*
* /
define ( [
'common/main/lib/util/utils' ,
'common/main/lib/component/MetricSpinner' ,
'common/main/lib/component/ComboBox' ,
'common/main/lib/view/AdvancedSettingsWindow'
] , function ( ) { 'use strict' ;
SSE . Views . FormatSettingsDialog = Common . Views . AdvancedSettingsWindow . extend ( _ . extend ( {
options : {
2017-01-17 17:44:36 +00:00
contentWidth : 284 ,
2020-10-13 11:30:52 +00:00
height : 340
2017-01-16 08:48:21 +00:00
} ,
initialize : function ( options ) {
var me = this ;
me . numFormatData = [
2017-01-16 14:06:46 +00:00
{ value : Asc . c _oAscNumFormatType . General , displayValue : this . txtGeneral } ,
{ value : Asc . c _oAscNumFormatType . Number , displayValue : this . txtNumber } ,
{ value : Asc . c _oAscNumFormatType . Scientific , displayValue : this . txtScientific } ,
{ value : Asc . c _oAscNumFormatType . Accounting , displayValue : this . txtAccounting } ,
{ value : Asc . c _oAscNumFormatType . Currency , displayValue : this . txtCurrency } ,
{ value : Asc . c _oAscNumFormatType . Date , displayValue : this . txtDate } ,
{ value : Asc . c _oAscNumFormatType . Time , displayValue : this . txtTime } ,
{ value : Asc . c _oAscNumFormatType . Percent , displayValue : this . txtPercentage } ,
{ value : Asc . c _oAscNumFormatType . Fraction , displayValue : this . txtFraction } ,
{ value : Asc . c _oAscNumFormatType . Text , displayValue : this . txtText } ,
{ value : Asc . c _oAscNumFormatType . Custom , displayValue : this . txtCustom }
2017-01-16 08:48:21 +00:00
] ;
me . FractionData = [
2017-01-16 14:06:46 +00:00
{ displayValue : this . txtUpto1 , value : "# ?/?" } ,
{ displayValue : this . txtUpto2 , value : "# ??/??" } ,
{ displayValue : this . txtUpto3 , value : "# ???/???" } ,
{ displayValue : this . txtAs2 , value : "# ?/2" } ,
{ displayValue : this . txtAs4 , value : "# ?/4" } ,
{ displayValue : this . txtAs8 , value : "# ?/8" } ,
{ displayValue : this . txtAs16 , value : "# ??/16" } ,
{ displayValue : this . txtAs10 , value : "# ?/10" } ,
{ displayValue : this . txtAs100 , value : "# ??/100" }
2017-01-16 08:48:21 +00:00
] ;
2017-01-17 08:19:26 +00:00
me . CurrencySymbolsData = null ;
me . langId = 0x0409 ;
2020-12-07 19:20:22 +00:00
this . api = options . api ;
this . handler = options . handler ;
this . props = options . props ;
this . linked = options . linked || false ;
var height = this . linked ? 360 : 340 ;
2017-01-16 08:48:21 +00:00
_ . extend ( this . options , {
title : this . textTitle ,
2020-12-07 19:20:22 +00:00
height : height ,
2017-01-16 08:48:21 +00:00
template : [
2020-12-07 19:20:22 +00:00
'<div class="box" style="height:' + ( height - 85 ) + 'px;">' ,
2017-01-17 17:44:36 +00:00
'<div class="content-panel" style="padding: 0 10px;"><div class="inner-content">' ,
2017-01-16 08:48:21 +00:00
'<div class="settings-panel active">' ,
2017-01-17 11:04:55 +00:00
'<table cols="1" style="width: 100%;">' ,
2017-01-16 08:48:21 +00:00
'<tr>' ,
2017-01-17 11:04:55 +00:00
'<td style="width:170px;padding-bottom: 3px;">' ,
2017-01-26 12:13:09 +00:00
'<label class="header">' , me . textCategory , '</label>' ,
2017-01-17 17:44:36 +00:00
'<div id="format-settings-combo-format" class="input-group-nr" style="width:264px;"></div>' ,
'</td>' ,
'</tr>' ,
'<tr>' ,
'<td class="padding-large" style="white-space: nowrap;">' ,
2020-12-07 19:20:22 +00:00
'<label class="format-sample" style="vertical-align: middle; margin-right: 4px;">' + me . txtSample + '</label>' ,
'<label class="format-sample" id="format-settings-label-example" style="vertical-align: middle; max-width: 220px; overflow: hidden; text-overflow: ellipsis;">100</label>' ,
2017-01-16 08:48:21 +00:00
'</td>' ,
2017-01-17 11:04:55 +00:00
'</tr>' ,
2020-12-02 14:09:43 +00:00
'<tr class="format-no-code">' ,
2017-01-16 08:48:21 +00:00
'<td class="padding-small">' ,
'</td>' ,
'</tr>' ,
'<tr class="format-decimal">' ,
'<td class="padding-large" style="vertical-align: bottom;">' ,
2017-01-26 12:13:09 +00:00
'<label class="header">' , me . textDecimal , '</label>' ,
2017-01-17 11:04:55 +00:00
'<div id="format-settings-spin-decimal"></div>' ,
2017-01-16 08:48:21 +00:00
'</td>' ,
'</tr>' ,
'<tr class="format-separator">' ,
2017-01-17 11:04:55 +00:00
'<td class="padding-large">' ,
2017-01-16 08:48:21 +00:00
'<div id="format-settings-checkbox-separator"></div>' ,
'</td>' ,
'</tr>' ,
'<tr class="format-symbols">' ,
2017-01-17 11:04:55 +00:00
'<td class="padding-large">' ,
2017-01-26 12:13:09 +00:00
'<label class="header">' , me . textSymbols , '</label>' ,
2017-01-17 17:44:36 +00:00
'<div id="format-settings-combo-symbols" class="input-group-nr" style="width:264px;"></div>' ,
2017-01-17 11:04:55 +00:00
'</td>' ,
'</tr>' ,
'<tr class="format-decimal">' ,
'<td class="padding-large format-negative">' ,
2017-01-26 12:13:09 +00:00
'<label class="header">' , me . textFormat , '</label>' ,
2017-01-17 17:44:36 +00:00
'<div id="format-settings-combo-negative" class="input-group-nr" style="width:264px;"></div>' ,
2017-01-17 11:04:55 +00:00
'</td>' ,
'</tr>' ,
'<tr class="format-type">' ,
'<td class="padding-large">' ,
2017-01-26 12:13:09 +00:00
'<label class="header">' , me . textFormat , '</label>' ,
2017-01-17 17:44:36 +00:00
'<div id="format-settings-combo-type" class="input-group-nr" style="width:264px;"></div>' ,
2017-01-16 08:48:21 +00:00
'</td>' ,
'</tr>' ,
'<tr class="format-code">' ,
2017-01-17 11:04:55 +00:00
'<td colspan="1" class="padding-large">' ,
2017-01-26 12:13:09 +00:00
'<label class="header">' , me . textFormat , '</label>' ,
2020-12-01 16:24:38 +00:00
'<div id="format-settings-txt-code" class="input-group-nr" style="height:22px;width:264px;margin-bottom: 8px;"></div>' ,
2020-12-02 14:09:43 +00:00
'<div id="format-settings-list-code" style="width:264px; height: 116px;"></div>' ,
2017-01-16 08:48:21 +00:00
'</td>' ,
'</tr>' ,
2020-12-07 19:20:22 +00:00
'<tr>' ,
'<td colspan="1">' ,
'<div id="format-settings-chk-linked"></div>' ,
'</td>' ,
'</tr>' ,
2017-01-16 08:48:21 +00:00
'</table>' ,
'</div></div>' ,
'</div>' ,
'</div>' ,
2020-06-05 13:10:48 +00:00
'<div class="separator horizontal"></div>'
2017-01-16 08:48:21 +00:00
] . join ( '' )
} , options ) ;
Common . Views . AdvancedSettingsWindow . prototype . initialize . call ( this , this . options ) ;
2020-12-07 19:20:22 +00:00
this . _state = { hasDecimal : false , hasNegative : false , hasSeparator : false , hasType : false , hasSymbols : false , hasCode : false } ;
2017-01-16 08:48:21 +00:00
this . FormatType = Asc . c _oAscNumFormatType . General ;
2017-01-16 14:06:46 +00:00
this . Format = "General" ;
2017-01-19 11:34:37 +00:00
this . CustomFormat = null ;
2017-01-16 08:48:21 +00:00
} ,
render : function ( ) {
Common . Views . AdvancedSettingsWindow . prototype . render . call ( this ) ;
var me = this ;
this . cmbFormat = new Common . UI . ComboBox ( {
el : $ ( '#format-settings-combo-format' ) ,
cls : 'input-group-nr' ,
2017-01-17 17:44:36 +00:00
menuStyle : 'min-width: 264px;' ,
2017-01-16 08:48:21 +00:00
editable : false ,
2020-09-25 11:44:15 +00:00
data : this . numFormatData ,
takeFocusOnClose : true
2017-01-16 08:48:21 +00:00
} ) ;
this . cmbFormat . setValue ( this . FormatType ) ;
this . cmbFormat . on ( 'selected' , _ . bind ( this . onFormatSelect , this ) ) ;
this . cmbNegative = new Common . UI . ComboBox ( {
el : $ ( '#format-settings-combo-negative' ) ,
cls : 'input-group-nr' ,
2017-04-11 11:05:56 +00:00
menuStyle : 'min-width: 264px;max-height:235px;' ,
2017-01-16 08:48:21 +00:00
editable : false ,
2017-01-16 11:14:47 +00:00
data : [ ] ,
2020-09-25 11:44:15 +00:00
scrollAlwaysVisible : true ,
takeFocusOnClose : true
2017-01-16 08:48:21 +00:00
} ) ;
this . cmbNegative . on ( 'selected' , _ . bind ( this . onNegativeSelect , this ) ) ;
this . spnDecimal = new Common . UI . MetricSpinner ( {
el : $ ( '#format-settings-spin-decimal' ) ,
step : 1 ,
width : 45 ,
defaultUnit : "" ,
value : 2 ,
maxValue : 30 ,
minValue : 0 ,
allowDecimal : false
} ) ;
this . spnDecimal . on ( 'change' , _ . bind ( this . onDecimalChange , this ) ) ;
this . chSeparator = new Common . UI . CheckBox ( {
el : $ ( '#format-settings-checkbox-separator' ) ,
labelText : this . textSeparator
} ) ;
this . chSeparator . on ( 'change' , _ . bind ( this . onSeparatorChange , this ) ) ;
this . cmbSymbols = new Common . UI . ComboBox ( {
el : $ ( '#format-settings-combo-symbols' ) ,
cls : 'input-group-nr' ,
2017-04-11 11:05:56 +00:00
menuStyle : 'min-width: 264px;max-height:235px;' ,
2017-01-16 08:48:21 +00:00
editable : false ,
2017-01-17 08:19:26 +00:00
data : [ ] ,
2020-09-25 11:44:15 +00:00
scrollAlwaysVisible : true ,
2021-12-20 13:59:41 +00:00
takeFocusOnClose : true ,
search : true
2017-01-16 08:48:21 +00:00
} ) ;
this . cmbSymbols . on ( 'selected' , _ . bind ( this . onSymbolsSelect , this ) ) ;
this . cmbType = new Common . UI . ComboBox ( {
el : $ ( '#format-settings-combo-type' ) ,
cls : 'input-group-nr' ,
2017-04-11 11:05:56 +00:00
menuStyle : 'min-width: 264px;max-height:235px;' ,
2017-01-16 08:48:21 +00:00
editable : false ,
2017-01-16 11:14:47 +00:00
data : [ ] ,
2020-09-25 11:44:15 +00:00
scrollAlwaysVisible : true ,
takeFocusOnClose : true
2017-01-16 08:48:21 +00:00
} ) ;
this . cmbType . on ( 'selected' , _ . bind ( this . onTypeSelect , this ) ) ;
2020-12-02 14:09:43 +00:00
this . codesList = new Common . UI . ListView ( {
el : $ ( '#format-settings-list-code' ) ,
store : new Common . UI . DataViewStore ( ) ,
tabindex : 1 ,
itemTemplate : _ . template ( '<div id="<%= id %>" class="list-item" style="pointer-events:none;overflow: hidden; text-overflow: ellipsis;"><%= value %></div>' )
2017-01-16 08:48:21 +00:00
} ) ;
2020-12-02 14:09:43 +00:00
this . codesList . on ( 'item:select' , _ . bind ( this . onCodeSelect , this ) ) ;
this . codesList . on ( 'entervalue' , _ . bind ( this . onPrimary , this ) ) ;
2017-01-16 08:48:21 +00:00
2020-12-01 16:24:38 +00:00
this . inputCustomFormat = new Common . UI . InputField ( {
el : $ ( '#format-settings-txt-code' ) ,
allowBlank : true ,
validateOnChange : true ,
validation : function ( ) { return true ; }
} ) . on ( 'changing' , function ( input , value ) {
2020-12-02 14:09:43 +00:00
me . codesList . deselectAll ( ) ;
2020-12-01 16:24:38 +00:00
me . Format = me . api . asc _convertNumFormatLocal2NumFormat ( value ) ;
me . lblExample . text ( me . api . asc _getLocaleExample ( me . Format ) ) ;
2020-12-07 19:20:22 +00:00
me . chLinked . setValue ( false , true ) ;
2020-12-25 11:50:01 +00:00
if ( ! me . _state . warning ) {
input . showWarning ( [ me . txtCustomWarning ] ) ;
me . _state . warning = true ;
}
2020-12-07 19:20:22 +00:00
} ) ;
this . chLinked = new Common . UI . CheckBox ( {
el : $ ( '#format-settings-chk-linked' ) ,
labelText : this . textLinked
} ) . on ( 'change' , function ( field , newValue , oldValue , eOpts ) {
2020-12-08 09:09:16 +00:00
me . props . linked = ( field . getValue ( ) == 'checked' ) ;
if ( me . props . linked ) {
me . props . chartFormat . putSourceLinked ( true ) ;
me . props . format = me . props . chartFormat . getFormatCode ( ) ;
me . props . formatInfo = me . props . chartFormat . getFormatCellsInfo ( ) ;
2020-12-07 19:20:22 +00:00
me . _setDefaults ( me . props ) ;
2020-12-08 09:09:16 +00:00
}
2020-12-01 16:24:38 +00:00
} ) ;
2020-12-07 19:20:22 +00:00
this . chLinked . setVisible ( this . linked ) ;
2020-12-01 16:24:38 +00:00
2017-01-16 08:48:21 +00:00
this . _decimalPanel = this . $window . find ( '.format-decimal' ) ;
this . _negativePanel = this . $window . find ( '.format-negative' ) ;
this . _separatorPanel = this . $window . find ( '.format-separator' ) ;
this . _typePanel = this . $window . find ( '.format-type' ) ;
this . _symbolsPanel = this . $window . find ( '.format-symbols' ) ;
this . _codePanel = this . $window . find ( '.format-code' ) ;
2020-12-02 14:09:43 +00:00
this . _nocodePanel = this . $window . find ( '.format-no-code' ) ;
2020-12-07 19:20:22 +00:00
this . $window . find ( '.format-sample' ) . toggleClass ( 'hidden' , this . linked ) ;
2017-01-16 08:48:21 +00:00
this . lblExample = this . $window . find ( '#format-settings-label-example' ) ;
this . afterRender ( ) ;
} ,
2020-10-13 11:30:52 +00:00
getFocusedComponents : function ( ) {
2021-04-13 22:12:59 +00:00
return [ this . cmbFormat , this . spnDecimal , this . chSeparator , this . cmbSymbols , this . cmbNegative , this . cmbType , this . inputCustomFormat , this . codesList , this . chLinked ] ;
2020-10-13 11:30:52 +00:00
} ,
2020-10-22 10:53:58 +00:00
getDefaultFocusableComponent : function ( ) {
return this . cmbFormat ;
} ,
2017-01-16 08:48:21 +00:00
afterRender : function ( ) {
this . _setDefaults ( this . props ) ;
} ,
show : function ( ) {
Common . Views . AdvancedSettingsWindow . prototype . show . apply ( this , arguments ) ;
} ,
_setDefaults : function ( props ) {
2017-02-07 09:56:32 +00:00
if ( props && props . formatInfo ) {
2017-01-17 08:19:26 +00:00
if ( this . langId )
this . langId = props . langId ;
2017-02-07 09:56:32 +00:00
this . cmbFormat . setValue ( props . formatInfo . asc _getType ( ) , this . txtCustom ) ;
2017-01-17 08:19:26 +00:00
2017-02-07 09:56:32 +00:00
if ( ( props . formatInfo . asc _getType ( ) == Asc . c _oAscNumFormatType . Custom ) && props . format )
2017-01-19 11:34:37 +00:00
this . CustomFormat = this . Format = props . format ;
2017-04-11 11:05:56 +00:00
this . onFormatSelect ( this . cmbFormat , this . cmbFormat . getSelectedRecord ( ) , null , props . formatInfo ) ;
2017-02-07 09:56:32 +00:00
if ( this . _state . hasDecimal )
this . spnDecimal . setValue ( props . formatInfo . asc _getDecimalPlaces ( ) ) ;
if ( this . _state . hasSeparator )
this . chSeparator . setValue ( props . formatInfo . asc _getSeparator ( ) ) ;
if ( this . _state . hasSymbols )
2021-12-20 13:30:22 +00:00
this . cmbSymbols . setValue ( props . formatInfo . asc _getSymbol ( ) || props . formatInfo . asc _getCurrencySymbol ( ) ) ;
2017-02-07 09:56:32 +00:00
2017-04-11 11:05:56 +00:00
if ( props . format ) {
if ( this . _state . hasNegative ) {
var selectedItem = this . cmbNegative . store . findWhere ( { value : props . format } ) ;
if ( selectedItem )
this . cmbNegative . selectRecord ( selectedItem ) ;
else
this . cmbNegative . setValue ( this . api . asc _getLocaleExample ( props . format ) ) ;
} else if ( this . _state . hasType ) {
var selectedItem = this . cmbType . store . findWhere ( { value : props . format } ) ;
if ( selectedItem )
this . cmbType . selectRecord ( selectedItem ) ;
else if ( props . formatInfo . asc _getType ( ) == Asc . c _oAscNumFormatType . Fraction )
this . cmbType . setValue ( this . txtCustom ) ;
else if ( props . formatInfo . asc _getType ( ) == Asc . c _oAscNumFormatType . Time )
this . cmbType . setValue ( this . api . asc _getLocaleExample ( props . format , 1.534 ) ) ;
else
this . cmbType . setValue ( this . api . asc _getLocaleExample ( props . format , 38822 ) ) ;
}
this . Format = props . format ;
this . lblExample . text ( this . api . asc _getLocaleExample ( this . Format ) ) ;
}
2017-01-16 14:06:46 +00:00
// for fraction - if props.format not in cmbType - setValue(this.txtCustom)
2017-04-11 11:05:56 +00:00
// for date/time - if props.format not in cmbType - setValue(this.api.asc_getLocaleExample(props.format, 38822))
2017-01-17 10:15:36 +00:00
// for cmbNegative - if props.format not in cmbNegative - setValue(this.api.asc_getLocaleExample(props.format))
2017-01-16 08:48:21 +00:00
}
2020-12-08 09:09:16 +00:00
if ( props && props . chartFormat ) {
this . chLinked . setValue ( ! ! props . chartFormat . getSourceLinked ( ) , true ) ;
}
2017-01-16 08:48:21 +00:00
} ,
getSettings : function ( ) {
2020-12-07 19:20:22 +00:00
return { format : this . Format , linked : this . chLinked . getValue ( ) === 'checked' } ;
2017-01-16 08:48:21 +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 ( ) {
2017-06-21 09:51:14 +00:00
this . onDlgBtnClick ( 'ok' ) ;
return false ;
2017-01-16 08:48:21 +00:00
} ,
onNegativeSelect : function ( combo , record ) {
this . Format = record . value ;
2017-01-17 10:15:36 +00:00
this . lblExample . text ( this . api . asc _getLocaleExample ( this . Format ) ) ;
2020-12-07 19:20:22 +00:00
this . chLinked . setValue ( false , true ) ;
2017-01-16 08:48:21 +00:00
} ,
onSymbolsSelect : function ( combo , record ) {
2017-01-16 14:06:46 +00:00
var me = this ,
info = new Asc . asc _CFormatCellsInfo ( ) ;
2017-01-16 08:48:21 +00:00
info . asc _setType ( this . FormatType ) ;
info . asc _setDecimalPlaces ( this . spnDecimal . getNumberValue ( ) ) ;
info . asc _setSeparator ( false ) ;
2021-12-20 13:20:48 +00:00
( typeof record . value === 'string' ) ? info . asc _setCurrencySymbol ( record . value ) : info . asc _setSymbol ( record . value ) ;
2017-01-16 08:48:21 +00:00
2017-01-16 14:06:46 +00:00
var format = this . api . asc _getFormatCells ( info ) ,
data = [ ] ;
format . forEach ( function ( item ) {
2017-01-17 10:15:36 +00:00
data . push ( { value : item , displayValue : me . api . asc _getLocaleExample ( item , - 1234.12345678901234567890 ) } ) ;
2017-01-16 14:06:46 +00:00
} ) ;
this . cmbNegative . setData ( data ) ;
this . cmbNegative . selectRecord ( this . cmbNegative . store . at ( 0 ) ) ;
this . cmbNegative . cmpEl . find ( 'li:nth-child(2) a, li:nth-child(4) a' ) . css ( { color : '#ff0000' } ) ;
this . Format = format [ 0 ] ;
2017-01-16 08:48:21 +00:00
2017-01-17 10:15:36 +00:00
this . lblExample . text ( this . api . asc _getLocaleExample ( this . Format ) ) ;
2020-12-07 19:20:22 +00:00
this . chLinked . setValue ( false , true ) ;
2017-01-16 08:48:21 +00:00
} ,
onDecimalChange : function ( field , newValue , oldValue , eOpts ) {
2017-01-16 14:06:46 +00:00
var me = this ,
info = new Asc . asc _CFormatCellsInfo ( ) ;
2017-01-16 08:48:21 +00:00
info . asc _setType ( this . FormatType ) ;
info . asc _setDecimalPlaces ( field . getNumberValue ( ) ) ;
info . asc _setSeparator ( ( this . FormatType == Asc . c _oAscNumFormatType . Number ) ? this . chSeparator . getValue ( ) == 'checked' : false ) ;
2021-12-20 13:20:48 +00:00
if ( this . FormatType == Asc . c _oAscNumFormatType . Currency || this . FormatType == Asc . c _oAscNumFormatType . Accounting ) {
var value = this . cmbSymbols . getValue ( ) ;
( typeof value === 'string' ) ? info . asc _setCurrencySymbol ( value ) : info . asc _setSymbol ( value ) ;
} else
info . asc _setSymbol ( false ) ;
2017-01-16 08:48:21 +00:00
var format = this . api . asc _getFormatCells ( info ) ;
2017-01-16 14:06:46 +00:00
if ( this . FormatType == Asc . c _oAscNumFormatType . Number || this . FormatType == Asc . c _oAscNumFormatType . Currency || this . FormatType == Asc . c _oAscNumFormatType . Accounting ) {
2017-01-16 11:14:47 +00:00
var data = [ ] ;
format . forEach ( function ( item ) {
2017-01-17 10:15:36 +00:00
data . push ( { value : item , displayValue : me . api . asc _getLocaleExample ( item , - 1234.12345678901234567890 ) } ) ;
2017-01-16 11:14:47 +00:00
} ) ;
this . cmbNegative . setData ( data ) ;
2017-01-16 08:48:21 +00:00
this . cmbNegative . selectRecord ( this . cmbNegative . store . at ( 0 ) ) ;
2017-01-16 14:06:46 +00:00
this . cmbNegative . cmpEl . find ( 'li:nth-child(2) a, li:nth-child(4) a' ) . css ( { color : '#ff0000' } ) ;
2017-01-16 08:48:21 +00:00
this . Format = format [ 0 ] ;
} else {
2017-01-16 14:06:46 +00:00
this . Format = format [ 0 ] ;
2017-01-16 08:48:21 +00:00
}
2017-01-17 10:15:36 +00:00
this . lblExample . text ( this . api . asc _getLocaleExample ( this . Format ) ) ;
2020-12-07 19:20:22 +00:00
this . chLinked . setValue ( false , true ) ;
2017-01-16 08:48:21 +00:00
} ,
onSeparatorChange : function ( field , newValue , oldValue , eOpts ) {
2017-01-16 14:06:46 +00:00
var me = this ,
info = new Asc . asc _CFormatCellsInfo ( ) ;
2017-01-16 08:48:21 +00:00
info . asc _setType ( this . FormatType ) ;
info . asc _setDecimalPlaces ( this . spnDecimal . getNumberValue ( ) ) ;
info . asc _setSeparator ( field . getValue ( ) == 'checked' ) ;
2017-01-16 11:14:47 +00:00
var format = this . api . asc _getFormatCells ( info ) ,
data = [ ] ;
format . forEach ( function ( item ) {
2017-01-17 10:15:36 +00:00
data . push ( { value : item , displayValue : me . api . asc _getLocaleExample ( item , - 1234.12345678901234567890 ) } ) ;
2017-01-16 11:14:47 +00:00
} ) ;
this . cmbNegative . setData ( data ) ;
2017-01-16 08:48:21 +00:00
this . cmbNegative . selectRecord ( this . cmbNegative . store . at ( 0 ) ) ;
2017-01-16 14:06:46 +00:00
this . cmbNegative . cmpEl . find ( 'li:nth-child(2) a, li:nth-child(4) a' ) . css ( { color : '#ff0000' } ) ;
2017-01-16 08:48:21 +00:00
this . Format = format [ 0 ] ;
2017-01-17 10:15:36 +00:00
this . lblExample . text ( this . api . asc _getLocaleExample ( this . Format ) ) ;
2020-12-07 19:20:22 +00:00
this . chLinked . setValue ( false , true ) ;
2017-01-16 08:48:21 +00:00
} ,
onTypeSelect : function ( combo , record ) {
2017-01-16 14:06:46 +00:00
this . Format = record . value ;
2017-01-17 10:15:36 +00:00
this . lblExample . text ( this . api . asc _getLocaleExample ( this . Format ) ) ;
2020-12-07 19:20:22 +00:00
this . chLinked . setValue ( false , true ) ;
2017-01-16 08:48:21 +00:00
} ,
2020-12-02 14:09:43 +00:00
onCodeSelect : function ( listView , itemView , record ) {
if ( ! record ) return ;
this . Format = record . get ( 'format' ) ;
2017-01-17 10:15:36 +00:00
this . lblExample . text ( this . api . asc _getLocaleExample ( this . Format ) ) ;
2020-12-02 14:09:43 +00:00
this . inputCustomFormat . setValue ( record . get ( 'value' ) ) ;
2020-12-07 19:20:22 +00:00
this . chLinked . setValue ( false , true ) ;
2020-12-25 11:50:01 +00:00
this . inputCustomFormat . showWarning ( ) ;
this . _state . warning = false ;
2017-01-16 08:48:21 +00:00
} ,
2017-04-11 11:05:56 +00:00
onFormatSelect : function ( combo , record , e , initFormatInfo ) {
2017-01-16 08:48:21 +00:00
if ( ! record ) return ;
this . FormatType = record . value ;
var hasDecimal = ( record . value == Asc . c _oAscNumFormatType . Number || record . value == Asc . c _oAscNumFormatType . Scientific || record . value == Asc . c _oAscNumFormatType . Accounting ||
record . value == Asc . c _oAscNumFormatType . Currency || record . value == Asc . c _oAscNumFormatType . Percent ) ,
2017-01-16 14:06:46 +00:00
hasNegative = ( record . value == Asc . c _oAscNumFormatType . Number || record . value == Asc . c _oAscNumFormatType . Currency || record . value == Asc . c _oAscNumFormatType . Accounting ) ,
2017-01-16 08:48:21 +00:00
hasSeparator = ( record . value == Asc . c _oAscNumFormatType . Number ) ,
hasType = ( record . value == Asc . c _oAscNumFormatType . Date || record . value == Asc . c _oAscNumFormatType . Time || record . value == Asc . c _oAscNumFormatType . Fraction ) ,
hasSymbols = ( record . value == Asc . c _oAscNumFormatType . Accounting || record . value == Asc . c _oAscNumFormatType . Currency ) ,
2017-01-17 08:19:26 +00:00
hasCode = ( record . value == Asc . c _oAscNumFormatType . Custom ) ,
2017-04-11 11:05:56 +00:00
me = this ,
valDecimal = ( initFormatInfo ) ? initFormatInfo . asc _getDecimalPlaces ( ) : this . spnDecimal . getNumberValue ( ) ,
valSeparator = ( initFormatInfo ) ? initFormatInfo . asc _getSeparator ( ) : ( this . chSeparator . getValue ( ) == 'checked' ) ,
2021-12-20 13:30:22 +00:00
valSymbol = ( initFormatInfo ) ? ( initFormatInfo . asc _getSymbol ( ) || initFormatInfo . asc _getCurrencySymbol ( ) ) : this . langId ;
2017-01-16 08:48:21 +00:00
2017-01-16 14:06:46 +00:00
if ( record . value !== Asc . c _oAscNumFormatType . Custom ) {
2017-01-16 08:48:21 +00:00
var info = new Asc . asc _CFormatCellsInfo ( ) ;
info . asc _setType ( record . value ) ;
2017-04-11 11:05:56 +00:00
info . asc _setDecimalPlaces ( hasDecimal ? valDecimal : 0 ) ;
info . asc _setSeparator ( hasSeparator ? valSeparator : false ) ;
2017-01-16 08:48:21 +00:00
if ( hasNegative || record . value == Asc . c _oAscNumFormatType . Date || record . value == Asc . c _oAscNumFormatType . Time ) {
2017-01-17 08:19:26 +00:00
if ( hasSymbols ) {
if ( ! me . CurrencySymbolsData ) {
2019-10-03 13:39:48 +00:00
me . CurrencySymbolsData = [ ] ;
2017-01-17 08:19:26 +00:00
var symbolssarr = this . api . asc _getCurrencySymbols ( ) ;
for ( var code in symbolssarr ) {
if ( symbolssarr . hasOwnProperty ( code ) ) {
me . CurrencySymbolsData . push ( { value : parseInt ( code ) , displayValue : symbolssarr [ code ] + ' ' + Common . util . LanguageInfo . getLocalLanguageName ( code ) [ 1 ] } ) ;
}
}
2019-10-03 13:39:48 +00:00
me . CurrencySymbolsData . sort ( function ( a , b ) {
if ( a . displayValue < b . displayValue ) return - 1 ;
if ( a . displayValue > b . displayValue ) return 1 ;
return 0 ;
} ) ;
me . CurrencySymbolsData . unshift ( { value : null , displayValue : me . txtNone } ) ;
2021-12-20 13:20:48 +00:00
symbolssarr = this . api . asc _getAdditionalCurrencySymbols ( ) ;
symbolssarr . forEach ( function ( item ) {
me . CurrencySymbolsData . push ( { value : item , displayValue : item } ) ;
} ) ;
2017-01-17 08:19:26 +00:00
this . cmbSymbols . setData ( this . CurrencySymbolsData ) ;
2017-04-11 11:05:56 +00:00
this . cmbSymbols . setValue ( valSymbol ) ;
2017-01-17 08:19:26 +00:00
}
info . asc _setSymbol ( this . cmbSymbols . getValue ( ) ) ;
}
2017-01-16 11:14:47 +00:00
var formatsarr = this . api . asc _getFormatCells ( info ) ,
2017-01-16 14:06:46 +00:00
data = [ ] ,
2017-04-11 11:05:56 +00:00
exampleVal = ( record . value == Asc . c _oAscNumFormatType . Date ) ? 38822 : ( ( record . value == Asc . c _oAscNumFormatType . Time ) ? 1.534 : parseFloat ( "-1234.12345678901234567890" ) ) ;
2017-01-16 11:14:47 +00:00
formatsarr . forEach ( function ( item ) {
2017-01-17 10:15:36 +00:00
data . push ( { value : item , displayValue : me . api . asc _getLocaleExample ( item , exampleVal ) } ) ;
2017-01-16 11:14:47 +00:00
} ) ;
2017-01-16 08:48:21 +00:00
if ( hasNegative ) {
2017-01-16 11:14:47 +00:00
this . cmbNegative . setData ( data ) ;
2017-01-16 08:48:21 +00:00
this . cmbNegative . selectRecord ( this . cmbNegative . store . at ( 0 ) ) ;
2017-01-16 14:06:46 +00:00
this . cmbNegative . cmpEl . find ( 'li:nth-child(2) a, li:nth-child(4) a' ) . css ( { color : '#ff0000' } ) ;
2017-01-16 08:48:21 +00:00
} else {
2017-01-16 11:14:47 +00:00
this . cmbType . setData ( data ) ;
2017-01-16 08:48:21 +00:00
this . cmbType . selectRecord ( this . cmbType . store . at ( 0 ) ) ;
}
this . Format = formatsarr [ 0 ] ;
2017-01-16 14:06:46 +00:00
} else if ( record . value == Asc . c _oAscNumFormatType . Fraction ) {
this . cmbType . setData ( this . FractionData ) ;
this . cmbType . selectRecord ( this . cmbType . store . at ( 0 ) ) ;
this . Format = this . cmbType . getValue ( ) ;
2017-01-16 08:48:21 +00:00
} else {
2017-01-16 14:06:46 +00:00
this . Format = this . api . asc _getFormatCells ( info ) [ 0 ] ;
2017-01-16 08:48:21 +00:00
}
} else {
2017-01-17 11:04:55 +00:00
var info = new Asc . asc _CFormatCellsInfo ( ) ;
2017-09-06 10:46:46 +00:00
info . asc _setType ( Asc . c _oAscNumFormatType . Custom ) ;
2017-04-11 11:05:56 +00:00
info . asc _setSymbol ( valSymbol ) ;
2017-01-17 11:04:55 +00:00
var formatsarr = this . api . asc _getFormatCells ( info ) ,
2017-01-19 11:34:37 +00:00
data = [ ] ,
isCustom = ( this . CustomFormat ) ? true : false ;
2017-01-16 11:14:47 +00:00
formatsarr . forEach ( function ( item ) {
2020-12-02 14:09:43 +00:00
var rec = new Common . UI . DataViewModel ( ) ;
rec . set ( {
value : me . api . asc _convertNumFormat2NumFormatLocal ( item ) ,
format : item
} ) ;
data . push ( rec ) ;
2017-01-19 11:34:37 +00:00
if ( me . CustomFormat == item )
isCustom = false ;
2017-01-16 11:14:47 +00:00
} ) ;
2017-01-19 11:34:37 +00:00
if ( isCustom ) {
2020-12-02 14:09:43 +00:00
var rec = new Common . UI . DataViewModel ( ) ;
rec . set ( {
value : me . api . asc _convertNumFormat2NumFormatLocal ( this . CustomFormat ) ,
format : this . CustomFormat
} ) ;
data . push ( rec ) ;
2017-01-19 11:34:37 +00:00
}
2020-12-02 14:09:43 +00:00
this . codesList . store . reset ( data , { silent : false } ) ;
var rec = this . codesList . store . findWhere ( { value : this . Format } ) ;
rec && this . codesList . selectRecord ( rec ) ;
rec && this . codesList . scrollToRecord ( rec ) ;
this . inputCustomFormat . setValue ( me . api . asc _convertNumFormat2NumFormatLocal ( this . Format ) ) ;
2017-01-16 08:48:21 +00:00
}
2017-01-17 10:15:36 +00:00
this . lblExample . text ( this . api . asc _getLocaleExample ( this . Format ) ) ;
2017-01-16 08:48:21 +00:00
this . _decimalPanel . toggleClass ( 'hidden' , ! hasDecimal ) ;
2020-09-25 11:44:15 +00:00
this . _negativePanel . toggleClass ( 'hidden' , ! hasNegative ) ;
2017-01-16 08:48:21 +00:00
this . _separatorPanel . toggleClass ( 'hidden' , ! hasSeparator ) ;
this . _typePanel . toggleClass ( 'hidden' , ! hasType ) ;
this . _symbolsPanel . toggleClass ( 'hidden' , ! hasSymbols ) ;
this . _codePanel . toggleClass ( 'hidden' , ! hasCode ) ;
2020-12-02 14:09:43 +00:00
this . _nocodePanel . toggleClass ( 'hidden' , hasCode ) ;
2017-02-07 09:56:32 +00:00
this . _state = { hasDecimal : hasDecimal , hasNegative : hasNegative , hasSeparator : hasSeparator , hasType : hasType , hasSymbols : hasSymbols , hasCode : hasCode } ;
2020-12-07 19:20:22 +00:00
! initFormatInfo && this . chLinked . setValue ( false , true ) ;
2017-01-16 08:48:21 +00:00
} ,
textTitle : 'Number Format' ,
2017-01-17 17:44:36 +00:00
textCategory : 'Category' ,
2017-01-16 08:48:21 +00:00
textDecimal : 'Decimal' ,
textSeparator : 'Use 1000 separator' ,
2017-01-17 17:44:36 +00:00
textFormat : 'Format' ,
2017-01-16 08:48:21 +00:00
textSymbols : 'Symbols' ,
txtGeneral : 'General' ,
txtNumber : 'Number' ,
txtCustom : 'Custom' ,
txtCurrency : 'Currency' ,
txtAccounting : 'Accounting' ,
txtDate : 'Date' ,
txtTime : 'Time' ,
txtPercentage : 'Percentage' ,
txtFraction : 'Fraction' ,
txtScientific : 'Scientific' ,
txtText : 'Text' ,
2017-04-11 11:05:56 +00:00
txtUpto1 : 'Up to one digit (1/3)' ,
txtUpto2 : 'Up to two digits (12/25)' ,
txtUpto3 : 'Up to three digits (131/135)' ,
txtAs2 : 'As halfs (1/2)' ,
txtAs8 : 'As eighths (4/8)' ,
txtAs4 : 'As fourths (2/4)' ,
txtAs16 : 'As sixteenths (8/16)' ,
txtAs10 : 'As tenths (5/10)' ,
txtAs100 : 'As hundredths (50/100)' ,
2017-11-24 09:46:33 +00:00
txtSample : 'Sample:' ,
2020-12-07 19:20:22 +00:00
txtNone : 'None' ,
2021-01-19 15:05:55 +00:00
textLinked : 'Linked to source' ,
2020-12-28 12:14:50 +00:00
txtCustomWarning : 'Please enter the custom number format carefully. Spreadsheet Editor does not check custom formats for errors that may affect the xlsx file.'
2017-01-16 08:48:21 +00:00
} , SSE . Views . FormatSettingsDialog || { } ) )
} ) ;