Diffstat (limited to 'frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportFields.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportFields.js | 22 |
1 files changed, 10 insertions, 12 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 index f7dbd5d..e816380 100644 --- a/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportFields.js +++ b/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportFields.js | |||
@@ -1,214 +1,212 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2013 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz, the online password manager. |
6 | Clipperz Community Edition is an online password manager. | ||
7 | For further information about its features and functionalities please | 6 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 7 | refer to http://www.clipperz.com. |
9 | 8 | ||
10 | * Clipperz Community Edition is free software: you can redistribute | 9 | * Clipperz is free software: you can redistribute it and/or modify it |
11 | it and/or modify it under the terms of the GNU Affero General Public | 10 | under the terms of the GNU Affero General Public License as published |
12 | License as published by the Free Software Foundation, either version | 11 | by the Free Software Foundation, either version 3 of the License, or |
13 | 3 of the License, or (at your option) any later version. | 12 | (at your option) any later version. |
14 | 13 | ||
15 | * Clipperz Community Edition is distributed in the hope that it will | 14 | * Clipperz is distributed in the hope that it will be useful, but |
16 | be useful, but WITHOUT ANY WARRANTY; without even the implied | 15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. | 17 | See the GNU Affero General Public License for more details. |
19 | 18 | ||
20 | * You should have received a copy of the GNU Affero General Public | 19 | * You should have received a copy of the GNU Affero General Public |
21 | License along with Clipperz Community Edition. If not, see | 20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. |
22 | <http://www.gnu.org/licenses/>. | ||
23 | 21 | ||
24 | */ | 22 | */ |
25 | 23 | ||
26 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 24 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
27 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | 25 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } |
28 | if (typeof(Clipperz.PM.Components) == 'undefined') { Clipperz.PM.Components = {}; } | 26 | if (typeof(Clipperz.PM.Components) == 'undefined') { Clipperz.PM.Components = {}; } |
29 | if (typeof(Clipperz.PM.Components.Import) == 'undefined') { Clipperz.PM.Components.Import = {}; } | 27 | if (typeof(Clipperz.PM.Components.Import) == 'undefined') { Clipperz.PM.Components.Import = {}; } |
30 | if (typeof(Clipperz.PM.Components.Import.CSVImport) == 'undefined') { Clipperz.PM.Components.Import.CSVImport = {}; } | 28 | if (typeof(Clipperz.PM.Components.Import.CSVImport) == 'undefined') { Clipperz.PM.Components.Import.CSVImport = {}; } |
31 | 29 | ||
32 | //############################################################################# | 30 | //############################################################################# |
33 | 31 | ||
34 | Clipperz.PM.Components.Import.CSVImport.CSVImportFields = function(anElement, args) { | 32 | Clipperz.PM.Components.Import.CSVImport.CSVImportFields = function(anElement, args) { |
35 | args = args || {}; | 33 | args = args || {}; |
36 | 34 | ||
37 | Clipperz.PM.Components.Import.CSVImport.CSVImportFields.superclass.constructor.call(this, anElement, args); | 35 | Clipperz.PM.Components.Import.CSVImport.CSVImportFields.superclass.constructor.call(this, anElement, args); |
38 | this._mainComponent = args.mainComponent; | 36 | this._mainComponent = args.mainComponent; |
39 | 37 | ||
40 | return this; | 38 | return this; |
41 | } | 39 | } |
42 | 40 | ||
43 | //============================================================================= | 41 | //============================================================================= |
44 | 42 | ||
45 | YAHOO.extendX(Clipperz.PM.Components.Import.CSVImport.CSVImportFields, Clipperz.PM.Components.BaseComponent, { | 43 | YAHOO.extendX(Clipperz.PM.Components.Import.CSVImport.CSVImportFields, Clipperz.PM.Components.BaseComponent, { |
46 | 44 | ||
47 | 'toString': function() { | 45 | 'toString': function() { |
48 | return "Clipperz.PM.Components.Import.CSVImport.CSVImportFields component"; | 46 | return "Clipperz.PM.Components.Import.CSVImport.CSVImportFields component"; |
49 | }, | 47 | }, |
50 | 48 | ||
51 | //------------------------------------------------------------------------- | 49 | //------------------------------------------------------------------------- |
52 | 50 | ||
53 | 'mainComponent': function() { | 51 | 'mainComponent': function() { |
54 | return this._mainComponent; | 52 | return this._mainComponent; |
55 | }, | 53 | }, |
56 | 54 | ||
57 | //------------------------------------------------------------------------- | 55 | //------------------------------------------------------------------------- |
58 | 56 | ||
59 | 'render': function() { | 57 | 'render': function() { |
60 | varfieldsHeaderCells; | 58 | varfieldsHeaderCells; |
61 | var titleColumnIndex; | 59 | var titleColumnIndex; |
62 | var notesColumnIndex; | 60 | var notesColumnIndex; |
63 | var i,c; | 61 | var i,c; |
64 | 62 | ||
65 | Clipperz.NotificationCenter.unregister(this); | 63 | Clipperz.NotificationCenter.unregister(this); |
66 | MochiKit.Signal.disconnectAllTo(this); | 64 | MochiKit.Signal.disconnectAllTo(this); |
67 | 65 | ||
68 | this.element().update(""); | 66 | this.element().update(""); |
69 | 67 | ||
70 | titleColumnIndex = this.mainComponent().titleColumnIndex() | 68 | titleColumnIndex = this.mainComponent().titleColumnIndex() |
71 | notesColumnIndex = this.mainComponent().notesColumnIndex() | 69 | notesColumnIndex = this.mainComponent().notesColumnIndex() |
72 | 70 | ||
73 | fieldsHeaderCells = []; | 71 | fieldsHeaderCells = []; |
74 | fieldsHeaderCells.push({tag:'td', valign:'top', cls:'title', html:this.mainComponent().labelForColumn(titleColumnIndex)}); | 72 | fieldsHeaderCells.push({tag:'td', valign:'top', cls:'title', html:this.mainComponent().labelForColumn(titleColumnIndex)}); |
75 | 73 | ||
76 | c =this.mainComponent().parsedValues()[0].length; | 74 | c =this.mainComponent().parsedValues()[0].length; |
77 | for (i=0; i<c; i++) { | 75 | for (i=0; i<c; i++) { |
78 | if ((i != titleColumnIndex) && (i != notesColumnIndex) && (this.mainComponent().isColumnSelected(i))) { | 76 | if ((i != titleColumnIndex) && (i != notesColumnIndex) && (this.mainComponent().isColumnSelected(i))) { |
79 | var trimmedLabel; | 77 | var trimmedLabel; |
80 | 78 | ||
81 | trimmedLabel = Clipperz.Base.trim(this.mainComponent().labelForColumn(i)); | 79 | trimmedLabel = Clipperz.Base.trim(this.mainComponent().labelForColumn(i)); |
82 | fieldsHeaderCells.push({tag:'td', valign:'top', id:this.getId('fieldHeaderTD_' + i), cls:((trimmedLabel == "") ? 'missingLabelWarning' : (this.isColumnSetup(i) ? 'configuredColumn': 'unconfiguredColumn')), children:[ | 80 | fieldsHeaderCells.push({tag:'td', valign:'top', id:this.getId('fieldHeaderTD_' + i), cls:((trimmedLabel == "") ? 'missingLabelWarning' : (this.isColumnSetup(i) ? 'configuredColumn': 'unconfiguredColumn')), children:[ |
83 | {tag:'span', html:((trimmedLabel == "") ? Clipperz.PM.Strings['CSV_ImportWizard_Fields_MissingLabelWarning'] : trimmedLabel)/*, cls:((trimmedLabel == "") ? 'missingLabelWarning' : '')*/}, | 81 | {tag:'span', html:((trimmedLabel == "") ? Clipperz.PM.Strings['CSV_ImportWizard_Fields_MissingLabelWarning'] : trimmedLabel)/*, cls:((trimmedLabel == "") ? 'missingLabelWarning' : '')*/}, |
84 | {tag:'select', id:this.getId('select_' + i), name:i, children:[ | 82 | {tag:'select', id:this.getId('select_' + i), name:i, children:[ |
85 | {tag:'option', value:'UNDEFINED', html:"select data type", cls:'disabledOption'}, | 83 | {tag:'option', value:'UNDEFINED', html:"select data type", cls:'disabledOption'}, |
86 | {tag:'option', value:'TXT', htmlString:Clipperz.PM.Strings['recordFieldTypologies']['TXT']['shortDescription']}, | 84 | {tag:'option', value:'TXT', htmlString:Clipperz.PM.Strings['recordFieldTypologies']['TXT']['shortDescription']}, |
87 | {tag:'option', value:'PWD', htmlString:Clipperz.PM.Strings['recordFieldTypologies']['PWD']['shortDescription']}, | 85 | {tag:'option', value:'PWD', htmlString:Clipperz.PM.Strings['recordFieldTypologies']['PWD']['shortDescription']}, |
88 | {tag:'option', value:'URL', htmlString:Clipperz.PM.Strings['recordFieldTypologies']['URL']['shortDescription']}, | 86 | {tag:'option', value:'URL', htmlString:Clipperz.PM.Strings['recordFieldTypologies']['URL']['shortDescription']}, |
89 | {tag:'option', value:'DATE', htmlString:Clipperz.PM.Strings['recordFieldTypologies']['DATE']['shortDescription']}, | 87 | {tag:'option', value:'DATE', htmlString:Clipperz.PM.Strings['recordFieldTypologies']['DATE']['shortDescription']}, |
90 | {tag:'option', value:'ADDR', htmlString:Clipperz.PM.Strings['recordFieldTypologies']['ADDR']['shortDescription']} | 88 | {tag:'option', value:'ADDR', htmlString:Clipperz.PM.Strings['recordFieldTypologies']['ADDR']['shortDescription']} |
91 | ]} | 89 | ]} |
92 | ]}) | 90 | ]}) |
93 | } | 91 | } |
94 | } | 92 | } |
95 | 93 | ||
96 | if (notesColumnIndex != -1) { | 94 | if (notesColumnIndex != -1) { |
97 | fieldsHeaderCells.push({tag:'td', valign:'top', cls:'notes', html:this.mainComponent().labelForColumn(notesColumnIndex)}); | 95 | fieldsHeaderCells.push({tag:'td', valign:'top', cls:'notes', html:this.mainComponent().labelForColumn(notesColumnIndex)}); |
98 | } | 96 | } |
99 | 97 | ||
100 | this.domHelper().append(this.element(), {tag:'div', children:[ | 98 | this.domHelper().append(this.element(), {tag:'div', children:[ |
101 | {tag:'div', cls:'importStepDescription', htmlString:Clipperz.PM.Strings['CSV_ImportWizard_Fields']}, | 99 | {tag:'div', cls:'importStepDescription', htmlString:Clipperz.PM.Strings['CSV_ImportWizard_Fields']}, |
102 | {tag:'div', id:this.getId('dataDiv'), children:[ | 100 | {tag:'div', id:this.getId('dataDiv'), children:[ |
103 | {tag:'div', children:[ | 101 | {tag:'div', children:[ |
104 | ]}, | 102 | ]}, |
105 | {tag:'div', cls:'csvImportPreview', children:[ | 103 | {tag:'div', cls:'csvImportPreview', children:[ |
106 | {tag:'table', id:this.getId('previewDada'), cls:'csvImportPreview', cellspacing:'0', children:[ | 104 | {tag:'table', id:this.getId('previewDada'), cls:'csvImportPreview', cellspacing:'0', children:[ |
107 | {tag:'thead', id:this.getId('previewData_thead'), children:[ | 105 | {tag:'thead', id:this.getId('previewData_thead'), children:[ |
108 | {tag:'tr', cls:'CSV_previewData_header', children:fieldsHeaderCells} | 106 | {tag:'tr', cls:'CSV_previewData_header', children:fieldsHeaderCells} |
109 | ]}, | 107 | ]}, |
110 | {tag:'tbody', id:this.getId('previewData_tbody'), children:[]} | 108 | {tag:'tbody', id:this.getId('previewData_tbody'), children:[]} |
111 | ]} | 109 | ]} |
112 | ]} | 110 | ]} |
113 | ]} | 111 | ]} |
114 | ]}); | 112 | ]}); |
115 | 113 | ||
116 | for (i=0; i<c; i++) { | 114 | for (i=0; i<c; i++) { |
117 | if ((i != titleColumnIndex) && (i != notesColumnIndex) && (this.mainComponent().isColumnSelected(i))) { | 115 | if ((i != titleColumnIndex) && (i != notesColumnIndex) && (this.mainComponent().isColumnSelected(i))) { |
118 | Clipperz.DOM.selectOptionMatchingValue(this.getDom('select_' + i), this.mainComponent().typeForColumn(i)); | 116 | Clipperz.DOM.selectOptionMatchingValue(this.getDom('select_' + i), this.mainComponent().typeForColumn(i)); |
119 | MochiKit.Signal.connect(this.getDom('select_' + i), 'onchange', this, 'renderDataRowsHandler'); | 117 | MochiKit.Signal.connect(this.getDom('select_' + i), 'onchange', this, 'renderDataRowsHandler'); |
120 | } | 118 | } |
121 | } | 119 | } |
122 | 120 | ||
123 | this.renderDataRows(this.getElement('previewData_tbody')); | 121 | this.renderDataRows(this.getElement('previewData_tbody')); |
124 | // Clipperz.NotificationCenter.register(null, 'updatedCSVImportColumnHeader', this, 'renderDataRowsHandler'); | 122 | // Clipperz.NotificationCenter.register(null, 'updatedCSVImportColumnHeader', this, 'renderDataRowsHandler'); |
125 | }, | 123 | }, |
126 | 124 | ||
127 | //------------------------------------------------------------------------- | 125 | //------------------------------------------------------------------------- |
128 | 126 | ||
129 | 'isColumnSetup': function(aColumnIndex) { | 127 | 'isColumnSetup': function(aColumnIndex) { |
130 | return ((Clipperz.Base.trim(this.mainComponent().labelForColumn(aColumnIndex)) != "") && (this.mainComponent().typeForColumn(aColumnIndex) != 'UNDEFINED')); | 128 | return ((Clipperz.Base.trim(this.mainComponent().labelForColumn(aColumnIndex)) != "") && (this.mainComponent().typeForColumn(aColumnIndex) != 'UNDEFINED')); |
131 | }, | 129 | }, |
132 | 130 | ||
133 | //------------------------------------------------------------------------- | 131 | //------------------------------------------------------------------------- |
134 | 132 | ||
135 | 'renderDataRowsHandler': function(anEvent) { | 133 | 'renderDataRowsHandler': function(anEvent) { |
136 | var columnIndex; | 134 | var columnIndex; |
137 | var tdElement; | 135 | var tdElement; |
138 | 136 | ||
139 | //MochiKit.Logging.logDebug(">>> renderDataRowsHandler") | 137 | //MochiKit.Logging.logDebug(">>> renderDataRowsHandler") |
140 | columnIndex = anEvent.src().name; | 138 | columnIndex = anEvent.src().name; |
141 | this.mainComponent().setTypeForColumn(anEvent.src().value, columnIndex); | 139 | this.mainComponent().setTypeForColumn(anEvent.src().value, columnIndex); |
142 | 140 | ||
143 | tdElement = this.getElement('fieldHeaderTD_' + columnIndex); | 141 | tdElement = this.getElement('fieldHeaderTD_' + columnIndex); |
144 | 142 | ||
145 | if (this.isColumnSetup(columnIndex)) { | 143 | if (this.isColumnSetup(columnIndex)) { |
146 | tdElement.removeClass('unconfiguredColumn'); | 144 | tdElement.removeClass('unconfiguredColumn'); |
147 | tdElement.addClass('configuredColumn'); | 145 | tdElement.addClass('configuredColumn'); |
148 | } else { | 146 | } else { |
149 | tdElement.addClass('unconfiguredColumn'); | 147 | tdElement.addClass('unconfiguredColumn'); |
150 | tdElement.removeClass('configuredColumn'); | 148 | tdElement.removeClass('configuredColumn'); |
151 | } | 149 | } |
152 | 150 | ||
153 | this.renderDataRows(this.getElement('previewData_tbody')); | 151 | this.renderDataRows(this.getElement('previewData_tbody')); |
154 | }, | 152 | }, |
155 | 153 | ||
156 | //------------------------------------------------------------------------- | 154 | //------------------------------------------------------------------------- |
157 | 155 | ||
158 | 'renderDataRows': function(anElement) { | 156 | 'renderDataRows': function(anElement) { |
159 | var titleColumnIndex; | 157 | var titleColumnIndex; |
160 | var notesColumnIndex; | 158 | var notesColumnIndex; |
161 | var data | 159 | var data |
162 | var i,c; | 160 | var i,c; |
163 | 161 | ||
164 | //MochiKit.Logging.logDebug("#### >> renderDataRows"); | 162 | //MochiKit.Logging.logDebug("#### >> renderDataRows"); |
165 | // anElement.update(""); | 163 | // anElement.update(""); |
166 | MochiKit.DOM.replaceChildNodes(anElement.dom); | 164 | MochiKit.DOM.replaceChildNodes(anElement.dom); |
167 | 165 | ||
168 | if (this.mainComponent().isFirstRowHeader()) { | 166 | if (this.mainComponent().isFirstRowHeader()) { |
169 | data = this.mainComponent().parsedValues().slice(1); | 167 | data = this.mainComponent().parsedValues().slice(1); |
170 | } else { | 168 | } else { |
171 | data = this.mainComponent().parsedValues(); | 169 | data = this.mainComponent().parsedValues(); |
172 | } | 170 | } |
173 | 171 | ||
174 | 172 | ||
175 | titleColumnIndex = this.mainComponent().titleColumnIndex(); | 173 | titleColumnIndex = this.mainComponent().titleColumnIndex(); |
176 | notesColumnIndex = this.mainComponent().notesColumnIndex(); | 174 | notesColumnIndex = this.mainComponent().notesColumnIndex(); |
177 | 175 | ||
178 | c = data.length; | 176 | c = data.length; |
179 | for (i=0; i<c; i++) { | 177 | for (i=0; i<c; i++) { |
180 | var rowData; | 178 | var rowData; |
181 | var rowConfig; | 179 | var rowConfig; |
182 | var ii, cc; | 180 | var ii, cc; |
183 | 181 | ||
184 | rowData = data[i]; | 182 | rowData = data[i]; |
185 | 183 | ||
186 | rowConfig = {tag:'tr', children:[ | 184 | rowConfig = {tag:'tr', children:[ |
187 | {tag:'td', valign:'top', cls:'title', html:(MochiKit.Base.isNotEmpty(rowData[titleColumnIndex]) ? rowData[titleColumnIndex].replace(/\n/g, '<br>') : ' ')} | 185 | {tag:'td', valign:'top', cls:'title', html:(MochiKit.Base.isNotEmpty(rowData[titleColumnIndex]) ? rowData[titleColumnIndex].replace(/\n/g, '<br>') : ' ')} |
188 | ]}; | 186 | ]}; |
189 | 187 | ||
190 | cc = rowData.length; | 188 | cc = rowData.length; |
191 | for (ii=0; ii<cc; ii++) { | 189 | for (ii=0; ii<cc; ii++) { |
192 | // if ((ii != titleColumnIndex) && (ii != notesColumnIndex)) { | 190 | // if ((ii != titleColumnIndex) && (ii != notesColumnIndex)) { |
193 | if ((ii != titleColumnIndex) && (ii != notesColumnIndex) && (this.mainComponent().isColumnSelected(ii))) { | 191 | if ((ii != titleColumnIndex) && (ii != notesColumnIndex) && (this.mainComponent().isColumnSelected(ii))) { |
194 | rowConfig.children.push({ | 192 | rowConfig.children.push({ |
195 | tag:'td', | 193 | tag:'td', |
196 | valign:'top', | 194 | valign:'top', |
197 | cls:(this.isColumnSetup(ii) ? 'configuredColumn' : 'unconfiguredColumn'), | 195 | cls:(this.isColumnSetup(ii) ? 'configuredColumn' : 'unconfiguredColumn'), |
198 | html:(MochiKit.Base.isNotEmpty(rowData[ii]) ? rowData[ii].replace(/\n/g, '<br>') : ' ') | 196 | html:(MochiKit.Base.isNotEmpty(rowData[ii]) ? rowData[ii].replace(/\n/g, '<br>') : ' ') |
199 | }); | 197 | }); |
200 | } | 198 | } |
201 | } | 199 | } |
202 | if (notesColumnIndex != -1) { | 200 | if (notesColumnIndex != -1) { |
203 | rowConfig.children.push({tag:'td', valign:'top', cls:'notes', html:(MochiKit.Base.isNotEmpty(rowData[notesColumnIndex]) ? rowData[notesColumnIndex].replace(/\n/g, '<br>') : ' ')}); | 201 | rowConfig.children.push({tag:'td', valign:'top', cls:'notes', html:(MochiKit.Base.isNotEmpty(rowData[notesColumnIndex]) ? rowData[notesColumnIndex].replace(/\n/g, '<br>') : ' ')}); |
204 | } | 202 | } |
205 | 203 | ||
206 | this.domHelper().append(anElement, rowConfig); | 204 | this.domHelper().append(anElement, rowConfig); |
207 | } | 205 | } |
208 | 206 | ||
209 | Clipperz.Style.applyZebraStylesToTable(this.getId('previewDada')); | 207 | Clipperz.Style.applyZebraStylesToTable(this.getId('previewDada')); |
210 | 208 | ||
211 | this.checkWetherToEnableNextButton(); | 209 | this.checkWetherToEnableNextButton(); |
212 | //MochiKit.Logging.logDebug("#### << renderDataRows"); | 210 | //MochiKit.Logging.logDebug("#### << renderDataRows"); |
213 | }, | 211 | }, |
214 | 212 | ||