Page 1 of 1

Go back from edit to browser form after 5 min of inactivity

Posted: Tue Aug 11, 2020 8:48 am
by gerese
Hi guys! I wants to challenge you with making a code, which will go back from edit to browseform, even if the form has been saved or not, after a period of time (5 min), possibly a small stopwatch with the remaining time. :)

Re: Go back from edit to browser form after 5 min of inactiv

Posted: Tue Aug 11, 2020 1:44 pm
by Janusz
Hi,
The attached code will work only for the form placed inside the iFrame.
Code is just with basic test only.
Example belowe will work with one form.
If used for more make sure than funtion is not fired several times and ref to forms are properly set.

Place the following in the Setup/Header:

Code: Select all

var time_in = new Date();
var form_1 = 0;

function time_watch() {
var x = 10;    // check period in seconds, time check accuracy
var time_now = new Date();
var time_diff = (time_now- time_in)/1000;
var time_off = 15; //off time in sec
if (time_diff>time_off) {nuHasNotBeenEdited();gotoPrevBreadcrumb();}
setTimeout(time_watch, x*1000);
}

function gotoPrevBreadcrumb() {
    if (parent.$('#nuModal').length > 0) {
        nuClosePopup();
        return;
    }
    var l = window.nuFORM.breadcrumbs.length;
    if (l > 1) {
        nuGetBreadcrumb(l - 2);
    }
}
and this in the JS of the specific form placed inside the iFrame

Code: Select all

if (nuFormType() == 'edit') {
form_1=form_1+1;
time_in = new Date();
if (form_1==1) {time_watch();}
}

Re: Go back from edit to browser form after 5 min of inactiv

Posted: Thu Aug 13, 2020 5:36 pm
by gerese
Thx Janusz for help , requires some changes, after go back from editscreen to browseform, the script ran and took me home.

Re: Go back from edit to browser form after 5 min of inactiv

Posted: Fri Aug 21, 2020 3:15 am
by kev1n
Here's a complete code with visual countdown and inactivity tracker (mouse, key press detection)

https://github.com/smalos/nuBuilder4-Co ... er_timeout

Re: Go back from edit to browser form after 5 min of inactiv

Posted: Sat Aug 22, 2020 6:23 pm
by gerese
Thx Kev1n , work great !!!