@ -32,7 +32,7 @@ define([
Cred ,
AppConfig ,
ApiConfig ,
Backup ,
Backup
)
{
var saveAs = window . saveAs ;
@ -303,45 +303,6 @@ define([
return $div ;
} ;
create [ 'backup' ] = function ( ) {
if ( ! common . isLoggedIn ( ) ) { return ; }
var $div = $ ( '<div>' , { 'class' : 'cp-settings-backup cp-sidebarlayout-element' } ) ;
$ ( '<span>' , { 'class' : 'label' } ) . text ( Messages . settings _backupTitle || 'TODO BACKUP' ) . appendTo ( $div ) ; // XXX
$ ( '<span>' , { 'class' : 'cp-sidebarlayout-description' } )
. append ( Messages . settings _backupHint || 'TODO' ) . appendTo ( $div ) ; // XXX
var $ok = $ ( '<span>' , { 'class' : 'fa fa-check' , title : Messages . saved } ) ;
var $spinner = $ ( '<span>' , { 'class' : 'fa fa-spinner fa-pulse' } ) ;
var $button = $ ( '<button>' , { 'id' : 'cp-settings-delete' , 'class' : 'btn btn-danger' } )
. text ( Messages . settings _backupButton || 'BACKUP' ) . appendTo ( $div ) ; // XXX
$button . click ( function ( ) {
$spinner . show ( ) ;
UI . confirm ( Messages . settings _backupConfirm || 'TODO Are you sure?' , function ( yes ) { // XXX
if ( ! yes ) { return ; }
} ) ;
// TODO
/ *
UI . confirm ( "Are you sure?" , function ( yes ) {
// Logout everywhere
// Disconnect other tabs
// Remove owned pads
// Remove owned drive
// Remove pinstore
// Alert: "Account deleted", press OK to be redirected to the home page
$spinner . hide ( ) ;
} ) ; * /
} ) ;
$spinner . hide ( ) . appendTo ( $div ) ;
$ok . hide ( ) . appendTo ( $div ) ;
return $div ;
} ;
create [ 'delete' ] = function ( ) {
if ( ! common . isLoggedIn ( ) ) { return ; }
var $div = $ ( '<div>' , { 'class' : 'cp-settings-delete cp-sidebarlayout-element' } ) ;
@ -857,6 +818,143 @@ define([
return $div ;
} ;
var createExportUI = function ( ) {
var progress = h ( 'div.cp-export-progress' ) ;
var actions = h ( 'div.cp-export-actions' ) ;
var errors = h ( 'div.cp-export-errors' , [
h ( 'p' , Messages . settings _exportErrorDescription )
] ) ;
var exportUI = h ( 'div#cp-export-container' , [
h ( 'div.cp-export-block' , [
h ( 'h3' , Messages . settings _exportTitle ) ,
h ( 'p' , [
Messages . settings _exportDescription ,
h ( 'br' ) ,
Messages . settings _exportWarning
] ) ,
progress ,
actions ,
errors
] )
] ) ;
$ ( 'body' ) . append ( exportUI ) ;
$ ( '#cp-sidebarlayout-container' ) . hide ( ) ;
var close = function ( ) {
$ ( exportUI ) . remove ( ) ;
$ ( '#cp-sidebarlayout-container' ) . show ( ) ;
} ;
var _onCancel = [ ] ;
var onCancel = function ( h ) {
if ( typeof ( h ) !== "function" ) { return ; }
_onCancel . push ( h ) ;
} ;
var cancel = h ( 'button.btn.btn-default' , Messages . cancel ) ;
$ ( cancel ) . click ( function ( ) {
UI . confirm ( Messages . settings _exportCancel , function ( yes ) {
if ( ! yes ) { return ; }
_onCancel . forEach ( function ( h ) { h ( ) ; } ) ;
} ) ;
} ) . appendTo ( actions ) ;
var error = h ( 'button.btn.btn-danger' , Messages . settings _exportError ) ;
var translateErrors = function ( err ) {
if ( err === 'EEMPTY' ) {
return Messages . settings _exportErrorEmpty ;
}
if ( [ 'E404' , 'EEXPIRED' , 'EDELETED' ] . indexOf ( err ) !== - 1 ) {
return Messages . settings _exportErrorMissing ;
}
return Messages . _getKey ( 'settings_exportErrorOther' , [ err ] ) ;
} ;
var addErrors = function ( errs ) {
if ( ! errs . length ) { return ; }
var onClick = function ( ) {
console . error ( 'clicked?' ) ;
$ ( errors ) . toggle ( ) ;
} ;
$ ( error ) . click ( onClick ) . appendTo ( actions ) ;
var list = h ( 'div.cp-export-errors-list' ) ;
$ ( list ) . appendTo ( errors ) ;
errs . forEach ( function ( err ) {
if ( ! err . data ) { return ; }
var href = err . data . href || err . data . roHref ;
$ ( h ( 'div' , [
h ( 'div.title' , err . data . filename || err . data . title ) ,
h ( 'div.link' , [
h ( 'a' , {
href : err . data . href || err . data . roHref ,
target : '_blank'
} , privateData . origin + href )
] ) ,
h ( 'div.reason' , translateErrors ( err . error ) )
] ) ) . appendTo ( list ) ;
} ) ;
} ;
var download = h ( 'button.btn.btn-primary' , Messages . download _mt _button ) ;
var completed = false ;
var complete = function ( h , err ) {
if ( completed ) { return ; }
completed = true ;
$ ( progress ) . find ( '.fa-square-o' ) . removeClass ( 'fa-square-o' )
. addClass ( 'fa-check-square-o' ) ;
$ ( cancel ) . text ( Messages . filePicker _close ) . off ( 'click' ) . click ( function ( ) {
_onCancel . forEach ( function ( h ) { h ( ) ; } ) ;
} ) ;
$ ( download ) . click ( h ) . appendTo ( actions ) ;
addErrors ( err ) ;
} ;
var done = { } ;
var update = function ( step , state ) {
console . log ( step , state ) ;
console . log ( done [ step ] ) ;
if ( done [ step ] && done [ step ] === - 1 ) { return ; }
// New step
if ( ! done [ step ] ) {
$ ( progress ) . find ( '.fa-square-o' ) . removeClass ( 'fa-square-o' )
. addClass ( 'fa-check-square-o' ) ;
$ ( progress ) . append ( h ( 'p' , [
h ( 'span.fa.fa-square-o' ) ,
h ( 'span.text' , Messages [ 'settings_export_' + step ] || step )
] ) ) ;
done [ step ] = state ; // -1 if no bar, object otherwise
if ( state !== - 1 ) {
var bar = h ( 'div.cp-export-progress-bar' ) ;
$ ( progress ) . append ( h ( 'div.cp-export-progress-bar-container' , [
bar
] ) ) ;
done [ step ] = { bar : bar } ;
}
return ;
}
// Updating existing step
if ( typeof state !== "object" ) { return ; }
var b = done [ step ] . bar ;
var w = ( state . current / state . max ) * 100 ;
$ ( b ) . css ( 'width' , w + '%' ) ;
if ( ! done [ step ] . text ) {
done [ step ] . text = h ( 'div.cp-export-progress-text' ) ;
$ ( done [ step ] . text ) . appendTo ( b ) ;
}
$ ( done [ step ] . text ) . text ( state . current + ' / ' + state . max ) ;
if ( state . current === state . max ) { done [ step ] = - 1 ; }
} ;
return {
close : close ,
update : update ,
complete : complete ,
onCancel : onCancel
} ;
} ;
create [ 'drive-backup' ] = function ( ) {
var $div = $ ( '<div>' , { 'class' : 'cp-settings-drive-backup cp-sidebarlayout-element' } ) ;
@ -911,18 +1009,28 @@ define([
if ( err ) { return void cb ( err ) ; }
if ( obj . error ) { return void cb ( obj . error ) ; }
cb ( null , obj . data ) ;
} );
} , { timeout : 5 * 60 * 1000 } );
} ;
Backup . create ( data , getPad , function ( blob ) {
var ui = createExportUI ( ) ;
var bu = Backup . create ( data , getPad , function ( blob , errors ) {
console . log ( blob ) ;
saveAs ( blob , filename ) ;
sframeChan . event ( 'EV_CRYPTGET_DISCONNECT' ) ;
ui . complete ( function ( ) {
saveAs ( blob , filename ) ;
} , errors ) ;
} , ui . update ) ;
ui . onCancel ( function ( ) {
ui . close ( ) ;
bu . stop ( ) ;
} ) ;
} ;
sframeChan . query ( "Q_SETTINGS_DRIVE_GET" , "full" , function ( err , data ) {
if ( err ) { return void console . error ( err ) ; }
if ( data . error ) { return void console . error ( data . error ) ; }
UI . prompt ( 'TODO are you sure? if yes, pick a name...' , // XXX
UI . prompt ( Messages . settings _backup2Confirm ,
Util . fixFileName ( suggestion ) + '.zip' , function ( filename ) {
if ( ! ( typeof ( filename ) === 'string' && filename ) ) { return ; }
todo ( data , filename ) ;
@ -931,9 +1039,9 @@ define([
} ;
$ ( '<span>' , { 'class' : 'cp-sidebarlayout-description' } )
. text ( Messages . settings _backupHint2 ) . appendTo ( $div ) ;
var $export = common . createButton ( 'export' , true , { } , exportDrive ) ;
$export . attr ( 'class' , 'btn btn-success' ) . text ( Messages . settings _backup2 ) ;
$div . append ( $export ) ;
var $export 2 = common . createButton ( 'export' , true , { } , exportDrive ) ;
$export 2 . attr ( 'class' , 'btn btn-success' ) . text ( Messages . settings _backup2 ) ;
$div . append ( $export 2 ) ;
return $div ;
} ;