src/js/widgets/createAnnotationWidget.js
author hamidouk
Mon, 13 Feb 2012 17:36:06 +0100
branchpopcorn-port
changeset 807 9f6c136ddc03
parent 799 5293a2c52fc6
parent 797 8407313c144f
child 814 9abad8fe5207
permissions -rw-r--r--
Merge with upstream
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;
762
5497895a3ddb if the platform has defined an user avatar, use it when submitting the annotation.
hamidouk
parents: 759
diff changeset
    30
  var template_params = {cinecast_version: this.cinecast_version, 
5497895a3ddb if the platform has defined an user avatar, use it when submitting the annotation.
hamidouk
parents: 759
diff changeset
    31
                         polemic_mode: this.polemic_mode};
5497895a3ddb if the platform has defined an user avatar, use it when submitting the annotation.
hamidouk
parents: 759
diff changeset
    32
                         
5497895a3ddb if the platform has defined an user avatar, use it when submitting the annotation.
hamidouk
parents: 759
diff changeset
    33
  if (!IriSP.null_or_undefined(IriSP.user) && !IriSP.null_or_undefined(IriSP.user.avatar))
764
628ae65defa7 fixed the option to specify an user.
hamidouk
parents: 762
diff changeset
    34
    template_params["user_avatar"] = IriSP.user.avatar;
762
5497895a3ddb if the platform has defined an user avatar, use it when submitting the annotation.
hamidouk
parents: 759
diff changeset
    35
  
718
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    36
  var annotationMarkup = IriSP.templToHTML(IriSP.createAnnotationWidget_template, 
762
5497895a3ddb if the platform has defined an user avatar, use it when submitting the annotation.
hamidouk
parents: 759
diff changeset
    37
                                           template_params);
553
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    38
  
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    39
	this.selector.append(annotationMarkup);
548
96a188138c20 refactored the code a bit.
hamidouk
parents: 547
diff changeset
    40
  
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
    41
  if (!this.cinecast_version)
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
    42
    this.selector.hide();
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
    43
  
773
b284013327fd remove debugger call.
hamidouk
parents: 769
diff changeset
    44
  // add the keywords.
548
96a188138c20 refactored the code a bit.
hamidouk
parents: 547
diff changeset
    45
  for (var i = 0; i < this.keywords.length; i++) {
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    46
    var keyword = this.keywords[i];
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    47
    var id = IriSP.guid("button_");
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    48
    var templ = IriSP.templToHTML("<button id={{id}} class='Ldt-createAnnotation-absent-keyword'>{{keyword}}</button>", 
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    49
                                  {keyword: keyword, id: id});
548
96a188138c20 refactored the code a bit.
hamidouk
parents: 547
diff changeset
    50
                                  
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    51
    this.ids[keyword] = id; // save it for the function that handle textarea changes.
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    52
    
548
96a188138c20 refactored the code a bit.
hamidouk
parents: 547
diff changeset
    53
    this.selector.find(".Ldt-createAnnotation-keywords").append(templ);
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    54
    this.selector.find("#" + id).click(function(keyword) { return function() {
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    55
      var contents = _this.selector.find(".Ldt-createAnnotation-Description").val();
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    56
      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
    57
        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
    58
        if (newVal == contents)
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
    59
          newVal = contents.replace(keyword, "");
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    60
      } else {
611
d931a7d12519 append a small space before keywords
hamidouk
parents: 608
diff changeset
    61
        if (contents === "")
d931a7d12519 append a small space before keywords
hamidouk
parents: 608
diff changeset
    62
          var newVal = keyword;
d931a7d12519 append a small space before keywords
hamidouk
parents: 608
diff changeset
    63
        else
d931a7d12519 append a small space before keywords
hamidouk
parents: 608
diff changeset
    64
          var newVal = contents + " " + keyword;      
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    65
      }
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    66
      
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    67
      _this.selector.find(".Ldt-createAnnotation-Description").val(newVal);
570
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
    68
      // 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
    69
      // change in a textfield.
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
    70
      _this.selector.find(".Ldt-createAnnotation-Description").trigger("js_mod");
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    71
      // also call our update function.
718
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    72
      //_this.handleTextChanges();
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    73
    }
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    74
   }(keyword));
548
96a188138c20 refactored the code a bit.
hamidouk
parents: 547
diff changeset
    75
  }
