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/CSVImportFields.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/CSVImportFields.js') (more/less context) (show whitespace changes)
-rw-r--r-- | frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportFields.js | 247 |
1 files changed, 247 insertions, 0 deletions
diff --git a/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportFields.js b/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportFields.js new file mode 100644 index 0000000..a368747 --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportFields.js | |||
@@ -0,0 +1,247 @@ | |||
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.CSVImportFields = function(anElement, args) { | ||
38 | args = args || {}; | ||
39 | |||
40 | Clipperz.PM.Components.Import.CSVImport.CSVImportFields.superclass.constructor.call(this, anElement, args); | ||
41 | this._mainComponent = args.mainComponent; | ||
42 | |||
43 | return this; | ||
44 | } | ||
45 | |||
46 | //============================================================================= | ||
47 | |||
48 | YAHOO.extendX(Clipperz.PM.Components.Import.CSVImport.CSVImportFields, Clipperz.PM.Components.BaseComponent, { | ||
49 | |||
50 | 'toString': function() { | ||
51 | return "Clipperz.PM.Components.Import.CSVImport.CSVImportFields component"; | ||
52 | }, | ||
53 | |||
54 | //------------------------------------------------------------------------- | ||
55 | |||
56 | 'mainComponent': function() { | ||
57 | return this._mainComponent; | ||
58 | }, | ||
59 | |||
60 | //------------------------------------------------------------------------- | ||
61 | |||
62 | 'render': function() { | ||
63 | varfieldsHeaderCells; | ||
64 | var titleColumnIndex; | ||
65 | var notesColumnIndex; | ||
66 | var i,c; | ||
67 | |||
68 | Clipperz.NotificationCenter.unregister(this); | ||
69 | MochiKit.Signal.disconnectAllTo(this); | ||
70 | |||
71 | this.element().update(""); | ||
72 | |||
73 | titleColumnIndex = this.mainComponent().titleColumnIndex() | ||
74 | notesColumnIndex = this.mainComponent().notesColumnIndex() | ||
75 | |||
76 | fieldsHeaderCells = []; | ||
77 | fieldsHeaderCells.push({tag:'td', valign:'top', cls:'title', html:this.mainComponent().labelForColumn(titleColumnIndex)}); | ||
78 | |||
79 | c =this.mainComponent().parsedValues()[0].length; | ||
80 | for (i=0; i<c; i++) { | ||
81 | if ((i != titleColumnIndex) && (i != notesColumnIndex) && (this.mainComponent().isColumnSelected(i))) { | ||
82 | var trimmedLabel; | ||
83 | |||
84 | trimmedLabel = Clipperz.Base.trim(this.mainComponent().labelForColumn(i)); | ||
85 | fieldsHeaderCells.push({tag:'td', valign:'top', id:this.getId('fieldHeaderTD_' + i), cls:((trimmedLabel == "") ? 'missingLabelWarning' : (this.isColumnSetup(i) ? 'configuredColumn': 'unconfiguredColumn')), children:[ | ||
86 | {tag:'span', html:((trimmedLabel == "") ? Clipperz.PM.Strings['CSV_ImportWizard_Fields_MissingLabelWarning'] : trimmedLabel)/*, cls:((trimmedLabel == "") ? 'missingLabelWarning' : '')*/}, | ||
87 | {tag:'select', id:this.getId('select_' + i), name:i, children:[ | ||
88 | {tag:'option', value:'UNDEFINED', html:"select data type", cls:'disabledOption'}, | ||
89 | {tag:'option', value:'TXT', htmlString:Clipperz.PM.Strings['recordFieldTypologies']['TXT']['shortDescription']}, | ||
90 | {tag:'option', value:'PWD', htmlString:Clipperz.PM.Strings['recordFieldTypologies']['PWD']['shortDescription']}, | ||
91 | {tag:'option', value:'URL', htmlString:Clipperz.PM.Strings['recordFieldTypologies']['URL']['shortDescription']}, | ||
92 | {tag:'option', value:'DATE', htmlString:Clipperz.PM.Strings['recordFieldTypologies']['DATE']['shortDescription']}, | ||
93 | {tag:'option', value:'ADDR', htmlString:Clipperz.PM.Strings['recordFieldTypologies']['ADDR']['shortDescription']} | ||
94 | ]} | ||
95 | ]}) | ||
96 | } | ||
97 | } | ||
98 | |||
99 | if (notesColumnIndex != -1) { | ||
100 | fieldsHeaderCells.push({tag:'td', valign:'top', cls:'notes', html:this.mainComponent().labelForColumn(notesColumnIndex)}); | ||
101 | } | ||
102 | |||
103 | this.domHelper().append(this.element(), {tag:'div', children:[ | ||
104 | {tag:'div', cls:'importStepDescription', htmlString:Clipperz.PM.Strings['CSV_ImportWizard_Fields']}, | ||
105 | {tag:'div', id:this.getId('dataDiv'), children:[ | ||
106 | {tag:'div', children:[ | ||
107 | ]}, | ||
108 | {tag:'div', cls:'csvImportPreview', children:[ | ||
109 | {tag:'table', id:this.getId('previewDada'), cls:'csvImportPreview', cellspacing:'0', children:[ | ||
110 | {tag:'thead', id:this.getId('previewData_thead'), children:[ | ||
111 | {tag:'tr', cls:'CSV_previewData_header', children:fieldsHeaderCells} | ||
112 | ]}, | ||
113 | {tag:'tbody', id:this.getId('previewData_tbody'), children:[]} | ||
114 | ]} | ||
115 | ]} | ||
116 | ]} | ||
117 | ]}); | ||
118 | |||
119 | for (i=0; i<c; i++) { | ||
120 | if ((i != titleColumnIndex) && (i != notesColumnIndex) && (this.mainComponent().isColumnSelected(i))) { | ||
121 | Clipperz.DOM.selectOptionMatchingValue(this.getDom('select_' + i), this.mainComponent().typeForColumn(i)); | ||
122 | MochiKit.Signal.connect(this.getDom('select_' + i), 'onchange', this, 'renderDataRowsHandler'); | ||
123 | } | ||
124 | } | ||
125 | |||
126 | this.renderDataRows(this.getElement('previewData_tbody')); | ||
127 | // Clipperz.NotificationCenter.register(null, 'updatedCSVImportColumnHeader', this, 'renderDataRowsHandler'); | ||
128 | }, | ||
129 | |||
130 | //------------------------------------------------------------------------- | ||
131 | |||
132 | 'isColumnSetup': function(aColumnIndex) { | ||
133 | return ((Clipperz.Base.trim(this.mainComponent().labelForColumn(aColumnIndex)) != "") && (this.mainComponent().typeForColumn(aColumnIndex) != 'UNDEFINED')); | ||
134 | }, | ||
135 | |||
136 | //------------------------------------------------------------------------- | ||
137 | |||
138 | 'renderDataRowsHandler': function(anEvent) { | ||
139 | var columnIndex; | ||
140 | var tdElement; | ||
141 | |||
142 | //MochiKit.Logging.logDebug(">>> renderDataRowsHandler") | ||
143 | columnIndex = anEvent.src().name; | ||
144 | this.mainComponent().setTypeForColumn(anEvent.src().value, columnIndex); | ||
145 | |||
146 | tdElement = this.getElement('fieldHeaderTD_' + columnIndex); | ||
147 | |||
148 | if (this.isColumnSetup(columnIndex)) { | ||
149 | tdElement.removeClass('unconfiguredColumn'); | ||
150 | tdElement.addClass('configuredColumn'); | ||
151 | } else { | ||
152 | tdElement.addClass('unconfiguredColumn'); | ||
153 | tdElement.removeClass('configuredColumn'); | ||
154 | } | ||
155 | |||
156 | this.renderDataRows(this.getElement('previewData_tbody')); | ||
157 | }, | ||
158 | |||
159 | //------------------------------------------------------------------------- | ||
160 | |||
161 | 'renderDataRows': function(anElement) { | ||
162 | var titleColumnIndex; | ||
163 | var notesColumnIndex; | ||
164 | var data | ||
165 | var i,c; | ||
166 | |||
167 | //MochiKit.Logging.logDebug("#### >> renderDataRows"); | ||
168 | // anElement.update(""); | ||
169 | MochiKit.DOM.replaceChildNodes(anElement.dom); | ||
170 | |||
171 | if (this.mainComponent().isFirstRowHeader()) { | ||
172 | data = this.mainComponent().parsedValues().slice(1); | ||
173 | } else { | ||
174 | data = this.mainComponent().parsedValues(); | ||
175 | } | ||
176 | |||
177 | |||
178 | titleColumnIndex = this.mainComponent().titleColumnIndex(); | ||
179 | notesColumnIndex = this.mainComponent().notesColumnIndex(); | ||
180 | |||
181 | c = data.length; | ||
182 | for (i=0; i<c; i++) { | ||
183 | var rowData; | ||
184 | var rowConfig; | ||
185 | var ii, cc; | ||
186 | |||
187 | rowData = data[i]; | ||
188 | |||
189 | rowConfig = {tag:'tr', children:[ | ||
190 | {tag:'td', valign:'top', cls:'title', html:(MochiKit.Base.isNotEmpty(rowData[titleColumnIndex]) ? rowData[titleColumnIndex].replace(/\n/g, '<br>') : ' ')} | ||
191 | ]}; | ||
192 | |||
193 | cc = rowData.length; | ||
194 | for (ii=0; ii<cc; ii++) { | ||
195 | // if ((ii != titleColumnIndex) && (ii != notesColumnIndex)) { | ||
196 | if ((ii != titleColumnIndex) && (ii != notesColumnIndex) && (this.mainComponent().isColumnSelected(ii))) { | ||
197 | rowConfig.children.push({ | ||
198 | tag:'td', | ||
199 | valign:'top', | ||
200 | cls:(this.isColumnSetup(ii) ? 'configuredColumn' : 'unconfiguredColumn'), | ||
201 | html:(MochiKit.Base.isNotEmpty(rowData[ii]) ? rowData[ii].replace(/\n/g, '<br>') : ' ') | ||
202 | }); | ||
203 | } | ||
204 | } | ||
205 | if (notesColumnIndex != -1) { | ||
206 | rowConfig.children.push({tag:'td', valign:'top', cls:'notes', html:(MochiKit.Base.isNotEmpty(rowData[notesColumnIndex]) ? rowData[notesColumnIndex].replace(/\n/g, '<br>') : ' ')}); | ||
207 | } | ||
208 | |||
209 | this.domHelper().append(anElement, rowConfig); | ||
210 | } | ||
211 | |||
212 | Clipperz.Style.applyZebraStylesToTable(this.getId('previewDada')); | ||
213 | |||
214 | this.checkWetherToEnableNextButton(); | ||
215 | //MochiKit.Logging.logDebug("#### << renderDataRows"); | ||
216 | }, | ||
217 | |||
218 | //------------------------------------------------------------------------- | ||
219 | |||
220 | 'checkWetherToEnableNextButton': function() { | ||
221 | var result; | ||
222 | var titleColumnIndex; | ||
223 | var notesColumnIndex; | ||
224 | var i,c; | ||
225 | |||
226 | titleColumnIndex = this.mainComponent().titleColumnIndex() | ||
227 | notesColumnIndex = this.mainComponent().notesColumnIndex() | ||
228 | |||
229 | result = true; | ||
230 | c =this.mainComponent().parsedValues()[0].length; | ||
231 | for (i=0; i<c; i++) { | ||
232 | if ((i != titleColumnIndex) && (i != notesColumnIndex) && (this.mainComponent().isColumnSelected(i))) { | ||
233 | result = result && this.isColumnSetup(i); | ||
234 | } | ||
235 | } | ||
236 | |||
237 | if (result) { | ||
238 | this.mainComponent().nextButton().enable(); | ||
239 | } else { | ||
240 | this.mainComponent().nextButton().disable(); | ||
241 | } | ||
242 | }, | ||
243 | |||
244 | //------------------------------------------------------------------------- | ||
245 | __syntaxFix__: "syntax fix" | ||
246 | }); | ||
247 | |||