| 
									
										
										
										
											2017-11-04 19:38:50 -04:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 13:55:46 -04:00
										 |  |  | const noteHistory = (function() { | 
					
						
							|  |  |  |     const dialogEl = $("#note-history-dialog"); | 
					
						
							|  |  |  |     const listEl = $("#note-history-list"); | 
					
						
							|  |  |  |     const contentEl = $("#note-history-content"); | 
					
						
							|  |  |  |     const titleEl = $("#note-history-title"); | 
					
						
							| 
									
										
										
										
											2017-09-23 10:18:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 13:55:46 -04:00
										 |  |  |     let historyItems = []; | 
					
						
							| 
									
										
										
										
											2017-10-09 11:28:56 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 13:55:46 -04:00
										 |  |  |     async function showCurrentNoteHistory() { | 
					
						
							| 
									
										
										
										
											2017-11-04 17:54:27 -04:00
										 |  |  |         await showNoteHistoryDialog(noteEditor.getCurrentNoteId()); | 
					
						
							| 
									
										
										
										
											2017-11-04 13:55:46 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async function showNoteHistoryDialog(noteId, noteHistoryId) { | 
					
						
							| 
									
										
										
										
											2017-11-04 17:03:15 -04:00
										 |  |  |         glob.activeDialog = dialogEl; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 13:55:46 -04:00
										 |  |  |         dialogEl.dialog({ | 
					
						
							|  |  |  |             modal: true, | 
					
						
							|  |  |  |             width: 800, | 
					
						
							|  |  |  |             height: 700 | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2017-09-21 22:20:10 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 13:55:46 -04:00
										 |  |  |         listEl.empty(); | 
					
						
							|  |  |  |         contentEl.empty(); | 
					
						
							| 
									
										
										
										
											2017-09-23 10:18:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-28 20:52:38 -05:00
										 |  |  |         historyItems = await server.get('notes-history/' + noteId); | 
					
						
							| 
									
										
										
										
											2017-09-23 10:18:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 13:55:46 -04:00
										 |  |  |         for (const item of historyItems) { | 
					
						
							| 
									
										
										
										
											2017-12-10 15:31:43 -05:00
										 |  |  |             const dateModified = parseDate(item.date_modified_from); | 
					
						
							| 
									
										
										
										
											2017-09-21 22:20:10 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-26 19:54:43 -05:00
										 |  |  |             listEl.append($('<option>', { | 
					
						
							| 
									
										
										
										
											2017-11-04 13:55:46 -04:00
										 |  |  |                 value: item.note_history_id, | 
					
						
							|  |  |  |                 text: formatDateTime(dateModified) | 
					
						
							|  |  |  |             })); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-09-21 22:20:10 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 13:55:46 -04:00
										 |  |  |         if (historyItems.length > 0) { | 
					
						
							|  |  |  |             if (!noteHistoryId) { | 
					
						
							|  |  |  |                 noteHistoryId = listEl.find("option:first").val(); | 
					
						
							| 
									
										
										
										
											2017-09-21 22:20:10 -04:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2017-10-02 23:38:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 13:55:46 -04:00
										 |  |  |             listEl.val(noteHistoryId).trigger('change'); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-12-26 19:54:43 -05:00
										 |  |  |         else { | 
					
						
							|  |  |  |             titleEl.text("No history for this note yet..."); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-11-04 13:55:46 -04:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-09-23 10:18:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-18 23:44:20 -05:00
										 |  |  |     $(document).bind('keydown', 'alt+h', e => { | 
					
						
							|  |  |  |         showCurrentNoteHistory(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         e.preventDefault(); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2017-10-24 20:00:54 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 13:55:46 -04:00
										 |  |  |     listEl.on('change', () => { | 
					
						
							|  |  |  |         const optVal = listEl.find(":selected").val(); | 
					
						
							| 
									
										
										
										
											2017-09-23 10:18:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 13:55:46 -04:00
										 |  |  |         const historyItem = historyItems.find(r => r.note_history_id === optVal); | 
					
						
							| 
									
										
										
										
											2017-11-02 23:36:58 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-14 22:21:56 -05:00
										 |  |  |         titleEl.html(historyItem.note_title); | 
					
						
							|  |  |  |         contentEl.html(historyItem.note_text); | 
					
						
							| 
									
										
										
										
											2017-11-04 13:55:46 -04:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2017-11-02 23:36:58 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 17:03:15 -04:00
										 |  |  |     $(document).on('click', "a[action='note-history']", event => { | 
					
						
							|  |  |  |         const linkEl = $(event.target); | 
					
						
							| 
									
										
										
										
											2017-11-21 20:04:06 -05:00
										 |  |  |         const noteId = linkEl.attr('note-path'); | 
					
						
							| 
									
										
										
										
											2017-11-04 17:03:15 -04:00
										 |  |  |         const noteHistoryId = linkEl.attr('note-history-id'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         showNoteHistoryDialog(noteId, noteHistoryId); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 13:55:46 -04:00
										 |  |  |     return { | 
					
						
							| 
									
										
										
										
											2017-11-04 17:03:15 -04:00
										 |  |  |         showCurrentNoteHistory | 
					
						
							| 
									
										
										
										
											2017-11-04 13:55:46 -04:00
										 |  |  |     }; | 
					
						
							|  |  |  | })(); |