2019-04-05 11:28:51 +00:00
/ *
*
* ( c ) Copyright Ascensio System SIA 2010 - 2019
*
* 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
*
* /
/ * *
* WatermarkSettingsDialog . js . js
*
* Created by Julia Radzhabova on 04.04 . 2019
* Copyright ( c ) 2019 Ascensio System SIA . All rights reserved .
*
* /
define ( [ 'text!documenteditor/main/app/template/WatermarkSettings.template' ,
'common/main/lib/util/utils' ,
'common/main/lib/component/RadioBox' ,
'common/main/lib/component/InputField' ,
'common/main/lib/view/AdvancedSettingsWindow'
] , function ( template ) { 'use strict' ;
2019-05-08 11:38:39 +00:00
DE . Views . WatermarkText = new ( function ( ) {
var langs ;
var _get = function ( ) {
2019-08-09 08:44:02 +00:00
return langs ;
} ;
var _load = function ( callback ) {
2019-05-08 11:38:39 +00:00
langs = [ ] ;
2019-08-09 08:44:02 +00:00
Common . Utils . loadConfig ( 'resources/watermark/wm-text.json' , function ( langJson ) {
2019-05-08 11:38:39 +00:00
for ( var lang in langJson ) {
var val = Common . util . LanguageInfo . getLocalLanguageCode ( lang ) ;
if ( val ) {
langs . push ( { code : val , name : Common . util . LanguageInfo . getLocalLanguageName ( val ) [ 1 ] , shortname : Common . util . LanguageInfo . getLocalLanguageName ( val ) [ 0 ] , text : langJson [ lang ] } ) ;
}
}
langs . sort ( function ( a , b ) {
if ( a . shortname < b . shortname ) return - 1 ;
if ( a . shortname > b . shortname ) return 1 ;
return 0 ;
} ) ;
2019-08-09 08:44:02 +00:00
callback && callback ( langs ) ;
} ) ;
2019-05-08 11:38:39 +00:00
} ;
return {
2019-08-09 08:44:02 +00:00
get : _get ,
load : _load
2019-05-08 11:38:39 +00:00
} ;
} ) ( ) ;
2019-04-05 11:28:51 +00:00
DE . Views . WatermarkSettingsDialog = Common . Views . AdvancedSettingsWindow . extend ( _ . extend ( {
options : {
contentWidth : 400 ,
height : 442
} ,
initialize : function ( options ) {
var me = this ;
_ . extend ( this . options , {
title : this . textTitle ,
template : _ . template (
[
'<div class="box" style="height:' + ( me . options . height - 85 ) + 'px;">' ,
'<div class="content-panel" style="padding: 10px 5px;"><div class="inner-content">' ,
'<div class="settings-panel active">' ,
template ,
'</div></div>' ,
'</div>' ,
'</div>'
] . join ( '' )
) ( {
scope : this
} )
} , options ) ;
this . handler = options . handler ;
this . props = options . props ;
this . fontStore = options . fontStore ;
this . api = options . api ;
2019-05-06 11:41:58 +00:00
this . textControls = [ ] ;
this . imageControls = [ ] ;
2019-06-17 14:05:27 +00:00
this . fontName = 'Arial' ;
2019-08-09 08:44:02 +00:00
this . text = '' ;
2019-06-18 09:22:24 +00:00
this . isAutoColor = false ;
2019-06-19 08:22:10 +00:00
this . isImageLoaded = false ;
2019-04-05 11:28:51 +00:00
2019-09-16 11:46:03 +00:00
var lang = options . lang || 'en' ,
val = Common . util . LanguageInfo . getLocalLanguageCode ( lang ) ;
this . lang = val ? { value : lang , displayValue : Common . util . LanguageInfo . getLocalLanguageName ( val ) [ 1 ] , default : true } : { value : 'en' , displayValue : 'English' , default : true } ;
2019-04-05 11:28:51 +00:00
Common . Views . AdvancedSettingsWindow . prototype . initialize . call ( this , this . options ) ;
} ,
render : function ( ) {
Common . Views . AdvancedSettingsWindow . prototype . render . call ( this ) ;
var me = this ;
this . radioNone = new Common . UI . RadioBox ( {
el : $ ( '#watermark-radio-none' ) ,
name : 'asc-radio-watermark-type' ,
labelText : this . textNone ,
2019-05-06 11:41:58 +00:00
checked : false
2019-04-05 11:28:51 +00:00
} ) ;
2019-04-05 12:03:01 +00:00
this . radioNone . on ( 'change' , _ . bind ( function ( field , newValue , eOpts ) {
if ( newValue ) {
// disable text and image
2019-06-17 14:05:27 +00:00
this . props . put _Type ( Asc . c _oAscWatermarkType . None ) ;
this . disableControls ( Asc . c _oAscWatermarkType . None ) ;
2019-04-05 12:03:01 +00:00
}
} , this ) ) ;
2019-04-05 11:28:51 +00:00
this . radioImage = new Common . UI . RadioBox ( {
el : $ ( '#watermark-radio-image' ) ,
name : 'asc-radio-watermark-type' ,
labelText : this . textImageW ,
2019-05-06 11:41:58 +00:00
checked : false
2019-04-05 11:28:51 +00:00
} ) ;
2019-04-05 12:03:01 +00:00
this . radioImage . on ( 'change' , _ . bind ( function ( field , newValue , eOpts ) {
if ( newValue ) {
// disable text
2019-06-17 14:05:27 +00:00
this . props . put _Type ( Asc . c _oAscWatermarkType . Image ) ;
this . disableControls ( Asc . c _oAscWatermarkType . Image ) ;
2019-04-05 12:03:01 +00:00
}
} , this ) ) ;
2019-04-05 11:28:51 +00:00
this . radioText = new Common . UI . RadioBox ( {
el : $ ( '#watermark-radio-text' ) ,
name : 'asc-radio-watermark-type' ,
labelText : this . textTextW ,
checked : true
} ) ;
2019-04-05 12:03:01 +00:00
this . radioText . on ( 'change' , _ . bind ( function ( field , newValue , eOpts ) {
if ( newValue ) {
// disable image
2019-06-17 14:05:27 +00:00
this . props . put _Type ( Asc . c _oAscWatermarkType . Text ) ;
this . disableControls ( Asc . c _oAscWatermarkType . Text ) ;
2019-04-05 12:03:01 +00:00
}
} , this ) ) ;
2019-04-05 11:28:51 +00:00
// Image watermark
this . btnFromFile = new Common . UI . Button ( {
el : $ ( '#watermark-from-file' )
} ) ;
this . btnFromFile . on ( 'click' , _ . bind ( function ( btn ) {
2019-06-17 14:05:27 +00:00
this . props . showFileDialog ( ) ;
2019-04-05 11:28:51 +00:00
} , this ) ) ;
2019-05-06 11:41:58 +00:00
this . imageControls . push ( this . btnFromFile ) ;
2019-04-05 11:28:51 +00:00
this . btnFromUrl = new Common . UI . Button ( {
el : $ ( '#watermark-from-url' )
} ) ;
2019-06-17 14:05:27 +00:00
this . btnFromUrl . on ( 'click' , _ . bind ( this . insertFromUrl , this ) ) ;
2019-05-06 11:41:58 +00:00
this . imageControls . push ( this . btnFromUrl ) ;
2019-04-05 11:28:51 +00:00
this . _arrScale = [
{ displayValue : this . textAuto , value : - 1 } ,
{ displayValue : '500%' , value : 500 } ,
{ displayValue : '200%' , value : 200 } ,
{ displayValue : '150%' , value : 150 } ,
{ displayValue : '100%' , value : 100 } ,
{ displayValue : '50%' , value : 50 }
] ;
this . cmbScale = new Common . UI . ComboBox ( {
el : $ ( '#watermark-combo-scale' ) ,
cls : 'input-group-nr' ,
menuStyle : 'min-width: 90px;' ,
data : this . _arrScale
} ) . on ( 'selected' , _ . bind ( function ( combo , record ) {
} , this ) ) ;
this . cmbScale . setValue ( this . _arrScale [ 0 ] . value ) ;
2019-05-06 11:41:58 +00:00
this . imageControls . push ( this . cmbScale ) ;
2019-04-05 11:28:51 +00:00
// Text watermark
2019-05-08 11:38:39 +00:00
this . cmbLang = new Common . UI . ComboBox ( {
el : $ ( '#watermark-combo-lang' ) ,
cls : 'input-group-nr' ,
editable : false ,
menuStyle : 'min-width: 100%;max-height: 210px;' ,
scrollAlwaysVisible : true ,
data : [ ]
2019-06-18 13:20:52 +00:00
} ) . on ( 'selected' , _ . bind ( this . onSelectLang , this ) ) ;
2019-08-09 08:44:02 +00:00
this . cmbLang . setValue ( Common . util . LanguageInfo . getLocalLanguageName ( 9 ) [ 1 ] ) ; //en
2019-05-08 11:38:39 +00:00
this . textControls . push ( this . cmbLang ) ;
2019-04-05 11:28:51 +00:00
this . cmbText = new Common . UI . ComboBox ( {
el : $ ( '#watermark-combo-text' ) ,
cls : 'input-group-nr' ,
2019-05-08 11:38:39 +00:00
menuStyle : 'min-width: 100%;max-height: 210px;' ,
scrollAlwaysVisible : true ,
displayField : 'value' ,
data : [ { value : "ASAP" } , { value : "CONFIDENTIAL" } , { value : "COPY" } , { value : "DO NOT COPY" } , { value : "DRAFT" } , { value : "ORIGINAL" } , { value : "PERSONAL" } , { value : "SAMPLE" } , { value : "TOP SECRET" } , { value : "URGENT" } ]
2019-04-05 11:28:51 +00:00
} ) . on ( 'selected' , _ . bind ( function ( combo , record ) {
} , this ) ) ;
2019-05-08 11:38:39 +00:00
this . cmbText . setValue ( this . cmbText . options . data [ 0 ] . value ) ;
2019-05-06 11:41:58 +00:00
this . textControls . push ( this . cmbText ) ;
2019-04-05 11:28:51 +00:00
this . cmbFonts = new Common . UI . ComboBoxFonts ( {
el : $ ( '#watermark-fonts' ) ,
cls : 'input-group-nr' ,
style : 'width: 142px;' ,
menuCls : 'scrollable-menu' ,
menuStyle : 'min-width: 100%;max-height: 270px;' ,
store : new Common . Collections . Fonts ( ) ,
recent : 0 ,
hint : this . tipFontName
2019-06-17 14:05:27 +00:00
} ) . on ( 'selected' , _ . bind ( function ( combo , record ) {
this . fontName = record . name ;
} , this ) ) ;
2019-05-06 11:41:58 +00:00
this . textControls . push ( this . cmbFonts ) ;
2019-04-05 11:28:51 +00:00
var data = [
{ value : - 1 , displayValue : this . textAuto } ,
{ value : 36 , displayValue : "36" } ,
2019-06-18 09:22:24 +00:00
{ value : 40 , displayValue : "40" } ,
{ value : 44 , displayValue : "44" } ,
2019-04-05 11:28:51 +00:00
{ value : 48 , displayValue : "48" } ,
2019-06-18 09:22:24 +00:00
{ value : 54 , displayValue : "54" } ,
{ value : 60 , displayValue : "60" } ,
{ value : 66 , displayValue : "66" } ,
{ value : 72 , displayValue : "72" } ,
{ value : 80 , displayValue : "80" } ,
{ value : 90 , displayValue : "90" } ,
{ value : 96 , displayValue : "96" } ,
{ value : 105 , displayValue : "105" } ,
{ value : 120 , displayValue : "120" } ,
{ value : 144 , displayValue : "144" }
2019-04-05 11:28:51 +00:00
] ;
this . cmbFontSize = new Common . UI . ComboBox ( {
el : $ ( '#watermark-font-size' ) ,
cls : 'input-group-nr' ,
style : 'width: 55px;' ,
menuCls : 'scrollable-menu' ,
menuStyle : 'min-width: 55px;max-height: 270px;' ,
hint : this . tipFontSize ,
data : data
} ) ;
this . cmbFontSize . setValue ( - 1 ) ;
2019-05-06 11:41:58 +00:00
this . textControls . push ( this . cmbFontSize ) ;
2019-04-05 11:28:51 +00:00
this . btnBold = new Common . UI . Button ( {
cls : 'btn-toolbar' ,
iconCls : 'btn-bold' ,
enableToggle : true ,
hint : this . textBold
} ) ;
this . btnBold . render ( $ ( '#watermark-bold' ) ) ;
2019-05-06 11:41:58 +00:00
this . textControls . push ( this . btnBold ) ;
2019-04-05 11:28:51 +00:00
this . btnItalic = new Common . UI . Button ( {
cls : 'btn-toolbar' ,
iconCls : 'btn-italic' ,
enableToggle : true ,
hint : this . textItalic
} ) ;
this . btnItalic . render ( $ ( '#watermark-italic' ) ) ;
2019-05-06 11:41:58 +00:00
this . textControls . push ( this . btnItalic ) ;
2019-04-05 11:28:51 +00:00
this . btnUnderline = new Common . UI . Button ( {
cls : 'btn-toolbar' ,
iconCls : 'btn-underline' ,
enableToggle : true ,
hint : this . textUnderline
} ) ;
this . btnUnderline . render ( $ ( '#watermark-underline' ) ) ;
2019-05-06 11:41:58 +00:00
this . textControls . push ( this . btnUnderline ) ;
2019-04-05 11:28:51 +00:00
this . btnStrikeout = new Common . UI . Button ( {
cls : 'btn-toolbar' ,
iconCls : 'btn-strikeout' ,
enableToggle : true ,
hint : this . textStrikeout
} ) ;
this . btnStrikeout . render ( $ ( '#watermark-strikeout' ) ) ;
2019-05-06 11:41:58 +00:00
this . textControls . push ( this . btnStrikeout ) ;
2019-04-05 11:28:51 +00:00
var initNewColor = function ( btn , picker _el ) {
if ( btn && btn . cmpEl ) {
2019-06-18 09:22:24 +00:00
btn . currentColor = '#c0c0c0' ;
2019-04-05 11:28:51 +00:00
var colorVal = $ ( '<div class="btn-color-value-line"></div>' ) ;
$ ( 'button:first-child' , btn . cmpEl ) . append ( colorVal ) ;
colorVal . css ( 'background-color' , btn . currentColor ) ;
var picker = new Common . UI . ThemeColorPalette ( {
el : $ ( picker _el )
} ) ;
}
btn . menu . cmpEl . on ( 'click' , picker _el + '-new' , _ . bind ( function ( ) {
picker . addNewColor ( ( typeof ( btn . color ) == 'object' ) ? btn . color . color : btn . color ) ;
} , me ) ) ;
picker . on ( 'select' , _ . bind ( me . onColorSelect , me ) ) ;
return picker ;
} ;
this . btnTextColor = new Common . UI . Button ( {
cls : 'btn-toolbar' ,
iconCls : 'btn-fontcolor' ,
hint : this . textColor ,
menu : new Common . UI . Menu ( {
items : [
{
id : 'watermark-auto-color' ,
caption : this . textAuto ,
template : _ . template ( '<a tabindex="-1" type="menuitem"><span class="menu-item-icon" style="background-image: none; width: 12px; height: 12px; margin: 1px 7px 0 -7px; background-color: #000;"></span><%= caption %></a>' )
} ,
{ caption : '--' } ,
{ template : _ . template ( '<div id="watermark-menu-textcolor" style="width: 169px; height: 220px; margin: 10px;"></div>' ) } ,
{ template : _ . template ( '<a id="watermark-menu-textcolor-new" style="padding-left:12px;">' + this . textNewColor + '</a>' ) }
]
} )
} ) ;
this . btnTextColor . render ( $ ( '#watermark-textcolor' ) ) ;
this . mnuTextColorPicker = initNewColor ( this . btnTextColor , "#watermark-menu-textcolor" ) ;
$ ( '#watermark-auto-color' ) . on ( 'click' , _ . bind ( this . onAutoColor , this ) ) ;
2019-05-06 11:41:58 +00:00
this . textControls . push ( this . btnTextColor ) ;
2019-04-05 11:28:51 +00:00
2019-06-17 14:05:27 +00:00
this . chTransparency = new Common . UI . CheckBox ( {
el : $ ( '#watermark-chb-transparency' ) ,
2019-06-18 09:22:24 +00:00
labelText : this . textTransparency ,
value : true
2019-04-05 11:28:51 +00:00
} ) ;
2019-06-17 14:05:27 +00:00
this . textControls . push ( this . chTransparency ) ;
2019-04-05 11:28:51 +00:00
this . radioDiag = new Common . UI . RadioBox ( {
el : $ ( '#watermark-radio-diag' ) ,
name : 'asc-radio-watermark-layout' ,
labelText : this . textDiagonal ,
checked : true
} ) ;
2019-05-06 11:41:58 +00:00
this . textControls . push ( this . radioDiag ) ;
2019-04-05 11:28:51 +00:00
this . radioHor = new Common . UI . RadioBox ( {
el : $ ( '#watermark-radio-hor' ) ,
name : 'asc-radio-watermark-layout' ,
labelText : this . textHor
} ) ;
2019-05-06 11:41:58 +00:00
this . textControls . push ( this . radioHor ) ;
2019-04-05 11:28:51 +00:00
2019-06-19 08:22:10 +00:00
this . btnOk = new Common . UI . Button ( {
el : this . $window . find ( '.primary' ) ,
disabled : true
} ) ;
2019-04-05 11:28:51 +00:00
this . afterRender ( ) ;
} ,
onColorSelect : function ( picker , color ) {
var clr _item = this . btnTextColor . menu . $el . find ( '#watermark-auto-color > a' ) ;
clr _item . hasClass ( 'selected' ) && clr _item . removeClass ( 'selected' ) ;
this . isAutoColor = false ;
var clr = ( typeof ( color ) == 'object' ) ? color . color : color ;
this . btnTextColor . currentColor = color ;
$ ( '.btn-color-value-line' , this . btnTextColor . cmpEl ) . css ( 'background-color' , '#' + clr ) ;
} ,
updateThemeColors : function ( ) {
this . mnuTextColorPicker . updateColors ( Common . Utils . ThemeColor . getEffectColors ( ) , Common . Utils . ThemeColor . getStandartColors ( ) ) ;
} ,
addNewColor : function ( picker , btn ) {
picker . addNewColor ( ( typeof ( btn . color ) == 'object' ) ? btn . color . color : btn . color ) ;
} ,
onAutoColor : function ( e ) {
var clr _item = this . btnTextColor . menu . $el . find ( '#watermark-auto-color > a' ) ;
! clr _item . hasClass ( 'selected' ) && clr _item . addClass ( 'selected' ) ;
this . isAutoColor = true ;
var color = "000" ;
this . btnTextColor . currentColor = color ;
$ ( '.btn-color-value-line' , this . btnTextColor . cmpEl ) . css ( 'background-color' , '#' + color ) ;
2019-06-18 09:22:24 +00:00
this . mnuTextColorPicker . clearSelection ( ) ;
2019-04-05 11:28:51 +00:00
} ,
afterRender : function ( ) {
this . cmbFonts . fillFonts ( this . fontStore ) ;
2019-06-17 14:05:27 +00:00
this . cmbFonts . selectRecord ( this . fontStore . findWhere ( { name : this . fontName } ) ) ;
2019-04-05 11:28:51 +00:00
this . updateThemeColors ( ) ;
this . _setDefaults ( this . props ) ;
2019-06-19 08:22:10 +00:00
var me = this ;
var onApiWMLoaded = function ( ) {
me . isImageLoaded = true ;
me . btnOk . setDisabled ( false ) ;
} ;
this . api . asc _registerCallback ( 'asc_onWatermarkImageLoaded' , onApiWMLoaded ) ;
this . on ( 'close' , function ( obj ) {
me . api . asc _unregisterCallback ( 'asc_onWatermarkImageLoaded' , onApiWMLoaded ) ;
} ) ;
2019-04-05 11:28:51 +00:00
} ,
show : function ( ) {
Common . Views . AdvancedSettingsWindow . prototype . show . apply ( this , arguments ) ;
} ,
2019-05-08 11:38:39 +00:00
loadLanguages : function ( ) {
2019-08-09 08:44:02 +00:00
var me = this ;
var callback = function ( languages ) {
var data = [ ] ;
me . languages = languages ;
me . languages && me . languages . forEach ( function ( item ) {
data . push ( { displayValue : item . name , value : item . shortname , wmtext : item . text } ) ;
} ) ;
if ( data . length ) {
me . cmbLang . setData ( data ) ;
2019-09-16 11:46:03 +00:00
var res = me . loadWMText ( me . lang . value ) ;
if ( res && me . lang . default )
me . cmbLang . setValue ( res ) ;
else
me . cmbLang . setValue ( me . lang . displayValue ) ;
2019-08-09 08:44:02 +00:00
me . cmbLang . setDisabled ( ! me . radioText . getValue ( ) ) ;
me . text && me . cmbText . setValue ( me . text ) ;
} else
me . cmbLang . setDisabled ( true ) ;
} ;
var languages = DE . Views . WatermarkText . get ( ) ;
if ( languages )
callback ( languages ) ;
else
DE . Views . WatermarkText . load ( callback ) ;
2019-05-08 11:38:39 +00:00
} ,
2019-06-18 13:20:52 +00:00
onSelectLang : function ( combo , record ) {
2019-05-08 11:38:39 +00:00
if ( ! record ) return ;
var data = [ ] ;
record . wmtext . forEach ( function ( item ) {
data . push ( { value : item } ) ;
} ) ;
2019-08-09 12:08:30 +00:00
this . lang = record ;
2019-08-09 08:44:02 +00:00
if ( data . length > 0 ) {
this . cmbText . setData ( data ) ;
this . cmbText . setValue ( data [ 0 ] . value ) ;
}
2019-06-18 13:20:52 +00:00
} ,
loadWMText : function ( lang ) {
if ( ! lang ) return ;
var data = [ ] ;
var item = this . cmbLang . store . findWhere ( { value : lang } ) ;
if ( ! item )
item = this . cmbLang . store . findWhere ( { value : lang . split ( /[\-\_]/ ) [ 0 ] } ) ;
if ( ! item )
item = this . cmbLang . store . findWhere ( { value : 'en' } ) ;
if ( ! item )
item = this . cmbLang . store . at ( 0 ) ;
item && item . get ( 'wmtext' ) . forEach ( function ( item ) {
data . push ( { value : item } ) ;
} ) ;
2019-08-09 08:44:02 +00:00
if ( data . length > 0 ) {
this . cmbText . setData ( data ) ;
this . cmbText . setValue ( data [ 0 ] . value ) ;
}
2019-09-16 11:46:03 +00:00
return item ? item . get ( 'displayValue' ) : null ;
2019-05-08 11:38:39 +00:00
} ,
2019-06-17 14:05:27 +00:00
insertFromUrl : function ( ) {
var me = this ;
( new Common . Views . ImageFromUrlDialog ( {
handler : function ( result , value ) {
if ( result == 'ok' ) {
var checkUrl = value . replace ( / /g , '' ) ;
if ( ! _ . isEmpty ( checkUrl ) ) {
me . props . put _ImageUrl ( checkUrl ) ;
}
}
}
} ) ) . show ( ) ;
} ,
2019-04-05 11:28:51 +00:00
_setDefaults : function ( props ) {
2019-05-08 11:38:39 +00:00
this . loadLanguages ( ) ;
2019-04-05 11:28:51 +00:00
if ( props ) {
2019-06-17 14:05:27 +00:00
props . put _DivId ( 'watermark-texture-img' ) ;
props . put _Api ( this . api ) ;
2019-06-19 08:22:10 +00:00
var val ,
type = props . get _Type ( ) ;
if ( type == Asc . c _oAscWatermarkType . None ) {
this . radioNone . setValue ( true , true ) ;
} else if ( type == Asc . c _oAscWatermarkType . Image ) {
this . radioImage . setValue ( true , true ) ;
this . isImageLoaded = ! ! props . get _ImageUrl ( ) ;
2019-06-17 14:05:27 +00:00
val = props . get _Scale ( ) || - 1 ;
2019-06-18 09:22:24 +00:00
this . cmbScale . setValue ( ( val < 0 ) ? - 1 : Math . round ( val * 100 ) , Math . round ( val * 100 ) + ' %' ) ;
2019-04-05 11:28:51 +00:00
} else {
2019-06-19 08:22:10 +00:00
this . radioText . setValue ( true , true ) ;
2019-06-17 14:05:27 +00:00
! props . get _IsDiagonal ( ) && this . radioHor . setValue ( true ) ;
this . chTransparency . setValue ( props . get _Opacity ( ) < 255 ) ;
2019-04-05 11:28:51 +00:00
2019-06-17 14:05:27 +00:00
val = props . get _TextPr ( ) ;
if ( val ) {
2019-06-18 13:20:52 +00:00
var lang = Common . util . LanguageInfo . getLocalLanguageName ( val . get _Lang ( ) ) ;
2019-08-09 12:08:30 +00:00
this . lang = { value : lang [ 0 ] , displayValue : lang [ 1 ] } ;
2019-06-18 13:20:52 +00:00
this . cmbLang . setValue ( lang [ 1 ] ) ;
this . loadWMText ( lang [ 0 ] ) ;
2019-06-17 14:05:27 +00:00
var font = val . get _FontFamily ( ) . get _Name ( ) ;
if ( font ) {
var rec = this . cmbFonts . store . findWhere ( { name : font } ) ;
this . fontName = ( rec ) ? rec . get ( 'name' ) : font ;
this . cmbFonts . setValue ( this . fontName ) ;
}
this . cmbFontSize . setValue ( val . get _FontSize ( ) ) ;
this . btnBold . toggle ( val . get _Bold ( ) ) ;
this . btnItalic . toggle ( val . get _Italic ( ) ) ;
this . btnUnderline . toggle ( val . get _Underline ( ) ) ;
this . btnStrikeout . toggle ( val . get _Strikeout ( ) ) ;
2019-06-18 09:22:24 +00:00
var color = val . get _Color ( ) ,
clr _item = this . btnTextColor . menu . $el . find ( '#watermark-auto-color > a' ) ,
clr = "c0c0c0" ;
if ( color . get _auto ( ) ) {
clr = "000" ;
this . isAutoColor = true ;
this . mnuTextColorPicker . clearSelection ( ) ;
! clr _item . hasClass ( 'selected' ) && clr _item . addClass ( 'selected' ) ;
} else {
clr _item . hasClass ( 'selected' ) && clr _item . removeClass ( 'selected' ) ;
if ( color ) {
color . get _type ( ) == Asc . c _oAscColor . COLOR _TYPE _SCHEME ?
clr = { color : Common . Utils . ThemeColor . getHexColor ( color . get _r ( ) , color . get _g ( ) , color . get _b ( ) ) , effectValue : color . get _value ( ) } :
clr = Common . Utils . ThemeColor . getHexColor ( color . get _r ( ) , color . get _g ( ) , color . get _b ( ) ) ;
}
if ( typeof ( clr ) == 'object' ) {
var isselected = false ;
for ( var i = 0 ; i < 10 ; i ++ ) {
if ( Common . Utils . ThemeColor . ThemeValues [ i ] == clr . effectValue ) {
this . mnuTextColorPicker . select ( clr , true ) ;
isselected = true ;
break ;
}
}
if ( ! isselected ) this . mnuTextColorPicker . clearSelection ( ) ;
} else {
this . mnuTextColorPicker . select ( clr , true ) ;
}
}
this . btnTextColor . currentColor = clr ;
2019-06-18 13:20:52 +00:00
$ ( '.btn-color-value-line' , this . btnTextColor . cmpEl ) . css ( 'background-color' , '#' + ( ( typeof ( clr ) == 'object' ) ? clr . color : clr ) ) ;
2019-06-17 14:05:27 +00:00
}
2019-06-18 13:20:52 +00:00
val = props . get _Text ( ) ;
val && this . cmbText . setValue ( val ) ;
2019-08-09 08:44:02 +00:00
this . text = val || '' ;
2019-06-17 14:05:27 +00:00
}
2019-06-19 08:22:10 +00:00
this . disableControls ( type ) ;
2019-04-05 11:28:51 +00:00
}
} ,
getSettings : function ( ) {
2019-06-17 14:05:27 +00:00
var props = this . props ;
2019-04-05 11:28:51 +00:00
2019-06-17 14:05:27 +00:00
var val = this . props . get _Type ( ) ;
if ( val == Asc . c _oAscWatermarkType . Image ) {
2019-06-18 09:22:24 +00:00
val = this . cmbScale . getValue ( ) ;
2019-06-17 14:05:27 +00:00
val = props . put _Scale ( ( val < 0 ) ? val : val / 100 ) ;
2019-04-05 11:28:51 +00:00
} else {
2019-06-17 14:05:27 +00:00
props . put _Text ( this . cmbText . getValue ( ) ) ;
props . put _IsDiagonal ( this . radioDiag . getValue ( ) ) ;
props . put _Opacity ( ( this . chTransparency . getValue ( ) == 'checked' ) ? 128 : 255 ) ;
2019-04-05 11:28:51 +00:00
2019-06-17 14:05:27 +00:00
val = props . get _TextPr ( ) || new Asc . CTextProp ( ) ;
if ( val ) {
2019-06-18 09:22:24 +00:00
val . put _FontSize ( this . cmbFontSize . getValue ( ) ) ;
2019-06-17 14:05:27 +00:00
var font = new AscCommon . asc _CTextFontFamily ( ) ;
font . put _Name ( this . fontName ) ;
font . put _Index ( - 1 ) ;
val . put _FontFamily ( font ) ;
val . put _Bold ( this . btnBold . pressed ) ;
val . put _Italic ( this . btnItalic . pressed ) ;
val . put _Underline ( this . btnUnderline . pressed ) ;
val . put _Strikeout ( this . btnStrikeout . pressed ) ;
2019-06-18 09:22:24 +00:00
2019-08-09 12:08:30 +00:00
val . put _Lang ( parseInt ( Common . util . LanguageInfo . getLocalLanguageCode ( this . lang . value ) ) ) ;
2019-06-18 13:20:52 +00:00
2019-06-18 09:22:24 +00:00
var color = new Asc . asc _CColor ( ) ;
if ( this . isAutoColor ) {
color . put _auto ( true ) ;
} else {
color = Common . Utils . ThemeColor . getRgbColor ( this . btnTextColor . currentColor ) ;
}
val . put _Color ( color ) ;
2019-06-17 14:05:27 +00:00
props . put _TextPr ( val ) ;
}
}
2019-04-05 11:28:51 +00:00
2019-06-17 14:05:27 +00:00
return this . props ;
2019-04-05 11:28:51 +00:00
} ,
2019-05-06 11:41:58 +00:00
disableControls : function ( type ) { // 0 - none, 1 - text, 2 - image
2019-06-17 14:05:27 +00:00
var disable = ( type != Asc . c _oAscWatermarkType . Image ) ;
2019-05-06 11:41:58 +00:00
_ . each ( this . imageControls , function ( item ) {
item . setDisabled ( disable ) ;
} ) ;
2019-06-17 14:05:27 +00:00
disable = ( type != Asc . c _oAscWatermarkType . Text ) ;
2019-05-06 11:41:58 +00:00
_ . each ( this . textControls , function ( item ) {
item . setDisabled ( disable ) ;
} ) ;
2019-08-09 08:44:02 +00:00
this . cmbLang . setDisabled ( disable || ! this . languages || this . languages . length < 1 ) ;
2019-06-19 08:22:10 +00:00
this . btnOk . setDisabled ( type == Asc . c _oAscWatermarkType . Image && ! this . isImageLoaded ) ;
2019-05-06 11:41:58 +00:00
} ,
2019-04-05 11:28:51 +00:00
onDlgBtnClick : function ( event ) {
2019-06-19 08:22:10 +00:00
this . _handleInput ( event . currentTarget . attributes [ 'result' ] . value ) ;
} ,
onPrimary : function ( ) {
this . _handleInput ( 'ok' ) ;
return false ;
} ,
_handleInput : function ( state ) {
if ( this . handler ) {
if ( state == 'ok' && this . btnOk . isDisabled ( ) ) {
return ;
}
this . handler . call ( this , state , this . getSettings ( ) ) ;
2019-04-05 11:28:51 +00:00
}
this . close ( ) ;
} ,
textTitle : 'Watermark Settings' ,
textNone : 'None' ,
textImageW : 'Image watermark' ,
textTextW : 'Text watermark' ,
textFromUrl : 'From URL' ,
textFromFile : 'From File' ,
textScale : 'Scale' ,
textAuto : 'Auto' ,
textText : 'Text' ,
textFont : 'Font' ,
tipFontName : 'Font Name' ,
tipFontSize : 'Font Size' ,
textBold : 'Bold' ,
textItalic : 'Italic' ,
textUnderline : 'Underline' ,
textStrikeout : 'Strikeout' ,
2019-06-17 14:05:27 +00:00
textTransparency : 'Semitransparent' ,
2019-04-05 11:28:51 +00:00
textLayout : 'Layout' ,
textDiagonal : 'Diagonal' ,
textHor : 'Horizontal' ,
textColor : 'Text color' ,
2019-05-08 11:38:39 +00:00
textNewColor : 'Add New Custom Color' ,
textLanguage : 'Language'
2019-04-05 11:28:51 +00:00
} , DE . Views . WatermarkSettingsDialog || { } ) )
} ) ;