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