settings.js 8.2 KB

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