src/js/model.js
author ymh <ymh.work@gmail.com>
Wed, 04 Sep 2024 17:32:50 +0200
changeset 1072 ac1eacb3aa33
parent 1068 7623f9af9272
permissions -rw-r--r--
Migrate source and build to vite.js
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
998
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
     1
/* js is where data is stored in a standard form, whatever the serializer */
917
eb8677d3a663 HTML 5 Mashup Player
veltr
parents: 916
diff changeset
     2
998
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
     3
//TODO: Separate Project-specific data from Source
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
     4
import _ from "lodash";
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
     5
import jQuery from "jquery";
998
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
     6
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
     7
const Model = function (ns) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
     8
  function pad(n, x, b) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
     9
    b = b || 10;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    10
    var s = x.toString(b);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    11
    while (s.length < n) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    12
      s = "0" + s;
980
9ee8c00ae5b7 Improvement of the Sparkline widget
veltr
parents: 976
diff changeset
    13
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    14
    return s;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    15
  }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    16
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    17
  function rand16(n) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    18
    return pad(n, Math.floor(Math.random() * Math.pow(16, n)), 16);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    19
  }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    20
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    21
  var uidbase = rand16(8) + "-" + rand16(4) + "-",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    22
    uidincrement = Math.floor(Math.random() * 0x10000);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    23
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    24
  var charsub = ["[aáàâä]", "[cç]", "[eéèêë]", "[iíìîï]", "[oóòôö]", "[uùûü]"];
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    25
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    26
  var removeChars = [
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    27
    String.fromCharCode(768),
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    28
    String.fromCharCode(769),
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    29
    String.fromCharCode(770),
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    30
    String.fromCharCode(771),
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    31
    String.fromCharCode(807),
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    32
    "{",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    33
    "}",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    34
    "(",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    35
    ")",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    36
    "[",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    37
    "]",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    38
    "【",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    39
    "】",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    40
    "、",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    41
    "・",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    42
    "‥",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    43
    "。",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    44
    "「",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    45
    "」",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    46
    "『",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    47
    "』",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    48
    "〜",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    49
    ":",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    50
    "!",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    51
    "?",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    52
    " ",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    53
    ",",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    54
    " ",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    55
    ";",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    56
    "(",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    57
    ")",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    58
    ".",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    59
    "*",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    60
    "+",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    61
    "\\",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    62
    "?",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    63
    "|",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    64
    "{",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    65
    "}",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    66
    "[",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    67
    "]",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    68
    "^",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    69
    "#",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    70
    "/",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    71
  ];
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    72
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    73
  var Model = {},
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    74
    _SOURCE_STATUS_EMPTY = (Model._SOURCE_STATUS_EMPTY = 0),
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    75
    _SOURCE_STATUS_WAITING = (Model._SOURCE_STATUS_WAITING = 1),
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    76
    _SOURCE_STATUS_READY = (Model._SOURCE_STATUS_READY = 2),
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    77
    extendPrototype = (Model.extendPrototype = function (toClass, fromClass) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    78
      var fromP = fromClass.prototype,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    79
        toP = toClass.prototype;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    80
      for (var k in fromP) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    81
        if (fromP.hasOwnProperty(k)) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    82
          toP[k] = fromP[k];
998
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
    83
        }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    84
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    85
    }),
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    86
    getUID = (Model.getUID = function () {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    87
      return (
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    88
        uidbase +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    89
        pad(4, ++uidincrement % 0x10000, 16) +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    90
        "-" +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    91
        rand16(4) +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    92
        "-" +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    93
        rand16(6) +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    94
        rand16(6)
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    95
      );
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    96
    }),
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    97
    isLocalURL = (Model.isLocalURL = function (url) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    98
      var matches = url.match(/^(\w+:)\/\/([^/]+)/);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
    99
      if (matches) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   100
        return (
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   101
          matches[1] === document.location.protocol &&
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   102
          matches[2] === document.location.host
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   103
        );
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   104
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   105
      return true;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   106
    }),
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   107
    regexpFromTextOrArray = (Model.regexpFromTextOrArray = function (
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   108
      _textOrArray,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   109
      _testOnly,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   110
      _iexact
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   111
    ) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   112
      var _testOnly = _testOnly || false,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   113
        _iexact = _iexact || false;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   114
      function escapeText(_text) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   115
        return _text.replace(/([\\\*\+\?\|\{\[\}\]\(\)\^\$\.\#\/])/gm, "\\$1");
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   116
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   117
      var _source =
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   118
          typeof _textOrArray === "string"
925
28efc97b5d78 Corrected MAJOR bug in search results
veltr
parents: 919
diff changeset
   119
            ? escapeText(_textOrArray)
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   120
            : _(_textOrArray).map(escapeText).join("|"),
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   121
        _flags = "im";
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   122
      if (!_testOnly) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   123
        _source = "(" + _source + ")";
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   124
        _flags += "g";
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   125
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   126
      if (_iexact) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   127
        _source = "^" + _source + "$";
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   128
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   129
      return new RegExp(_source, _flags);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   130
    }),
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   131
    fullTextRegexps = (Model.fullTextRegexps = function (_text) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   132
      var remsrc = "[\\" + removeChars.join("\\") + "]",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   133
        remrx = new RegExp(remsrc, "gm"),
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   134
        txt = _text.toLowerCase().replace(remrx, ""),
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   135
        res = [],
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   136
        charsrx = _(charsub).map(function (c) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   137
          return new RegExp(c);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   138
        }),
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   139
        src = "";
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   140
      for (var j = 0; j < txt.length; j++) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   141
        if (j) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   142
          src += remsrc + "*";
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
   143
        }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   144
        var l = txt[j];
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   145
        _(charsub).each(function (v, k) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   146
          l = l.replace(charsrx[k], v);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   147
        });
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   148
        src += l;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   149
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   150
      return "(" + src + ")";
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   151
    }),
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   152
    isoToDate = (Model.isoToDate = function (_str) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   153
      // http://delete.me.uk/2005/03/iso8601.html
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   154
      var regexp =
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   155
        "([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})))?)?)?)?";
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   156
      var d = _str.match(new RegExp(regexp));
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   157
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   158
      var offset = 0;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   159
      var date = new Date(d[1], 0, 1);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   160
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   161
      if (d[3]) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   162
        date.setMonth(d[3] - 1);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   163
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   164
      if (d[5]) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   165
        date.setDate(d[5]);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   166
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   167
      if (d[7]) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   168
        date.setHours(d[7]);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   169
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   170
      if (d[8]) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   171
        date.setMinutes(d[8]);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   172
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   173
      if (d[10]) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   174
        date.setSeconds(d[10]);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   175
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   176
      if (d[12]) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   177
        date.setMilliseconds(Number("0." + d[12]) * 1000);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   178
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   179
      if (d[14]) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   180
        offset = Number(d[16]) * 60 + Number(d[17]);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   181
        offset *= d[15] == "-" ? 1 : -1;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   182
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   183
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   184
      offset -= date.getTimezoneOffset();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   185
      const time = Number(date) + offset * 60 * 1000;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   186
      var _res = new Date();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   187
      _res.setTime(Number(time));
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   188
      return _res;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   189
    }),
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   190
    dateToIso = (Model.dateToIso = function (_d) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   191
      var d = _d ? new Date(_d) : new Date();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   192
      return (
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   193
        d.getUTCFullYear() +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   194
        "-" +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   195
        pad(2, d.getUTCMonth() + 1) +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   196
        "-" +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   197
        pad(2, d.getUTCDate()) +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   198
        "T" +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   199
        pad(2, d.getUTCHours()) +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   200
        ":" +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   201
        pad(2, d.getUTCMinutes()) +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   202
        ":" +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   203
        pad(2, d.getUTCSeconds()) +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   204
        "Z"
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   205
      );
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   206
    });
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   207
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   208
  /*
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   209
   * List is a class for a list of elements (e.g. annotations, medias, etc. that each have a distinct ID)
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   210
   */
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   211
  var List = (Model.List = function (_directory) {
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   212
    Array.call(this);
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   213
    this.directory = _directory;
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   214
    this.idIndex = [];
937
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   215
    this.__events = {};
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   216
    if (typeof _directory == "undefined") {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   217
      console.trace();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   218
      throw "Error : new List(directory): directory is undefined";
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   219
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   220
    var _this = this;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   221
    this.on("clear-search", function () {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   222
      _this.searching = false;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   223
      _this.regexp = undefined;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   224
      _this.forEach(function (_element) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   225
        _element.found = undefined;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   226
      });
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   227
      _this.trigger("search-cleared");
1013
392ddcd212d7 Throwed in a bunch of semicolons
veltr
parents: 1010
diff changeset
   228
    });
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   229
  });
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   230
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   231
  List.prototype = new Array();
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   232
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   233
  List.prototype.hasId = function (_id) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   234
    return _(this.idIndex).includes(_id);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   235
  };
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   236
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   237
  /* On recent browsers, forEach and map are defined and do what we want.
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   238
   * Otherwise, we'll use the Underscore.js functions
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   239
   */
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   240
  if (typeof Array.prototype.forEach === "undefined") {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   241
    List.prototype.forEach = function (_callback) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   242
      var _this = this;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   243
      _(this).forEach(function (_value, _key) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   244
        _callback(_value, _key, _this);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   245
      });
