src/js/widgets/createAnnotationWidget.js
author hamidouk
Thu, 02 Feb 2012 10:34:50 +0100
branchpopcorn-port
changeset 759 4dc3240f2c56
parent 722 ed12570ebd64
child 762 5497895a3ddb
permissions -rw-r--r--
send the correct username if the user is loggedin on the platform.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
     1
IriSP.createAnnotationWidget = function(Popcorn, config, Serializer) {
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
     2
  IriSP.Widget.call(this, Popcorn, config, Serializer);
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
     3
  this._hidden = true;
547
5b58a108086a adding support for keywords.
hamidouk
parents: 543
diff changeset
     4
  this.keywords = IriSP.widgetsDefaults["createAnnotationWidget"].keywords;
718
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
     5
  
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
     6
  this.polemic_mode = IriSP.widgetsDefaults["createAnnotationWidget"].polemic_mode;
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
     7
  this.polemics = IriSP.widgetsDefaults["createAnnotationWidget"].polemics;
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
     8
  
553
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
     9
  this.cinecast_version = IriSP.widgetsDefaults["createAnnotationWidget"].cinecast_version;
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    10
  this.ids = {}; /* a dictionnary linking buttons ids to keywords */
623
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
    11
  
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
    12
  /* variables to save the current position of the slicer */
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
    13
  if (this.cinecast_version) {
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
    14
    this.sliceLeft = 0;
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
    15
    this.sliceWidth = 0;
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
    16
  }
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    17
};
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    18
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    19
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    20
IriSP.createAnnotationWidget.prototype = new IriSP.Widget();
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    21
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    22
IriSP.createAnnotationWidget.prototype.clear = function() {
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    23
    this.selector.find(".Ldt-SaTitle").text("");
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    24
    this.selector.find(".Ldt-SaDescription").text("");
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    25
    this.selector.find(".Ldt-SaKeywordText").text("");
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    26
};
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    27
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    28
IriSP.createAnnotationWidget.prototype.draw = function() {
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    29
  var _this = this;
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    30
718
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    31
  var annotationMarkup = IriSP.templToHTML(IriSP.createAnnotationWidget_template, 
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    32
                                           {cinecast_version: this.cinecast_version, 
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    33
                                            polemic_mode: this.polemic_mode});
553
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    34
  
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    35
	this.selector.append(annotationMarkup);
548
96a188138c20 refactored the code a bit.
hamidouk
parents: 547
diff changeset
    36
  
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
    37
  if (!this.cinecast_version)
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
    38
    this.selector.hide();
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
    39
  
548
96a188138c20 refactored the code a bit.
hamidouk
parents: 547
diff changeset
    40
  for (var i = 0; i < this.keywords.length; i++) {
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    41
    var keyword = this.keywords[i];
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    42
    var id = IriSP.guid("button_");
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    43
    var templ = IriSP.templToHTML("<button id={{id}} class='Ldt-createAnnotation-absent-keyword'>{{keyword}}</button>", 
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    44
                                  {keyword: keyword, id: id});
548
96a188138c20 refactored the code a bit.
hamidouk
parents: 547
diff changeset
    45
                                  
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    46
    this.ids[keyword] = id; // save it for the function that handle textarea changes.
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    47
    
548
96a188138c20 refactored the code a bit.
hamidouk
parents: 547
diff changeset
    48
    this.selector.find(".Ldt-createAnnotation-keywords").append(templ);
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    49
    this.selector.find("#" + id).click(function(keyword) { return function() {
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    50
      var contents = _this.selector.find(".Ldt-createAnnotation-Description").val();
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    51
      if (contents.indexOf(keyword) != -1) {
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
    52
        var newVal = contents.replace(" " + keyword, "");
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
    53
        if (newVal == contents)
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
    54
          newVal = contents.replace(keyword, "");
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    55
      } else {
611
d931a7d12519 append a small space before keywords
hamidouk
parents: 608
diff changeset
    56
        if (contents === "")
d931a7d12519 append a small space before keywords
hamidouk
parents: 608
diff changeset
    57
          var newVal = keyword;
d931a7d12519 append a small space before keywords
hamidouk
parents: 608
diff changeset
    58
        else
d931a7d12519 append a small space before keywords
hamidouk
parents: 608
diff changeset
    59
          var newVal = contents + " " + keyword;      
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    60
      }
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    61
      
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    62
      _this.selector.find(".Ldt-createAnnotation-Description").val(newVal);
570
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
    63
      // we use a custom event because there's no simple way to test for a js
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
    64
      // change in a textfield.
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
    65
      _this.selector.find(".Ldt-createAnnotation-Description").trigger("js_mod");
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    66
      // also call our update function.
718
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    67
      //_this.handleTextChanges();
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    68
    }
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    69
   }(keyword));
548
96a188138c20 refactored the code a bit.
hamidouk
parents: 547
diff changeset
    70
  }
718
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    71
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    72
  // add the polemic buttons.
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    73
  if(this.polemic_mode)
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    74
    for (var polemic in this.polemics) {
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    75
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    76
      var classname = IriSP.templToHTML("Ldt-createAnnotation-polemic-{{classname}}", {classname : this.polemics[polemic]});
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    77
722
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
    78
      var templ = IriSP.templToHTML("<button class='{{classname}} Ldt-createAnnotation-polemic-button'>{{polemic}}</button>",
718
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    79
                  {classname: classname, polemic: polemic});
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    80
                  
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    81
      this.selector.find(".Ldt-createAnnotation-polemics").append(templ);
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    82
      this.selector.find("." + classname).click(function(polemic) { return function() {
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    83
          var contents = _this.selector.find(".Ldt-createAnnotation-Description").val();
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    84
          if (contents.indexOf(polemic) != -1) {
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    85
            var newVal = contents.replace(" " + polemic, "");
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    86
            if (newVal == contents)
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    87
              newVal = contents.replace(polemic, "");
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    88
          } else {
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    89
            if (contents === "")
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    90
              var newVal = polemic;
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    91
            else
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    92
              var newVal = contents + " " + polemic;      
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    93
          }
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    94
          
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    95
          _this.selector.find(".Ldt-createAnnotation-Description").val(newVal);
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    96
          // we use a custom event because there's no simple way to test for a js
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    97
          // change in a textfield.
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    98
          _this.selector.find(".Ldt-createAnnotation-Description").trigger("js_mod");
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    99
          // also call our update function.
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
   100
          _this.handleTextChanges();
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
   101
        }
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
   102
       }(polemic));
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
   103
      }    
548
96a188138c20 refactored the code a bit.
hamidouk
parents: 547
diff changeset
   104
  
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   105
  this.selector.find(".Ldt-createAnnotation-Description")
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   106
               .bind("propertychange keyup input paste", IriSP.wrap(this, this.handleTextChanges));
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   107
               
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   108
  /* the cinecast version of the player is supposed to pause when the user clicks on the button */
620
fe981f0aab71 automatically position and show the sliceWidget under the current chapter.
hamidouk
parents: 616
diff changeset
   109
  if (this.cinecast_version) {
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   110
    this.selector.find(".Ldt-createAnnotation-Description")
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   111
                 .one("propertychange keyup input paste js_mod", 
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   112
                 function() { if (!_this._Popcorn.media.paused) _this._Popcorn.pause() });
620
fe981f0aab71 automatically position and show the sliceWidget under the current chapter.
hamidouk
parents: 616
diff changeset
   113
  }
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   114
  /* the cinecast version expects the user to comment on a defined segment.
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   115
     As the widget is always shown, we need a way to update it's content as
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   116
     time passes. We do this like we did with the annotationsWidget : we schedule
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   117
     a .code start function which will be called at the right time.
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   118
  */
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   119
  if (this.cinecast_version) {
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   120
    var legal_ids;
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   121
    if (typeof(this._serializer.getChapitrage()) !== "undefined")
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   122
      legal_id = this._serializer.getChapitrage();
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   123
    else 
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   124
      legal_id = this._serializer.getNonTweetIds()[0];
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   125
    
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   126
    var annotations = this._serializer._data.annotations;
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   127
    var i;
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   128
  
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   129
    for (i in annotations) {     
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   130
      var annotation = annotations[i];
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   131
      if (typeof(annotation.meta) !== "undefined" && typeof(annotation.meta["id-ref"]) !== "undefined"
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   132
            && legal_id !== annotation.meta["id-ref"]) {
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   133
          continue;
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   134
      }
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   135
      
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   136
      code = {start: annotation.begin / 1000, end: annotation.end / 1000,
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   137
              onStart: function(annotation) { return function() {
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   138
                      if (typeof(annotation.content) !== "undefined")
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   139
                        _this.selector.find(".Ldt-createAnnotation-Title").html(annotation.content.title);
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   140
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   141
                      _this._currentAnnotation = annotation;
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   142
                      var beginTime = IriSP.msToTime(annotation.begin);
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   143
                      var endTime = IriSP.msToTime(annotation.end);
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   144
                      var timeTemplate = IriSP.templToHTML("- ({{begin}} - {{ end }})", {begin: beginTime, end: endTime });
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   145
                      _this.selector.find(".Ldt-createAnnotation-TimeFrame").html(timeTemplate);
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   146
              } }(annotation)
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   147
            };
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   148
      
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   149
      this._Popcorn.code(code);
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   150
    }
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   151
  }
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   152
  
553
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
   153
  this.selector.find(".Ldt-createAnnotation-submitButton").click(IriSP.wrap(this, this.handleButtonClick));
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   154
  
721
0c53eba54b11 added a "minimize" button.
hamidouk
parents: 719
diff changeset
   155
  if (!this.cinecast_version) {
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   156
    this._Popcorn.listen("IriSP.PlayerWidget.AnnotateButton.clicked", 
721
0c53eba54b11 added a "minimize" button.
hamidouk
parents: 719
diff changeset
   157
                          IriSP.wrap(this, this.handleAnnotateSignal));
0c53eba54b11 added a "minimize" button.
hamidouk
parents: 719
diff changeset
   158
    
0c53eba54b11 added a "minimize" button.
hamidouk
parents: 719
diff changeset
   159
    // handle clicks on the cancel button too.
0c53eba54b11 added a "minimize" button.
hamidouk
parents: 719
diff changeset
   160
    this.selector.find(".Ldt-createAnnotation-Minimize").click(IriSP.wrap(this, 
0c53eba54b11 added a "minimize" button.
hamidouk
parents: 719
diff changeset
   161
      function() {
0c53eba54b11 added a "minimize" button.
hamidouk
parents: 719
diff changeset
   162
        // we've got to simulate the pressing of the button because there's no
0c53eba54b11 added a "minimize" button.
hamidouk
parents: 719
diff changeset
   163
        // other way to minimize the widget and show the widgets that were hidden
0c53eba54b11 added a "minimize" button.
hamidouk
parents: 719
diff changeset
   164
        // same time
0c53eba54b11 added a "minimize" button.
hamidouk
parents: 719
diff changeset
   165
        this._Popcorn.trigger("IriSP.PlayerWidget.AnnotateButton.clicked");
0c53eba54b11 added a "minimize" button.
hamidouk
parents: 719
diff changeset
   166
      }
0c53eba54b11 added a "minimize" button.
hamidouk
parents: 719
diff changeset
   167
    ));
0c53eba54b11 added a "minimize" button.
hamidouk
parents: 719
diff changeset
   168
  }
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   169
};
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   170
620
fe981f0aab71 automatically position and show the sliceWidget under the current chapter.
hamidouk
parents: 616
diff changeset
   171
