2016-04-01 13:17:09 +00:00
/ *
*
2019-01-17 13:05:03 +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
*
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.
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
define ( [
'core' ,
'spreadsheeteditor/main/app/view/FileMenuPanels' ,
'spreadsheeteditor/main/app/view/PrintSettings'
] , function ( ) {
'use strict' ;
SSE . Controllers . Print = Backbone . Controller . extend ( _ . extend ( {
views : [
2021-10-19 16:03:31 +00:00
'MainSettingsPrint' ,
'PrintWithPreview'
2016-03-11 00:48:53 +00:00
] ,
initialize : function ( ) {
2016-03-31 11:13:16 +00:00
var value = Common . localStorage . getItem ( "sse-print-settings-range" ) ;
2016-04-05 11:52:34 +00:00
value = ( value !== null ) ? parseInt ( value ) : Asc . c _oAscPrintType . ActiveSheets ;
2021-11-11 11:41:44 +00:00
this . _currentPrintType = value ;
2016-04-01 13:01:12 +00:00
this . adjPrintParams = new Asc . asc _CAdjustPrint ( ) ;
2016-03-31 11:13:16 +00:00
this . adjPrintParams . asc _setPrintType ( value ) ;
2016-04-01 13:01:12 +00:00
this . _changedProps = null ;
2019-01-18 14:03:28 +00:00
this . _originalPageSettings = null ;
2016-03-11 00:48:53 +00:00
2021-10-27 17:22:23 +00:00
this . _navigationPreview = {
pageCount : false ,
currentPage : 0
} ;
2021-10-28 11:27:51 +00:00
this . _isPreviewVisible = false ;
2016-03-11 00:48:53 +00:00
this . addListeners ( {
2021-10-19 16:03:31 +00:00
'PrintWithPreview' : {
2016-03-11 00:48:53 +00:00
'show' : _ . bind ( this . onShowMainSettingsPrint , this ) ,
2021-10-20 14:56:06 +00:00
'render:after' : _ . bind ( this . onAfterRender , this ) ,
2022-04-07 14:12:39 +00:00
'changerange' : _ . bind ( this . onChangeRange , this , false ) ,
'openheader' : _ . bind ( this . onOpenHeaderSettings , this ) ,
2016-03-11 00:48:53 +00:00
} ,
'PrintSettings' : {
2021-10-20 14:56:06 +00:00
'changerange' : _ . bind ( this . onChangeRange , this , true )
2016-03-11 00:48:53 +00:00
}
} ) ;
2019-10-02 14:52:54 +00:00
Common . NotificationCenter . on ( 'print' , _ . bind ( this . openPrintSettings , this , 'print' ) ) ;
Common . NotificationCenter . on ( 'download:settings' , _ . bind ( this . openPrintSettings , this , 'download' ) ) ;
2016-03-11 00:48:53 +00:00
} ,
onLaunch : function ( ) {
2021-10-19 16:03:31 +00:00
this . printSettings = this . createView ( 'PrintWithPreview' ) ;
2016-03-11 00:48:53 +00:00
} ,
onAfterRender : function ( view ) {
2021-11-26 07:28:27 +00:00
var me = this ;
2021-10-26 17:21:24 +00:00
this . printSettings . menu . on ( 'menu:hide' , _ . bind ( this . onHidePrintMenu , this ) ) ;
2022-04-15 09:37:08 +00:00
this . printSettings . cmbSheet . on ( 'selected' , _ . bind ( function ( combo , record ) {
this . comboSheetsChange ( this . printSettings , combo , record ) ;
2022-04-15 09:43:14 +00:00
if ( this . _isPreviewVisible ) {
this . notUpdateSheetSettings = true ;
this . api . asc _drawPrintPreview ( undefined , record . value ) ;
}
2022-04-15 09:37:08 +00:00
} , this ) ) ;
2021-11-26 07:28:27 +00:00
this . printSettings . btnsSave . forEach ( function ( btn ) {
btn . on ( 'click' , _ . bind ( me . querySavePrintSettings , me , false ) ) ;
} ) ;
this . printSettings . btnsPrint . forEach ( function ( btn ) {
btn . on ( 'click' , _ . bind ( me . querySavePrintSettings , me , true ) ) ;
} ) ;
2021-10-27 17:22:23 +00:00
this . printSettings . btnPrevPage . on ( 'click' , _ . bind ( this . onChangePreviewPage , this , false ) ) ;
this . printSettings . btnNextPage . on ( 'click' , _ . bind ( this . onChangePreviewPage , this , true ) ) ;
this . printSettings . txtNumberPage . on ( {
'keypress:after' : _ . bind ( this . onKeypressPageNumber , this ) ,
'keyup:after' : _ . bind ( this . onKeyupPageNumber , this )
} ) ;
2021-12-01 09:43:26 +00:00
this . printSettings . txtNumberPage . cmpEl . find ( 'input' ) . on ( 'blur' , _ . bind ( this . onBlurPageNumber , this ) ) ;
2022-04-13 11:20:10 +00:00
this . printSettings . chIgnorePrintArea . on ( 'change' , _ . bind ( this . updatePreview , this , true ) ) ;
2021-10-21 12:20:32 +00:00
2020-03-17 14:55:37 +00:00
this . fillComponents ( this . printSettings ) ;
2016-04-01 13:01:12 +00:00
this . registerControlEvents ( this . printSettings ) ;
2021-11-25 16:41:19 +00:00
Common . NotificationCenter . on ( 'window:resize' , _ . bind ( function ( ) {
if ( this . _isPreviewVisible ) {
2022-04-13 11:20:10 +00:00
this . notUpdateSheetSettings = true ;
2021-11-25 16:41:19 +00:00
this . api . asc _drawPrintPreview ( this . _navigationPreview . currentPage ) ;
}
} , this ) ) ;
2022-02-17 17:37:31 +00:00
var eventname = ( /Firefox/i . test ( navigator . userAgent ) ) ? 'DOMMouseScroll' : 'mousewheel' ;
this . printSettings . $previewBox . on ( eventname , _ . bind ( this . onPreviewWheel , this ) ) ;
2016-03-11 00:48:53 +00:00
} ,
setApi : function ( o ) {
this . api = o ;
this . api . asc _registerCallback ( 'asc_onSheetsChanged' , _ . bind ( this . updateSheetsInfo , this ) ) ;
2021-11-25 15:59:48 +00:00
this . api . asc _registerCallback ( 'asc_onPrintPreviewSheetChanged' , _ . bind ( this . onApiChangePreviewSheet , this ) ) ;
2022-04-15 09:37:08 +00:00
this . api . asc _registerCallback ( 'asc_onPrintPreviewPageChanged' , _ . bind ( this . onApiChangePreviewPage , this ) ) ;
2022-04-18 20:47:29 +00:00
this . api . asc _registerCallback ( 'asc_onPrintPreviewSheetDataChanged' , _ . bind ( this . onApiPreviewSheetDataChanged , this ) ) ;
2016-03-11 00:48:53 +00:00
} ,
updateSheetsInfo : function ( ) {
if ( this . printSettings . isVisible ( ) ) {
2016-04-01 13:01:12 +00:00
this . updateSettings ( this . printSettings ) ;
2016-03-11 00:48:53 +00:00
} else {
this . isFillSheets = false ;
}
} ,
2016-04-01 13:01:12 +00:00
updateSettings : function ( panel ) {
2016-03-11 00:48:53 +00:00
var wc = this . api . asc _getWorksheetsCount ( ) , i = - 1 ;
2016-04-01 13:01:12 +00:00
var items = [ ] ;
2016-03-11 00:48:53 +00:00
while ( ++ i < wc ) {
if ( ! this . api . asc _isWorksheetHidden ( i ) ) {
items . push ( {
displayValue : this . api . asc _getWorksheetName ( i ) ,
value : i
} ) ;
}
}
2016-04-01 13:01:12 +00:00
panel . cmbSheet . store . reset ( items ) ;
var item = panel . cmbSheet . store . findWhere ( { value : panel . cmbSheet . getValue ( ) } ) ||
panel . cmbSheet . store . findWhere ( { value : this . api . asc _getActiveWorksheetIndex ( ) } ) ;
2016-03-11 00:48:53 +00:00
if ( item ) {
2016-04-01 13:01:12 +00:00
panel . cmbSheet . setValue ( item . get ( 'value' ) ) ;
2022-04-19 09:54:31 +00:00
panel . updateActiveSheet && panel . updateActiveSheet ( item . get ( 'displayValue' ) ) ;
2016-03-11 00:48:53 +00:00
}
} ,
2016-04-01 13:01:12 +00:00
comboSheetsChange : function ( panel , combo , record ) {
2022-04-08 11:42:29 +00:00
var currentSheet = record . value ;
this . fillPageOptions ( panel , this . _changedProps [ currentSheet ] ? this . _changedProps [ currentSheet ] : this . api . asc _getPageOptions ( currentSheet , true ) , currentSheet ) ;
if ( ! this . _changedProps [ currentSheet ] ) {
this . _changedProps [ currentSheet ] = this . getPageOptions ( this . printSettings , currentSheet ) ;
}
2016-03-11 00:48:53 +00:00
} ,
2020-03-18 10:06:18 +00:00
fillPageOptions : function ( panel , props , sheet ) {
2016-03-11 00:48:53 +00:00
var opt = props . asc _getPageSetup ( ) ;
2019-01-18 14:03:28 +00:00
this . _originalPageSettings = opt ;
2016-03-11 00:48:53 +00:00
var item = panel . cmbPaperOrientation . store . findWhere ( { value : opt . asc _getOrientation ( ) } ) ;
if ( item ) panel . cmbPaperOrientation . setValue ( item . get ( 'value' ) ) ;
var w = opt . asc _getWidth ( ) ;
var h = opt . asc _getHeight ( ) ;
2018-09-13 13:47:38 +00:00
var store = panel . cmbPaperSize . store ;
item = null ;
for ( var i = 0 ; i < store . length ; i ++ ) {
var rec = store . at ( i ) ,
value = rec . get ( 'value' ) ,
pagewidth = parseFloat ( /^\d{3}\.?\d*/ . exec ( value ) ) ,
pageheight = parseFloat ( /\d{3}\.?\d*$/ . exec ( value ) ) ;
if ( Math . abs ( pagewidth - w ) < 0.1 && Math . abs ( pageheight - h ) < 0.1 ) {
item = rec ;
break ;
}
}
2016-03-11 00:48:53 +00:00
if ( item )
panel . cmbPaperSize . setValue ( item . get ( 'value' ) ) ;
else
2019-09-04 09:58:34 +00:00
panel . cmbPaperSize . setValue ( this . txtCustom + ' (' + parseFloat ( Common . Utils . Metric . fnRecalcFromMM ( w ) . toFixed ( 2 ) ) + Common . Utils . Metric . getCurrentMetricName ( ) + ' x ' +
2019-01-18 14:03:28 +00:00
parseFloat ( Common . Utils . Metric . fnRecalcFromMM ( h ) . toFixed ( 2 ) ) + Common . Utils . Metric . getCurrentMetricName ( ) + ')' ) ;
2016-03-11 00:48:53 +00:00
2019-10-11 07:45:56 +00:00
this . fitWidth = opt . asc _getFitToWidth ( ) ;
this . fitHeight = opt . asc _getFitToHeight ( ) ;
this . fitScale = opt . asc _getScale ( ) ;
this . setScaling ( panel , this . fitWidth , this . fitHeight , this . fitScale ) ;
2016-04-01 13:01:12 +00:00
item = panel . cmbPaperOrientation . store . findWhere ( { value : opt . asc _getOrientation ( ) } ) ;
if ( item ) panel . cmbPaperOrientation . setValue ( item . get ( 'value' ) ) ;
2016-03-11 00:48:53 +00:00
opt = props . asc _getPageMargins ( ) ;
2016-04-01 14:06:16 +00:00
panel . spnMarginLeft . setValue ( Common . Utils . Metric . fnRecalcFromMM ( opt . asc _getLeft ( ) ) , true ) ;
panel . spnMarginTop . setValue ( Common . Utils . Metric . fnRecalcFromMM ( opt . asc _getTop ( ) ) , true ) ;
panel . spnMarginRight . setValue ( Common . Utils . Metric . fnRecalcFromMM ( opt . asc _getRight ( ) ) , true ) ;
panel . spnMarginBottom . setValue ( Common . Utils . Metric . fnRecalcFromMM ( opt . asc _getBottom ( ) ) , true ) ;
2016-03-11 00:48:53 +00:00
2016-04-01 14:06:16 +00:00
panel . chPrintGrid . setValue ( props . asc _getGridLines ( ) , true ) ;
panel . chPrintRows . setValue ( props . asc _getHeadings ( ) , true ) ;
2020-03-17 14:55:37 +00:00
2020-03-18 12:09:39 +00:00
var value = props . asc _getPrintTitlesHeight ( ) ;
2020-03-18 10:06:18 +00:00
panel . txtRangeTop . setValue ( ( value ) ? value : '' ) ;
2020-08-26 12:12:09 +00:00
this . _noApply = true ;
2020-03-18 10:06:18 +00:00
panel . txtRangeTop . checkValidate ( ) ;
2020-08-26 12:12:09 +00:00
this . _noApply = false ;
2020-03-18 10:06:18 +00:00
panel . dataRangeTop = value ;
2020-03-18 12:09:39 +00:00
value = props . asc _getPrintTitlesWidth ( ) ;
2020-03-18 10:06:18 +00:00
panel . txtRangeLeft . setValue ( ( value ) ? value : '' ) ;
2020-08-26 12:12:09 +00:00
this . _noApply = true ;
2020-03-18 10:06:18 +00:00
panel . txtRangeLeft . checkValidate ( ) ;
2020-08-26 12:12:09 +00:00
this . _noApply = false ;
2020-03-18 10:06:18 +00:00
panel . dataRangeLeft = value ;
2020-03-19 09:15:45 +00:00
value = ( this . api . asc _getActiveWorksheetIndex ( ) == sheet ) ;
2020-04-06 14:46:22 +00:00
if ( panel . btnPresetsTop . menu . items [ 0 ] . value == 'select' ) {
panel . btnPresetsTop . menu . items [ 0 ] . setVisible ( value ) ;
panel . txtRangeTop . setBtnDisabled && panel . txtRangeTop . setBtnDisabled ( ! value ) ;
}
if ( panel . btnPresetsLeft . menu . items [ 0 ] . value == 'select' ) {
panel . btnPresetsLeft . menu . items [ 0 ] . setVisible ( value ) ;
panel . txtRangeLeft . setBtnDisabled && panel . txtRangeLeft . setBtnDisabled ( ! value ) ;
}
2020-03-19 09:15:45 +00:00
2020-03-18 10:06:18 +00:00
panel . btnPresetsTop . menu . items [ panel . btnPresetsTop . menu . items [ 0 ] . value == 'frozen' ? 0 : 1 ] . setDisabled ( ! this . api . asc _getPrintTitlesRange ( Asc . c _oAscPrintTitlesRangeType . frozen , false , sheet ) ) ;
panel . btnPresetsLeft . menu . items [ panel . btnPresetsLeft . menu . items [ 0 ] . value == 'frozen' ? 0 : 1 ] . setDisabled ( ! this . api . asc _getPrintTitlesRange ( Asc . c _oAscPrintTitlesRangeType . frozen , true , sheet ) ) ;
2016-03-11 00:48:53 +00:00
} ,
2021-10-20 14:56:06 +00:00
fillPrintOptions : function ( props , isDlg ) {
var menu = isDlg ? this . printSettingsDlg : this . printSettings ;
menu . setRange ( props . asc _getPrintType ( ) ) ;
menu . setIgnorePrintArea ( ! ! props . asc _getIgnorePrintArea ( ) ) ;
this . onChangeRange ( isDlg ) ;
2016-03-11 00:48:53 +00:00
} ,
2021-10-20 14:56:06 +00:00
onChangeRange : function ( isDlg ) {
var menu = isDlg ? this . printSettingsDlg : this . printSettings ;
var printtype = menu . getRange ( ) ,
store = menu . cmbSheet . store ,
2016-04-05 11:52:34 +00:00
item = ( printtype !== Asc . c _oAscPrintType . EntireWorkbook ) ? store . findWhere ( { value : this . api . asc _getActiveWorksheetIndex ( ) } ) : store . at ( 0 ) ;
2016-04-01 13:01:12 +00:00
if ( item ) {
2021-10-20 14:56:06 +00:00
menu . cmbSheet . setValue ( item . get ( 'value' ) ) ;
this . comboSheetsChange ( menu , menu . cmbSheet , item . toJSON ( ) ) ;
2016-04-01 13:01:12 +00:00
}
2021-10-20 14:56:06 +00:00
menu . cmbSheet . setDisabled ( printtype !== Asc . c _oAscPrintType . EntireWorkbook ) ;
menu . chIgnorePrintArea . setDisabled ( printtype == Asc . c _oAscPrintType . Selection ) ;
2021-10-28 11:27:51 +00:00
if ( ! isDlg ) {
2022-04-13 11:20:10 +00:00
this . updatePreview ( true ) ;
2016-04-01 13:01:12 +00:00
}
2016-03-11 00:48:53 +00:00
} ,
2022-04-08 11:42:29 +00:00
getPageOptions : function ( panel , sheet ) {
var props = this . _changedProps [ sheet ] ? this . _changedProps [ sheet ] : new Asc . asc _CPageOptions ( ) ;
2020-08-26 11:13:28 +00:00
props . asc _setGridLines ( panel . chPrintGrid . getValue ( ) === 'checked' ) ;
props . asc _setHeadings ( panel . chPrintRows . getValue ( ) === 'checked' ) ;
2016-03-11 00:48:53 +00:00
2022-04-08 11:42:29 +00:00
var opt = this . _changedProps [ sheet ] ? this . _changedProps [ sheet ] . asc _getPageSetup ( ) : new Asc . asc _CPageSetup ( ) ;
2016-03-11 00:48:53 +00:00
opt . asc _setOrientation ( panel . cmbPaperOrientation . getValue ( ) == '-' ? undefined : panel . cmbPaperOrientation . getValue ( ) ) ;
var pagew = /^\d{3}\.?\d*/ . exec ( panel . cmbPaperSize . getValue ( ) ) ;
var pageh = /\d{3}\.?\d*$/ . exec ( panel . cmbPaperSize . getValue ( ) ) ;
2019-01-18 14:03:28 +00:00
opt . asc _setWidth ( pagew ? parseFloat ( pagew [ 0 ] ) : ( this . _originalPageSettings ? this . _originalPageSettings . asc _getWidth ( ) : undefined ) ) ;
opt . asc _setHeight ( pageh ? parseFloat ( pageh [ 0 ] ) : ( this . _originalPageSettings ? this . _originalPageSettings . asc _getHeight ( ) : undefined ) ) ;
2016-04-01 13:01:12 +00:00
var value = panel . cmbLayout . getValue ( ) ;
2019-09-04 07:53:56 +00:00
if ( value !== 4 ) {
2019-09-05 07:52:49 +00:00
var fitToWidth = ( value == 1 || value == 2 ) ? 1 : 0 ,
fitToHeight = ( value == 1 || value == 3 ) ? 1 : 0 ;
opt . asc _setFitToWidth ( fitToWidth ) ;
opt . asc _setFitToHeight ( fitToHeight ) ;
! fitToWidth && ! fitToHeight && opt . asc _setScale ( 100 ) ;
2019-10-15 12:07:03 +00:00
this . setScaling ( panel , fitToWidth , fitToHeight , 100 ) ;
2019-09-04 07:53:56 +00:00
} else {
opt . asc _setFitToWidth ( this . fitWidth ) ;
opt . asc _setFitToHeight ( this . fitHeight ) ;
opt . asc _setScale ( this . fitScale ) ;
}
2022-04-08 11:42:29 +00:00
if ( ! this . _changedProps [ sheet ] ) {
props . asc _setPageSetup ( opt ) ;
}
2016-03-11 00:48:53 +00:00
2022-04-08 11:42:29 +00:00
opt = this . _changedProps [ sheet ] ? this . _changedProps [ sheet ] . asc _getPageMargins ( ) : new Asc . asc _CPageMargins ( ) ;
2016-03-11 00:48:53 +00:00
opt . asc _setLeft ( panel . spnMarginLeft . getValue ( ) == '-' ? undefined : Common . Utils . Metric . fnRecalcToMM ( panel . spnMarginLeft . getNumberValue ( ) ) ) ; // because 1.91*10=19.0999999...
opt . asc _setTop ( panel . spnMarginTop . getValue ( ) == '-' ? undefined : Common . Utils . Metric . fnRecalcToMM ( panel . spnMarginTop . getNumberValue ( ) ) ) ;
opt . asc _setRight ( panel . spnMarginRight . getValue ( ) == '-' ? undefined : Common . Utils . Metric . fnRecalcToMM ( panel . spnMarginRight . getNumberValue ( ) ) ) ;
opt . asc _setBottom ( panel . spnMarginBottom . getValue ( ) == '-' ? undefined : Common . Utils . Metric . fnRecalcToMM ( panel . spnMarginBottom . getNumberValue ( ) ) ) ;
2022-04-08 11:42:29 +00:00
if ( ! this . _changedProps [ sheet ] ) {
props . asc _setPageMargins ( opt ) ;
}
2016-03-11 00:48:53 +00:00
2020-03-18 12:09:39 +00:00
var check = this . api . asc _checkDataRange ( Asc . c _oAscSelectionDialogType . PrintTitles , panel . txtRangeTop . getValue ( ) , false ) !== Asc . c _oAscError . ID . DataRangeError ;
props . asc _setPrintTitlesHeight ( check ? panel . txtRangeTop . getValue ( ) : panel . dataRangeTop ) ;
2020-03-18 10:06:18 +00:00
2020-03-18 12:09:39 +00:00
check = this . api . asc _checkDataRange ( Asc . c _oAscSelectionDialogType . PrintTitles , panel . txtRangeLeft . getValue ( ) , false ) !== Asc . c _oAscError . ID . DataRangeError ;
props . asc _setPrintTitlesWidth ( check ? panel . txtRangeLeft . getValue ( ) : panel . dataRangeLeft ) ;
2020-03-17 14:55:37 +00:00
2016-03-11 00:48:53 +00:00
return props ;
} ,
2016-04-01 13:01:12 +00:00
savePageOptions : function ( panel ) {
2018-07-30 14:51:28 +00:00
this . api . asc _savePagePrintOptions ( this . _changedProps ) ;
2018-06-28 09:27:11 +00:00
Common . NotificationCenter . trigger ( 'page:settings' ) ;
2016-03-11 00:48:53 +00:00
} ,
onShowMainSettingsPrint : function ( ) {
2016-04-01 13:01:12 +00:00
this . _changedProps = [ ] ;
2022-02-07 21:04:34 +00:00
this . printSettings . $previewBox . removeClass ( 'hidden' ) ;
2016-04-01 13:01:12 +00:00
2016-03-11 00:48:53 +00:00
if ( ! this . isFillSheets ) {
this . isFillSheets = true ;
2016-04-01 13:01:12 +00:00
this . updateSettings ( this . printSettings ) ;
2016-03-11 00:48:53 +00:00
}
2021-10-20 14:56:06 +00:00
this . fillPrintOptions ( this . adjPrintParams , false ) ;
2021-10-26 17:21:24 +00:00
2022-04-15 12:14:34 +00:00
var opts = new Asc . asc _CDownloadOptions ( null , Common . Utils . isChrome || Common . Utils . isOpera || Common . Utils . isGecko && Common . Utils . firefoxVersion > 86 ) ;
2022-02-08 16:22:28 +00:00
opts . asc _setAdvancedOptions ( this . adjPrintParams ) ;
var pageCount = this . api . asc _initPrintPreview ( 'print-preview' , opts ) ;
2021-10-28 11:27:51 +00:00
2022-02-07 21:04:34 +00:00
this . printSettings . $previewBox . toggleClass ( 'hidden' , ! pageCount ) ;
this . printSettings . $previewEmpty . toggleClass ( 'hidden' , ! ! pageCount ) ;
if ( ! ! pageCount ) {
this . updateNavigationButtons ( 0 , pageCount ) ;
this . printSettings . txtNumberPage . checkValidate ( ) ;
}
2022-02-21 14:50:25 +00:00
this . _isPreviewVisible = true ;
2022-04-13 15:02:21 +00:00
! ! pageCount && this . updatePreview ( ) ;
2016-03-11 00:48:53 +00:00
} ,
2018-07-18 11:07:24 +00:00
openPrintSettings : function ( type , cmp , format , asUrl ) {
2019-01-10 11:00:30 +00:00
if ( this . printSettingsDlg && this . printSettingsDlg . isVisible ( ) ) {
asUrl && Common . NotificationCenter . trigger ( 'download:cancel' ) ;
return ;
}
2016-04-04 08:17:21 +00:00
if ( this . api ) {
2020-04-10 10:53:25 +00:00
Common . UI . Menu . Manager . hideAll ( ) ;
2018-04-05 11:29:37 +00:00
this . asUrl = asUrl ;
2018-07-18 11:07:24 +00:00
this . downloadFormat = format ;
2016-03-11 00:48:53 +00:00
this . printSettingsDlg = ( new SSE . Views . PrintSettings ( {
2018-04-05 11:29:37 +00:00
type : type ,
2016-03-11 00:48:53 +00:00
handler : _ . bind ( this . resultPrintSettings , this ) ,
afterrender : _ . bind ( function ( ) {
2016-04-01 13:01:12 +00:00
this . _changedProps = [ ] ;
this . updateSettings ( this . printSettingsDlg ) ;
this . printSettingsDlg . cmbSheet . on ( 'selected' , _ . bind ( this . comboSheetsChange , this , this . printSettingsDlg ) ) ;
2020-03-17 14:55:37 +00:00
this . fillComponents ( this . printSettingsDlg , true ) ;
2021-10-20 14:56:06 +00:00
this . fillPrintOptions ( this . adjPrintParams , true ) ;
2016-04-01 13:01:12 +00:00
this . registerControlEvents ( this . printSettingsDlg ) ;
2016-03-11 00:48:53 +00:00
} , this )
} ) ) ;
this . printSettingsDlg . show ( ) ;
}
} ,
resultPrintSettings : function ( result , value ) {
var view = SSE . getController ( 'Toolbar' ) . getView ( 'Toolbar' ) ;
if ( result == 'ok' ) {
if ( this . checkMargins ( this . printSettingsDlg ) ) {
2016-04-01 13:01:12 +00:00
this . savePageOptions ( this . printSettingsDlg ) ;
2016-03-11 00:48:53 +00:00
2016-03-31 11:13:16 +00:00
var printtype = this . printSettingsDlg . getRange ( ) ;
this . adjPrintParams . asc _setPrintType ( printtype ) ;
2018-07-30 14:51:28 +00:00
this . adjPrintParams . asc _setPageOptionsMap ( this . _changedProps ) ;
2019-03-19 14:33:09 +00:00
this . adjPrintParams . asc _setIgnorePrintArea ( this . printSettingsDlg . getIgnorePrintArea ( ) ) ;
2016-03-31 11:13:16 +00:00
Common . localStorage . setItem ( "sse-print-settings-range" , printtype ) ;
2019-07-24 13:07:16 +00:00
if ( this . printSettingsDlg . type == 'print' ) {
2021-11-08 14:05:18 +00:00
var opts = new Asc . asc _CDownloadOptions ( null , Common . Utils . isChrome || Common . Utils . isOpera || Common . Utils . isGecko && Common . Utils . firefoxVersion > 86 ) ;
2019-07-25 10:17:33 +00:00
opts . asc _setAdvancedOptions ( this . adjPrintParams ) ;
2019-07-24 13:07:16 +00:00
this . api . asc _Print ( opts ) ;
} else {
2019-07-24 08:36:13 +00:00
var opts = new Asc . asc _CDownloadOptions ( this . downloadFormat , this . asUrl ) ;
2019-07-25 10:17:33 +00:00
opts . asc _setAdvancedOptions ( this . adjPrintParams ) ;
2019-07-24 08:36:13 +00:00
this . api . asc _DownloadAs ( opts ) ;
}
2018-04-05 11:29:37 +00:00
Common . component . Analytics . trackEvent ( ( this . printSettingsDlg . type == 'print' ) ? 'Print' : 'DownloadAs' ) ;
Common . component . Analytics . trackEvent ( 'ToolBar' , ( this . printSettingsDlg . type == 'print' ) ? 'Print' : 'DownloadAs' ) ;
2016-04-01 13:01:12 +00:00
Common . NotificationCenter . trigger ( 'edit:complete' , view ) ;
2016-03-11 00:48:53 +00:00
} else
return true ;
2019-01-10 11:00:30 +00:00
} else {
this . asUrl && Common . NotificationCenter . trigger ( 'download:cancel' ) ;
2016-04-01 13:01:12 +00:00
Common . NotificationCenter . trigger ( 'edit:complete' , view ) ;
2019-01-10 11:00:30 +00:00
}
2018-07-25 11:24:45 +00:00
this . printSettingsDlg = null ;
2016-03-11 00:48:53 +00:00
} ,
2021-10-21 12:20:32 +00:00
querySavePrintSettings : function ( print ) {
2016-03-11 00:48:53 +00:00
if ( this . checkMargins ( this . printSettings ) ) {
2016-04-01 13:01:12 +00:00
this . savePageOptions ( this . printSettings ) ;
2021-10-26 17:21:24 +00:00
this . _isPrint = print ;
2016-03-11 00:48:53 +00:00
this . printSettings . applySettings ( ) ;
2021-10-21 12:20:32 +00:00
if ( print ) {
var printType = this . printSettings . getRange ( ) ;
this . adjPrintParams . asc _setPrintType ( printType ) ;
this . adjPrintParams . asc _setPageOptionsMap ( this . _changedProps ) ;
this . adjPrintParams . asc _setIgnorePrintArea ( this . printSettings . getIgnorePrintArea ( ) ) ;
Common . localStorage . setItem ( "sse-print-settings-range" , printType ) ;
2022-04-15 12:14:34 +00:00
var opts = new Asc . asc _CDownloadOptions ( null , Common . Utils . isChrome || Common . Utils . isOpera || Common . Utils . isGecko && Common . Utils . firefoxVersion > 86 ) ;
2021-10-21 12:20:32 +00:00
opts . asc _setAdvancedOptions ( this . adjPrintParams ) ;
this . api . asc _Print ( opts ) ;
Common . NotificationCenter . trigger ( 'edit:complete' , view ) ;
2021-10-26 17:21:24 +00:00
this . _isPrint = false ;
2021-10-21 12:20:32 +00:00
}
2016-03-11 00:48:53 +00:00
}
} ,
checkMargins : function ( panel ) {
2016-04-05 11:52:34 +00:00
if ( panel . cmbPaperOrientation . getValue ( ) == Asc . c _oAscPageOrientation . PagePortrait ) {
2016-03-11 00:48:53 +00:00
var pagewidth = /^\d{3}\.?\d*/ . exec ( panel . cmbPaperSize . getValue ( ) ) ;
var pageheight = /\d{3}\.?\d*$/ . exec ( panel . cmbPaperSize . getValue ( ) ) ;
} else {
pageheight = /^\d{3}\.?\d*/ . exec ( panel . cmbPaperSize . getValue ( ) ) ;
pagewidth = /\d{3}\.?\d*$/ . exec ( panel . cmbPaperSize . getValue ( ) ) ;
}
2019-01-18 14:03:28 +00:00
pagewidth = pagewidth ? parseFloat ( pagewidth [ 0 ] ) : ( this . _originalPageSettings ? this . _originalPageSettings . asc _getWidth ( ) : 0 ) ;
pageheight = pageheight ? parseFloat ( pageheight [ 0 ] ) : ( this . _originalPageSettings ? this . _originalPageSettings . asc _getHeight ( ) : 0 ) ;
2016-03-11 00:48:53 +00:00
var ml = Common . Utils . Metric . fnRecalcToMM ( panel . spnMarginLeft . getNumberValue ( ) ) ;
var mr = Common . Utils . Metric . fnRecalcToMM ( panel . spnMarginRight . getNumberValue ( ) ) ;
var mt = Common . Utils . Metric . fnRecalcToMM ( panel . spnMarginTop . getNumberValue ( ) ) ;
var mb = Common . Utils . Metric . fnRecalcToMM ( panel . spnMarginBottom . getNumberValue ( ) ) ;
var result = false ;
if ( ml > pagewidth ) result = 'left' ; else
if ( mr > pagewidth - ml ) result = 'right' ; else
if ( mt > pageheight ) result = 'top' ; else
if ( mb > pageheight - mt ) result = 'bottom' ;
if ( result ) {
Common . UI . warning ( {
title : this . textWarning ,
msg : this . warnCheckMargings ,
callback : function ( btn , text ) {
switch ( result ) {
case 'left' : panel . spnMarginLeft . $el . focus ( ) ; return ;
case 'right' : panel . spnMarginRight . $el . focus ( ) ; return ;
case 'top' : panel . spnMarginTop . $el . focus ( ) ; return ;
case 'bottom' : panel . spnMarginBottom . $el . focus ( ) ; return ;
}
}
} ) ;
return false ;
}
return true ;
} ,
2016-04-01 13:01:12 +00:00
registerControlEvents : function ( panel ) {
panel . cmbPaperSize . on ( 'selected' , _ . bind ( this . propertyChange , this , panel ) ) ;
panel . cmbPaperOrientation . on ( 'selected' , _ . bind ( this . propertyChange , this , panel ) ) ;
2019-09-04 12:09:04 +00:00
panel . cmbLayout . on ( 'selected' , _ . bind ( this . propertyChange , this , panel , 'scale' ) ) ;
2016-04-01 13:01:12 +00:00
panel . spnMarginTop . on ( 'change' , _ . bind ( this . propertyChange , this , panel ) ) ;
panel . spnMarginBottom . on ( 'change' , _ . bind ( this . propertyChange , this , panel ) ) ;
panel . spnMarginLeft . on ( 'change' , _ . bind ( this . propertyChange , this , panel ) ) ;
panel . spnMarginRight . on ( 'change' , _ . bind ( this . propertyChange , this , panel ) ) ;
panel . chPrintGrid . on ( 'change' , _ . bind ( this . propertyChange , this , panel ) ) ;
panel . chPrintRows . on ( 'change' , _ . bind ( this . propertyChange , this , panel ) ) ;
2022-03-31 15:15:58 +00:00
panel . txtRangeTop . on ( 'changed:after' , _ . bind ( this . propertyChange , this , panel ) ) ;
panel . txtRangeLeft . on ( 'changed:after' , _ . bind ( this . propertyChange , this , panel ) ) ;
2020-04-06 14:46:22 +00:00
panel . txtRangeTop . on ( 'button:click' , _ . bind ( this . onPresetSelect , this , panel , 'top' , panel . btnPresetsTop . menu , { value : 'select' } ) ) ;
panel . txtRangeLeft . on ( 'button:click' , _ . bind ( this . onPresetSelect , this , panel , 'left' , panel . btnPresetsLeft . menu , { value : 'select' } ) ) ;
2020-03-17 14:55:37 +00:00
panel . btnPresetsTop . menu . on ( 'item:click' , _ . bind ( this . onPresetSelect , this , panel , 'top' ) ) ;
panel . btnPresetsLeft . menu . on ( 'item:click' , _ . bind ( this . onPresetSelect , this , panel , 'left' ) ) ;
2016-04-01 13:01:12 +00:00
} ,
2019-09-04 12:09:04 +00:00
propertyChange : function ( panel , scale , combo , record ) {
2019-10-15 12:07:03 +00:00
if ( scale === 'scale' && record . value === 'customoptions' ) {
2019-09-05 07:52:49 +00:00
var me = this ,
2020-03-18 12:09:39 +00:00
props = ( me . _changedProps . length > 0 && me . _changedProps [ panel . cmbSheet . getValue ( ) ] ) ? me . _changedProps [ panel . cmbSheet . getValue ( ) ] : me . api . asc _getPageOptions ( panel . cmbSheet . getValue ( ) , true ) ;
2019-09-04 12:09:04 +00:00
var win = new SSE . Views . ScaleDialog ( {
api : me . api ,
2019-09-05 07:52:49 +00:00
props : props ,
2019-09-04 12:09:04 +00:00
handler : function ( dlg , result ) {
if ( dlg == 'ok' ) {
if ( me . api && result ) {
me . fitWidth = result . width ;
me . fitHeight = result . height ;
me . fitScale = result . scale ;
me . setScaling ( panel , me . fitWidth , me . fitHeight , me . fitScale ) ;
if ( me . _changedProps ) {
2022-04-08 11:42:29 +00:00
var currentSheet = panel . cmbSheet . getValue ( ) ;
me . _changedProps [ currentSheet ] = me . getPageOptions ( panel , currentSheet ) ;
2021-10-28 11:27:51 +00:00
me . updatePreview ( ) ;
2019-09-04 12:09:04 +00:00
}
}
} else {
var opt = props . asc _getPageSetup ( ) ,
fitwidth = opt . asc _getFitToWidth ( ) ,
fitheight = opt . asc _getFitToHeight ( ) ,
fitscale = opt . asc _getScale ( ) ;
me . setScaling ( panel , fitwidth , fitheight , fitscale ) ;
}
Common . NotificationCenter . trigger ( 'edit:complete' ) ;
}
} ) ;
win . show ( ) ;
Common . NotificationCenter . trigger ( 'edit:complete' , this . toolbar ) ;
} else {
if ( this . _changedProps ) {
2022-04-08 11:42:29 +00:00
var currentSheet = panel . cmbSheet . getValue ( ) ;
this . _changedProps [ currentSheet ] = this . getPageOptions ( panel , currentSheet ) ;
2021-10-28 11:27:51 +00:00
this . updatePreview ( ) ;
2019-09-04 12:09:04 +00:00
}
2016-04-01 13:01:12 +00:00
}
} ,
2019-07-23 12:07:51 +00:00
getPrintParams : function ( ) {
return this . adjPrintParams ;
} ,
2019-09-04 07:53:56 +00:00
setScaling : function ( panel , width , height , scale ) {
2019-10-15 12:07:03 +00:00
var value ;
if ( ! width && ! height && scale === 100 ) value = 0 ;
else if ( width === 1 && height === 1 ) value = 1 ;
else if ( width === 1 && ! height ) value = 2 ;
else if ( ! width && height === 1 ) value = 3 ;
else value = 4 ;
panel . addCustomScale ( value === 4 ) ;
panel . cmbLayout . setValue ( value , true ) ;
2019-09-04 07:53:56 +00:00
} ,
2020-03-17 14:55:37 +00:00
fillComponents : function ( panel , selectdata ) {
var me = this ;
panel . txtRangeTop . validation = function ( value ) {
if ( _ . isEmpty ( value ) ) {
return true ;
}
2020-03-18 12:09:39 +00:00
var isvalid = me . api . asc _checkDataRange ( Asc . c _oAscSelectionDialogType . PrintTitles , value , false ) ;
2020-03-17 14:55:37 +00:00
return ( isvalid == Asc . c _oAscError . ID . DataRangeError ) ? me . textInvalidRange : true ;
} ;
2020-04-06 14:46:22 +00:00
selectdata && panel . txtRangeTop . updateBtnHint ( this . textSelectRange ) ;
2020-03-17 14:55:37 +00:00
panel . txtRangeLeft . validation = function ( value ) {
if ( _ . isEmpty ( value ) ) {
return true ;
}
2020-03-18 12:09:39 +00:00
var isvalid = me . api . asc _checkDataRange ( Asc . c _oAscSelectionDialogType . PrintTitles , value , false ) ;
2020-03-17 14:55:37 +00:00
return ( isvalid == Asc . c _oAscError . ID . DataRangeError ) ? me . textInvalidRange : true ;
} ;
2020-04-06 14:46:22 +00:00
selectdata && panel . txtRangeLeft . updateBtnHint ( this . textSelectRange ) ;
2020-04-06 14:57:55 +00:00
var data = ( ( selectdata ) ? [ { caption : this . textSelectRange + '...' , value : 'select' } ] : [ ] ) . concat ( [
2020-03-17 14:55:37 +00:00
{ caption : this . textFrozenRows , value : 'frozen' } ,
{ caption : this . textFirstRow , value : 'first' } ,
{ caption : '--' } ,
{ caption : this . textNoRepeat , value : 'empty' }
] ) ;
panel . btnPresetsTop . setMenu ( new Common . UI . Menu ( {
style : 'min-width: 100px;' ,
maxHeight : 200 ,
2020-04-09 14:14:42 +00:00
additionalAlign : panel . menuAddAlign ,
2020-03-17 14:55:37 +00:00
items : data
} ) ) ;
2020-04-06 14:57:55 +00:00
data = ( ( selectdata ) ? [ { caption : this . textSelectRange + '...' , value : 'select' } ] : [ ] ) . concat ( [
2020-03-17 14:55:37 +00:00
{ caption : this . textFrozenCols , value : 'frozen' } ,
{ caption : this . textFirstCol , value : 'first' } ,
{ caption : '--' } ,
{ caption : this . textNoRepeat , value : 'empty' }
] ) ;
panel . btnPresetsLeft . setMenu ( new Common . UI . Menu ( {
style : 'min-width: 100px;' ,
maxHeight : 200 ,
2020-04-09 14:14:42 +00:00
additionalAlign : panel . menuAddAlign ,
2020-03-17 14:55:37 +00:00
items : data
} ) ) ;
} ,
onPresetSelect : function ( panel , type , menu , item ) {
var txtRange = ( type == 'top' ) ? panel . txtRangeTop : panel . txtRangeLeft ;
if ( item . value == 'select' ) {
var me = this ;
if ( me . api ) {
2020-04-09 14:14:42 +00:00
panel . btnPresetsTop . menu . options . additionalAlign = panel . menuAddAlign ;
panel . btnPresetsLeft . menu . options . additionalAlign = panel . menuAddAlign ;
2020-03-17 14:55:37 +00:00
var handlerDlg = function ( dlg , result ) {
if ( result == 'ok' ) {
var valid = dlg . getSettings ( ) ;
if ( type == 'top' )
panel . dataRangeTop = valid ;
else
panel . dataRangeLeft = valid ;
txtRange . setValue ( valid ) ;
txtRange . checkValidate ( ) ;
}
} ;
var win = new SSE . Views . CellRangeDialog ( {
handler : handlerDlg
} ) . on ( 'close' , function ( ) {
panel . show ( ) ;
2020-09-26 13:58:37 +00:00
_ . delay ( function ( ) {
txtRange . focus ( ) ;
} , 1 ) ;
2020-03-17 14:55:37 +00:00
} ) ;
var xy = panel . $window . offset ( ) ;
panel . hide ( ) ;
win . show ( xy . left + 160 , xy . top + 125 ) ;
win . setSettings ( {
api : me . api ,
range : ( ! _ . isEmpty ( txtRange . getValue ( ) ) && ( txtRange . checkValidate ( ) == true ) ) ? txtRange . getValue ( ) : ( ( type == 'top' ) ? panel . dataRangeTop : panel . dataRangeLeft ) ,
2020-03-18 12:09:39 +00:00
type : Asc . c _oAscSelectionDialogType . PrintTitles
2020-03-17 14:55:37 +00:00
} ) ;
}
} else {
var value = '' ;
if ( item . value == 'frozen' )
2020-03-17 15:03:42 +00:00
value = this . api . asc _getPrintTitlesRange ( Asc . c _oAscPrintTitlesRangeType . frozen , type == 'left' , panel . cmbSheet . getValue ( ) ) ;
2020-03-17 14:55:37 +00:00
else if ( item . value == 'first' )
2020-03-17 15:03:42 +00:00
value = this . api . asc _getPrintTitlesRange ( Asc . c _oAscPrintTitlesRangeType . first , type == 'left' , panel . cmbSheet . getValue ( ) ) ;
2020-03-17 14:55:37 +00:00
txtRange . setValue ( value ) ;
txtRange . checkValidate ( ) ;
if ( type == 'top' )
panel . dataRangeTop = value ;
else
panel . dataRangeLeft = value ;
2020-09-26 13:58:37 +00:00
_ . delay ( function ( ) {
txtRange . focus ( ) ;
} , 1 ) ;
2020-03-17 14:55:37 +00:00
}
} ,
2021-10-26 17:21:24 +00:00
onHidePrintMenu : function ( ) {
2021-10-28 11:27:51 +00:00
if ( this . _isPreviewVisible ) {
this . api . asc _closePrintPreview ( this . _isPrint ) ;
this . _isPreviewVisible = false ;
}
2021-10-26 17:21:24 +00:00
} ,
2021-10-27 17:22:23 +00:00
onChangePreviewPage : function ( next ) {
var index = this . _navigationPreview . currentPage ;
if ( next ) {
index ++ ;
index = Math . min ( index , this . _navigationPreview . pageCount - 1 ) ;
} else {
index -- ;
index = Math . max ( index , 0 ) ;
}
this . api . asc _drawPrintPreview ( index ) ;
2021-11-26 13:11:20 +00:00
this . updateNavigationButtons ( index , this . _navigationPreview . pageCount ) ;
2021-10-27 17:22:23 +00:00
} ,
2022-02-17 17:37:31 +00:00
onPreviewWheel : function ( e ) {
2022-03-24 17:48:25 +00:00
if ( e . ctrlKey ) {
e . preventDefault ( ) ;
e . stopImmediatePropagation ( ) ;
}
2022-04-04 13:42:34 +00:00
this . printSettings . txtRangeTop . cmpEl . find ( 'input:focus' ) . blur ( ) ;
this . printSettings . txtRangeLeft . cmpEl . find ( 'input:focus' ) . blur ( ) ;
2022-02-17 17:37:31 +00:00
var forward = ( e . deltaY || ( e . detail && - e . detail ) || e . wheelDelta ) < 0 ;
this . onChangePreviewPage ( forward ) ;
} ,
2021-10-27 17:22:23 +00:00
onKeypressPageNumber : function ( input , e ) {
if ( e . keyCode === Common . UI . Keys . RETURN ) {
2021-11-11 10:32:26 +00:00
var box = this . printSettings . $el . find ( '#print-number-page' ) ,
2021-10-27 17:22:23 +00:00
edit = box . find ( 'input[type=text]' ) , page = parseInt ( edit . val ( ) ) ;
2021-11-11 10:32:26 +00:00
if ( ! page || page > this . _navigationPreview . pageCount || page < 0 ) {
2021-10-27 17:22:23 +00:00
edit . select ( ) ;
2021-12-01 09:43:26 +00:00
this . printSettings . txtNumberPage . setValue ( this . _navigationPreview . currentPage + 1 ) ;
this . printSettings . txtNumberPage . checkValidate ( ) ;
2021-10-27 17:22:23 +00:00
return false ;
}
box . focus ( ) ; // for IE
this . api . asc _drawPrintPreview ( page - 1 ) ;
this . api . asc _enableKeyEvents ( true ) ;
2021-11-26 13:11:20 +00:00
this . updateNavigationButtons ( page - 1 , this . _navigationPreview . pageCount ) ;
2021-10-27 17:22:23 +00:00
return false ;
}
} ,
onKeyupPageNumber : function ( input , e ) {
if ( e . keyCode === Common . UI . Keys . ESC ) {
2021-11-11 10:32:26 +00:00
var box = this . printSettings . $el . find ( '#print-number-page' ) ;
2021-10-27 17:22:23 +00:00
box . focus ( ) ; // for IE
this . api . asc _enableKeyEvents ( true ) ;
return false ;
}
} ,
2021-12-01 09:43:26 +00:00
onBlurPageNumber : function ( ) {
if ( this . printSettings . txtNumberPage . getValue ( ) != this . _navigationPreview . currentPage + 1 ) {
this . printSettings . txtNumberPage . setValue ( this . _navigationPreview . currentPage + 1 ) ;
this . printSettings . txtNumberPage . checkValidate ( ) ;
}
} ,
2022-04-13 11:20:10 +00:00
updatePreview : function ( needUpdate ) {
2021-10-28 11:27:51 +00:00
if ( this . _isPreviewVisible ) {
2022-04-18 20:47:29 +00:00
this . printSettings . $previewBox . removeClass ( 'hidden' ) ;
2021-11-11 11:41:44 +00:00
var adjPrintParams = new Asc . asc _CAdjustPrint ( ) ,
printType = this . printSettings . getRange ( ) ;
adjPrintParams . asc _setPrintType ( printType ) ;
2021-10-28 11:27:51 +00:00
adjPrintParams . asc _setPageOptionsMap ( this . _changedProps ) ;
adjPrintParams . asc _setIgnorePrintArea ( this . printSettings . getIgnorePrintArea ( ) ) ;
2022-04-15 12:14:34 +00:00
var opts = new Asc . asc _CDownloadOptions ( null , Common . Utils . isChrome || Common . Utils . isOpera || Common . Utils . isGecko && Common . Utils . firefoxVersion > 86 ) ;
2021-10-28 11:27:51 +00:00
opts . asc _setAdvancedOptions ( adjPrintParams ) ;
2021-11-11 11:41:44 +00:00
var pageCount = this . api . asc _updatePrintPreview ( opts ) ;
2022-04-18 20:47:29 +00:00
this . printSettings . $previewBox . toggleClass ( 'hidden' , ! pageCount ) ;
this . printSettings . $previewEmpty . toggleClass ( 'hidden' , ! ! pageCount ) ;
2021-11-11 11:41:44 +00:00
var newPage ;
if ( this . _currentPrintType !== printType ) {
newPage = 0 ;
this . _currentPrintType = printType ;
2021-11-25 17:40:41 +00:00
} else if ( this . _navigationPreview . currentPage > pageCount - 1 ) {
2022-04-19 09:54:31 +00:00
newPage = Math . max ( 0 , pageCount - 1 ) ;
2021-11-11 11:41:44 +00:00
} else {
newPage = this . _navigationPreview . currentPage ;
}
2022-04-13 11:20:10 +00:00
this . notUpdateSheetSettings = ! needUpdate ;
2021-11-11 11:41:44 +00:00
this . api . asc _drawPrintPreview ( newPage ) ;
2021-11-26 13:11:20 +00:00
this . updateNavigationButtons ( newPage , pageCount ) ;
2021-10-28 11:27:51 +00:00
}
} ,
2021-11-25 15:59:48 +00:00
onApiChangePreviewSheet : function ( index ) {
2022-04-18 20:47:29 +00:00
var item = this . printSettings . cmbSheet . store . findWhere ( { value : index } ) ;
this . printSettings . updateActiveSheet ( item . get ( 'displayValue' ) ) ;
2022-04-13 11:20:10 +00:00
if ( this . notUpdateSheetSettings ) {
this . notUpdateSheetSettings = false ;
2022-04-18 20:47:29 +00:00
} else if ( item ) {
2021-11-25 15:59:48 +00:00
this . printSettings . cmbSheet . setValue ( item . get ( 'value' ) ) ;
this . comboSheetsChange ( this . printSettings , this . printSettings . cmbSheet , item . toJSON ( ) ) ;
}
} ,
2021-11-26 13:11:20 +00:00
updateNavigationButtons : function ( page , count ) {
this . _navigationPreview . currentPage = page ;
this . printSettings . updateCurrentPage ( page ) ;
this . _navigationPreview . pageCount = count ;
this . printSettings . updateCountOfPages ( count ) ;
this . disableNavButtons ( ) ;
} ,
disableNavButtons : function ( force ) {
if ( force ) {
this . printSettings . btnPrevPage . setDisabled ( true ) ;
this . printSettings . btnNextPage . setDisabled ( true ) ;
return ;
}
var curPage = this . _navigationPreview . currentPage ,
pageCount = this . _navigationPreview . pageCount ;
this . printSettings . btnPrevPage . setDisabled ( curPage < 1 ) ;
this . printSettings . btnNextPage . setDisabled ( curPage > pageCount - 2 ) ;
} ,
2022-04-07 14:12:39 +00:00
onOpenHeaderSettings : function ( ) {
2022-04-08 11:42:29 +00:00
var pageSetup = this . _changedProps [ this . printSettings . cmbSheet . getValue ( ) ] . asc _getPageSetup ( ) ;
SSE . getController ( 'Toolbar' ) . onEditHeaderClick ( pageSetup ) ;
2022-03-31 19:19:38 +00:00
} ,
2022-04-15 09:37:08 +00:00
onApiChangePreviewPage : function ( page ) {
if ( this . _navigationPreview . currentPage !== page ) {
this . _navigationPreview . currentPage = page ;
this . updateNavigationButtons ( page , this . _navigationPreview . pageCount ) ;
this . disableNavButtons ( ) ;
}
} ,
2022-04-18 20:47:29 +00:00
onApiPreviewSheetDataChanged : function ( needUpdate ) {
if ( needUpdate ) {
this . updatePreview ( ) ;
} else {
this . notUpdateSheetSettings = true ;
this . api . asc _drawPrintPreview ( this . _navigationPreview . currentPage ) ;
this . updateNavigationButtons ( this . _navigationPreview . currentPage , this . _navigationPreview . pageCount ) ;
}
} ,
2016-03-11 00:48:53 +00:00
warnCheckMargings : 'Margins are incorrect' ,
strAllSheets : 'All Sheets' ,
2019-01-18 14:25:13 +00:00
textWarning : 'Warning' ,
2020-03-17 14:55:37 +00:00
txtCustom : 'Custom' ,
textInvalidRange : 'ERROR! Invalid cells range' ,
textRepeat : 'Repeat...' ,
textNoRepeat : 'Not repeat' ,
2020-04-06 14:57:55 +00:00
textSelectRange : 'Select range' ,
2020-03-17 14:55:37 +00:00
textFrozenRows : 'Frozen rows' ,
textFrozenCols : 'Frozen columns' ,
textFirstRow : 'First row' ,
textFirstCol : 'First column'
2016-03-11 00:48:53 +00:00
} , SSE . Controllers . Print || { } ) ) ;
} ) ;