src/js/model.js
author veltr
Wed, 11 Apr 2012 16:39:03 +0200
branchnew-model
changeset 856 41c574c807d1
parent 854 29f28a9f236f
child 858 ad1ffe0c0955
permissions -rw-r--r--
basic implementation of model: media, annotation type, annotation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
     1
/* model.js is where data is stored in a standard form, whatever the serializer */
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
     2
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
     3
IriSP.Model = {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
     4
    SOURCE_STATUS_EMPTY : 0,
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
     5
    SOURCE_STATUS_WAITING : 1,
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
     6
    SOURCE_STATUS_READY : 2,
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
     7
    IDS_AUTO_INCREMENT : 0,
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
     8
    IDS_PREFIX : 'autoid-'
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
     9
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    10
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    11
/* */
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    12
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    13
IriSP.Model.List = function() {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    14
    this.contents = {};
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    15
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    16
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    17
IriSP.Model.List.prototype.toString = function() {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    18
    return 'List of Elements, length=' + this.length();
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    19
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    20
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    21
IriSP.Model.List.prototype.keys = function() {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    22
    return IriSP._(this.contents).keys();
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    23
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    24
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    25
IriSP.Model.List.prototype.length = function() {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    26
    return this.keys().length;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    27
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    28
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    29
IriSP.Model.List.prototype.getElement = function(_id) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    30
    return this.contents[_id];
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    31
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    32
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    33
IriSP.Model.List.prototype.getFirst = function() {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    34
    return this.contents(this.keys()[0]);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    35
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    36
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    37
IriSP.Model.List.prototype.each = function(_callback) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    38
    var _this = this;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    39
    IriSP._(this.contents).each(function(_element, _id) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    40
        _callback.call(_this, _element, _id);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    41
    });
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    42
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    43
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    44
IriSP.Model.List.prototype.map = function(_callback) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    45
    var _this = this;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    46
    return IriSP._(this.contents).map(function(_element, _id) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    47
        return _callback.call(_this, _element, _id);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    48
    });
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    49
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    50
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    51
IriSP.Model.List.prototype.addElement = function(_element) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    52
    if ( typeof _element.id === "undefined" ) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    53
        IriSP.Model.AUTO_INCREMENT++;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    54
        _element.id = IriSP.Model.IDS_PREFIX + IriSP.Model.IDS_AUTO_INCREMENT;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    55
    }
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    56
    this.contents[_element.id] = _element;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    57
    if ( this.hasParent ) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    58
        this.parent.addElement(_element);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    59
    }
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    60
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    61
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    62
IriSP.Model.List.prototype.addElements = function(_list) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    63
    var _this = this;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    64
    _list.each(function(_element) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    65
        _this.addElement(_element);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    66
    });
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    67
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    68
/* */
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    69
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    70
IriSP.Model.Time = function(_milliseconds) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    71
    this.milliseconds = parseInt(typeof _milliseconds !== "undefined" ? _milliseconds : 0);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    72
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    73
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    74
IriSP.Model.Time.prototype.setSeconds = function(_seconds) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    75
    this.milliseconds = 1000 * _seconds;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    76
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    77
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    78
IriSP.Model.Time.prototype.getSeconds = function() {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    79
    return Math.floor(this.milliseconds / 1000);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    80
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    81
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    82
IriSP.Model.Time.prototype.getHMS = function() {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    83
    var _totalSeconds = Math.abs(this.getSeconds());
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    84
    return {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    85
        hours : Math.floor(_totalSeconds / 3600),
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    86
        minutes : (Math.floor(_totalSeconds / 60) % 60),
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    87
        seconds : _totalSeconds % 60
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    88
    } 
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    89
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    90
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    91
IriSP.Model.Time.prototype.toString = function() {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    92
    function pad(_n) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    93
        var _res = _n.toString();
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    94
        while (_res.length < 2) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    95
            _res = '0' + _res;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    96
        }
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    97
        return _res;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    98
    }
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    99
    var _hms = this.getHMS(),
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   100
        _res = '';
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   101
    if (_hms.hours) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   102
        _res += pad(_hms.hours) + ':'
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   103
    }
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   104
    _res += pad(_hms.minutes) + ':' + pad(_hms.seconds);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   105
    return _res;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   106
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   107
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   108
IriSP.Model.BrokenReference = function(_elementType, _idRef) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   109
    this.id = _idRef;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   110
    this.elementType = 'brokenReference';
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   111
    this.originalElementType = _elementType;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   112
    this.isSolved = false;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   113
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   114
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   115
IriSP.Model.BrokenReference.prototype.toString = function() {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   116
    return 'Broken reference to ' + IriSP.Model.ELEMENT_TYPES[_elementType].element_str + ', id=' + this.id;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   117
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   118
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   119
IriSP.Model.BrokenReference.prototype.tryToSolve = function(_container) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   120
    if (this.isSolved) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   121
        return this.solution;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   122
    }
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   123
    var _obj = _container.getElement(this.originalElementType, this.id);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   124
    if (typeof _obj !== "undefined") {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   125
        this.isSolved = true;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   126
        this.solution = _obj;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   127
        return this.solution;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   128
    } else {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   129
        return undefined;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   130
    }
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   131
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   132
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   133
/* */
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   134
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   135
IriSP.Model.Element = function(_id, _source) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   136
    this.elementType = 'element';
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   137
    if (typeof _id === "undefined") {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   138
        IriSP.Model.IDS_AUTO_INCREMENT++;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   139
        this.id = IriSP.Model.IDS_PREFIX + IriSP.Model.AUTO_INCREMENT;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   140
    } else {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   141
        this.id = _id;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   142
    }
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   143
    this.source = _source;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   144
    this.title = "";
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   145
    this.description = "";
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   146
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   147
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   148
IriSP.Model.Element.prototype.toString = function() {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   149
    return this.elementType + ', id=' + this.id + ', title="' + this.title + '"';
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   150
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   151
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   152
IriSP.Model.Element.prototype.getReference = function(_container, _elementType, _idRef) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   153
    var _obj = _container.getElement(_elementType, _idRef);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   154
    if (typeof _obj === "undefined") {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   155
        _obj = new IriSP.Model.BrokenReference(_elementType, _idRef);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   156
    }
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   157
    _obj.backReference(this);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   158
    return _obj;
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   159
}
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   160
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   161
IriSP.Model.Element.prototype.backReference = function(_object) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   162
    if (typeof this.referencedBy === "undefined") {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   163
        this.referencedBy = {}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   164
    }
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   165
    if (typeof this.referencedBy[_object.elementType] === "undefined") {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   166
        this.referencedBy[_object.elementType] = new IriSP.Model.List();
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   167
    }
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   168
    this.referencedBy[_object.elementType].addElement(_object);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   169
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   170
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   171
IriSP.Model.Element.prototype.otmCrossReference = function(_container, _elementType, _idRef) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   172
    if (typeof this.referencing === "undefined") {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   173
        this.referencing = {};
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   174
    }
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   175
    this.referencing[_elementType] = this.getReference(_container, _elementType, _idRef);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   176
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   177
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   178
IriSP.Model.Element.prototype.mtmCrossReference = function(_container, _elementType, _idRefList) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   179
    if (typeof this.referencing === "undefined") {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   180
        this.referencing = {};
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   181
    }
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   182
    this.referencing[_elementType] = new IriSP.Model.List;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   183
    for (var _i = 0; _i < _idRefList.length; _i++) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   184
        this.referencing[_elementType].addElement(this.getReference(_container, _elementType, _idRefList[_i]));
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   185
    }
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   186
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   187
/* */
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   188
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   189
IriSP.Model.Media = function(_id, _source) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   190
    IriSP.Model.Element.call(this, _id, _source);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   191
    this.elementType = 'media';
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   192
    this.duration = new IriSP.Model.Time();
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   193
    this.url = '';
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   194
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   195
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   196
IriSP.Model.Media.prototype = new IriSP.Model.Element(null);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   197
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   198
IriSP.Model.Media.prototype.setDuration = function(_durationMs) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   199
    this.duration.milliseconds = _durationMs;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   200
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   201
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   202
/* */
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   203
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   204
IriSP.Model.AnnotationType = function(_id, _source) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   205
    IriSP.Model.Element.call(this, _id, _source);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   206
    this.elementType = 'annotationType';
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   207
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   208
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   209
IriSP.Model.AnnotationType.prototype = new IriSP.Model.Element(null);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   210
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   211
/* Annotation
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   212
 * */
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   213
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   214
IriSP.Model.Annotation = function(_id, _source) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   215
    IriSP.Model.Element.call(this, _id, _source);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   216
    this.elementType = 'annotation';
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   217
    this.begin = new IriSP.Model.Time();
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   218
    this.end = new IriSP.Model.Time();
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   219
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   220
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   221
IriSP.Model.Annotation.prototype = new IriSP.Model.Element(null);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   222
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   223
IriSP.Model.Annotation.prototype.setBegin = function(_beginMs) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   224
    this.begin.milliseconds = _beginMs;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   225
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   226
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   227
IriSP.Model.Annotation.prototype.setEnd = function(_beginMs) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   228
    this.end.milliseconds = _beginMs;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   229
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   230
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   231
IriSP.Model.Annotation.prototype.setMedia = function(_idRef, _container) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   232
    this.otmCrossReference(_container, "media" , _idRef);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   233
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   234
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   235
IriSP.Model.Annotation.prototype.getMedia = function() {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   236
    return this.referencing.media;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   237
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   238
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   239
IriSP.Model.Annotation.prototype.setAnnotationType = function(_idRef, _container) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   240
    this.otmCrossReference(_container, "annotationType" , _idRef);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   241
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   242
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   243
IriSP.Model.Annotation.prototype.getAnnotationType = function() {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   244
    return this.referencing.annotation_type;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   245
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   246
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   247
/* A Container contains lists of elements. It corresponds to the root of Cinelab
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   248
 * */
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   249
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   250
IriSP.Model.Container = function(_parent) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   251
    this.hasParent = (typeof _parent !== "undefined");
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   252
    if (this.hasParent) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   253
        this.parent = _parent;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   254
    }
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   255
    this.contents = {}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   256
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   257
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   258
IriSP.Model.Container.prototype.each = function(_callback) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   259
    var _this = this;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   260
    IriSP._(this.contents).each(function(_element, _id) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   261
        _callback.call(_this, _element, _id);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   262
    });
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   263
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   264
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   265
IriSP.Model.Container.prototype.map = function(_callback) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   266
    var _this = this;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   267
    return IriSP._(this.contents).map(function(_element, _id) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   268
        return _callback.call(_this, _element, _id);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   269
    });
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   270
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   271
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   272
IriSP.Model.Container.prototype.addList = function(_listId, _contents) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   273
    if (this.hasParent) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   274
        this.parent.addList(_listId, _contents);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   275
    }
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   276
    if (typeof this.contents[_listId] === "undefined") {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   277
        this.contents[_listId] = _contents;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   278
    } else {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   279
        this.contents[_listId].addElements(_contents);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   280
    }
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   281
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   282
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   283
IriSP.Model.Container.prototype.getList = function(_listId) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   284
    if (typeof this.contents[_listId] === "undefined") {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   285
        if (this.hasParent) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   286
            return this.parent.getList(_listId);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   287
        } else {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   288
            return undefined;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   289
        }
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   290
    } else {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   291
        return this.contents[_listId];
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   292
    }
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   293
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   294
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   295
IriSP.Model.Container.prototype.getElement = function(_listId, _elId) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   296
    var _list = this.getList(_listId);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   297
    return (typeof _list !== "undefined" ? _list.getElement(_elId) : undefined);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   298
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   299
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   300
IriSP.Model.Container.prototype.getMedias = function(_contents) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   301
    return this.getList("media");
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   302
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   303
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   304
IriSP.Model.Container.prototype.getAnnotations = function(_contents) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   305
    return this.getList("annotation");
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   306
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   307
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   308
IriSP.Model.Container.prototype.setCurrentMediaById = function(_idRef) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   309
    if (typeof _idRef !== "undefined") {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   310
        this.currentMedia = this.getElement("media", _idRef);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   311
    }
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   312
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   313
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   314
IriSP.Model.Container.prototype.setDefaultCurrentMedia = function() {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   315
    if (typeof this.currentMedia === "undefined") {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   316
        this.currentMedia = this.getMedias().getFirst();
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   317
    }
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   318
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   319
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   320
/* */
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   321
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   322
IriSP.Model.Source = function(_directory, _url, _serializer) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   323
    this.status = IriSP.Model.SOURCE_STATUS_EMPTY;
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   324
    if (typeof _directory === "undefined") {
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   325
        throw "Error : Model.Source called with no parent directory";
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   326
    }
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   327
    if (typeof _url === "undefined") {
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   328
        throw "Error : Model.Source called with no URL";
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   329
    }
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   330
    if (typeof _serializer === "undefined") {
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   331
        throw "Error : Model.Source called with no serializer";
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   332
    }
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   333
    this.directory = _directory;
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   334
    this.serializer = _serializer;
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   335
    this.url = _url;
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   336
    this.callbackQueue = [];
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   337
    this.container = new IriSP.Model.Container(_directory.consolidated);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   338
    this.get();
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   339
}
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   340
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   341
IriSP.Model.Source.prototype.get = function() {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   342
    this.status = IriSP.Model.SOURCE_STATUS_WAITING;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   343
    var _this = this;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   344
    IriSP.jQuery.getJSON(this.url, function(_result) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   345
        _this.serializer.deSerialize(_result, _this.container);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   346
        if (_this.callbackQueue.length) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   347
            IriSP._.each(_this.callbackQueue, function(_callback) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   348
                _callback.call(_this);
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   349
            });
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   350
        }
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   351
        _this.callbackQueue = [];
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   352
        _this.status = IriSP.Model.SOURCE_STATUS_READY;
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   353
    });
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   354
}
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   355
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   356
IriSP.Model.Source.prototype.addCallback = function(_callback) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   357
    if (this.status === IriSP.Model.SOURCE_STATUS_READY) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   358
        callback.call(this);
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   359
    } else {
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   360
        this.callbackQueue.push(_callback);
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   361
    }
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   362
}
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   363
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   364
IriSP.Model.Source.prototype.getAnnotations = function() {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   365
    return this.container.getAnnotations();
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   366
}
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   367
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   368
IriSP.Model.Source.prototype.getMedias = function() {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   369
    return this.container.getMedias();
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   370
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   371
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   372
IriSP.Model.Source.prototype.getCurrentMedia = function() {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   373
    return this.container.currentMedia;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   374
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   375
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   376
IriSP.Model.Source.prototype.getDuration = function() {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   377
    return this.getCurrentMedia().duration;
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   378
}
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   379
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   380
/* */
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   381
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   382
IriSP.Model.Directory = function() {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   383
    this.sources = {};
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   384
    this.imports = {};
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   385
    this.consolidated = new IriSP.Model.Container();
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   386
}
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   387
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   388
IriSP.Model.Directory.prototype.addSource = function(_source, _serializer) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   389
    this.sources[_source] = new IriSP.Model.Source(this, _source, _serializer);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   390
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   391
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   392
IriSP.Model.Directory.prototype.source = function(_source, _serializer) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   393
    if (typeof this.sources[_source] === "undefined") {
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   394
        this.addSource(_source, _serializer);
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   395
    }
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   396
    return this.sources[_source];
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   397
}
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   398
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   399
/* */