settings.js 8.1 KB

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