Diffstat (limited to 'frontend/beta/js/Clipperz/PM/Proxy.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/beta/js/Clipperz/PM/Proxy.js | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/frontend/beta/js/Clipperz/PM/Proxy.js b/frontend/beta/js/Clipperz/PM/Proxy.js index bec9195..cf5a237 100644 --- a/frontend/beta/js/Clipperz/PM/Proxy.js +++ b/frontend/beta/js/Clipperz/PM/Proxy.js | |||
@@ -1,169 +1,167 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2013 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz, the online password manager. |
6 | Clipperz Community Edition is an online password manager. | ||
7 | For further information about its features and functionalities please | 6 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 7 | refer to http://www.clipperz.com. |
9 | 8 | ||
10 | * Clipperz Community Edition is free software: you can redistribute | 9 | * Clipperz is free software: you can redistribute it and/or modify it |
11 | it and/or modify it under the terms of the GNU Affero General Public | 10 | under the terms of the GNU Affero General Public License as published |
12 | License as published by the Free Software Foundation, either version | 11 | by the Free Software Foundation, either version 3 of the License, or |
13 | 3 of the License, or (at your option) any later version. | 12 | (at your option) any later version. |
14 | 13 | ||
15 | * Clipperz Community Edition is distributed in the hope that it will | 14 | * Clipperz is distributed in the hope that it will be useful, but |
16 | be useful, but WITHOUT ANY WARRANTY; without even the implied | 15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. | 17 | See the GNU Affero General Public License for more details. |
19 | 18 | ||
20 | * You should have received a copy of the GNU Affero General Public | 19 | * You should have received a copy of the GNU Affero General Public |
21 | License along with Clipperz Community Edition. If not, see | 20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. |
22 | <http://www.gnu.org/licenses/>. | ||
23 | 21 | ||
24 | */ | 22 | */ |
25 | 23 | ||
26 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 24 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
27 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | 25 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } |
28 | 26 | ||
29 | //============================================================================= | 27 | //============================================================================= |
30 | 28 | ||
31 | Clipperz.PM.Proxy = function(args) { | 29 | Clipperz.PM.Proxy = function(args) { |
32 | args = args || {}; | 30 | args = args || {}; |
33 | 31 | ||
34 | this._shouldPayTolls = args.shouldPayTolls || false; | 32 | this._shouldPayTolls = args.shouldPayTolls || false; |
35 | 33 | ||
36 | this._tolls = { | 34 | this._tolls = { |
37 | 'CONNECT':[], | 35 | 'CONNECT':[], |
38 | 'REGISTER':[], | 36 | 'REGISTER':[], |
39 | 'MESSAGE':[] | 37 | 'MESSAGE':[] |
40 | }; | 38 | }; |
41 | 39 | ||
42 | if (args.isDefault === true) { | 40 | if (args.isDefault === true) { |
43 | Clipperz.PM.Proxy.defaultProxy = this; | 41 | Clipperz.PM.Proxy.defaultProxy = this; |
44 | } | 42 | } |
45 | 43 | ||
46 | return this; | 44 | return this; |
47 | } | 45 | } |
48 | 46 | ||
49 | Clipperz.PM.Proxy.prototype = MochiKit.Base.update(null, { | 47 | Clipperz.PM.Proxy.prototype = MochiKit.Base.update(null, { |
50 | 48 | ||
51 | 'toString': function() { | 49 | 'toString': function() { |
52 | return "Clipperz.PM.Proxy"; | 50 | return "Clipperz.PM.Proxy"; |
53 | }, | 51 | }, |
54 | 52 | ||
55 | //========================================================================= | 53 | //========================================================================= |
56 | 54 | ||
57 | 'shouldPayTolls': function() { | 55 | 'shouldPayTolls': function() { |
58 | return this._shouldPayTolls; | 56 | return this._shouldPayTolls; |
59 | }, | 57 | }, |
60 | 58 | ||
61 | //------------------------------------------------------------------------- | 59 | //------------------------------------------------------------------------- |
62 | 60 | ||
63 | 'tolls': function() { | 61 | 'tolls': function() { |
64 | return this._tolls; | 62 | return this._tolls; |
65 | }, | 63 | }, |
66 | 64 | ||
67 | //------------------------------------------------------------------------- | 65 | //------------------------------------------------------------------------- |
68 | 66 | ||
69 | 'payToll': function(aRequestType, someParameters) { | 67 | 'payToll': function(aRequestType, someParameters) { |
70 | vardeferredResult; | 68 | vardeferredResult; |
71 | 69 | ||
72 | //console.log(">>> Proxy.payToll", aRequestType, someParameters); | 70 | //console.log(">>> Proxy.payToll", aRequestType, someParameters); |
73 | if (this.shouldPayTolls()) { | 71 | if (this.shouldPayTolls()) { |
74 | deferredResult = new MochiKit.Async.Deferred(); | 72 | deferredResult = new MochiKit.Async.Deferred(); |
75 | 73 | ||
76 | if (this.tolls()[aRequestType].length == 0) { | 74 | if (this.tolls()[aRequestType].length == 0) { |
77 | deferredResult.addCallback(MochiKit.Base.method(this, 'sendMessage', 'knock', {requestType:aRequestType})); | 75 | deferredResult.addCallback(MochiKit.Base.method(this, 'sendMessage', 'knock', {requestType:aRequestType})); |
78 | deferredResult.addCallback(MochiKit.Base.method(this, 'setTollCallback')); | 76 | deferredResult.addCallback(MochiKit.Base.method(this, 'setTollCallback')); |
79 | } | 77 | } |
80 | deferredResult.addCallback(MochiKit.Base.method(this.tolls()[aRequestType], 'pop')); | 78 | deferredResult.addCallback(MochiKit.Base.method(this.tolls()[aRequestType], 'pop')); |
81 | deferredResult.addCallback(MochiKit.Base.methodcaller('deferredPay')); | 79 | deferredResult.addCallback(MochiKit.Base.methodcaller('deferredPay')); |
82 | deferredResult.addCallback(function(aToll) { | 80 | deferredResult.addCallback(function(aToll) { |
83 | var result; | 81 | var result; |
84 | 82 | ||
85 | result = { | 83 | result = { |
86 | parameters: someParameters, | 84 | parameters: someParameters, |
87 | toll: aToll | 85 | toll: aToll |
88 | } | 86 | } |
89 | 87 | ||
90 | return result; | 88 | return result; |
91 | }); | 89 | }); |
92 | 90 | ||
93 | deferredResult.callback(); | 91 | deferredResult.callback(); |
94 | } else { | 92 | } else { |
95 | deferredResult = MochiKit.Async.succeed({parameters:someParameters}); | 93 | deferredResult = MochiKit.Async.succeed({parameters:someParameters}); |
96 | } | 94 | } |
97 | //console.log("<<< Proxy.payToll"); | 95 | //console.log("<<< Proxy.payToll"); |
98 | 96 | ||
99 | return deferredResult; | 97 | return deferredResult; |
100 | }, | 98 | }, |
101 | 99 | ||
102 | //------------------------------------------------------------------------- | 100 | //------------------------------------------------------------------------- |
103 | 101 | ||
104 | 'addToll': function(aToll) { | 102 | 'addToll': function(aToll) { |
105 | //console.log(">>> Proxy.addToll", aToll); | 103 | //console.log(">>> Proxy.addToll", aToll); |
106 | this.tolls()[aToll.requestType()].push(aToll); | 104 | this.tolls()[aToll.requestType()].push(aToll); |
107 | //console.log("<<< Proxy.addToll"); | 105 | //console.log("<<< Proxy.addToll"); |
108 | }, | 106 | }, |
109 | 107 | ||
110 | //========================================================================= | 108 | //========================================================================= |
111 | 109 | ||
112 | 'setTollCallback': function(someParameters) { | 110 | 'setTollCallback': function(someParameters) { |
113 | //console.log(">>> Proxy.setTollCallback", someParameters); | 111 | //console.log(">>> Proxy.setTollCallback", someParameters); |
114 | if (typeof(someParameters['toll']) != 'undefined') { | 112 | if (typeof(someParameters['toll']) != 'undefined') { |
115 | //console.log("added a new toll", someParameters['toll']); | 113 | //console.log("added a new toll", someParameters['toll']); |
116 | this.addToll(new Clipperz.PM.Toll(someParameters['toll'])); | 114 | this.addToll(new Clipperz.PM.Toll(someParameters['toll'])); |
117 | } | 115 | } |
118 | //console.log("<<< Proxy.setTallCallback", someParameters['result']); | 116 | //console.log("<<< Proxy.setTallCallback", someParameters['result']); |
119 | return someParameters['result']; | 117 | return someParameters['result']; |
120 | }, | 118 | }, |
121 | 119 | ||
122 | //========================================================================= | 120 | //========================================================================= |
123 | 121 | ||
124 | 'registration': function (someParameters) { | 122 | 'registration': function (someParameters) { |
125 | return this.processMessage('registration', someParameters, 'REGISTER'); | 123 | return this.processMessage('registration', someParameters, 'REGISTER'); |
126 | }, | 124 | }, |
127 | 125 | ||
128 | 'handshake': function (someParameters) { | 126 | 'handshake': function (someParameters) { |
129 | return this.processMessage('handshake', someParameters, 'CONNECT'); | 127 | return this.processMessage('handshake', someParameters, 'CONNECT'); |
130 | }, | 128 | }, |
131 | 129 | ||
132 | 'message': function (someParameters) { | 130 | 'message': function (someParameters) { |
133 | return this.processMessage('message', someParameters, 'MESSAGE'); | 131 | return this.processMessage('message', someParameters, 'MESSAGE'); |
134 | }, | 132 | }, |
135 | 133 | ||
136 | 'logout': function (someParameters) { | 134 | 'logout': function (someParameters) { |
137 | return this.processMessage('logout', someParameters, 'MESSAGE'); | 135 | return this.processMessage('logout', someParameters, 'MESSAGE'); |
138 | }, | 136 | }, |
139 | 137 | ||
140 | //========================================================================= | 138 | //========================================================================= |
141 | 139 | ||
142 | 'processMessage': function (aFunctionName, someParameters, aRequestType) { | 140 | 'processMessage': function (aFunctionName, someParameters, aRequestType) { |
143 | vardeferredResult; | 141 | vardeferredResult; |
144 | 142 | ||
145 | deferredResult = new MochiKit.Async.Deferred(); | 143 | deferredResult = new MochiKit.Async.Deferred(); |
146 | deferredResult.addCallback(MochiKit.Base.method(this, 'payToll', aRequestType)); | 144 | deferredResult.addCallback(MochiKit.Base.method(this, 'payToll', aRequestType)); |
147 | deferredResult.addCallback(MochiKit.Base.method(this, 'sendMessage', aFunctionName)); | 145 | deferredResult.addCallback(MochiKit.Base.method(this, 'sendMessage', aFunctionName)); |
148 | deferredResult.addCallback(MochiKit.Base.method(this, 'setTollCallback')); | 146 | deferredResult.addCallback(MochiKit.Base.method(this, 'setTollCallback')); |
149 | deferredResult.callback(someParameters); | 147 | deferredResult.callback(someParameters); |
150 | 148 | ||
151 | return deferredResult; | 149 | return deferredResult; |
152 | }, | 150 | }, |
153 | 151 | ||
154 | //========================================================================= | 152 | //========================================================================= |
155 | 153 | ||
156 | 'sendMessage': function () { | 154 | 'sendMessage': function () { |
157 | throw Clipperz.Base.exception.AbstractMethod; | 155 | throw Clipperz.Base.exception.AbstractMethod; |
158 | }, | 156 | }, |
159 | 157 | ||
160 | //========================================================================= | 158 | //========================================================================= |
161 | 159 | ||
162 | 'isReadOnly': function () { | 160 | 'isReadOnly': function () { |
163 | return false; | 161 | return false; |
164 | }, | 162 | }, |
165 | 163 | ||
166 | //========================================================================= | 164 | //========================================================================= |
167 | __syntaxFix__: "syntax fix" | 165 | __syntaxFix__: "syntax fix" |
168 | 166 | ||
169 | }); | 167 | }); |