src/js/data.js
author hamidouk
Tue, 11 Oct 2011 17:13:08 +0200
branchpopcorn-port
changeset 61 dc7b5ed7b02b
parent 44 1e295123f2a1
child 65 6a8cae20f190
permissions -rw-r--r--
DataLoader, first draft.
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 */
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
     2
61
dc7b5ed7b02b DataLoader, first draft.
hamidouk
parents: 44
diff changeset
     3
IriSP.DataLoader = function() {
dc7b5ed7b02b DataLoader, first draft.
hamidouk
parents: 44
diff changeset
     4
  this._cache = {};
dc7b5ed7b02b DataLoader, first draft.
hamidouk
parents: 44
diff changeset
     5
};
dc7b5ed7b02b DataLoader, first draft.
hamidouk
parents: 44
diff changeset
     6
dc7b5ed7b02b DataLoader, first draft.
hamidouk
parents: 44
diff changeset
     7
IriSP.DataLoader.prototype.get = function(url, callback) {  
dc7b5ed7b02b DataLoader, first draft.
hamidouk
parents: 44
diff changeset
     8
  if (this._cache.hasOwnProperty(url)) {
dc7b5ed7b02b DataLoader, first draft.
hamidouk
parents: 44
diff changeset
     9
    callback(this._cache[url]);
dc7b5ed7b02b DataLoader, first draft.
hamidouk
parents: 44
diff changeset
    10
  } else {
dc7b5ed7b02b DataLoader, first draft.
hamidouk
parents: 44
diff changeset
    11
    /* we need a closure because this gets lost when it's called back */
dc7b5ed7b02b DataLoader, first draft.
hamidouk
parents: 44
diff changeset
    12
    IriSP.jQuery.get(url, (function(obj) {      
dc7b5ed7b02b DataLoader, first draft.
hamidouk
parents: 44
diff changeset
    13
                               return function(data) {
dc7b5ed7b02b DataLoader, first draft.
hamidouk
parents: 44
diff changeset
    14
                                  obj._cache[url] = data;      
dc7b5ed7b02b DataLoader, first draft.
hamidouk
parents: 44
diff changeset
    15
                                  callback(obj._cache[url]);
dc7b5ed7b02b DataLoader, first draft.
hamidouk
parents: 44
diff changeset
    16
                                }; 
dc7b5ed7b02b DataLoader, first draft.
hamidouk
parents: 44
diff changeset
    17
                              })(this));
dc7b5ed7b02b DataLoader, first draft.
hamidouk
parents: 44
diff changeset
    18
       
dc7b5ed7b02b DataLoader, first draft.
hamidouk
parents: 44
diff changeset
    19
  }
dc7b5ed7b02b DataLoader, first draft.
hamidouk
parents: 44
diff changeset
    20
}
dc7b5ed7b02b DataLoader, first draft.
hamidouk
parents: 44
diff changeset
    21
dc7b5ed7b02b DataLoader, first draft.
hamidouk
parents: 44
diff changeset
    22
IriSP.Serializer = function(DataLoader) {
dc7b5ed7b02b DataLoader, first draft.
hamidouk
parents: 44
diff changeset
    23
  this.DataLoader = DataLoader;
dc7b5ed7b02b DataLoader, first draft.
hamidouk
parents: 44
diff changeset
    24
};
dc7b5ed7b02b DataLoader, first draft.
hamidouk
parents: 44
diff changeset
    25
31
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    26
IriSP.getMetadata = function() {
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    27
	
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    28
	IriSP.jQuery.ajax({
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    29
		  dataType: IriSP.config.metadata.load,
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    30
		  url:IriSP.config.metadata.src,
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    31
		  success : function( json ){
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    32
		  
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    33
				IriSP.trace( "ajax", "success" );
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    34
				
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    35
				// START PARSING ----------------------- 
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    36
				if( json === "" ){
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    37
					alert( "Json load error" );
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    38
				} else {							  							  
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    39
					// # CREATE MEDIA  							//
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    40
					// # JUSTE ONE PLAYER FOR THE MOMENT		//
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    41
					//__IriSP.jQuery("<div></div>").appendTo("#output");
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    42
					var MyMedia = new  __IriSP.Media(
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    43
														json.medias[0].id,
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    44
														json.medias[0].href,
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    45
														json.medias[0]['meta']['dc:duration'],
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    46
														json.medias[0]['dc:title'],
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    47
														json.medias[0]['dc:description']);
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    48
					
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    49
					IriSP.trace( "__IriSP.MyApiPlayer",
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    50
														IriSP.config.gui.width+"   "
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    51
														+ IriSP.config.gui.height + " "
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    52
														+ json.medias[0].href + " "
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    53
														+ json.medias[0]['meta']['dc:duration'] + " "
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    54
														+ json.medias[0]['meta']['item']['value']);
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    55
					
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    56
					// Create APIplayer
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    57
					IriSP.MyApiPlayer = new __IriSP.APIplayer (
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    58
														IriSP.config.gui.width,
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    59
														IriSP.config.gui.height,
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    60
														json.medias[0].href,
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    61
														json.medias[0]['meta']['dc:duration'],
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    62
														json.medias[0]['meta']['item']['value']);
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    63
				
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    64
					// # CREATE THE FIRST LINE  				//
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    65
					IriSP.trace( "__IriSP.init.main","__IriSP.Ligne" );
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    66
					IriSP.MyLdt = new __IriSP.Ligne(
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    67
														json['annotation-types'][0].id,
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    68
														json['annotation-types'][0]['dc:title'],
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    69
														json['annotation-types'][0]['dc:description'],
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    70
														json.medias[0]['meta']['dc:duration']);			
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    71
					
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    72
					// CREATE THE TAG CLOUD 					//
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    73
					IriSP.trace( "__IriSP.init.main","__IriSP.Tags" );
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    74
					IriSP.MyTags =  new __IriSP.Tags( json.tags );
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    75
				
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    76
					// CREATE THE ANNOTATIONS  				    //
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    77
					// JUSTE FOR THE FIRST TYPE   			 	//
44
1e295123f2a1 added a FIXME
hamidouk
parents: 31
diff changeset
    78
					/* FIXME: make it support more than one ligne de temps */
31
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    79
					IriSP.jQuery.each( json.annotations, function(i,item) {
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    80
						if (item.meta['id-ref'] == IriSP.MyLdt.id) {
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    81
							//__IriSP.trace("__IriSP.init.main","__IriSP.MyLdt.addAnnotation");
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    82
							IriSP.MyLdt.addAnnotation(
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    83
										item.id,
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    84
										item.begin,
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    85
										item.end,
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    86
										item.media,
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    87
										item.content.title,
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    88
										item.content.description,
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    89
										item.content.color,
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    90
										item.tags);
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    91
						}
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    92
							//MyTags.addAnnotation(item);
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    93
					} );	
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    94
					IriSP.jQuery.each( json.lists, function(i,item) {
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    95
						IriSP.trace("lists","");
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    96
					} );	
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    97
					IriSP.jQuery.each( json.views, function(i,item) {
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    98
						IriSP.trace("views","");
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    99
					} );	
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
   100
				}
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
   101
				// END PARSING ----------------------- //  
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
   102
			
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
   103
							
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
   104
		}, error : function(data){
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
   105
			  alert("ERROR : "+data);
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
   106
		}
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
   107
	  });	
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
   108
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
   109
}