src/js/data.js
author hamidouk
Mon, 14 Nov 2011 17:19:26 +0100
branchrequire-js
changeset 238 6008172a0592
parent 184 a4be54204b71
permissions -rw-r--r--
converted all the source files to use the require.js syntax.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
     1
/* data.js - this file deals with how the players gets and sends data */
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
     2
define(["IriSP"], function() {
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
     3
  IriSP.DataLoader = function() {
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
     4
    this._cache = {};
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
     5
  };
61
dc7b5ed7b02b DataLoader, first draft.
hamidouk
parents: 44
diff changeset
     6
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
     7
  IriSP.DataLoader.prototype.get = function(url, callback) {  
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
     8
    if (this._cache.hasOwnProperty(url)) {
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
     9
      callback(this._cache[url]);
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    10
    } else {
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    11
      /* we need a closure because this gets lost when it's called back */
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    12
      IriSP.jQuery.get(url, callback);  
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    13
      /*
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    14
      IriSP.jQuery.get(url, (function(obj) {      
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    15
                                 return function(data) {
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    16
                                    obj._cache[url] = data;      
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    17
                                    callback(obj._cache[url]);
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    18
                                  }; 
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    19
                                })(this));
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    20
      */
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    21
         
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    22
    }
61
dc7b5ed7b02b DataLoader, first draft.
hamidouk
parents: 44
diff changeset
    23
  }
dc7b5ed7b02b DataLoader, first draft.
hamidouk
parents: 44
diff changeset
    24
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    25
  /* the base abstract "class" */
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    26
  IriSP.Serializer = function(DataLoader, url) {
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    27
    this._DataLoader = DataLoader;
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    28
    this._url = url;
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    29
    this._data = [];
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    30
  };
65
6a8cae20f190 Added new unit tests and changes to the data classes.
hamidouk
parents: 61
diff changeset
    31
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    32
  IriSP.Serializer.prototype.serialize = function(data) { };
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    33
  IriSP.Serializer.prototype.deserialize = function(data) {};
65
6a8cae20f190 Added new unit tests and changes to the data classes.
hamidouk
parents: 61
diff changeset
    34
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    35
  IriSP.Serializer.prototype.currentMedia = function() {  
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    36
  };
70
3f86d4126491 added some changes to IriSP.Serializer.
hamidouk
parents: 69
diff changeset
    37
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    38
  IriSP.Serializer.prototype.sync = function(callback) {  
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    39
    callback.call(this, this._data);  
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    40
  };
70
3f86d4126491 added some changes to IriSP.Serializer.
hamidouk
parents: 69
diff changeset
    41
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    42
  IriSP.SerializerFactory = function(DataLoader) {
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    43
    this._dataloader = DataLoader;
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    44
  };
65
6a8cae20f190 Added new unit tests and changes to the data classes.
hamidouk
parents: 61
diff changeset
    45
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    46
  IriSP.SerializerFactory.prototype.getSerializer = function(metadataOptions) {
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    47
    /* This function returns serializer set-up with the correct
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    48
       configuration - takes a metadata struct describing the metadata source
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    49
    */
128
f3fec80dd31c renames and inheritance bug fixes.
hamidouk
parents: 108
diff changeset
    50
    
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    51
    if (metadataOptions === undefined)
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    52
      /* return an empty serializer */
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    53
      return IriSP.Serializer("", "");
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    54
              
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    55
    switch(metadataOptions.type) {
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    56
      case "json":
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    57
        return new IriSP.JSONSerializer(this._dataloader, metadataOptions.src);
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    58
        break;
128
f3fec80dd31c renames and inheritance bug fixes.
hamidouk
parents: 108
diff changeset
    59
      
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    60
      case "dummy": /* only used for unit testing - not defined in production */
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    61
        return new IriSP.MockSerializer(this._dataloader, metadataOptions.src);
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    62
        break;
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    63
      
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    64
      case "empty":
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    65
        return new IriSP.Serializer("", "empty");
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    66
        break;
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    67
        
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    68
      default:      
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    69
        return undefined;
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    70
    }
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    71
  };
65
6a8cae20f190 Added new unit tests and changes to the data classes.
hamidouk
parents: 61
diff changeset
    72
6a8cae20f190 Added new unit tests and changes to the data classes.
hamidouk
parents: 61
diff changeset
    73
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    74
  IriSP.getMetadata = function() {
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    75
    
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    76
    IriSP.jQuery.ajax({
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    77
        dataType: IriSP.config.metadata.load,
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    78
        url:IriSP.config.metadata.src,
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    79
        success : function( json ){
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    80
        
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    81
          IriSP.trace( "ajax", "success" );
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    82
          
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    83
          // START PARSING ----------------------- 
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    84
          if( json === "" ){
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    85
            alert( "Json load error" );
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    86
          } else {							  							  
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    87
            // # CREATE MEDIA  							//
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    88
            // # JUSTE ONE PLAYER FOR THE MOMENT		//
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    89
            //__IriSP.jQuery("<div></div>").appendTo("#output");
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    90
            var MyMedia = new  __IriSP.Media(
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    91
                              json.medias[0].id,
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    92
                              json.medias[0].href,
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    93
                              json.medias[0]['meta']['dc:duration'],
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    94
                              json.medias[0]['dc:title'],
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    95
                              json.medias[0]['dc:description']);
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    96
            
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    97
            IriSP.trace( "__IriSP.MyApiPlayer",
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    98
                              IriSP.config.gui.width+"   "
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
    99
                              + IriSP.config.gui.height + " "
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   100
                              + json.medias[0].href + " "
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   101
                              + json.medias[0]['meta']['dc:duration'] + " "
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   102
                              + json.medias[0]['meta']['item']['value']);
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   103
            
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   104
            // Create APIplayer
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   105
            IriSP.MyApiPlayer = new __IriSP.APIplayer (
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   106
                              IriSP.config.gui.width,
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   107
                              IriSP.config.gui.height,
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   108
                              json.medias[0].href,
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   109
                              json.medias[0]['meta']['dc:duration'],
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   110
                              json.medias[0]['meta']['item']['value']);
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   111
          
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   112
            // # CREATE THE FIRST LINE  				//
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   113
            IriSP.trace( "__IriSP.init.main","__IriSP.Ligne" );
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   114
            IriSP.MyLdt = new __IriSP.Ligne(
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   115
                              json['annotation-types'][0].id,
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   116
                              json['annotation-types'][0]['dc:title'],
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   117
                              json['annotation-types'][0]['dc:description'],
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   118
                              json.medias[0]['meta']['dc:duration']);			
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   119
            
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   120
            // CREATE THE TAG CLOUD 					//
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   121
            IriSP.trace( "__IriSP.init.main","__IriSP.Tags" );
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   122
            IriSP.MyTags =  new __IriSP.Tags( json.tags );
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   123
          
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   124
            // CREATE THE ANNOTATIONS  				    //
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   125
            // JUSTE FOR THE FIRST TYPE   			 	//
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   126
            /* FIXME: make it support more than one ligne de temps */
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   127
            IriSP.jQuery.each( json.annotations, function(i,item) {
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   128
              if (item.meta['id-ref'] == IriSP.MyLdt.id) {
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   129
                //__IriSP.trace("__IriSP.init.main","__IriSP.MyLdt.addAnnotation");
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   130
                IriSP.MyLdt.addAnnotation(
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   131
                      item.id,
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   132
                      item.begin,
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   133
                      item.end,
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   134
                      item.media,
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   135
                      item.content.title,
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   136
                      item.content.description,
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   137
                      item.content.color,
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   138
                      item.tags);
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   139
              }
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   140
                //MyTags.addAnnotation(item);
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   141
            } );	
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   142
            IriSP.jQuery.each( json.lists, function(i,item) {
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   143
              IriSP.trace("lists","");
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   144
            } );	
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   145
            IriSP.jQuery.each( json.views, function(i,item) {
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   146
              IriSP.trace("views","");
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   147
            } );	
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   148
          }
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   149
          // END PARSING ----------------------- //  
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   150
        
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   151
                
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   152
      }, error : function(data){
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   153
          alert("ERROR : "+data);
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   154
      }
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   155
      });	
31
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
   156
238
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   157
  }
6008172a0592 converted all the source files to use the require.js syntax.
hamidouk
parents: 184
diff changeset
   158
});