settings.js 8.4 KB

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