@ -3,14 +3,16 @@ define([
'/common/cryptpad-common.js' ,
'/common/cryptpad-common.js' ,
'/common/cryptget.js' ,
'/common/cryptget.js' ,
'/common/mergeDrive.js' ,
'/common/mergeDrive.js' ,
'/common/toolbar2.js' ,
'/bower_components/file-saver/FileSaver.min.js' ,
'/bower_components/file-saver/FileSaver.min.js' ,
'/customize/header.js' ,
// '/customize/header.js',
'less!/customize/src/less/cryptpad.less' ,
'less!/customize/src/less/cryptpad.less' ,
'css!/bower_components/components-font-awesome/css/font-awesome.min.css' ,
'css!/bower_components/components-font-awesome/css/font-awesome.min.css' ,
'css!/bower_components/bootstrap/dist/css/bootstrap.min.css' ,
'css!/bower_components/bootstrap/dist/css/bootstrap.min.css' ,
'less!/customize/src/less/toolbar.less' ,
'less!/settings/main.less' ,
'less!/settings/main.less' ,
] , function ( $ , Cryptpad , Crypt , Merge ) {
] , function ( $ , Cryptpad , Crypt , Merge , Toolbar ) {
var saveAs = window . saveAs ;
var saveAs = window . saveAs ;
var USERNAME _KEY = 'cryptpad.username' ;
var USERNAME _KEY = 'cryptpad.username' ;
@ -34,6 +36,22 @@ define([
} ) ;
} ) ;
} ;
} ;
var categories = {
'account' : [
'infoBlock' ,
'displayName' ,
'languageSelector' ,
'logoutEverywhere' ,
'resetTips' ,
'userFeedback'
] ,
'drive' : [
'backupDrive' ,
'importLocalPads' ,
'resetDrive'
]
} ;
// Title block
// Title block
var createTitle = function ( ) {
var createTitle = function ( ) {
return $ ( '<h1>' ) . text ( Messages . settings _title ) ;
return $ ( '<h1>' ) . text ( Messages . settings _title ) ;
@ -43,27 +61,25 @@ define([
var obj = store . proxy ;
var obj = store . proxy ;
var $div = $ ( '<div>' , { 'class' : 'infoBlock' } ) ;
var $div = $ ( '<div>' , { 'class' : 'infoBlock' } ) ;
var $account = $ ( '<div>' , { 'class' : 'element' } ) . appendTo ( $div ) ;
var accountName = obj . login _name || localStorage [ Cryptpad . userNameKey ] ;
var accountName = obj . login _name || localStorage [ Cryptpad . userNameKey ] ;
var $label = $ ( '<span>' , { 'class' : 'label' } ) . text ( Messages . user _accountName + ':' ) ;
var $label = $ ( '<span>' , { 'class' : 'label' } ) . text ( Messages . user _accountName ) ;
var $name = $ ( '<span>' ) . text ( accountName || '' ) ;
var $name = $ ( '<span>' ) . text ( accountName || '' ) ;
if ( ! accountName ) {
if ( ! accountName ) {
$label . text ( '' ) ;
$label . text ( '' ) ;
$name . text ( Messages . settings _anonymous ) ;
$name . text ( Messages . settings _anonymous ) ;
}
}
$account . append ( $label ) . append ( $name ) ;
$div . append ( $label ) . append ( $name ) ;
var publicKey = obj . edPublic ;
var publicKey = obj . edPublic ;
if ( publicKey ) {
if ( publicKey ) {
var $key = $ ( '<div>' , { 'class' : 'element' } ) . appendTo ( $div ) ;
var userHref = Cryptpad . getUserHrefFromKeys ( accountName , publicKey ) ;
var userHref = Cryptpad . getUserHrefFromKeys ( accountName , publicKey ) ;
var $pubLabel = $ ( '<span>' , { 'class' : 'label' } )
var $pubLabel = $ ( '<span>' , { 'class' : 'label' } )
. text ( Messages . settings _publicSigningKey + ':' ) ;
. text ( Messages . settings _publicSigningKey ) ;
var $pubKey = $ ( '<input>' , { type : 'text' , readonly : true } )
var $pubKey = $ ( '<input>' , { type : 'text' , readonly : true } )
. css ( {
width : '28em'
} )
. val ( userHref ) ;
. val ( userHref ) ;
$ div. append ( '<br>' ) . append ( $pubLabel ) . append ( $pubKey ) ;
$key . append ( $pubLabel ) . append ( $pubKey ) ;
}
}
return $div ;
return $div ;
@ -72,14 +88,14 @@ define([
// Create the block containing the display name field
// Create the block containing the display name field
var createDisplayNameInput = function ( store ) {
var createDisplayNameInput = function ( store ) {
var obj = store . proxy ;
var obj = store . proxy ;
var $div = $ ( '<div>' , { 'class' : 'displayName '} ) ;
var $div = $ ( '<div>' , { 'class' : 'displayName element '} ) ;
$ ( '<label>' , { 'for' : 'displayName' } ) . text ( Messages . user _displayName ) . appendTo ( $div ) ;
$ ( '<label>' , { 'for' : 'displayName' } ) . text ( Messages . user _displayName ) . appendTo ( $div ) ;
$ ( '<br>' ) . appendTo ( $div ) ;
var $inputBlock = $ ( '<div>' , { 'class' : 'inputBlock' } ) . appendTo ( $div ) ;
var $input = $ ( '<input>' , {
var $input = $ ( '<input>' , {
'type' : 'text' ,
'type' : 'text' ,
'id' : 'displayName' ,
'id' : 'displayName' ,
'placeholder' : Messages . anonymous } ) . appendTo ( $ div ) ;
'placeholder' : Messages . anonymous } ) . appendTo ( $ inputBlock ) ;
var $save = $ ( '<button>' , { 'class' : 'btn btn-primary' } ) . text ( Messages . settings _save ) . appendTo ( $ div ) ;
var $save = $ ( '<button>' , { 'class' : 'btn btn-primary' } ) . text ( Messages . settings _save ) . appendTo ( $ inputBlock ) ;
var $ok = $ ( '<span>' , { 'class' : 'fa fa-check' , title : Messages . saved } ) . hide ( ) . appendTo ( $div ) ;
var $ok = $ ( '<span>' , { 'class' : 'fa fa-check' , title : Messages . saved } ) . hide ( ) . appendTo ( $div ) ;
var $spinner = $ ( '<span>' , { 'class' : 'fa fa-spinner fa-pulse' } ) . hide ( ) . appendTo ( $div ) ;
var $spinner = $ ( '<span>' , { 'class' : 'fa fa-spinner fa-pulse' } ) . hide ( ) . appendTo ( $div ) ;
@ -115,11 +131,12 @@ define([
return $div ;
return $div ;
} ;
} ;
var createResetTips = function ( ) {
var createResetTips = function ( ) {
var $div = $ ( '<div>' , { 'class' : 'resetTips '} ) ;
var $div = $ ( '<div>' , { 'class' : 'resetTips element '} ) ;
$ ( '<label>' , { 'for' : 'resetTips' } ) . text ( Messages . settings _resetTips ) . appendTo ( $div ) ;
$ ( '<label>' , { 'for' : 'resetTips' } ) . text ( Messages . settings _resetTips ) . appendTo ( $div ) ;
$ ( '<br>' ) . appendTo ( $div ) ;
$ ( '<span>' , { 'class' : 'description' } )
var $button = $ ( '<button>' , { 'id' : 'resetTips' , 'class' : 'btn btn-primary' } )
. text ( Messages . settings _resetTipsButton ) . appendTo ( $div ) ;
. text ( Messages . settings _resetTipsButton ) . appendTo ( $div ) ;
var $button = $ ( '<button>' , { 'id' : 'resetTips' , 'class' : 'btn btn-primary' } )
. text ( Messages . settings _resetTipsAction ) . appendTo ( $div ) ;
$button . click ( function ( ) {
$button . click ( function ( ) {
Object . keys ( localStorage ) . forEach ( function ( k ) {
Object . keys ( localStorage ) . forEach ( function ( k ) {
@ -134,7 +151,7 @@ define([
} ;
} ;
var createBackupDrive = function ( store ) {
var createBackupDrive = function ( store ) {
var obj = store . proxy ;
var obj = store . proxy ;
var $div = $ ( '<div>' , { 'class' : 'backupDrive '} ) ;
var $div = $ ( '<div>' , { 'class' : 'backupDrive element '} ) ;
var exportFile = function ( ) {
var exportFile = function ( ) {
var sjson = JSON . stringify ( obj ) ;
var sjson = JSON . stringify ( obj ) ;
@ -155,27 +172,29 @@ define([
} ) ;
} ) ;
} ;
} ;
$ ( '<label>' , { 'for' : 'exportDrive' } ) . text ( Messages . settings _backupTitle ) . appendTo ( $div ) ;
$ ( '<label>' , { 'for' : 'exportDrive' } ) . text ( Messages . settings _backupCategory ) . appendTo ( $div ) ;
$ ( '<br>' ) . appendTo ( $div ) ;
$ ( '<span>' , { 'class' : 'description' } )
. text ( Messages . settings _backupTitle ) . appendTo ( $div ) ;
/* add an export button */
/* add an export button */
var $export = Cryptpad . createButton ( 'export' , true , { } , exportFile ) ;
var $export = Cryptpad . createButton ( 'export' , true , { } , exportFile ) ;
$export . a ddClass( 'btn' ) . addClass ( 'btn-success' ) . append ( Messages . settings _backup ) ;
$export . a ttr( 'class' , 'btn btn-success' ) . text ( Messages . settings _backup ) ;
$div . append ( $export ) ;
$div . append ( $export ) ;
/* add an import button */
/* add an import button */
var $import = Cryptpad . createButton ( 'import' , true , { } , importFile ) ;
var $import = Cryptpad . createButton ( 'import' , true , { } , importFile ) ;
$import . a ddClass( 'btn' ) . addClass ( 'btn-warning' ) . append ( Messages . settings _restore ) ;
$import . a ttr( 'class' , 'btn btn-success' ) . text ( Messages . settings _restore ) ;
$div . append ( $import ) ;
$div . append ( $import ) ;
return $div ;
return $div ;
} ;
} ;
var createResetDrive = function ( obj ) {
var createResetDrive = function ( obj ) {
var $div = $ ( '<div>' , { 'class' : 'resetDrive' } ) ;
var $div = $ ( '<div>' , { 'class' : 'resetDrive element' } ) ;
$ ( '<label>' , { 'for' : 'resetDrive' } ) . text ( Messages . settings _resetTitle ) . appendTo ( $div ) ;
$ ( '<label>' , { 'for' : 'resetDrive' } ) . text ( Messages . settings _resetNewTitle ) . appendTo ( $div ) ;
$ ( '<br>' ) . appendTo ( $div ) ;
$ ( '<span>' , { 'class' : 'description' } )
var $button = $ ( '<button>' , { 'id' : 'resetDrive' , 'class' : 'btn btn-danger' } )
. text ( Messages . settings _reset ) . appendTo ( $div ) ;
. text ( Messages . settings _reset ) . appendTo ( $div ) ;
var $button = $ ( '<button>' , { 'id' : 'resetDrive' , 'class' : 'btn btn-danger' } )
. text ( Messages . settings _resetButton ) . appendTo ( $div ) ;
$button . click ( function ( ) {
$button . click ( function ( ) {
Cryptpad . prompt ( Messages . settings _resetPrompt , "" , function ( val ) {
Cryptpad . prompt ( Messages . settings _resetPrompt , "" , function ( val ) {
@ -192,14 +211,16 @@ define([
} ;
} ;
var createUserFeedbackToggle = function ( obj ) {
var createUserFeedbackToggle = function ( obj ) {
var $div = $ ( '<div>' , { 'class' : 'userFeedback' , } ) ;
var $div = $ ( '<div>' , { 'class' : 'userFeedback element' } ) ;
var $label = $ ( '<label>' , { 'for' : 'userFeedback' } )
. text ( Messages . settings _userFeedback ) ;
$div . html ( '<hr />' + Messages . settings _userFeedbackHint1 + '<br />' +
$ ( '<span>' , { 'class' : 'label' } ) . text ( Messages . settings _userFeedbackTitle ) . appendTo ( $div ) ;
Messages . settings _userFeedbackHint2 ) . appendTo ( $div ) ;
$ ( '<br>' ) . appendTo ( $div ) ;
var $label = $ ( '<label>' , { 'for' : 'userFeedback' , 'class' : 'noTitle' } )
. text ( Messages . settings _userFeedback ) ;
$ ( '<span>' , { 'class' : 'description' } )
. append ( Messages . settings _userFeedbackHint1 )
. append ( Messages . settings _userFeedbackHint2 ) . appendTo ( $div ) ;
var $ok = $ ( '<span>' , { 'class' : 'fa fa-check' , title : Messages . saved } ) ;
var $ok = $ ( '<span>' , { 'class' : 'fa fa-check' , title : Messages . saved } ) ;
var $spinner = $ ( '<span>' , { 'class' : 'fa fa-spinner fa-pulse' } ) ;
var $spinner = $ ( '<span>' , { 'class' : 'fa fa-spinner fa-pulse' } ) ;
@ -229,25 +250,21 @@ define([
} ;
} ;
var createUsageButton = function ( ) {
var createUsageButton = function ( ) {
var $div = $ ( '<div>' , { 'class' : 'pinned-usage' } )
. text ( Messages . settings _usageTitle )
. append ( '<br>' ) ;
Cryptpad . createUsageBar ( function ( err , $bar ) {
Cryptpad . createUsageBar ( function ( err , $bar ) {
$div . find ( '.limit-container' ) . remove ( ) ;
if ( err ) { return void console . error ( err ) ; }
$div . append ( $bar ) ;
APP . $usage . html ( '' ) . append ( $bar ) ;
} , true ) ;
} , true ) ;
return $div ;
} ;
} ;
var createLogoutEverywhere = function ( obj ) {
var createLogoutEverywhere = function ( obj ) {
var proxy = obj . proxy ;
var proxy = obj . proxy ;
var $div = $ ( '<div>' , { 'class' : 'logoutEverywhere ', } ) ;
var $div = $ ( '<div>' , { 'class' : 'logoutEverywhere element '} ) ;
$ ( '<label>' , { 'for' : 'logoutEverywhere' } )
$ ( '<label>' , { 'for' : 'logoutEverywhere' } )
. text ( Messages . settings _logoutEverywhereTitle ) . appendTo ( $div ) ;
. text ( Messages . settings _logoutEverywhereTitle ) . appendTo ( $div ) ;
$ ( '<br>' ) . appendTo ( $div ) ;
$ ( '<span>' , { 'class' : 'description' } )
. text ( Messages . settings _logoutEverywhere ) . appendTo ( $div ) ;
var $button = $ ( '<button>' , { id : 'logoutEverywhere' , 'class' : 'btn btn-primary' } )
var $button = $ ( '<button>' , { id : 'logoutEverywhere' , 'class' : 'btn btn-primary' } )
. text ( Messages . settings _logoutEverywhere )
. text ( Messages . settings _logoutEverywhere Button )
. appendTo ( $div ) ;
. appendTo ( $div ) ;
var $ok = $ ( '<span>' , { 'class' : 'fa fa-check' , title : Messages . saved } ) . hide ( ) . appendTo ( $div ) ;
var $ok = $ ( '<span>' , { 'class' : 'fa fa-check' , title : Messages . saved } ) . hide ( ) . appendTo ( $div ) ;
var $spinner = $ ( '<span>' , { 'class' : 'fa fa-spinner fa-pulse' } ) . hide ( ) . appendTo ( $div ) ;
var $spinner = $ ( '<span>' , { 'class' : 'fa fa-spinner fa-pulse' } ) . hide ( ) . appendTo ( $div ) ;
@ -279,9 +296,10 @@ define([
var createImportLocalPads = function ( obj ) {
var createImportLocalPads = function ( obj ) {
if ( ! Cryptpad . isLoggedIn ( ) ) { return ; }
if ( ! Cryptpad . isLoggedIn ( ) ) { return ; }
var $div = $ ( '<div>' , { 'class' : 'importLocalPads' } ) ;
var $div = $ ( '<div>' , { 'class' : 'importLocalPads element' } ) ;
$ ( '<label>' , { 'for' : 'importLocalPads' } ) . text ( Messages . settings _importTitle ) . appendTo ( $div ) ;
$ ( '<label>' , { 'for' : 'importLocalPads' } ) . text ( Messages . settings _import ) . appendTo ( $div ) ;
$ ( '<br>' ) . appendTo ( $div ) ;
$ ( '<span>' , { 'class' : 'description' } )
. text ( Messages . settings _importTitle ) . appendTo ( $div ) ;
var $button = $ ( '<button>' , { 'id' : 'importLocalPads' , 'class' : 'btn btn-primary' } )
var $button = $ ( '<button>' , { 'id' : 'importLocalPads' , 'class' : 'btn btn-primary' } )
. text ( Messages . settings _import ) . appendTo ( $div ) ;
. text ( Messages . settings _import ) . appendTo ( $div ) ;
var $ok = $ ( '<span>' , { 'class' : 'fa fa-check' , title : Messages . saved } ) . hide ( ) . appendTo ( $div ) ;
var $ok = $ ( '<span>' , { 'class' : 'fa fa-check' , title : Messages . saved } ) . hide ( ) . appendTo ( $div ) ;
@ -304,31 +322,89 @@ define([
} ;
} ;
var createLanguageSelector = function ( ) {
var createLanguageSelector = function ( ) {
var $div = $ ( '<div>' , { 'class' : ' importLocalPads '} ) ;
var $div = $ ( '<div>' , { 'class' : ' languageSelector element '} ) ;
$ ( '<label>' ) . text ( Messages . language ) . appendTo ( $div ) ;
$ ( '<label>' ) . text ( Messages . language ) . appendTo ( $div ) ;
$ ( '<br>' ) . appendTo ( $div ) ;
var $b = Cryptpad . createLanguageSelector ( ) . appendTo ( $div ) ;
var $b = Cryptpad . createLanguageSelector ( ) . appendTo ( $div ) ;
$b . find ( 'button' ) . addClass ( 'btn btn-secondary' ) ;
$b . find ( 'button' ) . addClass ( 'btn btn-secondary' ) ;
return $div ;
return $div ;
} ;
} ;
var hideCategories = function ( ) {
APP . $rightside . find ( '> div' ) . hide ( ) ;
} ;
var showCategories = function ( cat ) {
hideCategories ( ) ;
cat . forEach ( function ( c ) {
APP . $rightside . find ( '.' + c ) . show ( ) ;
} ) ;
} ;
var createLeftside = function ( ) {
var $categories = $ ( '<div>' , { 'class' : 'categories' } ) . appendTo ( APP . $leftside ) ;
APP . $usage = $ ( '<div>' , { 'class' : 'usage' } ) . appendTo ( APP . $leftside ) ;
var active = 'account' ;
Object . keys ( categories ) . forEach ( function ( key ) {
var $category = $ ( '<div>' , { 'class' : 'category' } ) . appendTo ( $categories ) ;
if ( key === 'account' ) { $category . append ( $ ( '<span>' , { 'class' : 'fa fa-user-o' } ) ) ; }
if ( key === 'drive' ) { $category . append ( $ ( '<span>' , { 'class' : 'fa fa-hdd-o' } ) ) ; }
if ( key === active ) {
$category . addClass ( 'active' ) ;
}
$category . click ( function ( ) {
active = key ;
$categories . find ( '.active' ) . removeClass ( 'active' ) ;
$category . addClass ( 'active' ) ;
showCategories ( categories [ key ] ) ;
} ) ;
$category . append ( Messages [ 'settings_cat_' + key ] ) ;
} ) ;
showCategories ( categories [ active ] ) ;
} ;
var createToolbar = function ( ) {
var displayed = [ 'useradmin' , 'newpad' , 'limit' , 'upgrade' ] ;
var configTb = {
displayed : displayed ,
ifrw : window ,
common : Cryptpad ,
hideDisplayName : true ,
$container : APP . $toolbar
} ;
var toolbar = APP . toolbar = Toolbar . create ( configTb ) ;
toolbar . $rightside . html ( '' ) ; // Remove the drawer if we don't use it to hide the toolbar
} ;
var andThen = function ( obj ) {
var andThen = function ( obj ) {
APP . $container . append ( createTitle ( ) ) ;
APP . $leftside = $ ( '<div>' , { id : 'leftSide' } ) . appendTo ( APP . $container ) ;
APP . $container . append ( createInfoBlock ( obj ) ) ;
var $rightside = APP . $rightside = $ ( '<div>' , { id : 'rightSide' } ) . appendTo ( APP . $container ) ;
APP . $container . append ( createDisplayNameInput ( obj ) ) ;
APP . $container . append ( createLanguageSelector ( ) ) ;
createToolbar ( ) ;
//$rightside.append(createTitle());
$rightside . append ( createInfoBlock ( obj ) ) ;
$rightside . append ( createDisplayNameInput ( obj ) ) ;
$rightside . append ( createLanguageSelector ( ) ) ;
if ( Cryptpad . isLoggedIn ( ) ) {
if ( Cryptpad . isLoggedIn ( ) ) {
APP . $container . append ( createLogoutEverywhere ( obj ) ) ;
$rightside . append ( createLogoutEverywhere ( obj ) ) ;
}
}
APP . $container . append ( createResetTips ( ) ) ;
$rightside . append ( createResetTips ( ) ) ;
APP . $container . append ( createUsageButton ( obj ) ) ;
$rightside. append ( createBackupDrive ( obj ) ) ;
APP . $container . append ( createBackupDrive ( obj ) ) ;
$rightside. append ( createImportLocalPads ( obj ) ) ;
APP . $container . append ( createImportLocalPads ( obj ) ) ;
$rightside. append ( createResetDrive ( obj ) ) ;
APP . $container . append ( createResetDrive ( obj ) ) ;
$rightside. append ( createUserFeedbackToggl e( obj ) ) ;
APP . $container . append ( createUserFeedbackToggle ( obj ) ) ;
obj . proxy . on ( 'change' , [ ] , refresh ) ;
obj . proxy . on ( 'change' , [ ] , refresh ) ;
obj . proxy . on ( 'remove' , [ ] , refresh ) ;
obj . proxy . on ( 'remove' , [ ] , refresh ) ;
createLeftside ( ) ;
createUsageButton ( ) ;
Cryptpad . removeLoadingScreen ( ) ;
} ;
} ;
$ ( function ( ) {
$ ( function ( ) {
@ -342,6 +418,7 @@ define([
$main . removeClass ( 'hidden' ) ;
$main . removeClass ( 'hidden' ) ;
APP . $container = $ ( '#container' ) ;
APP . $container = $ ( '#container' ) ;
APP . $toolbar = $ ( '#toolbar' ) ;
Cryptpad . ready ( function ( ) {
Cryptpad . ready ( function ( ) {
//if (!Cryptpad.getUserHash()) { return redirectToMain(); }
//if (!Cryptpad.getUserHash()) { return redirectToMain(); }