src/js/widgets/createAnnotationWidget.js
author hamidouk
Tue, 17 Jan 2012 11:00:33 +0100
branchpopcorn-port
changeset 645 0c8ca890c9f1
parent 643 3e522b6f7bd0
child 651 c43441822b1b
permissions -rw-r--r--
fixed update bug.
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;
553
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
     5
  this.cinecast_version = IriSP.widgetsDefaults["createAnnotationWidget"].cinecast_version;
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
     6
  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
     7
  
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
     8
  /* 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
     9
  if (this.cinecast_version) {
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
    10
    this.sliceLeft = 0;
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
    11
    this.sliceWidth = 0;
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
    12
  }
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    13
};
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    14
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    15
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    16
IriSP.createAnnotationWidget.prototype = new IriSP.Widget();
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    17
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    18
IriSP.createAnnotationWidget.prototype.clear = function() {
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    19
    this.selector.find(".Ldt-SaTitle").text("");
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    20
    this.selector.find(".Ldt-SaDescription").text("");
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    21
    this.selector.find(".Ldt-SaKeywordText").text("");
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    22
};
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    23
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    24
IriSP.createAnnotationWidget.prototype.draw = function() {
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    25
  var _this = this;
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    26
553
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    27
  if (this.cinecast_version) {    
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    28
    var annotationMarkup = IriSP.templToHTML(IriSP.createAnnotationWidget_festivalCinecast_template);
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    29
  } else {
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    30
    var annotationMarkup = IriSP.templToHTML(IriSP.createAnnotationWidget_template);
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    31
  }
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    32
  
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    33
	this.selector.append(annotationMarkup);
548
96a188138c20 refactored the code a bit.
hamidouk
parents: 547
diff changeset
    34
  
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
    35
  if (!this.cinecast_version)
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
    36
    this.selector.hide();
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
    37
  
548
96a188138c20 refactored the code a bit.
hamidouk
parents: 547
diff changeset
    38
  for (var i = 0; i < this.keywords.length; i++) {
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    39
    var keyword = this.keywords[i];
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    40
    var id = IriSP.guid("button_");
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    41
    var templ = IriSP.templToHTML("<button id={{id}} class='Ldt-createAnnotation-absent-keyword'>{{keyword}}</button>", 
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    42
                                  {keyword: keyword, id: id});
548
96a188138c20 refactored the code a bit.
hamidouk
parents: 547
diff changeset
    43
                                  
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    44
    this.ids[keyword] = id; // save it for the function that handle textarea changes.
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    45
    
548
96a188138c20 refactored the code a bit.
hamidouk
parents: 547
diff changeset
    46
    this.selector.find(".Ldt-createAnnotation-keywords").append(templ);
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    47
    this.selector.find("#" + id).click(function(keyword) { return function() {
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    48
      var contents = _this.selector.find(".Ldt-createAnnotation-Description").val();
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    49
      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
    50
        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
    51
        if (newVal == contents)
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
    52
          newVal = contents.replace(keyword, "");
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    53
      } else {
611
d931a7d12519 append a small space before keywords
hamidouk
parents: 608
diff changeset
    54
        if (contents === "")
d931a7d12519 append a small space before keywords
hamidouk
parents: 608
diff changeset
    55
          var newVal = keyword;
d931a7d12519 append a small space before keywords
hamidouk
parents: 608
diff changeset
    56
        else
d931a7d12519 append a small space before keywords
hamidouk
parents: 608
diff changeset
    57
          var newVal = contents + " " + keyword;      
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    58
      }
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    59
      
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    60
      _this.selector.find(".Ldt-createAnnotation-Description").val(newVal);
570
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
    61
      // 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
    62
      // change in a textfield.
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
    63
      _this.selector.find(".Ldt-createAnnotation-Description").trigger("js_mod");
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    64
      // also call our update function.
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    65
      _this.handleTextChanges();
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    66
    }
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    67
   }(keyword));
548
96a188138c20 refactored the code a bit.
hamidouk
parents: 547
diff changeset
    68
  }
96a188138c20 refactored the code a bit.
hamidouk
parents: 547
diff changeset
    69
  
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    70
  this.selector.find(".Ldt-createAnnotation-Description")
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    71
               .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
    72
               
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
    73
  /* 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
    74
  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
    75
    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
    76
                 .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
    77
                 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
    78
  }
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
    79
  /* 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
    80
     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
    81
     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
    82
     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
    83
  */
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
    84
  if (this.cinecast_version) {
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
    85
    var legal_ids;
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
    86
    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
    87
      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
    88
    else 
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
    89
      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
    90
    
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
    91
    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
    92
    var i;
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
    93
  
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
    94
    for (i in annotations) {     
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
    95
      var annotation = annotations[i];
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
    96
      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
    97
            && 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
    98
          continue;
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
    99
      }
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   100
      
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   101
      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
   102
              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
   103
                      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
   104
                        _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
   105
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   106
                      _this._currentAnnotation = annotation;
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   107
                      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
   108
                      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
   109
                      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
   110
                      _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
   111
              } }(annotation)
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
      
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   114
      this._Popcorn.code(code);
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   115
    }
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   116
  }
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   117
  
