Friday, June 11, 2010

Violation Table + Filter

At some point I was given the task to build a working filter for our Violations Tables and it had to work for Firefox as well as IE. The filter needs to transform before the main three tables because it determines what can be shown in them. I experienced a number of difficulties with synchronizing the different xml transforms since there are several going on on this page, and some needed to be done before others. I succeeded but my solution was not as nice (code wise) as I would have liked. Later on, Firefox finally started supporting asynchronous xml and xsl downloads so I could tell better when things would finish instead of polling the ready state. Click on the image to the right to see my end result better.



Here's a snippet of my filter code so you'll be able to do that same: (new way)

function setXML(sourceURL) {
          this.xmlSource = sourceURL;
          if(window.ActiveXObject)
          {
            treeXml = new ActiveXObject('Microsoft.XMLDOM');
            treeXml.async = false;
            treeXml.load(sourceURL);
            this.XML = treeXml;

          }else{
            xmlhttp=new XMLHttpRequest();
            //xmlhttp.onreadystatechange=xml_Change;old way
            xmlhttp.open("GET",this.xmlSource,true);//"sourceURL"
            xmlhttp.overrideMimeType("text/xml");
            xmlhttp.send(null);

            setXML();//new way
          }
      }
      ViolationsFilterTable.prototype.setXML = setXML;

function setXML(){
      var xmlTree = xmlhttp.responseXML;
      lookupObject('filterTable').setMyXML(xmlTree);
      lookupObject('filterTable').setXmlLoaded(true);
      lookupObject('filterTable').initFilterTableFinal();//now transform in Firefox
call loadXSL(); (now with less waiting and polling) }


(old way) function xml_Change()//function for finished loading XSL
        {
            if (xmlhttp.readyState==4)//loaded = 4
            {
                if (xmlhttp.status==200)//status ok = 200
                {
                    var xmlTree = xmlhttp.responseXML;
                    lookupObject('filterTable').setMyXML(xmlTree);
                    lookupObject('filterTable').setXmlLoaded(true);
                    lookupObject('filterTable').initFilterTableFinal();//now transform in Firefox

//call loadXSL(); (old way)
                }
            }
        }

No comments:

Post a Comment