| 
									
										
										
										
											2017-11-04 19:38:50 -04:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 21:16:57 -04:00
										 |  |  | import protectedSessionHolder from '../services/protected_session_holder.js'; | 
					
						
							| 
									
										
										
										
											2018-03-25 13:02:39 -04:00
										 |  |  | import server from '../services/server.js'; | 
					
						
							| 
									
										
										
										
											2018-03-25 21:29:35 -04:00
										 |  |  | import infoService from "../services/info.js"; | 
					
						
							| 
									
										
										
										
											2018-06-08 23:18:53 -04:00
										 |  |  | import zoomService from "../services/zoom.js"; | 
					
						
							| 
									
										
										
										
											2018-06-09 10:34:51 -04:00
										 |  |  | import utils from "../services/utils.js"; | 
					
						
							| 
									
										
										
										
											2019-01-27 21:18:11 +01:00
										 |  |  | import cssLoader from "../services/css_loader.js"; | 
					
						
							| 
									
										
										
										
											2019-05-12 21:45:30 +02:00
										 |  |  | import optionsInit from "../services/options_init.js"; | 
					
						
							| 
									
										
										
										
											2017-09-12 23:04:17 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-01 17:41:28 -04:00
										 |  |  | const $dialog = $("#options-dialog"); | 
					
						
							| 
									
										
										
										
											2017-11-04 14:31:53 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 22:42:46 -04:00
										 |  |  | const tabHandlers = []; | 
					
						
							| 
									
										
										
										
											2017-09-10 23:10:32 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 22:42:46 -04:00
										 |  |  | function addTabHandler(handler) { | 
					
						
							|  |  |  |     tabHandlers.push(handler); | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-11-04 17:03:15 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  | async function showDialog() { | 
					
						
							|  |  |  |     glob.activeDialog = $dialog; | 
					
						
							| 
									
										
										
										
											2017-09-10 23:10:32 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-01 17:41:28 -04:00
										 |  |  |     const options = await server.get('options'); | 
					
						
							| 
									
										
										
										
											2017-09-12 22:23:57 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 17:47:40 +01:00
										 |  |  |     $dialog.modal(); | 
					
						
							| 
									
										
										
										
											2017-09-12 22:23:57 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 22:42:46 -04:00
										 |  |  |     for (const handler of tabHandlers) { | 
					
						
							| 
									
										
										
										
											2018-04-01 17:41:28 -04:00
										 |  |  |         if (handler.optionsLoaded) { | 
					
						
							|  |  |  |             handler.optionsLoaded(options); | 
					
						
							| 
									
										
										
										
											2017-11-04 14:31:53 -04:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-11-04 14:31:53 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-22 22:21:16 +02:00
										 |  |  | async function saveOptions(options) { | 
					
						
							|  |  |  |     await server.put('options', options); | 
					
						
							| 
									
										
										
										
											2017-11-28 20:52:38 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-01 17:41:28 -04:00
										 |  |  |     infoService.showMessage("Options change have been saved."); | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-11-04 14:31:53 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  | export default { | 
					
						
							|  |  |  |     showDialog, | 
					
						
							| 
									
										
										
										
											2018-04-01 17:41:28 -04:00
										 |  |  |     saveOptions | 
					
						
							| 
									
										
										
										
											2018-03-25 11:09:17 -04:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2017-11-04 14:31:53 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-08 23:18:53 -04:00
										 |  |  | addTabHandler((function() { | 
					
						
							|  |  |  |     const $themeSelect = $("#theme-select"); | 
					
						
							|  |  |  |     const $zoomFactorSelect = $("#zoom-factor-select"); | 
					
						
							| 
									
										
										
										
											2019-05-12 21:45:30 +02:00
										 |  |  |     const $oneTabDisplaySelect = $("#one-tab-display-select"); | 
					
						
							| 
									
										
										
										
											2018-09-06 11:17:30 +02:00
										 |  |  |     const $leftPaneMinWidth = $("#left-pane-min-width"); | 
					
						
							|  |  |  |     const $leftPaneWidthPercent = $("#left-pane-width-percent"); | 
					
						
							| 
									
										
										
										
											2019-01-13 22:03:06 +01:00
										 |  |  |     const $mainFontSize = $("#main-font-size"); | 
					
						
							|  |  |  |     const $treeFontSize = $("#tree-font-size"); | 
					
						
							|  |  |  |     const $detailFontSize = $("#detail-font-size"); | 
					
						
							|  |  |  |     const $body = $("body"); | 
					
						
							| 
									
										
										
										
											2018-09-06 11:54:04 +02:00
										 |  |  |     const $container = $("#container"); | 
					
						
							| 
									
										
										
										
											2018-06-08 23:18:53 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-27 21:18:11 +01:00
										 |  |  |     async function optionsLoaded(options) { | 
					
						
							|  |  |  |         const themes = [ | 
					
						
							|  |  |  |             { val: 'white', title: 'White' }, | 
					
						
							|  |  |  |             { val: 'dark', title: 'Dark' }, | 
					
						
							|  |  |  |             { val: 'black', title: 'Black' } | 
					
						
							|  |  |  |         ].concat(await server.get('options/user-themes')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $themeSelect.empty(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (const theme of themes) { | 
					
						
							|  |  |  |             $themeSelect.append($("<option>") | 
					
						
							|  |  |  |                 .attr("value", theme.val) | 
					
						
							|  |  |  |                 .attr("data-note-id", theme.noteId) | 
					
						
							|  |  |  |                 .html(theme.title)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-08 23:18:53 -04:00
										 |  |  |         $themeSelect.val(options.theme); | 
					
						
							| 
									
										
										
										
											2018-06-09 10:34:51 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (utils.isElectron()) { | 
					
						
							|  |  |  |             $zoomFactorSelect.val(options.zoomFactor); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             $zoomFactorSelect.prop('disabled', true); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-09-06 11:17:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-12 21:45:30 +02:00
										 |  |  |         $oneTabDisplaySelect.val(options.hideTabRowForOneTab === 'true' ? 'hide' : 'show'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 11:17:30 +02:00
										 |  |  |         $leftPaneMinWidth.val(options.leftPaneMinWidth); | 
					
						
							|  |  |  |         $leftPaneWidthPercent.val(options.leftPaneWidthPercent); | 
					
						
							| 
									
										
										
										
											2019-01-13 22:03:06 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $mainFontSize.val(options.mainFontSize); | 
					
						
							|  |  |  |         $treeFontSize.val(options.treeFontSize); | 
					
						
							|  |  |  |         $detailFontSize.val(options.detailFontSize); | 
					
						
							| 
									
										
										
										
											2018-06-08 23:18:53 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $themeSelect.change(function() { | 
					
						
							|  |  |  |         const newTheme = $(this).val(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-28 21:42:37 +01:00
										 |  |  |         for (const clazz of Array.from($body[0].classList)) { // create copy to safely iterate over while removing classes
 | 
					
						
							| 
									
										
										
										
											2019-01-13 22:03:06 +01:00
										 |  |  |             if (clazz.startsWith("theme-")) { | 
					
						
							|  |  |  |                 $body.removeClass(clazz); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-27 21:18:11 +01:00
										 |  |  |         const noteId = $(this).find(":selected").attr("data-note-id"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (noteId) { | 
					
						
							|  |  |  |             // make sure the CSS is loaded
 | 
					
						
							|  |  |  |             // if the CSS has been loaded and then updated then the changes won't take effect though
 | 
					
						
							| 
									
										
										
										
											2019-01-27 22:34:41 +01:00
										 |  |  |             cssLoader.requireCss(`/api/notes/download/${noteId}`); | 
					
						
							| 
									
										
										
										
											2019-01-27 21:18:11 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-13 22:03:06 +01:00
										 |  |  |         $body.addClass("theme-" + newTheme); | 
					
						
							| 
									
										
										
										
											2018-06-08 23:18:53 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         server.put('options/theme/' + newTheme); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-13 22:03:06 +01:00
										 |  |  |     $zoomFactorSelect.change(function() { zoomService.setZoomFactorAndSave($(this).val()); }); | 
					
						
							| 
									
										
										
										
											2018-06-08 23:18:53 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 11:54:04 +02:00
										 |  |  |     function resizeLeftPanel() { | 
					
						
							|  |  |  |         const leftPanePercent = parseInt($leftPaneWidthPercent.val()); | 
					
						
							|  |  |  |         const rightPanePercent = 100 - leftPanePercent; | 
					
						
							|  |  |  |         const leftPaneMinWidth = $leftPaneMinWidth.val(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $container.css("grid-template-columns", `minmax(${leftPaneMinWidth}px, ${leftPanePercent}fr) ${rightPanePercent}fr`); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-12 21:45:30 +02:00
										 |  |  |     $oneTabDisplaySelect.change(function() { | 
					
						
							|  |  |  |         const hideTabRowForOneTab = $(this).val() === 'hide' ? 'true' : 'false'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         server.put('options/hideTabRowForOneTab/' + hideTabRowForOneTab) | 
					
						
							|  |  |  |             .then(optionsInit.loadOptions); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-13 22:03:06 +01:00
										 |  |  |     $leftPaneMinWidth.change(async function() { | 
					
						
							|  |  |  |         await server.put('options/leftPaneMinWidth/' + $(this).val()); | 
					
						
							| 
									
										
										
										
											2018-09-06 11:17:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 11:54:04 +02:00
										 |  |  |         resizeLeftPanel(); | 
					
						
							| 
									
										
										
										
											2018-09-06 11:17:30 +02:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-13 22:03:06 +01:00
										 |  |  |     $leftPaneWidthPercent.change(async function() { | 
					
						
							|  |  |  |         await server.put('options/leftPaneWidthPercent/' + $(this).val()); | 
					
						
							| 
									
										
										
										
											2018-09-06 11:17:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 11:54:04 +02:00
										 |  |  |         resizeLeftPanel(); | 
					
						
							| 
									
										
										
										
											2019-01-13 22:03:06 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function applyFontSizes() { | 
					
						
							|  |  |  |         console.log($mainFontSize.val() + "% !important"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $body.get(0).style.setProperty("--main-font-size", $mainFontSize.val() + "%"); | 
					
						
							|  |  |  |         $body.get(0).style.setProperty("--tree-font-size", $treeFontSize.val() + "%"); | 
					
						
							|  |  |  |         $body.get(0).style.setProperty("--detail-font-size", $detailFontSize.val() + "%"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $mainFontSize.change(async function() { | 
					
						
							|  |  |  |         await server.put('options/mainFontSize/' + $(this).val()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         applyFontSizes(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $treeFontSize.change(async function() { | 
					
						
							|  |  |  |         await server.put('options/treeFontSize/' + $(this).val()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         applyFontSizes(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $detailFontSize.change(async function() { | 
					
						
							|  |  |  |         await server.put('options/detailFontSize/' + $(this).val()); | 
					
						
							| 
									
										
										
										
											2018-09-06 11:54:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-13 22:03:06 +01:00
										 |  |  |         applyFontSizes(); | 
					
						
							| 
									
										
										
										
											2018-09-06 11:17:30 +02:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-08 23:18:53 -04:00
										 |  |  |     return { | 
					
						
							|  |  |  |         optionsLoaded | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | })()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 22:42:46 -04:00
										 |  |  | addTabHandler((function() { | 
					
						
							| 
									
										
										
										
											2018-02-10 08:44:34 -05:00
										 |  |  |     const $form = $("#change-password-form"); | 
					
						
							|  |  |  |     const $oldPassword = $("#old-password"); | 
					
						
							|  |  |  |     const $newPassword1 = $("#new-password1"); | 
					
						
							|  |  |  |     const $newPassword2 = $("#new-password2"); | 
					
						
							| 
									
										
										
										
											2017-11-04 14:31:53 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-01 17:41:28 -04:00
										 |  |  |     function optionsLoaded(options) { | 
					
						
							| 
									
										
										
										
											2017-09-12 22:23:57 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-10 08:44:34 -05:00
										 |  |  |     $form.submit(() => { | 
					
						
							|  |  |  |         const oldPassword = $oldPassword.val(); | 
					
						
							|  |  |  |         const newPassword1 = $newPassword1.val(); | 
					
						
							|  |  |  |         const newPassword2 = $newPassword2.val(); | 
					
						
							| 
									
										
										
										
											2017-11-04 14:31:53 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-10 08:44:34 -05:00
										 |  |  |         $oldPassword.val(''); | 
					
						
							|  |  |  |         $newPassword1.val(''); | 
					
						
							|  |  |  |         $newPassword2.val(''); | 
					
						
							| 
									
										
										
										
											2017-11-04 14:31:53 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (newPassword1 !== newPassword2) { | 
					
						
							|  |  |  |             alert("New passwords are not the same."); | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-28 20:52:38 -05:00
										 |  |  |         server.post('password/change', { | 
					
						
							|  |  |  |             'current_password': oldPassword, | 
					
						
							|  |  |  |             'new_password': newPassword1 | 
					
						
							|  |  |  |         }).then(result => { | 
					
						
							|  |  |  |             if (result.success) { | 
					
						
							|  |  |  |                 alert("Password has been changed. Trilium will be reloaded after you press OK."); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 // password changed so current protected session is invalid and needs to be cleared
 | 
					
						
							| 
									
										
										
										
											2018-03-25 21:16:57 -04:00
										 |  |  |                 protectedSessionHolder.resetProtectedSession(); | 
					
						
							| 
									
										
										
										
											2017-11-28 20:52:38 -05:00
										 |  |  |             } | 
					
						
							|  |  |  |             else { | 
					
						
							| 
									
										
										
										
											2018-03-25 21:29:35 -04:00
										 |  |  |                 infoService.showError(result.message); | 
					
						
							| 
									
										
										
										
											2017-11-28 20:52:38 -05:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2017-11-04 14:31:53 -04:00
										 |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return false; | 
					
						
							| 
									
										
										
										
											2017-09-12 22:23:57 -04:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2017-09-10 23:10:32 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 14:31:53 -04:00
										 |  |  |     return { | 
					
						
							| 
									
										
										
										
											2018-04-01 17:41:28 -04:00
										 |  |  |         optionsLoaded | 
					
						
							| 
									
										
										
										
											2017-11-04 14:31:53 -04:00
										 |  |  |     }; | 
					
						
							|  |  |  | })()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 22:42:46 -04:00
										 |  |  | addTabHandler((function() { | 
					
						
							| 
									
										
										
										
											2018-02-10 08:44:34 -05:00
										 |  |  |     const $form = $("#protected-session-timeout-form"); | 
					
						
							|  |  |  |     const $protectedSessionTimeout = $("#protected-session-timeout-in-seconds"); | 
					
						
							| 
									
										
										
										
											2017-09-12 23:04:17 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-01 17:41:28 -04:00
										 |  |  |     function optionsLoaded(options) { | 
					
						
							| 
									
										
										
										
											2018-07-22 22:21:16 +02:00
										 |  |  |         $protectedSessionTimeout.val(options['protectedSessionTimeout']); | 
					
						
							| 
									
										
										
										
											2017-11-04 14:31:53 -04:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-09-12 23:04:17 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-10 08:44:34 -05:00
										 |  |  |     $form.submit(() => { | 
					
						
							|  |  |  |         const protectedSessionTimeout = $protectedSessionTimeout.val(); | 
					
						
							| 
									
										
										
										
											2017-09-23 10:59:36 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-22 22:21:16 +02:00
										 |  |  |         saveOptions({ 'protectedSessionTimeout': protectedSessionTimeout }).then(() => { | 
					
						
							| 
									
										
										
										
											2019-05-12 21:45:30 +02:00
										 |  |  |             optionsInit.loadOptions(); | 
					
						
							| 
									
										
										
										
											2017-11-04 14:31:53 -04:00
										 |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return false; | 
					
						
							| 
									
										
										
										
											2017-09-12 23:04:17 -04:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 14:31:53 -04:00
										 |  |  |     return { | 
					
						
							| 
									
										
										
										
											2018-04-01 17:41:28 -04:00
										 |  |  |         optionsLoaded | 
					
						
							| 
									
										
										
										
											2017-11-04 14:31:53 -04:00
										 |  |  |     }; | 
					
						
							|  |  |  | })()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 22:42:46 -04:00
										 |  |  | addTabHandler((function () { | 
					
						
							| 
									
										
										
										
											2018-03-25 20:52:38 -04:00
										 |  |  |     const $form = $("#note-revision-snapshot-time-interval-form"); | 
					
						
							|  |  |  |     const $timeInterval = $("#note-revision-snapshot-time-interval-in-seconds"); | 
					
						
							| 
									
										
										
										
											2017-11-04 14:31:53 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-01 17:41:28 -04:00
										 |  |  |     function optionsLoaded(options) { | 
					
						
							| 
									
										
										
										
											2018-07-22 22:21:16 +02:00
										 |  |  |         $timeInterval.val(options['noteRevisionSnapshotTimeInterval']); | 
					
						
							| 
									
										
										
										
											2017-11-04 14:31:53 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-10 08:44:34 -05:00
										 |  |  |     $form.submit(() => { | 
					
						
							| 
									
										
										
										
											2018-07-22 22:21:16 +02:00
										 |  |  |         saveOptions({ 'noteRevisionSnapshotTimeInterval': $timeInterval.val() }); | 
					
						
							| 
									
										
										
										
											2017-11-04 14:31:53 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return false; | 
					
						
							| 
									
										
										
										
											2017-09-24 20:50:14 -04:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 23:35:23 -05:00
										 |  |  |     return { | 
					
						
							| 
									
										
										
										
											2018-04-01 17:41:28 -04:00
										 |  |  |         optionsLoaded | 
					
						
							| 
									
										
										
										
											2017-11-13 23:35:23 -05:00
										 |  |  |     }; | 
					
						
							|  |  |  | })()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-22 22:21:16 +02:00
										 |  |  | addTabHandler((function() { | 
					
						
							|  |  |  |     const $form = $("#sync-setup-form"); | 
					
						
							|  |  |  |     const $syncServerHost = $("#sync-server-host"); | 
					
						
							|  |  |  |     const $syncServerTimeout = $("#sync-server-timeout"); | 
					
						
							|  |  |  |     const $syncProxy = $("#sync-proxy"); | 
					
						
							| 
									
										
										
										
											2018-07-23 10:29:17 +02:00
										 |  |  |     const $testSyncButton = $("#test-sync-button"); | 
					
						
							| 
									
										
										
										
											2018-07-22 22:21:16 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     function optionsLoaded(options) { | 
					
						
							|  |  |  |         $syncServerHost.val(options['syncServerHost']); | 
					
						
							|  |  |  |         $syncServerTimeout.val(options['syncServerTimeout']); | 
					
						
							|  |  |  |         $syncProxy.val(options['syncProxy']); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $form.submit(() => { | 
					
						
							|  |  |  |         saveOptions({ | 
					
						
							|  |  |  |             'syncServerHost': $syncServerHost.val(), | 
					
						
							|  |  |  |             'syncServerTimeout': $syncServerTimeout.val(), | 
					
						
							|  |  |  |             'syncProxy': $syncProxy.val() | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-23 10:29:17 +02:00
										 |  |  |     $testSyncButton.click(async () => { | 
					
						
							|  |  |  |         const result = await server.post('sync/test'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-10 20:05:10 +02:00
										 |  |  |         if (result.success) { | 
					
						
							|  |  |  |             infoService.showMessage(result.message); | 
					
						
							| 
									
										
										
										
											2018-07-23 10:29:17 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							| 
									
										
										
										
											2018-09-11 10:09:55 +02:00
										 |  |  |             infoService.showError("Sync server handshake failed, error: " + result.message); | 
					
						
							| 
									
										
										
										
											2018-07-23 10:29:17 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-22 22:21:16 +02:00
										 |  |  |     return { | 
					
						
							|  |  |  |         optionsLoaded | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | })()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 22:42:46 -04:00
										 |  |  | addTabHandler((async function () { | 
					
						
							| 
									
										
										
										
											2018-02-10 08:44:34 -05:00
										 |  |  |     const $forceFullSyncButton = $("#force-full-sync-button"); | 
					
						
							|  |  |  |     const $fillSyncRowsButton = $("#fill-sync-rows-button"); | 
					
						
							|  |  |  |     const $anonymizeButton = $("#anonymize-button"); | 
					
						
							|  |  |  |     const $cleanupSoftDeletedButton = $("#cleanup-soft-deleted-items-button"); | 
					
						
							|  |  |  |     const $cleanupUnusedImagesButton = $("#cleanup-unused-images-button"); | 
					
						
							|  |  |  |     const $vacuumDatabaseButton = $("#vacuum-database-button"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $forceFullSyncButton.click(async () => { | 
					
						
							| 
									
										
										
										
											2017-12-13 23:03:48 -05:00
										 |  |  |         await server.post('sync/force-full-sync'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 21:29:35 -04:00
										 |  |  |         infoService.showMessage("Full sync triggered"); | 
					
						
							| 
									
										
										
										
											2017-12-13 23:03:48 -05:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-10 08:44:34 -05:00
										 |  |  |     $fillSyncRowsButton.click(async () => { | 
					
						
							| 
									
										
										
										
											2017-12-19 22:04:51 -05:00
										 |  |  |         await server.post('sync/fill-sync-rows'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 21:29:35 -04:00
										 |  |  |         infoService.showMessage("Sync rows filled successfully"); | 
					
						
							| 
									
										
										
										
											2017-12-19 22:04:51 -05:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-16 00:05:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-10 08:44:34 -05:00
										 |  |  |     $anonymizeButton.click(async () => { | 
					
						
							| 
									
										
										
										
											2017-12-16 00:05:37 -05:00
										 |  |  |         await server.post('anonymization/anonymize'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 21:29:35 -04:00
										 |  |  |         infoService.showMessage("Created anonymized database"); | 
					
						
							| 
									
										
										
										
											2017-12-16 00:05:37 -05:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-10 08:44:34 -05:00
										 |  |  |     $cleanupSoftDeletedButton.click(async () => { | 
					
						
							| 
									
										
										
										
											2017-12-23 09:35:00 -05:00
										 |  |  |         if (confirm("Do you really want to clean up soft-deleted items?")) { | 
					
						
							|  |  |  |             await server.post('cleanup/cleanup-soft-deleted-items'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 21:29:35 -04:00
										 |  |  |             infoService.showMessage("Soft deleted items have been cleaned up"); | 
					
						
							| 
									
										
										
										
											2017-12-23 09:35:00 -05:00
										 |  |  |         } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-10 08:44:34 -05:00
										 |  |  |     $cleanupUnusedImagesButton.click(async () => { | 
					
						
							| 
									
										
										
										
											2018-01-07 14:07:59 -05:00
										 |  |  |         if (confirm("Do you really want to clean up unused images?")) { | 
					
						
							|  |  |  |             await server.post('cleanup/cleanup-unused-images'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 21:29:35 -04:00
										 |  |  |             infoService.showMessage("Unused images have been cleaned up"); | 
					
						
							| 
									
										
										
										
											2018-01-07 14:07:59 -05:00
										 |  |  |         } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-10 08:44:34 -05:00
										 |  |  |     $vacuumDatabaseButton.click(async () => { | 
					
						
							| 
									
										
										
										
											2017-12-23 09:35:00 -05:00
										 |  |  |         await server.post('cleanup/vacuum-database'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 21:29:35 -04:00
										 |  |  |         infoService.showMessage("Database has been vacuumed"); | 
					
						
							| 
									
										
										
										
											2017-12-23 09:35:00 -05:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-21 00:25:53 -05:00
										 |  |  |     return {}; | 
					
						
							| 
									
										
										
										
											2017-11-04 14:31:53 -04:00
										 |  |  | })()); |