PHP7 fix
[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     Roo.log('ctor-callLock');
39     this.callLock();
40 }
41
42 Roo.apply(Pman.Lock.prototype, {
43     cfg : false,
44     
45     id : false, // the id of the lock..
46     
47     callLock : function(force)
48     {
49         Roo.log('callLock');
50         force = force || 0;
51         var _t = this;
52         new Pman.Request({
53             url : baseURL + '/Core/Lock/lock',
54             params : {
55                 on_table : this.cfg.table,
56                 on_id : this.cfg.id,
57                 force : force
58             },
59             failure : function() {
60                 Roo.MessageBox.alert("Error", "Lock Request failed, please try again");
61             },
62             success : function(res)
63             {
64                 var data = res.data;
65                Roo.log(data);
66                 if (!force && typeof(data) == 'object') {
67                     _t.confirmBreak(data);
68                     return;
69                 }
70                 _t.id = data;
71                 _t.cfg.success(_t); //dont care about scope..
72                 
73                 
74             }
75         })
76     },
77     confirmBreak : function (ar)
78     {
79         
80         var msg = "This Record is Locked by the following people, <br/>" + 
81             "Do you want to continue, this will prevent these people from saving their changes<br/>";
82             
83         Roo.each(ar, function(p) {
84             msg += '<br/>' + p.name + ' at ' + p.lock_created ;
85         });
86         var _t = this;
87         Roo.MessageBox.confirm("Confirm breaking locks", msg, function(r) {
88             if (r != 'yes') {
89                 return;
90             }
91             _t.callLock(1);
92         });
93             
94         
95         
96         
97     },
98     
99     
100     unlock : function() {
101         new Pman.Request({
102             url : baseURL + '/Core/Lock/unlock',
103             params : {
104                 id : this.id
105             },
106             failure : function() {
107                 Roo.MessageBox.alert("Error", "UnLock Request failed, you may get a warning when trying to edit again");
108             },
109             success : function(data)
110             {
111                 // don nothing
112                 
113             }
114         });
115     }
116     
117
118 });
119