718
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    76
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    77
  // add the polemic buttons.
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    78
  if(this.polemic_mode)
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    79
    for (var polemic in this.polemics) {
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
      var classname = IriSP.templToHTML("Ldt-createAnnotation-polemic-{{classname}}", {classname : this.polemics[polemic]});
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    82
722
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
    83
      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
    84
                  {classname: classname, polemic: polemic});
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    85
                  
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    86
      this.selector.find(".Ldt-createAnnotation-polemics").append(templ);
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    87
      this.selector.find("." + classname).click(function(polemic) { return function() {
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    88
          var contents = _this.selector.find(".Ldt-createAnnotation-Description").val();
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    89
          if (contents.indexOf(polemic) != -1) {
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    90
            var newVal = contents.replace(" " + polemic, "");
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    91
            if (newVal == contents)
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    92
              newVal = contents.replace(polemic, "");
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    93
          } else {
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    94
            if (contents === "")
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    95
              var newVal = polemic;
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    96
            else
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    97
              var newVal = contents + " " + polemic;      
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    98
          }
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
    99
          
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
   100
          _this.selector.find(".Ldt-createAnnotation-Description").val(newVal);
799
5293a2c52fc6 fixed an odd regression.
hamidouk
parents: 779
diff changeset
   101
          
718
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
   102
          // also call our update function.
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
   103
          _this.handleTextChanges();
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
   104
        }
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
   105
       }(polemic));
c6660cd7bfb3 added buttons for adding polemic annotations.
hamidouk
parents: 683
diff changeset
   106
      }    
548
96a188138c20 refactored the code a bit.
hamidouk
parents: 547
diff changeset
   107
  
799
5293a2c52fc6 fixed an odd regression.
hamidouk
parents: 779
diff changeset
   108
  // js_mod is a custom event because there's no simple way to test for a js
5293a2c52fc6 fixed an odd regression.
hamidouk
parents: 779
diff changeset
   109
  // change in a textfield.                    
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   110
  this.selector.find(".Ldt-createAnnotation-Description")
799
5293a2c52fc6 fixed an odd regression.
hamidouk
parents: 779
diff changeset
   111
               .bind("propertychange keyup input paste js_mod", 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
   112
               
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   113
  /* 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
   114
  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
   115
    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
   116
                 .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
   117
                 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
   118
  }
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   119
  /* 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
   120
     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
   121
     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
   122
     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
   123
  */
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   124
  if (this.cinecast_version) {
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   125
    var legal_ids;
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   126
    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
   127
      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
   128
    else 
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   129
      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
   130
    
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   131
    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
   132
    var i;
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   133
  
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   134
    for (i in annotations) {     
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   135
      var annotation = annotations[i];
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   136
      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
   137
            && 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
   138
          continue;
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   139
      }
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
      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
   142
              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
   143
                      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
   144
                        _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
   145
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   146
                      _this._currentAnnotation = annotation;
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   147
                      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
   148
                      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
   149
                      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
   150
                      _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
   151
              } }(annotation)
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   152
            };
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   153
      
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   154
      this._Popcorn.code(code);
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   155
    }
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   156
  }
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   157
  
553
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
   158
  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
   159
  
721
0c53eba54b11 added a "minimize" button.
hamidouk
parents: 719
diff changeset
   160
  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
   161
    this._Popcorn.listen("IriSP.PlayerWidget.AnnotateButton.clicked", 
721
0c53eba54b11 added a "minimize" button.
hamidouk
parents: 719
diff changeset
   162
                          IriSP.wrap(this, this.handleAnnotateSignal));
0c53eba54b11 added a "minimize" button.
hamidouk
parents: 719
diff changeset
   163
    
0c53eba54b11 added a "minimize" button.
hamidouk
parents: 719
diff changeset
   164
    // handle clicks on the cancel button too.
