settings.js 8.2 KB

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