2017-07-18 08:44:12 +00:00
/ *
*
2019-01-17 13:05:03 +00:00
* ( c ) Copyright Ascensio System SIA 2010 - 2019
2017-07-18 08:44:12 +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-07-18 08:44:12 +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
*
* /
/ * *
* PivotSettingsAdvanced . js
*
* Created by Julia Radzhabova on 17.07 . 2017
2018-03-01 12:16:38 +00:00
* Copyright ( c ) 2018 Ascensio System SIA . All rights reserved .
2017-07-18 08:44:12 +00:00
*
* /
define ( [ 'text!spreadsheeteditor/main/app/template/PivotSettingsAdvanced.template' ,
'common/main/lib/util/utils' ,
'common/main/lib/component/InputField' ,
'common/main/lib/component/ComboBox' ,
'common/main/lib/component/CheckBox' ,
'common/main/lib/component/MetricSpinner' ,
'common/main/lib/view/AdvancedSettingsWindow'
] , function ( contentTemplate ) { 'use strict' ;
SSE . Views . PivotSettingsAdvanced = Common . Views . AdvancedSettingsWindow . extend ( _ . extend ( {
options : {
2022-08-23 12:09:52 +00:00
contentWidth : 310 ,
height : 440 ,
2017-07-18 08:44:12 +00:00
toggleGroup : 'pivot-adv-settings-group' ,
storageName : 'sse-pivot-adv-settings-category'
} ,
initialize : function ( options ) {
var me = this ;
_ . extend ( this . options , {
title : this . textTitle ,
items : [
{ panelId : 'id-adv-pivot-layout' , panelCaption : this . strLayout } ,
{ panelId : 'id-adv-pivot-data' , panelCaption : this . textDataSource } ,
{ panelId : 'id-adv-pivot-alttext' , panelCaption : this . textAlt }
] ,
contentTemplate : _ . template ( contentTemplate ) ( {
scope : this
} )
} , options ) ;
this . api = options . api ;
this . props = options . props ;
2019-10-04 11:44:42 +00:00
this . options . handler = function ( result , value ) {
if ( result != 'ok' || this . isRangeValid ( ) ) {
if ( options . handler )
options . handler . call ( this , result , value ) ;
return ;
}
return true ;
} ;
2017-07-18 08:44:12 +00:00
Common . Views . AdvancedSettingsWindow . prototype . initialize . call ( this , this . options ) ;
} ,
render : function ( ) {
Common . Views . AdvancedSettingsWindow . prototype . render . call ( this ) ;
var me = this ;
this . inputName = new Common . UI . InputField ( {
el : $ ( '#pivot-adv-name' ) ,
allowBlank : true ,
validateOnBlur : false ,
style : 'width: 100%;'
} ) ;
this . radioDown = new Common . UI . RadioBox ( {
el : $ ( '#pivot-adv-radio-down' ) ,
labelText : this . textDown ,
name : 'asc-radio-display-field' ,
checked : true
} ) ;
this . radioDown . on ( 'change' , _ . bind ( function ( field , newValue , eOpts ) {
if ( newValue ) {
this . lblPageWrap . html ( this . textWrapCol ) ;
}
} , this ) ) ;
this . radioOver = new Common . UI . RadioBox ( {
el : $ ( '#pivot-adv-radio-over' ) ,
labelText : this . textOver ,
name : 'asc-radio-display-field'
} ) ;
this . radioOver . on ( 'change' , _ . bind ( function ( field , newValue , eOpts ) {
if ( newValue ) {
this . lblPageWrap . html ( this . textWrapRow ) ;
}
} , this ) ) ;
this . chRows = new Common . UI . CheckBox ( {
el : $ ( '#pivot-adv-chk-show-rows' ) ,
labelText : this . textShowRows
} ) ;
this . chCols = new Common . UI . CheckBox ( {
el : $ ( '#pivot-adv-chk-show-columns' ) ,
labelText : this . textShowCols
} ) ;
this . numWrap = new Common . UI . MetricSpinner ( {
el : $ ( '#pivot-adv-spin-wrap' ) ,
step : 1 ,
2020-07-31 11:00:28 +00:00
width : 60 ,
2017-07-18 08:44:12 +00:00
allowDecimal : false ,
defaultUnit : "" ,
value : '0' ,
maxValue : 255 ,
minValue : 0
} ) ;
this . lblPageWrap = this . $window . find ( '#pivot-adv-label-wrap' ) ;
this . chHeaders = new Common . UI . CheckBox ( {
el : $ ( '#pivot-adv-chk-show-headers' ) ,
labelText : this . textShowHeaders
} ) ;
2022-07-26 20:14:11 +00:00
this . chAutofitColWidth = new Common . UI . CheckBox ( {
el : $ ( '#pivot-adv-chk-autofit-col-width' ) ,
labelText : this . textAutofitColWidth
} ) ;
2020-04-06 14:46:22 +00:00
this . txtDataRange = new Common . UI . InputFieldBtn ( {
2017-07-18 08:44:12 +00:00
el : $ ( '#pivot-adv-txt-range' ) ,
name : 'range' ,
style : 'width: 100%;' ,
2020-04-06 14:46:22 +00:00
btnHint : this . textSelectData ,
2017-07-18 08:44:12 +00:00
allowBlank : true ,
blankError : this . txtEmpty ,
validateOnChange : true
} ) ;
2020-04-06 14:46:22 +00:00
this . txtDataRange . on ( 'button:click' , _ . bind ( this . onSelectData , this ) ) ;
2017-07-18 08:44:12 +00:00
// Alt Text
this . inputAltTitle = new Common . UI . InputField ( {
el : $ ( '#pivot-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 ( ) ;
} ,
2020-10-14 10:43:44 +00:00
getFocusedComponents : function ( ) {
return [
2022-07-26 20:14:11 +00:00
this . inputName , this . chRows , this . chCols , this . radioDown , this . radioOver , this . numWrap , this . chHeaders , this . chAutofitColWidth , // 0 tab
2020-10-14 10:43:44 +00:00
this . txtDataRange , // 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 . inputName . focus ( ) ;
break ;
case 1 :
me . txtDataRange . focus ( ) ;
break ;
case 2 :
me . inputAltTitle . focus ( ) ;
break ;
}
} , 10 ) ;
} ,
2017-07-18 08:44:12 +00:00
afterRender : function ( ) {
this . _setDefaults ( this . props ) ;
if ( this . storageName ) {
var value = Common . localStorage . getItem ( this . storageName ) ;
this . setActiveCategory ( ( value !== null ) ? parseInt ( value ) : 0 ) ;
}
} ,
show : function ( ) {
Common . Views . AdvancedSettingsWindow . prototype . show . apply ( this , arguments ) ;
} ,
_setDefaults : function ( props ) {
if ( props ) {
var me = this ;
this . inputName . setValue ( Common . Utils . String . htmlEncode ( props . asc _getName ( ) ) ) ;
2017-08-03 13:33:16 +00:00
this . chCols . setValue ( props . asc _getRowGrandTotals ( ) , true ) ;
this . chRows . setValue ( props . asc _getColGrandTotals ( ) , true ) ;
2017-07-18 08:44:12 +00:00
( props . asc _getPageOverThenDown ( ) ) ? this . radioOver . setValue ( true ) : this . radioDown . setValue ( true ) ;
this . lblPageWrap . html ( ( props . asc _getPageOverThenDown ( ) ) ? this . textWrapRow : this . textWrapCol ) ;
this . numWrap . setValue ( props . asc _getPageWrap ( ) ) ;
this . chHeaders . setValue ( props . asc _getShowHeaders ( ) , true ) ;
2022-07-26 20:14:11 +00:00
this . chAutofitColWidth . setValue ( props . asc _getUseAutoFormatting ( ) , true ) ;
2017-07-18 08:44:12 +00:00
2019-10-11 10:07:17 +00:00
var value = props . asc _getDataRef ( ) ;
this . txtDataRange . setValue ( ( value ) ? value : '' ) ;
this . dataRangeValid = value ;
2017-07-18 08:44:12 +00:00
this . txtDataRange . validation = function ( value ) {
2019-10-11 10:07:17 +00:00
var isvalid = me . api . asc _checkDataRange ( Asc . c _oAscSelectionDialogType . PivotTableData , value , false ) ;
return ( isvalid == Asc . c _oAscError . ID . DataRangeError ) ? me . textInvalidRange : true ;
2017-07-18 08:44:12 +00:00
} ;
2019-10-04 13:15:06 +00:00
2019-10-11 10:07:17 +00:00
value = props . asc _getTitle ( ) ;
this . inputAltTitle . setValue ( value ? value : '' ) ;
value = props . asc _getDescription ( ) ;
this . textareaAltDescription . val ( value ? value : '' ) ;
2017-07-18 08:44:12 +00:00
}
} ,
getSettings : function ( ) {
2017-08-08 14:03:09 +00:00
var props = new Asc . CT _pivotTableDefinition ( ) ;
2019-09-30 15:54:37 +00:00
props . asc _setName ( this . inputName . getValue ( ) ) ;
2017-08-03 13:33:16 +00:00
props . asc _setRowGrandTotals ( this . chCols . getValue ( ) == 'checked' ) ;
props . asc _setColGrandTotals ( this . chRows . getValue ( ) == 'checked' ) ;
2019-09-30 15:54:37 +00:00
props . asc _setPageOverThenDown ( this . radioOver . getValue ( ) ) ;
props . asc _setPageWrap ( this . numWrap . getNumberValue ( ) ) ;
props . asc _setShowHeaders ( this . chHeaders . getValue ( ) == 'checked' ) ;
2022-07-26 20:14:11 +00:00
props . asc _setUseAutoFormatting ( this . chAutofitColWidth . getValue ( ) == 'checked' ) ;
2019-10-11 10:07:17 +00:00
props . asc _setDataRef ( this . txtDataRange . getValue ( ) ) ;
2017-07-21 07:35:19 +00:00
2019-10-11 10:07:17 +00:00
if ( this . isAltTitleChanged )
props . asc _setTitle ( this . inputAltTitle . getValue ( ) ) ;
if ( this . isAltDescChanged )
props . asc _setDescription ( this . textareaAltDescription . val ( ) ) ;
2019-10-04 13:15:06 +00:00
2017-07-21 07:35:19 +00:00
return props ;
2017-07-18 08:44:12 +00:00
} ,
isRangeValid : function ( ) {
2019-10-04 11:44:42 +00:00
var isvalid = true ,
txtError = '' ;
if ( _ . isEmpty ( this . txtDataRange . getValue ( ) ) ) {
isvalid = false ;
txtError = this . txtEmpty ;
} else {
2019-10-11 10:07:17 +00:00
isvalid = this . api . asc _checkDataRange ( Asc . c _oAscSelectionDialogType . PivotTableData , this . txtDataRange . getValue ( ) ) ;
isvalid = ( isvalid == Asc . c _oAscError . ID . No ) ;
2019-10-04 11:44:42 +00:00
! isvalid && ( txtError = this . textInvalidRange ) ;
}
if ( ! isvalid ) {
2017-07-18 08:44:12 +00:00
this . setActiveCategory ( 1 ) ;
2019-10-04 11:44:42 +00:00
this . txtDataRange . showError ( [ txtError ] ) ;
2017-07-18 08:44:12 +00:00
this . txtDataRange . cmpEl . find ( 'input' ) . focus ( ) ;
2019-10-04 11:44:42 +00:00
return isvalid ;
}
return isvalid ;
2017-07-18 08:44:12 +00:00
} ,
onSelectData : function ( ) {
var me = this ;
if ( me . api ) {
var handlerDlg = function ( dlg , result ) {
if ( result == 'ok' ) {
me . dataRangeValid = dlg . getSettings ( ) ;
me . txtDataRange . setValue ( me . dataRangeValid ) ;
me . txtDataRange . checkValidate ( ) ;
}
} ;
var win = new SSE . Views . CellRangeDialog ( {
handler : handlerDlg
} ) . on ( 'close' , function ( ) {
me . show ( ) ;
} ) ;
var xy = me . $window . offset ( ) ;
me . hide ( ) ;
win . show ( xy . left + 160 , xy . top + 125 ) ;
win . setSettings ( {
api : me . api ,
range : ( ! _ . isEmpty ( me . txtDataRange . getValue ( ) ) && ( me . txtDataRange . checkValidate ( ) == true ) ) ? me . txtDataRange . getValue ( ) : me . dataRangeValid ,
2019-10-11 10:07:17 +00:00
type : Asc . c _oAscSelectionDialogType . PivotTableData
2017-07-18 08:44:12 +00:00
} ) ;
}
} ,
textTitle : 'Pivot Table - Advanced Settings' ,
strLayout : 'Name and Layout' ,
txtName : 'Name' ,
textGrandTotals : 'Grand Totals' ,
textShowRows : 'Show for rows' ,
textShowCols : 'Show for columns' ,
textDataSource : 'Data Source' ,
textDataRange : 'Data Range' ,
2020-04-06 14:57:55 +00:00
textSelectData : 'Select data' ,
2017-07-18 08:44:12 +00:00
textAlt : 'Alternative Text' ,
textAltTitle : 'Title' ,
textAltDescription : 'Description' ,
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.' ,
txtEmpty : 'This field is required' ,
textInvalidRange : 'ERROR! Invalid cells range' ,
textDisplayFields : 'Display fields in report filter area' ,
textDown : 'Down, then over' ,
textOver : 'Over, then down' ,
textWrapCol : 'Report filter fields per column' ,
textWrapRow : 'Report filter fields per row' ,
textHeaders : 'Field Headers' ,
2022-07-26 20:14:11 +00:00
textShowHeaders : 'Show field headers for rows and columns' ,
textAutofitColWidth : 'Autofit column widths on update'
2017-07-18 08:44:12 +00:00
} , SSE . Views . PivotSettingsAdvanced || { } ) )
} ) ;