Front-end rewrite #275

This commit is contained in:
Tobias Reich 2014-11-20 23:27:41 +01:00
parent 752d094775
commit c849cf33a9
10 changed files with 259 additions and 246 deletions

BIN
dist/main.js vendored

Binary file not shown.

View File

@ -3,9 +3,11 @@
* @copyright 2014 by Tobias Reich * @copyright 2014 by Tobias Reich
*/ */
album = {} album = {
album.json = null; json: null
}
album.getID = function() { album.getID = function() {

View File

@ -3,9 +3,11 @@
* @copyright 2014 by Tobias Reich * @copyright 2014 by Tobias Reich
*/ */
albums = {} albums = {
albums.json = null; json: null
}
albums.load = function() { albums.load = function() {

View File

@ -3,9 +3,11 @@
* @copyright 2014 by Tobias Reich * @copyright 2014 by Tobias Reich
*/ */
loadingBar = {} loadingBar = {
loadingBar.status = null; status: null
}
loadingBar.show = function(status, errorText) { loadingBar.show = function(status, errorText) {

View File

@ -3,9 +3,11 @@
* @copyright 2014 by Tobias Reich * @copyright 2014 by Tobias Reich
*/ */
modal = {} modal = {
modal.fns = null; fns: null
}
modal.show = function(title, text, buttons, marginTop, closeButton) { modal.show = function(title, text, buttons, marginTop, closeButton) {

View File

@ -3,9 +3,11 @@
* @copyright 2014 by Tobias Reich * @copyright 2014 by Tobias Reich
*/ */
password = {} password = {
password.value = ''; value: ''
}
password.get = function(albumID, callback) { password.get = function(albumID, callback) {

View File

@ -3,10 +3,12 @@
* @copyright 2014 by Tobias Reich * @copyright 2014 by Tobias Reich
*/ */
photo = {} photo = {
photo.json = null; json: null,
photo.cache = null; cache: null
}
photo.getID = function() { photo.getID = function() {

View File

@ -3,9 +3,11 @@
* @copyright 2014 by Tobias Reich * @copyright 2014 by Tobias Reich
*/ */
search = {} search = {
search.code = null; code: null
}
search.find = function(term) { search.find = function(term) {

View File

@ -3,9 +3,9 @@
* @copyright 2014 by Tobias Reich * @copyright 2014 by Tobias Reich
*/ */
var settings = { settings = {}
createConfig: function() { settings.createConfig = function() {
var dbName, var dbName,
dbUser, dbUser,
@ -16,18 +16,18 @@ var settings = {
params; params;
buttons = [ buttons = [
["Connect", function() { ['Connect', function() {
dbHost = $(".message input.text#dbHost").val(); dbHost = $('.message input.text#dbHost').val();
dbUser = $(".message input.text#dbUser").val(); dbUser = $('.message input.text#dbUser').val();
dbPassword = $(".message input.text#dbPassword").val(); dbPassword = $('.message input.text#dbPassword').val();
dbName = $(".message input.text#dbName").val(); dbName = $('.message input.text#dbName').val();
dbTablePrefix = $(".message input.text#dbTablePrefix").val(); dbTablePrefix = $('.message input.text#dbTablePrefix').val();
if (dbHost.length<1) dbHost = "localhost"; if (dbHost.length<1) dbHost = 'localhost';
if (dbName.length<1) dbName = "lychee"; if (dbName.length<1) dbName = 'lychee';
params = "dbCreateConfig&dbName=" + escape(dbName) + "&dbUser=" + escape(dbUser) + "&dbPassword=" + escape(dbPassword) + "&dbHost=" + escape(dbHost) + "&dbTablePrefix=" + escape(dbTablePrefix); params = 'dbCreateConfig&dbName=' + escape(dbName) + '&dbUser=' + escape(dbUser) + '&dbPassword=' + escape(dbPassword) + '&dbHost=' + escape(dbHost) + '&dbTablePrefix=' + escape(dbTablePrefix);
lychee.api(params, function(data) { lychee.api(params, function(data) {
if (data!==true) { if (data!==true) {
@ -36,47 +36,47 @@ var settings = {
setTimeout(function() { setTimeout(function() {
// Connection failed // Connection failed
if (data.indexOf("Warning: Connection failed!")!==-1) { if (data.indexOf('Warning: Connection failed!')!==-1) {
buttons = [ buttons = [
["Retry", function() { setTimeout(settings.createConfig, 400) }], ['Retry', function() { setTimeout(settings.createConfig, 400) }],
["", function() {}] ['', 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); 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; return false;
} }
// Creation failed // Creation failed
if (data.indexOf("Warning: Creation failed!")!==-1) { if (data.indexOf('Warning: Creation failed!')!==-1) {
buttons = [ buttons = [
["Retry", function() { setTimeout(settings.createConfig, 400) }], ['Retry', function() { setTimeout(settings.createConfig, 400) }],
["", function() {}] ['', 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); 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; return false;
} }
// Could not create file // Could not create file
if (data.indexOf("Warning: Could not create file!")!==-1) { if (data.indexOf('Warning: Could not create file!')!==-1) {
buttons = [ buttons = [
["Retry", function() { setTimeout(settings.createConfig, 400) }], ['Retry', function() { setTimeout(settings.createConfig, 400) }],
["", function() {}] ['', function() {}]
]; ];
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); 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);
return false; return false;
} }
// Something went wrong // Something went wrong
buttons = [ buttons = [
["Retry", function() { setTimeout(settings.createConfig, 400) }], ['Retry', function() { setTimeout(settings.createConfig, 400) }],
["", function() {}] ['', 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); 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; return false;
}, 400); }, 400);
@ -91,14 +91,14 @@ var settings = {
}); });
}], }],
["", function() {}] ['', function() {}]
]; ];
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); 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);
}, }
createLogin: function() { settings.createLogin = function() {
var username, var username,
password, password,
@ -106,27 +106,27 @@ var settings = {
buttons; buttons;
buttons = [ buttons = [
["Create Login", function() { ['Create Login', function() {
username = $(".message input.text#username").val(); username = $('.message input.text#username').val();
password = $(".message input.text#password").val(); password = $('.message input.text#password').val();
if (username.length<1||password.length<1) { if (username.length<1||password.length<1) {
setTimeout(function() { setTimeout(function() {
buttons = [ buttons = [
["Retry", function() { setTimeout(settings.createLogin, 400) }], ['Retry', function() { setTimeout(settings.createLogin, 400) }],
["", function() {}] ['', 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); 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; return false;
}, 400); }, 400);
} else { } else {
params = "setLogin&username=" + escape(username) + "&password=" + md5(password); params = 'setLogin&username=' + escape(username) + '&password=' + md5(password);
lychee.api(params, function(data) { lychee.api(params, function(data) {
if (data!==true) { if (data!==true) {
@ -134,10 +134,10 @@ var settings = {
setTimeout(function() { setTimeout(function() {
buttons = [ buttons = [
["Retry", function() { setTimeout(settings.createLogin, 400) }], ['Retry', function() { setTimeout(settings.createLogin, 400) }],
["", function() {}] ['', function() {}]
]; ];
modal.show("Creation Failed", "Unable to save login. Please try again with another username and password!", buttons, null, false); modal.show('Creation Failed', 'Unable to save login. Please try again with another username and password!', buttons, null, false);
return false; return false;
}, 400); }, 400);
@ -149,14 +149,14 @@ var settings = {
} }
}], }],
["", function() {}] ['', function() {}]
]; ];
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); 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() { settings.setLogin = function() {
var old_password, var old_password,
username, username,
@ -165,28 +165,28 @@ var settings = {
buttons; buttons;
buttons = [ buttons = [
["Change Login", function() { ['Change Login', function() {
old_password = $(".message input.text#old_password").val(); old_password = $('.message input.text#old_password').val();
username = $(".message input.text#username").val(); username = $('.message input.text#username').val();
password = $(".message input.text#password").val(); password = $('.message input.text#password').val();
if (old_password.length<1) { if (old_password.length<1) {
loadingBar.show("error", "Your old password was entered incorrectly. Please try again!"); loadingBar.show('error', 'Your old password was entered incorrectly. Please try again!');
return false; return false;
} }
if (username.length<1) { if (username.length<1) {
loadingBar.show("error", "Your new username was entered incorrectly. Please try again!"); loadingBar.show('error', 'Your new username was entered incorrectly. Please try again!');
return false; return false;
} }
if (password.length<1) { if (password.length<1) {
loadingBar.show("error", "Your new password was entered incorrectly. Please try again!"); loadingBar.show('error', 'Your new password was entered incorrectly. Please try again!');
return false; return false;
} }
params = "setLogin&oldPassword=" + md5(old_password) + "&username=" + escape(username) + "&password=" + md5(password); params = 'setLogin&oldPassword=' + md5(old_password) + '&username=' + escape(username) + '&password=' + md5(password);
lychee.api(params, function(data) { lychee.api(params, function(data) {
if (data!==true) lychee.error(null, params, data); if (data!==true) lychee.error(null, params, data);
@ -194,41 +194,42 @@ var settings = {
}); });
}], }],
["Cancel", function() {}] ['Cancel', function() {}]
]; ];
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); 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() { settings.setSorting = function() {
var buttons, var buttons,
sorting, sorting,
params; params;
buttons = [ buttons = [
["Change Sorting", function() { ['Change Sorting', function() {
sorting[0] = $("select#settings_type").val(); sorting[0] = $('select#settings_type').val();
sorting[1] = $("select#settings_order").val(); sorting[1] = $('select#settings_order').val();
albums.refresh(); albums.refresh();
params = "setSorting&type=" + sorting[0] + "&order=" + sorting[1]; params = 'setSorting&type=' + sorting[0] + '&order=' + sorting[1];
lychee.api(params, function(data) { lychee.api(params, function(data) {
if (data===true) { if (data===true) {
lychee.sorting = "ORDER BY " + sorting[0] + " " + sorting[1]; lychee.sorting = 'ORDER BY ' + sorting[0] + ' ' + sorting[1];
lychee.load(); lychee.load();
} else lychee.error(null, params, data); } else lychee.error(null, params, data);
}); });
}], }],
["Cancel", function() {}] ['Cancel', function() {}]
]; ];
modal.show("Change Sorting",
modal.show('Change Sorting',
"Sort photos by \ "Sort photos by \
<select id='settings_type'> \ <select id='settings_type'> \
<option value='id'>Upload Time</option> \ <option value='id'>Upload Time</option> \
@ -247,29 +248,29 @@ var settings = {
order.\ order.\
", buttons); ", buttons);
if (lychee.sorting!=="") { if (lychee.sorting!=='') {
sorting = lychee.sorting.replace("ORDER BY ", "").split(" "); sorting = lychee.sorting.replace('ORDER BY ', '').split(' ');
$("select#settings_type").val(sorting[0]); $('select#settings_type').val(sorting[0]);
$("select#settings_order").val(sorting[1]); $('select#settings_order').val(sorting[1]);
} }
}, }
setDropboxKey: function(callback) { settings.setDropboxKey = function(callback) {
var buttons, var buttons,
params, params,
key; key;
buttons = [ buttons = [
["Set Key", function() { ['Set Key', function() {
key = $(".message input.text#key").val(); key = $('.message input.text#key').val();
params = "setDropboxKey&key=" + key; params = 'setDropboxKey&key=' + key;
lychee.api(params, function(data) { lychee.api(params, function(data) {
if (data===true) { if (data===true) {
@ -280,11 +281,9 @@ var settings = {
}); });
}], }],
["Cancel", function() {}] ['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); 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);
} }
};

View File

@ -9,57 +9,57 @@ visible = {}
visible.albums = function() { visible.albums = function() {
if ($('#tools_albums').css('display')==='block') return true; if ($('#tools_albums').css('display')==='block') return true;
else return false; return false;
} }
visible.album = function() { visible.album = function() {
if ($('#tools_album').css('display')==='block') return true; if ($('#tools_album').css('display')==='block') return true;
else return false; return false;
} }
visible.photo = function() { visible.photo = function() {
if ($('#imageview.fadeIn').length>0) return true; if ($('#imageview.fadeIn').length>0) return true;
else return false; return false;
} }
visible.search = function() { visible.search = function() {
if (search.code!==null&&search.code!=='') return true; if (search.code!==null&&search.code!=='') return true;
else return false; return false;
} }
visible.infobox = function() { visible.infobox = function() {
if ($('#infobox.active').length>0) return true; if ($('#infobox.active').length>0) return true;
else return false; return false;
} }
visible.infoboxbutton = function() { visible.infoboxbutton = function() {
if (visible.albums()) return false; if (visible.albums()) return false;
if (visible.photo()) return true; if (visible.photo()) return true;
if (visible.album()&&$('#button_info_album:visible').length>0) return true; if (visible.album()&&$('#button_info_album:visible').length>0) return true;
else return false; return false;
} }
visible.controls = function() { visible.controls = function() {
if (lychee.loadingBar.css('opacity')<1) return false; if (lychee.loadingBar.css('opacity')<1) return false;
else return true; return true;
} }
visible.message = function() { visible.message = function() {
if ($('.message').length>0) return true; if ($('.message').length>0) return true;
else return false; return false;
} }
visible.signin = function() { visible.signin = function() {
if ($('.message .sign_in').length>0) return true; if ($('.message .sign_in').length>0) return true;
else return false; return false;
} }
visible.contextMenu = function() { visible.contextMenu = function() {
if ($('.contextContainer').length>0) return true; if ($('.contextContainer').length>0) return true;
else return false; return false;
} }
visible.multiselect = function() { visible.multiselect = function() {
if ($('#multiselect').length>0) return true; if ($('#multiselect').length>0) return true;
else return false; return false;
} }