Ignore:
Timestamp:
2011-03-01T11:51:24+13:00 (13 years ago)
Author:
davidb
Message:

Adding of reindex and explode functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/web/script/gsajaxapi.js

    r23466 r23740  
    2626    }
    2727
    28 
    29     this.urlGetAsync = function(url,locid)
     28    this.indexserverURL = function()
     29    {
     30        return this.apiURL("index-server.pl");
     31    }
     32
     33    this.explodeserverURL = function()
     34    {
     35        return this.apiURL("explode-server.pl");
     36    }
     37
     38
     39    this.urlGetAsync = function(url,callback)
    3040    {
    3141       var xmlHttp;
     
    4959         }
    5060       }
    51    
    52        xmlHttp.onreadystatechange=function() {
    53          if(xmlHttp.readyState==4) {
    54            if (locelem != null) {
    55              var locelem = document.getElementById(locid);
    56    
    57              locelem.innerHTML = xmlHttp.responseText;
    58            }
    59          }
    60        }
    61    
    62        xmlHttp.open("GET",url,true);
    63        xmlHttp.send(null);
     61
     62    var typeof_callback = typeof(callback);
     63    if ((typeof_callback == "string") || (typeof_callback == "number") || (typeof_callback == "boolean")) {
     64        var locid = callback;
     65
     66        xmlHttp.onreadystatechange=function() {
     67        if(xmlHttp.readyState==4) {
     68            if (locelem != null) {
     69            var locelem = document.getElementById(locid);
     70           
     71            locelem.innerHTML = xmlHttp.responseText;
     72            }
     73        }
     74        }
     75    }
     76    else if (typeof_callback == "function") {
     77        xmlHttp.onreadystatechange=function() {
     78        if(xmlHttp.readyState==4) {
     79            callback(xmlHttp);
     80        }
     81        }
     82    }
     83    else {
     84        alert("Unrecognized type of callback value: " + typeof_callback);
     85    }
     86
     87    xmlHttp.open("GET",url,true);
     88    xmlHttp.send(null);
    6489    }
    6590   
     
    98123    }
    99124   
     125
    100126   
    101127    this.setLiveMetadata = function(id,metaname,metavalue)
     
    114140    }
    115141   
    116     this._setMetadata = function(mode,docid,metaname,metapos,metavalue,metamode)
    117     {
    118         var mdserver = this.metadataserverURL();
    119    
    120         var url = mdserver + "?a=set" + mode + "-metadata";
    121         url += "&c="+collect_;
    122         url += "&d="+docid;
    123         url += "&metaname=" + metaname;
     142    this._setMetadata = function(mode,docid,metaname,metapos,metavalue,metamode)
     143    {
     144        var mdserver = this.metadataserverURL();
     145   
     146        var params = "a=set" + mode + "-metadata";
     147        params += "&c="+collect_;
     148        params += "&d="+docid;
     149        params += "&metaname=" + metaname;
    124150        if (metapos!=null) {
    125             url += "&metapos=" + metapos;
    126         }
    127         url += "&metavalue=" + metavalue;
    128         if (metamode!=null) {
    129             url += "&metamode=" + metamode;
    130         }
    131     // alert("url = " + url);
    132    
    133         this.urlGetSync(url);
     151            params += "&metapos=" + metapos;
     152        }
     153        params += "&metavalue=" + metavalue;
     154    if (metamode!=null) {
     155            params += "&metamode=" + metamode;
     156    }
     157    // alert("params = " + params);
     158   
     159    //alert(mdserver + "?" + params);
     160
     161        this.urlGetSync(mdserver + "?" + params);
     162        //this.urlPostSync(mdserver,params);
    134163    }
    135164   
    136165    this.setDocumentMetadata = function(docid,metaname,metapos,metavalue)
    137166    {
    138         // Allow for three param call to function, where metapos is missed out
     167    // Allow for three param call to function, where metapos is missed out
    139168        if (metavalue==null) {
    140169        // 4 param case
    141170        metavalue = metapos;
    142171        metapos = null;
    143         }
    144    
    145         this._setMetadata("",docid,metaname,metapos,metavalue);
    146         // this._setMetadata("-archives",docid,metaname,metapos,metavalue,"override");
    147     }
    148 
    149      this.setNewDocumentMetadata = function(docid,metaname,metavalue)
    150     {
    151         this._setMetadata("",docid,metaname,null,metavalue);
    152         this._setMetadata("-archives",docid,metaname,null,metavalue,"accumulate");
    153     }
    154    
    155     this.setImportMetadata = function(docid,metaname,metapos,metavalue)
    156     {
    157         this._setMetadata("-import",docid,metaname,metapos,metavalue);
    158     }
    159    
    160 
     172    }
     173   
     174    this._setMetadata("",docid,metaname,metapos,metavalue);
     175    this._setMetadata("-archives",docid,metaname,metapos,metavalue,"override");
     176    }
     177
     178    this.setNewDocumentMetadata = function(docid,metaname,metavalue)
     179    {
     180    this._setMetadata("",docid,metaname,null,metavalue);
     181    this._setMetadata("-archives",docid,metaname,null,metavalue,"accumulate");
     182    }
     183   
     184    this.setImportMetadata = function(docid,metaname,metapos,metavalue)
     185    {
     186    this._setMetadata("-import",docid,metaname,metapos,metavalue,"override");
     187    }
     188   
     189
     190    this.explodeDocument = function(docid)
     191    {
     192        var exserver = this.explodeserverURL();
     193
     194        var url = exserver + "?a=explode";
     195        url += "&c="+collect_;
     196        url += "&d="+docid;
     197
     198    // alert("url = " + url);
     199   
     200        this.urlGetSync(url);
     201    }
     202   
     203    // consider name change to reindexDocument
    161204    this.documentReindex = function(docid)
    162205    {
     
    171214        this.urlGetSync(url);
    172215    }
    173    
     216
     217
     218    this.reindexCollection = function(mode,callback)
     219    {
     220        if (mode==null) {
     221        mode = "incremental";
     222    }
     223
     224        var idserver = this.indexserverURL();
     225   
     226        var url = idserver + "?a=" + mode + "-rebuild";
     227        url += "&c="+collect_;
     228
     229    // alert("url = " + url);
     230   
     231        this.urlGetAsync(url,callback);
     232    }   
     233   
     234
    174235    this.getLiveMetadata = function(id,metaname)
    175236    {
Note: See TracChangeset for help on using the changeset viewer.