0c53eba54b11 added a "minimize" button.
hamidouk
parents: 719
diff changeset
   165
    this.selector.find(".Ldt-createAnnotation-Minimize").click(IriSP.wrap(this, 
0c53eba54b11 added a "minimize" button.
hamidouk
parents: 719
diff changeset
   166
      function() {
0c53eba54b11 added a "minimize" button.
hamidouk
parents: 719
diff changeset
   167
        // we've got to simulate the pressing of the button because there's no
0c53eba54b11 added a "minimize" button.
hamidouk
parents: 719
diff changeset
   168
        // other way to minimize the widget and show the widgets that were hidden
0c53eba54b11 added a "minimize" button.
hamidouk
parents: 719
diff changeset
   169
        // same time
0c53eba54b11 added a "minimize" button.
hamidouk
parents: 719
diff changeset
   170
        this._Popcorn.trigger("IriSP.PlayerWidget.AnnotateButton.clicked");
0c53eba54b11 added a "minimize" button.
hamidouk
parents: 719
diff changeset
   171
      }
0c53eba54b11 added a "minimize" button.
hamidouk
parents: 719
diff changeset
   172
    ));
0c53eba54b11 added a "minimize" button.
hamidouk
parents: 719
diff changeset
   173
  }
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   174
};
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   175
620
fe981f0aab71 automatically position and show the sliceWidget under the current chapter.
hamidouk
parents: 616
diff changeset
   176
