src/js/widgets/createAnnotationWidget.js
author hamidouk
Fri, 30 Dec 2011 16:01:09 +0100
branchpopcorn-port
changeset 553 10d08f43c534
parent 549 8abffd2de54a
child 561 a10e7b6fdb08
permissions -rw-r--r--
widget works now more or less like in samuel's crea.
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 */
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
     7
};
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
     8
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
     9
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    10
IriSP.createAnnotationWidget.prototype = new IriSP.Widget();
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    11
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    12
IriSP.createAnnotationWidget.prototype.clear = function() {
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    13
    this.selector.find(".Ldt-SaTitle").text("");
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    14
    this.selector.find(".Ldt-SaDescription").text("");
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    15
    this.selector.find(".Ldt-SaKeywordText").text("");
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    16
};
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.draw = function() {
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    19
  var _this = this;
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    20
553
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    21
  if (this.cinecast_version) {    
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    22
    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
    23
  } else {
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    24
    var annotationMarkup = IriSP.templToHTML(IriSP.createAnnotationWidget_template);
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    25
  }
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    26
  
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    27
	this.selector.append(annotationMarkup);
548
96a188138c20 refactored the code a bit.
hamidouk
parents: 547
diff changeset
    28
  
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    29
  this.selector.hide();
548
96a188138c20 refactored the code a bit.
hamidouk
parents: 547
diff changeset
    30
  for (var i = 0; i < this.keywords.length; i++) {
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    31
    var keyword = this.keywords[i];
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    32
    var id = IriSP.guid("button_");
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    33
    var templ = IriSP.templToHTML("<button id={{id}} class='Ldt-createAnnotation-absent-keyword'>{{keyword}}</button>", 
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    34
                                  {keyword: keyword, id: id});
548
96a188138c20 refactored the code a bit.
hamidouk
parents: 547
diff changeset
    35
                                  
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    36
    this.ids[keyword] = id; // save it for the function that handle textarea changes.
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    37
    
548
96a188138c20 refactored the code a bit.
hamidouk
parents: 547
diff changeset
    38
    this.selector.find(".Ldt-createAnnotation-keywords").append(templ);
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    39
    this.selector.find("#" + id).click(function(keyword) { return function() {
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    40
      var contents = _this.selector.find(".Ldt-createAnnotation-Description").val();
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    41
      if (contents.indexOf(keyword) != -1) {
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    42
        var newVal = contents.replace(keyword, "");        
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    43
      } else {
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    44
        var newVal = contents + keyword;      
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    45
      }
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    46
      
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    47
      _this.selector.find(".Ldt-createAnnotation-Description").val(newVal);
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    48
      // also call our update function.
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    49
      _this.handleTextChanges();
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    50
    }
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    51
   }(keyword));
548
96a188138c20 refactored the code a bit.
hamidouk
parents: 547
diff changeset
    52
  }
96a188138c20 refactored the code a bit.
hamidouk
parents: 547
diff changeset
    53
  
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    54
  this.selector.find(".Ldt-createAnnotation-Description")
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    55
               .bind("propertychange keyup input paste", IriSP.wrap(this, this.handleTextChanges));
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    56
  
553
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    57
  this.selector.find(".Ldt-createAnnotation-submitButton").click(IriSP.wrap(this, this.handleButtonClick));
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    58
  this._Popcorn.listen("IriSP.PlayerWidget.AnnotateButton.clicked", 
547
5b58a108086a adding support for keywords.
hamidouk
parents: 543
diff changeset
    59
                        IriSP.wrap(this, this.handleAnnotateSignal));  
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    60
};
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    61
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    62
IriSP.createAnnotationWidget.prototype.handleAnnotateSignal = function() {
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    63
  if (this._hidden == false) {
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    64
    this.selector.hide();
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    65
    this._hidden = true;
553
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    66
    /* reinit the fields */
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    67
    
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    68
    this.selector.find(".Ldt-createAnnotation-DoubleBorder").children().show();
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    69
    this.selector.find("Ldt-createAnnotation-Description").val("");
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    70
    this.selector.find(".Ldt-createAnnotation-endScreen").hide();
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    71
  } else {
553
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    72
    if (this.cinecast_version) {
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    73
      var currentTime = this._Popcorn.currentTime();
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    74
      var currentAnnotation = this._serializer.currentAnnotations(currentTime)[0];
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    75
      var beginTime = IriSP.msToTime(currentAnnotation.begin);
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    76
      var endTime = IriSP.msToTime(currentAnnotation.end);
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    77
      
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    78
      if (typeof(currentAnnotation.content) !== "undefined")
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    79
        this.selector.find(".Ldt-createAnnotation-Title").html(currentAnnotation.content.title);
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    80
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    81
      var timeTemplate = IriSP.templToHTML("- ({{begin}} - {{ end }})", {begin: beginTime, end: endTime });
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    82
      this.selector.find(".Ldt-createAnnotation-TimeFrame").html(timeTemplate);
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    83
    }
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
    84
    
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    85
    this.selector.show();
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    86
    this._hidden = false;
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
    87
  }
549
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    88
};
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    89
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    90
/** watch for changes in the textfield and change the buttons accordingly */
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    91
IriSP.createAnnotationWidget.prototype.handleTextChanges = function(event) {
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    92
  var contents = this.selector.find(".Ldt-createAnnotation-Description").val();
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    93
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    94
  for(var keyword in this.ids) {
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    95
  
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    96
    var id = this.ids[keyword];
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    97
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    98
    if (contents.indexOf(keyword) != -1) {
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
    99
      /* the word is present in the textarea but the button is not toggled */
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   100
      if (this.selector.find("#" + id).hasClass("Ldt-createAnnotation-absent-keyword"))
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   101
          this.selector.find("#" + id).removeClass("Ldt-createAnnotation-absent-keyword")
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   102
                                      .addClass("Ldt-createAnnotation-present-keyword");      
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   103
    } else {
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   104
      /* the word is absent from the textarea but the button is toggled */
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   105
      if (this.selector.find("#" + id).hasClass("Ldt-createAnnotation-present-keyword")) {
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   106
          this.selector.find("#" + id).removeClass("Ldt-createAnnotation-present-keyword")
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   107
                                      .addClass("Ldt-createAnnotation-absent-keyword");
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   108
      }
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   109
    }
8abffd2de54a implemented correct button behaviour.
hamidouk
parents: 548
diff changeset
   110
  }
553
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
   111
};
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
   112
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
   113
/** handle clicks on "send annotation" button */
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
   114
IriSP.createAnnotationWidget.prototype.handleButtonClick = function(event) {
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
   115
  this.selector.find(".Ldt-createAnnotation-DoubleBorder").children().hide();
10d08f43c534 widget works now more or less like in samuel's crea.
hamidouk
parents: 549
diff changeset
   116
  this.selector.find(".Ldt-createAnnotation-endScreen").show();
543
5856fab9596c WIP - adding widget to create annotations.
hamidouk
parents:
diff changeset
   117
};