Browse Source

#788 Whenever a timeout is detected by an ajax request, a popup dialog warns the user to log-in again.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@3613 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 10 năm trước cách đây
mục cha
commit
7dff949a36

+ 26 - 0
application/itopwebpage.class.inc.php

@@ -117,7 +117,13 @@ EOF
 				myLayout.addPinBtn( "#tPinMenu", "west" );
 EOF;
 		}
+
 		
+		$sJSDisconnectedMessage = json_encode(Dict::S('UI:DisconnectedDlgMessage'));
+		$sJSTitle = json_encode(Dict::S('UI:DisconnectedDlgTitle'));
+		$sJSLoginAgain = json_encode(Dict::S('UI:LoginAgain'));
+		$sJSStayOnThePage = json_encode(Dict::S('UI:StayOnThePage'));
+					
 		$this->m_sInitScript =
 <<< EOF
 	try
@@ -391,6 +397,26 @@ EOF
 	$('#logOffBtn>ul').popupmenu();
 	
 	$('.caselog_header').click( function () { $(this).toggleClass('open').next('.caselog_entry').toggle(); });
+	
+	$(document).ajaxSend(function(event, jqxhr, options) {
+		jqxhr.setRequestHeader('X-Combodo-Ajax', 'true');
+	});
+	$(document).ajaxError(function(event, jqxhr, options) {
+		if (jqxhr.status == 401)
+		{
+			$('<div>'+$sJSDisconnectedMessage+'</div>').dialog({
+				modal:true,
+				title: $sJSTitle,
+				close: function() { $(this).remove(); },
+				minWidth: 400,
+				buttons: [
+					{ text: $sJSLoginAgain, click: function() { window.location.href= GetAbsoluteUrlAppRoot()+'pages/UI.php' } },
+					{ text: $sJSStayOnThePage, click: function() { $(this).dialog('close'); } }
+				]
+			});
+		}
+	});
+			
 EOF
 		);
 		$sUserPrefs = appUserPreferences::GetAsJSON();

+ 7 - 0
application/loginwebpage.class.inc.php

@@ -581,6 +581,13 @@ EOF
 				{
 					$sLoginMode = $aAllowedLoginTypes[0]; // First in the list...
 				}
+				if (array_key_exists('HTTP_X_COMBODO_AJAX', $_SERVER))
+				{
+					// X-Combodo-Ajax is a special header automatically added to all ajax requests
+					// Let's reply that we're currently logged-out
+					header('HTTP/1.0 401 Unauthorized');
+					exit;
+				}
 				if (($iOnExit == self::EXIT_HTTP_401) || ($sLoginMode == 'basic'))
 				{
 					header('WWW-Authenticate: Basic realm="'.Dict::Format('UI:iTopVersion:Short', ITOP_VERSION));

+ 25 - 0
application/portalwebpage.class.inc.php

@@ -92,6 +92,12 @@ class PortalWebPage extends NiceWebPage
 		$this->add_linked_script("../js/ajaxfileupload.js");
 		$this->add_linked_script("../js/ckeditor/ckeditor.js");
 		$this->add_linked_script("../js/ckeditor/adapters/jquery.js");
+
+		$sJSDisconnectedMessage = json_encode(Dict::S('UI:DisconnectedDlgMessage'));
+		$sJSTitle = json_encode(Dict::S('UI:DisconnectedDlgTitle'));
+		$sJSLoginAgain = json_encode(Dict::S('UI:LoginAgain'));
+		$sJSStayOnThePage = json_encode(Dict::S('UI:StayOnThePage'));
+		
 		$this->add_ready_script(
 <<<EOF
 try
@@ -154,6 +160,25 @@ try
 
 	//$('.resizable').resizable(); // Make resizable everything that claims to be resizable !
 	$('.caselog_header').click( function () { $(this).toggleClass('open').next('.caselog_entry').toggle(); });
+			
+	$(document).ajaxSend(function(event, jqxhr, options) {
+		jqxhr.setRequestHeader('X-Combodo-Ajax', 'true');
+	});
+	$(document).ajaxError(function(event, jqxhr, options) {
+		if (jqxhr.status == 401)
+		{
+			$('<div>'+$sJSDisconnectedMessage+'</div>').dialog({
+				modal:true,
+				title: $sJSTitle,
+				close: function() { $(this).remove(); },
+				minWidth: 400,
+				buttons: [
+				{ text: $sJSLoginAgain, click: function() { window.location.href= GetAbsoluteUrlAppRoot()+'pages/UI.php' } },
+				{ text: $sJSStayOnThePage, click: function() { $(this).dialog('close'); } }
+				]
+			});
+		}
+	});
 }
 catch(err)
 {

+ 4 - 0
dictionaries/de.dictionary.itop.ui.php

@@ -987,5 +987,9 @@ Wenn Aktionen mit Trigger verknüpft sind, bekommt jede Aktion eine Auftragsnumm
 	'Month-11' => 'November',
 	'Month-12' => 'Dezember',
 	'UI:FillAllMandatoryFields' => 'Bitte füllen Sie alle Pflichtfelder',
+	'UI:DisconnectedDlgMessage' => 'You are disconnected. You must identify yourself to continue using the application.~~',
+	'UI:DisconnectedDlgTitle' => 'Warning!~~',
+	'UI:LoginAgain' => 'Login again~~',
+	'UI:StayOnThePage' => 'Stay on this page~~',	
 ));
 ?>

+ 5 - 0
dictionaries/dictionary.itop.ui.php

@@ -1240,6 +1240,11 @@ When associated with a trigger, each action is given an "order" number, specifyi
 	'UI:About:Licenses' => 'Licenses',
 	'UI:About:Modules' => 'Installed modules',
 	
+	'UI:DisconnectedDlgMessage' => 'You are disconnected. You must identify yourself to continue using the application.',
+	'UI:DisconnectedDlgTitle' => 'Warning!',
+	'UI:LoginAgain' => 'Login again',
+	'UI:StayOnThePage' => 'Stay on this page',
+	
 	'ExcelExporter:ExportMenu' => 'Excel Export...',
 	'ExcelExporter:ExportDialogTitle' => 'Excel Export',
 	'ExcelExporter:ExportButton' => 'Export',

+ 5 - 0
dictionaries/fr.dictionary.itop.ui.php

@@ -1082,6 +1082,11 @@ Lors de l\'association à un déclencheur, on attribue à chaque action un numé
 	'UI:About:Licenses' => 'Licences',
 	'UI:About:Modules' => 'Modules installés',
 	
+	'UI:DisconnectedDlgMessage' => 'Vous êtes déconnecté(e). Vous devez vous identifier pour pouvoir continuer à utiliser l\'application.',
+	'UI:DisconnectedDlgTitle' => 'Attention !',
+	'UI:LoginAgain' => 'S\'identifier',
+	'UI:StayOnThePage' => 'Rester sur cette page',
+		
 	'ExcelExporter:ExportMenu' => 'Exporter pour Excel...',
 	'ExcelExporter:ExportDialogTitle' => 'Export au format Excel',
 	'ExcelExporter:ExportButton' => 'Exporter',