src/js/model.js
author veltr
Mon, 23 Apr 2012 19:11:08 +0200
branchnew-model
changeset 875 43629caa77bc
parent 872 d777d05a16e4
child 880 4c7b33bf2795
permissions -rw-r--r--
Big refactoring of widget files + started migration of segmentwidget
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 = {
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
     4
    _SOURCE_STATUS_EMPTY : 0,
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
     5
    _SOURCE_STATUS_WAITING : 1,
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
     6
    _SOURCE_STATUS_READY : 2,
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
     7
    _ID_AUTO_INCREMENT : 0,
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
     8
    getUID : function() {
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
     9
        return "autoid-" + (++this._ID_AUTO_INCREMENT);
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    10
    },
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
    11
    regexpFromTextOrArray : function(_textOrArray) {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
    12
        function escapeText(_text) {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
    13
            return _text.replace(/([\\\*\+\?\|\{\[\}\]\(\)\^\$\.\#\/])/gm, '\\$1');
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
    14
        }
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
    15
        return new RegExp( '('
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
    16
            + (
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
    17
                typeof _textOrArray === "string"
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
    18
                ? escapeText(_textOrArray)
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
    19
                : IriSP._(_textOrArray).map(escapeText).join("|")
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
    20
            )
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
    21
            + ')',
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
    22
            'gim'
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
    23
        );
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
    24
    },
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    25
    isoToDate : function(_str) {
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    26
        // http://delete.me.uk/2005/03/iso8601.html
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    27
        var regexp = "([0-9]{4})(-([0-9]{2})(-([0-9]{2})(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?";
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    28
        var d = _str.match(new RegExp(regexp));
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    29
    
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    30
        var offset = 0;
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    31
        var date = new Date(d[1], 0, 1);
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    32
    
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    33
        if (d[3]) { date.setMonth(d[3] - 1); }
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    34
        if (d[5]) { date.setDate(d[5]); }
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    35
        if (d[7]) { date.setHours(d[7]); }
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    36
        if (d[8]) { date.setMinutes(d[8]); }
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    37
        if (d[10]) { date.setSeconds(d[10]); }
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    38
        if (d[12]) { date.setMilliseconds(Number("0." + d[12]) * 1000); }
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    39
        if (d[14]) {
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    40
            offset = (Number(d[16]) * 60) + Number(d[17]);
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    41
            offset *= ((d[15] == '-') ? 1 : -1);
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    42
        }
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    43
    
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    44
        offset -= date.getTimezoneOffset();
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    45
        time = (Number(date) + (offset * 60 * 1000));
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    46
        var _res = new Date();
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    47
        _res.setTime(Number(time));
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    48
        return _res;
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    49
    },
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    50
    dateToIso : function(d) {  
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    51
        function pad(n){return n<10 ? '0'+n : n}  
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    52
        return d.getUTCFullYear()+'-'  
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    53
            + pad(d.getUTCMonth()+1)+'-'  
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    54
            + pad(d.getUTCDate())+'T'  
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    55
            + pad(d.getUTCHours())+':'  
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    56
            + pad(d.getUTCMinutes())+':'  
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    57
            + pad(d.getUTCSeconds())+'Z'  
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    58
    }
856
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
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    61
/*
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    62
 * IriSP.Model.List is a class for a list of elements (e.g. annotations, medias, etc. that each have a distinct ID)
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    63
 */
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
    64
IriSP.Model.List = function(_directory) {
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    65
    Array.call(this);
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
    66
    this.directory = _directory;
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    67
    this.idIndex = [];
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    68
    if (typeof _directory == "undefined") {
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
    69
        throw "Error : new IriSP.Model.List(directory): directory is undefined";
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    70
    }
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    71
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    72
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    73
IriSP.Model.List.prototype = new Array();
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    74
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    75
IriSP.Model.List.prototype.getElement = function(_id) {
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
    76
    var _index = (IriSP._(this.idIndex).indexOf(_id));
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
    77
    if (_index !== -1) {
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
    78
        return this[_index];
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
    79
    }
856
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
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
    82
IriSP.Model.List.prototype.hasId = function(_id) {
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    83
    return (IriSP._(this.idIndex).indexOf(_id) !== -1);
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
    84
}
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
    85
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    86
/* On recent browsers, forEach and map are defined and do what we want.
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    87
 * Otherwise, we'll use the Underscore.js functions
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    88
 */
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    89
if (typeof Array.prototype.forEach === "undefined") {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    90
    IriSP.Model.List.prototype.forEach = function(_callback) {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    91
        var _this = this;
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    92
        IriSP._(this).forEach(function(_value, _key) {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    93
            _callback(_value, _key, _this);
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    94
        });
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    95
    }
856
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
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    98
if (typeof Array.prototype.map === "undefined") {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    99
    IriSP.Model.List.prototype.map = function(_callback) {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   100
        var _this = this;
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   101
        return IriSP._(this).map(function(_value, _key) {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   102
            return _callback(_value, _key, _this);
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   103
        });
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   104
    }
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   105
}
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   106
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   107
/* We override Array's filter function because it doesn't return an IriSP.Model.List
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   108
 */
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   109
IriSP.Model.List.prototype.filter = function(_callback) {
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   110
    var _this = this,
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   111
        _res = new IriSP.Model.List(this.directory);
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   112
    _res.addElements(IriSP._(this).filter(function(_value, _key) {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   113
        return _callback(_value, _key, _this);
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   114
    }));
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   115
    return _res;
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   116
}
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   117
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   118
IriSP.Model.List.prototype.slice = function(_start, _end) {
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   119
    var _res = new IriSP.Model.List(this.directory);
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   120
    _res.addElements(Array.prototype.slice.call(this, _start, _end));
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   121
    return _res;
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   122
}
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   123
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   124
IriSP.Model.List.prototype.splice = function(_start, _end) {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   125
    var _res = new IriSP.Model.List(this.directory);
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   126
    _res.addElements(Array.prototype.splice.call(this, _start, _end));
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   127
    this.idIndex.splice(_start, _end);
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   128
    return _res;
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   129
}
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   130
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   131
/* Array has a sort function, but it's not as interesting as Underscore.js's sortBy
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   132
 * and won't return a new IriSP.Model.List
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   133
 */
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   134
IriSP.Model.List.prototype.sortBy = function(_callback) {
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   135
    var _this = this,
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   136
        _res = new IriSP.Model.List(this.directory);
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   137
    _res.addElements(IriSP._(this).sortBy(function(_value, _key) {
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   138
        return _callback(_value, _key, _this);
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   139
    }));
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   140
    return _res;
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   141
}
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   142
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   143
/* Title and Description are basic information for (almost) all element types,
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   144
 * here we can search by these criteria
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   145
 */
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   146
IriSP.Model.List.prototype.searchByTitle = function(_text) {
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   147
    var _rgxp = IriSP.Model.regexpFromTextOrArray(_text);
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   148
    return this.filter(function(_element) {
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   149
        return _rgxp.test(_element.title);
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   150
    });
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   151
}
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   152
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   153
IriSP.Model.List.prototype.searchByDescription = function(_text) {
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   154
    var _rgxp = IriSP.Model.regexpFromTextOrArray(_text);
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   155
    return this.filter(function(_element) {
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   156
        return _rgxp.test(_element.description);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   157
    });
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   158
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   159
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   160
IriSP.Model.List.prototype.searchByTextFields = function(_text) {
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   161
    var _rgxp =  IriSP.Model.regexpFromTextOrArray(_text);
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   162
    return this.filter(function(_element) {
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   163
        return _rgxp.test(_element.description) || _rgxp.test(_element.title);
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   164
    });
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   165
}
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   166
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   167
IriSP.Model.List.prototype.getTitles = function() {
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   168
    return this.map(function(_el) {
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   169
        return _el.title;
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   170
    });
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   171
}
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   172
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   173
IriSP.Model.List.prototype.addId = function(_id) {
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   174
    var _el = this.directory.getElement(_id)
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   175
    if (!this.hasId(_id) && typeof _el !== "undefined") {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   176
        this.idIndex.push(_id);
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   177
        Array.prototype.push.call(this, _el);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   178
    }
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   179
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   180
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   181
IriSP.Model.List.prototype.push = function(_el) {
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   182
    if (typeof _el === "undefined") {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   183
        return;
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   184
    }
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   185
    var _index = (IriSP._(this.idIndex).indexOf(_el.id));
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   186
    if (_index === -1) {
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   187
        this.idIndex.push(_el.id);
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   188
        Array.prototype.push.call(this, _el);
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   189
    } else {
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   190
        this[_index] = _el;
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   191
    }
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   192
}
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   193
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   194
IriSP.Model.List.prototype.addIds = function(_array) {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   195
    var _l = _array.length,
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   196
        _this = this;
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   197
    IriSP._(_array).forEach(function(_id) {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   198
        _this.addId(_id);
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   199
    });
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   200
}
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   201
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   202
IriSP.Model.List.prototype.addElements = function(_array) {
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   203
    var _this = this;
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   204
    IriSP._(_array).forEach(function(_el) {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   205
        _this.push(_el);
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   206
    });
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   207
}
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   208
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   209
IriSP.Model.List.prototype.removeId = function(_id) {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   210
    var _index = (IriSP._(this.idIndex).indexOf(_id));
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   211
    if (_index !== -1) {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   212
        this.splice(_index,1);
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   213
    }
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   214
}
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   215
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   216
IriSP.Model.List.prototype.removeElement = function(_el) {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   217
    this.removeId(_el.id);
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   218
}
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   219
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   220
IriSP.Model.List.prototype.removeIds = function(_list) {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   221
    var _this = this;
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   222
    IriSP._(_list).forEach(function(_id) {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   223
        _this.removeId(_id);
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   224
    });
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   225
}
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   226
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   227
IriSP.Model.List.prototype.removeElements = function(_list) {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   228
    var _this = this;
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   229
    IriSP._(_list).forEach(function(_el) {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   230
        _this.removeElement(_el);
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   231
    });
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   232
}
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   233
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   234
/* A simple time management object, that helps converting millisecs to seconds and strings,
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   235
 * without the clumsiness of the original Date object.
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   236
 */
856
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
IriSP.Model.Time = function(_milliseconds) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   239
    this.milliseconds = parseInt(typeof _milliseconds !== "undefined" ? _milliseconds : 0);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   240
}
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
IriSP.Model.Time.prototype.setSeconds = function(_seconds) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   243
    this.milliseconds = 1000 * _seconds;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   244
}
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
IriSP.Model.Time.prototype.getSeconds = function() {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   247
    return Math.floor(this.milliseconds / 1000);
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.Time.prototype.getHMS = function() {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   251
    var _totalSeconds = Math.abs(this.getSeconds());
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   252
    return {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   253
        hours : Math.floor(_totalSeconds / 3600),
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   254
        minutes : (Math.floor(_totalSeconds / 60) % 60),
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   255
        seconds : _totalSeconds % 60
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
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   259
IriSP.Model.Time.prototype.valueOf = function() {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   260
    return this.milliseconds;
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   261
}
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   262
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   263
IriSP.Model.Time.prototype.toString = function() {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   264
    function pad(_n) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   265
        var _res = _n.toString();
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   266
        while (_res.length < 2) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   267
            _res = '0' + _res;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   268
        }
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   269
        return _res;
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
    var _hms = this.getHMS(),
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   272
        _res = '';
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   273
    if (_hms.hours) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   274
        _res += pad(_hms.hours) + ':'
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
    _res += pad(_hms.minutes) + ':' + pad(_hms.seconds);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   277
    return _res;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   278
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   279
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   280
/* IriSP.Model.Reference handles references between elements
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   281
 */
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   282
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   283
IriSP.Model.Reference = function(_source, _idRef) {
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   284
    this.source = _source;
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   285
    if (typeof _idRef === "object") {
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   286
        this.isList = true;
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   287
        this.id = IriSP._(_idRef).map(function(_id) {
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   288
            return _source.getNamespaced(_id).fullname;
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   289
        });
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   290
    } else {
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   291
        this.isList = false;
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   292
        this.id = _source.getNamespaced(_idRef).fullname;
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   293
    }
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   294
    this.refresh();
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   295
}
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   296
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   297
IriSP.Model.Reference.prototype.refresh = function() {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   298
    if (this.isList) {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   299
        this.contents = new IriSP.Model.List(this.source.directory);
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   300
        this.contents.addIds(this.id);
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   301
    } else {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   302
        this.contents = this.source.directory.getElement(this.id);
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   303
    }
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   304
    
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   305
}
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   306
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   307
IriSP.Model.Reference.prototype.getContents = function() {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   308
    if (typeof this.contents === "undefined" || (this.isList && this.contents.length != this.id.length)) {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   309
        this.refresh();
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   310
    }
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   311
    return this.contents;
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   312
}
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   313
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   314
IriSP.Model.Reference.prototype.isOrHasId = function(_idRef) {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   315
    if (this.isList) {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   316
        return (IriSP._(this.id).indexOf(_idRef) !== -1)
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   317
    } else {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   318
        return (this.id == _idRef);
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   319
    }
856
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
/* */
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   323
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   324
IriSP.Model.Element = function(_id, _source) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   325
    this.elementType = 'element';
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   326
    if (typeof _source === "undefined") {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   327
        return;
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   328
    }
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   329
    if (typeof _id === "undefined" || !_id) {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   330
        _id = IriSP.Model.getUID();
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   331
    }
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   332
    this.source = _source;
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   333
    this.namespacedId = _source.getNamespaced(_id)
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   334
    this.id = this.namespacedId.fullname;
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   335
    this.title = "";
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   336
    this.description = "";
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   337
    this.source.directory.addElement(this);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   338
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   339
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   340
IriSP.Model.Element.prototype.toString = function() {
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   341
    return this.elementType + (this.elementType !== 'element' ? ', id=' + this.id + ', title="' + this.title + '"' : '');
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   342
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   343
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   344
IriSP.Model.Element.prototype.setReference = function(_elementType, _idRef) {
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   345
    this[_elementType] = new IriSP.Model.Reference(this.source, _idRef);
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   346
}
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   347
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   348
IriSP.Model.Element.prototype.getReference = function(_elementType) {
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   349
    if (typeof this[_elementType] !== "undefined") {
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   350
        return this[_elementType].getContents();
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   351
    }
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   352
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   353
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   354
IriSP.Model.Element.prototype.getRelated = function(_elementType, _global) {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   355
    _global = (typeof _global !== "undefined" && _global);
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   356
    var _this = this;
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   357
    return this.source.getList(_elementType, _global).filter(function(_el) {
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   358
        var _ref = _el[_this.elementType];
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   359
        return _ref.isOrHasId(_this.id);
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   360
    });
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   361
}
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   362
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   363
/* */
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   364
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   365
IriSP.Model.Media = function(_id, _source) {
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   366
    IriSP.Model.Element.call(this, _id, _source);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   367
    this.elementType = 'media';
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   368
    this.duration = new IriSP.Model.Time();
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   369
    this.video = '';
856
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
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   372
IriSP.Model.Media.prototype = new IriSP.Model.Element();
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   373
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   374
IriSP.Model.Media.prototype.setDuration = function(_durationMs) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   375
    this.duration.milliseconds = _durationMs;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   376
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   377
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   378
IriSP.Model.Media.prototype.getAnnotations = function() {
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   379
    return this.getRelated("annotation");
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   380
}
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   381
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   382
/* */
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   383
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   384
IriSP.Model.Tag = function(_id, _source) {
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   385
    IriSP.Model.Element.call(this, _id, _source);
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   386
    this.elementType = 'tag';
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   387
}
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   388
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   389
IriSP.Model.Tag.prototype = new IriSP.Model.Element();
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   390
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   391
IriSP.Model.Tag.prototype.getAnnotations = function() {
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   392
    return this.getRelated("annotation");
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   393
}
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   394
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   395
/* */
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   396
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   397
IriSP.Model.AnnotationType = function(_id, _source) {
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   398
    IriSP.Model.Element.call(this, _id, _source);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   399
    this.elementType = 'annotationType';
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   400
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   401
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   402
IriSP.Model.AnnotationType.prototype = new IriSP.Model.Element();
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   403
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   404
IriSP.Model.AnnotationType.prototype.getAnnotations = function() {
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   405
    return this.getRelated("annotation");
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   406
}
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   407
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   408
/* Annotation
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   409
 * */
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   410
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   411
IriSP.Model.Annotation = function(_id, _source) {
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   412
    IriSP.Model.Element.call(this, _id, _source);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   413
    this.elementType = 'annotation';
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   414
    this.begin = new IriSP.Model.Time();
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   415
    this.end = new IriSP.Model.Time();
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   416
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   417
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   418
IriSP.Model.Annotation.prototype = new IriSP.Model.Element(null);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   419
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   420
IriSP.Model.Annotation.prototype.setBegin = function(_beginMs) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   421
    this.begin.milliseconds = _beginMs;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   422
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   423
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   424
IriSP.Model.Annotation.prototype.setEnd = function(_beginMs) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   425
    this.end.milliseconds = _beginMs;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   426
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   427
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   428
IriSP.Model.Annotation.prototype.setMedia = function(_idRef) {
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   429
    this.setReference("media", _idRef);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   430
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   431
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   432
IriSP.Model.Annotation.prototype.getMedia = function() {
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   433
    return this.getReference("media");
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   434
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   435
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   436
IriSP.Model.Annotation.prototype.setAnnotationType = function(_idRef) {
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   437
    this.setReference("annotationType", _idRef);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   438
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   439
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   440
IriSP.Model.Annotation.prototype.getAnnotationType = function() {
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   441
    return this.getReference("annotationType");
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   442
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   443
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   444
IriSP.Model.Annotation.prototype.setTags = function(_idRefs) {
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   445
    this.setReference("tag", _idRefs);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   446
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   447
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   448
IriSP.Model.Annotation.prototype.getTags = function() {
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   449
    return this.getReference("tag");
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   450
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   451
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   452
IriSP.Model.Annotation.prototype.getTagTexts = function() {
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   453
    return this.getTags().getTitles();
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   454
}
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   455
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   456
/* */
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   457
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   458
IriSP.Model.Source = function(_config) {
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   459
    this.status = IriSP.Model._SOURCE_STATUS_EMPTY;
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   460
    if (typeof _config !== "undefined") {
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   461
        var _this = this;
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   462
        IriSP._(_config).forEach(function(_v, _k) {
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   463
            _this[_k] = _v;
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   464
        })
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   465
        this.callbackQueue = [];
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   466
        this.contents = {};
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   467
        if (typeof this.namespace === "undefined") {
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   468
            this.namespace = "metadataplayer";
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   469
        } else {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   470
            if (typeof this.namespaceUrl === "undefined" && typeof this.url !== "undefined") {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   471
                var _matches = this.url.match(/(^[^?&]+|[^?&][a-zA-Z0-9_%=?]+)/g),
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   472
                    _url = _matches[0];
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   473
                if (_matches.length > 1) {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   474
                    _matches = IriSP._(_matches.slice(1)).reject(function(_txt) {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   475
                        return /\?$/.test(_txt);
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   476
                    });
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   477
                }
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   478
                if (_matches.length > 0) {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   479
                    _url += '?' + _matches.join('&');
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   480
                }
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   481
                this.namespaceUrl = _url;
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   482
            }
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   483
        }
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   484
        if (typeof this.namespaceUrl === "undefined") {
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   485
            this.namespaceUrl = "http://ldt.iri.centrepompidou.fr/";
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   486
        }
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   487
        this.directory.addNamespace(this.namespace, this.namespaceUrl);
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   488
        this.get();
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   489
    }
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   490
}
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   491
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   492
IriSP.Model.Source.prototype.getNamespaced = function(_id) {
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   493
    var _tab = _id.split(':');
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   494
    if (_tab.length > 1) {
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   495
        return {
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   496
            namespace : _tab[0],
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   497
            name : _tab[1],
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   498
            fullname : _id
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   499
        }
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   500
    } else {
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   501
        return {
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   502
            namespace : this.namespace,
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   503
            name : _id,
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   504
            fullname : this.namespace + ':' + _id
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   505
        }
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   506
    }
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   507
}
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   508
    
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   509
IriSP.Model.Source.prototype.unNamespace = function(_id) {
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   510
    if (typeof _id !== "undefined") {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   511
        return _id.replace(this.namespace + ':', '');
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   512
    }
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   513
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   514
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   515
IriSP.Model.Source.prototype.addList = function(_listId, _contents) {
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   516
    if (typeof this.contents[_listId] === "undefined") {
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   517
        this.contents[_listId] = new IriSP.Model.List(this.directory);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   518
    }
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   519
    this.contents[_listId].addElements(_contents);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   520
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   521
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   522
IriSP.Model.Source.prototype.getList = function(_listId, _global) {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   523
    _global = (typeof _global !== "undefined" && _global);
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   524
    if (_global || typeof this.contents[_listId] === "undefined") {
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   525
        return this.directory.getGlobalList().filter(function(_e) {
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   526
            return (_e.elementType === _listId);
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   527
        });
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   528
    } else {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   529
        return this.contents[_listId];
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   530
    }
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   531
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   532
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   533
IriSP.Model.Source.prototype.forEach = function(_callback) {
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   534
    var _this = this;
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   535
    IriSP._(this.contents).forEach(function(_value, _key) {
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   536
        _callback.call(_this, _value, _key);
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   537
    })
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   538
}
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   539
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   540
IriSP.Model.Source.prototype.getElement = function(_elId) {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   541
    return this.directory.getElement(_elId);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   542
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   543
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   544
IriSP.Model.Source.prototype.setCurrentMediaId = function(_idRef) {
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   545
    if (typeof _idRef !== "undefined") {
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   546
        this.currentMedia = this.getMedias().getElement(this.getNamespaced(_idRef).fullname);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   547
    }
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   548
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   549
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   550
IriSP.Model.Source.prototype.setDefaultCurrentMedia = function() {
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   551
    if (typeof this.currentMedia === "undefined" && this.getMedias().length) {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   552
        this.currentMedia = this.getMedias()[0];
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   553
    }
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   554
}
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   555
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   556
IriSP.Model.Source.prototype.listNamespaces = function(_excludeSelf) {
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   557
    var _this = this,
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   558
        _nsls = [],
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   559
        _excludeSelf = (typeof _excludeSelf !== "undefined" && _excludeSelf);
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   560
    this.forEach(function(_list) {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   561
        IriSP._(_list).forEach(function(_el) {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   562
            var _ns = _el.id.replace(/:.*$/,'');
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   563
            if (IriSP._(_nsls).indexOf(_ns) === -1 && (!_excludeSelf || _ns !== _this.namespace)) {
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   564
                _nsls.push(_ns);
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   565
            }
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   566
        })
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   567
    });
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   568
    return _nsls;
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   569
}
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   570
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   571
IriSP.Model.Source.prototype.get = function() {
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   572
    this.status = IriSP.Model._SOURCE_STATUS_WAITING;
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   573
    this.handleCallbacks();
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   574
}
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   575
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   576
/* We defer the callbacks calls so they execute after the queue is cleared */
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   577
IriSP.Model.Source.prototype.deferCallback = function(_callback) {
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   578
    var _this = this;
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   579
    IriSP._.defer(function() {
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   580
        _callback.call(_this);
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   581
    });
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   582
}
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   583
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   584
IriSP.Model.Source.prototype.handleCallbacks = function() {
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   585
    this.status = IriSP.Model._SOURCE_STATUS_READY;
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   586
    while (this.callbackQueue.length) {
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   587
        this.deferCallback(this.callbackQueue.splice(0,1)[0]);
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   588
    }
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   589
}
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   590
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   591
IriSP.Model.Source.prototype.onLoad = function(_callback) {
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   592
    if (this.status === IriSP.Model._SOURCE_STATUS_READY) {
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   593
        this.deferCallback(_callback);
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   594
    } else {
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   595
        this.callbackQueue.push(_callback);
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   596
    }
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   597
}
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   598
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   599
IriSP.Model.Source.prototype.serialize = function() {
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   600
    return this.serializer.serialize(this);
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   601
}
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   602
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   603
IriSP.Model.Source.prototype.deSerialize = function(_data) {
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   604
    this.serializer.deSerialize(_data, this);
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   605
}
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   606
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   607
IriSP.Model.Source.prototype.getAnnotations = function(_global) {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   608
    _global = (typeof _global !== "undefined" && _global);
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   609
    return this.getList("annotation", _global);
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   610
}
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   611
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   612
IriSP.Model.Source.prototype.getMedias = function(_global) {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   613
    _global = (typeof _global !== "undefined" && _global);
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   614
    return this.getList("media", _global);
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   615
}
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   616
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   617
IriSP.Model.Source.prototype.getAnnotationTypes = function(_global) {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   618
    _global = (typeof _global !== "undefined" && _global);
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   619
    return this.getList("annotationType", _global);
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   620
}
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   621
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   622
IriSP.Model.Source.prototype.getAnnotationsByTypeTitle = function(_title, _global) {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   623
    _global = (typeof _global !== "undefined" && _global);
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   624
    var _res = new IriSP.Model.List(this.directory),
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   625
        _annTypes = this.getAnnotationTypes(_global).searchByTitle(_title);
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   626
    _annTypes.forEach(function(_annType) {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   627
        _res.addElements(_annType.getAnnotations(_global));
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   628
    })
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   629
    return _res;
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   630
}
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   631
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   632
IriSP.Model.Source.prototype.getDuration = function() {
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   633
    var _m = this.currentMedia;
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   634
    if (typeof _m !== "undefined") {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   635
        return this.currentMedia.duration;
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   636
    }
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   637
}
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   638
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   639
/* */
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   640
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   641
IriSP.Model.RemoteSource = function(_config) {
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   642
    IriSP.Model.Source.call(this, _config);
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   643
}
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   644
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   645
IriSP.Model.RemoteSource.prototype = new IriSP.Model.Source();
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   646
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   647
IriSP.Model.RemoteSource.prototype.get = function() {
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   648
    this.status = IriSP.Model._SOURCE_STATUS_WAITING;
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   649
    var _this = this;
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   650
    this.serializer.loadData(this.url, function(_result) {
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   651
        _this.deSerialize(_result);
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   652
        _this.handleCallbacks();
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   653
    });
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   654
}
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   655
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   656
/* */
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   657
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   658
IriSP.Model.Directory = function() {
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   659
    this.remoteSources = {};
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   660
    this.elements = {};
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   661
    this.namespaces = {};
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   662
}
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   663
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   664
IriSP.Model.Directory.prototype.addNamespace = function(_namespace, _url) {
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   665
    this.namespaces[_namespace] = _url;
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   666
}
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   667
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   668
IriSP.Model.Directory.prototype.remoteSource = function(_properties) {
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   669
    var _config = IriSP._({ directory: this }).extend(_properties);
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   670
    if (typeof this.remoteSources[_properties.url] === "undefined") {
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   671
        this.remoteSources[_properties.url] = new IriSP.Model.RemoteSource(_config);
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   672
    }
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   673
    return this.remoteSources[_properties.url];
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   674
}
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   675
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   676
IriSP.Model.Directory.prototype.newLocalSource = function(_properties) {
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   677
    var _config = IriSP._({ directory: this }).extend(_properties),
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   678
        _res = new IriSP.Model.Source(_config);
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   679
    return _res;
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   680
}
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   681
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   682
IriSP.Model.Directory.prototype.getElement = function(_id) {
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   683
    return this.elements[_id];
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   684
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   685
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   686
IriSP.Model.Directory.prototype.addElement = function(_element) {
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   687
    this.elements[_element.id] = _element;
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   688
}
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   689
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   690
IriSP.Model.Directory.prototype.getGlobalList = function() {
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   691
    var _res = new IriSP.Model.List(this);
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   692
    _res.addIds(IriSP._(this.elements).keys());
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   693
    return _res;
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   694
}
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   695
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   696
/* */