| 
									
										
										
										
											2020-07-03 22:32:39 +01:00
										 |  |  | import CommandService, { CommandRuntime, CommandDeclaration } from '../../../lib/services/CommandService'; | 
					
						
							| 
									
										
										
										
											2020-10-09 18:35:46 +01:00
										 |  |  | import { _ } from 'lib/locale'; | 
					
						
							| 
									
										
										
										
											2020-07-03 22:32:39 +01:00
										 |  |  | const TemplateUtils = require('lib/TemplateUtils'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const declaration:CommandDeclaration = { | 
					
						
							|  |  |  | 	name: 'selectTemplate', | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const runtime = (comp:any):CommandRuntime => { | 
					
						
							|  |  |  | 	return { | 
					
						
							|  |  |  | 		execute: async ({ noteType }:any) => { | 
					
						
							|  |  |  | 			comp.setState({ | 
					
						
							|  |  |  | 				promptOptions: { | 
					
						
							|  |  |  | 					label: _('Template file:'), | 
					
						
							|  |  |  | 					inputType: 'dropdown', | 
					
						
							|  |  |  | 					value: comp.props.templates[0], // Need to start with some value
 | 
					
						
							|  |  |  | 					autocomplete: comp.props.templates, | 
					
						
							|  |  |  | 					onClose: async (answer:any) => { | 
					
						
							|  |  |  | 						if (answer) { | 
					
						
							|  |  |  | 							if (noteType === 'note' || noteType === 'todo') { | 
					
						
							|  |  |  | 								CommandService.instance().execute('newNote', { template: answer.value, isTodo: noteType === 'todo' }); | 
					
						
							|  |  |  | 							} else { | 
					
						
							|  |  |  | 								CommandService.instance().execute('insertText', { value: TemplateUtils.render(answer.value) }); | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						comp.setState({ promptOptions: null }); | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | }; |