src/js/serializers/JSONSerializer.js
branchpopcorn-port
changeset 352 cc2cdecc5ce5
parent 320 b693ba1a83be
child 395 5766e8238aaf
equal deleted inserted replaced
351:e5190c3a682c 352:cc2cdecc5ce5
    39 
    39 
    40 /* this function searches for an annotation which matches title, description and keyword 
    40 /* this function searches for an annotation which matches title, description and keyword 
    41    "" matches any field. 
    41    "" matches any field. 
    42 */    
    42 */    
    43 IriSP.JSONSerializer.prototype.searchAnnotations = function(title, description, keyword) {
    43 IriSP.JSONSerializer.prototype.searchAnnotations = function(title, description, keyword) {
       
    44  
       
    45     /* we can have many types of annotations. We want search to only look for regular segments */
       
    46     /* the next two lines are a bit verbose because for some test data, _serializer.data.view is either
       
    47        null or undefined.
       
    48     */
       
    49     var view;
       
    50 
       
    51     if (typeof(this._data.views) !== "undefined" && this._data.views !== null)
       
    52        view = this._data.views[0];
       
    53 
       
    54     var searchViewType = "";
       
    55 
       
    56     if(typeof(view) !== "undefined" && typeof(view.annotation_types) !== "undefined" && view.annotation_types.length > 1) {
       
    57             searchViewType = view.annotation_types[0];
       
    58     }
       
    59 
    44     var rTitle;
    60     var rTitle;
    45     var rDescription;
    61     var rDescription;
    46     var rKeyword;
    62     var rKeyword;
    47     
    63     
    48     /* match anything if given the empty string */
    64     /* match anything if given the empty string */
    61     
    77     
    62     var i;
    78     var i;
    63     for (i in this._data.annotations) {
    79     for (i in this._data.annotations) {
    64       var annotation = this._data.annotations[i];
    80       var annotation = this._data.annotations[i];
    65       
    81       
       
    82       /* filter the annotations whose type is not the one we want */
       
    83       if (searchViewType  != "" && typeof(annotation.meta) !== "undefined" && typeof(annotation.meta["id-ref"]) !== "undefined"
       
    84             && annotation.meta["id-ref"] !== searchViewType) {
       
    85           continue;
       
    86       }
       
    87     
    66       if (rTitle.test(annotation.content.title) && 
    88       if (rTitle.test(annotation.content.title) && 
    67           rDescription.test(annotation.content.description)) {
    89           rDescription.test(annotation.content.description)) {
    68           /* FIXME : implement keyword support */
    90           /* FIXME : implement keyword support */
    69           ret_array.push(annotation);
    91           ret_array.push(annotation);
    70       }
    92       }