Diffstat (limited to 'frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportTitle.js') (more/less context) (show whitespace changes)
-rw-r--r-- | frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportTitle.js | 189 |
1 files changed, 189 insertions, 0 deletions
diff --git a/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportTitle.js b/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportTitle.js new file mode 100644 index 0000000..9162867 --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportTitle.js | |||
@@ -0,0 +1,189 @@ | |||
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.CSVImportTitle = function(anElement, args) { | ||
38 | args = args || {}; | ||
39 | |||
40 | Clipperz.PM.Components.Import.CSVImport.CSVImportTitle.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.CSVImportTitle, Clipperz.PM.Components.BaseComponent, { | ||
49 | |||
50 | 'toString': function() { | ||
51 | return "Clipperz.PM.Components.Import.CSVImport.CSVImportTitle component"; | ||
52 | }, | ||
53 | |||
54 | //------------------------------------------------------------------------- | ||
55 | |||
56 | 'mainComponent': function() { | ||
57 | return this._mainComponent; | ||
58 | }, | ||
59 | |||
60 | //------------------------------------------------------------------------- | ||
61 | |||
62 | 'render': function() { | ||
63 | vartitleSelectorCheckboxCells; | ||
64 | var titleColumnIndex; | ||
65 | var i,c; | ||
66 | |||
67 | Clipperz.NotificationCenter.unregister(this); | ||
68 | MochiKit.Signal.disconnectAllTo(this); | ||
69 | |||
70 | this.element().update(""); | ||
71 | |||
72 | titleColumnIndex = this.mainComponent().titleColumnIndex() | ||
73 | titleSelectorCheckboxCells = []; | ||
74 | c =this.mainComponent().parsedValues()[0].length; | ||
75 | for (i=0; i<c; i++) { | ||
76 | if (this.mainComponent().isColumnSelected(i)) { | ||
77 | titleSelectorCheckboxCells.push({tag:'th', valign:'top', id:this.getId('th_' + i), children:[ | ||
78 | {tag:'input', type:'radio', id:this.getId('radio_' + i), name:'CSVImportTitleColumn', value:i}, | ||
79 | {tag:'span', cls:'clickableSpan', id:this.getId('columnLabel_' + i), html:this.mainComponent().labelForColumn(i)} | ||
80 | ]}) | ||
81 | } | ||
82 | } | ||
83 | |||
84 | if (titleColumnIndex >= titleSelectorCheckboxCells.length) { | ||
85 | this.mainComponent().setTitleColumnIndex(-1); | ||
86 | } | ||
87 | |||
88 | this.domHelper().append(this.element(), {tag:'div', children:[ | ||
89 | {tag:'div', cls:'importStepDescription', htmlString:Clipperz.PM.Strings['CSV_ImportWizard_Title']}, | ||
90 | {tag:'div', id:this.getId('dataDiv'), cls:'csvImportPreview', children:[ | ||
91 | {tag:'table', id:this.getId('previewDada'), cls:'csvImportPreview', cellspacing:'0', children:[ | ||
92 | {tag:'thead', id:this.getId('previewData_thead'), children:[ | ||
93 | {tag:'tr', children:titleSelectorCheckboxCells} | ||
94 | ]}, | ||
95 | {tag:'tbody', id:this.getId('previewData_tbody'), children:[]} | ||
96 | ]} | ||
97 | ]} | ||
98 | ]}); | ||
99 | |||
100 | this.renderData(this.getElement('previewData_tbody'), this.mainComponent().parsedValues()); | ||
101 | |||
102 | c =this.mainComponent().parsedValues()[0].length; | ||
103 | for (i=0; i<c; i++) { | ||
104 | if (this.mainComponent().isColumnSelected(i)) { | ||
105 | MochiKit.Signal.connect(this.getDom('radio_' + i), 'onclick', this, 'renderDataHandler'); | ||
106 | if (Clipperz_IEisBroken != true) { | ||
107 | MochiKit.Signal.connect(this.getDom('columnLabel_' + i), 'onclick', this.getDom('radio_' + i), 'click'); | ||
108 | } | ||
109 | } | ||
110 | } | ||
111 | |||
112 | if (titleColumnIndex != -1) { | ||
113 | this.getDom('radio_' + titleColumnIndex).click(); | ||
114 | } else { | ||
115 | this.mainComponent().nextButton().disable(); | ||
116 | } | ||
117 | |||
118 | }, | ||
119 | |||
120 | //------------------------------------------------------------------------- | ||
121 | |||
122 | 'renderData': function(anElement, someData) { | ||
123 | var data; | ||
124 | var config; | ||
125 | var titleColumnIndex; | ||
126 | var i,c; | ||
127 | |||
128 | // anElement.update(""); | ||
129 | MochiKit.DOM.replaceChildNodes(anElement.dom); | ||
130 | |||
131 | titleColumnIndex = this.mainComponent().titleColumnIndex() | ||
132 | |||
133 | if (this.mainComponent().isFirstRowHeader()) { | ||
134 | data = someData.slice(1); | ||
135 | } else { | ||
136 | data = someData; | ||
137 | } | ||
138 | |||
139 | config = MochiKit.Base.map(MochiKit.Base.bind(function(aRowData) { | ||
140 | var result; | ||
141 | var i,c; | ||
142 | |||
143 | result = {tag:'tr', children:[]}; | ||
144 | c = aRowData.length; | ||
145 | for (i=0; i<c; i++) { | ||
146 | if (this.mainComponent().isColumnSelected(i)) { | ||
147 | var field; | ||
148 | |||
149 | field = aRowData[i]; | ||
150 | result.children.push({tag:'td', valign:'top', cls:((titleColumnIndex == i) ? 'titleColumn': ''), html:(MochiKit.Base.isNotEmpty(field) ? field.replace(/\n/g, '<br>') : ' ')}); | ||
151 | } | ||
152 | } | ||
153 | |||
154 | return result; | ||
155 | }, this), data); | ||
156 | |||
157 | MochiKit.Base.map(function(aRowConfig) {Clipperz.YUI.DomHelper.append(anElement, aRowConfig);}, config); | ||
158 | |||
159 | Clipperz.Style.applyZebraStylesToTable(this.getId('previewDada')); | ||
160 | }, | ||
161 | |||
162 | //------------------------------------------------------------------------- | ||
163 | |||
164 | 'renderDataHandler': function(anEvent) { | ||
165 | var i,c; | ||
166 | |||
167 | this.mainComponent().setTitleColumnIndex(anEvent.src().value); | ||
168 | |||
169 | c = this.mainComponent().parsedValues()[0].length; | ||
170 | for (i=0; i<c; i++) { | ||
171 | if (this.mainComponent().isColumnSelected(i)) { | ||
172 | this.getElement('th_' + i).removeClass('titleColumn'); | ||
173 | } | ||
174 | } | ||
175 | this.getElement('th_' + anEvent.src().value).addClass('titleColumn'); | ||
176 | |||
177 | if (anEvent.src().value != -1) { | ||
178 | this.mainComponent().nextButton().enable(); | ||
179 | } else { | ||
180 | this.mainComponent().nextButton().disable(); | ||
181 | } | ||
182 | |||
183 | this.renderData(this.getElement('previewData_tbody'), this.mainComponent().parsedValues()); | ||
184 | }, | ||
185 | |||
186 | //------------------------------------------------------------------------- | ||
187 | __syntaxFix__: "syntax fix" | ||
188 | }); | ||
189 | |||