/** 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
   177
IriSP.createAnnotationWidget.prototype.handleAnnotateSignal = function() {
620
fe981f0aab71 automatically position and show the sliceWidget under the current chapter.
hamidouk
parents: 616
diff changeset
   178
  
778
8329f476d852 clicking on the annotate button when the annotation creation widget is opened
hamidouk
parents: 776
diff changeset
   179
  if (this._hidden == false && this._state == 'startScreen') {
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   180
    this.selector.hide();
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   181
    this._hidden = true;
570
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   182
    
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   183
    // free the arrow.
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   184
    this._Popcorn.trigger("IriSP.ArrowWidget.releaseArrow");
620
fe981f0aab71 automatically position and show the sliceWidget under the current chapter.
hamidouk
parents: 616
diff changeset
   185
    this._Popcorn.trigger("IriSP.SliceWidget.hide");
778
8329f476d852 clicking on the annotate button when the annotation creation widget is opened
hamidouk
parents: 776
diff changeset
   186
    this._Popcorn.trigger("IriSP.AnnotationsWidget.show");
620
fe981f0aab71 automatically position and show the sliceWidget under the current chapter.
hamidouk
parents: 616
diff changeset
   187
    
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   188
  } else {
778
8329f476d852 clicking on the annotate button when the annotation creation widget is opened
hamidouk
parents: 776
diff changeset
   189
    this._Popcorn.trigger("IriSP.AnnotationsWidget.hide");
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   190
    this.showStartScreen();
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   191
    this.selector.show();
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   192
    this._hidden = false;
620
fe981f0aab71 automatically position and show the sliceWidget under the current chapter.
hamidouk
parents: 616
diff changeset
   193
    var currentTime = this._Popcorn.currentTime();
563
4816e3425933 block the arrow when the user is annotating.
hamidouk
parents: 562
diff changeset
   194
    
4816e3425933 block the arrow when the user is annotating.
hamidouk
parents: 562
diff changeset
   195
    // block the arrow.
4816e3425933 block the arrow when the user is annotating.
hamidouk
parents: 562
diff changeset
   196
    this._Popcorn.trigger("IriSP.ArrowWidget.blockArrow");
623
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   197
    
620
fe981f0aab71 automatically position and show the sliceWidget under the current chapter.
hamidouk
parents: 616
diff changeset
   198
    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
   199
        
620
fe981f0aab71 automatically position and show the sliceWidget under the current chapter.
hamidouk
parents: 616
diff changeset
   200
    var currentChapter = this._serializer.currentChapitre(currentTime);
779
52be94ec8e1c fixed default slicerWidget position bug. check boundaries of created annotations.
hamidouk
parents: 778
diff changeset
   201
52be94ec8e1c fixed default slicerWidget position bug. check boundaries of created annotations.
hamidouk
parents: 778
diff changeset
   202
    if (IriSP.null_or_undefined(currentChapter)) {      
623
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   203
      var left = this.selector.width() / 2;
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   204
      var width = this.selector.width() / 10;
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   205
    } else {
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   206
      var left = (currentChapter.begin / duration) * this.selector.width();
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   207
      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
   208
    }
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   209
    
779
52be94ec8e1c fixed default slicerWidget position bug. check boundaries of created annotations.
hamidouk
parents: 778
diff changeset
   210
    // slider position and length is kept in percents.
52be94ec8e1c fixed default slicerWidget position bug. check boundaries of created annotations.
hamidouk
parents: 778
diff changeset
   211
    this.sliceLeft = (left / this.selector.width()) * 100;
52be94ec8e1c fixed default slicerWidget position bug. check boundaries of created annotations.
hamidouk
parents: 778
diff changeset
   212
    this.sliceWidth = (width / this.selector.width()) * 100;
52be94ec8e1c fixed default slicerWidget position bug. check boundaries of created annotations.
hamidouk
parents: 778
diff changeset
   213
    
620
fe981f0aab71 automatically position and show the sliceWidget under the current chapter.
hamidouk
parents: 616
diff changeset
   214
    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
   215
    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
   216
    this._Popcorn.trigger("IriSP.SliceWidget.show");
722
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   217
    
776
f3c758ef9952 moar checking.
hamidouk
parents: 773
diff changeset
   218
    if (!IriSP.null_or_undefined(currentChapter)) {
f3c758ef9952 moar checking.
hamidouk
parents: 773
diff changeset
   219
      this.selector.find(".Ldt-createAnnotation-Title").html(currentChapter.content.title);
722
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   220
776
f3c758ef9952 moar checking.
hamidouk
parents: 773
diff changeset
   221
      this._currentcurrentChapter = currentChapter;
f3c758ef9952 moar checking.
hamidouk
parents: 773
diff changeset
   222
      var beginTime = IriSP.msToTime(currentChapter.begin);
f3c758ef9952 moar checking.
hamidouk
parents: 773
diff changeset
   223
      var endTime = IriSP.msToTime(currentChapter.end);
f3c758ef9952 moar checking.
hamidouk
parents: 773
diff changeset
   224
      var timeTemplate = IriSP.templToHTML("- ({{begin}} - {{ end }})", {begin: beginTime, end: endTime });
f3c758ef9952 moar checking.
hamidouk
parents: 773
diff changeset
   225
      this.selector.find(".Ldt-createAnnotation-TimeFrame").html(timeTemplate);
f3c758ef9952 moar checking.
hamidouk
parents: 773
diff changeset
   226
    }
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   227
  }
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   228
};
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   229
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   230
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   231
/** watch for changes in the textfield and change the buttons accordingly */
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   232
IriSP.createAnnotationWidget.prototype.handleTextChanges = function(event) {
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   233
  var contents = this.selector.find(".Ldt-createAnnotation-Description").val();
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   234
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   235
  for(var keyword in this.ids) {
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   236
  
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   237
    var id = this.ids[keyword];
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   238
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   239
    if (contents.indexOf(keyword) != -1) {
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   240
      /* the word is present in the textarea but the button is not toggled */
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   241
      if (this.selector.find("#" + id).hasClass("Ldt-createAnnotation-absent-keyword"))
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   242
          this.selector.find("#" + id).removeClass("Ldt-createAnnotation-absent-keyword")
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   243
                                      .addClass("Ldt-createAnnotation-present-keyword");      
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   244
    } else {
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   245
      /* the word is absent from the textarea but the button is toggled */
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   246
      if (this.selector.find("#" + id).hasClass("Ldt-createAnnotation-present-keyword")) {
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   247
          this.selector.find("#" + id).removeClass("Ldt-createAnnotation-present-keyword")
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   248
                                      .addClass("Ldt-createAnnotation-absent-keyword");
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   249
      }
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   250
    }
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   251
  }
722
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
  if (this.polemic_mode) {
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   254
    /* Also go through the polemics to highlight the buttons */
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   255
    for (var polemic in this.polemics) {
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   256
      /* Add the active class to the button */
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   257
      var classname = "Ldt-createAnnotation-polemic-" + this.polemics[polemic];
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   258
      if (contents.indexOf(polemic) != -1) {        
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   259
        this.selector.find("." + classname).addClass("Ldt-createAnnotation-polemic-active");
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   260
      } else {
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   261
        if (this.selector.find("." + classname).addClass("Ldt-createAnnotation-polemic-active"))
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   262
          this.selector.find("." + classname).removeClass("Ldt-createAnnotation-polemic-active")
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   263
      }
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   264
    }
ed12570ebd64 added support for the polemic tweet buttons.
hamidouk
parents: 721
diff changeset
   265
  }
553
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
   266
};
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
   267
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   268
IriSP.createAnnotationWidget.prototype.showStartScreen = function() {
627
13b9f14bf49a added a spinner displayed while submitting an annotation.
hamidouk
parents: 626
diff changeset
   269
  this.selector.find(".Ldt-createAnnotation-DoubleBorder").children().hide();
13b9f14bf49a added a spinner displayed while submitting an annotation.
hamidouk
parents: 626
diff changeset
   270
  this.selector.find(".Ldt-createAnnotation-startScreen").show();
778
8329f476d852 clicking on the annotate button when the annotation creation widget is opened
hamidouk
parents: 776
diff changeset
   271
  this.selector.find(".Ldt-createAnnotation-Description").val("Type your annotation here.");
8329f476d852 clicking on the annotate button when the annotation creation widget is opened
hamidouk
parents: 776
diff changeset
   272
8329f476d852 clicking on the annotate button when the annotation creation widget is opened
hamidouk
parents: 776
diff changeset
   273
  this._state = "startScreen";
627
13b9f14bf49a added a spinner displayed while submitting an annotation.
hamidouk
parents: 626
diff changeset
   274
};
13b9f14bf49a added a spinner displayed while submitting an annotation.
hamidouk
parents: 626
diff changeset
   275
