Link to home
Start Free TrialLog in
Avatar of fskilnik
fskilnikFlag for Brazil

asked on

bootstrap collapsible panel rule...

Hi there!

This code (below) works as expected, but I would like to avoid the "4-min refresher" not only when there is a video in the page, but also when the user is typing an online question , that is, when the collapsible panel is open. Reason: when the page refreshes, the panel closes and the user "looses" the content typed!

-------------------------------------------------------------------------------------------------------------------------
<script type="text/javascript" language="javascript">
      $(function () {
    var pageTimeout

        function resetTimer() {
            clearTimeout(pageTimeout);
            pageTimeout = setTimeout(timeoutExpired,  240000);
        }

    $(document.body).bind('mousemove,keydown,click', resetTimer);

    $('#collapsePanelQuestion').on('hidden.bs.collapse', function () {resetTimer();})       
//if user is not typing a "Have a Question", we may reload page if already 4 min without other activities


    <% If (Not thereisvideoinpage) Then %>
           resetTimer();
    <% end if %>

    function timeoutExpired() {
        window.location.reload() // if not activity for 4 minutes reload page, 1min = 60 000
    }
});
</script>  
----------------------------------------------------------------------------------------------------

The part in bold is the way I have tried to put it to work, but the page refreshes every 4min even when the collapsible panel is open, therefore my solution is wrong.

Could someone change my code so that it works as expected?

Thanks a lot,
fskilnik.
Avatar of Big Monty
Big Monty
Flag of United States of America image

if you want to call the refreshTimer() function when the user is typing, why not check the container they're typing into. let's say you have a textbox they're typing into called txt1, you could do something like this:

$( "#txt1" ).keypress(function() {
      resetTimer();
});

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fskilnik

ASKER

Hello there!

Thank you both for coming here, and very sorry for my delay!

@Big Monty:  I guess you had a simple and great idea, but I guess I need something slightly different, in the sense that while the user is typing, I want the resetTimer NOT to work.  (I really know nothing about javascript, therefore although I guess the correction in your code is really easy, I cannot do it. Please help!)

@Scott Fell: I´ve read your careful suggestion and I am VERY inclined to make as you suggest in the near-future. But, for the moment, I have to have a "solution working", because my students are using the online environment while I am implementing all this. (I am NOT a professional programmer but a maths teacher. The fact that I am able to even explain my difficulties and implement all suggestions you all give me here at EE - till now, at least - makes me really proud, but of course I suffer and take much longer time than I should need IF I had the proper experience and qualifications...)
i see what you're saying, makes sense...

let me ask you this, do you want to cancel the page refresh only while the user is typing? or do you want to cancel the page refresh once the user starts typing for the life of the page? this means the user starts typing, you cancel the refresh() function and it never turns back on after the user is done typing...this would mean if the user goes and gets a cup of coffee and returns ten minutes later to submit the page, you'll run into problems, right?
Hi, Big Monty!

Right!

In other words: I want the refresh to restart working after the user updates that page that is "behind" the form he is filling. If he starts typing, stops to get some coffee, the best scenario would be NOT to refresh because the collapsible panel in which the textarea he is filling is still open but... I don´t know if it is easy to handle this.
Let me ask you something, Big Monty:

<form class="form-horizontal" id="idForm" name="idForm" method="post" action="../../Codes_my/ins_questionDB.asp">

The form is "initiated" like above, therefore he must press "send" button to run the insertion storeprocedure.

Is there a way to change this, so that IF the page reloads, the insertion store procedure runs anyway?  I guess this would be great, because after the reloading, the user WILL be able to "edit" (and therefore complete, for instance) his/her question... got it?
the best scenario would be NOT to refresh because the collapsible panel in which the textarea he is filling is still open

but if they come back in an hour or two, they're session on the site will be lost, no?
Yes... but in this case I guess the form has already a hidden variable with the user´s ID, therefore the database would be updated and THEN the user would be redirected to the (re)login page... when he is redirected to the page before-expiration, he would see the page updated, because the database was, accordingly.

In other words, if you agree and help me with my last suggestion (I mean, being able to run the updating when the page refreshes, not only when the button is pressed), we were able to solve the problem in a very pleasant way...

WHat do you think?
Hello, Big Monty!

I guess you did not answer my last post because you saw that I will try to implement Scott Fell´s "token idea" in the next days (or one or two weeks, depending on my difficulties).

Anyway, I will spare your efforts if you simply haven´t had time to come back here (and would in the next few days), because I have decided to stop the "refresh" behavior for good, not only because it is bothering some students (they say that when a page refreshes, the position at the page they were, before refreshing, was lost), but also because Scott Fell´s suggestion (token idea) is also the proper way of dealing with my site for now on. I am sure you agree, therefore I will take the time needed to make the change.

THanks a lot for your expertise and advice/answers, as usual. I hope to "see" you again in other EE posts!

All the best and Kind Regards,
fskilnik.
Ya I figured as much, that's why I gradually phased myself out of answering, as to not confuse you going forward. while it'll take longer to implement, it is indeed the proper solution for your situation, so no worries there.

good luck and happy programming!
Big Monty!

You are not only a great programmer, but also a gentleman.   :)

Thanks a LOT, as usual, also for your understanding and for your approval on my decision. It´s good to know I am really on the right track.

Kind Regards,
fskilnik.