2018-04-13 17:00:49 +00:00
/ * *
* Settings general section
*
* @ author Pierre HUBERT
* /
ComunicWeb . pages . settings . sections . general = {
/ * *
* Open settings section
*
* @ param { object } args Additionnal arguments
* @ param { HTMLElement } target The target for the page
* /
open : function ( args , target ) {
2018-04-15 13:02:32 +00:00
//Create a box
var box = createElem2 ( {
appendTo : target ,
type : "div" ,
2018-04-16 16:44:13 +00:00
class : "box box-primary box-general-settings"
} ) ;
//Add box header
var boxHead = createElem2 ( {
appendTo : box ,
type : "div" ,
class : "box-header" ,
} ) ;
var boxTitle = createElem2 ( {
appendTo : boxHead ,
type : "h3" ,
class : "box-title" ,
innerHTML : "General settings"
2018-04-15 13:02:32 +00:00
} ) ;
//Create box body
var boxBody = createElem2 ( {
appendTo : box ,
type : "div" ,
class : "box-body"
} ) ;
//Display loading message
2018-04-29 13:13:51 +00:00
var loadingMsg = ComunicWeb . common . messages . createLoadingCallout ( ) ;
2018-04-15 13:02:32 +00:00
boxBody . appendChild ( loadingMsg ) ;
2018-04-16 14:15:48 +00:00
//Load general settings information
ComunicWeb . components . settings . interface . getGeneral ( function ( infos ) {
//Remove loading message
loadingMsg . remove ( ) ;
//Check for errors
if ( infos . error ) {
var errMsg = ComunicWeb . common . messages . createCalloutElem ( "Error" , "An error occured while retrieving account settings..." , "danger" ) ;
boxBody . appendChild ( errMsg ) ;
2018-04-19 08:12:42 +00:00
return ;
2018-04-16 14:15:48 +00:00
}
2018-04-16 16:44:13 +00:00
//Display the settings form
ComunicWeb . pages . settings . sections . general . _show _form ( infos , boxBody ) ;
2018-04-16 14:15:48 +00:00
} ) ;
2018-04-16 16:44:13 +00:00
} ,
/ * *
* Show the settings form
*
* @ param { object } infos Informations about the user ( General settings )
* @ param { HTMLElement } target The target for the page
* /
_show _form : function ( infos , target ) {
2018-04-17 09:32:54 +00:00
//Main account information
createElem2 ( {
appendTo : target ,
type : "h4" ,
innerHTML : "Main account information"
} ) ;
2018-04-16 16:44:13 +00:00
//Display user ID
2019-01-11 15:34:43 +00:00
var userIDInput = createFormGroup ( {
2018-04-16 16:44:13 +00:00
target : target ,
label : "User ID" ,
type : "text" ,
value : infos . id ,
disabled : true ,
additionalGroupClasses : "input-user-id"
} ) ;
2019-01-11 15:34:43 +00:00
//Easter egg : open pacman when clicking 10 times on user ID input label
var clicks = 0 ;
userIDInput . parentNode . parentNode . addEventListener ( "click" , function ( ) {
clicks ++ ;
if ( clicks >= 10 ) {
ComunicWeb . components . pacman . open ( ) ;
clicks = 0 ;
}
} ) ;
2018-04-17 09:32:54 +00:00
//Display user email
2018-04-16 16:44:13 +00:00
createFormGroup ( {
target : target ,
label : "Email address" ,
type : "email" ,
value : infos . email ,
disabled : true ,
additionalGroupClasses : "input-user-email"
} ) ;
2021-04-16 05:54:03 +00:00
// Display user first name
2018-04-17 09:32:54 +00:00
var firstName = createFormGroup ( {
target : target ,
2021-04-16 05:54:03 +00:00
label : tr ( "First name" ) ,
placeholder : tr ( "Your first name" ) ,
2018-04-17 09:32:54 +00:00
type : "text" ,
value : infos . firstName ,
2021-04-16 05:54:03 +00:00
maxLength : ServerConfig . conf . account _info _policy . max _first _name _length
2018-04-17 09:32:54 +00:00
} ) ;
2021-04-16 05:54:03 +00:00
// Last name
2018-04-17 09:32:54 +00:00
var lastName = createFormGroup ( {
target : target ,
2021-04-16 05:54:03 +00:00
label : tr ( "Last name" ) ,
placeholder : tr ( "Your last name" ) ,
2018-04-17 09:32:54 +00:00
type : "text" ,
2021-04-16 05:54:03 +00:00
value : infos . lastName ,
maxLength : ServerConfig . conf . account _info _policy . max _last _name _length
2018-04-17 09:32:54 +00:00
} ) ;
2018-04-18 09:54:06 +00:00
//Allow mails from Comunic
var allowEmails = createFormGroup ( {
target : target ,
type : "checkbox" ,
2021-04-16 05:54:03 +00:00
label : tr ( "Allow Comunic to send you emails" ) ,
2018-04-18 09:54:06 +00:00
checked : infos . allow _comunic _mails
} ) ;
2018-04-17 09:32:54 +00:00
//Page settings
add _space ( target ) ;
createElem2 ( {
appendTo : target ,
type : "h4" ,
innerHTML : "Page settings"
} ) ;
//Public page
var publicPage = createFormGroup ( {
target : target ,
type : "checkbox" ,
2021-04-16 05:54:03 +00:00
label : tr ( "Make your page public (available to every Comunic users)" ) ,
2018-04-17 09:32:54 +00:00
checked : infos . is _public
} ) ;
//Open page
var openPage = createFormGroup ( {
target : target ,
type : "checkbox" ,
label : "Make your page open (available for the entire world)" ,
checked : infos . is _open
} ) ;
//Make the public and open button begin synchronized
$ ( publicPage ) . on ( "ifChanged" , function ( ) {
if ( ! publicPage . checked ) {
$ ( openPage ) . iCheck ( "uncheck" ) ;
}
} ) ;
$ ( openPage ) . on ( "ifChanged" , function ( ) {
if ( openPage . checked ) {
$ ( publicPage ) . iCheck ( "check" ) ;
}
} ) ;
//Allow comments creation
var allowComments = createFormGroup ( {
target : target ,
type : "checkbox" ,
2021-04-16 05:54:03 +00:00
label : tr ( "Allow comments on your page" ) ,
2018-04-17 09:32:54 +00:00
checked : infos . allow _comments
} ) ;
//Allow posts from friends
var allowPostsFromFriends = createFormGroup ( {
target : target ,
type : "checkbox" ,
2021-04-16 05:54:03 +00:00
label : tr ( "Allow the creation of posts from your friends on your page" ) ,
2018-04-17 09:32:54 +00:00
checked : infos . allow _posts _from _friends
} ) ;
//Public friends list
2018-04-17 17:47:18 +00:00
var publicFriendsList = createFormGroup ( {
2018-04-17 09:32:54 +00:00
target : target ,
type : "checkbox" ,
2021-04-16 05:54:03 +00:00
label : tr ( "Make your friend list public" ) ,
2018-04-18 14:32:30 +00:00
checked : infos . public _friends _list
2018-04-17 09:32:54 +00:00
} ) ;
2021-04-16 13:20:44 +00:00
//Public email address
var publicEmailAddress = createFormGroup ( {
target : target ,
type : "checkbox" ,
label : tr ( "Make your email address public" ) ,
checked : infos . public _email
} ) ;
2018-04-17 09:32:54 +00:00
//Personnal website
2018-04-17 12:05:27 +00:00
var personnalWebsite = createFormGroup ( {
2018-04-17 09:32:54 +00:00
target : target ,
2021-04-16 13:20:44 +00:00
label : tr ( "Personnal website (optional)" ) ,
2018-04-17 09:32:54 +00:00
type : "text" ,
placeholder : "https://..." ,
value : infos . personnal _website != "null" ? infos . personnal _website : ""
} ) ;
2021-04-16 13:20:44 +00:00
//Location
var location = createFormGroup ( {
target : target ,
label : tr ( "Location (optional)" ) ,
type : "text" ,
placeholder : "Feurs" ,
value : infos . location != null ? infos . location : "" ,
maxLength : ServerConfig . conf . account _info _policy . max _location _length ,
} ) ;
2018-05-05 09:14:13 +00:00
//Public notes
var publicNotes = createFormGroup ( {
target : target ,
label : "Public notes for your account 255 characters max (optionnal)" ,
type : "textarea" ,
placeholder : "Notes about your account..." ,
value : infos . publicNote != "null" ? infos . publicNote : ""
} ) ;
2018-04-17 09:32:54 +00:00
//Virtual directory
2018-04-17 12:05:27 +00:00
var virtualDirectory = createFormGroup ( {
2018-04-17 09:32:54 +00:00
target : target ,
2018-05-03 19:58:36 +00:00
label : "Virtual directory for your user page (" + ComunicWeb . _ _config . siteURL + "user/{virtual_directory})<br />Account tag (in the form @{virtual_directory})" ,
2018-04-17 09:32:54 +00:00
type : "text" ,
placeholder : "Eg. john.way" ,
value : infos . virtual _directory != "null" ? infos . virtual _directory : ""
} ) ;
2018-04-17 12:05:27 +00:00
//Auto-check the virtual directory when it is updated
var checkTarget = createElem2 ( {
appendTo : target ,
type : "small"
} ) ;
virtualDirectory . onkeyup = function ( ) {
checkTarget . innerHTML = "Checking availability..." ;
//Get the directory to check
var directory = virtualDirectory . value ;
//Check if the directory is empty
if ( directory == "" ) {
checkTarget . innerHTML = "" ;
return ;
}
//Perform a request on the API
ComunicWeb . components . settings . interface . checkUserDirectoryAvailability ( directory , function ( callback ) {
//Check if the directory is available or not
checkTarget . innerHTML = callback . error ? "<invalidDirectory>This directory is not available!</invalidDirectory>" : "This directory seems to be available!" ;
} )
}
2018-04-17 09:32:54 +00:00
//Submit button
var sendButton = createElem2 ( {
appendTo : target ,
type : "div" ,
class : "btn btn-primary submit-form" ,
innerHTML : "Update"
} ) ;
//Make the submit button lives
sendButton . onclick = function ( ) {
2018-04-17 12:05:27 +00:00
//Check the given values
2021-04-16 05:54:03 +00:00
if ( ! ComunicWeb . common . formChecker . checkInput ( firstName , true , ServerConfig . conf . account _info _policy . min _first _name _length ) )
return notify ( tr ( "Please check your first name!" ) , "danger" ) ;
2018-04-17 17:47:18 +00:00
2021-04-16 05:54:03 +00:00
if ( ! ComunicWeb . common . formChecker . checkInput ( lastName , true , ServerConfig . conf . account _info _policy . min _last _name _length ) )
return notify ( tr ( "Please check your last name!" ) , "danger" ) ;
2018-04-17 17:47:18 +00:00
if ( personnalWebsite . value != "" ) {
if ( ! check _url ( personnalWebsite . value ) )
2021-04-16 05:54:03 +00:00
return notify ( tr ( "Please check the given URL !" ) , "danger" ) ;
2018-04-17 17:47:18 +00:00
}
2018-04-17 09:32:54 +00:00
2018-04-17 17:47:18 +00:00
//Pack all the values in an object
var settings = {
firstName : firstName . value ,
lastName : lastName . value ,
2018-04-18 09:54:06 +00:00
allow _comunic _mails : allowEmails . checked ,
2018-04-17 17:47:18 +00:00
isPublic : publicPage . checked ,
isOpen : openPage . checked ,
allowComments : allowComments . checked ,
allowPostsFromFriends : allowPostsFromFriends . checked ,
publicFriendsList : publicFriendsList . checked ,
2021-04-16 13:20:44 +00:00
email _public : publicEmailAddress . checked ,
2018-04-17 17:47:18 +00:00
personnalWebsite : personnalWebsite . value ,
2018-05-05 09:14:13 +00:00
virtualDirectory : virtualDirectory . value ,
publicNote : publicNotes . value ,
2021-04-16 13:20:44 +00:00
location : location . value ,
2018-04-17 17:47:18 +00:00
} ;
//Lock send button
sendButton . style . visibility = "hidden" ;
//Perform the request over the API
2021-04-16 13:20:44 +00:00
SettingsInterface . setGeneral ( settings , function ( result ) {
2018-04-17 17:47:18 +00:00
//Unlock send button
sendButton . style . visibility = "visible" ;
//Check for errors
if ( result . error ) {
notify ( "An error occured while updating user settings!" , "danger" ) ;
return ;
}
//Success
notify ( "Your settings have been successfully saved !" , "success" ) ;
//Reset the system
ComunicWeb . common . system . reset ( ) ;
} ) ;
2018-04-17 09:32:54 +00:00
} ;
2018-04-16 16:44:13 +00:00
} ,
2018-04-13 17:00:49 +00:00
} ;