settings.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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 = '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 = `
  78. <p>
  79. Enter your database connection details below:
  80. <input data-name='dbHost' class='text' type='text' placeholder='Database Host (optional)' value=''>
  81. <input data-name='dbUser' class='text' type='text' placeholder='Database Username' value=''>
  82. <input data-name='dbPassword' class='text' type='password' placeholder='Database Password' value=''>
  83. </p>
  84. <p>
  85. Lychee will create its own database. If required, you can enter the name of an existing database instead:
  86. <input data-name='dbName' class='text' type='text' placeholder='Database Name (optional)' value=''>
  87. <input data-name='dbTablePrefix' class='text' type='text' placeholder='Table prefix (optional)' value=''>
  88. </p>
  89. `
  90. basicModal.show({
  91. body: msg,
  92. buttons: {
  93. action: {
  94. title: 'Connect',
  95. fn: action
  96. }
  97. }
  98. });
  99. }
  100. settings.createLogin = function() {
  101. var action,
  102. msg = '';
  103. action = function(data) {
  104. var params,
  105. username = data.username,
  106. password = data.password;
  107. if (username.length<1) {
  108. basicModal.error('username');
  109. return false;
  110. }
  111. if (password.length<1) {
  112. basicModal.error('password');
  113. return false;
  114. }
  115. basicModal.close();
  116. params = 'setLogin&username=' + escape(username) + '&password=' + md5(password);
  117. lychee.api(params, function(data) {
  118. if (data!==true) {
  119. basicModal.show({
  120. body: '<p>Unable to save login. Please try again with another username and password!</p>',
  121. buttons: {
  122. action: {
  123. title: 'Retry',
  124. fn: settings.createLogin
  125. }
  126. }
  127. });
  128. }
  129. });
  130. }
  131. msg = `
  132. <p>
  133. Enter a username and password for your installation:
  134. <input data-name='username' class='text' type='text' placeholder='New Username' value=''>
  135. <input data-name='password' class='text' type='password' placeholder='New Password' value=''>
  136. </p>
  137. `
  138. basicModal.show({
  139. body: msg,
  140. buttons: {
  141. action: {
  142. title: 'Create Login',
  143. fn: action
  144. }
  145. }
  146. });
  147. }
  148. settings.setLogin = function() {
  149. var msg = '',
  150. action;
  151. action = function(data) {
  152. var oldPassword = data.oldPassword || '',
  153. username = data.username || '',
  154. password = data.password || '',
  155. params;
  156. if (oldPassword.length<1) {
  157. basicModal.error('oldPassword');
  158. return false;
  159. }
  160. if (username.length<1) {
  161. basicModal.error('username');
  162. return false;
  163. }
  164. if (password.length<1) {
  165. basicModal.error('password');
  166. return false;
  167. }
  168. basicModal.close();
  169. params = 'setLogin&oldPassword=' + md5(oldPassword) + '&username=' + escape(username) + '&password=' + md5(password);
  170. lychee.api(params, function(data) {
  171. if (data!==true) lychee.error(null, params, data);
  172. });
  173. }
  174. msg = `
  175. <p>
  176. Enter your current password:
  177. <input data-name='oldPassword' class='text' type='password' placeholder='Current Password' value=''>
  178. </p>
  179. <p>
  180. Your username and password will be changed to the following:
  181. <input data-name='username' class='text' type='text' placeholder='New Username' value=''>
  182. <input data-name='password' class='text' type='password' placeholder='New Password' value=''>
  183. </p>
  184. `
  185. basicModal.show({
  186. body: msg,
  187. buttons: {
  188. action: {
  189. title: 'Change Login',
  190. fn: action
  191. },
  192. cancel: {
  193. title: 'Cancel',
  194. fn: basicModal.close
  195. }
  196. }
  197. });
  198. }
  199. settings.setSorting = function() {
  200. var sorting = [],
  201. action,
  202. msg = '';
  203. action = function() {
  204. var params;
  205. sorting[0] = $('.basicModal select#settings_type').val();
  206. sorting[1] = $('.basicModal select#settings_order').val();
  207. basicModal.close();
  208. albums.refresh();
  209. params = 'setSorting&type=' + sorting[0] + '&order=' + sorting[1];
  210. lychee.api(params, function(data) {
  211. if (data===true) {
  212. lychee.sorting = 'ORDER BY ' + sorting[0] + ' ' + sorting[1];
  213. lychee.load();
  214. } else lychee.error(null, params, data);
  215. });
  216. }
  217. msg = `
  218. <p>
  219. Sort photos by
  220. <select id='settings_type'>
  221. <option value='id'>Upload Time</option>
  222. <option value='takestamp'>Take Date</option>
  223. <option value='title'>Title</option>
  224. <option value='description'>Description</option>
  225. <option value='public'>Public</option>
  226. <option value='star'>Star</option>
  227. <option value='type'>Photo Format</option>
  228. </select>
  229. in an
  230. <select id='settings_order'>
  231. <option value='ASC'>Ascending</option>
  232. <option value='DESC'>Descending</option>
  233. </select>
  234. order.
  235. </p>
  236. `
  237. basicModal.show({
  238. body: msg,
  239. buttons: {
  240. action: {
  241. title: 'Change Sorting',
  242. fn: action
  243. },
  244. cancel: {
  245. title: 'Cancel',
  246. fn: basicModal.close
  247. }
  248. }
  249. });
  250. if (lychee.sorting!=='') {
  251. sorting = lychee.sorting.replace('ORDER BY ', '').split(' ');
  252. $('.basicModal select#settings_type').val(sorting[0]);
  253. $('.basicModal select#settings_order').val(sorting[1]);
  254. }
  255. }
  256. settings.setDropboxKey = function(callback) {
  257. var action,
  258. msg = "";
  259. action = function(data) {
  260. var params,
  261. key = data.key;
  262. if (data.key.length<1) {
  263. basicModal.error('key');
  264. return false;
  265. }
  266. basicModal.close();
  267. params = 'setDropboxKey&key=' + key;
  268. lychee.api(params, function(data) {
  269. if (data===true) {
  270. lychee.dropboxKey = key;
  271. if (callback) lychee.loadDropbox(callback);
  272. } else lychee.error(null, params, data);
  273. });
  274. }
  275. msg = `
  276. <p>
  277. 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:
  278. <input class='text' data-name='key' type='text' placeholder='Dropbox API Key' value='${ lychee.dropboxKey }'>
  279. </p>
  280. `
  281. basicModal.show({
  282. body: msg,
  283. buttons: {
  284. action: {
  285. title: 'Set Dropbox Key',
  286. fn: action
  287. },
  288. cancel: {
  289. title: 'Cancel',
  290. fn: basicModal.close
  291. }
  292. }
  293. });
  294. }