553
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
   118
  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
   119
  
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   120
  if (!this.cinecast_version)
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   121
    this._Popcorn.listen("IriSP.PlayerWidget.AnnotateButton.clicked", 
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   122
                          IriSP.wrap(this, this.handleAnnotateSignal));  
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   123
};
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   124
620
fe981f0aab71 automatically position and show the sliceWidget under the current chapter.
hamidouk
parents: 616
diff changeset
   125
/** 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
   126
IriSP.createAnnotationWidget.prototype.handleAnnotateSignal = function() {
620
fe981f0aab71 automatically position and show the sliceWidget under the current chapter.
hamidouk
parents: 616
diff changeset
   127
  
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   128
  if (this._hidden == false) {
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   129
    this.selector.hide();
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   130
    this._hidden = true;
570
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   131
    
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   132
    // free the arrow.
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   133
    this._Popcorn.trigger("IriSP.ArrowWidget.releaseArrow");
620
fe981f0aab71 automatically position and show the sliceWidget under the current chapter.
hamidouk
parents: 616
diff changeset
   134
    this._Popcorn.trigger("IriSP.SliceWidget.hide");
fe981f0aab71 automatically position and show the sliceWidget under the current chapter.
hamidouk
parents: 616
diff changeset
   135
    
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   136
  } else {
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   137
    this.showStartScreen();
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   138
    this.selector.show();
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   139
    this._hidden = false;
620
fe981f0aab71 automatically position and show the sliceWidget under the current chapter.
hamidouk
parents: 616
diff changeset
   140
    var currentTime = this._Popcorn.currentTime();
563
4816e3425933 block the arrow when the user is annotating.
hamidouk
parents: 562
diff changeset
   141
    
4816e3425933 block the arrow when the user is annotating.
hamidouk
parents: 562
diff changeset
   142
    // block the arrow.
4816e3425933 block the arrow when the user is annotating.
hamidouk
parents: 562
diff changeset
   143
    this._Popcorn.trigger("IriSP.ArrowWidget.blockArrow");
623
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   144
    
620
fe981f0aab71 automatically position and show the sliceWidget under the current chapter.
hamidouk
parents: 616
diff changeset
   145
    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
   146
        
620
fe981f0aab71 automatically position and show the sliceWidget under the current chapter.
hamidouk
parents: 616
diff changeset
   147
    var currentChapter = this._serializer.currentChapitre(currentTime);
623
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   148
    if (typeof(currentChapter) === "undefined") {
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   149
      var left = this.selector.width() / 2;
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   150
      var width = this.selector.width() / 10;
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   151
    } else {
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   152
      var left = (currentChapter.begin / duration) * this.selector.width();
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   153
      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
   154
    }
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   155
    
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   156
    this.sliceLeft = left;
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   157
    this.sliceWidth = width;
620
fe981f0aab71 automatically position and show the sliceWidget under the current chapter.
hamidouk
parents: 616
diff changeset
   158
    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
   159
    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
   160
    this._Popcorn.trigger("IriSP.SliceWidget.show");
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   161
  }
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   162
};
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   163
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   164
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   165
/** watch for changes in the textfield and change the buttons accordingly */
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   166
IriSP.createAnnotationWidget.prototype.handleTextChanges = function(event) {
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   167
  var contents = this.selector.find(".Ldt-createAnnotation-Description").val();
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   168
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   169
  for(var keyword in this.ids) {
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   170
  
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   171
    var id = this.ids[keyword];
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   172
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   173
    if (contents.indexOf(keyword) != -1) {
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   174
      /* the word is present in the textarea but the button is not toggled */
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   175
      if (this.selector.find("#" + id).hasClass("Ldt-createAnnotation-absent-keyword"))
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   176
          this.selector.find("#" + id).removeClass("Ldt-createAnnotation-absent-keyword")
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   177
                                      .addClass("Ldt-createAnnotation-present-keyword");      
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   178
    } else {
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   179
      /* the word is absent from the textarea but the button is toggled */
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   180
      if (this.selector.find("#" + id).hasClass("Ldt-createAnnotation-present-keyword")) {
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   181
          this.selector.find("#" + id).removeClass("Ldt-createAnnotation-present-keyword")
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   182
                                      .addClass("Ldt-createAnnotation-absent-keyword");
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   183
      }
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   184
    }
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   185
  }
553
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
   186
};
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
   187
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   188
IriSP.createAnnotationWidget.prototype.showStartScreen = function() {
627
13b9f14bf49a added a spinner displayed while submitting an annotation.
hamidouk
parents: 626
diff changeset
   189
  this.selector.find(".Ldt-createAnnotation-DoubleBorder").children().hide();
13b9f14bf49a added a spinner displayed while submitting an annotation.
hamidouk
parents: 626
diff changeset
   190
  this.selector.find(".Ldt-createAnnotation-startScreen").show();
13b9f14bf49a added a spinner displayed while submitting an annotation.
hamidouk
parents: 626
diff changeset
   191
  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
   192
};
13b9f14bf49a added a spinner displayed while submitting an annotation.
hamidouk
parents: 626
diff changeset
   193
