/** * @description Lets you change settings. */ settings = {} settings.createConfig = function() { const action = function(data) { let dbName = data.dbName || '' let dbUser = data.dbUser || '' let dbPassword = data.dbPassword || '' let dbHost = data.dbHost || '' let dbTablePrefix = data.dbTablePrefix || '' if (dbUser.length<1) { basicModal.error('dbUser') return false } if (dbHost.length<1) dbHost = 'localhost' if (dbName.length<1) dbName = 'lychee' let params = { dbName, dbUser, dbPassword, dbHost, dbTablePrefix } api.post('Config::create', params, function(data) { if (data!==true) { // Connection failed if (data==='Warning: Connection failed!') { basicModal.show({ body: '

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: { action: { title: 'Retry', fn: settings.createConfig } } }) return false } // Creation failed if (data==='Warning: Creation failed!') { basicModal.show({ body: '

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: { action: { title: 'Retry', fn: settings.createConfig } } }) return false } // Could not create file if (data==='Warning: Could not create file!') { basicModal.show({ body: "

Unable to save this configuration. Permission denied in 'data/'. Please set the read, write and execute rights for others in 'data/' and 'uploads/'. Take a look at the readme for more information.

", buttons: { action: { title: 'Retry', fn: settings.createConfig } } }) return false } // Something went wrong basicModal.show({ body: '

Something unexpected happened. Please try again and check your installation and server. Take a look at the readme for more information.

', buttons: { action: { title: 'Retry', fn: settings.createConfig } } }) return false } else { // Configuration successful window.location.reload() } }) } let msg = `

Enter your database connection details below:

Lychee will create its own database. If required, you can enter the name of an existing database instead:

` basicModal.show({ body: msg, buttons: { action: { title: 'Connect', fn: action } } }) } settings.createLogin = function() { const action = function(data) { let username = data.username let password = data.password if (username.length<1) { basicModal.error('username') return false } if (password.length<1) { basicModal.error('password') return false } basicModal.close() let params = { username, password } api.post('Settings::setLogin', params, function(data) { if (data!==true) { basicModal.show({ body: '

Unable to save login. Please try again with another username and password!

', buttons: { action: { title: 'Retry', fn: settings.createLogin } } }) } }) } let msg = `

Enter a username and password for your installation:

` basicModal.show({ body: msg, buttons: { action: { title: 'Create Login', fn: action } } }) } settings.setLogin = function() { const action = function(data) { let oldPassword = data.oldPassword || '' let username = data.username || '' let password = data.password || '' if (oldPassword.length<1) { basicModal.error('oldPassword') return false } if (username.length<1) { basicModal.error('username') return false } if (password.length<1) { basicModal.error('password') return false } basicModal.close() let params = { oldPassword, username, password } api.post('Settings::setLogin', params, function(data) { if (data!==true) lychee.error(null, params, data) }) } let msg = `

Enter your current password:

Your username and password will be changed to the following:

` basicModal.show({ body: msg, buttons: { action: { title: 'Change Login', fn: action }, cancel: { title: 'Cancel', fn: basicModal.close } } }) } settings.setSorting = function() { let sortingPhotos = [] let sortingAlbums = [] const action = function() { sortingAlbums[0] = $('.basicModal select#settings_albums_type').val() sortingAlbums[1] = $('.basicModal select#settings_albums_order').val() sortingPhotos[0] = $('.basicModal select#settings_photos_type').val() sortingPhotos[1] = $('.basicModal select#settings_photos_order').val() basicModal.close() albums.refresh() let params = { typeAlbums : sortingAlbums[0], orderAlbums : sortingAlbums[1], typePhotos : sortingPhotos[0], orderPhotos : sortingPhotos[1] } api.post('Settings::setSorting', params, function(data) { if (data===true) { lychee.sortingAlbums = 'ORDER BY ' + sortingAlbums[0] + ' ' + sortingAlbums[1] lychee.sortingPhotos = 'ORDER BY ' + sortingPhotos[0] + ' ' + sortingPhotos[1] lychee.load() } else lychee.error(null, params, data) }) } let msg = `

Sort albums by in an order.

Sort photos by in an order.

` basicModal.show({ body: msg, buttons: { action: { title: 'Change Sorting', fn: action }, cancel: { title: 'Cancel', fn: basicModal.close } } }) if (lychee.sortingAlbums!=='') { sortingAlbums = lychee.sortingAlbums.replace('ORDER BY ', '').split(' ') $('.basicModal select#settings_albums_type').val(sortingAlbums[0]) $('.basicModal select#settings_albums_order').val(sortingAlbums[1]) } if (lychee.sortingPhotos!=='') { sortingPhotos = lychee.sortingPhotos.replace('ORDER BY ', '').split(' ') $('.basicModal select#settings_photos_type').val(sortingPhotos[0]) $('.basicModal select#settings_photos_order').val(sortingPhotos[1]) } } settings.setDropboxKey = function(callback) { const action = function(data) { let key = data.key if (data.key.length<1) { basicModal.error('key') return false } basicModal.close() api.post('Settings::setDropboxKey', { key }, function(data) { if (data===true) { lychee.dropboxKey = key if (callback) lychee.loadDropbox(callback) } else lychee.error(null, params, data) }) } let msg = lychee.html`

In order to import photos from your Dropbox, you need a valid drop-ins app key from their website. Generate yourself a personal key and enter it below:

` basicModal.show({ body: msg, buttons: { action: { title: 'Set Dropbox Key', fn: action }, cancel: { title: 'Cancel', fn: basicModal.close } } }) }