13b9f14bf49a added a spinner displayed while submitting an annotation.
hamidouk
parents: 626
diff changeset
   276
IriSP.createAnnotationWidget.prototype.showWaitScreen = function() {
13b9f14bf49a added a spinner displayed while submitting an annotation.
hamidouk
parents: 626
diff changeset
   277
  this.selector.find(".Ldt-createAnnotation-DoubleBorder").children().hide();
778
8329f476d852 clicking on the annotate button when the annotation creation widget is opened
hamidouk
parents: 776
diff changeset
   278
  this.selector.find(".Ldt-createAnnotation-waitScreen").show();
8329f476d852 clicking on the annotate button when the annotation creation widget is opened
hamidouk
parents: 776
diff changeset
   279
  this._state = "waitScreen";
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   280
};
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   281
769
70464200b601 added an error screen.
hamidouk
parents: 764
diff changeset
   282
IriSP.createAnnotationWidget.prototype.showErrorScreen = function() {
70464200b601 added an error screen.
hamidouk
parents: 764
diff changeset
   283
  this.selector.find(".Ldt-createAnnotation-DoubleBorder").children().hide();
778
8329f476d852 clicking on the annotate button when the annotation creation widget is opened
hamidouk
parents: 776
diff changeset
   284
  this.selector.find(".Ldt-createAnnotation-errorScreen").show();
8329f476d852 clicking on the annotate button when the annotation creation widget is opened
hamidouk
parents: 776
diff changeset
   285
  this._state = "errorScreen";
769
70464200b601 added an error screen.
hamidouk
parents: 764
diff changeset
   286
};
70464200b601 added an error screen.
hamidouk
parents: 764
diff changeset
   287
70464200b601 added an error screen.
hamidouk
parents: 764
diff changeset
   288
/** update show the final screen with links to share the created annotation */
651
c43441822b1b use the new annotation shortening functions.
hamidouk
parents: 645
diff changeset
   289
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
   290
  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
   291
  
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   292
  if (this.cinecast_version) {
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   293
    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
   294
  }
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   295
719
f2aa75a4d848 fixed link bug.
hamidouk
parents: 718
diff changeset
   296
  var url = document.location.href + "#id=" + annotation.id;
651
c43441822b1b use the new annotation shortening functions.
hamidouk
parents: 645
diff changeset
   297
  var twStatus = IriSP.mkTweetUrl(url);
c43441822b1b use the new annotation shortening functions.
hamidouk
parents: 645
diff changeset
   298
  var gpStatus = IriSP.mkGplusUrl(url);
c43441822b1b use the new annotation shortening functions.
hamidouk
parents: 645
diff changeset
   299
  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
   300
  
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   301
  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
   302
  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
   303
  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
   304
          
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   305
  this.selector.find(".Ldt-createAnnotation-endScreen").show();
778
8329f476d852 clicking on the annotate button when the annotation creation widget is opened
hamidouk
parents: 776
diff changeset
   306
  this._state = "endScreen";
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   307
};
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   308
553
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
   309
/** handle clicks on "send annotation" button */
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
   310