13b9f14bf49a added a spinner displayed while submitting an annotation.
hamidouk
parents: 626
diff changeset
   194
IriSP.createAnnotationWidget.prototype.showWaitScreen = function() {
13b9f14bf49a added a spinner displayed while submitting an annotation.
hamidouk
parents: 626
diff changeset
   195
  this.selector.find(".Ldt-createAnnotation-DoubleBorder").children().hide();
13b9f14bf49a added a spinner displayed while submitting an annotation.
hamidouk
parents: 626
diff changeset
   196
  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
   197
};
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   198
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   199
IriSP.createAnnotationWidget.prototype.showEndScreen = function() {
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   200
  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
   201
  
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   202
  if (this.cinecast_version) {
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   203
    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
   204
  }
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   205
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   206
  var twStatus = IriSP.mkTweetUrl(document.location.href);
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   207
  var gpStatus = IriSP.mkGplusUrl(document.location.href);
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   208
  var fbStatus = IriSP.mkFbUrl(document.location.href);
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   209
  
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   210
  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
   211
  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
   212
  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
   213
          
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   214
  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
   215
};
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   216
553
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
   217
/** handle clicks on "send annotation" button */
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
   218
IriSP.createAnnotationWidget.prototype.handleButtonClick = function(event) {
597
93feb85bb07f correctly add an annotation.
hamidouk
parents: 594
diff changeset
   219
  var _this = this;
561
a10e7b6fdb08 display an error message when the user forget to enter text.
hamidouk
parents: 553
diff changeset
   220
  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
   221
  var contents = textfield.val();
a10e7b6fdb08 display an error message when the user forget to enter text.
hamidouk
parents: 553
diff changeset
   222
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   223
  if (contents === "") {  
570
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   224
    if (this.selector.find(".Ldt-createAnnotation-errorMessage").length === 0) {
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   225
      this.selector.find(".Ldt-createAnnotation-Container")
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   226
                   .after(IriSP.templToHTML(IriSP.createAnnotation_errorMessage_template));
571
a471ef7efc0e fixes to the fixes.
hamidouk
parents: 570
diff changeset
   227
      textfield.css("background-color", "#d93c71");      
a471ef7efc0e fixes to the fixes.
hamidouk
parents: 570
diff changeset
   228
    } else {
a471ef7efc0e fixes to the fixes.
hamidouk
parents: 570
diff changeset
   229
      this.selector.find(".Ldt-createAnnotation-errorMessage").show();
a471ef7efc0e fixes to the fixes.
hamidouk
parents: 570
diff changeset
   230
    }
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   231
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   232
      textfield.one("js_mod propertychange keyup input paste", IriSP.wrap(this, function() {
570
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   233
                      var contents = textfield.val();
611
d931a7d12519 append a small space before keywords
hamidouk
parents: 608
diff changeset
   234
                      
570
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   235
                      if (contents !== "") {
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   236
                        this.selector.find(".Ldt-createAnnotation-errorMessage").hide();
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   237
                        textfield.css("background-color", "");
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   238
                      }
244f04a9af85 a couple changes.
hamidouk
parents: 563
diff changeset
   239
                   }));
561
a10e7b6fdb08 display an error message when the user forget to enter text.
hamidouk
parents: 553
diff changeset
   240
  } else {
627
13b9f14bf49a added a spinner displayed while submitting an annotation.
hamidouk
parents: 626
diff changeset
   241
    this.showWaitScreen();
594
96af41097260 WIP - adapting the widget to the new segments conventions.
hamidouk
parents: 575
diff changeset
   242
    
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   243
    this.sendLdtData(contents, function() {
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   244
                    if (_this.cinecast_version) {
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   245
                        if (_this._Popcorn.media.paused)
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   246
                          _this._Popcorn.play();
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   247
                    }
630
7c53857650b1 create a new contribution line in the json if it's not defined already.
hamidouk
parents: 627
diff changeset
   248
627
13b9f14bf49a added a spinner displayed while submitting an annotation.
hamidouk
parents: 626
diff changeset
   249
                    _this.showEndScreen();
13b9f14bf49a added a spinner displayed while submitting an annotation.
hamidouk
parents: 626
diff changeset
   250
                    window.setTimeout(IriSP.wrap(_this, function() { this.showStartScreen(); }), 5000);
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   251
                    });
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   252
  }
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   253
};
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   254
623
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   255
IriSP.createAnnotationWidget.prototype.handleSliderChanges = function(params) {
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   256
  this.sliceLeft = params[0];
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   257
  this.sliceWidth = params[1];
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   258
};
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   259
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   260
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
   261
  var _this = this;
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   262
  var apiJson = {annotations : [{}], meta: {}};
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   263
  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
   264
  
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   265
  annotation["media"] = this._serializer.currentMedia()["id"];
