Getting rid of Bug 1364.
authorJakub Skoczen <jakub@indexdata.dk>
Tue, 11 Sep 2007 15:52:13 +0000 (15:52 +0000)
committerJakub Skoczen <jakub@indexdata.dk>
Tue, 11 Sep 2007 15:52:13 +0000 (15:52 +0000)
js/pz2.js

index 5850c59..0d61d04 100644 (file)
--- a/js/pz2.js
+++ b/js/pz2.js
@@ -1,5 +1,5 @@
 /*
-** $Id: pz2.js,v 1.54 2007-09-10 13:18:53 jakub Exp $
+** $Id: pz2.js,v 1.55 2007-09-11 15:52:13 jakub Exp $
 ** pz2.js - pazpar2's javascript client library.
 */
 
@@ -816,16 +816,83 @@ Element_getTextContent = function (DOM_Element)
 ** QUERY CLASS ******************************************************************
 *********************************************************************************
 */
-var pzQuery = function()
+
+var pzFilter = function()
 {
+    this.filterHash = new Array();
+    this.filterNums = 0;
+};
+
+pzFilter.prototype = 
+{
+    addFilter: function(name, value)
+    {
+        var filter = {"name": name, "id": value };
+        this.filterHash[this.filterHash.length] = filter;
+        this.filterNums++
+        return  this.filterHash.length - 1;
+    },
+    
+    setFilter: function(name, value)
+    {
+        this.filterHash = new Array();
+        this.filterNums = 0;
+        this.addFilter(name, value);
+    },
+    
+    getFilter: function(index)
+    {
+        return this.filterHash[index].id;
+    },
+    
+    getFilterName: function(index)
+    {
+        return this.filterHash[index].name;
+    },
+    
+    removeFilter: function(index)
+    {
+        delete this.filterHash[index];
+        this.filterNums--;
+    },
+    
+    clearFilter: function()
+    {
+        this.filterHash = new Array();
+        this.filterNums = 0;
+    },
+    
+    getFilterString: function()
+    { 
+        if( this.filterNums <= 0 ) {
+            return undefined;
+        }
+
+        var filter = 'pz:id=';
+        for(var i = 0; i < this.filterHash.length; i++)
+        {
+            if (this.filterHash[i] == undefined) continue;
+            if (filter > 'pz:id=') filter = filter + '|';            
+            filter += this.filterHash[i].id; 
+        }
+        return filter;
+    }
+};
+
+var mkState = function()
+{
+    this.sort = 'relevance';
+    this.perPage = 20;
+    this.page = 0;
     this.simpleQuery = '';
     this.singleFilter = null;
     this.advTerms = new Array();
-    this.filterHash = new Array();
     this.numTerms = 0;
-    this.filterNums = 0;
+    this.action = '';
 };
-pzQuery.prototype = {
+
+mkState.prototype = 
+{
     reset: function()
     {
         this.simpleQuery = '';
@@ -833,24 +900,29 @@ pzQuery.prototype = {
         this.simpleFilter = null;
         this.numTerms = 0;
     },
+    
     clearSimpleQuery: function()
     {
         this.simpleQuery = '';
     },
+    
     addTerm: function(field, value)
     {
         var term = {"field": field, "value": value};
         this.advTerms[this.numTerms] = term;
         this.numTerms++;
     },
+    
     getTermValueByIdx: function(index)
     {
         return this.advTerms[index].value;
     },
+    
     getTermFieldByIdx: function(index)
     {
         return this.advTerms[index].field;
     },
+    
     /* semicolon separated list of terms for given field*/
     getTermsByField: function(field)
     {
@@ -862,21 +934,25 @@ pzQuery.prototype = {
         }
         return terms;
     },
+    
     addTermsFromList: function(inputString, field)
     {
         var inputArr = inputString.split(';');
         for(var i=0; i < inputArr.length; i++)
         {
             if(inputArr[i].length < 3) continue;
-            this.advTerms[this.numTerms] = {"field": field, "value": inputArr[i] };
+            this.advTerms[this.numTerms] 
+                = {"field": field, "value": inputArr[i] };
             this.numTerms++;
         }
     },
+    
     removeTermByIdx: function(index)
     {
         this.advTerms.splice(index, 1);
         this.numTerms--;
     },
+    
     toCCL: function()
     {   
         var ccl = '';
@@ -885,77 +961,40 @@ pzQuery.prototype = {
         for(var i = 0; i < this.advTerms.length; i++)
         {
             if (ccl != '') ccl = ccl + ' and ';
-            ccl = ccl + this.advTerms[i].field+'="'+this.advTerms[i].value+'"';
+            ccl = ccl + this.advTerms[i].field
+                +'="'+this.advTerms[i].value+'"';
         }
         return ccl;
     },
-    addFilter: function(name, value)
-    {
-        var filter = {"name": name, "id": value };
-        this.filterHash[this.filterHash.length] = filter;
-        this.filterNums++
-        return  this.filterHash.length - 1;
-    },
-    setFilter: function(name, value)
-    {
-        this.filterHash = new Array();
-        this.filterNums = 0;
-        this.addFilter(name, value);
-    },
-    getFilter: function(index)
-    {
-        return this.filterHash[index].id;
-    },
-    getFilterName: function(index)
-    {
-        return this.filterHash[index].name;
-    },
-    removeFilter: function(index)
-    {
-        delete this.filterHash[index];
-        this.filterNums--;
-    },
-    clearFilter: function()
-    {
-        this.filterHash = new Array();
-        this.filterNums = 0;
-    },
-    getFilterString: function()
-    {
-        //temporary
-        if( this.singleFilter != null ) {
-            return 'pz:id='+this.singleFilter.id;
-        } 
-        else if( this.filterNums <= 0 ) {
-            return undefined;
-        }
-
-        var filter = 'pz:id=';
-        for(var i = 0; i < this.filterHash.length; i++)
-        {
-            if (this.filterHash[i] == undefined) continue;
-            if (filter > 'pz:id=') filter = filter + '|';            
-            filter += this.filterHash[i].id; 
-        }
-        return filter;
-    },
+    
     totalLength: function()
     {
         var simpleLength = this.simpleQuery != '' ? 1 : 0;
         return this.advTerms.length + simpleLength;
     },
+    
     clearSingleFilter: function()
     {
         this.singleFilter = null;
     },
+    
     setSingleFilter: function(name, value)
     {
         this.singleFilter = {"name": name, "id": value };
     },
+    
     getSingleFilterName: function()
     {
         return this.singleFilter.name;
-    }
-}
+    },
 
+    getSingleFilterString: function()
+    {
+        if( this.singleFilter != null ) {
+            return 'pz:id='+this.singleFilter.id;
+        } else {
+            return undefined;
+        }
+    }
+};
 }