Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/UI/Common/Controllers/ProgressBarController.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/PM/UI/Common/Controllers/ProgressBarController.js | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/UI/Common/Controllers/ProgressBarController.js b/frontend/gamma/js/Clipperz/PM/UI/Common/Controllers/ProgressBarController.js new file mode 100644 index 0000000..a4fa400 --- a/dev/null +++ b/frontend/gamma/js/Clipperz/PM/UI/Common/Controllers/ProgressBarController.js | |||
@@ -0,0 +1,143 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2011 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz's Javascript Crypto Library. | ||
6 | Javascript Crypto Library provides web developers with an extensive | ||
7 | and efficient set of cryptographic functions. The library aims to | ||
8 | obtain maximum execution speed while preserving modularity and | ||
9 | reusability. | ||
10 | For further information about its features and functionalities please | ||
11 | refer to http://www.clipperz.com | ||
12 | |||
13 | * Javascript Crypto Library is free software: you can redistribute | ||
14 | it and/or modify it under the terms of the GNU Affero General Public | ||
15 | License as published by the Free Software Foundation, either version | ||
16 | 3 of the License, or (at your option) any later version. | ||
17 | |||
18 | * Javascript Crypto Library is distributed in the hope that it will | ||
19 | be useful, but WITHOUT ANY WARRANTY; without even the implied | ||
20 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
21 | See the GNU Affero General Public License for more details. | ||
22 | |||
23 | * You should have received a copy of the GNU Affero General Public | ||
24 | License along with Javascript Crypto Library. If not, see | ||
25 | <http://www.gnu.org/licenses/>. | ||
26 | |||
27 | */ | ||
28 | |||
29 | Clipperz.Base.module('Clipperz.PM.UI.Common.Controllers'); | ||
30 | |||
31 | Clipperz.PM.UI.Common.Controllers.ProgressBarController = function(args) { | ||
32 | args = args || {}; | ||
33 | |||
34 | this._numberOfSteps= 0; | ||
35 | this._currentStep= 0; | ||
36 | |||
37 | MochiKit.Signal.connect(Clipperz.Signal.NotificationCenter, 'initProgress', this, 'initProgressHandle'); | ||
38 | MochiKit.Signal.connect(Clipperz.Signal.NotificationCenter, 'updateProgress',this, 'updateProgressHandle'); | ||
39 | MochiKit.Signal.connect(Clipperz.Signal.NotificationCenter, 'advanceProgress',this, 'advanceProgressHandle'); | ||
40 | MochiKit.Signal.connect(Clipperz.Signal.NotificationCenter, 'progressDone', this, 'progressDoneHandle'); | ||
41 | |||
42 | return this; | ||
43 | } | ||
44 | |||
45 | MochiKit.Base.update(Clipperz.PM.UI.Common.Controllers.ProgressBarController.prototype, { | ||
46 | |||
47 | 'toString': function() { | ||
48 | return "Clipperz.PM.UI.Common.Controllers.ProgressBarController"; | ||
49 | }, | ||
50 | |||
51 | //----------------------------------------------------------------------------- | ||
52 | |||
53 | 'numberOfSteps': function() { | ||
54 | return this._numberOfSteps; | ||
55 | }, | ||
56 | |||
57 | 'setNumberOfSteps': function (aValue) { | ||
58 | this._numberOfSteps = aValue; | ||
59 | }, | ||
60 | |||
61 | 'updateNumberOfSteps': function (aValue) { | ||
62 | this._numberOfSteps += aValue; | ||
63 | }, | ||
64 | |||
65 | //----------------------------------------------------------------------------- | ||
66 | |||
67 | 'currentStep': function() { | ||
68 | return this._currentStep; | ||
69 | }, | ||
70 | |||
71 | 'advanceCurrentStep': function () { | ||
72 | this._currentStep ++; | ||
73 | }, | ||
74 | |||
75 | //----------------------------------------------------------------------------- | ||
76 | |||
77 | 'completedPercentage': function () { | ||
78 | var result; | ||
79 | //Clipperz.log(">>> completedPercentage" + this.currentStep() + "/" + this.numberOfSteps(), this.currentStep() / this.numberOfSteps()); | ||
80 | if (this.numberOfSteps() == 0) { | ||
81 | result = 0; | ||
82 | } else { | ||
83 | result = (Math.min(100, 100 * (this.currentStep() / this.numberOfSteps()))); | ||
84 | } | ||
85 | //Clipperz.log("<<< completedPercentage", result); | ||
86 | return result; | ||
87 | }, | ||
88 | |||
89 | //----------------------------------------------------------------------------- | ||
90 | |||
91 | 'resetStatus': function () { | ||
92 | this._numberOfSteps= 0; | ||
93 | this._currentStep= 0; | ||
94 | }, | ||
95 | |||
96 | //----------------------------------------------------------------------------- | ||
97 | |||
98 | 'updateProgress': function () { | ||
99 | //Clipperz.log(">>> updateProgress: " + this.completedPercentage() + "%"); | ||
100 | MochiKit.Signal.signal(this, 'updateProgress', this.completedPercentage()); | ||
101 | }, | ||
102 | |||
103 | //============================================================================= | ||
104 | |||
105 | 'initProgressHandle': function (anEvent) { | ||
106 | //Clipperz.log(">>> initProgressHandle - steps: " + (anEvent != null ? anEvent['steps'] : 0)); | ||
107 | this.resetStatus(); | ||
108 | if (anEvent != null) { | ||
109 | this.setNumberOfSteps(anEvent['steps']); | ||
110 | } | ||
111 | MochiKit.Signal.signal(this, 'initProgress'); | ||
112 | this.updateProgress(); | ||
113 | }, | ||
114 | |||
115 | //............................................................................. | ||
116 | |||
117 | 'updateProgressHandle': function (anEvent) { | ||
118 | this.updateNumberOfSteps(anEvent['extraSteps']); | ||
119 | //Clipperz.log("=== updateProgressHandle - steps: " + this.numberOfSteps() + " (extra " + anEvent['extraSteps'] + ")"); | ||
120 | this.updateProgress(); | ||
121 | }, | ||
122 | |||
123 | //............................................................................. | ||
124 | |||
125 | 'advanceProgressHandle': function (anEvent) { | ||
126 | this.advanceCurrentStep(); | ||
127 | //Clipperz.log("--- advanceProgressHandle: " + this.currentStep() + "/" + this.numberOfSteps()); | ||
128 | this.updateProgress(); | ||
129 | }, | ||
130 | |||
131 | //............................................................................. | ||
132 | |||
133 | 'progressDoneHandle': function (anEvent) { | ||
134 | //Clipperz.log("<<< progressDoneHandle: " + this.currentStep() + "/" + this.numberOfSteps()); | ||
135 | this.resetStatus(); | ||
136 | MochiKit.Signal.signal(this, 'progressDone'); | ||
137 | }, | ||
138 | |||
139 | //============================================================================= | ||
140 | __syntaxFix__: "syntax fix" | ||
141 | }); | ||
142 | |||
143 | Clipperz.PM.UI.Common.Controllers.ProgressBarController.defaultController = new Clipperz.PM.UI.Common.Controllers.ProgressBarController(); | ||