home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / 01_02.iso / software / netscape62win / mail.xpi / bin / chrome / messenger.jar / content / messenger / fieldMapExport.js < prev    next >
Text File  |  2001-03-21  |  4KB  |  160 lines

  1. /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2.  *
  3.  * The contents of this file are subject to the Mozilla Public
  4.  * License Version 1.1 (the "License"); you may not use this file
  5.  * except in compliance with the License. You may obtain a copy of
  6.  * the License at http://www.mozilla.org/MPL/
  7.  *
  8.  * Software distributed under the License is distributed on an "AS
  9.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10.  * implied. See the License for the specific language governing
  11.  * rights and limitations under the License.
  12.  *
  13.  * The Original Code is mozilla.org code.
  14.  *
  15.  * The Initial Developer of the Original Code is Netscape
  16.  * Communications Corporation.  Portions created by Netscape are
  17.  * Copyright (C) 1999 Netscape Communications Corporation. All
  18.  * Rights Reserved.
  19.  *
  20.  * Contributor(s):
  21.  */
  22.  
  23. var importService = 0;
  24. var fieldMap = null;
  25.  
  26. function OnLoadFieldMapExport()
  27. {
  28.   top.importService = Components.classes["@mozilla.org/import/import-service;1"].getService();
  29.   top.importService = top.importService.QueryInterface(Components.interfaces.nsIImportService);
  30.  
  31.   // We need a field map object...
  32.   // assume we have one passed in? or just make one?
  33.   if (window.arguments && window.arguments[0])
  34.     top.fieldMap = window.arguments[0].fieldMap;
  35.   if (!top.fieldMap) {
  36.     top.fieldMap = top.importService.CreateNewFieldMap();
  37.     top.fieldMap.DefaultFieldMap( top.fieldMap.numMozFields);
  38.   }
  39.  
  40.   doSetOKCancel( FieldExportOKButton, 0);
  41.  
  42.   ListFields();
  43. }
  44.  
  45. function SetDivText(id, text)
  46. {
  47.   var div = document.getElementById(id);
  48.  
  49.   if ( div )
  50.   {
  51.     if ( div.childNodes.length == 0 )
  52.     {
  53.       var textNode = document.createTextNode(text);
  54.       div.appendChild(textNode);
  55.     }
  56.     else if ( div.childNodes.length == 1 )
  57.       div.childNodes[0].nodeValue = text;
  58.   }
  59. }
  60.  
  61.  
  62. function FieldExportOKButton()
  63. {
  64.   // hmmm... can we re-build the map from the tree values?
  65.   return true;
  66. }
  67.  
  68.  
  69. function FieldSelectionChanged()
  70. {
  71.   var tree = document.getElementById('fieldList');
  72.   if ( tree && tree.selectedItems && (tree.selectedItems.length == 1) )
  73.   {
  74.   }
  75. }
  76.  
  77. function ExportSelectionChanged()
  78. {
  79.   var tree = document.getElementById('exportList');
  80.   if ( tree && tree.selectedItems && (tree.selectedItems.length == 1) )
  81.   {
  82.   }
  83. }
  84.  
  85.  
  86. function ListFields() {
  87.   if (top.fieldMap == null)
  88.     return;
  89.  
  90.   // we should fill in the field list with the data from the field map?
  91.   var body = document.getElementById("fieldBody");
  92.   var count = top.fieldMap.numMozFields;
  93.   for (i = 0; i < count; i++) {
  94.     AddFieldToList( body, top.fieldMap.GetFieldDescription( i), i);
  95.   }
  96.  
  97.   body = document.getElementById("exportBody");
  98.   count = top.fieldMap.mapSize;
  99.   var index;
  100.   for (i = 0; i < count; i++) {
  101.     index = top.fieldMap.GetFieldMap( i);
  102.     AddFieldToList( body, top.fieldMap.GetFieldDescription( index), index);
  103.   }
  104. }
  105.  
  106. function AddFieldToList(body, name, index)
  107. {
  108.  
  109.   var item = document.createElement('treeitem');
  110.   var row = document.createElement('treerow');
  111.   var cell = document.createElement('treecell');
  112.   cell.setAttribute('label', name);
  113.   item.setAttribute('field-index', index);
  114.  
  115.   row.appendChild(cell);
  116.   item.appendChild(row);
  117.   body.appendChild(item);
  118. }
  119.  
  120. function DeleteExportItems()
  121. {
  122.   var tree = document.getElementById('exportList');
  123.   if ( tree && tree.selectedItems && (tree.selectedItems.length > 0) ) {
  124.     var body = document.getElementById("exportBody");
  125.     if (body) {
  126.       while (tree.selectedItems.length) {
  127.         body.removeChild( tree.selectedItems[0]);
  128.       }
  129.     }
  130.   }
  131. }
  132.  
  133. function OnAddExport()
  134. {
  135.   var tree = document.getElementById('fieldList');
  136.   if ( tree && tree.selectedItems && (tree.selectedItems.length > 0) ) {
  137.     var body = document.getElementById("exportBody");
  138.     if (body) {
  139.       var name;
  140.       var fIndex;
  141.       for (var index = 0; index < tree.selectedItems.length; index++) {
  142.         name = tree.selectedItems[index].firstChild.firstChild.getAttribute( 'label');
  143.         fIndex = tree.selectedItems[index].getAttribute( 'field-index');
  144.         AddFieldToList( body, name, fIndex);
  145.       }
  146.     }
  147.   }
  148. }
  149.  
  150. function OnAddAllExport()
  151. {
  152.   var body = document.getElementById("exportBody");
  153.   var count = top.fieldMap.numMozFields;
  154.   for (var i = 0; i < count; i++) {
  155.     AddFieldToList( body, top.fieldMap.GetFieldDescription( i), i);
  156.   }
  157. }
  158.  
  159.  
  160.