123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428 |
- /**
- * @description Lets you change settings.
- * @copyright 2015 by Tobias Reich
- */
- 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: '<p>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.</p>',
- buttons: {
- action: {
- title: 'Retry',
- fn: settings.createConfig
- }
- }
- })
- return false
- }
- // Creation failed
- if (data==='Warning: Creation failed!') {
- basicModal.show({
- body: '<p>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.</p>',
- buttons: {
- action: {
- title: 'Retry',
- fn: settings.createConfig
- }
- }
- })
- return false
- }
- // Could not create file
- if (data==='Warning: Could not create file!') {
- basicModal.show({
- body: "<p>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 at the readme for more information.</p>",
- buttons: {
- action: {
- title: 'Retry',
- fn: settings.createConfig
- }
- }
- })
- return false
- }
- // Something went wrong
- basicModal.show({
- body: '<p>Something unexpected happened. Please try again and check your installation and server. Take a look at the readme for more information.</p>',
- buttons: {
- action: {
- title: 'Retry',
- fn: settings.createConfig
- }
- }
- })
- return false
- } else {
- // Configuration successful
- window.location.reload()
- }
- })
- }
- let msg = `
- <p>
- Enter your database connection details below:
- <input name='dbHost' class='text' type='text' placeholder='Database Host (optional)' value=''>
- <input name='dbUser' class='text' type='text' placeholder='Database Username' value=''>
- <input name='dbPassword' class='text' type='password' placeholder='Database Password' value=''>
- </p>
- <p>
- Lychee will create its own database. If required, you can enter the name of an existing database instead:
- <input name='dbName' class='text' type='text' placeholder='Database Name (optional)' value=''>
- <input name='dbTablePrefix' class='text' type='text' placeholder='Table prefix (optional)' value=''>
- </p>
- `
- 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: '<p>Unable to save login. Please try again with another username and password!</p>',
- buttons: {
- action: {
- title: 'Retry',
- fn: settings.createLogin
- }
- }
- })
- }
- })
- }
- let msg = `
- <p>
- Enter a username and password for your installation:
- <input name='username' class='text' type='text' placeholder='New Username' value=''>
- <input name='password' class='text' type='password' placeholder='New Password' value=''>
- </p>
- `
- 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 = `
- <p>
- Enter your current password:
- <input name='oldPassword' class='text' type='password' placeholder='Current Password' value=''>
- </p>
- <p>
- Your username and password will be changed to the following:
- <input name='username' class='text' type='text' placeholder='New Username' value=''>
- <input name='password' class='text' type='password' placeholder='New Password' value=''>
- </p>
- `
- 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 = `
- <p>
- Sort albums by
- <span class="select">
- <select id='settings_albums_type'>
- <option value='id'>Creation Time</option>
- <option value='title'>Title</option>
- <option value='description'>Description</option>
- <option value='public'>Public</option>
- </select>
- </span>
- in an
- <span class="select">
- <select id='settings_albums_order'>
- <option value='ASC'>Ascending</option>
- <option value='DESC'>Descending</option>
- </select>
- </span>
- order.
- </p>
- <p>
- Sort photos by
- <span class="select">
- <select id='settings_photos_type'>
- <option value='id'>Upload Time</option>
- <option value='takestamp'>Take Date</option>
- <option value='title'>Title</option>
- <option value='description'>Description</option>
- <option value='public'>Public</option>
- <option value='star'>Star</option>
- <option value='type'>Photo Format</option>
- </select>
- </span>
- in an
- <span class="select">
- <select id='settings_photos_order'>
- <option value='ASC'>Ascending</option>
- <option value='DESC'>Descending</option>
- </select>
- </span>
- order.
- </p>
- `
- 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`
- <p>
- 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 class='text' name='key' type='text' placeholder='Dropbox API Key' value='$${ lychee.dropboxKey }'>
- </p>
- `
- basicModal.show({
- body: msg,
- buttons: {
- action: {
- title: 'Set Dropbox Key',
- fn: action
- },
- cancel: {
- title: 'Cancel',
- fn: basicModal.close
- }
- }
- })
- }
|