From 9d87beeb7528ceff45fdc46130ed7f53f1ba3481 Mon Sep 17 00:00:00 2001 From: Tobias Reich Date: Tue, 20 Jan 2015 13:21:13 +0100 Subject: [PATCH] Updated createConfig dialog --- src/scripts/settings.js | 174 +++++++++++++++++++++++----------------- 1 file changed, 100 insertions(+), 74 deletions(-) diff --git a/src/scripts/settings.js b/src/scripts/settings.js index 61dd673..5c7aa5e 100644 --- a/src/scripts/settings.js +++ b/src/scripts/settings.js @@ -7,94 +7,120 @@ settings = {} settings.createConfig = function() { - var dbName, - dbUser, - dbPassword, - dbHost, - dbTablePrefix, - buttons, - params; + var msg, + action; - buttons = [ - ['Connect', function() { + action = function(data) { - 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(); + 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'; + 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) { + 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) { + 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; + // 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 + } } + }); - // 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; - - } - - // Could not create file - if (data.indexOf('Warning: Could not create file!')!==-1) { - - buttons = [ - ['Retry', function() { setTimeout(settings.createConfig, 400) }], - ['', function() {}] - ]; - modal.show('Saving Failed', "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 the readme for more information.", buttons, null, false); - 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 - window.location.reload(); + return false; } - }); + // Creation failed + if (data.indexOf('Warning: Creation failed!')!==-1) { - }], - ['', function() {}] - ]; + 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 + } + } + }); - modal.show('Configuration', "Enter your database connection details below:
Lychee will create its own database. If required, you can enter the name of an existing database instead:", buttons, -235, false); + 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 + } + } + }); }