src/js/model.js
author veltr
Tue, 17 Apr 2012 20:19:46 +0200
branchnew-model
changeset 868 a525cc2214e7
parent 866 3bf7aa8216e5
child 870 2c025db10a10
permissions -rw-r--r--
Started big refactoring
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,
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
     8
    getAI : 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
    },
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    11
    isoToDate : function(_str) {
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    12
        // http://delete.me.uk/2005/03/iso8601.html
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    13
        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
    14
        var d = _str.match(new RegExp(regexp));
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    15
    
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    16
        var offset = 0;
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    17
        var date = new Date(d[1], 0, 1);
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    18
    
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    19
        if (d[3]) { date.setMonth(d[3] - 1); }
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    20
        if (d[5]) { date.setDate(d[5]); }
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    21
        if (d[7]) { date.setHours(d[7]); }
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    22
        if (d[8]) { date.setMinutes(d[8]); }
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    23
        if (d[10]) { date.setSeconds(d[10]); }
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    24
        if (d[12]) { date.setMilliseconds(Number("0." + d[12]) * 1000); }
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    25
        if (d[14]) {
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    26
            offset = (Number(d[16]) * 60) + Number(d[17]);
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    27
            offset *= ((d[15] == '-') ? 1 : -1);
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    28
        }
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    29
    
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    30
        offset -= date.getTimezoneOffset();
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    31
        time = (Number(date) + (offset * 60 * 1000));
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    32
        var _res = new Date();
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    33
        _res.setTime(Number(time));
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    34
        return _res;
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    35
    },
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    36
    dateToIso : function(d) {  
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    37
        function pad(n){return n<10 ? '0'+n : n}  
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    38
        return d.getUTCFullYear()+'-'  
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    39
            + pad(d.getUTCMonth()+1)+'-'  
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    40
            + pad(d.getUTCDate())+'T'  
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    41
            + pad(d.getUTCHours())+':'  
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    42
            + pad(d.getUTCMinutes())+':'  
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    43
            + pad(d.getUTCSeconds())+'Z'  
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    44
    }
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    45
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    46
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    47
/*
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    48
 * 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
    49
 */
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
    50
