!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 var importService;
2 var fieldMap = null;
3 var recordNum = 0;
4 var addInterface = null;
5 var dialogResult = null;
6 var gPreviousButton;
7 var gNextButton;
8 var gMoveUpButton;
9 var gMoveDownButton;
10 var gListbox;
11 var gSkipFirstRecordButton;
12
OnLoadFieldMapImport
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
13 function OnLoadFieldMapImport()
14 {
15 top.importService = Components.classes["@mozilla.org/import/import-service;1"].getService();
16 top.importService = top.importService.QueryInterface(Components.interfaces.nsIImportService);
17
18 // We need a field map object...
19 // assume we have one passed in? or just make one?
20 if (window.arguments && window.arguments[0]) {
21 top.fieldMap = window.arguments[0].fieldMap;
22 top.addInterface = window.arguments[0].addInterface;
23 top.dialogResult = window.arguments[0].result;
24 }
25 if (top.fieldMap == null) {
26 top.fieldMap = top.importService.CreateNewFieldMap();
27 top.fieldMap.DefaultFieldMap( top.fieldMap.numMozFields);
28 }
29
30 gMoveUpButton = document.getElementById("upButton");
31 gMoveDownButton = document.getElementById("downButton");
32 gPreviousButton = document.getElementById("previous");
33 gNextButton = document.getElementById("next");
34 gListbox = document.getElementById("fieldList");
35 gSkipFirstRecordButton = document.getElementById("skipFirstRecord");
36
37 // Set the state of the skip first record button
38 gSkipFirstRecordButton.checked = top.fieldMap.skipFirstRecord;
39
40 ListFields();
41 Browse(1);
42 gListbox.selectedItem = gListbox.getItemAtIndex(0);
43 disableMoveButtons();
44 }
45
IndexInMap
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
46 function IndexInMap( index)
47 {
48 var count = top.fieldMap.mapSize;
49 for (var i = 0; i < count; i++) {
50 if (top.fieldMap.GetFieldMap( i) == index)
51 return( true);
52 }
53
54 return( false);
55 }
56
ListFields
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
57 function ListFields() {
58 if (top.fieldMap == null)
59 return;
60
61 var count = top.fieldMap.mapSize;
62 var index;
63 var i;
64 for (i = 0; i < count; i++) {
65 index = top.fieldMap.GetFieldMap( i);
66 AddFieldToList(top.fieldMap.GetFieldDescription( index), index, top.fieldMap.GetFieldActive( i));
67 }
68
69 count = top.fieldMap.numMozFields;
70 for (i = 0; i < count; i++) {
71 if (!IndexInMap( i))
72 AddFieldToList(top.fieldMap.GetFieldDescription( i), i, false);
73 }
74 }
75
CreateField
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
76 function CreateField( name, index, on)
77 {
78 var item = document.createElement('listitem');
79 item.setAttribute('field-index', index);
80 item.setAttribute('type', "checkbox");
81 var cell = document.createElement('listcell');
82 var cCell = document.createElement( 'listcell');
83 cCell.setAttribute('type', "checkbox");
84 cCell.setAttribute( 'label', name);
85 if (on == true)
86 cCell.setAttribute( 'checked', "true");
87 item.appendChild( cCell);
88 cell.setAttribute( "class", "importsampledata");
89 cell.setAttribute( 'label', "");
90 item.appendChild( cell);
91 return( item);
92 }
93
AddFieldToList
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
94 function AddFieldToList(name, index, on)
95 {
96 var item = CreateField(name, index, on);
97 gListbox.appendChild(item);
98 }
99
itemClicked
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
100 function itemClicked(event)
101 {
102 if (event.button == 0) {
103 var on = gListbox.selectedItem.firstChild.getAttribute('checked');
104 gListbox.selectedItem.firstChild.setAttribute('checked', (on != "true"));
105 }
106 }
107
108 // The "Move Up/Move Down" buttons should move the items in the left column
109 // up/down but the values in the right column should not change.
moveItem
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
110 function moveItem(up)
111 {
112 var selectedItem = gListbox.selectedItem;
113 var swapPartner = (up ? gListbox.getPreviousItem(selectedItem, 1)
114 : gListbox.getNextItem(selectedItem, 1));
115
116 var tmpLabel = swapPartner.lastChild.getAttribute('label');
117 swapPartner.lastChild.setAttribute('label', selectedItem.lastChild.getAttribute('label'));
118 selectedItem.lastChild.setAttribute('label', tmpLabel);
119
120 var newItemPosition = (up ? selectedItem.nextSibling : selectedItem);
121 gListbox.insertBefore(swapPartner, newItemPosition);
122 gListbox.ensureElementIsVisible(selectedItem);
123 disableMoveButtons();
124 }
125
disableMoveButtons
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
126 function disableMoveButtons()
127 {
128 var selectedIndex = gListbox.selectedIndex;
129 gMoveUpButton.disabled = (selectedIndex == 0);
130 gMoveDownButton.disabled = (selectedIndex == (gListbox.getRowCount() - 1));
131 }
132
ShowSampleData
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
133 function ShowSampleData(data)
134 {
135 var fields = data.split("\n");
136 for (var i = 0; i < gListbox.getRowCount(); i++)
137 gListbox.getItemAtIndex(i).lastChild.setAttribute('label', (i < fields.length) ? fields[i] : '');
138 }
139
FetchSampleData
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
140 function FetchSampleData(num)
141 {
142 if (!top.addInterface)
143 return false;
144
145 var data = top.addInterface.GetData( "sampleData-" + num);
146 if (!(data instanceof Components.interfaces.nsISupportsString))
147 return false;
148 ShowSampleData( data.data);
149 return true;
150 }
151
Browse
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
152 function Browse(step)
153 {
154 recordNum += step;
155 if (FetchSampleData(recordNum - 1))
156 document.getElementById('recordNumber').setAttribute('value', ("" + recordNum));
157
158 gPreviousButton.disabled = (recordNum == 1);
159 gNextButton.disabled = (addInterface.GetData("sampleData-" + recordNum) == null);
160 }
161
FieldImportOKButton
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
162 function FieldImportOKButton()
163 {
164 var max = gListbox.getRowCount();
165 var fIndex;
166 var on;
167 for (var i = 0; i < max; i++) {
168 fIndex = gListbox.getItemAtIndex(i).getAttribute( 'field-index');
169 on = gListbox.getItemAtIndex(i).firstChild.getAttribute('checked');
170 top.fieldMap.SetFieldMap( i, fIndex);
171 top.fieldMap.SetFieldActive( i, (on == "true"));
172 }
173
174 top.fieldMap.skipFirstRecord = gSkipFirstRecordButton.checked;
175
176 top.dialogResult.ok = true;
177
178 return true;
179 }