[jboss-cvs] jboss-seam/examples/seambay/view ...

Shane Bryzak sbryzak at redhat.com
Wed Jul 4 22:20:14 EDT 2007


  User: sbryzak2
  Date: 07/07/04 22:20:14

  Modified:    examples/seambay/view   sell2.js sell2.xhtml
  Log:
  category selection
  
  Revision  Changes    Path
  1.2       +104 -3    jboss-seam/examples/seambay/view/sell2.js
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: sell2.js
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/seambay/view/sell2.js,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- sell2.js	4 Jul 2007 05:40:11 -0000	1.1
  +++ sell2.js	5 Jul 2007 02:20:14 -0000	1.2
  @@ -17,11 +17,94 @@
       
       if (cat.getParent() == null)
       {     
  +      // Set the tier for root categories to 1    
  +      cat.tier = 1;
  +      
         var option = new Option(cat.getName() + (isParent(cat) ? " >" : ""), cat.getCategoryId());
         var idx = catList.options.length;
         catList.options[idx] = option;
       }
     }   
  +  
  +  var catId = document.getElementById("catSelection:categoryId").value;  
  +  
  +  // If the category ID is valid, select it
  +  if ((typeof(catId) == "number" || !isNaN(parseInt(catId))))
  +  {
  +    var cats = new Array();
  +    var cat = findCategory(catId);
  +    
  +    while (cat.parent != null)
  +    {
  +       cats.push(cat);
  +       cat = cat.parent;
  +    }
  +    cats.push(cat);    
  +    
  +    // select the correct root category
  +    var rootCat = document.getElementById("rootCategory");
  +    for (var i = 0; i < rootCat.options.length; i++)
  +    {
  +      if (rootCat.options[i].value == cat.getCategoryId())
  +      {
  +        rootCat.options[i].selected = true;
  +        break; 
  +      } 
  +    }
  +    
  +    for (var i = cats.length - 1; i >= 0; i--)
  +    {
  +      if (i > 0)
  +        drawSubTier(cats[i], cats[i - 1].getCategoryId())
  +      else              
  +        drawSubTier(cats[i]); 
  +    }
  +  }
  +}
  +
  +function findCategory(categoryId)
  +{
  +  for (var i = 0; i < categories.length; i++)
  +  {
  +    if (categories[i].getCategoryId() == categoryId)
  +      return categories[i]; 
  +  } 
  +  
  +  return null;
  +}
  +
  +function drawSubTier(category, selectedCatId)
  +{
  +  var container = document.getElementById("container");
  +  
  +  if (isParent(category))
  +  {
  +    var subcats = document.createElement("select");
  +    subcats.size = 8;
  +    subcats.className = "categoryList";
  +    subcats.id = "tier" + (category.tier + 1);
  +    subcats.onchange = function() { selectCategory(subcats); };      
  +    
  +    for (var i = 0; i < categories.length; i++)
  +    {
  +      var subcat = categories[i];
  +      if (subcat.getParent() == category)
  +      {
  +        subcat.tier = category.tier + 1; 
  +        var option = new Option(subcat.getName() + (isParent(subcat) ? " >" : ""), subcat.getCategoryId());
  +        if (subcat.getCategoryId() == selectedCatId)
  +        {
  +          option.selected = true;
  +        }
  +        var idx = subcats.options.length;
  +        subcats.options[idx] = option;
  +      } 
  +    }
  +    
  +    var d = document.createElement("div");
  +    d.appendChild(subcats);
  +    container.appendChild(d);  
  +  }  
   }
   
   function isParent(category)
  @@ -55,5 +138,23 @@
   function selectCategory(ctl)
   {
     var opt = getSelectedOption(ctl);
  -  document.getElementById("categoryId").value = opt.value;
  +  
  +  var ctl = document.getElementById("catSelection:categoryId");
  +  var previous = findCategory(ctl.value);
  +  ctl.value = opt.value;
  +  
  +  var cat = findCategory(opt.value);
  + 
  +  if (previous)
  +  {
  +    // Prune the previously selected category
  +    var container = document.getElementById("container");  
  +    for (var i = previous.tier + 1; i > cat.tier; i--)
  +    {    
  +      var t = document.getElementById("tier" + i);
  +      if (t) container.removeChild(t.parentNode);
  +    }
  +  }
  +  
  +  drawSubTier(cat);
   }
  \ No newline at end of file
  
  
  
  1.4       +2 -2      jboss-seam/examples/seambay/view/sell2.xhtml
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: sell2.xhtml
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/seambay/view/sell2.xhtml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- sell2.xhtml	4 Jul 2007 05:40:11 -0000	1.3
  +++ sell2.xhtml	5 Jul 2007 02:20:14 -0000	1.4
  @@ -28,9 +28,9 @@
             Select the category that most closely matches the item you're selling
           </div>
   
  -        <h:form>
  +        <h:form id="catSelection">
                   
  -          <div class="category">
  +          <div id="container" class="category">
               <div>
                 <select id="rootCategory" class="categoryList" size="8" onchange="selectCategory(this)">
                   <option>Loading categories...</option>
  
  
  



More information about the jboss-cvs-commits mailing list