IriSP.createAnnotationWidget.prototype.handleButtonClick = function(event) {
597
93feb85bb07f correctly add an annotation.
hamidouk
parents: 594
diff changeset
   311
  var _this = this;
561
a10e7b6fdb08 display an error message when the user forget to enter text.
hamidouk
parents: 553
diff changeset
   312
  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
   313
  var contents = textfield.val();
a10e7b6fdb08 display an error message when the user forget to enter text.
hamidouk
parents: 553
diff changeset
   314
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   315
  if (contents === "") {  
570
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   316
    if (this.selector.find(".Ldt-createAnnotation-errorMessage").length === 0) {
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   317
      this.selector.find(".Ldt-createAnnotation-Container")
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   318
                   .after(IriSP.templToHTML(IriSP.createAnnotation_errorMessage_template));
571
a471ef7efc0e fixes to the fixes.
hamidouk
parents: 570
diff changeset
   319
      textfield.css("background-color", "#d93c71");      
769
70464200b601 added an error screen.
hamidouk
parents: 764
diff changeset
   320
    } else {      
571
a471ef7efc0e fixes to the fixes.
hamidouk
parents: 570
diff changeset
   321
      this.selector.find(".Ldt-createAnnotation-errorMessage").show();
a471ef7efc0e fixes to the fixes.
hamidouk
parents: 570
diff changeset
   322
    }
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   323
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   324
      textfield.one("js_mod propertychange keyup input paste", IriSP.wrap(this, function() {
570
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   325
                      var contents = textfield.val();
611
d931a7d12519 append a small space before keywords
hamidouk
parents: 608
diff changeset
   326
                      
570
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   327
                      if (contents !== "") {
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   328
                        this.selector.find(".Ldt-createAnnotation-errorMessage").hide();
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   329
                        textfield.css("background-color", "");
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   330
                      }
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   331
                   }));
561
a10e7b6fdb08 display an error message when the user forget to enter text.
hamidouk
parents: 553
diff changeset
   332
  } else {
627
13b9f14bf49a added a spinner displayed while submitting an annotation.
hamidouk
parents: 626
diff changeset
   333
    this.showWaitScreen();
594
96af41097260 WIP - adapting the widget to the new segments conventions.
hamidouk
parents: 575
diff changeset
   334
    
678
45385e19022a fixes and debugging to the cinecast_version.
hamidouk
parents: 651
diff changeset
   335
    this.sendLdtData(contents, function(annotation) {
683
00f37b85b2e2 hide the slicerwidget when done.
hamidouk
parents: 682
diff changeset
   336
                      if (_this.cinecast_version) {
00f37b85b2e2 hide the slicerwidget when done.
hamidouk
parents: 682
diff changeset
   337
                          if (_this._Popcorn.media.paused)
00f37b85b2e2 hide the slicerwidget when done.
hamidouk
parents: 682
diff changeset
   338
                            _this._Popcorn.play();
00f37b85b2e2 hide the slicerwidget when done.
hamidouk
parents: 682
diff changeset
   339
                      }
630
7c53857650b1 create a new contribution line in the json if it's not defined already.
hamidouk
parents: 627
diff changeset
   340
778
8329f476d852 clicking on the annotate button when the annotation creation widget is opened
hamidouk
parents: 776
diff changeset
   341
                      if (_this._state == "waitScreen") {
8329f476d852 clicking on the annotate button when the annotation creation widget is opened
hamidouk
parents: 776
diff changeset
   342
                        _this.showEndScreen(annotation);
8329f476d852 clicking on the annotate button when the annotation creation widget is opened
hamidouk
parents: 776
diff changeset
   343
                        if (_this.cinecast_version) {
8329f476d852 clicking on the annotate button when the annotation creation widget is opened
hamidouk
parents: 776
diff changeset
   344
                          window.setTimeout(IriSP.wrap(_this, function() { this.showStartScreen(); }), 5000);
8329f476d852 clicking on the annotate button when the annotation creation widget is opened
hamidouk
parents: 776
diff changeset
   345
                        }
683
00f37b85b2e2 hide the slicerwidget when done.
hamidouk
parents: 682
diff changeset
   346
                      }
00f37b85b2e2 hide the slicerwidget when done.
hamidouk
parents: 682
diff changeset
   347
                      // hide the slicer widget
00f37b85b2e2 hide the slicerwidget when done.
hamidouk
parents: 682
diff changeset
   348
                      if (!_this.cinecast_version) {                      
00f37b85b2e2 hide the slicerwidget when done.
hamidouk
parents: 682
diff changeset
   349
                        _this._Popcorn.trigger("IriSP.SliceWidget.hide");
00f37b85b2e2 hide the slicerwidget when done.
hamidouk
parents: 682
diff changeset
   350
                      }           
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   351
                    });
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   352
  }
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   353
};
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   354
623
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   355
IriSP.createAnnotationWidget.prototype.handleSliderChanges = function(params) {
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   356
  this.sliceLeft = params[0];
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   357
  this.sliceWidth = params[1];
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   358
};
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   359
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   360
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
   361
  var _this = this;
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   362
  var apiJson = {annotations : [{}], meta: {}};
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   363
  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
   364
  
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   365
  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
   366
  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
   367
  
