author | Giulio Cesare Solaroli <giulio.cesare@solaroli.it> | 2011-10-03 16:04:12 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@solaroli.it> | 2011-10-03 16:04:12 (UTC) |
commit | 541bb378ddece2eab135a8066a16994e94436dea (patch) (unidiff) | |
tree | ff160ea3e26f7fe07fcfd401387c5a0232ca715e /frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportHeader.js | |
parent | 1bf431fd3d45cbdf4afa3e12afefe5d24f4d3bc7 (diff) | |
parent | ecad5e895831337216544e81f1a467e0c68c4a6a (diff) | |
download | clipperz-541bb378ddece2eab135a8066a16994e94436dea.zip clipperz-541bb378ddece2eab135a8066a16994e94436dea.tar.gz clipperz-541bb378ddece2eab135a8066a16994e94436dea.tar.bz2 |
Merge pull request #1 from gcsolaroli/master
First version of the restructured repository
Diffstat (limited to 'frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportHeader.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportHeader.js | 240 |
1 files changed, 240 insertions, 0 deletions
diff --git a/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportHeader.js b/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportHeader.js new file mode 100644 index 0000000..ebd243a --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportHeader.js | |||
@@ -0,0 +1,240 @@ | |||
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 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | ||
30 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | ||
31 | if (typeof(Clipperz.PM.Components) == 'undefined') { Clipperz.PM.Components = {}; } | ||
32 | if (typeof(Clipperz.PM.Components.Import) == 'undefined') { Clipperz.PM.Components.Import = {}; } | ||
33 | if (typeof(Clipperz.PM.Components.Import.CSVImport) == 'undefined') { Clipperz.PM.Components.Import.CSVImport = {}; } | ||
34 | |||
35 | //############################################################################# | ||
36 | |||
37 | Clipperz.PM.Components.Import.CSVImport.CSVImportHeader = function(anElement, args) { | ||
38 | args = args || {}; | ||
39 | |||
40 | Clipperz.PM.Components.Import.CSVImport.CSVImportHeader.superclass.constructor.call(this, anElement, args); | ||
41 | this._mainComponent = args.mainComponent; | ||
42 | |||
43 | this._pendingDeferredLabelFieldHandlerEvents = 0; | ||
44 | |||
45 | return this; | ||
46 | } | ||
47 | |||
48 | //============================================================================= | ||
49 | |||
50 | YAHOO.extendX(Clipperz.PM.Components.Import.CSVImport.CSVImportHeader, Clipperz.PM.Components.BaseComponent, { | ||
51 | |||
52 | 'toString': function() { | ||
53 | return "Clipperz.PM.Components.Import.CSVImport.CSVImportHeader component"; | ||
54 | }, | ||
55 | |||
56 | //------------------------------------------------------------------------- | ||
57 | |||
58 | 'mainComponent': function() { | ||
59 | return this._mainComponent; | ||
60 | }, | ||
61 | |||
62 | //------------------------------------------------------------------------- | ||
63 | |||
64 | 'render': function() { | ||
65 | var thConfigs; | ||
66 | var i,c; | ||
67 | |||
68 | //MochiKit.Logging.logDebug(">>> CSVImportHeader.render"); | ||
69 | Clipperz.NotificationCenter.unregister(this); | ||
70 | MochiKit.Signal.disconnectAllTo(this); | ||
71 | |||
72 | thConfigs = []; | ||
73 | c = this.mainComponent().parsedValues()[0].length; | ||
74 | for (i=0; i<c; i++) { | ||
75 | if (this.mainComponent().isColumnSelected(i)) { | ||
76 | // thConfigs.push({tag:'th', children:[{tag:'input', type:'text', id:this.getId('headerTextField_' + i), value:this.mainComponent().labelForColumn(i)}]}); | ||
77 | thConfigs.push({tag:'th', children:[{tag:'input', type:'text', id:this.getId('headerTextField_' + i), value:""}]}); | ||
78 | } | ||
79 | } | ||
80 | |||
81 | this.element().update(""); | ||
82 | this.domHelper().append(this.element(), {tag:'div', children:[ | ||
83 | {tag:'div', cls:'importStepDescription', htmlString:Clipperz.PM.Strings['CSV_ImportWizard_Header']}, | ||
84 | {tag:'div', cls:'importStepParameters', children:[ | ||
85 | {tag:'input', type:'checkbox', name:'isFistRowHeader', id:this.getId('isFirstRowHeader_checkbox')}, | ||
86 | {tag:'span', id:this.getId('isFirstRowHeader_span'), cls:'clickableSpan', htmlString:Clipperz.PM.Strings['CSV_ImportWizard_Header_Settings_firstRowHeaderLabel']} | ||
87 | ]}, | ||
88 | {tag:'div', id:this.getId('dataDiv'), children:[ | ||
89 | {tag:'div', cls:'csvImportPreview', children:[ | ||
90 | {tag:'table', id:this.getId('previewDada'), cls:'csvImportPreview header', cellspacing:'0', children:[ | ||
91 | {tag:'thead', children:[{tag:'tr', children:thConfigs}]}, | ||
92 | {tag:'tbody', id:this.getId('previewData_tbody')} | ||
93 | ]} | ||
94 | ]} | ||
95 | ]} | ||
96 | ]}); | ||
97 | |||
98 | for (i=0; i<c; i++) { | ||
99 | if (this.mainComponent().isColumnSelected(i)) { | ||
100 | this.getElement('headerTextField_' + i).dom.value = this.mainComponent().labelForColumn(i); | ||
101 | } | ||
102 | } | ||
103 | |||
104 | this.renderData(this.getElement('previewData_tbody'), this.mainComponent().parsedValues()); | ||
105 | |||
106 | if (this.mainComponent().isFirstRowHeader()) { | ||
107 | this.getDom('isFirstRowHeader_checkbox').click(); | ||
108 | } | ||
109 | |||
110 | c = this.mainComponent().parsedValues()[0].length; | ||
111 | for (i=0; i<c; i++) { | ||
112 | if (this.mainComponent().isColumnSelected(i)) { | ||
113 | MochiKit.Signal.connect(this.getDom('headerTextField_' + i), 'onchange', MochiKit.Base.partial(MochiKit.Base.method(this, 'labelFieldHandler'), i)); | ||
114 | MochiKit.Signal.connect(this.getDom('headerTextField_' + i), 'onkeypress', MochiKit.Base.partial(MochiKit.Base.method(this, 'deferredLabelFieldHandler'), i)); | ||
115 | } | ||
116 | } | ||
117 | |||
118 | MochiKit.Signal.connect(this.getDom('isFirstRowHeader_checkbox'), 'onclick', this, 'toggleFirstRowHeaderCheckboxHandler'); | ||
119 | if (Clipperz_IEisBroken != true) { | ||
120 | MochiKit.Signal.connect(this.getDom('isFirstRowHeader_span'), 'onclick', this.getDom('isFirstRowHeader_checkbox'), 'click'); | ||
121 | } | ||
122 | //MochiKit.Logging.logDebug("<<< CSVImportHeader.render"); | ||
123 | }, | ||
124 | |||
125 | //------------------------------------------------------------------------- | ||
126 | |||
127 | 'renderData': function(anElement, someData) { | ||
128 | var trConfigs; | ||
129 | var data; | ||
130 | var i,c; | ||
131 | |||
132 | // anElement.update(""); | ||
133 | MochiKit.DOM.replaceChildNodes(anElement.dom); | ||
134 | |||
135 | if (this.mainComponent().isFirstRowHeader()) { | ||
136 | data = someData.slice(1); | ||
137 | } else { | ||
138 | data = someData; | ||
139 | } | ||
140 | |||
141 | trConfigs = MochiKit.Base.map(MochiKit.Base.bind(function(aRowData) { | ||
142 | var result; | ||
143 | var i,c; | ||
144 | |||
145 | result = {tag:'tr', children:[]}; | ||
146 | c = aRowData.length; | ||
147 | for (i=0; i<c; i++) { | ||
148 | if (this.mainComponent().isColumnSelected(i)) { | ||
149 | result.children.push({tag:'td', valign:'top', html:(MochiKit.Base.isNotEmpty(aRowData[i]) ? aRowData[i].replace(/\n/g, '<br>') : ' ')}); | ||
150 | } | ||
151 | } | ||
152 | |||
153 | return result; | ||
154 | }, this), data); | ||
155 | |||
156 | MochiKit.Base.map(function(aRowConfig) {Clipperz.YUI.DomHelper.append(anElement, aRowConfig);}, trConfigs); | ||
157 | |||
158 | Clipperz.Style.applyZebraStylesToTable(this.getId('previewDada')); | ||
159 | }, | ||
160 | |||
161 | //------------------------------------------------------------------------- | ||
162 | |||
163 | 'toggleFirstRowHeaderCheckboxHandler': function() { | ||
164 | var firstRowData; | ||
165 | var i,c; | ||
166 | |||
167 | //MochiKit.Logging.logDebug(">>> toggleFirstRowHeaderCheckboxHandler"); | ||
168 | this.mainComponent().setIsFirstRowHeader(this.getDom('isFirstRowHeader_checkbox').checked); | ||
169 | |||
170 | firstRowData = this.mainComponent().parsedValues()[0]; | ||
171 | |||
172 | c = firstRowData.length; | ||
173 | for (i=0; i<c; i++) { | ||
174 | if (this.mainComponent().isColumnSelected(i)) { | ||
175 | var label; | ||
176 | |||
177 | if (this.mainComponent().isFirstRowHeader()) { | ||
178 | label = firstRowData[i]; | ||
179 | } else { | ||
180 | label = null; | ||
181 | } | ||
182 | |||
183 | this.mainComponent().setLabelForColumn(label, i); | ||
184 | } | ||
185 | }; | ||
186 | |||
187 | this.updateInputFieldValues(); | ||
188 | this.renderData(this.getElement('previewData_tbody'), this.mainComponent().parsedValues()); | ||
189 | //MochiKit.Logging.logDebug("<<< toggleFirstRowHeaderCheckboxHandler"); | ||
190 | }, | ||
191 | |||
192 | //------------------------------------------------------------------------- | ||
193 | |||
194 | 'updateInputFieldValues': function() { | ||
195 | var i,c; | ||
196 | |||
197 | //MochiKit.Logging.logDebug(">>> updateInputFieldValues"); | ||
198 | c = this.mainComponent().parsedValues()[0].length; | ||
199 | for (i=0; i<c; i++) { | ||
200 | if (this.mainComponent().isColumnSelected(i)) { | ||
201 | this.getDom('headerTextField_' + i).value = this.mainComponent().labelForColumn(i); | ||
202 | } | ||
203 | } | ||
204 | //console.log('[1] fieldSettings', fieldSettings); | ||
205 | //MochiKit.Logging.logDebug("<<< updateInputFieldValues"); | ||
206 | }, | ||
207 | |||
208 | //------------------------------------------------------------------------- | ||
209 | |||
210 | 'labelFieldHandler': function(aColumnIndex, anEvent) { | ||
211 | var inputField; | ||
212 | |||
213 | //MochiKit.Logging.logDebug(">>> labelFieldHandler"); | ||
214 | inputField = anEvent.src(); | ||
215 | |||
216 | this.mainComponent().setLabelForColumn(inputField.value, aColumnIndex); | ||
217 | //MochiKit.Logging.logDebug("##### [" + anEvent.src().id + "] -> label[" + aColumnIndex + "]: '" + inputField.value + "'"); | ||
218 | //MochiKit.Logging.logDebug("<<< labelFieldHandler"); | ||
219 | }, | ||
220 | |||
221 | 'deferredLabelFieldHandler': function(aColumnIndex, anEvent) { | ||
222 | //MochiKit.Logging.logDebug(">>> deferredLabelFieldHandler"); | ||
223 | this._pendingDeferredLabelFieldHandlerEvents ++; | ||
224 | MochiKit.Async.callLater(1, MochiKit.Base.partial(MochiKit.Base.method(this, 'deferredLabelFieldHandlerCatcher'), aColumnIndex, anEvent)); | ||
225 | //MochiKit.Logging.logDebug("<<< deferredLabelFieldHandler"); | ||
226 | }, | ||
227 | |||
228 | 'deferredLabelFieldHandlerCatcher': function(aColumnIndex, anEvent) { | ||
229 | //MochiKit.Logging.logDebug(">>> deferredLabelFieldHandlerCatcher"); | ||
230 | this._pendingDeferredLabelFieldHandlerEvents --; | ||
231 | if (this._pendingDeferredLabelFieldHandlerEvents == 0) { | ||
232 | this.labelFieldHandler(aColumnIndex, anEvent); | ||
233 | } | ||
234 | //MochiKit.Logging.logDebug("<<< deferredLabelFieldHandlerCatcher"); | ||
235 | }, | ||
236 | |||
237 | //------------------------------------------------------------------------- | ||
238 | __syntaxFix__: "syntax fix" | ||
239 | }); | ||
240 | |||