2019-05-30 10:15:49 +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
*
* /
/ * *
* DataTab . js
*
* Created by Julia Radzhabova on 30.05 . 2019
* Copyright ( c ) 2019 Ascensio System SIA . All rights reserved .
*
* /
define ( [
'core' ,
'spreadsheeteditor/main/app/view/DataTab' ,
2019-10-05 11:20:38 +00:00
'spreadsheeteditor/main/app/view/GroupDialog' ,
2020-04-07 12:48:45 +00:00
'spreadsheeteditor/main/app/view/SortDialog' ,
'spreadsheeteditor/main/app/view/RemoveDuplicatesDialog'
2019-05-30 10:15:49 +00:00
] , function ( ) {
'use strict' ;
SSE . Controllers . DataTab = Backbone . Controller . extend ( _ . extend ( {
models : [ ] ,
collections : [
] ,
views : [
'DataTab'
] ,
sdkViewName : '#id_main' ,
initialize : function ( ) {
2019-05-30 12:52:25 +00:00
this . _state = {
2019-07-25 07:14:45 +00:00
CSVOptions : new Asc . asc _CTextOptions ( 0 , 4 , '' )
2019-05-30 12:52:25 +00:00
} ;
2019-05-30 10:15:49 +00:00
} ,
onLaunch : function ( ) {
} ,
setApi : function ( api ) {
if ( api ) {
this . api = api ;
this . api . asc _registerCallback ( 'asc_onSelectionChanged' , _ . bind ( this . onSelectionChanged , this ) ) ;
2019-08-06 13:12:07 +00:00
this . api . asc _registerCallback ( 'asc_onWorksheetLocked' , _ . bind ( this . onWorksheetLocked , this ) ) ;
2019-05-30 10:15:49 +00:00
this . api . asc _registerCallback ( 'asc_onCoAuthoringDisconnect' , _ . bind ( this . onCoAuthoringDisconnect , this ) ) ;
Common . NotificationCenter . on ( 'api:disconnect' , _ . bind ( this . onCoAuthoringDisconnect , this ) ) ;
}
return this ;
} ,
setConfig : function ( config ) {
this . toolbar = config . toolbar ;
this . view = this . createView ( 'DataTab' , {
toolbar : this . toolbar . toolbar
} ) ;
2019-08-28 14:19:53 +00:00
this . addListeners ( {
'DataTab' : {
'data:group' : this . onGroup ,
'data:ungroup' : this . onUngroup ,
'data:tocolumns' : this . onTextToColumn ,
'data:show' : this . onShowClick ,
'data:hide' : this . onHideClick ,
2019-10-01 11:20:52 +00:00
'data:groupsettings' : this . onGroupSettings ,
2020-04-07 12:48:45 +00:00
'data:sortcustom' : this . onCustomSort ,
'data:remduplicates' : this . onRemoveDuplicates
2019-08-28 14:19:53 +00:00
} ,
'Statusbar' : {
'sheet:changed' : this . onApiSheetChanged
}
} ) ;
2020-04-13 09:45:11 +00:00
Common . NotificationCenter . on ( 'data:remduplicates' , _ . bind ( this . onRemoveDuplicates , this ) ) ;
2019-05-30 10:15:49 +00:00
} ,
SetDisabled : function ( state ) {
this . view && this . view . SetDisabled ( state ) ;
} ,
getView : function ( name ) {
return ! name && this . view ?
this . view : Backbone . Controller . prototype . getView . call ( this , name ) ;
} ,
onCoAuthoringDisconnect : function ( ) {
this . SetDisabled ( true ) ;
} ,
onSelectionChanged : function ( info ) {
2019-05-30 12:52:25 +00:00
if ( ! this . toolbar . editMode || ! this . view ) return ;
2019-05-30 10:15:49 +00:00
// special disable conditions
2019-05-30 12:52:25 +00:00
Common . Utils . lockControls ( SSE . enumLock . multiselectCols , info . asc _getSelectedColsCount ( ) > 1 , { array : [ this . view . btnTextToColumns ] } ) ;
2020-05-14 08:45:23 +00:00
Common . Utils . lockControls ( SSE . enumLock . multiselect , info . asc _getMultiselect ( ) , { array : [ this . view . btnTextToColumns ] } ) ;
2019-05-30 10:15:49 +00:00
} ,
onUngroup : function ( type ) {
2019-06-05 12:26:29 +00:00
var me = this ;
2019-05-30 10:15:49 +00:00
if ( type == 'rows' ) {
2019-06-05 12:26:29 +00:00
( me . api . asc _checkAddGroup ( true ) !== undefined ) && me . api . asc _ungroup ( true )
2019-05-30 10:15:49 +00:00
} else if ( type == 'columns' ) {
2019-06-05 12:26:29 +00:00
( me . api . asc _checkAddGroup ( true ) !== undefined ) && me . api . asc _ungroup ( false )
2019-05-30 10:15:49 +00:00
} else if ( type == 'clear' ) {
me . api . asc _clearOutline ( ) ;
2019-06-05 11:19:33 +00:00
} else {
2019-06-05 12:26:29 +00:00
var val = me . api . asc _checkAddGroup ( true ) ;
2019-06-05 11:19:33 +00:00
if ( val === null ) {
( new SSE . Views . GroupDialog ( {
title : me . view . capBtnUngroup ,
props : 'rows' ,
handler : function ( dlg , result ) {
if ( result == 'ok' ) {
me . api . asc _ungroup ( dlg . getSettings ( ) ) ;
}
Common . NotificationCenter . trigger ( 'edit:complete' , me . toolbar ) ;
2019-05-30 10:15:49 +00:00
}
2019-06-05 11:19:33 +00:00
} ) ) . show ( ) ;
} else if ( val !== undefined ) //undefined - error, true - rows, false - columns
me . api . asc _ungroup ( val ) ;
}
2019-05-30 10:15:49 +00:00
Common . NotificationCenter . trigger ( 'edit:complete' , me . toolbar ) ;
} ,
2019-08-08 07:48:27 +00:00
onGroup : function ( type , checked ) {
if ( type == 'rows' ) {
( this . api . asc _checkAddGroup ( ) !== undefined ) && this . api . asc _group ( true )
} else if ( type == 'columns' ) {
( this . api . asc _checkAddGroup ( ) !== undefined ) && this . api . asc _group ( false )
} else if ( type == 'below' ) {
this . api . asc _setGroupSummary ( checked , false ) ;
} else if ( type == 'right' ) {
this . api . asc _setGroupSummary ( checked , true ) ;
} else {
var me = this ,
val = me . api . asc _checkAddGroup ( ) ;
if ( val === null ) {
( new SSE . Views . GroupDialog ( {
title : me . view . capBtnGroup ,
props : 'rows' ,
handler : function ( dlg , result ) {
if ( result == 'ok' ) {
me . api . asc _group ( dlg . getSettings ( ) ) ;
}
Common . NotificationCenter . trigger ( 'edit:complete' , me . toolbar ) ;
2019-05-30 10:15:49 +00:00
}
2019-08-08 07:48:27 +00:00
} ) ) . show ( ) ;
} else if ( val !== undefined ) //undefined - error, true - rows, false - columns
me . api . asc _group ( val ) ;
}
Common . NotificationCenter . trigger ( 'edit:complete' , this . toolbar ) ;
} ,
onGroupSettings : function ( menu ) {
var value = this . api . asc _getGroupSummaryBelow ( ) ;
menu . items [ 3 ] . setChecked ( ! ! value , true ) ;
value = this . api . asc _getGroupSummaryRight ( ) ;
menu . items [ 4 ] . setChecked ( ! ! value , true ) ;
2019-05-30 12:52:25 +00:00
} ,
onTextToColumn : function ( ) {
this . api . asc _TextImport ( this . _state . CSVOptions , _ . bind ( this . onTextToColumnCallback , this ) , false ) ;
} ,
onTextToColumnCallback : function ( data ) {
if ( ! data || ! data . length ) return ;
var me = this ;
( new Common . Views . OpenDialog ( {
title : me . textWizard ,
closable : true ,
type : Common . Utils . importTextType . Columns ,
preview : true ,
previewData : data ,
settings : me . _state . CSVOptions ,
api : me . api ,
handler : function ( result , encoding , delimiter , delimiterChar ) {
if ( result == 'ok' ) {
if ( me && me . api ) {
2019-07-25 07:14:45 +00:00
me . api . asc _TextToColumns ( new Asc . asc _CTextOptions ( encoding , delimiter , delimiterChar ) ) ;
2019-05-30 12:52:25 +00:00
}
}
}
} ) ) . show ( ) ;
} ,
2019-05-30 14:51:11 +00:00
onShowClick : function ( ) {
2019-05-31 07:59:38 +00:00
this . api . asc _changeGroupDetails ( true ) ;
2019-05-30 14:51:11 +00:00
} ,
onHideClick : function ( ) {
2019-05-31 07:59:38 +00:00
this . api . asc _changeGroupDetails ( false ) ;
2019-05-30 14:51:11 +00:00
} ,
2019-10-01 11:20:52 +00:00
onCustomSort : function ( ) {
var me = this ;
2019-10-05 11:20:38 +00:00
if ( this . api ) {
var res = this . api . asc _sortCellsRangeExpand ( ) ;
if ( res ) {
var config = {
width : 500 ,
2019-12-02 12:07:56 +00:00
title : this . toolbar . txtSorting ,
msg : this . toolbar . txtExpandSort ,
2019-10-05 11:20:38 +00:00
2019-12-02 12:07:56 +00:00
buttons : [ { caption : this . toolbar . txtExpand , primary : true , value : 'expand' } ,
{ caption : this . toolbar . txtSortSelected , primary : true , value : 'sort' } ,
2019-10-05 11:20:38 +00:00
'cancel' ] ,
callback : function ( btn ) {
if ( btn == 'expand' || btn == 'sort' ) {
setTimeout ( function ( ) {
me . showCustomSort ( btn == 'expand' ) ;
} , 1 ) ;
}
}
} ;
Common . UI . alert ( config ) ;
} else
me . showCustomSort ( res !== null ) ;
}
} ,
showCustomSort : function ( expand ) {
var me = this ,
props = me . api . asc _getSortProps ( expand ) ;
// props = new Asc.CSortProperties();
if ( props ) {
( new SSE . Views . SortDialog ( {
props : props ,
api : me . api ,
2019-10-10 11:46:39 +00:00
handler : function ( result , settings ) {
2019-12-26 13:27:59 +00:00
if ( me && me . api ) {
me . api . asc _setSortProps ( settings , result != 'ok' ) ;
2019-10-05 11:20:38 +00:00
}
}
} ) ) . show ( ) ;
}
2019-10-01 11:20:52 +00:00
} ,
2020-04-07 12:48:45 +00:00
onRemoveDuplicates : function ( ) {
var me = this ;
if ( this . api ) {
var res = this . api . asc _sortCellsRangeExpand ( ) ;
if ( res ) {
var config = {
width : 500 ,
title : this . txtRemDuplicates ,
msg : this . txtExpandRemDuplicates ,
buttons : [ { caption : this . txtExpand , primary : true , value : 'expand' } ,
{ caption : this . txtRemSelected , primary : true , value : 'remove' } ,
'cancel' ] ,
callback : function ( btn ) {
if ( btn == 'expand' || btn == 'remove' ) {
setTimeout ( function ( ) {
me . showRemDuplicates ( btn == 'expand' ) ;
} , 1 ) ;
}
}
} ;
Common . UI . alert ( config ) ;
} else
me . showRemDuplicates ( res !== null ) ;
}
} ,
showRemDuplicates : function ( expand ) {
var me = this ,
props = me . api . asc _getRemoveDuplicates ( expand ) ;
if ( props ) {
( new SSE . Views . RemoveDuplicatesDialog ( {
props : props ,
api : me . api ,
handler : function ( result , settings ) {
if ( me && me . api ) {
me . api . asc _setRemoveDuplicates ( settings , result != 'ok' ) ;
}
}
} ) ) . show ( ) ;
}
} ,
2019-08-06 13:12:07 +00:00
onWorksheetLocked : function ( index , locked ) {
if ( index == this . api . asc _getActiveWorksheetIndex ( ) ) {
2019-11-01 13:43:05 +00:00
Common . Utils . lockControls ( SSE . enumLock . sheetLock , locked , { array : this . view . btnsSortDown . concat ( this . view . btnsSortUp , this . view . btnCustomSort , this . view . btnGroup , this . view . btnUngroup ) } ) ;
2019-08-06 13:12:07 +00:00
}
} ,
2019-08-28 14:19:53 +00:00
onApiSheetChanged : function ( ) {
if ( ! this . toolbar . mode || ! this . toolbar . mode . isEdit || this . toolbar . mode . isEditDiagram || this . toolbar . mode . isEditMailMerge ) return ;
var currentSheet = this . api . asc _getActiveWorksheetIndex ( ) ;
this . onWorksheetLocked ( currentSheet , this . api . asc _isWorksheetLockedOrDeleted ( currentSheet ) ) ;
} ,
2020-04-07 12:48:45 +00:00
textWizard : 'Text to Columns Wizard' ,
txtRemDuplicates : 'Remove Duplicates' ,
txtExpandRemDuplicates : 'The data next to the selection will not be removed. Do you want to expand the selection to include the adjacent data or continue with the currently selected cells only?' ,
txtExpand : 'Expand' ,
txtRemSelected : 'Remove in selected'
2019-05-30 10:15:49 +00:00
} , SSE . Controllers . DataTab || { } ) ) ;
} ) ;