Changeset 82


Ignore:
Timestamp:
01/28/13 23:11:13 (6 years ago)
Author:
nhoyt
Message:

ai-sidebar.js (all references within namespace ainspectorSidebar)

  • in updateView fn., set variable rulesTable with call to getRulesData
  • in updateView fn., added call to sortRulesTable

rule-category.js (all references within namespace ainspectorSidebar)

  • added functions getRulesData and sortRulesTable
  • converted treeView to a constructor that takes a table as argument
  • updated setView function

rule-category.xul

  • added attributes to tree element: persist, sortDirection, sortResource
  • added attributes to treecol elements: onclick, class=sortDirectionIndicator
Location:
trunk/proto-10/chrome/content
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/proto-10/chrome/content/ai-sidebar.js

    r79 r82  
    150150 
    151151  ainspectorSidebar.viewTitle.value = ainspectorSidebar.getViewTitle(); 
     152  ainspectorSidebar.rulesTable = ainspectorSidebar.getRulesData(); 
     153  ainspectorSidebar.sortRulesTable(); 
    152154  ainspectorSidebar.setView(); 
    153155}; 
  • trunk/proto-10/chrome/content/rule-category.js

    r81 r82  
    1919}; 
    2020 
    21 ainspectorSidebar.treeView = { 
    22   rowCount : 10000, 
    23   getCellText : function (row, column) { 
    24     if (column.id == "ai-rule-col") return "Rule " + (row + 1); 
    25     else return ainspectorSidebar.getSampleString(row); 
    26   }, 
    27   setTree: function (treebox) { this.treebox = treebox; }, 
    28   isContainer: function (row) { return false; }, 
    29   isSeparator: function (row) { return false; }, 
    30   isSorted: function () { return false; }, 
    31   getLevel: function (row) { return 0; }, 
    32   getImageSrc: function (row, col) { return null; }, 
    33   getRowProperties: function (row, props) {}, 
    34   getCellProperties: function (row, col, props) {}, 
    35   getColumnProperties: function (colid, col, props) {} 
     21ainspectorSidebar.getRulesData = function () { 
     22  var table = []; 
     23  var maxRows = 10000; 
     24  for (var i = 0; i < maxRows; i++) { 
     25    table.push({ 
     26      "ai-rule-col": "Rule " + i, 
     27      // "ai-required-col": i % 2 ? "Yes" : "No", 
     28      "ai-required-col": ainspectorSidebar.getSampleString(i), 
     29      "ai-level-col": i % 3 ? (i % 3 == 1 ? "AA" : "AAA") : "A", 
     30      "ai-impl-col": i % 100, 
     31      "ai-mc-col": i % 10 }); 
     32  } 
     33  return table; 
     34}; 
     35 
     36ainspectorSidebar.treeView = function (table) { 
     37  this.rowCount = table.length; 
     38        this.getCellText = function (row, col) { return table[row][col.id];     }; 
     39        this.getCellValue = function (row, col) {       return table[row][col.id]; }; 
     40        this.setTree = function (treebox) {     this.treebox = treebox; }; 
     41  this.isEditable = function (row, col) { return col.editable;  }; 
     42        this.isContainer = function (row) { return false; }; 
     43        this.isSeparator = function (row) { return false; }; 
     44        this.isSorted = function () { return false; }; 
     45        this.getLevel = function (row) { return 0; }; 
     46        this.getImageSrc = function (row, col) { return null; }; 
     47        this.getRowProperties = function (row, props) {}; 
     48        this.getCellProperties = function (row, col, props) {}; 
     49        this.getColumnProperties = function (colid, col, props) {}; 
     50        this.cycleHeader = function (col, elem) {}; 
     51}; 
     52 
     53ainspectorSidebar.sortRulesTable = function (column) { 
     54        var columnName; 
     55        var tree = document.getElementById("ai-rule-category-tree"); 
     56        var order = tree.getAttribute("sortDirection") == "ascending" ? 1 : -1; 
     57 
     58        // If the column is passed and it's already sorted by that column, reverse sort. 
     59        if (column) { 
     60                columnName = column.id; 
     61                if (tree.getAttribute("sortResource") == columnName) { 
     62                        order *= -1; 
     63                } 
     64        } 
     65        else { 
     66                columnName = tree.getAttribute("sortResource"); 
     67        } 
     68 
     69        function normalize(o) { 
     70        if (typeof o == "string") { 
     71                  return o.toLowerCase(); 
     72          } 
     73          return o; 
     74  } 
     75 
     76        function columnSort(a, b) { 
     77                if (normalize(a[columnName]) > normalize(b[columnName])) return 1 * order; 
     78                if (normalize(a[columnName]) < normalize(b[columnName])) return -1 * order; 
     79 
     80                //tie breaker: ai-rule-col ascending is the second level sort 
     81    var secondary = "ai-rule-col"; 
     82                if (columnName != secondary) { 
     83                        if (normalize(a[secondary]) > normalize(b[secondary])) return 1; 
     84                        if (normalize(a[secondary]) < normalize(b[secondary])) return -1; 
     85                } 
     86                return 0; 
     87        } 
     88        ainspectorSidebar.rulesTable.sort(columnSort); 
     89 
     90        // Setting these will make the sort option persist. 
     91        tree.setAttribute("sortDirection", order == 1 ? "ascending" : "descending"); 
     92        tree.setAttribute("sortResource", columnName); 
     93        tree.view = new ainspectorSidebar.treeView(ainspectorSidebar.rulesTable); 
     94 
     95        // Set the appropriate attributes to show indicator. 
     96        var cols = tree.getElementsByTagName("treecol"); 
     97        for (var i = 0; i < cols.length; i++) { 
     98                cols[i].removeAttribute("sortDirection"); 
     99        } 
     100        document.getElementById(columnName).setAttribute("sortDirection", order == 1 ? "ascending" : "descending"); 
    36101}; 
    37102 
    38103ainspectorSidebar.setView = function () { 
    39   document.getElementById("ai-rule-category-tree").view = ainspectorSidebar.treeView; 
     104  document.getElementById("ai-rule-category-tree").view = 
     105    new ainspectorSidebar.treeView(ainspectorSidebar.rulesTable); 
    40106}; 
  • trunk/proto-10/chrome/content/rule-category.xul

    r81 r82  
    11<?xml version="1.0"?> 
     2<?xml-stylesheet href="chrome://global/skin/" type="text/css"?> 
    23<!DOCTYPE overlay SYSTEM "chrome://ai-sidebar/locale/ai-sidebar.dtd"> 
    34 
     
    910  <vbox id="ai-rule-category"> 
    1011 
    11     <tree id="ai-rule-category-tree" rows="10" flex="1"> 
     12    <tree id="ai-rule-category-tree" 
     13      rows="10" flex="1" 
     14      persist="sortDirection sortResource" 
     15      sortDirection="ascending" 
     16      sortResource="ai-rule-col"> 
    1217      <treecols> 
    1318        <treecol id="ai-rule-col" 
    1419          flex="1" minwidth="70" 
    1520          ignoreincolumnpicker="true" 
    16           label="&ai-treecol.rule;"/> 
     21          label="&ai-treecol.rule;" 
     22          onclick="ainspectorSidebar.sortRulesTable(this)" 
     23          sortDirection="ascending" 
     24          class="sortDirectionIndicator"/> 
    1725        <splitter class="tree-splitter"/> 
    1826        <treecol id="ai-required-col" 
    19           width="60" minwidth="40" 
    20           style="text-align: center" 
    21           label="&ai-treecol.required;"/> 
     27          width="68" minwidth="68" 
     28          style="text-align: left" 
     29          label="&ai-treecol.required;" 
     30          onclick="ainspectorSidebar.sortRulesTable(this)" 
     31          class="sortDirectionIndicator"/> 
    2232        <splitter class="tree-splitter"/> 
    2333        <treecol id="ai-level-col" 
    24           width="40" minwidth="40" 
    25           style="text-align: center" 
    26           label="&ai-treecol.level;"/> 
     34          width="47" minwidth="47" 
     35          style="text-align: left" 
     36          label="&ai-treecol.level;" 
     37          onclick="ainspectorSidebar.sortRulesTable(this)" 
     38          class="sortDirectionIndicator"/> 
    2739        <splitter class="tree-splitter"/> 
    2840        <treecol id="ai-impl-col" 
    29           width="40" minwidth="40" 
     41          width="56" minwidth="56" 
    3042          style="text-align: center" 
    3143          label="&ai-treecol.implementation;" 
    32           tooltiptext="&ai-treecol.implementationTooltip;"/> 
     44          tooltiptext="&ai-treecol.implementationTooltip;" 
     45          onclick="ainspectorSidebar.sortRulesTable(this)" 
     46          class="sortDirectionIndicator"/> 
    3347        <splitter class="tree-splitter"/> 
    3448        <treecol id="ai-mc-col" 
    35           width="40" minwidth="40" 
     49          width="48" minwidth="48" 
    3650          style="text-align: center" 
    3751          label="&ai-treecol.manualChecks;" 
    38           tooltiptext="&ai-treecol.manualChecksTooltip;"/> 
     52          tooltiptext="&ai-treecol.manualChecksTooltip;" 
     53          onclick="ainspectorSidebar.sortRulesTable(this)" 
     54          class="sortDirectionIndicator"/> 
    3955      </treecols> 
    4056      <treechildren/> 
Note: See TracChangeset for help on using the changeset viewer.