1013
392ddcd212d7 Throwed in a bunch of semicolons
veltr
parents: 1010
diff changeset
   246
    };
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   247
  }
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   248
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   249
  if (typeof Array.prototype.map === "undefined") {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   250
    List.prototype.map = function (_callback) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   251
      var _this = this;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   252
      return _(this).map(function (_value, _key) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   253
        return _callback(_value, _key, _this);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   254
      });
1013
392ddcd212d7 Throwed in a bunch of semicolons
veltr
parents: 1010
diff changeset
   255
    };
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   256
  }
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   257
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   258
  List.prototype.pluck = function (_key) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   259
    return this.map(function (_value) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   260
      return _value[_key];
900
7673d645a8e0 Metadataplayer Mashup
veltr
parents: 887
diff changeset
   261
    });
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   262
  };
900
7673d645a8e0 Metadataplayer Mashup
veltr
parents: 887
diff changeset
   263
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   264
  /* We override Array's filter function because it doesn't return an List
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   265
   */
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   266
  List.prototype.filter = function (_callback) {
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   267
    var _this = this,
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   268
      _res = new List(this.directory);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   269
    _res.addElements(
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   270
      _(this).filter(function (_value, _key) {
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   271
        return _callback(_value, _key, _this);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   272
      })
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   273
    );
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   274
    return _res;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   275
  };
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   276
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   277
  List.prototype.slice = function (_start, _end) {
998
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
   278
    var _res = new List(this.directory);
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   279
    _res.addElements(Array.prototype.slice.call(this, _start, _end));
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   280
    return _res;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   281
  };
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   282
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   283
  List.prototype.splice = function (_start, _end) {
998
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
   284
    var _res = new List(this.directory);
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   285
    _res.addElements(Array.prototype.splice.call(this, _start, _end));
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   286
    this.idIndex.splice(_start, _end);
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   287
    return _res;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   288
  };
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   289
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   290
  /* Array has a sort function, but it's not as interesting as Underscore.js's sortBy
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   291
   * and won't return a new List
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   292
   */
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   293
  List.prototype.sortBy = function (_callback) {
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   294
    var _this = this,
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   295
      _res = new List(this.directory);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   296
    _res.addElements(
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   297
      _(this).sortBy(function (_value, _key) {
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   298
        return _callback(_value, _key, _this);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   299
      })
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   300
    );
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   301
    return _res;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   302
  };
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   303
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   304
  /* Title and Description are basic information for (almost) all element types,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   305
   * here we can search by these criteria
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   306
   */
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   307
  List.prototype.searchByTitle = function (_text, _iexact) {
973
638fe8541a2e Now allowing "iexact" searchByTitle
veltr
parents: 972
diff changeset
   308
    var _iexact = _iexact || false,
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   309
      _rgxp = regexpFromTextOrArray(_text, true, _iexact);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   310
    return this.filter(function (_element) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   311
      return _rgxp.test(_element.title);
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   312
    });
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   313
  };
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   314
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   315
  List.prototype.searchByDescription = function (_text, _iexact) {
973
638fe8541a2e Now allowing "iexact" searchByTitle
veltr
parents: 972
diff changeset
   316
    var _iexact = _iexact || false,
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   317
      _rgxp = regexpFromTextOrArray(_text, true, _iexact);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   318
    return this.filter(function (_element) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   319
      return _rgxp.test(_element.description);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   320
    });
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   321
  };
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   322
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   323
  List.prototype.searchByTextFields = function (_text, _iexact) {
973
638fe8541a2e Now allowing "iexact" searchByTitle
veltr
parents: 972
diff changeset
   324
    var _iexact = _iexact || false,
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   325
      _rgxp = regexpFromTextOrArray(_text, true, _iexact);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   326
    return this.filter(function (_element) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   327
      var keywords = (_element.keywords || _element.getTagTexts() || []).join(
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   328
        ", "
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   329
      );
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   330
      return (
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   331
        _rgxp.test(_element.description) ||
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   332
        _rgxp.test(_element.title) ||
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   333
        _rgxp.test(keywords)
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   334
      );
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   335
    });
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   336
  };
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   337
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   338
  List.prototype.search = function (_text) {
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
   339
    if (!_text) {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   340
      this.trigger("clear-search");
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   341
      return this;
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
   342
    }
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
   343
    this.searching = true;
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
   344
    this.trigger("search", _text);
1013
392ddcd212d7 Throwed in a bunch of semicolons
veltr
parents: 1010
diff changeset
   345
    var rxsource = fullTextRegexps(_text),
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   346
      rgxp = new RegExp(rxsource, "im");
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   347
    this.regexp = new RegExp(rxsource, "gim");
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   348
    var res = this.filter(function (_element, _k) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   349
      var titlematch = rgxp.test(_element.title),
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   350
        descmatch = rgxp.test(_element.description),
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   351
        _isfound = !!(titlematch || descmatch);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   352
      _element.found = _isfound;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   353
      _element.trigger(_isfound ? "found" : "not-found");
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   354
      return _isfound;
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
   355
    });
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   356
    this.trigger(res.length ? "found" : "not-found", res);
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
   357
    return res;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   358
  };
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
   359
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   360
  List.prototype.searchByTags = function (_text) {
1026
420608a77566 few enhancements
cavaliet
parents: 1013
diff changeset
   361
    if (!_text) {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   362
      this.trigger("clear-search");
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   363
      return this;
1026
420608a77566 few enhancements
cavaliet
parents: 1013
diff changeset
   364
    }
420608a77566 few enhancements
cavaliet
parents: 1013
diff changeset
   365
    this.searching = true;
420608a77566 few enhancements
cavaliet
parents: 1013
diff changeset
   366
    this.trigger("search", _text);
420608a77566 few enhancements
cavaliet
parents: 1013
diff changeset
   367
    var rxsource = fullTextRegexps(_text),
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   368
      rgxp = new RegExp(rxsource, "im");
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   369
    this.regexp = new RegExp(rxsource, "gim");
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   370
    var res = this.filter(function (_element, _k) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   371
      var _isfound = rgxp.test(_element.getTagTexts());
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   372
      _element.found = _isfound;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   373
      _element.trigger(_isfound ? "found" : "not-found");
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   374
      return _isfound;
1026
420608a77566 few enhancements
cavaliet
parents: 1013
diff changeset
   375
    });
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   376
    this.trigger(res.length ? "found" : "not-found", res);
1026
420608a77566 few enhancements
cavaliet
parents: 1013
diff changeset
   377
    return res;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   378
  };
