Pman.Lock.js
[Pman.Core] / Pman.Lock.js
1 //<script type="text/javascript">
2 /**
3  * Locking - 
4  * 
5  * usage:
6  * 
7  
8      new Pman.Lock( {
9           table : 'Product',
10          id : 123,
11          success : function(lock) { ..show dialog etc..... 
12           
13            ... dostuff..
14            ... send _lock=XXX to Roo updated code..
15            
16             lock.unlock() -- we dont care about the result..
17           }
18         }
19     * 
20  * 
21  * 
22  *  call : 
23  * try and lock it..
24  * baseURL + /Core/Lock/lock?on_id=...&on_table=...
25  * - returns id or an array of who has the locks.
26  * 
27  * Force an unlock after a warning..
28  * baseURL + /Core/Lock/lock?on_id=...&on_table=...&force=1
29  * - returns id..
30  * 
31  * Unlock - call when window is closed..
32  * baseURL + /Core/Lock/unlock?on_id=...&on_table=...&force=1
33  * - returns jerr or jok
34  * 
35  */
36 Pman.Lock = function (cfg) {
37     this.cfg = cfg;
38     this.attemptLock();
39 }
40
41 Roo.apply(Pman.Lock.prototype, {
42     
43     attemptLock : function()
44     {
45         var _t = this
46         Pman.Request({
47             url : baseURL + 'Core/Lock/lock',
48             params : {
49                 on_table : cfg.table,
50                 on_id : cfg.id
51             },
52             failure : function() {
53                 Roo.MessageBox.alert("Error", "Lock Request failed, please try again");
54             },
55             success : function(data)
56             {
57                 Roo.log(data);
58                 
59                 if (typeof(data) == 'object') {
60                     _t.confirmBreak(data);
61                 }
62                 
63                 _t.cfg.success(_t); //dont care about scope..
64                 
65                 
66             }
67         })
68     },
69     confirmBreak : function (ar)
70     {
71         
72         var msg = '';
73         Roo.each(ar, function(p) {
74             
75            }
76         
77         
78         
79     }
80     
81     
82     unlock : function() {
83         Pman.Request({
84             url : baseURL + 'Core/Lock/unlock',
85             params : {
86                 id : this.lock_id,
87                 on_id : cfg.id
88             },
89             failure : function() {
90                 Roo.MessageBox.alert("Error", "Lock Request failed, please try again");
91             },
92             success : function(data)
93             {
94                 Roo.log(data);
95                 
96                 if (typeof(data) == 'object') {
97                     _t.confirmBreak(data);
98                 }
99                 
100                 _t.cfg.success(_t); //dont care about scope..
101                 
102                 
103             }
104         })
105     }
106     
107
108 });
109