678
45385e19022a fixes and debugging to the cinecast_version.
hamidouk
parents: 651
diff changeset
   368
  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
   369
      annotation["begin"] = Math.round(this._Popcorn.currentTime() * 1000 - duration_part);
779
52be94ec8e1c fixed default slicerWidget position bug. check boundaries of created annotations.
hamidouk
parents: 778
diff changeset
   370
      annotation["end"] = Math.round(this._Popcorn.currentTime() * 1000 + duration_part);      
623
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   371
  } else {
643
3e522b6f7bd0 fixed a couple bugs.
hamidouk
parents: 630
diff changeset
   372
    var duration = +this._serializer.currentMedia().meta["dc:duration"];    
645
0c8ca890c9f1 fixed update bug.
hamidouk
parents: 643
diff changeset
   373
    annotation["begin"] = +((duration * (this.sliceLeft / 100)).toFixed(0));
0c8ca890c9f1 fixed update bug.
hamidouk
parents: 643
diff changeset
   374
    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
   375
  }
779
52be94ec8e1c fixed default slicerWidget position bug. check boundaries of created annotations.
hamidouk
parents: 778
diff changeset
   376
52be94ec8e1c fixed default slicerWidget position bug. check boundaries of created annotations.
hamidouk
parents: 778
diff changeset
   377
  // boundary checks
52be94ec8e1c fixed default slicerWidget position bug. check boundaries of created annotations.
hamidouk
parents: 778
diff changeset
   378
  if (annotation["begin"] < 0)
52be94ec8e1c fixed default slicerWidget position bug. check boundaries of created annotations.
hamidouk
parents: 778
diff changeset
   379
        annotation["begin"] = 0;
52be94ec8e1c fixed default slicerWidget position bug. check boundaries of created annotations.
hamidouk
parents: 778
diff changeset
   380
  
52be94ec8e1c fixed default slicerWidget position bug. check boundaries of created annotations.
hamidouk
parents: 778
diff changeset
   381
  if (annotation["end"] > this._serializer.currentMedia().meta["dc:duration"])
52be94ec8e1c fixed default slicerWidget position bug. check boundaries of created annotations.
hamidouk
parents: 778
diff changeset
   382
    annotation["end"] = this._serializer.currentMedia().meta["dc:duration"];
52be94ec8e1c fixed default slicerWidget position bug. check boundaries of created annotations.
hamidouk
parents: 778
diff changeset
   383
      
645
0c8ca890c9f1 fixed update bug.
hamidouk
parents: 643
diff changeset
   384
  
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   385
  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
   386
  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
   387
    annotation["type"] = "";
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   388
  
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   389
  annotation["type_title"] = "Contributions";
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   390
  annotation.content = {};
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   391
  annotation.content["data"] = contents;
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   392
  
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   393
  var meta = apiJson["meta"];
759
4dc3240f2c56 send the correct username if the user is loggedin on the platform.
hamidouk
parents: 722
diff changeset
   394
  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
   395
    meta.creator = IriSP.user.name;    
4dc3240f2c56 send the correct username if the user is loggedin on the platform.
hamidouk
parents: 722
diff changeset
   396
  else 
4dc3240f2c56 send the correct username if the user is loggedin on the platform.
hamidouk
parents: 722
diff changeset
   397
    meta.creator = "An User";