1026
420608a77566 few enhancements
cavaliet
parents: 1013
diff changeset
   379
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   380
  List.prototype.getTitles = function () {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   381
    return this.map(function (_el) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   382
      return _el.title;
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   383
    });
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   384
  };
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   385
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   386
  List.prototype.addId = function (_id) {
1013
392ddcd212d7 Throwed in a bunch of semicolons
veltr
parents: 1010
diff changeset
   387
    var _el = this.directory.getElement(_id);
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   388
    if (!this.hasId(_id) && typeof _el !== "undefined") {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   389
      this.idIndex.push(_id);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   390
      Array.prototype.push.call(this, _el);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   391
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   392
  };
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   393
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   394
  List.prototype.push = function (_el) {
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   395
    if (typeof _el === "undefined") {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   396
      return;
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   397
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   398
    var _index = _(this.idIndex).indexOf(_el.id);
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   399
    if (_index === -1) {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   400
      this.idIndex.push(_el.id);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   401
      Array.prototype.push.call(this, _el);
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   402
    } else {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   403
      this[_index] = _el;
868
a525cc2214e7 Started big refactoring
veltr
parents: 866
diff changeset
   404
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   405
  };
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   406
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   407
  List.prototype.addIds = function (_array) {
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   408
    var _l = _array.length,
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   409
      _this = this;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   410
    _(_array).forEach(function (_id) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   411
      _this.addId(_id);
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   412
    });
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   413
  };
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   414
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   415
  List.prototype.addElements = function (_array) {
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   416
    var _this = this;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   417
    _(_array).forEach(function (_el) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   418
      _this.push(_el);
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
   419
    });
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   420
  };
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   421
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   422
  List.prototype.removeId = function (_id, _deleteFromDirectory) {
908
f56199193fad CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents: 904
diff changeset
   423
    var _deleteFromDirectory = _deleteFromDirectory || false,
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   424
      _index = _(this.idIndex).indexOf(_id);
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   425
    if (_index !== -1) {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   426
      this.splice(_index, 1);
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   427
    }
908
f56199193fad CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents: 904
diff changeset
   428
    if (_deleteFromDirectory) {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   429
      delete this.directory.elements[_id];
908
f56199193fad CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents: 904
diff changeset
   430
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   431
  };
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   432
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   433
  List.prototype.removeElement = function (_el, _deleteFromDirectory) {
908
f56199193fad CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents: 904
diff changeset
   434
    var _deleteFromDirectory = _deleteFromDirectory || false;
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   435
    this.removeId(_el.id);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   436
  };
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   437
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   438
  List.prototype.removeIds = function (_list, _deleteFromDirectory) {
908
f56199193fad CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents: 904
diff changeset
   439
    var _deleteFromDirectory = _deleteFromDirectory || false,
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   440
      _this = this;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   441
    _(_list).forEach(function (_id) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   442
      _this.removeId(_id);
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   443
    });
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   444
  };
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   445
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   446
  List.prototype.removeElements = function (_list, _deleteFromDirectory) {
908
f56199193fad CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents: 904
diff changeset
   447
    var _deleteFromDirectory = _deleteFromDirectory || false,
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   448
      _this = this;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   449
    _(_list).forEach(function (_el) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   450
      _this.removeElement(_el);
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   451
    });
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   452
  };
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   453
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   454
  List.prototype.on = function (_event, _callback) {
937
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   455
    if (typeof this.__events[_event] === "undefined") {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   456
      this.__events[_event] = [];
937
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   457
    }
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   458
    this.__events[_event].push(_callback);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   459
  };
937
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   460
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   461
  List.prototype.off = function (_event, _callback) {
969
353b0881a0b9 Added On-the-fly (file-less) metadata generation test
veltr
parents: 965
diff changeset
   462
    if (typeof this.__events[_event] !== "undefined") {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   463
      this.__events[_event] = ns
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   464
        ._(this.__events[_event])
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   465
        .reject(function (_fn) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   466
          return _fn === _callback;
969
353b0881a0b9 Added On-the-fly (file-less) metadata generation test
veltr
parents: 965
diff changeset
   467
        });
353b0881a0b9 Added On-the-fly (file-less) metadata generation test
veltr
parents: 965
diff changeset
   468
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   469
  };
969
353b0881a0b9 Added On-the-fly (file-less) metadata generation test
veltr
parents: 965
diff changeset
   470
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   471
  List.prototype.trigger = function (_event, _data) {
937
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   472
    var _list = this;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   473
    _(this.__events[_event]).each(function (_callback) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   474
      _callback.call(_list, _data);
937
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   475
    });
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   476
  };
937
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   477
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   478
  /* A simple time management object, that helps converting millisecs to seconds and strings,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   479
   * without the clumsiness of the original Date object.
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   480
   */
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   481
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   482
  var Time = (Model.Time = function (_milliseconds) {
900
7673d645a8e0 Metadataplayer Mashup
veltr
parents: 887
diff changeset
   483
    this.milliseconds = 0;
7673d645a8e0 Metadataplayer Mashup
veltr
parents: 887
diff changeset
   484
    this.setMilliseconds(_milliseconds);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   485
  });
900
7673d645a8e0 Metadataplayer Mashup
veltr
parents: 887
diff changeset
   486
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   487
  Time.prototype.setMilliseconds = function (_milliseconds) {
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
   488
    var _ante = this.milliseconds;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   489
    switch (typeof _milliseconds) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   490
      case "string":
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   491
        this.milliseconds = parseInt(_milliseconds);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   492
        break;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   493
      case "number":
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   494
        this.milliseconds = Math.floor(_milliseconds);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   495
        break;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   496
      case "object":
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   497
        this.milliseconds = parseInt(_milliseconds.valueOf());
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   498
        break;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   499
      default:
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   500
        this.milliseconds = 0;
887
6a04bd37da0a Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents: 881
diff changeset
   501
    }
6a04bd37da0a Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents: 881
diff changeset
   502
    if (this.milliseconds === NaN) {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   503
      this.milliseconds = _ante;
887
6a04bd37da0a Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents: 881
diff changeset
   504
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   505
  };
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   506
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   507
  Time.prototype.setSeconds = function (_seconds) {
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   508
    this.milliseconds = 1000 * _seconds;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   509
  };
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   510
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   511
  Time.prototype.getSeconds = function () {
917
eb8677d3a663 HTML 5 Mashup Player
veltr
parents: 916
diff changeset
   512
    return this.milliseconds / 1000;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   513
  };
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   514
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   515
  Time.prototype.getHMS = function () {
917
eb8677d3a663 HTML 5 Mashup Player
veltr
parents: 916
diff changeset
   516
    var _totalSeconds = Math.abs(Math.floor(this.getSeconds()));
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   517
    return {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   518
      hours: Math.floor(_totalSeconds / 3600),
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   519
      minutes: Math.floor(_totalSeconds / 60) % 60,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   520
      seconds: _totalSeconds % 60,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   521
      milliseconds: this.milliseconds % 1000,
1013
392ddcd212d7 Throwed in a bunch of semicolons
veltr
parents: 1010
diff changeset
   522
    };
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   523
  };
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   524
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   525
  Time.prototype.add = function (_milliseconds) {
998
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
   526
    this.milliseconds += new Time(_milliseconds).milliseconds;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   527
  };
