summaryrefslogtreecommitdiff
path: root/frontend/beta/js/Clipperz/PM/Components/RecordDetail/CreationWizard.js
authorGiulio Cesare Solaroli <giulio.cesare@clipperz.com>2011-10-02 23:56:18 (UTC)
committer Giulio Cesare Solaroli <giulio.cesare@clipperz.com>2011-10-02 23:56:18 (UTC)
commitef68436ac04da078ffdcacd7e1f785473a303d45 (patch) (unidiff)
treec403752d66a2c4775f00affd4fa8431b29c5b68c /frontend/beta/js/Clipperz/PM/Components/RecordDetail/CreationWizard.js
parent597ecfbc0249d83e1b856cbd558340c01237a360 (diff)
downloadclipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.zip
clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.gz
clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.bz2
First version of the newly restructured repository
Diffstat (limited to 'frontend/beta/js/Clipperz/PM/Components/RecordDetail/CreationWizard.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/beta/js/Clipperz/PM/Components/RecordDetail/CreationWizard.js317
1 files changed, 317 insertions, 0 deletions
diff --git a/frontend/beta/js/Clipperz/PM/Components/RecordDetail/CreationWizard.js b/frontend/beta/js/Clipperz/PM/Components/RecordDetail/CreationWizard.js
new file mode 100644
index 0000000..a92285f
--- a/dev/null
+++ b/frontend/beta/js/Clipperz/PM/Components/RecordDetail/CreationWizard.js
@@ -0,0 +1,317 @@
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.RecordDetail) == 'undefined') { Clipperz.PM.Components.RecordDetail = {}; }
33
34//#############################################################################
35
36Clipperz.PM.Components.RecordDetail.CreationWizard = function(anElement, args) {
37 args = args || {};
38
39 Clipperz.PM.Components.RecordDetail.CreationWizard.superclass.constructor.call(this, anElement, args);
40
41 this._mainComponent = args.mainComponent;
42 this._previouslySelectedRecord = args.previouslySelectedRecord;
43//MochiKit.Logging.logDebug("--- new CreationWizard - previouslySelectedRecord: " + args.previouslySelectedRecord);
44 this._createButton_header = null;
45 this._createButton_footer = null;
46
47 this._cancelButton_header = null;
48 this._cancelButton_footer = null;
49
50 this.render();
51
52 return this;
53}
54
55//=============================================================================
56
57YAHOO.extendX(Clipperz.PM.Components.RecordDetail.CreationWizard, Clipperz.PM.Components.BaseComponent, {
58
59 'toString': function() {
60 return "Clipperz.PM.Components.RecordDetail.CreationWizard component";
61 },
62
63 //-------------------------------------------------------------------------
64
65 'previouslySelectedRecord': function() {
66 return this._previouslySelectedRecord;
67 },
68
69 //-------------------------------------------------------------------------
70
71 'render': function() {
72 vartemplateListElement;
73 vartemplates;
74
75 this.element().update("");
76
77 Clipperz.YUI.DomHelper.append(this.element().dom,
78 {tag:'form', cls:'recordDataFORM', id:this.getId('form'), children:[
79 {tag:'div', id:'recordDetailDataBox', cls:'recordDetailDataBox', children:[
80 {tag:'div', id:this.getId('wizardBox'), cls:'recordCreationWizard', children:[
81 {tag:'div', id:this.getId('recordCreationWizardTitleBox'), cls:'recordCreationWizardTitleBox', htmlString:Clipperz.PM.Strings['newRecordWizardTitleBox']},
82 {tag:'ul', id:this.getId('templateList'), cls:'radioList'}
83 ]}
84 ]}
85 ]}
86 );
87
88 Clipperz.YUI.DomHelper.append(this.getDom('recordCreationWizardTitleBox'), {tag:'div', cls:'newRecordWizardHeader', children:[
89 {tag:'table', width:'100%', cellpadding:'5', children:[
90 {tag:'tbody', children:[
91 {tag:'tr', children:[
92 {tag:'td', width:'49%', align:'right', children:[
93 {tag:'div', id:this.getId('cancelButton_header')}
94 ]},
95 {tag:'td', width:'10', html:'&nbsp;'},
96 {tag:'td', width:'49%', align:'left', children:[
97 {tag:'div', id:this.getId('createButton_header')}
98 ]}
99 ]}
100 ]}
101 ]}
102 ]});
103
104 templateListElement = this.getElement('templateList');
105 templates = Clipperz.PM.Strings['recordTemplates'];
106 MochiKit.Iter.forEach(MochiKit.Base.keys(templates), MochiKit.Base.bind(function(aTemplateKey) {
107 Clipperz.YUI.DomHelper.append(templateListElement.dom, {tag:'li', children:[
108 {tag:'table', children:[
109 {tag:'tbody', children:[
110 {tag:'tr', children:[
111 {tag:'td', valign:'top', children:[
112 {tag:'input', id:this.getId(aTemplateKey+"_radio"), type:'radio', name:'recordTemplate', value:"aTemplateKey"}
113 ]},
114 {tag:'td', valign:'top', children:[
115 {tag:'h4', id:this.getId(aTemplateKey+"_title"), html:templates[aTemplateKey]['title']},
116 {tag:'div', cls:'templateDescription', htmlString:templates[aTemplateKey]['description']}
117 ]}
118 ]}
119 ]}
120 ]}
121 ]});
122 this.getElement(aTemplateKey+"_radio").dom.value = aTemplateKey;
123 MochiKit.Signal.connect(this.getDom(aTemplateKey+"_title"), 'onclick', MochiKit.Base.partial(function(aRadioButton) {aRadioButton.click();}, this.getDom(aTemplateKey+"_radio")));
124 }, this));
125
126 Clipperz.YUI.DomHelper.append(templateListElement.dom, {tag:'li', children:[
127 {tag:'table', children:[
128 {tag:'tbody', children:[
129 {tag:'tr', children:[
130 {tag:'td', valign:'top', children:[
131 {tag:'input', type:'radio', name:'recordTemplate', id:this.getId('bookmarkletRadioButton'), value:'BookmarkletConfigurationTemplate'}
132 ]},
133 {tag:'td', valign:'top', children:[
134 {tag:'h4', htmlString:Clipperz.PM.Strings['newRecordWizardBookmarkletConfigurationTitle']},
135 {tag:'div', cls:'templateDescription', htmlString:Clipperz.PM.Strings['newRecordWizardBookmarkletConfigurationDescription']},
136 {tag:'div', cls:'bookmarkletConfiguration', children:[
137 // {tag:'span', htmlString:Clipperz.PM.Strings['newRecordWizardBookmarkletConfigurationLabel']},
138 {tag:'div', htmlString:Clipperz.PM.Strings['recordDetailNewDirectLoginDescription']},
139 {tag:'textarea', id:this.getId('bookmarkletConfiguration')}
140 ]}
141 ]}
142 ]}
143 ]}
144 ]}
145 ]});
146
147 Clipperz.YUI.DomHelper.append(this.getDom('wizardBox'), {tag:'div', cls:'newRecordWizardFooter', children:[
148 {tag:'table', width:'100%', cellpadding:'5', children:[
149 {tag:'tbody', children:[
150 {tag:'tr', children:[
151 {tag:'td', width:'49%', align:'right', children:[
152 {tag:'div', id:this.getId('cancelButton_footer')}
153 ]},
154 {tag:'td', width:'10', html:'&nbsp;'},
155 {tag:'td', width:'49%', align:'left', children:[
156 {tag:'div', id:this.getId('createButton_footer')}
157 ]}
158 ]}
159 ]}
160 ]}
161 ]});
162
163 this.setCreateButton_header(new YAHOO.ext.Button(this.getDom('createButton_header'), {text:Clipperz.PM.Strings['newRecordWizardCreateButtonLabel'], handler:this.createRecord, scope:this}));
164 this.setCreateButton_footer(new YAHOO.ext.Button(this.getDom('createButton_footer'), {text:Clipperz.PM.Strings['newRecordWizardCreateButtonLabel'], handler:this.createRecord, scope:this}));
165
166 this.setCancelButton_header(new YAHOO.ext.Button(this.getDom('cancelButton_header'), {text:Clipperz.PM.Strings['newRecordWizardCancelButtonLabel'], handler:this.exitWizard, scope:this}));
167 this.setCancelButton_footer(new YAHOO.ext.Button(this.getDom('cancelButton_footer'), {text:Clipperz.PM.Strings['newRecordWizardCancelButtonLabel'], handler:this.exitWizard, scope:this}));
168
169 this.createButton_header().disable();
170 this.createButton_footer().disable();
171
172 MochiKit.Iter.forEach(this.getElement('form').getChildrenByTagName('input'), MochiKit.Base.bind(function(anInput) {
173 // MochiKit.Signal.connect(anInput.dom, 'onchange', this, 'enableCreateButton');
174 MochiKit.Signal.connect(anInput.dom, 'onclick', this, 'enableCreateButton'); //for Safari
175 },this));
176
177 MochiKit.Signal.connect(this.getDom('bookmarkletConfiguration'), 'onkeyup', this, 'enableCreateButton');
178 MochiKit.Signal.connect(this.getDom('bookmarkletConfiguration'), 'onkeydown', this, 'enableCreateButton'); //for Safari
179 },
180
181 //-------------------------------------------------------------------------
182
183 'createButton_header': function() {
184 return this._createButton_header;
185 },
186
187 'setCreateButton_header': function(aValue) {
188 this._createButton_header = aValue;
189 },
190
191 //.........................................................................
192
193 'createButton_footer': function() {
194 return this._createButton_footer;
195 },
196
197 'setCreateButton_footer': function(aValue) {
198 this._createButton_footer = aValue;
199 },
200
201
202 //-------------------------------------------------------------------------
203
204 'cancelButton_header': function() {
205 return this._cancelButton_header;
206 },
207
208 'setCancelButton_header': function(aValue) {
209 this._cancelButton_header = aValue;
210 },
211
212 //.........................................................................
213
214 'cancelButton_footer': function() {
215 return this._cancelButton_footer;
216 },
217
218 'setCancelButton_footer': function(aValue) {
219 this._cancelButton_footer = aValue;
220 },
221
222 //-------------------------------------------------------------------------
223
224 'enableCreateButton': function(anEvent, skipKeyDownCheck) {
225//MochiKit.Logging.logDebug(">>> CreationWizard.enableCreateButton (" + anEvent.type() + ")");
226 if ((anEvent.type() == "keydown") && (skipKeyDownCheck != true)) {
227//MochiKit.Logging.logDebug("--- CreationWizard.enableCreateButton - handling 'keydown' event with a postponed execution of the check");
228 MochiKit.Async.callLater(0.3, MochiKit.Base.method(this, 'enableCreateButton', anEvent, true));
229 } else {
230 var shouldEnableCreateButton;
231 var isBookmarkletConfigurationEmpty;
232
233//MochiKit.Logging.logDebug("--- CreationWizard.enableCreateButton - common execution");
234
235 shouldEnableCreateButton = true;
236
237 isBookmarkletConfigurationEmpty = !/[^ \n]/.test(this.getDom('bookmarkletConfiguration').value);
238//MochiKit.Logging.logDebug("--- CreationWizard.enableCreateButton - isBookmarkletConfigurationEmpty: " + isBookmarkletConfigurationEmpty);
239
240 if ((anEvent.src() == this.getDom('bookmarkletConfiguration')) && !isBookmarkletConfigurationEmpty) {
241 this.getDom('bookmarkletRadioButton').checked = true;
242 }
243
244 if ((this.getDom('bookmarkletRadioButton').checked) && isBookmarkletConfigurationEmpty) {
245 shouldEnableCreateButton = false;
246 }
247
248 if (shouldEnableCreateButton) {
249//MochiKit.Logging.logDebug("--- CreationWizard.enableCreateButton - enabling button");
250 this.createButton_header().enable();
251 this.createButton_footer().enable();
252 } else {
253//MochiKit.Logging.logDebug("--- CreationWizard.enableCreateButton - disabling button");
254 this.createButton_header().disable();
255 this.createButton_footer().disable();
256 }
257 }
258//MochiKit.Logging.logDebug("<<< CreationWizard.enableCreateButton");
259 },
260
261 //-------------------------------------------------------------------------
262
263 'createRecord': function() {
264 varselectedTemplateKey;
265 varnewRecord;
266
267 selectedTemplateKey = MochiKit.Base.filter(function(aCheckBoxElement) {
268 return aCheckBoxElement.dom.checked;
269 },this.getElement('form').getChildrenByTagName('input'))[0].dom.value;
270
271//MochiKit.Logging.logDebug("--- CreationWizard.createRecord - selectedTemplateKey: " + selectedTemplateKey);
272 if (selectedTemplateKey == 'BookmarkletConfigurationTemplate') {
273 var bookmarkletConfiguration;
274
275 this.mainComponent().exitModalView();
276 bookmarkletConfiguration = Clipperz.PM.BookmarkletProcessor.checkBookmarkletConfiguration(this.getDom('bookmarkletConfiguration').value, this.getDom('createButton'), MochiKit.Base.method(this.mainComponent(), 'enterModalView'));
277 this.mainComponent().enterModalView();
278 newRecord = Clipperz.PM.BookmarkletProcessor.createRecordFromBookmarkletConfiguration(this.mainComponent().user(), bookmarkletConfiguration);
279 } else {
280 varfieldsConfigurations;
281
282 newRecord = this.mainComponent().user().addNewRecord();
283 newRecord.setLabel(Clipperz.PM.Strings['recordTemplates'][selectedTemplateKey]['title']);
284
285 fieldsConfigurations = Clipperz.PM.Strings['recordTemplates'][selectedTemplateKey]['fields'];
286
287 MochiKit.Iter.forEach(fieldsConfigurations, MochiKit.Base.partial(function(aRecord, aFieldConfiguration) {
288 var newField;
289
290 newField = new Clipperz.PM.DataModel.RecordField({recordVersion:aRecord.currentVersion()});
291 newField.setLabel(aFieldConfiguration['label']);
292 newField.setType(aFieldConfiguration['type']);
293 aRecord.currentVersion().addField(newField);
294 }, newRecord));
295 }
296
297 this.mainComponent().exitWizard(newRecord, true);
298 },
299
300 //-------------------------------------------------------------------------
301
302 'exitWizard': function() {
303//MochiKit.Logging.logDebug(">>> CreationWizard.exitWizard - " + this.previouslySelectedRecord());
304 this.mainComponent().exitWizard(this.previouslySelectedRecord());
305//MochiKit.Logging.logDebug("<<< CreationWizard.exitWizard");
306 },
307
308 //-------------------------------------------------------------------------
309
310 'mainComponent': function() {
311 return this._mainComponent;
312 },
313
314 //-------------------------------------------------------------------------
315 __syntaxFix__: "syntax fix"
316});
317