/** * @description Lets you change settings. * @copyright 2014 by Tobias Reich */ settings = {} settings.createConfig = function() { var msg, action; action = function(data) { var dbName = data.dbName || '', dbUser = data.dbUser || '', dbPassword = data.dbPassword || '', dbHost = data.dbHost || '', dbTablePrefix = data.dbTablePrefix || '', params; if (dbHost.length<1) dbHost = 'localhost'; if (dbName.length<1) dbName = 'lychee'; params = 'dbCreateConfig&dbName=' + escape(dbName) + '&dbUser=' + escape(dbUser) + '&dbPassword=' + escape(dbPassword) + '&dbHost=' + escape(dbHost) + '&dbTablePrefix=' + escape(dbTablePrefix); lychee.api(params, function(data) { if (data!==true) { // Connection failed if (data.indexOf('Warning: Connection failed!')!==-1) { 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.indexOf('Warning: Creation failed!')!==-1) { 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.indexOf('Warning: Could not create file!')!==-1) { 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(); } }); } msg = "

Enter your database connection details below:"; msg += ""; msg += ""; msg += ""; msg += "

"; msg += "

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

"; basicModal.show({ body: msg, buttons: { action: { title: 'Connect', fn: action } } }); } settings.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 { params = 'setLogin&username=' + escape(username) + '&password=' + md5(password); 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() {}] ]; modal.show('Create Login', "Enter a username and password for your installation: ", buttons, -122, false); } settings.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; } params = 'setLogin&oldPassword=' + md5(old_password) + '&username=' + escape(username) + '&password=' + md5(password); lychee.api(params, function(data) { if (data!==true) lychee.error(null, params, data); }); }], ['Cancel', function() {}] ]; modal.show('Change Login', "Enter your current password:
Your username and password will be changed to the following: ", buttons, -171); } settings.setSorting = function() { var buttons, sorting, params; buttons = [ ['Change Sorting', function() { sorting[0] = $('select#settings_type').val(); sorting[1] = $('select#settings_order').val(); albums.refresh(); 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 \ \ in an \ \ order.\ ", buttons); if (lychee.sorting!=='') { sorting = lychee.sorting.replace('ORDER BY ', '').split(' '); $('select#settings_type').val(sorting[0]); $('select#settings_order').val(sorting[1]); } } settings.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 their website. Generate yourself a personal key and enter it below: ", buttons); }