/** handles clicks on the annotate button. Works only for the non-cinecast version */
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   172
IriSP.createAnnotationWidget.prototype.handleAnnotateSignal = function() {
620
fe981f0aab71 automatically position and show the sliceWidget under the current chapter.
hamidouk
parents: 616
diff changeset
   173
  
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   174
  if (this._hidden == false) {
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   175
    this.selector.hide();
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   176
    this._hidden = true;
570
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   177
    
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   178
    // free the arrow.
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   179
    this._Popcorn.trigger("IriSP.ArrowWidget.releaseArrow");
620
fe981f0aab71 automatically position and show the sliceWidget under the current chapter.
hamidouk
parents: 616
diff changeset
   180
    this._Popcorn.trigger("IriSP.SliceWidget.hide");
fe981f0aab71 automatically position and show the sliceWidget under the current chapter.
hamidouk
parents: 616
diff changeset
   181
    
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   182
  } else {
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   183
    this.showStartScreen();
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   184
    this.selector.show();
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   185
    this._hidden = false;
620
fe981f0aab71 automatically position and show the sliceWidget under the current chapter.
hamidouk
parents: 616
diff changeset
   186
    var currentTime = this._Popcorn.currentTime();
563
4816e3425933 block the arrow when the user is annotating.
hamidouk
parents: 562
diff changeset
   187
    
4816e3425933 block the arrow when the user is annotating.
hamidouk
parents: 562
diff changeset
   188
    // block the arrow.
4816e3425933 block the arrow when the user is annotating.
hamidouk
parents: 562
diff changeset
   189
    this._Popcorn.trigger("IriSP.ArrowWidget.blockArrow");
623
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   190
    
620
fe981f0aab71 automatically position and show the sliceWidget under the current chapter.
hamidouk
parents: 616
diff changeset
   191
    var duration = +this._serializer.currentMedia().meta["dc:duration"];
623
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   192
        
620
fe981f0aab71 automatically position and show the sliceWidget under the current chapter.
hamidouk
parents: 616
diff changeset
   193
    var currentChapter = this._serializer.currentChapitre(currentTime);
623
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   194
    if (typeof(currentChapter) === "undefined") {
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   195
      var left = this.selector.width() / 2;
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   196
      var width = this.selector.width() / 10;
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   197
    } else {
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   198
      var left = (currentChapter.begin / duration) * this.selector.width();
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   199
      var width = (currentChapter.end / duration) * this.selector.width() - left;
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   200
    }
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   201
    
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   202
    this.sliceLeft = left;
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   203
    this.sliceWidth = width;
620
fe981f0aab71 automatically position and show the sliceWidget under the current chapter.
hamidouk
parents: 616
diff changeset
   204
    this._Popcorn.trigger("IriSP.SliceWidget.position", [left, width]);
623
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   205
    this._Popcorn.listen("IriSP.SliceWidget.zoneChange", IriSP.wrap(this, this.handleSliderChanges));
620
fe981f0aab71 automatically position and show the sliceWidget under the current chapter.
hamidouk
parents: 616
diff changeset
   206
    this._Popcorn.trigger("IriSP.SliceWidget.show");
722
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   207
    
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   208
    this.selector.find(".Ldt-createAnnotation-Title").html(currentChapter.content.title);
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   209
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   210
    this._currentcurrentChapter = currentChapter;
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   211
    var beginTime = IriSP.msToTime(currentChapter.begin);
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   212
    var endTime = IriSP.msToTime(currentChapter.end);
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   213
    var timeTemplate = IriSP.templToHTML("- ({{begin}} - {{ end }})", {begin: beginTime, end: endTime });
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   214
    this.selector.find(".Ldt-createAnnotation-TimeFrame").html(timeTemplate);
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   215
  }
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   216
};
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   217
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   218
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   219
/** watch for changes in the textfield and change the buttons accordingly */
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   220
IriSP.createAnnotationWidget.prototype.handleTextChanges = function(event) {
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   221
  var contents = this.selector.find(".Ldt-createAnnotation-Description").val();
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   222
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   223
  for(var keyword in this.ids) {
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   224
  
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   225
    var id = this.ids[keyword];
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   226
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   227
    if (contents.indexOf(keyword) != -1) {
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   228
      /* the word is present in the textarea but the button is not toggled */
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   229
      if (this.selector.find("#" + id).hasClass("Ldt-createAnnotation-absent-keyword"))
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   230
          this.selector.find("#" + id).removeClass("Ldt-createAnnotation-absent-keyword")
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   231
                                      .addClass("Ldt-createAnnotation-present-keyword");      
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   232
    } else {
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   233
      /* the word is absent from the textarea but the button is toggled */
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   234
      if (this.selector.find("#" + id).hasClass("Ldt-createAnnotation-present-keyword")) {
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   235
          this.selector.find("#" + id).removeClass("Ldt-createAnnotation-present-keyword")
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   236
                                      .addClass("Ldt-createAnnotation-absent-keyword");
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   237
      }
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   238
    }
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   239
  }
722
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   240
  
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   241
  if (this.polemic_mode) {
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   242
    /* Also go through the polemics to highlight the buttons */
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   243
    for (var polemic in this.polemics) {
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   244
      /* Add the active class to the button */
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   245
      var classname = "Ldt-createAnnotation-polemic-" + this.polemics[polemic];
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   246
      if (contents.indexOf(polemic) != -1) {        
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   247
        this.selector.find("." + classname).addClass("Ldt-createAnnotation-polemic-active");
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   248
      } else {
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   249
        if (this.selector.find("." + classname).addClass("Ldt-createAnnotation-polemic-active"))
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   250
          this.selector.find("." + classname).removeClass("Ldt-createAnnotation-polemic-active")
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   251
      }
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   252
    }
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   253
  }
553
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
   254
};
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
   255
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   256
IriSP.createAnnotationWidget.prototype.showStartScreen = function() {
627
13b9f14bf49a added a spinner displayed while submitting an annotation.
hamidouk
parents: 626
diff changeset
   257
  this.selector.find(".Ldt-createAnnotation-DoubleBorder").children().hide();
13b9f14bf49a added a spinner displayed while submitting an annotation.
hamidouk
parents: 626
diff changeset
   258
  this.selector.find(".Ldt-createAnnotation-startScreen").show();
13b9f14bf49a added a spinner displayed while submitting an annotation.
hamidouk
parents: 626
diff changeset
   259
  this.selector.find("Ldt-createAnnotation-Description").val("Type your annotation here.");  
13b9f14bf49a added a spinner displayed while submitting an annotation.
hamidouk
parents: 626
diff changeset
   260
};
13b9f14bf49a added a spinner displayed while submitting an annotation.
hamidouk
parents: 626
diff changeset
   261
