2020-07-02 15:10:27 +00:00
/ *
*
* ( c ) Copyright Ascensio System SIA 2010 - 2020
*
* This program is a free software product . You can redistribute it and / or
* modify it under the terms of the GNU Affero General Public License ( AGPL )
* version 3 as published by the Free Software Foundation . In accordance with
* Section 7 ( a ) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non - infringement
* of any third - party rights .
*
* This program is distributed WITHOUT ANY WARRANTY ; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . For
* details , see the GNU AGPL at : http : //www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20 A - 12 Ernesta Birznieka - Upisha
* street , Riga , Latvia , EU , LV - 1050.
*
* 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
*
* /
/ * *
* ChartDataRangeDialog . js
*
* Created by Julia Radzhabova on 02.07 . 2020
* Copyright ( c ) 2020 Ascensio System SIA . All rights reserved .
*
* /
if ( Common === undefined )
var Common = { } ;
define ( [
'common/main/lib/component/InputField' ,
'common/main/lib/component/Window'
] , function ( ) { 'use strict' ;
SSE . Views . ChartDataRangeDialog = Common . UI . Window . extend ( _ . extend ( {
options : {
type : 0 , // 0 - category, 1 - series
width : 350 ,
cls : 'modal-dlg' ,
2020-10-13 11:30:52 +00:00
buttons : [ 'ok' , 'cancel' ]
2020-07-02 15:10:27 +00:00
} ,
initialize : function ( options ) {
this . type = options . type || 0 ;
2020-07-07 12:07:15 +00:00
this . isScatter = options . isScatter ;
2020-07-02 15:10:27 +00:00
_ . extend ( this . options , {
title : this . type == 1 ? this . txtTitleSeries : this . txtTitleCategory
} , options ) ;
this . template = [
'<div class="box">' ,
'<table cols="2" style="width: 100%;">' ,
'<tr>' ,
'<td colspan="2">' ,
'<label>' + ( this . type == 1 ? this . txtSeriesName : this . txtAxisLabel ) + '</label>' ,
'</td>' ,
'</tr>' ,
'<tr>' ,
'<td style="padding-bottom: 8px;width: 100%;">' ,
'<div id="id-dlg-chart-range-range1"></div>' ,
'</td>' ,
'<td style="padding-bottom: 8px;">' ,
'<label id="id-dlg-chart-range-lbl1" style="width: 120px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-left: 5px;margin-top: 4px;">' + this . txtChoose + '</label>' ,
'</td>' ,
'</tr>' ,
'<% if (type==1) { %>' ,
'<tr>' ,
'<td colspan="2">' ,
2020-07-07 12:07:15 +00:00
'<label>' + ( this . isScatter ? this . txtXValues : this . txtValues ) + '</label>' ,
2020-07-02 15:10:27 +00:00
'</td>' ,
'</tr>' ,
'<tr>' ,
'<td style="padding-bottom: 8px;width: 100%;">' ,
'<div id="id-dlg-chart-range-range2"></div>' ,
'</td>' ,
'<td style="padding-bottom: 8px;">' ,
'<label id="id-dlg-chart-range-lbl2" style="width: 120px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-left: 5px;margin-top: 4px;"></label>' ,
'</td>' ,
'</tr>' ,
2020-07-07 12:07:15 +00:00
'<% if (isScatter) { %>' ,
'<tr>' ,
'<td colspan="2">' ,
'<label>' + this . txtYValues + '</label>' ,
'</td>' ,
'</tr>' ,
'<tr>' ,
'<td style="padding-bottom: 8px;width: 100%;">' ,
'<div id="id-dlg-chart-range-range3"></div>' ,
'</td>' ,
'<td style="padding-bottom: 8px;">' ,
'<label id="id-dlg-chart-range-lbl3" style="width: 120px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-left: 5px;margin-top: 4px;"></label>' ,
'</td>' ,
'</tr>' ,
'<% } %>' ,
2020-07-02 15:10:27 +00:00
'<% } %>' ,
'</table>' ,
'</div>'
] . join ( '' ) ;
this . options . tpl = _ . template ( this . template ) ( this . options ) ;
Common . UI . Window . prototype . initialize . call ( this , this . options ) ;
} ,
render : function ( ) {
Common . UI . Window . prototype . render . call ( this ) ;
var $window = this . getChild ( ) ,
me = this ;
me . inputRange1 = new Common . UI . InputFieldBtn ( {
el : $ ( '#id-dlg-chart-range-range1' ) ,
style : '100%' ,
2020-11-18 16:23:11 +00:00
btnHint : this . textSelectData ,
2020-07-08 09:51:57 +00:00
// validateOnChange: true,
2020-07-02 15:10:27 +00:00
validateOnBlur : false
} ) . on ( 'changed:after' , function ( input , newValue , oldValue , e ) {
2020-07-08 07:41:18 +00:00
if ( newValue == oldValue ) return ;
me . updateRangeData ( 1 , newValue ) ;
2020-07-02 15:10:27 +00:00
} ) . on ( 'changing' , function ( input , newValue , oldValue , e ) {
if ( newValue == oldValue ) return ;
// me.onInputChanging(input, newValue, oldValue);
2020-07-08 07:41:18 +00:00
} ) . on ( 'button:click' , _ . bind ( this . onSelectData , this , 1 ) ) ;
2020-07-02 15:10:27 +00:00
this . lblRange1 = $window . find ( '#id-dlg-chart-range-lbl1' ) ;
me . inputRange2 = new Common . UI . InputFieldBtn ( {
el : $ ( '#id-dlg-chart-range-range2' ) ,
style : '100%' ,
2020-11-18 16:23:11 +00:00
btnHint : this . textSelectData ,
2020-07-08 09:51:57 +00:00
// validateOnChange: true,
2020-07-02 15:10:27 +00:00
validateOnBlur : false
} ) . on ( 'changed:after' , function ( input , newValue , oldValue , e ) {
2020-07-08 07:41:18 +00:00
if ( newValue == oldValue ) return ;
me . updateRangeData ( 2 , newValue ) ;
2020-07-02 15:10:27 +00:00
} ) . on ( 'changing' , function ( input , newValue , oldValue , e ) {
if ( newValue == oldValue ) return ;
// me.onInputChanging(input, newValue, oldValue);
2020-07-08 07:41:18 +00:00
} ) . on ( 'button:click' , _ . bind ( this . onSelectData , this , 2 ) ) ;
2020-07-02 15:10:27 +00:00
this . lblRange2 = $window . find ( '#id-dlg-chart-range-lbl2' ) ;
2020-07-07 12:07:15 +00:00
me . inputRange3 = new Common . UI . InputFieldBtn ( {
el : $ ( '#id-dlg-chart-range-range3' ) ,
style : '100%' ,
2020-11-18 16:23:11 +00:00
btnHint : this . textSelectData ,
2020-07-08 09:51:57 +00:00
// validateOnChange: true,
2020-07-07 12:07:15 +00:00
validateOnBlur : false
} ) . on ( 'changed:after' , function ( input , newValue , oldValue , e ) {
2020-07-08 07:41:18 +00:00
if ( newValue == oldValue ) return ;
me . updateRangeData ( 3 , newValue ) ;
2020-07-07 12:07:15 +00:00
} ) . on ( 'changing' , function ( input , newValue , oldValue , e ) {
if ( newValue == oldValue ) return ;
// me.onInputChanging(input, newValue, oldValue);
2020-07-08 07:41:18 +00:00
} ) . on ( 'button:click' , _ . bind ( this . onSelectData , this , 3 ) ) ;
2020-07-07 12:07:15 +00:00
this . lblRange3 = $window . find ( '#id-dlg-chart-range-lbl3' ) ;
2020-07-02 15:10:27 +00:00
$window . find ( '.dlg-btn' ) . on ( 'click' , _ . bind ( this . onBtnClick , this ) ) ;
} ,
2020-10-13 11:30:52 +00:00
getFocusedComponents : function ( ) {
return [ this . inputRange1 , this . inputRange2 , this . inputRange3 ] ;
} ,
2020-10-22 10:53:58 +00:00
getDefaultFocusableComponent : function ( ) {
if ( this . _alreadyRendered ) return ; // focus only at first show
this . _alreadyRendered = true ;
return this . inputRange1 ;
} ,
2020-07-02 15:10:27 +00:00
onPrimary : function ( ) {
this . _handleInput ( 'ok' ) ;
return false ;
} ,
setSettings : function ( settings ) {
var me = this ;
this . api = settings . api ;
2020-07-07 12:07:15 +00:00
this . props = settings . props ;
2020-07-08 07:41:18 +00:00
this . chartSettings = settings . chartSettings ;
if ( this . type == 1 ) {
if ( this . props . series ) {
var series = this . props . series ;
this . inputRange1 . setValue ( series . asc _getName ( ) ) ;
2020-07-08 09:51:57 +00:00
this . lblRange1 . html ( ( this . inputRange1 . getValue ( ) !== '' ) ? ( '= ' + ( series . asc _getNameVal ( ) || '' ) ) : this . txtChoose ) ;
2020-07-08 07:41:18 +00:00
if ( this . props . isScatter ) {
2020-07-08 09:51:57 +00:00
var arr = series . asc _getXValuesArr ( ) ;
2020-07-08 07:41:18 +00:00
this . inputRange2 . setValue ( series . asc _getXValues ( ) ) ;
2020-07-08 09:51:57 +00:00
this . lblRange2 . html ( ( this . inputRange2 . getValue ( ) !== '' ) ? ( '= ' + ( arr ? arr . join ( '; ' ) : '' ) ) : this . txtChoose ) ;
2020-07-08 07:41:18 +00:00
this . inputRange3 . setValue ( series . asc _getYValues ( ) ) ;
2020-07-08 09:51:57 +00:00
arr = series . asc _getYValuesArr ( ) ;
this . lblRange3 . html ( ( this . inputRange3 . getValue ( ) !== '' ) ? ( '= ' + ( arr ? arr . join ( '; ' ) : '' ) ) : this . txtChoose ) ;
2020-07-08 07:41:18 +00:00
} else {
2020-07-08 09:51:57 +00:00
var arr = series . asc _getValuesArr ( ) ;
2020-07-08 07:41:18 +00:00
this . inputRange2 . setValue ( series . asc _getValues ( ) ) ;
2020-07-08 09:51:57 +00:00
this . lblRange2 . html ( ( this . inputRange2 . getValue ( ) !== '' ) ? ( '= ' + ( arr ? arr . join ( '; ' ) : '' ) ) : this . txtChoose ) ;
2020-07-08 07:41:18 +00:00
}
2020-07-07 12:07:15 +00:00
}
2020-07-07 13:19:30 +00:00
} else {
2020-07-08 09:51:57 +00:00
var arr = this . props . values ;
2020-07-07 13:19:30 +00:00
this . inputRange1 . setValue ( this . props . category || '' ) ;
2020-07-08 09:51:57 +00:00
this . lblRange1 . html ( ( this . inputRange1 . getValue ( ) !== '' ) ? ( '= ' + ( arr ? arr . join ( '; ' ) : '' ) ) : this . txtChoose ) ;
2020-07-07 12:07:15 +00:00
}
2020-07-02 15:10:27 +00:00
} ,
getSettings : function ( ) {
2020-07-08 07:41:18 +00:00
return { name : this . inputRange1 . getValue ( ) , valuesX : this . inputRange2 . getValue ( ) , valuesY : this . inputRange3 . getValue ( ) } ;
2020-07-02 15:10:27 +00:00
} ,
2020-07-08 07:41:18 +00:00
onSelectData : function ( type , input ) {
2020-07-02 15:10:27 +00:00
var me = this ;
if ( me . api ) {
var handlerDlg = function ( dlg , result ) {
if ( result == 'ok' ) {
2020-07-08 07:41:18 +00:00
input . setValue ( dlg . getSettings ( ) ) ;
2020-07-10 16:11:55 +00:00
_ . delay ( function ( ) {
me . updateRangeData ( type , dlg . getSettings ( ) ) ;
} , 10 ) ;
2020-07-02 15:10:27 +00:00
}
} ;
var win = new SSE . Views . CellRangeDialog ( {
allowBlank : true ,
handler : handlerDlg
} ) . on ( 'close' , function ( ) {
// me.onInputChanging(input);
me . show ( ) ;
_ . delay ( function ( ) {
me . _noApply = true ;
2020-09-26 13:58:37 +00:00
input . focus ( ) ;
2020-07-02 15:10:27 +00:00
me . _noApply = false ;
} , 1 ) ;
} ) ;
var xy = me . $window . offset ( ) ;
me . hide ( ) ;
win . show ( xy . left + 65 , xy . top + 77 ) ;
win . setSettings ( {
api : me . api ,
range : ! _ . isEmpty ( input . getValue ( ) ) ? input . getValue ( ) : '' ,
2020-07-10 16:11:55 +00:00
type : Asc . c _oAscSelectionDialogType . Chart ,
validation : function ( ) { return true ; }
2020-07-02 15:10:27 +00:00
} ) ;
}
} ,
2020-07-08 07:41:18 +00:00
isRangeValid : function ( type , value ) {
var isvalid ;
2020-07-15 10:01:05 +00:00
switch ( type ) {
case 1 :
if ( this . props . series ) {
isvalid = this . props . series . asc _IsValidName ( value ) ;
} else {
isvalid = this . chartSettings . isValidCatFormula ( value ) ;
}
break ;
case 2 :
if ( this . props . isScatter ) {
isvalid = this . props . series . asc _IsValidXValues ( value ) ;
} else {
isvalid = this . props . series . asc _IsValidValues ( value ) ;
}
break ;
case 3 :
isvalid = this . props . series . asc _IsValidYValues ( value ) ;
break ;
}
if ( isvalid === true || isvalid == Asc . c _oAscError . ID . No )
2020-07-08 07:41:18 +00:00
return true ;
2020-07-15 10:01:05 +00:00
var error = this . textInvalidRange ;
switch ( isvalid ) {
case Asc . c _oAscError . ID . StockChartError :
error = this . errorStockChart ;
break ;
case Asc . c _oAscError . ID . MaxDataSeriesError :
error = this . errorMaxRows ;
break ;
case Asc . c _oAscError . ID . MaxDataPointsError :
error = this . errorMaxPoints ;
break ;
case Asc . c _oAscError . ID . ErrorInFormula :
error = this . errorInFormula ;
break ;
case Asc . c _oAscError . ID . InvalidReference :
error = this . errorInvalidReference ;
break ;
case Asc . c _oAscError . ID . NoSingleRowCol :
error = this . errorNoSingleRowCol ;
break ;
case Asc . c _oAscError . ID . NoValues :
error = this . errorNoValues ;
break ;
}
Common . UI . warning ( { msg : error , maxwidth : 600 } ) ;
2020-07-08 07:41:18 +00:00
return false ;
} ,
updateRangeData : function ( type , value ) {
if ( ! this . isRangeValid ( type , value ) ) return ;
if ( this . props . series ) {
var series = this . props . series ;
switch ( type ) {
case 1 :
series . asc _setName ( value ) ;
2020-07-08 09:51:57 +00:00
this . lblRange1 . html ( ( this . inputRange1 . getValue ( ) !== '' ) ? ( '= ' + ( series . asc _getNameVal ( ) || '' ) ) : this . txtChoose ) ;
2020-07-08 07:41:18 +00:00
break ;
case 2 :
if ( this . isScatter ) {
2020-07-08 09:51:57 +00:00
var arr = series . asc _getXValuesArr ( ) ;
2020-07-08 07:41:18 +00:00
series . asc _setXValues ( value ) ;
2020-07-08 09:51:57 +00:00
this . lblRange2 . html ( ( this . inputRange2 . getValue ( ) !== '' ) ? ( '= ' + ( arr ? arr . join ( '; ' ) : '' ) ) : this . txtChoose ) ;
2020-07-08 07:41:18 +00:00
} else {
2020-07-08 09:51:57 +00:00
var arr = series . asc _getValuesArr ( ) ;
2020-07-08 07:41:18 +00:00
series . asc _setValues ( value ) ;
2020-07-08 09:51:57 +00:00
this . lblRange2 . html ( ( this . inputRange2 . getValue ( ) !== '' ) ? ( '= ' + ( arr ? arr . join ( '; ' ) : '' ) ) : this . txtChoose ) ;
2020-07-08 07:41:18 +00:00
}
break ;
case 3 :
2020-07-08 09:51:57 +00:00
var arr = series . asc _getYValuesArr ( ) ;
2020-07-08 07:41:18 +00:00
series . asc _setYValues ( value ) ;
2020-07-08 09:51:57 +00:00
this . lblRange3 . html ( ( this . inputRange3 . getValue ( ) !== '' ) ? ( '= ' + ( arr ? arr . join ( '; ' ) : '' ) ) : this . txtChoose ) ;
2020-07-08 07:41:18 +00:00
break ;
}
} else {
2020-07-10 16:11:55 +00:00
this . chartSettings . setCatFormula ( value ) ;
2020-07-08 09:51:57 +00:00
var arr = this . chartSettings . getCatValues ( ) ;
this . lblRange1 . html ( ( this . inputRange1 . getValue ( ) !== '' ) ? ( '= ' + ( arr ? arr . join ( '; ' ) : '' ) ) : this . txtChoose ) ;
2020-07-08 07:41:18 +00:00
}
} ,
2020-07-02 15:10:27 +00:00
onBtnClick : function ( event ) {
this . _handleInput ( event . currentTarget . attributes [ 'result' ] . value ) ;
} ,
_handleInput : function ( state ) {
if ( this . options . handler ) {
if ( state == 'ok' ) {
2020-07-08 07:41:18 +00:00
if ( ! this . isRangeValid ( 1 , this . inputRange1 . getValue ( ) ) ) return ;
2020-07-15 10:01:05 +00:00
if ( this . type == 1 && ! this . isRangeValid ( 2 , this . inputRange2 . getValue ( ) ) ) return ;
if ( this . type == 1 && this . isScatter && ! this . isRangeValid ( 3 , this . inputRange3 . getValue ( ) ) ) return ;
2020-07-02 15:10:27 +00:00
}
if ( this . options . handler . call ( this , this , state ) )
return ;
}
this . close ( ) ;
} ,
txtTitleSeries : 'Edit Series' ,
txtTitleCategory : 'Axis Labels' ,
txtSeriesName : 'Series name' ,
txtValues : 'Values' ,
2020-07-07 12:07:15 +00:00
txtXValues : 'X Values' ,
txtYValues : 'Y Values' ,
2020-07-02 15:10:27 +00:00
txtAxisLabel : 'Axis label range' ,
txtChoose : 'Choose range' ,
textSelectData : 'Select data' ,
2020-07-08 12:04:19 +00:00
textInvalidRange : 'Invalid cells range' ,
errorMaxRows : 'The maximum number of data series per chart is 255.' ,
errorStockChart : 'Incorrect row order. To build a stock chart place the data on the sheet in the following order:<br> opening price, max price, min price, closing price.' ,
2020-07-15 10:01:05 +00:00
errorMaxPoints : 'The maximum number of points in series per chart is 4096.' ,
errorInFormula : "There's an error in formula you entered." ,
errorInvalidReference : 'The reference is not valid. Reference must be to an open worksheet.' ,
errorNoSingleRowCol : 'The reference is not valid. References for titles, values, sizes, or data labels must be a single cell, row, or column.' ,
errorNoValues : 'To create a chart, the series must contain at least one value.'
2020-07-08 12:04:19 +00:00
2020-07-02 15:10:27 +00:00
} , SSE . Views . ChartDataRangeDialog || { } ) )
} ) ;