887
6a04bd37da0a Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents: 881
diff changeset
   528
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   529
  Time.prototype.valueOf = function () {
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   530
    return this.milliseconds;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   531
  };
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   532
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   533
  Time.prototype.toString = function (showCs) {
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   534
    var _hms = this.getHMS(),
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   535
      _res = "";
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   536
    if (_hms.hours) {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   537
      _res += _hms.hours + ":";
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   538
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   539
    _res += pad(2, _hms.minutes) + ":" + pad(2, _hms.seconds);
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
   540
    if (showCs) {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   541
      _res += "." + Math.floor(_hms.milliseconds / 100);
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
   542
    }
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   543
    return _res;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   544
  };
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   545
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   546
  /* Reference handles references between elements
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   547
   */
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   548
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   549
  var Reference = (Model.Reference = function (_source, _idRef) {
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
   550
    this.source = _source;
916
ec6849bbbdcc Removed Namespacing before rewrite
veltr
parents: 915
diff changeset
   551
    this.id = _idRef;
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   552
    if (typeof _idRef === "object") {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   553
      this.isList = true;
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   554
    } else {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   555
      this.isList = false;
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   556
    }
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   557
    this.refresh();
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   558
  });
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   559
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   560
  Reference.prototype.refresh = function () {
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   561
    if (this.isList) {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   562
      this.contents = new List(this.source.directory);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   563
      this.contents.addIds(this.id);
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   564
    } else {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   565
      this.contents = this.source.getElement(this.id);
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   566
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   567
  };
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   568
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   569
  Reference.prototype.getContents = function () {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   570
    if (
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   571
      typeof this.contents === "undefined" ||
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   572
      (this.isList && this.contents.length != this.id.length)
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   573
    ) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   574
      this.refresh();
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   575
    }
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   576
    return this.contents;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   577
  };
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   578
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   579
  Reference.prototype.isOrHasId = function (_idRef) {
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   580
    if (this.isList) {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   581
      return _(this.id).indexOf(_idRef) !== -1;
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   582
    } else {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   583
      return this.id == _idRef;
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   584
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   585
  };
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   586
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   587
  /* */
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   588
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   589
  var BaseElement = (Model.Element = function (_id, _source) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   590
    this.elementType = "element";
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
   591
    this.title = "";
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
   592
    this.description = "";
1013
392ddcd212d7 Throwed in a bunch of semicolons
veltr
parents: 1010
diff changeset
   593
    this.__events = {};
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   594
    if (typeof _source === "undefined") {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   595
      return;
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   596
    }
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   597
    if (typeof _id === "undefined" || !_id) {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   598
      _id = getUID();
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   599
    }
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
   600
    this.id = _id;
872
d777d05a16e4 finished AnnotationsList and started New PolemicWidget
veltr
parents: 870
diff changeset
   601
    this.source = _source;
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
   602
    if (_source !== this) {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   603
      this.source.directory.addElement(this);
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
   604
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   605
  });
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   606
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   607
  BaseElement.prototype.toString = function () {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   608
    return (
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   609
      this.elementType +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   610
      (this.elementType !== "element"
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   611
        ? ", id=" + this.id + ', title="' + this.title + '"'
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   612
        : "")
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   613
    );
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   614
  };
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   615
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   616
  BaseElement.prototype.setReference = function (_elementType, _idRef) {
998
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
   617
    this[_elementType] = new Reference(this.source, _idRef);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   618
  };
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
   619
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   620
  BaseElement.prototype.getReference = function (_elementType) {
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   621
    if (typeof this[_elementType] !== "undefined") {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   622
      return this[_elementType].getContents();
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   623
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   624
  };
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   625
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   626
  BaseElement.prototype.getRelated = function (_elementType, _global) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   627
    _global = typeof _global !== "undefined" && _global;
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   628
    var _this = this;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   629
    return this.source.getList(_elementType, _global).filter(function (_el) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   630
      var _ref = _el[_this.elementType];
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   631
      return _ref && _ref.isOrHasId(_this.id);
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   632
    });
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   633
  };
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   634
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   635
  BaseElement.prototype.on = function (_event, _callback) {
937
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   636
    if (typeof this.__events[_event] === "undefined") {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   637
      this.__events[_event] = [];
937
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   638
    }
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   639
    this.__events[_event].push(_callback);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   640
  };
937
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   641
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   642
  BaseElement.prototype.off = function (_event, _callback) {
969
353b0881a0b9 Added On-the-fly (file-less) metadata generation test
veltr
parents: 965
diff changeset
   643
    if (typeof this.__events[_event] !== "undefined") {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   644
      this.__events[_event] = _(this.__events[_event]).reject(function (_fn) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   645
        return _fn === _callback;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   646
      });
969
353b0881a0b9 Added On-the-fly (file-less) metadata generation test
veltr
parents: 965
diff changeset
   647
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   648
  };
969
353b0881a0b9 Added On-the-fly (file-less) metadata generation test
veltr
parents: 965
diff changeset
   649
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   650
  BaseElement.prototype.trigger = function (_event, _data) {
937
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   651
    var _element = this;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   652
    _(this.__events[_event]).each(function (_callback) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   653
      _callback.call(_element, _data);
937
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   654
    });
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   655
  };
937
eb3c442cec50 Added events on annotation for inter widget communication
veltr
parents: 930
diff changeset
   656
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   657
  /* */
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   658
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   659
  var Playable = (Model.Playable = function (_id, _source) {
998
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
   660
    BaseElement.call(this, _id, _source);
970
b1c3bf6eca78 Cleaning and refactoring
veltr
parents: 969
diff changeset
   661
    if (typeof _source === "undefined") {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   662
      return;
970
b1c3bf6eca78 Cleaning and refactoring
veltr
parents: 969
diff changeset
   663
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   664
    this.elementType = "playable";
998
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
   665
    this.currentTime = new Time();
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   666
    this.volume = 0.5;
970
b1c3bf6eca78 Cleaning and refactoring
veltr
parents: 969
diff changeset
   667
    this.paused = true;
b1c3bf6eca78 Cleaning and refactoring
veltr
parents: 969
diff changeset
   668
    this.muted = false;
1044
d8339b45edc4 Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents: 1026
diff changeset
   669
    this.timeRange = false;
987
7b65bf78873a Bugfixes
veltr
parents: 986
diff changeset
   670
    this.loadedMetadata = false;
970
b1c3bf6eca78 Cleaning and refactoring
veltr
parents: 969
diff changeset
   671
    var _this = this;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   672
    this.on("play", function () {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   673
      _this.paused = false;
970
b1c3bf6eca78 Cleaning and refactoring
veltr
parents: 969
diff changeset
   674
    });
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   675
    this.on("pause", function () {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   676
      _this.paused = true;
970
b1c3bf6eca78 Cleaning and refactoring
veltr
parents: 969
diff changeset
   677
    });
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   678
    this.on("timeupdate", function (_time) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   679
      _this.currentTime = _time;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   680
      _this
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   681
        .getAnnotations()
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   682
        .filter(function (_a) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   683
          return (_a.end <= _time || _a.begin > _time) && _a.playing;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   684
        })
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   685
        .forEach(function (_a) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   686
          _a.playing = false;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   687
          _a.trigger("leave");
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   688
          _this.trigger("leave-annotation", _a);
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
   689
        });
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   690
      _this
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   691
        .getAnnotations()
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   692
        .filter(function (_a) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   693
          return _a.begin <= _time && _a.end > _time && !_a.playing;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   694
        })
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   695
        .forEach(function (_a) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   696
          _a.playing = true;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   697
          _a.trigger("enter");
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   698
          _this.trigger("enter-annotation", _a);
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
   699
        });
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   700
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   701
      if (_this.getTimeRange()) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   702
        if (_this.getTimeRange()[0] > _time) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   703
          _this.pause();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   704
          _this.setCurrentTime(_this.getTimeRange()[0]);
1044
d8339b45edc4 Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents: 1026
diff changeset
   705
        }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   706
        if (_this.getTimeRange()[1] < _time) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   707
          _this.pause();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   708
          _this.setCurrentTime(_this.getTimeRange()[1]);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   709
        }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   710
      }
970
b1c3bf6eca78 Cleaning and refactoring
veltr
parents: 969
diff changeset
   711
    });
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   712
    this.on("loadedmetadata", function () {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   713
      _this.loadedMetadata = true;
998
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
   714
    });
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   715
  });
970
b1c3bf6eca78 Cleaning and refactoring
veltr
parents: 969
diff changeset
   716
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   717
  extendPrototype(Playable, BaseElement);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   718
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   719
  Playable.prototype.getCurrentTime = function () {
970
b1c3bf6eca78 Cleaning and refactoring
veltr
parents: 969
diff changeset
   720
    return this.currentTime;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   721
  };
970
b1c3bf6eca78 Cleaning and refactoring
veltr
parents: 969
diff changeset
   722
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   723
  Playable.prototype.getVolume = function () {
970
b1c3bf6eca78 Cleaning and refactoring
veltr
parents: 969
diff changeset
   724
    return this.volume;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   725
  };
970
b1c3bf6eca78 Cleaning and refactoring
veltr
parents: 969
diff changeset
   726
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   727
  Playable.prototype.getPaused = function () {
970
b1c3bf6eca78 Cleaning and refactoring
veltr
parents: 969
diff changeset
   728
    return this.paused;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   729
  };
