| 
									
										
										
										
											2017-11-01 20:31:44 -04:00
										 |  |  | function checkStatus() { | 
					
						
							|  |  |  |     $.ajax({ | 
					
						
							| 
									
										
										
										
											2017-11-01 22:36:26 -04:00
										 |  |  |         url: baseApiUrl + 'status', | 
					
						
							|  |  |  |         type: 'POST', | 
					
						
							|  |  |  |         contentType: "application/json", | 
					
						
							|  |  |  |         data: JSON.stringify({ | 
					
						
							|  |  |  |             treeLoadTime: globalTreeLoadTime, | 
					
						
							|  |  |  |             currentNoteId: globalCurrentNote ? globalCurrentNote.detail.note_id : null, | 
					
						
							|  |  |  |             currentNoteDateModified: globalCurrentNoteLoadTime | 
					
						
							|  |  |  |         }), | 
					
						
							| 
									
										
										
										
											2017-11-01 20:31:44 -04:00
										 |  |  |         success: resp => { | 
					
						
							| 
									
										
										
										
											2017-11-01 22:36:26 -04:00
										 |  |  |             if (resp.changedTree) { | 
					
						
							|  |  |  |                 loadTree().then(resp => { | 
					
						
							|  |  |  |                     console.log("Reloading tree because of background changes"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     globalTree.fancytree('getTree').reload(resp.notes); | 
					
						
							|  |  |  |                 }); | 
					
						
							| 
									
										
										
										
											2017-11-01 20:31:44 -04:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2017-11-01 22:36:26 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if (resp.changedCurrentNote) { | 
					
						
							|  |  |  |                 alert("Current note has been changed in different window / computer. Please reload the application and resolve the conflict manually."); | 
					
						
							| 
									
										
										
										
											2017-11-01 20:31:44 -04:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2017-11-01 22:36:26 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |             $("#changesToPushCount").html(resp.changesToPushCount); | 
					
						
							| 
									
										
										
										
											2017-11-01 20:31:44 -04:00
										 |  |  |         }, | 
					
						
							|  |  |  |         statusCode: { | 
					
						
							|  |  |  |             401: () => { | 
					
						
							|  |  |  |                 // if the user got logged out then we should display the page
 | 
					
						
							|  |  |  |                 // here we do that by reloading which will force the redirect if the user is really logged out
 | 
					
						
							|  |  |  |                 window.location.reload(true); | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             409: () => { | 
					
						
							|  |  |  |                 // 409 means we need to migrate database, reload will take care of it
 | 
					
						
							|  |  |  |                 window.location.reload(true); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-01 22:36:26 -04:00
										 |  |  | setInterval(checkStatus, 5 * 1000); |