| 
									
										
										
										
											2017-09-23 10:18:08 -04:00
										 |  |  | let globalHistoryItems = null; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-09 11:28:56 -04:00
										 |  |  | function showCurrentNoteHistory() { | 
					
						
							|  |  |  |     showNoteHistoryDialog(globalCurrentNote.detail.note_id); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-02 23:38:05 -04:00
										 |  |  | function showNoteHistoryDialog(noteId, noteHistoryId) { | 
					
						
							| 
									
										
										
										
											2017-10-10 20:19:16 -04:00
										 |  |  |     $("#note-history-dialog").dialog({ | 
					
						
							| 
									
										
										
										
											2017-09-21 22:20:10 -04:00
										 |  |  |         modal: true, | 
					
						
							|  |  |  |         width: 800, | 
					
						
							|  |  |  |         height: 700 | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-10 20:19:16 -04:00
										 |  |  |     $("#note-history-list").empty(); | 
					
						
							|  |  |  |     $("#note-history-content").empty(); | 
					
						
							| 
									
										
										
										
											2017-09-21 22:20:10 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $.ajax({ | 
					
						
							| 
									
										
										
										
											2017-10-02 23:38:05 -04:00
										 |  |  |         url: baseApiUrl + 'notes-history/' + noteId, | 
					
						
							| 
									
										
										
										
											2017-09-21 22:20:10 -04:00
										 |  |  |         type: 'GET', | 
					
						
							| 
									
										
										
										
											2017-10-09 18:53:11 -04:00
										 |  |  |         success: result => { | 
					
						
							| 
									
										
										
										
											2017-09-23 10:18:08 -04:00
										 |  |  |             globalHistoryItems = result; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             for (const row of result) { | 
					
						
							| 
									
										
										
										
											2017-10-24 19:36:37 -04:00
										 |  |  |                 const dateModified = getDateFromTS(row.date_modified_to); | 
					
						
							| 
									
										
										
										
											2017-09-23 10:18:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-10 20:19:16 -04:00
										 |  |  |                 $("#note-history-list").append($('<option>', { | 
					
						
							| 
									
										
										
										
											2017-11-02 23:36:58 -04:00
										 |  |  |                     value: row.note_history_id, | 
					
						
							| 
									
										
										
										
											2017-09-26 23:23:03 -04:00
										 |  |  |                     text: formatDateTime(dateModified) | 
					
						
							| 
									
										
										
										
											2017-09-23 10:18:08 -04:00
										 |  |  |                 })); | 
					
						
							| 
									
										
										
										
											2017-09-21 22:20:10 -04:00
										 |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-23 10:18:08 -04:00
										 |  |  |             if (result.length > 0) { | 
					
						
							| 
									
										
										
										
											2017-10-02 23:38:05 -04:00
										 |  |  |                 if (!noteHistoryId) { | 
					
						
							| 
									
										
										
										
											2017-10-10 20:19:16 -04:00
										 |  |  |                     noteHistoryId = $("#note-history-list option:first").val(); | 
					
						
							| 
									
										
										
										
											2017-10-02 23:38:05 -04:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2017-09-21 22:20:10 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-10 20:19:16 -04:00
										 |  |  |                 $("#note-history-list").val(noteHistoryId).trigger('change'); | 
					
						
							| 
									
										
										
										
											2017-09-21 22:20:10 -04:00
										 |  |  |             } | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2017-11-03 22:08:27 -04:00
										 |  |  |         error: () => error("Error getting note history.") | 
					
						
							| 
									
										
										
										
											2017-09-21 22:20:10 -04:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2017-10-02 23:38:05 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-09 11:28:56 -04:00
										 |  |  | $(document).bind('keydown', 'alt+h', showCurrentNoteHistory); | 
					
						
							| 
									
										
										
										
											2017-09-23 10:18:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-10 20:19:16 -04:00
										 |  |  | $("#note-history-list").on('change', () => { | 
					
						
							|  |  |  |     const optVal = $("#note-history-list").find(":selected").val(); | 
					
						
							| 
									
										
										
										
											2017-10-24 20:00:54 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-02 23:36:58 -04:00
										 |  |  |     const historyItem = globalHistoryItems.find(r => r.note_history_id === optVal); | 
					
						
							| 
									
										
										
										
											2017-09-23 10:18:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-02 23:36:58 -04:00
										 |  |  |     let noteTitle = historyItem.note_title; | 
					
						
							|  |  |  |     let noteText = historyItem.note_text; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (historyItem.encryption > 0) { | 
					
						
							|  |  |  |         noteTitle = decryptString(noteTitle); | 
					
						
							|  |  |  |         noteText = decryptString(noteText); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $("#note-history-title").html(noteTitle); | 
					
						
							|  |  |  |     $("#note-history-content").html(noteText); | 
					
						
							| 
									
										
										
										
											2017-09-21 22:20:10 -04:00
										 |  |  | }); |