970
b1c3bf6eca78 Cleaning and refactoring
veltr
parents: 969
diff changeset
   730
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   731
  Playable.prototype.getMuted = function () {
970
b1c3bf6eca78 Cleaning and refactoring
veltr
parents: 969
diff changeset
   732
    return this.muted;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   733
  };
970
b1c3bf6eca78 Cleaning and refactoring
veltr
parents: 969
diff changeset
   734
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   735
  Playable.prototype.getTimeRange = function () {
1044
d8339b45edc4 Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents: 1026
diff changeset
   736
    return this.timeRange;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   737
  };
1044
d8339b45edc4 Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents: 1026
diff changeset
   738
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   739
  Playable.prototype.setCurrentTime = function (_time) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   740
    this.trigger("setcurrenttime", _time);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   741
  };
970
b1c3bf6eca78 Cleaning and refactoring
veltr
parents: 969
diff changeset
   742
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   743
  Playable.prototype.setVolume = function (_vol) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   744
    this.trigger("setvolume", _vol);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   745
  };
970
b1c3bf6eca78 Cleaning and refactoring
veltr
parents: 969
diff changeset
   746
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   747
  Playable.prototype.setMuted = function (_muted) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   748
    this.trigger("setmuted", _muted);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   749
  };
970
b1c3bf6eca78 Cleaning and refactoring
veltr
parents: 969
diff changeset
   750
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   751
  Playable.prototype.setTimeRange = function (_timeBegin, _timeEnd) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   752
    if (_timeBegin < _timeEnd && _timeBegin >= 0 && _timeEnd > 0) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   753
      return this.trigger("settimerange", [_timeBegin, _timeEnd]);
1044
d8339b45edc4 Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents: 1026
diff changeset
   754
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   755
  };
1044
d8339b45edc4 Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents: 1026
diff changeset
   756
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   757
  Playable.prototype.resetTimeRange = function () {
1044
d8339b45edc4 Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents: 1026
diff changeset
   758
    return this.trigger("resettimerange");
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   759
  };
1044
d8339b45edc4 Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents: 1026
diff changeset
   760
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   761
  Playable.prototype.play = function () {
970
b1c3bf6eca78 Cleaning and refactoring
veltr
parents: 969
diff changeset
   762
    this.trigger("setplay");
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   763
  };
970
b1c3bf6eca78 Cleaning and refactoring
veltr
parents: 969
diff changeset
   764
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   765
  Playable.prototype.pause = function () {
970
b1c3bf6eca78 Cleaning and refactoring
veltr
parents: 969
diff changeset
   766
    this.trigger("setpause");
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   767
  };
970
b1c3bf6eca78 Cleaning and refactoring
veltr
parents: 969
diff changeset
   768
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   769
  Playable.prototype.show = function () {};
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
   770
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   771
  Playable.prototype.hide = function () {};
970
b1c3bf6eca78 Cleaning and refactoring
veltr
parents: 969
diff changeset
   772
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   773
  /* */
970
b1c3bf6eca78 Cleaning and refactoring
veltr
parents: 969
diff changeset
   774
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   775
  var Media = (Model.Media = function (_id, _source) {
998
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
   776
    Playable.call(this, _id, _source);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   777
    this.elementType = "media";
998
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
   778
    this.duration = new Time();
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   779
    this.video = "";
965
eadb7290c325 Improvements in widget communication
veltr
parents: 964
diff changeset
   780
    var _this = this;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   781
  });
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   782
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   783
  extendPrototype(Media, Playable);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   784
  /* */
1044
d8339b45edc4 Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents: 1026
diff changeset
   785
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   786
  var Media = (Model.Media = function (_id, _source) {
1044
d8339b45edc4 Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents: 1026
diff changeset
   787
    Playable.call(this, _id, _source);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   788
    this.elementType = "media";
1044
d8339b45edc4 Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents: 1026
diff changeset
   789
    this.duration = new Time();
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   790
    this.video = "";
1044
d8339b45edc4 Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents: 1026
diff changeset
   791
    var _this = this;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   792
  });
1044
d8339b45edc4 Added support for defining a "time range" for a Playable to set the time boundaries of what can be played by the diffenrent players (Popcorn and HtmlPlayer for now). Added option in Segment widget to define a timerange on click.
durandn
parents: 1026
diff changeset
   793
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   794
  extendPrototype(Media, Playable);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   795
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   796
  /* Default functions to be overriden by players */
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   797
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   798
  Media.prototype.setDuration = function (_durationMs) {
900
7673d645a8e0 Metadataplayer Mashup
veltr
parents: 887
diff changeset
   799
    this.duration.setMilliseconds(_durationMs);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   800
  };
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   801
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   802
  Media.prototype.getAnnotations = function () {
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   803
    return this.getRelated("annotation");
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   804
  };
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   805
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   806
  Media.prototype.getAnnotationsByTypeTitle = function (_title) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   807
    var _annTypes = this.source
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   808
      .getAnnotationTypes()
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   809
      .searchByTitle(_title)
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   810
      .pluck("id");
900
7673d645a8e0 Metadataplayer Mashup
veltr
parents: 887
diff changeset
   811
    if (_annTypes.length) {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   812
      return this.getAnnotations().filter(function (_annotation) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   813
        return _(_annTypes).indexOf(_annotation.getAnnotationType().id) !== -1;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   814
      });
900
7673d645a8e0 Metadataplayer Mashup
veltr
parents: 887
diff changeset
   815
    } else {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   816
      return new List(this.source.directory);
900
7673d645a8e0 Metadataplayer Mashup
veltr
parents: 887
diff changeset
   817
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   818
  };
900
7673d645a8e0 Metadataplayer Mashup
veltr
parents: 887
diff changeset
   819
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   820
  /* */
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   821
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   822
  var Tag = (Model.Tag = function (_id, _source) {
998
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
   823
    BaseElement.call(this, _id, _source);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   824
    this.elementType = "tag";
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   825
  });
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   826
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   827
  extendPrototype(Tag, BaseElement);
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   828
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   829
  Tag.prototype.getAnnotations = function () {
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   830
    return this.getRelated("annotation");
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   831
  };
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   832
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   833
  /* */
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   834
  var AnnotationType = (Model.AnnotationType = function (_id, _source) {
998
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
   835
    BaseElement.call(this, _id, _source);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   836
    this.elementType = "annotationType";
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   837
  });
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   838
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   839
  extendPrototype(AnnotationType, BaseElement);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   840
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   841
  AnnotationType.prototype.getAnnotations = function () {
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   842
    return this.getRelated("annotation");
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   843
  };
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
   844
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   845
  /* Annotation
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   846
   * */
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   847
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   848
  var Annotation = (Model.Annotation = function (_id, _source) {
998
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
   849
    BaseElement.call(this, _id, _source);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   850
    this.elementType = "annotation";
998
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
   851
    this.begin = new Time();
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
   852
    this.end = new Time();
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
   853
    this.tag = new Reference(_source, []);
965
eadb7290c325 Improvements in widget communication
veltr
parents: 964
diff changeset
   854
    this.playing = false;
964
d7d56ea2d0a6 Adaptations for Knowledge Concierge
veltr
parents: 959
diff changeset
   855
    var _this = this;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   856
    this.on("click", function () {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   857
      _this.getMedia().setCurrentTime(_this.begin);
965
eadb7290c325 Improvements in widget communication
veltr
parents: 964
diff changeset
   858
    });
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   859
  });
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   860
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   861
  extendPrototype(Annotation, BaseElement);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   862
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   863
  /* Set begin and end in one go, to avoid undesired side-effects in
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   864
   * setBegin/setEnd interaction */
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   865
  Annotation.prototype.setBeginEnd = function (_beginMs, _endMs) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   866
    _beginMs = Math.max(0, _beginMs);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   867
    _endMs = Math.max(0, _endMs);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   868
    if (_endMs < _beginMs) _endMs = _beginMs;
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1044
diff changeset
   869
    this.begin.setMilliseconds(_beginMs);
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1044
diff changeset
   870
    this.end.setMilliseconds(_endMs);
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1044
diff changeset
   871
    this.trigger("change-begin");
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1044
diff changeset
   872
    this.trigger("change-end");
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   873
  };
