summaryrefslogtreecommitdiff
path: root/frontend/beta/js/Clipperz/PM/Components/Import/ClipperzImportComponent.js
Unidiff
Diffstat (limited to 'frontend/beta/js/Clipperz/PM/Components/Import/ClipperzImportComponent.js') (more/less context) (show whitespace changes)
-rw-r--r--frontend/beta/js/Clipperz/PM/Components/Import/ClipperzImportComponent.js212
1 files changed, 212 insertions, 0 deletions
diff --git a/frontend/beta/js/Clipperz/PM/Components/Import/ClipperzImportComponent.js b/frontend/beta/js/Clipperz/PM/Components/Import/ClipperzImportComponent.js
new file mode 100644
index 0000000..50dcb93
--- a/dev/null
+++ b/frontend/beta/js/Clipperz/PM/Components/Import/ClipperzImportComponent.js
@@ -0,0 +1,212 @@
1/*
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer 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
29if (typeof(Clipperz) == 'undefined') { Clipperz = {}; }
30if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; }
31if (typeof(Clipperz.PM.Components) == 'undefined') { Clipperz.PM.Components = {}; }
32if (typeof(Clipperz.PM.Components.Import) == 'undefined') { Clipperz.PM.Components.Import = {}; }
33
34//#############################################################################
35
36Clipperz.PM.Components.Import.ClipperzImportComponent = function(anElement, args) {
37 args = args || {};
38
39 Clipperz.PM.Components.Import.ClipperzImportComponent.superclass.constructor.call(this, anElement, args);
40
41 this.render();
42
43 return this;
44}
45
46//=============================================================================
47
48YAHOO.extendX(Clipperz.PM.Components.Import.ClipperzImportComponent, Clipperz.PM.Components.Import.GenericImportComponent, {
49
50 'toString': function() {
51 return "Clipperz.PM.Components.Import.ClipperzImportComponent component";
52 },
53
54 //-------------------------------------------------------------------------
55
56 'render': function() {
57//MochiKit.Logging.logDebug(">>> Import.ClipperzImportComponent.render");
58 this.domHelper().append(this.element(), {tag:'div', cls:'clipperzImportWizard', children:[
59 {tag:'h3', htmlString:Clipperz.PM.Strings['Clipperz_ImportWizard_Title']},
60 {tag:'div', cls:'importSteps', id:this.getId('importSteps')},
61 {tag:'div', cls:'importStepBlocks', children:[
62 {tag:'div', cls:'step_0', id:this.getId('step_0'), children:[
63 {tag:'div', children:[
64 {tag:'div', cls:'importOptionsDescription', htmlString:Clipperz.PM.Strings['importOptions_clipperz_description']},
65 {tag:'div', cls:'importOptionsParameters', children:[]},
66 this.textAreaConfig()
67 ]}
68 ]},
69 {tag:'div', cls:'step_1', id:this.getId('step_1'), children:[
70 {tag:'div', children:[
71 {tag:'div', id:this.getId('previewDiv'), html:"preview"}
72 ]}
73 ]},
74 {tag:'div', cls:'step_2', id:this.getId('step_2'), children:[
75 {tag:'div', children:[
76 {tag:'h4', html:"done"}
77 ]}
78 ]}
79 ]},
80 {tag:'div', cls:'importOptionsButtons', children:[
81 {tag:'table', children:[
82 {tag:'tbody', children:[
83 {tag:'tr', children:[
84 {tag:'td', html:'&nbsp;'},
85 {tag:'td', children:[
86 {tag:'div', id:this.getId('backActionButton')}
87 ]},
88 {tag:'td', html:'&nbsp;'},
89 {tag:'td', children:[
90 {tag:'div', id:this.getId('nextActionButton')}
91 ]},
92 {tag:'td', html:'&nbsp;'}
93 ]}
94 ]}
95 ]}
96 ]}
97 ]});
98
99 this.updateSteps();
100
101 this.setBackButton(new YAHOO.ext.Button(this.getDom('backActionButton'), {text:"back", handler:this.backAction, scope:this}));
102 this.setNextButton(new YAHOO.ext.Button(this.getDom('nextActionButton'), {text:"next", handler:this.nextAction, scope:this}));
103
104 this.getElement('step_0').setVisibilityMode(YAHOO.ext.Element.DISPLAY).show()
105 this.getElement('step_1').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide();
106 this.getElement('step_2').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide();
107//MochiKit.Logging.logDebug("<<< Import.ClipperzImportComponent.render");
108 },
109
110 //-------------------------------------------------------------------------
111
112 'nextAction': function() {
113 switch (this.currentStep()) {
114 case 0: //-> 1
115 this.previewValues();
116 break;
117 case 1: //-> 2
118 this.importValues();
119 break;
120 }
121 },
122
123 //-------------------------------------------------------------------------
124
125 'deferredPreviewValues': function() {
126 var deferredResult;
127
128 deferredResult = new MochiKit.Async.Deferred();
129 deferredResult.addCallback(MochiKit.Base.bind(function(res) {
130 this.startProcessing();
131
132 return res;
133 }, this));
134 deferredResult.addCallback(MochiKit.Base.method(this, 'processClipperzValues'));
135 deferredResult.addCallback(MochiKit.Base.method(this, 'setProcessedValues'));
136 deferredResult.addCallback(MochiKit.Base.method(this, 'previewRecordValues'));
137 deferredResult.addCallback(MochiKit.Base.bind(function(res) {
138 this.processingDone();
139 this.getElement('step_0').hide();
140 this.getElement('step_1').show();
141 this.backButton().enable();
142
143 return res;
144 }, this));
145 // deferredResult.addErrback(MochiKit.Base.bind(function() {
146 // this.processingAborted();
147 // }, this))
148 deferredResult.callback(this.textAreaContent());
149
150 return deferredResult;
151 },
152
153 //-------------------------------------------------------------------------
154
155 'processClipperzValues': function(someData) {
156 var deferredResult;
157
158 deferredResult = new MochiKit.Async.Deferred();
159//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.processClipperzValues - 1: " + res); return res;});
160 deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'parseImportData');
161//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.processClipperzValues - 2: " + res); return res;});
162 deferredResult.addCallback(Clipperz.Base.evalJSON);
163//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.processClipperzValues - 3: " + res); return res;});
164 deferredResult.addCallback(function(res) {
165 return Clipperz.NotificationCenter.deferredNotification(this, 'updatedProgressState', {steps:(res.length)}, res);
166 })
167//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.processClipperzValues - 4: " + res); return res;});
168 deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'previewImportData');
169//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.processClipperzValues - 5: " + res); return res;});
170 deferredResult.addCallback(MochiKit.Base.bind(function(someClipperzValues) {
171 var innerDeferredResult;
172 var records;
173 var i,c;
174
175 innerDeferredResult = new MochiKit.Async.Deferred();
176 records = [];
177
178 c = someClipperzValues.length;
179 for(i=0; i<c; i++) {
180 innerDeferredResult.addCallback(MochiKit.Async.wait, 0.2);
181 innerDeferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', {});
182 innerDeferredResult.addCallback(MochiKit.Base.bind(function(someRecords, someData) {
183 var record;
184 var recordVersion;
185
186//MochiKit.Logging.logDebug("=== someData: " + Clipperz.Base.serializeJSON(someData));
187 record = new Clipperz.PM.DataModel.Record({user:this.user()});
188 record.setLabel(someData['label']);
189 record.setShouldProcessData(true);
190 record.processData(someData);
191
192 someRecords.push(record);
193
194 return someRecords;
195 }, this), records, someClipperzValues[i]);
196 }
197 innerDeferredResult.addCallback(MochiKit.Async.succeed, records);
198 innerDeferredResult.callback();
199
200 return innerDeferredResult;
201 }, this));
202//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Record.processClipperzValues - 6: " + res); return res;});
203 deferredResult.callback(someData);
204
205 return deferredResult;
206 },
207
208
209 //-------------------------------------------------------------------------
210 __syntaxFix__: "syntax fix"
211});
212