settings.js 8.8 KB

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