623
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   266
  
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   267
  if (this.cinecast_version) {
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   268
    if (typeof(this._currentAnnotation) !== "undefined") {
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   269
      annotation["begin"] = this._currentAnnotation.begin;
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   270
      annotation["end"] = this._currentAnnotation.end;
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   271
    }
d8f107938feb WIP - create custom-sized segments in "normal" (non-cinecast) mode.
hamidouk
parents: 620
diff changeset
   272
  } else {
643
3e522b6f7bd0 fixed a couple bugs.
hamidouk
parents: 630
diff changeset
   273
    var duration = +this._serializer.currentMedia().meta["dc:duration"];    
645
0c8ca890c9f1 fixed update bug.
hamidouk
parents: 643
diff changeset
   274
    annotation["begin"] = +((duration * (this.sliceLeft / 100)).toFixed(0));
0c8ca890c9f1 fixed update bug.
hamidouk
parents: 643
diff changeset
   275
    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
   276
  }
645
0c8ca890c9f1 fixed update bug.
hamidouk
parents: 643
diff changeset
   277
  
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   278
  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
   279
  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
   280
    annotation["type"] = "";
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   281
  
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   282
  annotation["type_title"] = "Contributions";
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   283
  annotation.content = {};
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   284
  annotation.content["data"] = contents;
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   285
  
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   286
  var meta = apiJson["meta"];
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   287
  meta.creator = "An User";    
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   288
  meta.created = Date().toString();
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   289
  
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   290
  annotation["tags"] = [];
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
  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
   293
    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
   294
    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
   295
      annotation["tags"].push(keyword);
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   296
  }
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   297
  
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   298
  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
   299
  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
   300
  
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   301
  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
   302
                              {platf_url: IriSP.platform_url, id: project_id});