13b9f14bf49a added a spinner displayed while submitting an annotation.
hamidouk
parents: 626
diff changeset
   262
IriSP.createAnnotationWidget.prototype.showWaitScreen = function() {
13b9f14bf49a added a spinner displayed while submitting an annotation.
hamidouk
parents: 626
diff changeset
   263
  this.selector.find(".Ldt-createAnnotation-DoubleBorder").children().hide();
13b9f14bf49a added a spinner displayed while submitting an annotation.
hamidouk
parents: 626
diff changeset
   264
  this.selector.find(".Ldt-createAnnotation-waitScreen").show();  
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   265
};
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   266
651
c43441822b1b use the new annotation shortening functions.
hamidouk
parents: 645
diff changeset
   267
IriSP.createAnnotationWidget.prototype.showEndScreen = function(annotation) {
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   268
  this.selector.find(".Ldt-createAnnotation-DoubleBorder").children().hide();
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   269
  
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   270
  if (this.cinecast_version) {
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   271
    this.selector.find(".Ldt-createAnnotation-Title").parent().show();      
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   272
  }
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   273
719
f2aa75a4d848 fixed link bug.
hamidouk
parents: 718
diff changeset
   274
  var url = document.location.href + "#id=" + annotation.id;
651
c43441822b1b use the new annotation shortening functions.
hamidouk
parents: 645
diff changeset
   275
  var twStatus = IriSP.mkTweetUrl(url);
c43441822b1b use the new annotation shortening functions.
hamidouk
parents: 645
diff changeset
   276
  var gpStatus = IriSP.mkGplusUrl(url);
c43441822b1b use the new annotation shortening functions.
hamidouk
parents: 645
diff changeset
   277
  var fbStatus = IriSP.mkFbUrl(url);
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   278
  
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   279
  this.selector.find(".Ldt-createAnnotation-endScreen-TweetLink").attr("href", twStatus);
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   280
  this.selector.find(".Ldt-createAnnotation-endScreen-FbLink").attr("href", fbStatus);
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   281
  this.selector.find(".Ldt-createAnnotation-endScreen-GplusLink").attr("href", gpStatus);
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   282
          
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   283
  this.selector.find(".Ldt-createAnnotation-endScreen").show();
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   284
};
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   285
553
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
   286
