| 
									
										
										
										
											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-09-21 22:20:10 -04:00
										 |  |  |     $("#noteHistoryDialog").dialog({ | 
					
						
							|  |  |  |         modal: true, | 
					
						
							|  |  |  |         width: 800, | 
					
						
							|  |  |  |         height: 700 | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $("#noteHistoryList").empty(); | 
					
						
							|  |  |  |     $("#noteHistoryContent").empty(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $.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-09-30 22:35:13 -04:00
										 |  |  |                 const dateModified = getDateFromTS(row.date_modified); | 
					
						
							| 
									
										
										
										
											2017-09-23 10:18:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 $("#noteHistoryList").append($('<option>', { | 
					
						
							|  |  |  |                     value: row.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) { | 
					
						
							|  |  |  |                     noteHistoryId = $("#noteHistoryList option:first").val(); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2017-09-21 22:20:10 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-02 23:38:05 -04:00
										 |  |  |                 $("#noteHistoryList").val(noteHistoryId).trigger('change'); | 
					
						
							| 
									
										
										
										
											2017-09-21 22:20:10 -04:00
										 |  |  |             } | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         error: () => alert("Error getting note history.") | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							|  |  |  | $("#noteHistoryList").on('change', () => { | 
					
						
							|  |  |  |     const optVal = $("#noteHistoryList").find(":selected").val(); | 
					
						
							|  |  |  |     const historyItem = globalHistoryItems.find(r => r.id == optVal); // non-strict comparison is important here!!!s
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $("#noteHistoryTitle").html(historyItem.note_title); | 
					
						
							|  |  |  |     $("#noteHistoryContent").html(historyItem.note_text); | 
					
						
							| 
									
										
										
										
											2017-09-21 22:20:10 -04:00
										 |  |  | }); |