IriSP.Model.List = function(_directory) {
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    51
    Array.call(this);
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
    52
    this.directory = _directory;
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    53
    this.idIndex = [];
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    54
    if (typeof _directory == "undefined") {
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    55
        throw("Error : new IriSP.Model.List(directory): directory is undefined");
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
    56
    }
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    57
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    58
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    59
IriSP.Model.List.prototype = new Array();
856
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
IriSP.Model.List.prototype.getElement = function(_id) {
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    62
    if (this.hasId(_id)) {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    63
        return this;
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
    64
    }
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    65
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
    66
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
    67
IriSP.Model.List.prototype.hasId = function(_id) {
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    68
    return (IriSP._(this.idIndex).indexOf(_id) !== -1);
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
    69
}
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
    70
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    71
/* On recent browsers, forEach and map are defined and do what we want.
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    72
 * Otherwise, we'll use the Underscore.js functions
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    73
 */
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    74
if (typeof Array.prototype.forEach === "undefined") {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    75
    IriSP.Model.List.prototype.forEach = function(_callback) {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    76
        var _this = this;
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    77
        IriSP._(this).forEach(function(_value, _key) {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    78
            _callback(_value, _key, _this);
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    79
        });
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    80
    }
856
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
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    83
if (typeof Array.prototype.map === "undefined") {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    84
    IriSP.Model.List.prototype.map = function(_callback) {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    85
        var _this = this;
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    86
        return IriSP._(this).map(function(_value, _key) {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    87
            return _callback(_value, _key, _this);
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    88
        });
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    89
    }
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
    90
}
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
    91
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    92
/* We override Array's filter function because it doesn't return an IriSP.Model.List
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
    93
 */
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
    94
IriSP.Model.List.prototype.filter = function(_callback) {
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
    95
    var _this = this,
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
    96
        _res = new IriSP.Model.List(this.directory);
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    97
    _res.addElements(IriSP._(this).filter(function(_value, _key) {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    98
        return _callback(_value, _key, _this);
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
    99
    }));
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   100
    return _res;
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   101
}
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   102
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   103
/* 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
   104
 * and won't return a new IriSP.Model.List
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   105
 */
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   106
IriSP.Model.List.prototype.sortBy = function(_callback) {
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   107
    var _this = this,
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   108
        _res = new IriSP.Model.List(this.directory);
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   109
    _res.contents = IriSP._(this).sortBy(function(_value, _key) {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   110
        return _callback(_value, _key, _this);
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   111
    });
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   112
    return _res;
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   113
}
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   114
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   115
/* Title and Description are basic information for (almost) all element types,
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   116
 * here we can search by these criteria
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   117
 */
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   118
IriSP.Model.List.prototype.searchByTitle = function(_text) {
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   119
    var _rgxp = new RegExp('(' + _text.replace(/(\W)/gm,'\\$1') + ')','gim');
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   120
    return this.filter(function(_element) {
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   121
        return _rgxp.test(_element.title);
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   122
    });
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   123
}
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   124
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   125
IriSP.Model.List.prototype.searchByDescription = function(_text) {
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   126
    var _rgxp = new RegExp('(' + _text.replace(/(\W)/gm,'\\$1') + ')','gim');
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   127
    return this.filter(function(_element) {
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   128
        return _rgxp.test(_element.description);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   129
    });
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
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   132
IriSP.Model.List.prototype.searchByTextFields = function(_text) {
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   133
    var _rgxp = new RegExp('(' + _text.replace(/(\W)/gm,'\\$1') + ')','gim');
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   134
    return this.filter(function(_element) {
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   135
        return _rgxp.test(_element.description) || _rgxp.test(_element.title);
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   136
    });
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   137
}
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   138
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   139
IriSP.Model.List.prototype.addId = function(_id) {
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   140
    var _el = this.directory.getElement(_id)
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   141
    if (!this.hasId(_id) && typeof _el !== "undefined") {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   142
        this.idIndex.push(_id);
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   143
        Array.prototype.push.call(this, _el);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   144
    }
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   145
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   146
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   147
IriSP.Model.List.prototype.push = function(_el) {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   148
    if (typeof this.directory.getElement(_el.id) === "undefined") {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   149
        this.directory.addElement(_el);
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   150
    }
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   151
    var _index = (IriSP._(this.idIndex).indexOf(_el.id));
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   152
    if (_index === -1) {
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   153
        this.idIndex.push(_el.id);
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   154
        Array.prototype.push.call(this, _el);
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   155
    } else {
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   156
        this[_index] = _el;
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   157
    }
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   158
}
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   159
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   160
IriSP.Model.List.prototype.addIds = function(_array) {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   161
    var _l = _array.length,
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   162
        _this = this;
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   163
    IriSP._(_array).forEach(function(_id) {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   164
        _this.addId(_id);
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   165
    });
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   166
}
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   167
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   168
IriSP.Model.List.prototype.addElements = function(_array) {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   169
    var _l = _array.length,
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   170
        _this = this;
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   171
    IriSP._(_array).forEach(function(_el) {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   172
        _this.push(_el);
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   173
    });
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   174
}
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   175
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   176
/* A simple time management object, that helps converting millisecs to seconds and strings,
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   177
 * without the clumsiness of the original Date object.
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   178
 */
856
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
IriSP.Model.Time = function(_milliseconds) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   181
    this.milliseconds = parseInt(typeof _milliseconds !== "undefined" ? _milliseconds : 0);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   182
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   183
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   184
IriSP.Model.Time.prototype.setSeconds = function(_seconds) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   185
    this.milliseconds = 1000 * _seconds;
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
IriSP.Model.Time.prototype.getSeconds = function() {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   189
    return Math.floor(this.milliseconds / 1000);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   190
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   191
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   192
IriSP.Model.Time.prototype.getHMS = function() {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   193
    var _totalSeconds = Math.abs(this.getSeconds());
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   194
    return {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   195
        hours : Math.floor(_totalSeconds / 3600),
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   196
        minutes : (Math.floor(_totalSeconds / 60) % 60),
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   197
        seconds : _totalSeconds % 60
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   198
    } 
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   199
}
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
IriSP.Model.Time.prototype.toString = function() {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   202
    function pad(_n) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   203
        var _res = _n.toString();
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   204
        while (_res.length < 2) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   205
            _res = '0' + _res;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   206
        }
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   207
        return _res;
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
    var _hms = this.getHMS(),
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   210
        _res = '';
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   211
    if (_hms.hours) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   212
        _res += pad(_hms.hours) + ':'
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
    _res += pad(_hms.minutes) + ':' + pad(_hms.seconds);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   215
    return _res;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   216
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   217
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   218
/* IriSP.Model.Reference handles references between elements
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   219
 */
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   220
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   221
IriSP.Model.Reference = function(_source, _idRef) {
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   222
    this.source = _source;
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   223
    if (typeof _idRef === "object") {
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   224
        this.isList = true;
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   225
        this.contents = new IriSP.Model.List(this.source.directory);
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   226
        this.contents.addIds(IriSP._(_idRef).map(function(_id) {
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   227
            return _source.getNamespaced(_id).fullname;
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   228
        }));
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   229
    } else {
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   230
        this.isList = false;
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   231
        this.contents = this.source.directory.getElement(_source.getNamespaced(_idRef).fullname);
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   232
    }
856
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
/* */
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   236
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   237
IriSP.Model.Element = function(_id, _source) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   238
    this.elementType = 'element';
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   239
    if (typeof _source !== "undefined") {
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   240
        if (typeof _id === "undefined" || !_id) {
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   241
            _id = IriSP.Model.getAI();
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   242
        }
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   243
        this.source = _source;
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   244
        this.id = _source.getNamespaced(_id).fullname;
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   245
        this.title = "";
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   246
        this.description = "";
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   247
        this.source.directory.addElement(this);
856
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
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   251
IriSP.Model.Element.prototype.toString = function() {
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   252
    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
   253
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   254
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   255
IriSP.Model.Element.prototype.setReference = function(_elementType, _idRef) {
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   256
    this[_elementType] = new IriSP.Model.Reference(this.source, _idRef);
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   257
}
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   258
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   259
IriSP.Model.Element.prototype.getReference = function(_elementType) {
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   260
    if (typeof this[_elementType] !== "undefined") {
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   261
        return this[_elementType].contents;
856
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
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   265
IriSP.Model.Element.prototype.getRelated = function(_elementType) {
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   266
    var _this = this;
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   267
    return this.source.getList(_elementType).filter(function(_el) {
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   268
        var _ref = _el[_this.elementType];
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   269
        if (_ref.isList) {
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   270
            return _ref.contents.hasId(_this.id);
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   271
        }
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   272
        else {
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   273
            return _ref.contents.id === _this.id;
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   274
        }
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   275
    });
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   276
}
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   277
856
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
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   280
IriSP.Model.Media = function(_id, _source) {
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   281
    IriSP.Model.Element.call(this, _id, _source);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   282
    this.elementType = 'media';
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   283
    this.duration = new IriSP.Model.Time();
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   284
    this.video = '';
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   285
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   286
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   287
IriSP.Model.Media.prototype = new IriSP.Model.Element();
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   288
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   289
IriSP.Model.Media.prototype.setDuration = function(_durationMs) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   290
    this.duration.milliseconds = _durationMs;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   291
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   292
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   293
IriSP.Model.Media.prototype.getAnnotations = function() {
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   294
    return this.getRelated("annotation");
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   295
}
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   296
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   297
/* */
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   298
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   299
IriSP.Model.Tag = function(_id, _source) {
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   300
    IriSP.Model.Element.call(this, _id, _source);
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   301
    this.elementType = 'tag';
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   302
}
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   303
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   304
IriSP.Model.Tag.prototype = new IriSP.Model.Element();
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   305
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   306
IriSP.Model.Tag.prototype.getAnnotations = function() {
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   307
    return this.getRelated("annotation");
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   308
}
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   309
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   310
/* */
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   311
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   312
IriSP.Model.AnnotationType = function(_id, _source) {
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   313
    IriSP.Model.Element.call(this, _id, _source);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   314
    this.elementType = 'annotationType';
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   315
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   316
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   317
IriSP.Model.AnnotationType.prototype = new IriSP.Model.Element();
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   318
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   319
IriSP.Model.AnnotationType.prototype.getAnnotations = function() {
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   320
    return this.getRelated("annotation");
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   321
}
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   322
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   323
/* Annotation
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   324
 * */
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   325
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   326
IriSP.Model.Annotation = function(_id, _source) {
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   327
    IriSP.Model.Element.call(this, _id, _source);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   328
    this.elementType = 'annotation';
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   329
    this.begin = new IriSP.Model.Time();
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   330
    this.end = new IriSP.Model.Time();
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   331
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   332
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   333
IriSP.Model.Annotation.prototype = new IriSP.Model.Element(null);
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   334
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   335
IriSP.Model.Annotation.prototype.setBegin = function(_beginMs) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   336
    this.begin.milliseconds = _beginMs;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   337
}
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
IriSP.Model.Annotation.prototype.setEnd = function(_beginMs) {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   340
    this.end.milliseconds = _beginMs;
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   341
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   342
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   343
IriSP.Model.Annotation.prototype.setMedia = function(_idRef) {
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   344
    this.setReference("media", _idRef);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   345
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   346
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   347
IriSP.Model.Annotation.prototype.getMedia = function() {
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   348
    return this.getReference("media");
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   349
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   350
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   351
IriSP.Model.Annotation.prototype.setAnnotationType = function(_idRef) {
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   352
    this.setReference("annotationType", _idRef);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   353
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   354
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   355
IriSP.Model.Annotation.prototype.getAnnotationType = function() {
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   356
    return this.getReference("annotationType");
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   357
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   358
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   359
IriSP.Model.Annotation.prototype.setTags = function(_idRefs) {
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   360
    this.setReference("tag", _idRefs);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   361
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   362
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   363
IriSP.Model.Annotation.prototype.getTags = function() {
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   364
    return this.getReference("tag");
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   365
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   366
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   367
/* */
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   368
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   369
IriSP.Model.Source = function(_config) {
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   370
    this.status = IriSP.Model._SOURCE_STATUS_EMPTY;
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   371
    if (typeof _config !== "undefined") {
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   372
        var _this = this;
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   373
        IriSP._(_config).forEach(function(_v, _k) {
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   374
            _this[_k] = _v;
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   375
        })
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   376
        this.callbackQueue = [];
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   377
        this.contents = {};
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   378
        if (typeof this.namespace === "undefined") {
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   379
            this.namespace = IriSP.Model.getAI();
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   380
        }
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   381
        if (typeof this.namespaceUrl === "undefined") {
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   382
            this.namespaceUrl = (typeof this.url !== "undefined" ? this.url : this.namespaceUrl);
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   383
        }
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   384
        this.directory.namespaces[this.namespace] = this.namespaceUrl;
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   385
        this.get();
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   386
    }
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   387
}
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   388
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   389
IriSP.Model.Source.prototype.getNamespaced = function(_id) {
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   390
    var _tab = _id.split(':');
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   391
    if (_tab.length > 1) {
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   392
        return {
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   393
            namespace : _tab[0],
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   394
            name : _tab[1],
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   395
            fullname : _id
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   396
        }
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   397
    } else {
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   398
        return {
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   399
            namespace : this.namespace,
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   400
            name : _id,
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   401
            fullname : this.namespace + ':' + _id
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   402
        }
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   403
    }
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   404
}
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   405
    
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   406
IriSP.Model.Source.prototype.unNamespace = function(_id) {
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   407
    return _id.replace(this.namespace + ':', '');
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   408
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   409
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   410
IriSP.Model.Source.prototype.addList = function(_listId, _contents) {
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   411
    if (typeof this.contents[_listId] === "undefined") {
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   412
        this.contents[_listId] = new IriSP.Model.List(this.directory);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   413
    }
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   414
    this.contents[_listId].addElements(_contents);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   415
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   416
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   417
IriSP.Model.Source.prototype.getList = function(_listId) {
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   418
    if (typeof this.contents[_listId] === "undefined") {
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   419
        return this.directory.getGlobalList().filter(function(_e) {
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   420
            return (_e.elType === _listId);
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   421
        });
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   422
    } else {
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   423
        return this.contents[_listId];
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   424
    }
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   425
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   426
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   427
IriSP.Model.Source.prototype.forEach = function(_callback) {
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   428
    var _this = this;
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   429
    IriSP._(this.contents).forEach(function(_value, _key) {
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   430
        _callback.call(_this, _value, _key);
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   431
    })
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   432
}
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   433
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   434
IriSP.Model.Source.prototype.getElement = function(_elId) {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   435
    return this.directory.getElement(_elId);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   436
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   437
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   438
IriSP.Model.Source.prototype.setCurrentMediaId = function(_idRef) {
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   439
    if (typeof _idRef !== "undefined") {
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   440
        this.currentMedia = this.getMedias().getElement(this.getNamespaced(_idRef).fullname);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   441
    }
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.Source.prototype.setDefaultCurrentMedia = function() {
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   445
    if (typeof this.currentMedia === "undefined" && this.getMedias().length) {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   446
        this.currentMedia = this.getMedias()[0];
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   447
    }
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   448
}
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   449
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   450
IriSP.Model.Source.prototype.listNamespaces = function(_excludeSelf) {
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   451
    var _this = this,
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   452
        _nsls = [],
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   453
        _excludeSelf = (typeof _excludeSelf !== "undefined" && _excludeSelf);
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   454
    this.forEach(function(_list) {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   455
        IriSP._(_list).forEach(function(_el) {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   456
            var _ns = _el.id.replace(/:.*$/,'');
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   457
            if (IriSP._(_nsls).indexOf(_ns) === -1 && (!_excludeSelf || _ns !== _this.namespace)) {
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   458
                _nsls.push(_ns);
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   459
            }
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   460
        })
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   461
    });
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   462
    return _nsls;
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   463
}
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   464
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   465
IriSP.Model.Source.prototype.get = function() {
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   466
    this.status = IriSP.Model._SOURCE_STATUS_READY;
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   467
    var _this = this;
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   468
    if (_this.callbackQueue.length) {
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   469
        IriSP._(_this.callbackQueue).forEach(function(_callback) {
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   470
            _callback.call(_this);
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   471
        });
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   472
    }
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   473
    _this.callbackQueue = [];
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   474
}
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   475
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   476
IriSP.Model.Source.prototype.serialize = function() {
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   477
    return this.serializer.serialize(this);
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   478
}
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   479
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   480
IriSP.Model.Source.prototype.onLoad = function(_callback) {
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   481
    if (this.status === IriSP.Model._SOURCE_STATUS_READY) {
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   482
        console.log("Called on load, Ready");
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   483
        var _this = this;
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   484
        IriSP._.defer(function() {
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   485
            _callback.call(_this);
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   486
        });        
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   487
    } else {
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   488
        console.log("Called on load, not ready");
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   489
        this.callbackQueue.push(_callback);
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   490
    }
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   491
}
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   492
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   493
IriSP.Model.Source.prototype.getAnnotations = function() {
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   494
    return this.getList("annotation");
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   495
}
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   496
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   497
IriSP.Model.Source.prototype.getMedias = function() {
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   498
    return this.getList("media");
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   499
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   500
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   501
IriSP.Model.Source.prototype.getAnnotationTypes = function() {
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   502
    return this.getList("annotationType");
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   503
}
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   504
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   505
IriSP.Model.Source.prototype.getAnnotationTypeByTitle = function(_title) {
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   506
    var _res = this.getAnnotationTypes().searchByTitle(_title);
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   507
    if (_res.length) {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   508
        return _res[0];
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   509
    }
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   510
}
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   511
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   512
IriSP.Model.Source.prototype.getDuration = function() {
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   513
    var _m = this.currentMedia;
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   514
    if (typeof _m !== "undefined") {
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   515
        return this.currentMedia.duration;
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   516
    }
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   517
}
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   518
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   519
/* */
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   520
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   521
IriSP.Model.RemoteSource = function(_config) {
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   522
    IriSP.Model.Source.call(this, _config);
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   523
}
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   524
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   525
IriSP.Model.RemoteSource.prototype = new IriSP.Model.Source();
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   526
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   527
IriSP.Model.RemoteSource.prototype.get = function() {
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   528
    this.status = IriSP.Model._SOURCE_STATUS_WAITING;
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   529
    var _this = this;
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   530
    IriSP.jQuery.getJSON(this.url, function(_result) {
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   531
        _this.serializer.deSerialize(_result, _this);
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   532
        console.log('Received data, we have '+_this.callbackQueue.length+' callbacks waiting');
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   533
        if (_this.callbackQueue.length) {
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   534
            IriSP._(_this.callbackQueue).forEach(function(_callback) {
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   535
                _callback.call(_this);
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   536
            });
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   537
        }
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   538
        _this.callbackQueue = [];
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   539
        _this.status = IriSP.Model._SOURCE_STATUS_READY;
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   540
    });
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   541
}
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   542
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   543
/* */
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   544
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   545
IriSP.Model.Directory = function() {
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   546
    this.remoteSources = {};
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   547
    this.elements = {};
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   548
    this.namespaces = {};
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   549
}
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   550
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   551
IriSP.Model.Directory.prototype.remoteSource = function(_properties) {
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   552
    var _config = IriSP._({ directory: this }).extend(_properties);
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   553
    if (typeof this.remoteSources[_properties.url] === "undefined") {
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   554
        this.remoteSources[_properties.url] = new IriSP.Model.RemoteSource(_config);
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   555
    }
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   556
    return this.remoteSources[_properties.url];
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   557
}
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   558
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   559
IriSP.Model.Directory.prototype.newLocalSource = function(_properties) {
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   560
    var _config = IriSP._({ directory: this }).extend(_properties),
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   561
        _res = new IriSP.Model.Source(_config);
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   562
    return _res;
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   563
}
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   564
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   565
IriSP.Model.Directory.prototype.getElement = function(_id) {
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   566
    return this.elements[_id];
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   567
}
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   568
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   569
IriSP.Model.Directory.prototype.addElement = function(_element) {
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   570
    this.elements[_element.id] = _element;
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   571
}
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   572
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   573
IriSP.Model.Directory.prototype.getGlobalList = function() {
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   574
    var _res = new IriSP.Model.List(this);
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   575
    _res.addIds(IriSP._(this.elements).keys());
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   576
    return _res;
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   577
}
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   578
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   579
/* */