1068
7623f9af9272 merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents: 1044
diff changeset
   874
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   875
  Annotation.prototype.setBegin = function (_beginMs) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   876
    this.begin.setMilliseconds(Math.max(0, _beginMs));
976
4b9ec475026a Modified AutoPlayer for the platform
veltr
parents: 973
diff changeset
   877
    this.trigger("change-begin");
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
   878
    if (this.end < this.begin) {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   879
      this.setEnd(this.begin);
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
   880
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   881
  };
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   882
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   883
  Annotation.prototype.setEnd = function (_endMs) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   884
    this.end.setMilliseconds(
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   885
      Math.min(_endMs, this.getMedia().duration.milliseconds)
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   886
    );
976
4b9ec475026a Modified AutoPlayer for the platform
veltr
parents: 973
diff changeset
   887
    this.trigger("change-end");
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
   888
    if (this.end < this.begin) {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   889
      this.setBegin(this.end);
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
   890
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   891
  };
976
4b9ec475026a Modified AutoPlayer for the platform
veltr
parents: 973
diff changeset
   892
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   893
  Annotation.prototype.setDuration = function (_durMs) {
976
4b9ec475026a Modified AutoPlayer for the platform
veltr
parents: 973
diff changeset
   894
    this.setEnd(_durMs + this.begin.milliseconds);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   895
  };
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   896
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   897
  Annotation.prototype.setMedia = function (_idRef) {
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   898
    this.setReference("media", _idRef);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   899
  };
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   900
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   901
  Annotation.prototype.getMedia = function () {
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   902
    return this.getReference("media");
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   903
  };
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   904
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   905
  Annotation.prototype.setAnnotationType = function (_idRef) {
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   906
    this.setReference("annotationType", _idRef);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   907
  };
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   908
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   909
  Annotation.prototype.getAnnotationType = function () {
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   910
    return this.getReference("annotationType");
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   911
  };
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   912
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   913
  Annotation.prototype.setTags = function (_idRefs) {
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   914
    this.setReference("tag", _idRefs);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   915
  };
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   916
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   917
  Annotation.prototype.getTags = function () {
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
   918
    return this.getReference("tag");
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   919
  };
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
   920
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   921
  Annotation.prototype.getTagTexts = function () {
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   922
    return this.getTags().getTitles();
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   923
  };
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
   924
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   925
  Annotation.prototype.getDuration = function () {
1013
392ddcd212d7 Throwed in a bunch of semicolons
veltr
parents: 1010
diff changeset
   926
    return new Time(this.end.milliseconds - this.begin.milliseconds);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   927
  };
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   928
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   929
  /* */
900
7673d645a8e0 Metadataplayer Mashup
veltr
parents: 887
diff changeset
   930
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   931
  var MashedAnnotation = (Model.MashedAnnotation = function (
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   932
    _mashup,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   933
    _annotation
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   934
  ) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   935
    BaseElement.call(
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   936
      this,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   937
      _mashup.id + "_" + _annotation.id,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   938
      _annotation.source
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   939
    );
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   940
    this.elementType = "mashedAnnotation";
887
6a04bd37da0a Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents: 881
diff changeset
   941
    this.annotation = _annotation;
998
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
   942
    this.begin = new Time();
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
   943
    this.end = new Time();
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
   944
    this.duration = new Time();
887
6a04bd37da0a Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents: 881
diff changeset
   945
    this.title = this.annotation.title;
6a04bd37da0a Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents: 881
diff changeset
   946
    this.description = this.annotation.description;
900
7673d645a8e0 Metadataplayer Mashup
veltr
parents: 887
diff changeset
   947
    this.color = this.annotation.color;
965
eadb7290c325 Improvements in widget communication
veltr
parents: 964
diff changeset
   948
    var _this = this;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   949
    this.on("click", function () {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   950
      _mashup.setCurrentTime(_this.begin);
965
eadb7290c325 Improvements in widget communication
veltr
parents: 964
diff changeset
   951
    });
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   952
    this.on("enter", function () {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   953
      _this.annotation.trigger("enter");
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
   954
    });
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   955
    this.on("leave", function () {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   956
      _this.annotation.trigger("leave");
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
   957
    });
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   958
  });
887
6a04bd37da0a Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents: 881
diff changeset
   959
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   960
  extendPrototype(MashedAnnotation, BaseElement);
887
6a04bd37da0a Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents: 881
diff changeset
   961
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   962
  MashedAnnotation.prototype.getMedia = function () {
887
6a04bd37da0a Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents: 881
diff changeset
   963
    return this.annotation.getReference("media");
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   964
  };
887
6a04bd37da0a Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents: 881
diff changeset
   965
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   966
  MashedAnnotation.prototype.getAnnotationType = function () {
887
6a04bd37da0a Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents: 881
diff changeset
   967
    return this.annotation.getReference("annotationType");
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   968
  };
887
6a04bd37da0a Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents: 881
diff changeset
   969
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   970
  MashedAnnotation.prototype.getTags = function () {
887
6a04bd37da0a Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents: 881
diff changeset
   971
    return this.annotation.getReference("tag");
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   972
  };
887
6a04bd37da0a Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents: 881
diff changeset
   973
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   974
  MashedAnnotation.prototype.getTagTexts = function () {
887
6a04bd37da0a Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents: 881
diff changeset
   975
    return this.annotation.getTags().getTitles();
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   976
  };
887
6a04bd37da0a Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents: 881
diff changeset
   977
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   978
  MashedAnnotation.prototype.getDuration = function () {
940
veltr
parents: 937
diff changeset
   979
    return this.annotation.getDuration();
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   980
  };
940
veltr
parents: 937
diff changeset
   981
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   982
  MashedAnnotation.prototype.setBegin = function (_begin) {
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
   983
    this.begin.setMilliseconds(_begin);
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
   984
    this.duration.setMilliseconds(this.annotation.getDuration());
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
   985
    this.end.setMilliseconds(_begin + this.duration);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   986
  };
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
   987
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   988
  /* */
887
6a04bd37da0a Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents: 881
diff changeset
   989
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   990
  var Mashup = (Model.Mashup = function (_id, _source) {
998
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
   991
    Playable.call(this, _id, _source);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   992
    this.elementType = "mashup";
998
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
   993
    this.duration = new Time();
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
   994
    this.segments = new List(_source.directory);
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
   995
    this.loaded = false;
965
eadb7290c325 Improvements in widget communication
veltr
parents: 964
diff changeset
   996
    var _this = this;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   997
    this._updateTimes = function () {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   998
      _this.updateTimes();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
   999
      _this.trigger("change");
1013
392ddcd212d7 Throwed in a bunch of semicolons
veltr
parents: 1010
diff changeset
  1000
    };
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1001
    this.on("add", this._updateTimes);
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1002
    this.on("remove", this._updateTimes);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1003
  });
887
6a04bd37da0a Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents: 881
diff changeset
  1004
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1005
  extendPrototype(Mashup, Playable);