627
13b9f14bf49a added a spinner displayed while submitting an annotation.
hamidouk
parents: 626
diff changeset
   303
                          
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   304
  IriSP.jQuery.ajax({
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   305
      url: url,
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   306
      type: 'PUT',
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   307
      contentType: 'application/json',
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   308
      data: jsonString,               
626
c66bf61262fa round the ms
hamidouk
parents: 623
diff changeset
   309
      //dataType: 'json',
630
7c53857650b1 create a new contribution line in the json if it's not defined already.
hamidouk
parents: 627
diff changeset
   310
      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
   311
                    /* 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
   312
                    
7c53857650b1 create a new contribution line in the json if it's not defined already.
hamidouk
parents: 627
diff changeset
   313
                    /* 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
   314
                    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
   315
                      /* 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
   316
                      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
   317
                                      "id": json.annotations[0].type}
7c53857650b1 create a new contribution line in the json if it's not defined already.
hamidouk
parents: 627
diff changeset
   318
                      console.log(tmp_view);
7c53857650b1 create a new contribution line in the json if it's not defined already.
hamidouk
parents: 627
diff changeset
   319
                      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
   320
                    }
7c53857650b1 create a new contribution line in the json if it's not defined already.
hamidouk
parents: 627
diff changeset
   321
                    
597
93feb85bb07f correctly add an annotation.
hamidouk
parents: 594
diff changeset
   322
                    delete annotation.tags;
93feb85bb07f correctly add an annotation.
hamidouk
parents: 594
diff changeset
   323
                    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
   324
                    annotation.content.title = "";
597
93feb85bb07f correctly add an annotation.
hamidouk
parents: 594
diff changeset
   325
                    delete annotation.content.data;
93feb85bb07f correctly add an annotation.
hamidouk
parents: 594
diff changeset
   326
                    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
   327
606
13675511a01a fixed creation bug.
hamidouk
parents: 597
diff changeset
   328
                    annotation.meta = meta;
643
3e522b6f7bd0 fixed a couple bugs.
hamidouk
parents: 630
diff changeset
   329
                    annotation.meta["id-ref"] = json.annotations[0]["type"];
3e522b6f7bd0 fixed a couple bugs.
hamidouk
parents: 630
diff changeset
   330
                    
597
93feb85bb07f correctly add an annotation.
hamidouk
parents: 594
diff changeset
   331
                    // everything is shared so there's no need to propagate the change
93feb85bb07f correctly add an annotation.
hamidouk
parents: 594
diff changeset
   332
                    _this._serializer._data.annotations.push(annotation);
630
7c53857650b1 create a new contribution line in the json if it's not defined already.
hamidouk
parents: 627
diff changeset
   333
                    console.log(_this._serializer._data);
643
3e522b6f7bd0 fixed a couple bugs.
hamidouk
parents: 630
diff changeset
   334
                    _this._Popcorn.trigger("IriSP.createAnnotationWidget.addedAnnotation", annotation);
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   335
                    callback();
630
7c53857650b1 create a new contribution line in the json if it's not defined already.
hamidouk
parents: 627
diff changeset
   336
      }), 
614
116de1c38a7d lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents: 611
diff changeset
   337
      error: 
626
c66bf61262fa round the ms
hamidouk
parents: 623
diff changeset
   338
              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
   339
                            console.log("an error occured while contacting " 
626
c66bf61262fa round the ms
hamidouk
parents: 623
diff changeset
   340
                            + url + " and sending " + jsonString + textStatus ); } });
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   341
};