Intercept Save All action

Mehr
4 Jahre 2 Monate her #100649 von dimkaraiskos
dimkaraiskos erstellte das Thema Intercept Save All action
Hi,

I would like to ask your help regarding an issue. I need to intercept the Save All action in a survey and perform an ajax call and then let Save All to continue.

Although I have succeeded this kind of functionality with the Next button I cannot make it work with Save All.

I run Version 1.92+(120919) [pls take under consideration that update to new version is not a possibility at the moment]

Thanks in advance!

Bitte Anmelden um an der Konversation teilzunehmen.

Mehr
4 Jahre 2 Monate her #100764 von tpartner
tpartner antwortete auf das Thema: Intercept Save All action
You should be able to do something like this. The script below clears the original save-all click event, adds an AJAX call and the re-fires the original save-all click event after the AJAX call is finished.
<script type="text/javascript" charset="utf-8">	
	$(document).ready(function() {
 
		var oldClick = new Function($('input.saveall').attr('onClick'));
 
		// Clear the original save-all click event and add a new one
		$('input.saveall').attr('onclick', '').click(function(event) {
			$.ajax({
				url: 'http://path/to/your/file.php',
				async: true,
				data: {var1: 'some data'},
				success: function(results){
					// Do something with the returned data
					alert(results);
 
					// Fire the original save-all click event
					oldClick();
				},
				error: function(){
					// Oops, the AJAX call failed
					alert('Fail!');
				}
			});
		});
	});
</script>

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Bitte Anmelden um an der Konversation teilzunehmen.

Mehr
4 Jahre 1 Monat her #100809 von dimkaraiskos
dimkaraiskos antwortete auf das Thema: Intercept Save All action
Tony,

thanks for the reply!

I put the script you provided both at question (level) and at group (level), separately each time, and still Save All works as before :)

Even if I try to change the onclick event of Save All to do just a simple alert, I cannot!

Any thoughts here?

Bitte Anmelden um an der Konversation teilzunehmen.

Mehr
4 Jahre 1 Monat her - 3 Jahre 10 Monate her #100814 von tpartner
tpartner antwortete auf das Thema: Intercept Save All action
That's odd, I just tested and it worked as expected.

Do you have any JavaScript errors?

Here's a little working sample that interrupts the save-all function, counts down a timer for 5 seconds and then carries on with the save-all function.

Dateianhang:

Dateiname: limesurvey...4328.lss
Dateigröße:13 KB


The code is in the question text:
<script type="text/javascript" charset="utf-8">	
	$(document).ready(function() {
 
		var oldClick = new Function($('input.saveall').attr('onClick'));
 
		var t = '';
 
		$('input.saveall').attr('onclick', '').click(function(event) {
			var timer = '<div class="timer" style="position:absolute; top: 100px; left: 50%; margin-left:-50px; width: 100px; height: 50px; background:black; text-align:center; line-height: 50px; color: white; font-size:200%;"></div>';
			$('body').append(timer);
 
			// Update timer
			function updateTime(remainSec){ 
 
			$('input.saveall').unbind('click');
 
				$('.timer').text(remainSec);
 
				if(remainSec != 0) {
					remainSec--;
 
					t = setTimeout(function() { 
						updateTime(remainSec);
					}, 1000);
				}
				else {
					// Timer is expired so carry on with the saveall
					oldClick();
				}
			}
 
			// Start the timer
			updateTime(5)
		});
	});
</script>

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Anhang:
Letzte Änderung: 3 Jahre 10 Monate her von tpartner.

Bitte Anmelden um an der Konversation teilzunehmen.

Mehr
4 Jahre 1 Monat her #100867 von dimkaraiskos
dimkaraiskos antwortete auf das Thema: Intercept Save All action
Tony,

it works perfectly!!

The problem was that $('input.saveall') could not find anything.
So fixing that to $("input[name='saveallbtn']") it worked like a charm.

Thanx!!

Bitte Anmelden um an der Konversation teilzunehmen.

Jetzt loslegen!

Melden Sie sich jetzt an, und erstellen Sie in wenigen Minuten Ihre erste Umfrage.

Account einrichten

Abonnieren Sie unseren Newsletter

Abonnieren Sie unseren Newsletter für alle Neuigkeiten rund um LimeSurvey
captcha