settings.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. /**
  2. * @description Lets you change settings.
  3. * @copyright 2015 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 (dbUser.length<1) {
  17. basicModal.error('dbUser');
  18. return false;
  19. }
  20. if (dbHost.length<1) dbHost = 'localhost';
  21. if (dbName.length<1) dbName = 'lychee';
  22. params = {
  23. dbName,
  24. dbUser,
  25. dbPassword,
  26. dbHost,
  27. dbTablePrefix
  28. }
  29. api.post('dbCreateConfig', params, function(data) {
  30. if (data!==true) {
  31. // Connection failed
  32. if (data.indexOf('Warning: Connection failed!')!==-1) {
  33. basicModal.show({
  34. 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>',
  35. buttons: {
  36. action: {
  37. title: 'Retry',
  38. fn: settings.createConfig
  39. }
  40. }
  41. });
  42. return false;
  43. }
  44. // Creation failed
  45. if (data.indexOf('Warning: Creation failed!')!==-1) {
  46. basicModal.show({
  47. 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>',
  48. buttons: {
  49. action: {
  50. title: 'Retry',
  51. fn: settings.createConfig
  52. }
  53. }
  54. });
  55. return false;
  56. }
  57. // Could not create file
  58. if (data.indexOf('Warning: Could not create file!')!==-1) {
  59. basicModal.show({
  60. 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>",
  61. buttons: {
  62. action: {
  63. title: 'Retry',
  64. fn: settings.createConfig
  65. }
  66. }
  67. });
  68. return false;
  69. }
  70. // Something went wrong
  71. basicModal.show({
  72. body: '<p>Something unexpected happened. Please try again and check your installation and server. Take a look at the readme for more information.</p>',
  73. buttons: {
  74. action: {
  75. title: 'Retry',
  76. fn: settings.createConfig
  77. }
  78. }
  79. });
  80. return false;
  81. } else {
  82. // Configuration successful
  83. window.location.reload();
  84. }
  85. });
  86. }
  87. msg = `
  88. <p>
  89. Enter your database connection details below:
  90. <input data-name='dbHost' class='text' type='text' placeholder='Database Host (optional)' value=''>
  91. <input data-name='dbUser' class='text' type='text' placeholder='Database Username' value=''>
  92. <input data-name='dbPassword' class='text' type='password' placeholder='Database Password' value=''>
  93. </p>
  94. <p>
  95. Lychee will create its own database. If required, you can enter the name of an existing database instead:
  96. <input data-name='dbName' class='text' type='text' placeholder='Database Name (optional)' value=''>
  97. <input data-name='dbTablePrefix' class='text' type='text' placeholder='Table prefix (optional)' value=''>
  98. </p>
  99. `
  100. basicModal.show({
  101. body: msg,
  102. buttons: {
  103. action: {
  104. title: 'Connect',
  105. fn: action
  106. }
  107. }
  108. });
  109. }
  110. settings.createLogin = function() {
  111. var action,
  112. msg = '';
  113. action = function(data) {
  114. var params,
  115. username = data.username,
  116. password = data.password;
  117. if (username.length<1) {
  118. basicModal.error('username');
  119. return false;
  120. }
  121. if (password.length<1) {
  122. basicModal.error('password');
  123. return false;
  124. }
  125. basicModal.close();
  126. params = 'setLogin&username=' + escape(username) + '&password=' + md5(password);
  127. params = {
  128. username,
  129. password: md5(password)
  130. }
  131. api.post('setLogin', params, function(data) {
  132. if (data!==true) {
  133. basicModal.show({
  134. body: '<p>Unable to save login. Please try again with another username and password!</p>',
  135. buttons: {
  136. action: {
  137. title: 'Retry',
  138. fn: settings.createLogin
  139. }
  140. }
  141. });
  142. }
  143. });
  144. }
  145. msg = `
  146. <p>
  147. Enter a username and password for your installation:
  148. <input data-name='username' class='text' type='text' placeholder='New Username' value=''>
  149. <input data-name='password' class='text' type='password' placeholder='New Password' value=''>
  150. </p>
  151. `
  152. basicModal.show({
  153. body: msg,
  154. buttons: {
  155. action: {
  156. title: 'Create Login',
  157. fn: action
  158. }
  159. }
  160. });
  161. }
  162. settings.setLogin = function() {
  163. var msg = '',
  164. action;
  165. action = function(data) {
  166. var oldPassword = data.oldPassword || '',
  167. username = data.username || '',
  168. password = data.password || '',
  169. params;
  170. if (oldPassword.length<1) {
  171. basicModal.error('oldPassword');
  172. return false;
  173. }
  174. if (username.length<1) {
  175. basicModal.error('username');
  176. return false;
  177. }
  178. if (password.length<1) {
  179. basicModal.error('password');
  180. return false;
  181. }
  182. basicModal.close();
  183. params = {
  184. oldPassword: md5(oldPassword),
  185. username,
  186. password: md5(password)
  187. }
  188. api.post('setLogin', params, function(data) {
  189. if (data!==true) lychee.error(null, params, data);
  190. });
  191. }
  192. msg = `
  193. <p>
  194. Enter your current password:
  195. <input data-name='oldPassword' class='text' type='password' placeholder='Current Password' value=''>
  196. </p>
  197. <p>
  198. Your username and password will be changed to the following:
  199. <input data-name='username' class='text' type='text' placeholder='New Username' value=''>
  200. <input data-name='password' class='text' type='password' placeholder='New Password' value=''>
  201. </p>
  202. `
  203. basicModal.show({
  204. body: msg,
  205. buttons: {
  206. action: {
  207. title: 'Change Login',
  208. fn: action
  209. },
  210. cancel: {
  211. title: 'Cancel',
  212. fn: basicModal.close
  213. }
  214. }
  215. });
  216. }
  217. settings.setSorting = function() {
  218. var sorting = [],
  219. action,
  220. msg = '';
  221. action = function() {
  222. var params;
  223. sorting[0] = $('.basicModal select#settings_type').val();
  224. sorting[1] = $('.basicModal select#settings_order').val();
  225. basicModal.close();
  226. albums.refresh();
  227. params = {
  228. type: sorting[0],
  229. order: sorting[1]
  230. }
  231. api.post('setSorting', params, function(data) {
  232. if (data===true) {
  233. lychee.sorting = 'ORDER BY ' + sorting[0] + ' ' + sorting[1];
  234. lychee.load();
  235. } else lychee.error(null, params, data);
  236. });
  237. }
  238. msg = `
  239. <p>
  240. Sort photos by
  241. <select id='settings_type'>
  242. <option value='id'>Upload Time</option>
  243. <option value='takestamp'>Take Date</option>
  244. <option value='title'>Title</option>
  245. <option value='description'>Description</option>
  246. <option value='public'>Public</option>
  247. <option value='star'>Star</option>
  248. <option value='type'>Photo Format</option>
  249. </select>
  250. in an
  251. <select id='settings_order'>
  252. <option value='ASC'>Ascending</option>
  253. <option value='DESC'>Descending</option>
  254. </select>
  255. order.
  256. </p>
  257. `
  258. basicModal.show({
  259. body: msg,
  260. buttons: {
  261. action: {
  262. title: 'Change Sorting',
  263. fn: action
  264. },
  265. cancel: {
  266. title: 'Cancel',
  267. fn: basicModal.close
  268. }
  269. }
  270. });
  271. if (lychee.sorting!=='') {
  272. sorting = lychee.sorting.replace('ORDER BY ', '').split(' ');
  273. $('.basicModal select#settings_type').val(sorting[0]);
  274. $('.basicModal select#settings_order').val(sorting[1]);
  275. }
  276. }
  277. settings.setDropboxKey = function(callback) {
  278. var action,
  279. msg = "";
  280. action = function(data) {
  281. var key = data.key;
  282. if (data.key.length<1) {
  283. basicModal.error('key');
  284. return false;
  285. }
  286. basicModal.close();
  287. api.post('setDropboxKey', { key }, function(data) {
  288. if (data===true) {
  289. lychee.dropboxKey = key;
  290. if (callback) lychee.loadDropbox(callback);
  291. } else lychee.error(null, params, data);
  292. });
  293. }
  294. msg = `
  295. <p>
  296. 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:
  297. <input class='text' data-name='key' type='text' placeholder='Dropbox API Key' value='${ lychee.dropboxKey }'>
  298. </p>
  299. `
  300. basicModal.show({
  301. body: msg,
  302. buttons: {
  303. action: {
  304. title: 'Set Dropbox Key',
  305. fn: action
  306. },
  307. cancel: {
  308. title: 'Cancel',
  309. fn: basicModal.close
  310. }
  311. }
  312. });
  313. }