settings.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /**
  2. * @description Lets you change settings.
  3. * @copyright 2014 by Tobias Reich
  4. */
  5. var settings = {
  6. createConfig: function() {
  7. var dbName,
  8. dbUser,
  9. dbPassword,
  10. dbHost,
  11. dbTablePrefix,
  12. buttons,
  13. params;
  14. buttons = [
  15. ["Connect", function() {
  16. dbHost = $(".message input.text#dbHost").val();
  17. dbUser = $(".message input.text#dbUser").val();
  18. dbPassword = $(".message input.text#dbPassword").val();
  19. dbName = $(".message input.text#dbName").val();
  20. dbTablePrefix = $(".message input.text#dbTablePrefix").val();
  21. if (dbHost.length<1) dbHost = "localhost";
  22. if (dbName.length<1) dbName = "lychee";
  23. params = "dbCreateConfig&dbName=" + escape(dbName) + "&dbUser=" + escape(dbUser) + "&dbPassword=" + escape(dbPassword) + "&dbHost=" + escape(dbHost) + "&dbTablePrefix=" + escape(dbTablePrefix);
  24. lychee.api(params, function(data) {
  25. if (data!==true) {
  26. // Configuration failed
  27. setTimeout(function() {
  28. // Connection failed
  29. if (data.indexOf("Warning: Connection failed!")!==-1) {
  30. buttons = [
  31. ["Retry", function() { setTimeout(settings.createConfig, 400) }],
  32. ["", function() {}]
  33. ];
  34. 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);
  35. return false;
  36. }
  37. // Creation failed
  38. if (data.indexOf("Warning: Creation failed!")!==-1) {
  39. buttons = [
  40. ["Retry", function() { setTimeout(settings.createConfig, 400) }],
  41. ["", function() {}]
  42. ];
  43. 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);
  44. return false;
  45. }
  46. // Could not create file
  47. if (data.indexOf("Warning: Could not create file!")!==-1) {
  48. buttons = [
  49. ["Retry", function() { setTimeout(settings.createConfig, 400) }],
  50. ["", function() {}]
  51. ];
  52. 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);
  53. return false;
  54. }
  55. // Something went wrong
  56. buttons = [
  57. ["Retry", function() { setTimeout(settings.createConfig, 400) }],
  58. ["", function() {}]
  59. ];
  60. 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);
  61. return false;
  62. }, 400);
  63. } else {
  64. // Configuration successful
  65. window.location.reload();
  66. }
  67. });
  68. }],
  69. ["", function() {}]
  70. ];
  71. 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);
  72. },
  73. createLogin: function() {
  74. var username,
  75. password,
  76. params,
  77. buttons;
  78. buttons = [
  79. ["Create Login", function() {
  80. username = $(".message input.text#username").val();
  81. password = $(".message input.text#password").val();
  82. if (username.length<1||password.length<1) {
  83. setTimeout(function() {
  84. buttons = [
  85. ["Retry", function() { setTimeout(settings.createLogin, 400) }],
  86. ["", function() {}]
  87. ];
  88. 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);
  89. return false;
  90. }, 400);
  91. } else {
  92. params = "setLogin&username=" + escape(username) + "&password=" + md5(password);
  93. lychee.api(params, function(data) {
  94. if (data!==true) {
  95. setTimeout(function() {
  96. buttons = [
  97. ["Retry", function() { setTimeout(settings.createLogin, 400) }],
  98. ["", function() {}]
  99. ];
  100. modal.show("Creation Failed", "Unable to save login. Please try again with another username and password!", buttons, null, false);
  101. return false;
  102. }, 400);
  103. }
  104. });
  105. }
  106. }],
  107. ["", function() {}]
  108. ];
  109. 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);
  110. },
  111. setLogin: function() {
  112. var old_password,
  113. username,
  114. password,
  115. params,
  116. buttons;
  117. buttons = [
  118. ["Change Login", function() {
  119. old_password = $(".message input.text#old_password").val();
  120. username = $(".message input.text#username").val();
  121. password = $(".message input.text#password").val();
  122. if (old_password.length<1) {
  123. loadingBar.show("error", "Your old password was entered incorrectly. Please try again!");
  124. return false;
  125. }
  126. if (username.length<1) {
  127. loadingBar.show("error", "Your new username was entered incorrectly. Please try again!");
  128. return false;
  129. }
  130. if (password.length<1) {
  131. loadingBar.show("error", "Your new password was entered incorrectly. Please try again!");
  132. return false;
  133. }
  134. params = "setLogin&oldPassword=" + md5(old_password) + "&username=" + escape(username) + "&password=" + md5(password);
  135. lychee.api(params, function(data) {
  136. if (data!==true) lychee.error(null, params, data);
  137. });
  138. }],
  139. ["Cancel", function() {}]
  140. ];
  141. 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);
  142. },
  143. setSorting: function() {
  144. var buttons,
  145. sorting,
  146. params;
  147. buttons = [
  148. ["Change Sorting", function() {
  149. sorting[0] = $("select#settings_type").val();
  150. sorting[1] = $("select#settings_order").val();
  151. albums.refresh();
  152. params = "setSorting&type=" + sorting[0] + "&order=" + sorting[1];
  153. lychee.api(params, function(data) {
  154. if (data===true) {
  155. lychee.sorting = "ORDER BY " + sorting[0] + " " + sorting[1];
  156. lychee.load();
  157. } else lychee.error(null, params, data);
  158. });
  159. }],
  160. ["Cancel", function() {}]
  161. ];
  162. modal.show("Change Sorting",
  163. "Sort photos by \
  164. <select id='settings_type'> \
  165. <option value='id'>Upload Time</option> \
  166. <option value='takestamp'>Take Date</option> \
  167. <option value='title'>Title</option> \
  168. <option value='description'>Description</option> \
  169. <option value='public'>Public</option> \
  170. <option value='star'>Star</option> \
  171. <option value='type'>Photo Format</option> \
  172. </select> \
  173. in an \
  174. <select id='settings_order'> \
  175. <option value='ASC'>Ascending</option> \
  176. <option value='DESC'>Descending</option> \
  177. </select> \
  178. order.\
  179. ", buttons);
  180. if (lychee.sorting!=="") {
  181. sorting = lychee.sorting.replace("ORDER BY ", "").split(" ");
  182. $("select#settings_type").val(sorting[0]);
  183. $("select#settings_order").val(sorting[1]);
  184. }
  185. },
  186. setDropboxKey: function(callback) {
  187. var buttons,
  188. params,
  189. key;
  190. buttons = [
  191. ["Set Key", function() {
  192. key = $(".message input.text#key").val();
  193. params = "setDropboxKey&key=" + key;
  194. lychee.api(params, function(data) {
  195. if (data===true) {
  196. lychee.dropboxKey = key;
  197. if (callback) lychee.loadDropbox(callback);
  198. } else lychee.error(null, params, data);
  199. });
  200. }],
  201. ["Cancel", function() {}]
  202. ];
  203. 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);
  204. }
  205. };