src/js/serializers/JSONSerializer.js
author hamidouk
Wed, 26 Oct 2011 11:32:21 +0200
branchpopcorn-port
changeset 147 955119f901b4
parent 137 ef6c1252c459
child 149 a10198c95808
permissions -rw-r--r--
added a function to search annotations to the json serializer.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
108
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
     1
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
     2
IriSP.JSONSerializer = function(DataLoader, url) {
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
     3
  IriSP.Serializer.call(this, DataLoader, url);
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
     4
};
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
     5
128
f3fec80dd31c renames and inheritance bug fixes.
hamidouk
parents: 108
diff changeset
     6
IriSP.JSONSerializer.prototype = new IriSP.Serializer();
108
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
     7
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
     8
IriSP.JSONSerializer.prototype.serialize = function(data) {
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
     9
  return JSON.stringify(data);
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    10
};
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    11
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    12
IriSP.JSONSerializer.prototype.deserialize = function(data) {
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    13
  return JSON.parse(data);
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    14
};
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    15
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    16
IriSP.JSONSerializer.prototype.sync = function(callback) {
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    17
  /* we don't have to do much because jQuery handles json for us */
128
f3fec80dd31c renames and inheritance bug fixes.
hamidouk
parents: 108
diff changeset
    18
137
ef6c1252c459 clarified the closure code.
hamidouk
parents: 128
diff changeset
    19
  var self = this;
ef6c1252c459 clarified the closure code.
hamidouk
parents: 128
diff changeset
    20
ef6c1252c459 clarified the closure code.
hamidouk
parents: 128
diff changeset
    21
  var fn = function(data) {      
ef6c1252c459 clarified the closure code.
hamidouk
parents: 128
diff changeset
    22
      self._data = data;      
ef6c1252c459 clarified the closure code.
hamidouk
parents: 128
diff changeset
    23
      // sort the data too     
ef6c1252c459 clarified the closure code.
hamidouk
parents: 128
diff changeset
    24
      self._data["annotations"].sort(function(a, b) 
108
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    25
          { var a_begin = +a.begin;
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    26
            var b_begin = +b.begin;
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    27
            return a_begin - b_begin;
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    28
          });
137
ef6c1252c459 clarified the closure code.
hamidouk
parents: 128
diff changeset
    29
     
ef6c1252c459 clarified the closure code.
hamidouk
parents: 128
diff changeset
    30
      callback(data);      
108
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    31
  };
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    32
  
137
ef6c1252c459 clarified the closure code.
hamidouk
parents: 128
diff changeset
    33
  this._DataLoader.get(this._url, fn);
108
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    34
};
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    35
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    36
IriSP.JSONSerializer.prototype.currentMedia = function() {  
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    37
  return this._data.medias[0]; /* FIXME: don't hardcode it */
62da43e72e30 broke the serializers across multiple files. added a newline to the end of
hamidouk
parents:
diff changeset
    38
};
147
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    39
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    40
/* this function searches for an annotation which matches title, description and keyword 
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    41
   "" matches any field. 
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    42
*/    
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    43
IriSP.JSONSerializer.prototype.searchAnnotations = function(title, description, keyword) {
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    44
    var rTitle;
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    45
    var rDescription;
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    46
    var rKeyword;
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    47
    
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    48
    /* match anything if given the empty string */
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    49
    if (title == "")
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    50
      title = ".*";
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    51
    if (description == "")
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    52
      description = ".*";
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    53
    if (keyword == "")
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    54
      keyword = ".*";
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    55
    
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    56
    rTitle = new RegExp(title, "i");  
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    57
    rDescription = new RegExp(description, "i");  
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    58
    rKeyword = new RegExp(keyword, "i");  
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    59
    
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    60
    var ret_array = [];
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    61
    
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    62
    var i;
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    63
    for (i in this._data.annotations) {
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    64
      var annotation = this._data.annotations[i];
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    65
      
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    66
      if (rTitle.test(annotation.content.title) && 
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    67
          rDescription.test(annotation.content.description)) {
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    68
          /* FIXME : implement keyword support */
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    69
          ret_array.push(annotation);
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    70
      }
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    71
    }
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    72
    
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    73
    return ret_array;
955119f901b4 added a function to search annotations to the json serializer.
hamidouk
parents: 137
diff changeset
    74
}
<  5!PW2PXCC0Wb)Gp2U`2U`ZʲSRhwϛ/!KVD2?! 0` 0`U{(w4"_=C0`¯ v)AWĩEYT?Dҡڑ}Uh%;p%X2Ci He 7PHd;_1UYi x }ad>d}2:jEWh8 UZ\S90`6=F1:lw櫽Wp j]*ccChyccPC5zA*ȂTSWd:UmV?WBeC^[5niWA ,0`ҕG9\Y|h`'hBJVC!UeHVE“ch\_~cʗ=]Z}!> CQ ^hhn%u"U}E0`VC!ʡ`m 7UUY *~֪eV/Xc씽I] / 0` h` 5 0` 0hh` 94?/Ewu}h}(} Y  *!0~ %{ 0`t 0`2<U:hjC'Kc ~y!/n)x&1`+"p0hhh{ UX1CCc EWe pd00b,n5x|«ccUC0p8  eC"+:%>vJH]jG1+(yxy`40~A!X:Q`p942"U =_: Uʗd2eW68Y"9v잷kdX:+=G8%w/:Ur|wU>;q t=qyCWQ` 0vRy|C%y⡱T..hw( ($PCKΆC! Y40JMC!%C 2/OAD?Z44d5PҮ*%5VJd~*!X:P]z.`D?@0`(C;!`aEbMU|}8<+0Jy" ,E,p Cd:0b,0`_UYI?X !0d,P= 30`ʫpeVPd2WP]a%?!7;vE?p~0~L|f,0}j>աCCp4J0d0p5C|Ec*U*U:~o/gw8sr7Uո`VCccUd~]!>d;>yJ:0` 640h{2*UYV)V@2F]UEULOTU+*fbS; E膇0zȾMnȣSEA[\"ړ7"T-CB``T>"c`-8x440`^\ !`0j+8ЂC "UOK/-YS(d2ˮh6)8UlE[6:C690U;C=u2,vg;Fcd9 80htG]hr< 0yThnnԇ"# CRO RDd:Q=Q`b,!C_Q=h~}G`b,22-WJU07 j"8;Cc;/ô;!w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