4dc3240f2c56 send the correct username if the user is loggedin on the platform.
hamidouk
parents: 722
diff changeset
   398
  
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   399
  meta.created = Date().toString();
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   400
  
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   401
  annotation["tags"] = [];
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   402
  
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   403
  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
   404
    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
   405
    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
   406
      annotation["tags"].push(keyword);
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   407
  }
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   408
  
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   409
  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
   410
  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
   411
  
797
8407313c144f correct url for annotations + null data on serializer
ymh <ymh.work@gmail.com>
parents: 779
diff changeset
   412
  //TODO: extract magic url
8407313c144f correct url for annotations + null data on serializer
ymh <ymh.work@gmail.com>
parents: 779
diff changeset
   413
  var url = Mustache.to_html("{{platf_url}}/ldtplatform/api/ldt/annotations/{{id}}.json",
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   414
                              {platf_url: IriSP.platform_url, id: project_id});
627
13b9f14bf49a added a spinner displayed while submitting an annotation.
hamidouk
parents: 626
diff changeset
   415
                          
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   416
  IriSP.jQuery.ajax({
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   417
      url: url,
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   418
      type: 'PUT',
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   419
      contentType: 'application/json',
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   420
      data: jsonString,               
626
c66bf61262fa round the ms
hamidouk
parents: 623
diff changeset
   421
      //dataType: 'json',
630
7c53857650b1 create a new contribution line in the json if it's not defined already.
hamidouk
parents: 627
diff changeset
   422
      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
   423
                    /* 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
   424
                    
7c53857650b1 create a new contribution line in the json if it's not defined already.
hamidouk
parents: 627
diff changeset
   425
                    /* 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
   426
                    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
   427
                      /* 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
   428
                      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
   429
                                      "id": json.annotations[0].type}
651
c43441822b1b use the new annotation shortening functions.
hamidouk
parents: 645
diff changeset
   430
630
7c53857650b1 create a new contribution line in the json if it's not defined already.
hamidouk
parents: 627
diff changeset
   431
                      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
   432
                    }
7c53857650b1 create a new contribution line in the json if it's not defined already.
hamidouk
parents: 627
diff changeset
   433
                    
597
93feb85bb07f correctly add an annotation.
hamidouk
parents: 594
diff changeset
   434
                    delete annotation.tags;
93feb85bb07f correctly add an annotation.
hamidouk
parents: 594
diff changeset
   435
                    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
   436
                    annotation.content.title = "";
597
93feb85bb07f correctly add an annotation.
hamidouk
parents: 594
diff changeset
   437
                    delete annotation.content.data;
93feb85bb07f correctly add an annotation.
hamidouk
parents: 594
diff changeset
   438
                    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
   439
606
13675511a01a fixed creation bug.
hamidouk
parents: 597
diff changeset
   440
                    annotation.meta = meta;
643
3e522b6f7bd0 fixed a couple bugs.
hamidouk
parents: 630
diff changeset
   441
                    annotation.meta["id-ref"] = json.annotations[0]["type"];
3e522b6f7bd0 fixed a couple bugs.
hamidouk
parents: 630
diff changeset
   442
                    
597
93feb85bb07f correctly add an annotation.
hamidouk
parents: 594
diff changeset
   443
                    // everything is shared so there's no need to propagate the change
93feb85bb07f correctly add an annotation.
hamidouk
parents: 594
diff changeset
   444
                    _this._serializer._data.annotations.push(annotation);
651
c43441822b1b use the new annotation shortening functions.
hamidouk
parents: 645
diff changeset
   445
 
643
3e522b6f7bd0 fixed a couple bugs.
hamidouk
parents: 630
diff changeset
   446
                    _this._Popcorn.trigger("IriSP.createAnnotationWidget.addedAnnotation", annotation);
651
c43441822b1b use the new annotation shortening functions.
hamidouk
parents: 645
diff changeset
   447
                    callback(annotation);
630
7c53857650b1 create a new contribution line in the json if it's not defined already.
hamidouk
parents: 627
diff changeset
   448
      }), 
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   449
      error: 
626
c66bf61262fa round the ms
hamidouk
parents: 623
diff changeset
   450
              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
   451
                            console.log("an error occured while contacting " 
769
70464200b601 added an error screen.
hamidouk
parents: 764
diff changeset
   452
                            + url + " and sending " + jsonString + textStatus ); 
70464200b601 added an error screen.
hamidouk
parents: 764
diff changeset
   453
                            _this.showErrorScreen(); } });
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   454
};