2014-01-22 10:12:51 +00:00
/ * *
* @ name Settings Module
* @ description Lets you change settings .
* @ author Tobias Reich
* @ copyright 2014 by Tobias Reich
* /
var settings = {
createConfig : function ( ) {
var dbName ,
dbUser ,
dbPassword ,
dbHost ,
2014-08-29 17:55:21 +00:00
dbTablePrefix ,
2014-04-15 12:17:32 +00:00
buttons ,
params ;
2014-01-22 10:12:51 +00:00
buttons = [
[ "Connect" , function ( ) {
2014-08-29 17:55:21 +00:00
dbHost = $ ( ".message input.text#dbHost" ) . val ( ) ;
dbUser = $ ( ".message input.text#dbUser" ) . val ( ) ;
dbPassword = $ ( ".message input.text#dbPassword" ) . val ( ) ;
dbName = $ ( ".message input.text#dbName" ) . val ( ) ;
dbTablePrefix = $ ( ".message input.text#dbTablePrefix" ) . val ( ) ;
2014-01-22 10:12:51 +00:00
if ( dbHost . length < 1 ) dbHost = "localhost" ;
if ( dbName . length < 1 ) dbName = "lychee" ;
2014-08-29 17:55:21 +00:00
params = "dbCreateConfig&dbName=" + escape ( dbName ) + "&dbUser=" + escape ( dbUser ) + "&dbPassword=" + escape ( dbPassword ) + "&dbHost=" + escape ( dbHost ) + "&dbTablePrefix=" + escape ( dbTablePrefix ) ;
2014-01-22 10:12:51 +00:00
lychee . api ( params , function ( data ) {
if ( data !== true ) {
// Configuration failed
setTimeout ( function ( ) {
// Connection failed
if ( data . indexOf ( "Warning: Connection failed!" ) !== - 1 ) {
buttons = [
[ "Retry" , function ( ) { setTimeout ( settings . createConfig , 400 ) } ] ,
[ "" , function ( ) { } ]
] ;
modal . show ( "Connection Failed" , "Unable to connect to host database because access was denied. Double-check your host, username and password and ensure that access from your current location is permitted." , buttons , null , false ) ;
return false ;
}
2014-08-07 18:23:39 +00:00
// Creation failed
if ( data . indexOf ( "Warning: Creation failed!" ) !== - 1 ) {
buttons = [
[ "Retry" , function ( ) { setTimeout ( settings . createConfig , 400 ) } ] ,
[ "" , function ( ) { } ]
] ;
modal . show ( "Creation Failed" , "Unable to create the database. Double-check your host, username and password and ensure that the specified user has the rights to modify and add content to the database." , buttons , null , false ) ;
return false ;
}
2014-01-22 10:12:51 +00:00
// Could not create file
if ( data . indexOf ( "Warning: Could not create file!" ) !== - 1 ) {
buttons = [
[ "Retry" , function ( ) { setTimeout ( settings . createConfig , 400 ) } ] ,
[ "" , function ( ) { } ]
] ;
2014-02-09 21:39:12 +00:00
modal . show ( "Saving Failed" , "Unable to save this configuration. Permission denied in <b>'data/'</b>. Please set the read, write and execute rights for others in <b>'data/'</b> and <b>'uploads/'</b>. Take a look the readme for more information." , buttons , null , false ) ;
2014-01-22 10:12:51 +00:00
return false ;
}
// Something went wrong
buttons = [
[ "Retry" , function ( ) { setTimeout ( settings . createConfig , 400 ) } ] ,
[ "" , function ( ) { } ]
] ;
modal . show ( "Configuration Failed" , "Something unexpected happened. Please try again and check your installation and server. Take a look the readme for more information." , buttons , null , false ) ;
return false ;
} , 400 ) ;
} else {
// Configuration successful
2014-02-23 18:41:12 +00:00
window . location . reload ( ) ;
2014-01-22 10:12:51 +00:00
}
} ) ;
} ] ,
[ "" , function ( ) { } ]
] ;
2014-02-23 21:42:15 +00:00
2014-08-29 17:55:21 +00:00
modal . show ( "Configuration" , "Enter your database connection details below: <input id='dbHost' class='text less' type='text' placeholder='Database Host (optional)' value=''><input id='dbUser' class='text less' type='text' placeholder='Database Username' value=''><input id='dbPassword' class='text more' type='password' placeholder='Database Password' value=''><br>Lychee will create its own database. If required, you can enter the name of an existing database instead:<input id='dbName' class='text less' type='text' placeholder='Database Name (optional)' value=''><input id='dbTablePrefix' class='text more' type='text' placeholder='Table prefix (optional)' value=''>" , buttons , - 235 , false ) ;
2014-01-22 10:12:51 +00:00
} ,
createLogin : function ( ) {
var username ,
password ,
params ,
buttons ;
buttons = [
[ "Create Login" , function ( ) {
username = $ ( ".message input.text#username" ) . val ( ) ;
password = $ ( ".message input.text#password" ) . val ( ) ;
if ( username . length < 1 || password . length < 1 ) {
setTimeout ( function ( ) {
buttons = [
[ "Retry" , function ( ) { setTimeout ( settings . createLogin , 400 ) } ] ,
[ "" , function ( ) { } ]
] ;
modal . show ( "Wrong Input" , "The username or password you entered is not long enough. Please try again with another username and password!" , buttons , null , false ) ;
return false ;
} , 400 ) ;
} else {
2014-04-01 19:33:29 +00:00
params = "setLogin&username=" + escape ( username ) + "&password=" + md5 ( password ) ;
2014-01-22 10:12:51 +00:00
lychee . api ( params , function ( data ) {
if ( data !== true ) {
setTimeout ( function ( ) {
buttons = [
[ "Retry" , function ( ) { setTimeout ( settings . createLogin , 400 ) } ] ,
[ "" , function ( ) { } ]
] ;
modal . show ( "Creation Failed" , "Unable to save login. Please try again with another username and password!" , buttons , null , false ) ;
return false ;
} , 400 ) ;
}
} ) ;
}
} ] ,
[ "" , function ( ) { } ]
] ;
2014-02-23 21:42:15 +00:00
2014-01-22 10:12:51 +00:00
modal . show ( "Create Login" , "Enter a username and password for your installation: <input id='username' class='text less' type='text' placeholder='New Username' value=''><input id='password' class='text' type='password' placeholder='New Password' value=''>" , buttons , - 122 , false ) ;
} ,
setLogin : function ( ) {
var old _password ,
username ,
password ,
params ,
buttons ;
buttons = [
[ "Change Login" , function ( ) {
old _password = $ ( ".message input.text#old_password" ) . val ( ) ;
username = $ ( ".message input.text#username" ) . val ( ) ;
password = $ ( ".message input.text#password" ) . val ( ) ;
if ( old _password . length < 1 ) {
loadingBar . show ( "error" , "Your old password was entered incorrectly. Please try again!" ) ;
return false ;
}
if ( username . length < 1 ) {
loadingBar . show ( "error" , "Your new username was entered incorrectly. Please try again!" ) ;
return false ;
}
if ( password . length < 1 ) {
loadingBar . show ( "error" , "Your new password was entered incorrectly. Please try again!" ) ;
return false ;
}
2014-04-01 19:33:29 +00:00
params = "setLogin&oldPassword=" + md5 ( old _password ) + "&username=" + escape ( username ) + "&password=" + md5 ( password ) ;
2014-01-22 10:12:51 +00:00
lychee . api ( params , function ( data ) {
if ( data !== true ) lychee . error ( null , params , data ) ;
} ) ;
} ] ,
[ "Cancel" , function ( ) { } ]
] ;
2014-02-23 21:42:15 +00:00
2014-01-22 10:12:51 +00:00
modal . show ( "Change Login" , "Enter your current password: <input id='old_password' class='text more' type='password' placeholder='Current Password' value=''><br>Your username and password will be changed to the following: <input id='username' class='text less' type='text' placeholder='New Username' value=''><input id='password' class='text' type='password' placeholder='New Password' value=''>" , buttons , - 171 ) ;
} ,
setSorting : function ( ) {
var buttons ,
2014-04-15 12:17:32 +00:00
sorting ,
params ;
2014-01-22 10:12:51 +00:00
buttons = [
[ "Change Sorting" , function ( ) {
sorting [ 0 ] = $ ( "select#settings_type" ) . val ( ) ;
sorting [ 1 ] = $ ( "select#settings_order" ) . val ( ) ;
2014-09-19 21:14:53 +00:00
albums . refresh ( ) ;
2014-01-22 10:12:51 +00:00
params = "setSorting&type=" + sorting [ 0 ] + "&order=" + sorting [ 1 ] ;
lychee . api ( params , function ( data ) {
if ( data === true ) {
lychee . sorting = "ORDER BY " + sorting [ 0 ] + " " + sorting [ 1 ] ;
lychee . load ( ) ;
} else lychee . error ( null , params , data ) ;
} ) ;
} ] ,
[ "Cancel" , function ( ) { } ]
] ;
modal . show ( "Change Sorting" ,
" Sort photos by \
< select id = 'settings_type' > \
< option value = 'id' > Upload Time < / o p t i o n > \
2014-05-06 17:57:59 +00:00
< option value = 'takestamp' > Take Date < / o p t i o n > \
2014-01-22 10:12:51 +00:00
< option value = 'title' > Title < / o p t i o n > \
< option value = 'description' > Description < / o p t i o n > \
< option value = 'public' > Public < / o p t i o n > \
< option value = 'star' > Star < / o p t i o n > \
< option value = 'type' > Photo Format < / o p t i o n > \
< / s e l e c t > \
in an \
< select id = 'settings_order' > \
< option value = 'ASC' > Ascending < / o p t i o n > \
< option value = 'DESC' > Descending < / o p t i o n > \
< / s e l e c t > \
order . \
" , buttons ) ;
2014-02-25 22:37:05 +00:00
if ( lychee . sorting !== "" ) {
2014-03-20 17:54:23 +00:00
2014-05-06 17:57:59 +00:00
sorting = lychee . sorting . replace ( "ORDER BY " , "" ) . split ( " " ) ;
2014-03-20 17:54:23 +00:00
2014-01-22 10:12:51 +00:00
$ ( "select#settings_type" ) . val ( sorting [ 0 ] ) ;
$ ( "select#settings_order" ) . val ( sorting [ 1 ] ) ;
2014-05-06 17:57:59 +00:00
2014-01-22 10:12:51 +00:00
}
2014-02-23 21:42:15 +00:00
} ,
setDropboxKey : function ( callback ) {
var buttons ,
params ,
key ;
buttons = [
[ "Set Key" , function ( ) {
key = $ ( ".message input.text#key" ) . val ( ) ;
params = "setDropboxKey&key=" + key ;
lychee . api ( params , function ( data ) {
if ( data === true ) {
lychee . dropboxKey = key ;
if ( callback ) lychee . loadDropbox ( callback ) ;
} else lychee . error ( null , params , data ) ;
} ) ;
} ] ,
[ "Cancel" , function ( ) { } ]
] ;
modal . show ( "Set Dropbox Key" , "In order to import photos from your Dropbox, you need a valid drop-ins app key from <a href='https://www.dropbox.com/developers/apps/create'>their website</a>. Generate yourself a personal key and enter it below: <input id='key' class='text' type='text' placeholder='Dropbox API Key' value='" + lychee . dropboxKey + "'>" , buttons ) ;
2014-01-22 10:12:51 +00:00
}
2014-02-25 22:37:05 +00:00
} ;