2018-05-09 10:18:28 +00:00
/ * *
* Privacy settings section
*
* @ author Pierre HUBERT
* /
2021-02-16 17:00:26 +00:00
const SettingsPrivacySection = {
2018-05-09 10:18:28 +00:00
/ * *
* Open settings section
*
* @ param { object } args Additionnal arguments
* @ param { HTMLElement } target The target for the page
* /
2021-02-16 17:00:26 +00:00
open : async function ( args , target ) {
2018-05-09 12:57:46 +00:00
2021-02-16 17:00:26 +00:00
try {
2018-05-22 20:23:16 +00:00
2021-02-16 17:00:26 +00:00
// Information box
this . showInfoBox ( target ) ;
2018-05-13 14:52:19 +00:00
2021-02-16 17:00:26 +00:00
// Data conservation policy
await this . showDataConservationPolicy ( target ) ;
//Export data box
this . showExportDataBox ( target ) ;
//Delete account box
this . showDeleteAccountBox ( target ) ;
}
catch ( e ) {
console . error ( e ) ;
target . appendChild ( ComunicWeb . common . messages . createCalloutElem ( "Failed to load page" , "The page failed to load !" , "danger" ) ) ;
}
2018-05-09 12:57:46 +00:00
} ,
2018-05-13 14:52:19 +00:00
2018-05-22 20:23:16 +00:00
/ * *
* Show privacy policy information box
*
* @ param { HTMLElement } target The target for the box
* /
showInfoBox : function ( target ) {
//Create a box
var box = createElem2 ( {
appendTo : target ,
type : "div" ,
class : "box box-primary box-export-account-data-settings"
} ) ;
//Add box header
var boxHead = createElem2 ( {
appendTo : box ,
type : "div" ,
class : "box-header" ,
} ) ;
var boxTitle = createElem2 ( {
appendTo : boxHead ,
type : "h3" ,
class : "box-title" ,
2021-02-16 17:00:26 +00:00
innerHTML : tr ( "About our policy" )
2018-05-22 20:23:16 +00:00
} ) ;
//Create box body
var boxBody = createElem2 ( {
appendTo : box ,
type : "div" ,
class : "box-body"
} ) ;
//Box content
createElem2 ( {
appendTo : boxBody ,
type : "p" ,
2021-02-20 10:25:53 +00:00
innerHTML : tr (
"We give an high importance to our users privacy. Please take some time to check our <a href='%privacy_policy_url%' target='_blank'>Privacy Policy</a> and our <a href='%terms_url%' target='_blank'>Terms of use</a>." ,
{
"privacy_policy_url" : ServerConfig . conf . privacy _policy _url ,
"terms_url" : ServerConfig . conf . terms _url ,
}
)
2018-05-22 20:23:16 +00:00
} )
} ,
2021-02-16 17:00:26 +00:00
/ * *
* Show data conservation policy
*
* @ param { HTMLElement } target
* /
showDataConservationPolicy : async function ( target ) {
// Load template
const tpl = await Page . loadHTMLTemplate ( "pages/settings/privacy/ConservationPolicy.html" ) ;
const el = document . createElement ( "div" )
el . innerHTML = tpl ;
target . appendChild ( el )
// Load user settings
const settings = await SettingsInterface . getDataConservationPolicy ( ) ;
// Load server policy
2021-02-16 17:23:59 +00:00
const serverPolicy = ServerConfig . conf . data _conservation _policy ;
2021-02-16 17:00:26 +00:00
// Use Vue
const oneDay = 60 * 60 * 24 ;
const lifetimeOptions = [
{ label : tr ( "Never" ) , value : 0 } ,
{ label : tr ( "7 days" ) , value : oneDay * 7 } ,
{ label : tr ( "15 days" ) , value : oneDay * 15 } ,
{ label : tr ( "1 month" ) , value : oneDay * 30 } ,
{ label : tr ( "3 months" ) , value : oneDay * 30 * 3 } ,
{ label : tr ( "6 months" ) , value : oneDay * 30 * 6 } ,
{ label : tr ( "1 year" ) , value : oneDay * 365 } ,
{ label : tr ( "5 years" ) , value : oneDay * 365 * 5 } ,
{ label : tr ( "10 years" ) , value : oneDay * 365 * 10 } ,
{ label : tr ( "50 years" ) , value : oneDay * 365 * 50 }
] ;
let findOptionIndex = ( value ) => {
if ( ! value ) return lifetimeOptions [ 0 ] . value ;
2021-02-16 17:23:59 +00:00
return lifetimeOptions . find ( v => v . value >= value ) . value
2021-02-16 17:00:26 +00:00
}
const DataConservationPolicyVueApp = {
data ( ) {
return {
options : lifetimeOptions ,
settings : [
{
2021-02-16 18:37:01 +00:00
title : tr ( "Automatically delete unread notifications after" ) ,
2021-02-16 17:00:26 +00:00
key : "notification_lifetime" ,
value : findOptionIndex ( settings . notification _lifetime ) ,
2021-02-16 17:23:59 +00:00
minVal : serverPolicy . min _notification _lifetime ,
2021-02-16 17:00:26 +00:00
} ,
{
title : tr ( "Automatically delete your comments after" ) ,
key : "comments_lifetime" ,
2021-02-16 17:23:59 +00:00
value : findOptionIndex ( settings . comments _lifetime ) ,
minVal : serverPolicy . min _comments _lifetime ,
2021-02-16 17:00:26 +00:00
} ,
{
title : tr ( "Automatically delete your posts after" ) ,
key : "posts_lifetime" ,
2021-02-16 17:23:59 +00:00
value : findOptionIndex ( settings . posts _lifetime ) ,
minVal : serverPolicy . min _posts _lifetime ,
2021-02-16 17:00:26 +00:00
} ,
{
title : tr ( "Automatically delete your conversation messages after" ) ,
key : "conversation_messages_lifetime" ,
2021-02-16 17:23:59 +00:00
value : findOptionIndex ( settings . conversation _messages _lifetime ) ,
minVal : serverPolicy . min _conversation _messages _lifetime ,
2021-02-16 17:00:26 +00:00
} ,
{
title : tr ( "Automatically delete your likes after" ) ,
key : "likes_lifetime" ,
2021-02-16 17:23:59 +00:00
value : findOptionIndex ( settings . likes _lifetime ) ,
minVal : serverPolicy . min _likes _lifetime ,
2021-02-16 17:00:26 +00:00
} ,
{
title : tr ( "Automatically delete your account if you have been inactive for" ) ,
key : "inactive_account_lifetime" ,
2021-02-16 17:23:59 +00:00
value : findOptionIndex ( settings . inactive _account _lifetime ) ,
minVal : serverPolicy . min _inactive _account _lifetime ,
2021-02-16 17:00:26 +00:00
}
2021-02-16 17:23:59 +00:00
] ,
password : "" ,
updating : false ,
}
} ,
methods : {
async submitUpdate ( ) {
try {
if ( this . password . length < 3 )
return notify ( tr ( "Please specify your password !" ) , "danger" )
let newSettings = { }
for ( let el of this . settings )
newSettings [ el . key ] = el . value ;
this . updating = true ;
await SettingsInterface . setDataConservationPolicy ( newSettings , this . password )
}
catch ( e ) {
console . error ( e )
notify ( tr ( "Failed to update data conservation policy!" ) , "danger" ) ;
}
this . updating = false
2021-02-16 17:00:26 +00:00
}
}
2021-02-16 17:23:59 +00:00
} ;
2021-02-16 17:00:26 +00:00
Vue . createApp ( DataConservationPolicyVueApp ) . mount ( el ) ;
} ,
2018-05-13 14:52:19 +00:00
/ * *
* Show export personnal data box
*
* @ param { HTMLElement } target The target for the box
* /
showExportDataBox : function ( target ) {
//Create a box
var box = createElem2 ( {
appendTo : target ,
type : "div" ,
class : "box box-primary box-export-account-data-settings"
} ) ;
//Add box header
var boxHead = createElem2 ( {
appendTo : box ,
type : "div" ,
class : "box-header" ,
} ) ;
var boxTitle = createElem2 ( {
appendTo : boxHead ,
type : "h3" ,
class : "box-title" ,
2021-02-16 17:00:26 +00:00
innerHTML : tr ( "Export account data" )
2018-05-13 14:52:19 +00:00
} ) ;
//Create box body
var boxBody = createElem2 ( {
appendTo : box ,
type : "div" ,
class : "box-body"
} ) ;
//Add a notice
createElem2 ( {
appendTo : boxBody ,
type : "p" ,
2021-02-16 17:00:26 +00:00
innerHTML : tr ( "You can export all the data of your account from here." )
2018-05-13 14:52:19 +00:00
} ) ;
//Add delete account button
var exportAccountDataBtn = createElem2 ( {
appendTo : boxBody ,
type : "div" ,
class : "btn btn-primary" ,
2021-02-16 17:00:26 +00:00
innerHTML : tr ( "Export account data" )
2018-05-13 14:52:19 +00:00
} ) ;
2021-02-16 17:00:26 +00:00
exportAccountDataBtn . addEventListener ( "click" , ( e ) => {
2018-05-13 14:52:19 +00:00
//Request account deletion
ComunicWeb . components . settings . helper . requestAccountDataExport ( ) ;
} ) ;
} ,
2018-05-09 10:18:28 +00:00
2018-05-09 12:57:46 +00:00
/ * *
* Display delete account box
*
* @ param { HTMLElement } target The target for the box
* /
showDeleteAccountBox : function ( target ) {
2018-05-09 10:18:28 +00:00
//Create a box
var box = createElem2 ( {
appendTo : target ,
type : "div" ,
2018-05-09 12:57:46 +00:00
class : "box box-danger box-delete-account-settings"
2018-05-09 10:18:28 +00:00
} ) ;
//Add box header
var boxHead = createElem2 ( {
appendTo : box ,
type : "div" ,
class : "box-header" ,
} ) ;
var boxTitle = createElem2 ( {
appendTo : boxHead ,
type : "h3" ,
class : "box-title" ,
2018-05-09 12:57:46 +00:00
innerHTML : "Delete account"
2018-05-09 10:18:28 +00:00
} ) ;
//Create box body
var boxBody = createElem2 ( {
appendTo : box ,
type : "div" ,
class : "box-body"
} ) ;
2018-05-09 12:57:46 +00:00
//Add a notice
createElem2 ( {
2018-05-09 10:18:28 +00:00
appendTo : boxBody ,
2018-05-09 12:57:46 +00:00
type : "p" ,
2021-02-16 17:00:26 +00:00
innerHTML : tr ( "You can decide here to delete your account. <br /><b>Warning! Warning! Warning! This operation CAN NOT BE REVERTED !!!! All your data (post, conversation messages, comments...) will be permanently deleted ! You will not be able to recover from this operation !</b>" )
2018-05-09 12:57:46 +00:00
} ) ;
//Add delete account button
var deleteAccountBtn = createElem2 ( {
appendTo : boxBody ,
type : "div" ,
class : "btn btn-danger" ,
2021-02-16 17:00:26 +00:00
innerHTML : tr ( "Delete your account" )
2018-05-09 12:57:46 +00:00
} ) ;
deleteAccountBtn . addEventListener ( "click" , function ( e ) {
//Request account deletion
ComunicWeb . components . settings . helper . requestAccountDeletion ( ) ;
2018-05-09 10:18:28 +00:00
} ) ;
} ,
2021-02-16 17:00:26 +00:00
}
ComunicWeb . pages . settings . sections . privacy = SettingsPrivacySection ;