Fix title underline error in faq.rst
[ganeti_webmgr.git] / muddle / templates / config_lock.js
blobaebcb1301b932e42606d61e3be596a15a3b6c148
1 var lock = false;
2 var timeout = undefined;
3 var active = true;
4 var lock_interval = undefined;
6 function start_activity_tracking(){
7     timeout = setTimeout(timed_out,30000)
8     $('body')
9         .mousemove(activity)
10         .keypress(activity);
13 function activity(){
14     /*
15         called whenever activity is detected.  This function will prevent
16         the time_out function from being called
17     */
18     if (timeout!=undefined) {
19         clearTimeout(timeout);
20     }
21     timeout = setTimeout(timed_out,180000)
24 function timed_out(){
25     /*
26         called when the owner of the lock times out
27     */
28     clearTimeout(lock_interval);
29     $('body')
30         .unbind('mousemove',activity)
31         .unbind('keypress',activity)
32         .mousemove(reacquire_lock)
33         .keypress(reacquire_lock);
34     $errors.empty().append('<li>Your lock has timed out due to inactivity.  If you become active again it will automatically be reacquired if the page is not in use by another user.</li>')
35     $errors.show();
36     lock = false;
37     active = false;
40 function reacquire_lock() {
41     /*
42         called when a timed out user tries to reacquire the lock
43     */
44     if (!active){
45         active = true
46         $('body')
47             .unbind('mousemove',reacquire_lock)
48             .unbind('keypress',reacquire_lock);
49         refresh_lock();
50     }
53 function acquire_lock() {
54     /*
55         called by users wishing to obtain the lock.  The result of this method
56         may be cached.
57     */
58     $.get('{{ROOT}}/plugin/lock/acquire', {}, process_lock);
61 function refresh_lock() {
62     /*
63         called by owner of lock to maintain possession
64     */
65     $.get('{{ROOT}}/plugin/lock/refresh', {}, process_lock);
68 function process_lock(data){
69     /*
70         processes response about lock possession
71     */
72     if (active){
73         if (data == 1){
74             if (!lock){
75                 // only hide on lock acquire, otherwise you could hide an important error
76                 start_activity_tracking()
77                 $errors.hide();
78                 lock = true;
79             }
80             lock_interval = setTimeout(refresh_lock, 10000);
81         } else {
82             $errors.empty().append('<li>You do not hold the lock.  You cannot edit configuration until $USER is finished.<br/>  Page will unlock when lock is acquired.</li>')
83             $errors.show();
84             lock = false;
85             setTimeout(acquire_lock, 10000);
86         }
87     }