| 
									
										
										
										
											2020-01-20 22:35:52 +01:00
										 |  |  | import TabAwareWidget from "./tab_aware_widget.js"; | 
					
						
							| 
									
										
										
										
											2020-04-29 00:01:07 +02:00
										 |  |  | import protectedSessionService from "../services/protected_session.js"; | 
					
						
							| 
									
										
										
										
											2021-04-24 22:18:25 +02:00
										 |  |  | import utils from "../services/utils.js"; | 
					
						
							| 
									
										
										
										
											2020-01-19 13:19:40 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | const TPL = `
 | 
					
						
							|  |  |  | <div class="dropdown note-actions"> | 
					
						
							| 
									
										
										
										
											2020-02-27 00:58:10 +01:00
										 |  |  |     <style> | 
					
						
							|  |  |  |     .note-actions .dropdown-menu { | 
					
						
							| 
									
										
										
										
											2021-04-24 21:56:44 +02:00
										 |  |  |         width: 20em; | 
					
						
							| 
									
										
										
										
											2020-02-27 00:58:10 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-03-25 11:28:44 +01:00
										 |  |  |      | 
					
						
							|  |  |  |     .note-actions .dropdown-item[disabled], .note-actions .dropdown-item[disabled]:hover { | 
					
						
							|  |  |  |         color: var(--muted-text-color) !important; | 
					
						
							|  |  |  |         background-color: transparent !important; | 
					
						
							| 
									
										
										
										
											2020-03-29 22:15:09 +02:00
										 |  |  |         pointer-events: none; /* makes it unclickable */ | 
					
						
							| 
									
										
										
										
											2020-03-25 11:28:44 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-04-29 00:01:07 +02:00
										 |  |  |      | 
					
						
							|  |  |  |     /* The switch - the box around the slider */ | 
					
						
							|  |  |  |     .switch { | 
					
						
							|  |  |  |         position: relative; | 
					
						
							|  |  |  |         display: inline-block; | 
					
						
							|  |  |  |         width: 50px; | 
					
						
							|  |  |  |         height: 24px; | 
					
						
							|  |  |  |         float: right; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     /* The slider */ | 
					
						
							|  |  |  |     .slider { | 
					
						
							|  |  |  |         border-radius: 24px; | 
					
						
							|  |  |  |         position: absolute; | 
					
						
							|  |  |  |         cursor: pointer; | 
					
						
							|  |  |  |         top: 0; | 
					
						
							|  |  |  |         left: 0; | 
					
						
							|  |  |  |         right: 0; | 
					
						
							|  |  |  |         bottom: 0; | 
					
						
							|  |  |  |         background-color: var(--more-accented-background-color); | 
					
						
							|  |  |  |         transition: .4s; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     .slider:before { | 
					
						
							|  |  |  |         border-radius: 50%; | 
					
						
							|  |  |  |         position: absolute; | 
					
						
							|  |  |  |         content: ""; | 
					
						
							|  |  |  |         height: 16px; | 
					
						
							|  |  |  |         width: 16px; | 
					
						
							|  |  |  |         left: 4px; | 
					
						
							|  |  |  |         bottom: 4px; | 
					
						
							|  |  |  |         background-color: var(--main-background-color); | 
					
						
							|  |  |  |         -webkit-transition: .4s; | 
					
						
							|  |  |  |         transition: .4s; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     .slider.checked { | 
					
						
							|  |  |  |         background-color: var(--main-text-color); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     .slider.checked:before { | 
					
						
							|  |  |  |         transform: translateX(26px); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-02-27 00:58:10 +01:00
										 |  |  |     </style> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-19 13:19:40 +01:00
										 |  |  |     <button type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="btn btn-sm dropdown-toggle"> | 
					
						
							| 
									
										
										
										
											2021-02-13 21:52:31 +01:00
										 |  |  |         Actions | 
					
						
							| 
									
										
										
										
											2020-01-19 13:19:40 +01:00
										 |  |  |         <span class="caret"></span> | 
					
						
							|  |  |  |     </button> | 
					
						
							|  |  |  |     <div class="dropdown-menu dropdown-menu-right"> | 
					
						
							| 
									
										
										
										
											2021-03-20 00:00:49 +01:00
										 |  |  |         <a data-trigger-command="renderActiveNote" class="dropdown-item render-note-button"><kbd data-command="renderActiveNote"></kbd> Re-render note</a> | 
					
						
							| 
									
										
										
										
											2020-04-29 00:01:07 +02:00
										 |  |  |         <div class="dropdown-item protect-button"> | 
					
						
							|  |  |  |             Protect the note | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  |             <span title="Note is not protected, click to make it protected"> | 
					
						
							|  |  |  |                 <label class="switch"> | 
					
						
							|  |  |  |                 <span class="slider"></span> | 
					
						
							|  |  |  |             </span> | 
					
						
							|  |  |  |         </div> | 
					
						
							|  |  |  |         <div class="dropdown-item unprotect-button"> | 
					
						
							|  |  |  |             Unprotect the note | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  |             <span title="Note is protected, click to make it unprotected"> | 
					
						
							|  |  |  |                 <label class="switch"> | 
					
						
							|  |  |  |                 <span class="slider checked"></span> | 
					
						
							|  |  |  |             </span> | 
					
						
							|  |  |  |         </div> | 
					
						
							| 
									
										
										
										
											2020-08-14 20:58:19 +02:00
										 |  |  |         <a data-trigger-command="findInText" class="dropdown-item">Search in note <kbd data-command="findInText"></a> | 
					
						
							| 
									
										
										
										
											2020-02-29 14:32:26 +01:00
										 |  |  |         <a data-trigger-command="showNoteRevisions" class="dropdown-item show-note-revisions-button">Revisions</a> | 
					
						
							|  |  |  |         <a data-trigger-command="showLinkMap" class="dropdown-item show-link-map-button"><kbd data-command="showLinkMap"></kbd> Link map</a> | 
					
						
							|  |  |  |         <a data-trigger-command="showNoteSource" class="dropdown-item show-source-button"><kbd data-command="showNoteSource"></kbd> Note source</a> | 
					
						
							| 
									
										
										
										
											2021-04-24 21:56:44 +02:00
										 |  |  |         <a data-trigger-command="openNoteExternally" class="dropdown-item open-note-externally-button"><kbd data-command="openNoteExternally"></kbd> Open note externally</a> | 
					
						
							| 
									
										
										
										
											2020-01-19 13:19:40 +01:00
										 |  |  |         <a class="dropdown-item import-files-button">Import files</a> | 
					
						
							| 
									
										
										
										
											2020-01-20 22:35:52 +01:00
										 |  |  |         <a class="dropdown-item export-note-button">Export note</a> | 
					
						
							| 
									
										
										
										
											2020-02-29 14:32:26 +01:00
										 |  |  |         <a data-trigger-command="printActiveNote" class="dropdown-item print-note-button"><kbd data-command="printActiveNote"></kbd> Print note</a> | 
					
						
							|  |  |  |         <a data-trigger-command="showNoteInfo" class="dropdown-item show-note-info-button"><kbd data-command="showNoteInfo"></kbd> Note info</a> | 
					
						
							| 
									
										
										
										
											2020-01-19 13:19:40 +01:00
										 |  |  |     </div> | 
					
						
							|  |  |  | </div>`; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-20 22:35:52 +01:00
										 |  |  | export default class NoteActionsWidget extends TabAwareWidget { | 
					
						
							| 
									
										
										
										
											2020-01-19 13:19:40 +01:00
										 |  |  |     doRender() { | 
					
						
							|  |  |  |         this.$widget = $(TPL); | 
					
						
							| 
									
										
										
										
											2020-08-17 20:58:34 +02:00
										 |  |  |         this.overflowing(); | 
					
						
							| 
									
										
										
										
											2020-01-19 13:19:40 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-20 22:35:52 +01:00
										 |  |  |         this.$showSourceButton = this.$widget.find('.show-source-button'); | 
					
						
							| 
									
										
										
										
											2021-03-19 22:34:56 +01:00
										 |  |  |         this.$renderNoteButton = this.$widget.find('.render-note-button'); | 
					
						
							| 
									
										
										
										
											2020-01-21 21:43:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-20 22:35:52 +01:00
										 |  |  |         this.$exportNoteButton = this.$widget.find('.export-note-button'); | 
					
						
							| 
									
										
										
										
											2020-01-21 21:43:23 +01:00
										 |  |  |         this.$exportNoteButton.on("click", () => { | 
					
						
							|  |  |  |             if (this.$exportNoteButton.hasClass("disabled")) { | 
					
						
							|  |  |  |                 return; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             import('../dialogs/export.js').then(d => d.showDialog(this.tabContext.notePath, 'single')); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.$importNoteButton = this.$widget.find('.import-files-button'); | 
					
						
							| 
									
										
										
										
											2020-02-03 21:56:45 +01:00
										 |  |  |         this.$importNoteButton.on("click", () => import('../dialogs/import.js').then(d => d.showDialog(this.noteId))); | 
					
						
							| 
									
										
										
										
											2020-01-20 22:35:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-29 00:01:07 +02:00
										 |  |  |         this.$protectButton = this.$widget.find(".protect-button"); | 
					
						
							|  |  |  |         this.$protectButton.on('click', () => protectedSessionService.protectNote(this.noteId, true, false)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.$unprotectButton = this.$widget.find(".unprotect-button"); | 
					
						
							|  |  |  |         this.$unprotectButton.on('click', () => protectedSessionService.protectNote(this.noteId, false, false)); | 
					
						
							| 
									
										
										
										
											2020-08-28 14:52:38 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         this.$widget.on('click', '.dropdown-item', | 
					
						
							|  |  |  |             () => this.$widget.find('.dropdown-toggle').dropdown('toggle')); | 
					
						
							| 
									
										
										
										
											2021-04-24 21:56:44 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         this.$openNoteExternallyButton = this.$widget.find(".open-note-externally-button"); | 
					
						
							| 
									
										
										
										
											2020-01-19 13:19:40 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-01-20 22:35:52 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     refreshWithNote(note) { | 
					
						
							| 
									
										
										
										
											2021-03-19 22:34:56 +01:00
										 |  |  |         this.toggleDisabled(this.$showSourceButton, ['text', 'relation-map', 'search', 'code'].includes(note.type)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.$renderNoteButton.toggle(note.type === 'render'); | 
					
						
							| 
									
										
										
										
											2020-03-25 11:28:44 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-29 00:01:07 +02:00
										 |  |  |         this.$protectButton.toggle(!note.isProtected); | 
					
						
							|  |  |  |         this.$unprotectButton.toggle(!!note.isProtected); | 
					
						
							| 
									
										
										
										
											2021-04-24 22:18:25 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         this.$openNoteExternallyButton.toggle(utils.isElectron()); | 
					
						
							| 
									
										
										
										
											2020-04-29 00:01:07 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-19 22:34:56 +01:00
										 |  |  |     toggleDisabled($el, enable) { | 
					
						
							|  |  |  |         if (enable) { | 
					
						
							|  |  |  |             $el.removeAttr('disabled'); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $el.attr('disabled', 'disabled'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-29 00:01:07 +02:00
										 |  |  |     entitiesReloadedEvent({loadResults}) { | 
					
						
							|  |  |  |         if (loadResults.isNoteReloaded(this.noteId)) { | 
					
						
							|  |  |  |             this.refresh(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-01-20 22:35:52 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-07-03 22:27:45 +02:00
										 |  |  | } |