settings.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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' type='text' placeholder='Database Host (optional)' value=''>";
  79. msg += "<input data-name='dbUser' class='text' type='text' placeholder='Database Username' value=''>";
  80. msg += "<input data-name='dbPassword' class='text' 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' type='text' placeholder='Database Name (optional)' value=''>";
  84. msg += "<input data-name='dbTablePrefix' class='text' 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 msg = '',
  136. action;
  137. action = function(data) {
  138. var oldPassword = data.oldPassword || '',
  139. username = data.username || '',
  140. password = data.password || '',
  141. params;
  142. if (oldPassword.length<1) {
  143. basicModal.error('oldPassword');
  144. return false;
  145. }
  146. if (username.length<1) {
  147. basicModal.error('username');
  148. return false;
  149. }
  150. if (password.length<1) {
  151. basicModal.error('password');
  152. return false;
  153. }
  154. basicModal.close();
  155. params = 'setLogin&oldPassword=' + md5(oldPassword) + '&username=' + escape(username) + '&password=' + md5(password);
  156. lychee.api(params, function(data) {
  157. if (data!==true) lychee.error(null, params, data);
  158. });
  159. }
  160. msg += "<p>Enter your current password:";
  161. msg += "<input data-name='oldPassword' class='text' type='password' placeholder='Current Password' value=''>";
  162. msg += "</p>"
  163. msg += "<p>Your username and password will be changed to the following:";
  164. msg += "<input data-name='username' class='text' type='text' placeholder='New Username' value=''>";
  165. msg += "<input data-name='password' class='text' type='password' placeholder='New Password' value=''>";
  166. msg += "</p>";
  167. basicModal.show({
  168. body: msg,
  169. buttons: {
  170. action: {
  171. title: 'Change Login',
  172. fn: action
  173. },
  174. cancel: {
  175. title: 'Cancel',
  176. fn: basicModal.close
  177. }
  178. }
  179. });
  180. }
  181. settings.setSorting = function() {
  182. var buttons,
  183. sorting,
  184. params;
  185. buttons = [
  186. ['Change Sorting', function() {
  187. sorting[0] = $('select#settings_type').val();
  188. sorting[1] = $('select#settings_order').val();
  189. albums.refresh();
  190. params = 'setSorting&type=' + sorting[0] + '&order=' + sorting[1];
  191. lychee.api(params, function(data) {
  192. if (data===true) {
  193. lychee.sorting = 'ORDER BY ' + sorting[0] + ' ' + sorting[1];
  194. lychee.load();
  195. } else lychee.error(null, params, data);
  196. });
  197. }],
  198. ['Cancel', function() {}]
  199. ];
  200. modal.show('Change Sorting',
  201. "Sort photos by \
  202. <select id='settings_type'> \
  203. <option value='id'>Upload Time</option> \
  204. <option value='takestamp'>Take Date</option> \
  205. <option value='title'>Title</option> \
  206. <option value='description'>Description</option> \
  207. <option value='public'>Public</option> \
  208. <option value='star'>Star</option> \
  209. <option value='type'>Photo Format</option> \
  210. </select> \
  211. in an \
  212. <select id='settings_order'> \
  213. <option value='ASC'>Ascending</option> \
  214. <option value='DESC'>Descending</option> \
  215. </select> \
  216. order.\
  217. ", buttons);
  218. if (lychee.sorting!=='') {
  219. sorting = lychee.sorting.replace('ORDER BY ', '').split(' ');
  220. $('select#settings_type').val(sorting[0]);
  221. $('select#settings_order').val(sorting[1]);
  222. }
  223. }
  224. settings.setDropboxKey = function(callback) {
  225. var action,
  226. msg = "";
  227. action = function(data) {
  228. var params,
  229. key = data.key;
  230. if (data.key.length<1) {
  231. basicModal.error('key');
  232. return false;
  233. }
  234. basicModal.close();
  235. params = 'setDropboxKey&key=' + key;
  236. lychee.api(params, function(data) {
  237. if (data===true) {
  238. lychee.dropboxKey = key;
  239. if (callback) lychee.loadDropbox(callback);
  240. } else lychee.error(null, params, data);
  241. });
  242. }
  243. msg += "<p>";
  244. msg += "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:";
  245. msg += "<input class='text' data-name='key' type='text' placeholder='Dropbox API Key' value='" + lychee.dropboxKey + "'>";
  246. msg += "</p>";
  247. basicModal.show({
  248. body: msg,
  249. buttons: {
  250. action: {
  251. title: 'Set Dropbox Key',
  252. fn: action
  253. },
  254. cancel: {
  255. title: 'Cancel',
  256. fn: basicModal.close
  257. }
  258. }
  259. });
  260. }