| 
									
										
										
										
											2020-01-20 22:35:52 +01:00
										 |  |  | import TabAwareWidget from "./tab_aware_widget.js"; | 
					
						
							| 
									
										
										
										
											2020-01-19 13:19:40 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | const TPL = `
 | 
					
						
							|  |  |  | <div class="dropdown note-actions"> | 
					
						
							|  |  |  |     <button type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="btn btn-sm dropdown-toggle"> | 
					
						
							|  |  |  |         Note actions | 
					
						
							|  |  |  |         <span class="caret"></span> | 
					
						
							|  |  |  |     </button> | 
					
						
							|  |  |  |     <div class="dropdown-menu dropdown-menu-right"> | 
					
						
							| 
									
										
										
										
											2020-01-21 22:08:41 +01:00
										 |  |  |         <a data-trigger-event="showNoteRevisions" class="dropdown-item show-note-revisions-button">Revisions</a> | 
					
						
							|  |  |  |         <a data-trigger-event="showAttributes" class="dropdown-item show-attributes-button"><kbd data-kb-action="ShowAttributes"></kbd> Attributes</a> | 
					
						
							|  |  |  |         <a data-trigger-event="showLinkMap" class="dropdown-item show-link-map-button"><kbd data-kb-action="ShowLinkMap"></kbd> Link map</a> | 
					
						
							|  |  |  |         <a data-trigger-event="showNoteSource" class="dropdown-item show-source-button"><kbd data-kb-action="ShowNoteSource"></kbd> Note source</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-01-21 22:08:41 +01:00
										 |  |  |         <a data-trigger-event="printActiveNote" class="dropdown-item print-note-button"><kbd data-kb-action="PrintActiveNote"></kbd> Print note</a> | 
					
						
							|  |  |  |         <a data-trigger-event="showNoteInfo" class="dropdown-item show-note-info-button"><kbd data-kb-action="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-01-20 22:35:52 +01:00
										 |  |  |         this.$showSourceButton = this.$widget.find('.show-source-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'); | 
					
						
							|  |  |  |         this.$importNoteButton.on("click", () => import('../dialogs/import.js').then(d => d.showDialog(this.tabContext.note.noteId))); | 
					
						
							| 
									
										
										
										
											2020-01-20 22:35:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-19 13:19:40 +01:00
										 |  |  |         return this.$widget; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-01-20 22:35:52 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     refreshWithNote(note) { | 
					
						
							|  |  |  |         this.$showSourceButton.prop('disabled', !['text', 'relation-map', 'search', 'code'].includes(note.type)); | 
					
						
							|  |  |  |         this.$exportNoteButton.prop('disabled', note.type !== 'text'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     triggerEvent(e, eventName) { | 
					
						
							|  |  |  |         const $item = $(e.target).closest('dropdown-item'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if ($item.is('[disabled]')) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.trigger(eventName); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-01-19 13:19:40 +01:00
										 |  |  | } |