summaryrefslogtreecommitdiff
path: root/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportColumns.js
Unidiff
Diffstat (limited to 'frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportColumns.js') (more/less context) (show whitespace changes)
-rw-r--r--frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportColumns.js174
1 files changed, 174 insertions, 0 deletions
diff --git a/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportColumns.js b/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportColumns.js
new file mode 100644
index 0000000..18b36da
--- a/dev/null
+++ b/frontend/beta/js/Clipperz/PM/Components/Import/CSVImport/CSVImportColumns.js
@@ -0,0 +1,174 @@
1/*
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer 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
29if (typeof(Clipperz) == 'undefined') { Clipperz = {}; }
30if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; }
31if (typeof(Clipperz.PM.Components) == 'undefined') { Clipperz.PM.Components = {}; }
32if (typeof(Clipperz.PM.Components.Import) == 'undefined') { Clipperz.PM.Components.Import = {}; }
33if (typeof(Clipperz.PM.Components.Import.CSVImport) == 'undefined') { Clipperz.PM.Components.Import.CSVImport = {}; }
34
35//#############################################################################
36
37Clipperz.PM.Components.Import.CSVImport.CSVImportColumns = function(anElement, args) {
38 args = args || {};
39
40 Clipperz.PM.Components.Import.CSVImport.CSVImportColumns.superclass.constructor.call(this, anElement, args);
41 this._mainComponent = args.mainComponent;
42
43 return this;
44}
45
46//=============================================================================
47
48YAHOO.extendX(Clipperz.PM.Components.Import.CSVImport.CSVImportColumns, Clipperz.PM.Components.BaseComponent, {
49
50 'toString': function() {
51 return "Clipperz.PM.Components.Import.CSVImport.CSVImportColumns component";
52 },
53
54 //-------------------------------------------------------------------------
55
56 'mainComponent': function() {
57 return this._mainComponent;
58 },
59
60 //-------------------------------------------------------------------------
61
62 'render': function() {
63 var i,c;
64 var columnSelectorCheckboxCells;
65 var checkboxes;
66 var data;
67
68//MochiKit.Logging.logDebug(">>> CSVImportColumns.render");
69 Clipperz.NotificationCenter.unregister(this);
70 MochiKit.Signal.disconnectAllTo(this);
71
72 this.element().update("");
73
74 data = this.mainComponent().parsedValues();
75 columnSelectorCheckboxCells = [];
76
77 c =data[0].length;
78 for (i=0; i<c; i++) {
79 columnSelectorCheckboxCells.push({tag:'th', valign:'top', cls:(this.mainComponent().isColumnSelected(i) ? 'selectedColumn': 'skippedColumn'), children:[
80 {tag:'input', type:'checkbox', id:this.getId('columnCheckbox_' + i), value:i}
81 ]})
82 }
83
84 this.domHelper().append(this.element(), {tag:'div', children:[
85 {tag:'div', cls:'importStepDescription', htmlString:Clipperz.PM.Strings['CSV_ImportWizard_Columns']},
86 {tag:'div', id:this.getId('dataDiv'), cls:'csvImportPreview', children:[
87 {tag:'table', id:this.getId('previewDada'), cls:'csvImportPreview columns', cellspacing:'0', children:[
88 {tag:'thead', id:this.getId('previewData_thead'), children:[
89 {tag:'tr', children:columnSelectorCheckboxCells}
90 ]},
91 {tag:'tbody', id:this.getId('previewData_tbody'), children:[]}
92 ]}
93 ]}
94 ]});
95
96 c =data[0].length;
97 for (i=0; i<c; i++) {
98 if (this.mainComponent().isColumnSelected(i)) {
99 this.getDom('columnCheckbox_' + i).checked = true;
100 }
101 }
102
103 this.renderData(this.getElement('previewData_tbody'), data);
104
105 checkboxes = MochiKit.DOM.getElementsByTagAndClassName('input', null, this.getDom('previewData_thead'));
106 c = checkboxes.length;
107 for (i=0; i<c; i++) {
108 MochiKit.Signal.connect(checkboxes[i], 'onclick', this, 'renderDataHandler');
109 }
110//MochiKit.Logging.logDebug("<<< CSVImportColumns.render");
111 },
112
113 //-------------------------------------------------------------------------
114
115 'renderData': function(anElement, someData) {
116 var config;
117 var i,c;
118
119//MochiKit.Logging.logDebug(">>> CSVImportColumns.renderData");
120 // anElement.update("");
121 MochiKit.DOM.replaceChildNodes(anElement.dom);
122
123 config = MochiKit.Base.map(MochiKit.Base.bind(function(aRowData) {
124 var result;
125 var i,c;
126
127 result = {tag:'tr', children:[]};
128 c = aRowData.length;
129 for (i=0; i<c; i++) {
130 var field;
131
132 field = aRowData[i];
133 result.children.push({tag:'td', valign:'top', cls:(this.mainComponent().isColumnSelected(i) ? 'selectedColumn': 'skippedColumn'), html:(MochiKit.Base.isNotEmpty(field) ? field.replace(/\n/g, '<br>') : '&nbsp;')});
134 }
135
136 return result;
137 }, this), someData);
138
139 MochiKit.Base.map(function(aRowConfig) {Clipperz.YUI.DomHelper.append(anElement, aRowConfig);}, config);
140
141 Clipperz.Style.applyZebraStylesToTable(this.getId('previewDada'));
142//MochiKit.Logging.logDebug("<<< CSVImportColumns.renderData");
143 },
144
145 //-------------------------------------------------------------------------
146
147 'renderDataHandler': function(anEvent) {
148 var thElement;
149
150 thElement = YAHOO.ext.Element.get(anEvent.src().parentNode);
151
152 if (anEvent.src().checked == true) {
153 this.mainComponent().skippedColumns().remove(anEvent.src().value);
154 thElement.addClass('selectedColumn');
155 thElement.removeClass('skippedColumn');
156 } else {
157 this.mainComponent().skippedColumns().add(anEvent.src().value);
158 thElement.removeClass('selectedColumn');
159 thElement.addClass('skippedColumn');
160 }
161
162 if (this.mainComponent().skippedColumns().allItems().length == this.mainComponent().parsedValues()[0].length) {
163 this.mainComponent().nextButton().disable();
164 } else {
165 this.mainComponent().nextButton().enable();
166 }
167
168 this.renderData(this.getElement('previewData_tbody'), this.mainComponent().parsedValues());
169 },
170
171 //-------------------------------------------------------------------------
172 __syntaxFix__: "syntax fix"
173});
174