src/js/model.js
branchnew-model
changeset 887 6a04bd37da0a
parent 881 f11b234497f7
child 900 7673d645a8e0
equal deleted inserted replaced
884:10233337f6da 887:6a04bd37da0a
   239 /* A simple time management object, that helps converting millisecs to seconds and strings,
   239 /* A simple time management object, that helps converting millisecs to seconds and strings,
   240  * without the clumsiness of the original Date object.
   240  * without the clumsiness of the original Date object.
   241  */
   241  */
   242 
   242 
   243 IriSP.Model.Time = function(_milliseconds) {
   243 IriSP.Model.Time = function(_milliseconds) {
   244     this.milliseconds = parseInt(typeof _milliseconds !== "undefined" ? _milliseconds : 0);
   244     switch(typeof _milliseconds) {
       
   245         case "string":
       
   246             this.milliseconds = parseFloat(_milliseconds);
       
   247             break;
       
   248         case "number":
       
   249             this.milliseconds = _milliseconds;
       
   250             break;
       
   251         case "object":
       
   252             this.milliseconds = parseFloat(_milliseconds.valueOf());
       
   253             break;
       
   254         default:
       
   255             this.milliseconds = 0;
       
   256     }
       
   257     if (this.milliseconds === NaN) {
       
   258         this.milliseconds = 0;
       
   259     }
   245 }
   260 }
   246 
   261 
   247 IriSP.Model.Time.prototype.setSeconds = function(_seconds) {
   262 IriSP.Model.Time.prototype.setSeconds = function(_seconds) {
   248     this.milliseconds = 1000 * _seconds;
   263     this.milliseconds = 1000 * _seconds;
   249 }
   264 }
   257     return {
   272     return {
   258         hours : Math.floor(_totalSeconds / 3600),
   273         hours : Math.floor(_totalSeconds / 3600),
   259         minutes : (Math.floor(_totalSeconds / 60) % 60),
   274         minutes : (Math.floor(_totalSeconds / 60) % 60),
   260         seconds : _totalSeconds % 60
   275         seconds : _totalSeconds % 60
   261     } 
   276     } 
       
   277 }
       
   278 
       
   279 IriSP.Model.Time.prototype.add = function(_milliseconds) {
       
   280     this.milliseconds += new IriSP.Model.Time(_milliseconds).milliseconds;
   262 }
   281 }
   263 
   282 
   264 IriSP.Model.Time.prototype.valueOf = function() {
   283 IriSP.Model.Time.prototype.valueOf = function() {
   265     return this.milliseconds;
   284     return this.milliseconds;
   266 }
   285 }
   456 
   475 
   457 IriSP.Model.Annotation.prototype.getTagTexts = function() {
   476 IriSP.Model.Annotation.prototype.getTagTexts = function() {
   458     return this.getTags().getTitles();
   477     return this.getTags().getTitles();
   459 }
   478 }
   460 
   479 
       
   480 /* */
       
   481 
       
   482 IriSP.Model.MashedAnnotation = function(_annotation, _offset) {
       
   483     IriSP.Model.Element.call(this, IriSP.Model.getUID(), _annotation.source);
       
   484     this.elementType = 'mashedAnnotation';
       
   485     this.annotation = _annotation;
       
   486     this.begin = new IriSP.Model.Time(_offset);
       
   487     var _duration = (this.annotation.end - this.annotation.begin);
       
   488     this.end = new IriSP.Model.Time(_offset + _duration)
       
   489     this.title = this.annotation.title;
       
   490     this.description = this.annotation.description;
       
   491 }
       
   492 
       
   493 IriSP.Model.MashedAnnotation.prototype = new IriSP.Model.Element(null);
       
   494 
       
   495 IriSP.Model.MashedAnnotation.prototype.getMedia = function() {
       
   496     return this.annotation.getReference("media");
       
   497 }
       
   498 
       
   499 IriSP.Model.MashedAnnotation.prototype.getAnnotationType = function() {
       
   500     return this.annotation.getReference("annotationType");
       
   501 }
       
   502 
       
   503 IriSP.Model.MashedAnnotation.prototype.getTags = function() {
       
   504     return this.annotation.getReference("tag");
       
   505 }
       
   506 
       
   507 IriSP.Model.MashedAnnotation.prototype.getTagTexts = function() {
       
   508     return this.annotation.getTags().getTitles();
       
   509 }
       
   510 
       
   511 /* */
       
   512 
       
   513 IriSP.Model.Mashup = function(_id, _source) {
       
   514     IriSP.Model.Element.call(this, _id, _source);
       
   515     this.elementType = 'mashup';
       
   516     this.duration = new IriSP.Model.Time();
       
   517     this.segments = new IriSP.Model.List();
       
   518     this.medias = new IriSP.Model.List();
       
   519 }
       
   520 
       
   521 IriSP.Model.Mashup.prototype = new IriSP.Model.Element();
       
   522 
       
   523 IriSP.Model.Mashup.prototype.addSegment = function(_annotation) {
       
   524     this.segments.push(new IriSP.Model.MashedAnnotation(_annotation));
       
   525     this.medias.addElement(_annotation.getMedia());
       
   526 }
       
   527 
       
   528 IriSP.Model.Mashup.prototype.getAnnotations = function() {
       
   529     return this.segments;
       
   530 }
       
   531 
       
   532 IriSP.Model.Mashup.prototype.getMedias = function() {
       
   533     return this.medias;
       
   534 }
   461 /* */
   535 /* */
   462 
   536 
   463 IriSP.Model.Source = function(_config) {
   537 IriSP.Model.Source = function(_config) {
   464     this.status = IriSP.Model._SOURCE_STATUS_EMPTY;
   538     this.status = IriSP.Model._SOURCE_STATUS_EMPTY;
   465     if (typeof _config !== "undefined") {
   539     if (typeof _config !== "undefined") {