/** handle clicks on "send annotation" button */
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
   287
IriSP.createAnnotationWidget.prototype.handleButtonClick = function(event) {
597
93feb85bb07f correctly add an annotation.
hamidouk
parents: 594
diff changeset
   288
  var _this = this;
561
a10e7b6fdb08 display an error message when the user forget to enter text.
hamidouk
parents: 553
diff changeset
   289
  var textfield = this.selector.find(".Ldt-createAnnotation-Description");
a10e7b6fdb08 display an error message when the user forget to enter text.
hamidouk
parents: 553
diff changeset
   290
  var contents = textfield.val();
a10e7b6fdb08 display an error message when the user forget to enter text.
hamidouk
parents: 553
diff changeset
   291
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   292
  if (contents === "") {  
570
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   293
    if (this.selector.find(".Ldt-createAnnotation-errorMessage").length === 0) {
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   294
      this.selector.find(".Ldt-createAnnotation-Container")
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   295
                   .after(IriSP.templToHTML(IriSP.createAnnotation_errorMessage_template));
571
a471ef7efc0e fixes to the fixes.
hamidouk
parents: 570
diff changeset
   296
      textfield.css("background-color", "#d93c71");      
a471ef7efc0e fixes to the fixes.
hamidouk
parents: 570
diff changeset
   297
    } else {
a471ef7efc0e fixes to the fixes.
hamidouk
parents: 570
diff changeset
   298
      this.selector.find(".Ldt-createAnnotation-errorMessage").show();
a471ef7efc0e fixes to the fixes.
hamidouk
parents: 570
diff changeset
   299
    }
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   300
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   301
      textfield.one("js_mod propertychange keyup input paste", IriSP.wrap(this, function() {
570
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   302
                      var contents = textfield.val();
611
d931a7d12519 append a small space before keywords
hamidouk
parents: 608
diff changeset
   303
                      
570
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   304
                      if (contents !== "") {
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   305
                        this.selector.find(".Ldt-createAnnotation-errorMessage").hide();
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   306
                        textfield.css("background-color", "");
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   307
                      }
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   308
                   }));
561
a10e7b6fdb08 display an error message when the user forget to enter text.
hamidouk
parents: 553
diff changeset
   309
  } else {
627
13b9f14bf49a added a spinner displayed while submitting an annotation.
hamidouk
parents: 626
diff changeset
   310
    this.showWaitScreen();
594
96af41097260 WIP - adapting the widget to the new segments conventions.
hamidouk
parents: 575
diff changeset
   311
    
678
45385e19022a fixes and debugging to the cinecast_version.
hamidouk
parents: 651
diff changeset
   312
    this.sendLdtData(contents, function(annotation) {
683
00f37b85b2e2 hide the slicerwidget when done.
hamidouk
parents: 682
diff changeset
   313
                      if (_this.cinecast_version) {
00f37b85b2e2 hide the slicerwidget when done.
hamidouk
parents: 682
diff changeset
   314
                          if (_this._Popcorn.media.paused)
00f37b85b2e2 hide the slicerwidget when done.
hamidouk
parents: 682
diff changeset
   315
                            _this._Popcorn.play();
00f37b85b2e2 hide the slicerwidget when done.
hamidouk
parents: 682
diff changeset
   316
                      }
630
7c53857650b1 create a new contribution line in the json if it's not defined already.
hamidouk
parents: 627
diff changeset
   317
683
00f37b85b2e2 hide the slicerwidget when done.
hamidouk
parents: 682
diff changeset
   318
                      _this.showEndScreen(annotation);
00f37b85b2e2 hide the slicerwidget when done.
hamidouk
parents: 682
diff changeset
   319
                      if (_this.cinecast_version) {
00f37b85b2e2 hide the slicerwidget when done.
hamidouk
parents: 682
diff changeset
   320
                        window.setTimeout(IriSP.wrap(_this, function() { this.showStartScreen(); }), 5000);
00f37b85b2e2 hide the slicerwidget when done.
hamidouk
parents: 682
diff changeset
   321
                      }
00f37b85b2e2 hide the slicerwidget when done.
hamidouk
parents: 682
diff changeset
   322
                      
00f37b85b2e2 hide the slicerwidget when done.
hamidouk
parents: 682
diff changeset
   323
                      // hide the slicer widget
00f37b85b2e2 hide the slicerwidget when done.
hamidouk
parents: 682
diff changeset
   324
                      if (!_this.cinecast_version) {                      
00f37b85b2e2 hide the slicerwidget when done.
hamidouk
parents: 682
diff changeset
   325
                        _this._Popcorn.trigger("IriSP.SliceWidget.hide");
00f37b85b2e2 hide the slicerwidget when done.
hamidouk
parents: 682
diff changeset
   326
                      }           
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   327
                    });
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   328
  }
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   329
};
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   330
623
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   331
IriSP.createAnnotationWidget.prototype.handleSliderChanges = function(params) {
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   332
  this.sliceLeft = params[0];
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   333
  this.sliceWidth = params[1];
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   334
};
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   335
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   336
IriSP.createAnnotationWidget.prototype.sendLdtData = function(contents, callback) {
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   337
  var _this = this;
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   338
  var apiJson = {annotations : [{}], meta: {}};
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   339
  var annotation = apiJson["annotations"][0];
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   340
  
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   341
  annotation["media"] = this._serializer.currentMedia()["id"];
682
10a52271579d set the duration of the cinecast annotation as a function of the total length of
hamidouk
parents: 678
diff changeset
   342
  var duration_part = Math.round(this._serializer.currentMedia().meta["dc:duration"] / 20);
623
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   343
  
678
45385e19022a fixes and debugging to the cinecast_version.
hamidouk
parents: 651
diff changeset
   344
  if (this.cinecast_version) {   
682
10a52271579d set the duration of the cinecast annotation as a function of the total length of
hamidouk
parents: 678
diff changeset
   345
      annotation["begin"] = Math.round(this._Popcorn.currentTime() * 1000 - duration_part);
10a52271579d set the duration of the cinecast annotation as a function of the total length of
hamidouk
parents: 678
diff changeset
   346
      annotation["end"] = Math.round(this._Popcorn.currentTime() * 1000 + duration_part);
678
45385e19022a fixes and debugging to the cinecast_version.
hamidouk
parents: 651
diff changeset
   347
      if (annotation["begin"] < 0)
45385e19022a fixes and debugging to the cinecast_version.
hamidouk
parents: 651
diff changeset
   348
        annotation["begin"] = 0;
45385e19022a fixes and debugging to the cinecast_version.
hamidouk
parents: 651
diff changeset
   349
      
45385e19022a fixes and debugging to the cinecast_version.
hamidouk
parents: 651
diff changeset
   350
      if (annotation["end"] > this._serializer.currentMedia().meta["dc:duration"])
45385e19022a fixes and debugging to the cinecast_version.
hamidouk
parents: 651
diff changeset
   351
        annotation["end"] = this._serializer.currentMedia().meta["dc:duration"];
45385e19022a fixes and debugging to the cinecast_version.
hamidouk
parents: 651
diff changeset
   352
      
623
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   353
  } else {
643
3e522b6f7bd0 fixed a couple bugs.
hamidouk
parents: 630
diff changeset
   354
    var duration = +this._serializer.currentMedia().meta["dc:duration"];    
645
0c8ca890c9f1 fixed update bug.
hamidouk
parents: 643
diff changeset
   355
    annotation["begin"] = +((duration * (this.sliceLeft / 100)).toFixed(0));
0c8ca890c9f1 fixed update bug.
hamidouk
parents: 643
diff changeset
   356
    annotation["end"] = +((duration * ((this.sliceWidth + this.sliceLeft) / 100)).toFixed(0));
623
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   357
  }
645
0c8ca890c9f1 fixed update bug.
hamidouk
parents: 643
diff changeset
   358
  
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   359
  annotation["type"] = this._serializer.getContributions();
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   360
  if (typeof(annotation["type"]) === "undefined")
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   361
    annotation["type"] = "";
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   362
  
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   363
  annotation["type_title"] = "Contributions";
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   364
  annotation.content = {};
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   365
  annotation.content["data"] = contents;
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   366
  
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   367
  var meta = apiJson["meta"];
759
4dc3240f2c56 send the correct username if the user is loggedin on the platform.
hamidouk
parents: 722
diff changeset
   368
  if (!IriSP.null_or_undefined(IriSP.user) && !IriSP.null_or_undefined(IriSP.user.name))
4dc3240f2c56 send the correct username if the user is loggedin on the platform.
hamidouk
parents: 722
diff changeset
   369
    meta.creator = IriSP.user.name;    
4dc3240f2c56 send the correct username if the user is loggedin on the platform.
hamidouk
parents: 722
diff changeset
   370
  else 
4dc3240f2c56 send the correct username if the user is loggedin on the platform.
hamidouk
parents: 722
diff changeset
   371
    meta.creator = "An User";
4dc3240f2c56 send the correct username if the user is loggedin on the platform.
hamidouk
parents: 722
diff changeset
   372
  
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   373
  meta.created = Date().toString();
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   374
  
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   375
  annotation["tags"] = [];
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   376
  
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   377
  for (var i = 0; i < this.keywords.length; i++) {
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   378
    var keyword = this.keywords[i];
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   379
    if (contents.indexOf(keyword) != -1)
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   380
      annotation["tags"].push(keyword);
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   381
  }
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   382
  
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   383
  var jsonString = JSON.stringify(apiJson);
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   384
  var project_id = this._serializer._data.meta.id;
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   385
  
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   386
  var url = Mustache.to_html("{{platf_url}}/ldtplatform/api/ldt/projects/{{id}}.json",
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   387
                              {platf_url: IriSP.platform_url, id: project_id});
627
13b9f14bf49a added a spinner displayed while submitting an annotation.
hamidouk
parents: 626
diff changeset
   388
                          
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   389
  IriSP.jQuery.ajax({
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   390
      url: url,
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   391
      type: 'PUT',
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   392
      contentType: 'application/json',
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   393
      data: jsonString,               
626
c66bf61262fa round the ms
hamidouk
parents: 623
diff changeset
   394
      //dataType: 'json',
630
7c53857650b1 create a new contribution line in the json if it's not defined already.
hamidouk
parents: 627
diff changeset
   395
      success: IriSP.wrap(this, function(json, textStatus, XMLHttpRequest) {                   
7c53857650b1 create a new contribution line in the json if it's not defined already.
hamidouk
parents: 627
diff changeset
   396
                    /* add the annotation to the annotation and tell the world */
7c53857650b1 create a new contribution line in the json if it's not defined already.
hamidouk
parents: 627
diff changeset
   397
                    
7c53857650b1 create a new contribution line in the json if it's not defined already.
hamidouk
parents: 627
diff changeset
   398
                    /* if the media doesn't have a contributions line, we need to add one */
7c53857650b1 create a new contribution line in the json if it's not defined already.
hamidouk
parents: 627
diff changeset
   399
                    if (typeof(this._serializer.getContributions()) === "undefined") {
7c53857650b1 create a new contribution line in the json if it's not defined already.
hamidouk
parents: 627
diff changeset
   400
                      /* set up a basic view */
7c53857650b1 create a new contribution line in the json if it's not defined already.
hamidouk
parents: 627
diff changeset
   401
                      var tmp_view = {"dc:contributor": "perso", "dc:creator": "perso", "dc:title": "Contributions",
7c53857650b1 create a new contribution line in the json if it's not defined already.
hamidouk
parents: 627
diff changeset
   402
                                      "id": json.annotations[0].type}
651
c43441822b1b use the new annotation shortening functions.
hamidouk
parents: 645
diff changeset
   403
630
7c53857650b1 create a new contribution line in the json if it's not defined already.
hamidouk
parents: 627
diff changeset
   404
                      this._serializer._data["annotation-types"].push(tmp_view);
7c53857650b1 create a new contribution line in the json if it's not defined already.
hamidouk
parents: 627
diff changeset
   405
                    }
7c53857650b1 create a new contribution line in the json if it's not defined already.
hamidouk
parents: 627
diff changeset
   406
                    
597
93feb85bb07f correctly add an annotation.
hamidouk
parents: 594
diff changeset
   407
                    delete annotation.tags;
93feb85bb07f correctly add an annotation.
hamidouk
parents: 594
diff changeset
   408
                    annotation.content.description = annotation.content.data;
630
7c53857650b1 create a new contribution line in the json if it's not defined already.
hamidouk
parents: 627
diff changeset
   409
                    annotation.content.title = "";
597
93feb85bb07f correctly add an annotation.
hamidouk
parents: 594
diff changeset
   410
                    delete annotation.content.data;
93feb85bb07f correctly add an annotation.
hamidouk
parents: 594
diff changeset
   411
                    annotation.id = json.annotations[0].id;
630
7c53857650b1 create a new contribution line in the json if it's not defined already.
hamidouk
parents: 627
diff changeset
   412
606
13675511a01a fixed creation bug.
hamidouk
parents: 597
diff changeset
   413
                    annotation.meta = meta;
643
3e522b6f7bd0 fixed a couple bugs.
hamidouk
parents: 630
diff changeset
   414
                    annotation.meta["id-ref"] = json.annotations[0]["type"];
3e522b6f7bd0 fixed a couple bugs.
hamidouk
parents: 630
diff changeset
   415
                    
597
93feb85bb07f correctly add an annotation.
hamidouk
parents: 594
diff changeset
   416
                    // everything is shared so there's no need to propagate the change
93feb85bb07f correctly add an annotation.
hamidouk
parents: 594
diff changeset
   417
                    _this._serializer._data.annotations.push(annotation);
651
c43441822b1b use the new annotation shortening functions.
hamidouk
parents: 645
diff changeset
   418
 
643
3e522b6f7bd0 fixed a couple bugs.
hamidouk
parents: 630
diff changeset
   419
                    _this._Popcorn.trigger("IriSP.createAnnotationWidget.addedAnnotation", annotation);
651
c43441822b1b use the new annotation shortening functions.
hamidouk
parents: 645
diff changeset
   420
                    callback(annotation);
630
7c53857650b1 create a new contribution line in the json if it's not defined already.
hamidouk
parents: 627
diff changeset
   421
      }), 
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   422
      error: 
626
c66bf61262fa round the ms
hamidouk
parents: 623
diff changeset
   423
              function(jqXHR, textStatus, errorThrown) { 
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   424
                            console.log("an error occured while contacting " 
626
c66bf61262fa round the ms
hamidouk
parents: 623
diff changeset
   425
                            + url + " and sending " + jsonString + textStatus ); } });
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   426
};