887
6a04bd37da0a Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents: 881
diff changeset
  1006
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1007
  Mashup.prototype.updateTimes = function () {
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1008
    var _time = 0;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1009
    this.segments.forEach(function (_segment) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1010
      _segment.setBegin(_time);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1011
      _time = _segment.end;
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1012
    });
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1013
    this.duration.setMilliseconds(_time);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1014
  };
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1015
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1016
  Mashup.prototype.addAnnotation = function (_annotation, _defer) {
998
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
  1017
    var _mashedAnnotation = new MashedAnnotation(this, _annotation),
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1018
      _defer = _defer || false;
900
7673d645a8e0 Metadataplayer Mashup
veltr
parents: 887
diff changeset
  1019
    this.segments.push(_mashedAnnotation);
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1020
    _annotation.on("change-begin", this._updateTimes);
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1021
    _annotation.on("change-end", this._updateTimes);
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1022
    if (!_defer) {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1023
      this.trigger("add");
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1024
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1025
  };
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1026
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1027
  Mashup.prototype.addAnnotationById = function (_elId, _defer) {
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1028
    var _annotation = this.source.getElement(_elId),
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1029
      _defer = _defer || false;
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1030
    if (typeof _annotation !== "undefined") {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1031
      this.addAnnotation(_annotation, _defer);
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1032
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1033
  };
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1034
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1035
  Mashup.prototype.addAnnotations = function (_segments) {
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1036
    var _this = this;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1037
    _(_segments).forEach(function (_segment) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1038
      _this.addAnnotation(_segment, true);
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1039
    });
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1040
    this.trigger("add");
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1041
  };
900
7673d645a8e0 Metadataplayer Mashup
veltr
parents: 887
diff changeset
  1042
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1043
  Mashup.prototype.addAnnotationsById = function (_segments) {
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1044
    var _this = this;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1045
    _(_segments).forEach(function (_segment) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1046
      _this.addAnnotationById(_segment, true);
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1047
    });
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1048
    this.trigger("add");
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1049
  };
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1050
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1051
  Mashup.prototype.removeAnnotation = function (_annotation, _defer) {
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1052
    var _defer = _defer || false;
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1053
    _annotation.off("change-begin", this._updateTimes);
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1054
    _annotation.off("change-end", this._updateTimes);
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1055
    this.segments.removeId(this.id + "_" + _annotation.id);
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1056
    if (!_defer) {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1057
      this.trigger("remove");
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1058
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1059
  };
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1060
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1061
  Mashup.prototype.removeAnnotationById = function (_annId, _defer) {
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1062
    var _defer = _defer || false;
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1063
    var _annotation = this.source.getElement(_annId);
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1064
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1065
    if (_annotation) {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1066
      this.removeAnnotation(_annotation, _defer);
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1067
    }
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1068
    if (!_defer) {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1069
      this.trigger("remove");
900
7673d645a8e0 Metadataplayer Mashup
veltr
parents: 887
diff changeset
  1070
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1071
  };
887
6a04bd37da0a Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents: 881
diff changeset
  1072
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1073
  Mashup.prototype.setAnnotations = function (_segments) {
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1074
    while (this.segments.length) {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1075
      this.removeAnnotation(this.segments[0].annotation, true);
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1076
    }
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1077
    this.addAnnotations(_segments);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1078
  };
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1079
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1080
  Mashup.prototype.setAnnotationsById = function (_segments) {
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1081
    while (this.segments.length) {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1082
      this.removeAnnotation(this.segments[0].annotation, true);
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1083
    }
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1084
    this.addAnnotationsById(_segments);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1085
  };
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1086
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1087
  Mashup.prototype.hasAnnotation = function (_annotation) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1088
    return !!_(this.segments).find(function (_s) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1089
      return _s.annotation === _annotation;
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1090
    });
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1091
  };
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1092
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1093
  Mashup.prototype.getAnnotation = function (_annotation) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1094
    return _(this.segments).find(function (_s) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1095
      return _s.annotation === _annotation;
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1096
    });
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1097
  };
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1098
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1099
  Mashup.prototype.getAnnotationById = function (_id) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1100
    return _(this.segments).find(function (_s) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1101
      return _s.annotation.id === _id;
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1102
    });
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1103
  };
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1104
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1105
  Mashup.prototype.getAnnotations = function () {
887
6a04bd37da0a Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents: 881
diff changeset
  1106
    return this.segments;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1107
  };
887
6a04bd37da0a Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents: 881
diff changeset
  1108
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1109
  Mashup.prototype.getOriginalAnnotations = function () {
998
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
  1110
    var annotations = new List(this.source.directory);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1111
    this.segments.forEach(function (_s) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1112
      annotations.push(_s.annotation);
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1113
    });
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1114
    return annotations;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1115
  };
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1116
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1117
  Mashup.prototype.getMedias = function () {
998
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
  1118
    var medias = new List(this.source.directory);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1119
    this.segments.forEach(function (_annotation) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1120
      medias.push(_annotation.getMedia());
1013
392ddcd212d7 Throwed in a bunch of semicolons
veltr
parents: 1010
diff changeset
  1121
    });
983
97fef7a4b189 updated search
veltr
parents: 980
diff changeset
  1122
    return medias;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1123
  };
900
7673d645a8e0 Metadataplayer Mashup
veltr
parents: 887
diff changeset
  1124
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1125
  Mashup.prototype.getAnnotationsByTypeTitle = function (_title) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1126
    var _annTypes = this.source
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1127
      .getAnnotationTypes()
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1128
      .searchByTitle(_title)
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1129
      .pluck("id");
900
7673d645a8e0 Metadataplayer Mashup
veltr
parents: 887
diff changeset
  1130
    if (_annTypes.length) {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1131
      return this.getAnnotations().filter(function (_annotation) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1132
        return _(_annTypes).indexOf(_annotation.getAnnotationType().id) !== -1;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1133
      });
900
7673d645a8e0 Metadataplayer Mashup
veltr
parents: 887
diff changeset
  1134
    } else {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1135
      return new List(this.source.directory);
900
7673d645a8e0 Metadataplayer Mashup
veltr
parents: 887
diff changeset
  1136
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1137
  };
900
7673d645a8e0 Metadataplayer Mashup
veltr
parents: 887
diff changeset
  1138
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1139
  Mashup.prototype.getAnnotationAtTime = function (_time) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1140
    var _list = this.segments.filter(function (_annotation) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1141
      return _annotation.begin <= _time && _annotation.end > _time;
903
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
  1142
    });
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
  1143
    if (_list.length) {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1144
      return _list[0];
903
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
  1145
    } else {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1146
      return undefined;
903
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
  1147
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1148
  };
