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 | 22 |
1 files changed, 10 insertions, 12 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 index 5cb8679..dbde138 100644 --- a/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportHeader.js +++ b/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportHeader.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.CSVImportHeader = function(anElement, args) { | 32 | Clipperz.PM.Components.Import.CSVImport.CSVImportHeader = function(anElement, args) { |
35 | args = args || {}; | 33 | args = args || {}; |
36 | 34 | ||
37 | Clipperz.PM.Components.Import.CSVImport.CSVImportHeader.superclass.constructor.call(this, anElement, args); | 35 | Clipperz.PM.Components.Import.CSVImport.CSVImportHeader.superclass.constructor.call(this, anElement, args); |
38 | this._mainComponent = args.mainComponent; | 36 | this._mainComponent = args.mainComponent; |
39 | 37 | ||
40 | this._pendingDeferredLabelFieldHandlerEvents = 0; | 38 | this._pendingDeferredLabelFieldHandlerEvents = 0; |
41 | 39 | ||
42 | return this; | 40 | return this; |
43 | } | 41 | } |
44 | 42 | ||
45 | //============================================================================= | 43 | //============================================================================= |
46 | 44 | ||
47 | YAHOO.extendX(Clipperz.PM.Components.Import.CSVImport.CSVImportHeader, Clipperz.PM.Components.BaseComponent, { | 45 | YAHOO.extendX(Clipperz.PM.Components.Import.CSVImport.CSVImportHeader, Clipperz.PM.Components.BaseComponent, { |
48 | 46 | ||
49 | 'toString': function() { | 47 | 'toString': function() { |
50 | return "Clipperz.PM.Components.Import.CSVImport.CSVImportHeader component"; | 48 | return "Clipperz.PM.Components.Import.CSVImport.CSVImportHeader component"; |
51 | }, | 49 | }, |
52 | 50 | ||
53 | //------------------------------------------------------------------------- | 51 | //------------------------------------------------------------------------- |
54 | 52 | ||
55 | 'mainComponent': function() { | 53 | 'mainComponent': function() { |
56 | return this._mainComponent; | 54 | return this._mainComponent; |
57 | }, | 55 | }, |
58 | 56 | ||
59 | //------------------------------------------------------------------------- | 57 | //------------------------------------------------------------------------- |
60 | 58 | ||
61 | 'render': function() { | 59 | 'render': function() { |
62 | var thConfigs; | 60 | var thConfigs; |
63 | var i,c; | 61 | var i,c; |
64 | 62 | ||
65 | //MochiKit.Logging.logDebug(">>> CSVImportHeader.render"); | 63 | //MochiKit.Logging.logDebug(">>> CSVImportHeader.render"); |
66 | Clipperz.NotificationCenter.unregister(this); | 64 | Clipperz.NotificationCenter.unregister(this); |
67 | MochiKit.Signal.disconnectAllTo(this); | 65 | MochiKit.Signal.disconnectAllTo(this); |
68 | 66 | ||
69 | thConfigs = []; | 67 | thConfigs = []; |
70 | c = this.mainComponent().parsedValues()[0].length; | 68 | c = this.mainComponent().parsedValues()[0].length; |
71 | for (i=0; i<c; i++) { | 69 | for (i=0; i<c; i++) { |
72 | if (this.mainComponent().isColumnSelected(i)) { | 70 | if (this.mainComponent().isColumnSelected(i)) { |
73 | // thConfigs.push({tag:'th', children:[{tag:'input', type:'text', id:this.getId('headerTextField_' + i), value:this.mainComponent().labelForColumn(i)}]}); | 71 | // thConfigs.push({tag:'th', children:[{tag:'input', type:'text', id:this.getId('headerTextField_' + i), value:this.mainComponent().labelForColumn(i)}]}); |
74 | thConfigs.push({tag:'th', children:[{tag:'input', type:'text', id:this.getId('headerTextField_' + i), value:""}]}); | 72 | thConfigs.push({tag:'th', children:[{tag:'input', type:'text', id:this.getId('headerTextField_' + i), value:""}]}); |
75 | } | 73 | } |
76 | } | 74 | } |
77 | 75 | ||
78 | this.element().update(""); | 76 | this.element().update(""); |
79 | this.domHelper().append(this.element(), {tag:'div', children:[ | 77 | this.domHelper().append(this.element(), {tag:'div', children:[ |
80 | {tag:'div', cls:'importStepDescription', htmlString:Clipperz.PM.Strings['CSV_ImportWizard_Header']}, | 78 | {tag:'div', cls:'importStepDescription', htmlString:Clipperz.PM.Strings['CSV_ImportWizard_Header']}, |
81 | {tag:'div', cls:'importStepParameters', children:[ | 79 | {tag:'div', cls:'importStepParameters', children:[ |
82 | {tag:'input', type:'checkbox', name:'isFistRowHeader', id:this.getId('isFirstRowHeader_checkbox')}, | 80 | {tag:'input', type:'checkbox', name:'isFistRowHeader', id:this.getId('isFirstRowHeader_checkbox')}, |
83 | {tag:'span', id:this.getId('isFirstRowHeader_span'), cls:'clickableSpan', htmlString:Clipperz.PM.Strings['CSV_ImportWizard_Header_Settings_firstRowHeaderLabel']} | 81 | {tag:'span', id:this.getId('isFirstRowHeader_span'), cls:'clickableSpan', htmlString:Clipperz.PM.Strings['CSV_ImportWizard_Header_Settings_firstRowHeaderLabel']} |
84 | ]}, | 82 | ]}, |
85 | {tag:'div', id:this.getId('dataDiv'), children:[ | 83 | {tag:'div', id:this.getId('dataDiv'), children:[ |
86 | {tag:'div', cls:'csvImportPreview', children:[ | 84 | {tag:'div', cls:'csvImportPreview', children:[ |
87 | {tag:'table', id:this.getId('previewDada'), cls:'csvImportPreview header', cellspacing:'0', children:[ | 85 | {tag:'table', id:this.getId('previewDada'), cls:'csvImportPreview header', cellspacing:'0', children:[ |
88 | {tag:'thead', children:[{tag:'tr', children:thConfigs}]}, | 86 | {tag:'thead', children:[{tag:'tr', children:thConfigs}]}, |
89 | {tag:'tbody', id:this.getId('previewData_tbody')} | 87 | {tag:'tbody', id:this.getId('previewData_tbody')} |
90 | ]} | 88 | ]} |
91 | ]} | 89 | ]} |
92 | ]} | 90 | ]} |
93 | ]}); | 91 | ]}); |
94 | 92 | ||
95 | for (i=0; i<c; i++) { | 93 | for (i=0; i<c; i++) { |
96 | if (this.mainComponent().isColumnSelected(i)) { | 94 | if (this.mainComponent().isColumnSelected(i)) { |
97 | this.getElement('headerTextField_' + i).dom.value = this.mainComponent().labelForColumn(i); | 95 | this.getElement('headerTextField_' + i).dom.value = this.mainComponent().labelForColumn(i); |
98 | } | 96 | } |
99 | } | 97 | } |
100 | 98 | ||
101 | this.renderData(this.getElement('previewData_tbody'), this.mainComponent().parsedValues()); | 99 | this.renderData(this.getElement('previewData_tbody'), this.mainComponent().parsedValues()); |
102 | 100 | ||
103 | if (this.mainComponent().isFirstRowHeader()) { | 101 | if (this.mainComponent().isFirstRowHeader()) { |
104 | this.getDom('isFirstRowHeader_checkbox').click(); | 102 | this.getDom('isFirstRowHeader_checkbox').click(); |
105 | } | 103 | } |
106 | 104 | ||
107 | c = this.mainComponent().parsedValues()[0].length; | 105 | c = this.mainComponent().parsedValues()[0].length; |
108 | for (i=0; i<c; i++) { | 106 | for (i=0; i<c; i++) { |
109 | if (this.mainComponent().isColumnSelected(i)) { | 107 | if (this.mainComponent().isColumnSelected(i)) { |
110 | MochiKit.Signal.connect(this.getDom('headerTextField_' + i), 'onchange', MochiKit.Base.partial(MochiKit.Base.method(this, 'labelFieldHandler'), i)); | 108 | MochiKit.Signal.connect(this.getDom('headerTextField_' + i), 'onchange', MochiKit.Base.partial(MochiKit.Base.method(this, 'labelFieldHandler'), i)); |
111 | MochiKit.Signal.connect(this.getDom('headerTextField_' + i), 'onkeypress', MochiKit.Base.partial(MochiKit.Base.method(this, 'deferredLabelFieldHandler'), i)); | 109 | MochiKit.Signal.connect(this.getDom('headerTextField_' + i), 'onkeypress', MochiKit.Base.partial(MochiKit.Base.method(this, 'deferredLabelFieldHandler'), i)); |
112 | } | 110 | } |
113 | } | 111 | } |
114 | 112 | ||
115 | MochiKit.Signal.connect(this.getDom('isFirstRowHeader_checkbox'), 'onclick', this, 'toggleFirstRowHeaderCheckboxHandler'); | 113 | MochiKit.Signal.connect(this.getDom('isFirstRowHeader_checkbox'), 'onclick', this, 'toggleFirstRowHeaderCheckboxHandler'); |
116 | if (Clipperz_IEisBroken != true) { | 114 | if (Clipperz_IEisBroken != true) { |
117 | MochiKit.Signal.connect(this.getDom('isFirstRowHeader_span'), 'onclick', this.getDom('isFirstRowHeader_checkbox'), 'click'); | 115 | MochiKit.Signal.connect(this.getDom('isFirstRowHeader_span'), 'onclick', this.getDom('isFirstRowHeader_checkbox'), 'click'); |
118 | } | 116 | } |
119 | //MochiKit.Logging.logDebug("<<< CSVImportHeader.render"); | 117 | //MochiKit.Logging.logDebug("<<< CSVImportHeader.render"); |
120 | }, | 118 | }, |
121 | 119 | ||
122 | //------------------------------------------------------------------------- | 120 | //------------------------------------------------------------------------- |
123 | 121 | ||
124 | 'renderData': function(anElement, someData) { | 122 | 'renderData': function(anElement, someData) { |
125 | var trConfigs; | 123 | var trConfigs; |
126 | var data; | 124 | var data; |
127 | var i,c; | 125 | var i,c; |
128 | 126 | ||
129 | // anElement.update(""); | 127 | // anElement.update(""); |
130 | MochiKit.DOM.replaceChildNodes(anElement.dom); | 128 | MochiKit.DOM.replaceChildNodes(anElement.dom); |
131 | 129 | ||
132 | if (this.mainComponent().isFirstRowHeader()) { | 130 | if (this.mainComponent().isFirstRowHeader()) { |
133 | data = someData.slice(1); | 131 | data = someData.slice(1); |
134 | } else { | 132 | } else { |
135 | data = someData; | 133 | data = someData; |
136 | } | 134 | } |
137 | 135 | ||
138 | trConfigs = MochiKit.Base.map(MochiKit.Base.bind(function(aRowData) { | 136 | trConfigs = MochiKit.Base.map(MochiKit.Base.bind(function(aRowData) { |
139 | var result; | 137 | var result; |
140 | var i,c; | 138 | var i,c; |
141 | 139 | ||
142 | result = {tag:'tr', children:[]}; | 140 | result = {tag:'tr', children:[]}; |
143 | c = aRowData.length; | 141 | c = aRowData.length; |
144 | for (i=0; i<c; i++) { | 142 | for (i=0; i<c; i++) { |
145 | if (this.mainComponent().isColumnSelected(i)) { | 143 | if (this.mainComponent().isColumnSelected(i)) { |
146 | result.children.push({tag:'td', valign:'top', html:(MochiKit.Base.isNotEmpty(aRowData[i]) ? aRowData[i].replace(/\n/g, '<br>') : ' ')}); | 144 | result.children.push({tag:'td', valign:'top', html:(MochiKit.Base.isNotEmpty(aRowData[i]) ? aRowData[i].replace(/\n/g, '<br>') : ' ')}); |
147 | } | 145 | } |
148 | } | 146 | } |
149 | 147 | ||
150 | return result; | 148 | return result; |
151 | }, this), data); | 149 | }, this), data); |
152 | 150 | ||
153 | MochiKit.Base.map(function(aRowConfig) {Clipperz.YUI.DomHelper.append(anElement, aRowConfig);}, trConfigs); | 151 | MochiKit.Base.map(function(aRowConfig) {Clipperz.YUI.DomHelper.append(anElement, aRowConfig);}, trConfigs); |
154 | 152 | ||
155 | Clipperz.Style.applyZebraStylesToTable(this.getId('previewDada')); | 153 | Clipperz.Style.applyZebraStylesToTable(this.getId('previewDada')); |
156 | }, | 154 | }, |
157 | 155 | ||
158 | //------------------------------------------------------------------------- | 156 | //------------------------------------------------------------------------- |
159 | 157 | ||
160 | 'toggleFirstRowHeaderCheckboxHandler': function() { | 158 | 'toggleFirstRowHeaderCheckboxHandler': function() { |
161 | var firstRowData; | 159 | var firstRowData; |
162 | var i,c; | 160 | var i,c; |
163 | 161 | ||
164 | //MochiKit.Logging.logDebug(">>> toggleFirstRowHeaderCheckboxHandler"); | 162 | //MochiKit.Logging.logDebug(">>> toggleFirstRowHeaderCheckboxHandler"); |
165 | this.mainComponent().setIsFirstRowHeader(this.getDom('isFirstRowHeader_checkbox').checked); | 163 | this.mainComponent().setIsFirstRowHeader(this.getDom('isFirstRowHeader_checkbox').checked); |
166 | 164 | ||
167 | firstRowData = this.mainComponent().parsedValues()[0]; | 165 | firstRowData = this.mainComponent().parsedValues()[0]; |
168 | 166 | ||
169 | c = firstRowData.length; | 167 | c = firstRowData.length; |
170 | for (i=0; i<c; i++) { | 168 | for (i=0; i<c; i++) { |
171 | if (this.mainComponent().isColumnSelected(i)) { | 169 | if (this.mainComponent().isColumnSelected(i)) { |
172 | var label; | 170 | var label; |
173 | 171 | ||
174 | if (this.mainComponent().isFirstRowHeader()) { | 172 | if (this.mainComponent().isFirstRowHeader()) { |
175 | label = firstRowData[i]; | 173 | label = firstRowData[i]; |
176 | } else { | 174 | } else { |
177 | label = null; | 175 | label = null; |
178 | } | 176 | } |
179 | 177 | ||
180 | this.mainComponent().setLabelForColumn(label, i); | 178 | this.mainComponent().setLabelForColumn(label, i); |
181 | } | 179 | } |
182 | }; | 180 | }; |
183 | 181 | ||
184 | this.updateInputFieldValues(); | 182 | this.updateInputFieldValues(); |
185 | this.renderData(this.getElement('previewData_tbody'), this.mainComponent().parsedValues()); | 183 | this.renderData(this.getElement('previewData_tbody'), this.mainComponent().parsedValues()); |
186 | //MochiKit.Logging.logDebug("<<< toggleFirstRowHeaderCheckboxHandler"); | 184 | //MochiKit.Logging.logDebug("<<< toggleFirstRowHeaderCheckboxHandler"); |
187 | }, | 185 | }, |
188 | 186 | ||
189 | //------------------------------------------------------------------------- | 187 | //------------------------------------------------------------------------- |
190 | 188 | ||
191 | 'updateInputFieldValues': function() { | 189 | 'updateInputFieldValues': function() { |
192 | var i,c; | 190 | var i,c; |
193 | 191 | ||
194 | //MochiKit.Logging.logDebug(">>> updateInputFieldValues"); | 192 | //MochiKit.Logging.logDebug(">>> updateInputFieldValues"); |
195 | c = this.mainComponent().parsedValues()[0].length; | 193 | c = this.mainComponent().parsedValues()[0].length; |
196 | for (i=0; i<c; i++) { | 194 | for (i=0; i<c; i++) { |
197 | if (this.mainComponent().isColumnSelected(i)) { | 195 | if (this.mainComponent().isColumnSelected(i)) { |
198 | this.getDom('headerTextField_' + i).value = this.mainComponent().labelForColumn(i); | 196 | this.getDom('headerTextField_' + i).value = this.mainComponent().labelForColumn(i); |
199 | } | 197 | } |
200 | } | 198 | } |
201 | //console.log('[1] fieldSettings', fieldSettings); | 199 | //console.log('[1] fieldSettings', fieldSettings); |
202 | //MochiKit.Logging.logDebug("<<< updateInputFieldValues"); | 200 | //MochiKit.Logging.logDebug("<<< updateInputFieldValues"); |
203 | }, | 201 | }, |
204 | 202 | ||
205 | //------------------------------------------------------------------------- | 203 | //------------------------------------------------------------------------- |
206 | 204 | ||
207 | 'labelFieldHandler': function(aColumnIndex, anEvent) { | 205 | 'labelFieldHandler': function(aColumnIndex, anEvent) { |
208 | var inputField; | 206 | var inputField; |
209 | 207 | ||
210 | //MochiKit.Logging.logDebug(">>> labelFieldHandler"); | 208 | //MochiKit.Logging.logDebug(">>> labelFieldHandler"); |
211 | inputField = anEvent.src(); | 209 | inputField = anEvent.src(); |
212 | 210 | ||
213 | this.mainComponent().setLabelForColumn(inputField.value, aColumnIndex); | 211 | this.mainComponent().setLabelForColumn(inputField.value, aColumnIndex); |
214 | //MochiKit.Logging.logDebug("##### [" + anEvent.src().id + "] -> label[" + aColumnIndex + "]: '" + inputField.value + "'"); | 212 | //MochiKit.Logging.logDebug("##### [" + anEvent.src().id + "] -> label[" + aColumnIndex + "]: '" + inputField.value + "'"); |