e51c21173471086486f0f9fe035678b75a4c4782
[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         var _t = this;
39         Pman.Request({
40             url : baseURL + 'Core/Lock/lock',
41             params : {
42                 on_table : cfg.table,
43                 on_id : cfg.id
44             },
45             failure : function() {
46                 Roo.MessageBox.alert("Error", "Lock Request failed, please try again");
47             },
48             success : function(data)
49             {
50                 Roo.log(data);
51                 
52                 if (typeof(data) == 'object') {
53                     this.confirmBreak();
54                     
55                     
56                     
57                 }
58                 
59                 _t.cfg.success.call(_t,_t);
60                 
61                 
62             }
63         })
64     
65     
66     },
67     
68     
69     attempt : function()
70     {
71         var _t = this
72         Pman.Request({
73             url : baseURL + 'Core/Lock/lock',
74             params : {
75                 on_table : cfg.table,
76                 on_id : cfg.id
77             },
78             failure : function() {
79                 Roo.MessageBox.alert("Error", "Lock Request failed, please try again");
80             },
81             success : function(data)
82             {
83                 Roo.log(data);
84                 
85                 if (typeof(data) == 'object') {
86                     _t.confirmBreak(data);
87                 }
88                 
89                 _t.cfg.success(_t); //dont care about scope..
90                 
91                 
92             }
93         })
94     },
95     confirmBreak : function 
96     
97     
98     unlock : function() {
99         Pman.Request({
100             url : baseURL + 'Core/Lock/unlock',
101             params : {
102                 id : this.lock_id,
103                 on_id : cfg.id
104             },
105             failure : function() {
106                 Roo.MessageBox.alert("Error", "Lock Request failed, please try again");
107             },
108             success : function(data)
109             {
110                 Roo.log(data);
111                 
112                 if (typeof(data) == 'object') {
113                     _t.confirmBreak(data);
114                 }
115                 
116                 _t.cfg.success(_t); //dont care about scope..
117                 
118                 
119             }
120         })
121     }
122     
123
124 }
125