903
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
  1149
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1150
  Mashup.prototype.getMediaAtTime = function (_time) {
903
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
  1151
    var _annotation = this.getAnnotationAtTime(_time);
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
  1152
    if (typeof _annotation !== "undefined") {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1153
      return _annotation.getMedia();
903
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
  1154
    } else {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1155
      return undefined;
903
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
  1156
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1157
  };
903
d9da52e20f7f AnnotationsList now updated to work with mashups
veltr
parents: 902
diff changeset
  1158
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1159
  /* */
887
6a04bd37da0a Corrected lib loading function so several instances of the Metadataplayer can be called
veltr
parents: 881
diff changeset
  1160
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1161
  var Source = (Model.Source = function (_config) {
998
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
  1162
    BaseElement.call(this, false, this);
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
  1163
    this.status = _SOURCE_STATUS_EMPTY;
969
353b0881a0b9 Added On-the-fly (file-less) metadata generation test
veltr
parents: 965
diff changeset
  1164
    this.elementType = "source";
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
  1165
    if (typeof _config !== "undefined") {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1166
      var _this = this;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1167
      _(_config).forEach(function (_v, _k) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1168
        _this[_k] = _v;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1169
      });
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1170
      this.callbackQueue = [];
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1171
      this.contents = {};
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1172
      this.get();
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
  1173
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1174
  });
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
  1175
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1176
  extendPrototype(Source, BaseElement);
969
353b0881a0b9 Added On-the-fly (file-less) metadata generation test
veltr
parents: 965
diff changeset
  1177
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1178
  Source.prototype.addList = function (_listId, _contents) {
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
  1179
    if (typeof this.contents[_listId] === "undefined") {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1180
      this.contents[_listId] = new List(this.directory);
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
  1181
    }
866
3bf7aa8216e5 IriSP.Model.List now inherits from Array
veltr
parents: 864
diff changeset
  1182
    this.contents[_listId].addElements(_contents);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1183
  };
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
  1184
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1185
  Source.prototype.getList = function (_listId, _global) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1186
    _global = typeof _global !== "undefined" && _global;
986
f9d51dd4a3fe Tooltip Improvements, Update Popcorn
veltr
parents: 983
diff changeset
  1187
    if (_global) {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1188
      return this.directory.getGlobalList().filter(function (_e) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1189
        return _e.elementType === _listId;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1190
      });
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
  1191
    } else {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1192
      if (typeof this.contents[_listId] === "undefined") {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1193
        this.contents[_listId] = new List(this.directory);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1194
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1195
      return this.contents[_listId];
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
  1196
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1197
  };
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
  1198
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1199
  Source.prototype.forEach = function (_callback) {
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
  1200
    var _this = this;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1201
    _(this.contents).forEach(function (_value, _key) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1202
      _callback.call(_this, _value, _key);
1013
392ddcd212d7 Throwed in a bunch of semicolons
veltr
parents: 1010
diff changeset
  1203
    });
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1204
  };
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
  1205
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1206
  Source.prototype.getElement = function (_elId) {
916
ec6849bbbdcc Removed Namespacing before rewrite
veltr
parents: 915
diff changeset
  1207
    return this.directory.getElement(_elId);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1208
  };
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
  1209
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1210
  Source.prototype.get = function () {
998
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
  1211
    this.status = _SOURCE_STATUS_WAITING;
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
  1212
    this.handleCallbacks();
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1213
  };
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
  1214
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1215
  /* We defer the callbacks calls so they execute after the queue is cleared */
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1216
  Source.prototype.deferCallback = function (_callback) {
856
41c574c807d1 basic implementation of model: media, annotation type, annotation
veltr
parents: 854
diff changeset
  1217
    var _this = this;
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1218
    _.defer(function () {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1219
      _callback.call(_this);
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
  1220
    });
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1221
  };
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
  1222
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1223
  Source.prototype.handleCallbacks = function () {
998
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
  1224
    this.status = _SOURCE_STATUS_READY;
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
  1225
    while (this.callbackQueue.length) {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1226
      this.deferCallback(this.callbackQueue.splice(0, 1)[0]);
858
ad1ffe0c0955 save before switch
veltr
parents: 856
diff changeset
  1227
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1228
  };
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1229
  Source.prototype.onLoad = function (_callback) {
998
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
  1230
    if (this.status === _SOURCE_STATUS_READY) {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1231
      this.deferCallback(_callback);
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
  1232
    } else {
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1233
      this.callbackQueue.push(_callback);
870
2c025db10a10 Migrated playerWidget and started annotationsListWidget
veltr
parents: 868
diff changeset
  1234
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1235
  };
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
  1236
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1237
  Source.prototype.serialize = function () {
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
  1238
    return this.serializer.serialize(this);
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1239
  };
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1240
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1241
  Source.prototype.deSerialize = function (_data) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1242
    this.serializer.deSerialize(_data, this);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1243
  };
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1244
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1245
  Source.prototype.getAnnotations = function (_global) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1246
    _global = typeof _global !== "undefined" && _global;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1247
    return this.getList("annotation", _global);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1248
  };
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1249
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1250
  Source.prototype.getMedias = function (_global) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1251
    _global = typeof _global !== "undefined" && _global;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1252
    return this.getList("media", _global);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1253
  };
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1254
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1255
  Source.prototype.getTags = function (_global) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1256
    _global = typeof _global !== "undefined" && _global;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1257
    return this.getList("tag", _global);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1258
  };
860
7fd843e0dc4e Implemented serialize functions
veltr
parents: 858
diff changeset
  1259
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1260
  Source.prototype.getMashups = function (_global) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1261
    _global = typeof _global !== "undefined" && _global;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1262
    return this.getList("mashup", _global);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1263
  };
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1264
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1265
  Source.prototype.getAnnotationTypes = function (_global) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1266
    _global = typeof _global !== "undefined" && _global;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1267
    return this.getList("annotationType", _global);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1268
  };
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1269
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1270
  Source.prototype.getAnnotationsByTypeTitle = function (_title, _global) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1271
    _global = typeof _global !== "undefined" && _global;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1272
    var _res = new List(this.directory),
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1273
      _annTypes = this.getAnnotationTypes(_global).searchByTitle(_title);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1274
    _annTypes.forEach(function (_annType) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1275
      _res.addElements(_annType.getAnnotations(_global));
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1276
    });
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1277
    return _res;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1278
  };
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1279
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1280
  Source.prototype.getDuration = function () {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1281
    var _m = this.currentMedia;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1282
    if (typeof _m !== "undefined") {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1283
      return this.currentMedia.duration;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1284
    }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1285
  };
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
  1286
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1287
  Source.prototype.getCurrentMedia = function (_opts) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1288
    if (typeof this.currentMedia === "undefined") {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1289
      if (_opts.is_mashup) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1290
        var _mashups = this.getMashups();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1291
        if (_mashups.length) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1292
          this.currentMedia = _mashups[0];
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1293
        }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1294
      } else {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1295
        var _medias = this.getMedias();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1296
        if (_medias.length) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1297
          this.currentMedia = _medias[0];
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1298
        }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1299
      }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1300
    }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1301
    return this.currentMedia;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1302
  };
854
29f28a9f236f New Model first commit
veltr
parents:
diff changeset
  1303
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1304
  Source.prototype.merge = function (_source) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1305
    var _this = this;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1306
    _source.forEach(function (_value, _key) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1307
      _this.getList(_key).addElements(_value);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1308
    });
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1309
  };
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1310
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1311
  /* */
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1312
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1313
  var RemoteSource = (Model.RemoteSource = function (_config) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1314
    Source.call(this, _config);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1315
  });
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1316
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1317
  extendPrototype(RemoteSource, Source);
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
  1318
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1319
  RemoteSource.prototype.get = function () {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1320
    this.status = _SOURCE_STATUS_WAITING;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1321
    var _this = this,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1322
      urlparams = this.url_params || {},
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1323
      dataType = this.dataType || "json";
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1324
    urlparams.format = dataType;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1325
    jQuery.ajax({
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1326
      url: this.url,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1327
      dataType: dataType,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1328
      data: urlparams,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1329
      traditional: true,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1330
      success: function (_result) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1331
        _this.deSerialize(_result);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1332
        _this.handleCallbacks();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1333
      },
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1334
    });
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1335
  };
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1336
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1337
  /* */
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1338
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1339
  var Directory = (Model.Directory = function () {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1340
    this.remoteSources = {};
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1341
    this.elements = {};
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1342
  });
904
510ebab76fa3 Work on CreateAnnotation Widget
veltr
parents: 903
diff changeset
  1343
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1344
  Directory.prototype.remoteSource = function (_properties) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1345
    if (
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1346
      typeof _properties !== "object" ||
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1347
      typeof _properties.url === "undefined"
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1348
    ) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1349
      throw "Error : Directory.remoteSource(configuration): configuration.url is undefined";
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1350
    }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1351
    var _config = _({ directory: this }).extend(_properties);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1352
    _config.url_params = _config.url_params || {};
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1353
    var _hash = _config.url + "?" + jQuery.param(_config.url_params);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1354
    if (typeof this.remoteSources[_hash] === "undefined") {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1355
      this.remoteSources[_hash] = new RemoteSource(_config);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1356
    }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1357
    return this.remoteSources[_hash];
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1358
  };
900
7673d645a8e0 Metadataplayer Mashup
veltr
parents: 887
diff changeset
  1359
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1360
  Directory.prototype.newLocalSource = function (_properties) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1361
    var _config = _({ directory: this }).extend(_properties),
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1362
      _res = new Source(_config);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1363
    return _res;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1364
  };
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1365
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1366
  Directory.prototype.getElement = function (_id) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1367
    return this.elements[_id];
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1368
  };
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1369
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1370
  Directory.prototype.addElement = function (_element) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1371
    this.elements[_element.id] = _element;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1372
  };
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1373
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1374
  Directory.prototype.getGlobalList = function () {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1375
    var _res = new List(this);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1376
    _res.addIds(_(this.elements).keys());
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1377
    return _res;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1378
  };
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1379
  return Model;
998
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
  1380
};
864
5e76a06b961c Added Cinecast serializer, with imports management
veltr
parents: 860
diff changeset
  1381
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1068
diff changeset
  1382
export default Model;
988
eefd336335f9 Some improvements: Hashtags can be used, links are now clickable, ....
veltr
parents: 987
diff changeset
  1383
998
9521347ede1d Refactoring
veltr
parents: 988
diff changeset
  1384
/* END js */