Question

Run a timer on load of Account Page

Hi Community,

 

We have this requirement from our client to redirect the Account Page to Account Section after 2 minutes. So basically on load on Account Page I will trigger a timer then after 2 minutes I will redirect it to Account Section. Any idea please? Thank

Like 0

Like

4 comments

Something like this could work:

onEntityInitialized: function() {
    this.callParent(arguments);
 
    var self = this;
    setTimeout(function() {
        self.sandbox.publish("PushHistoryState", { hash: "SectionModuleV2/AccountSectionV2" });
    }, 120000);
}

However, if the user is in the middle of changing the record it could leave things unsaved. Might be a good idea to check and save record before navigating away. 

Ryan

Ryan Farley,



Thank you Ryan. Maybe I need to check only the idle time. Do you have any idea how can I detect idle time in Edit page?

 

Fulgen Ninofranco,

You'd basically need to detect mouse or keyboard activity and reset your timer. Something like this (keep in mind none of this is tested, just ideas)

properties: {
    idleTime: 0,
    idleIntervalId: null
},
methods: {
    onEntityInitialized: function() {
        this.callParent(arguments);
 
        if (this.idleIntervalId) {
            clearInterval(this.idleIntervalId);
        }
 
        var self = this;
        this.idleTime = 0;
        this.idleIntervalId = setInterval(self.trackIdleTime, 60000);
 
        $(document).mousemove(function (e) {
            self.idleTime = 0;
        });
        $(document).keypress(function (e) {
            self.idleTime = 0;
        });
    },
 
    trackIdleTime: function() {
        this.idleTime++;
        if (this.idleTime >= 2) {
            // 2 mins idle, nav back to section
            this.sandbox.publish("PushHistoryState", { hash: "SectionModuleV2/AccountSectionV2" });
        }
    }
}

Again, none of that is tested, but that's the general idea - or something like that.

You'd probably need to call this at some point, maybe in the page's destroy method to stop the interval from checking:

clearInterval(this.idleIntervalId);
 
// and maybe these?
$(document).unbind("mousemove");
$(document).unbind("keypress");

Anyway, hope this gets you closer to implementing the task.

Ryan

Ryan Farley,

 

Thank you so much Ryan. This is working fine.

Show all comments