| author | hamidouk |
| Mon, 02 Jan 2012 15:27:32 +0100 | |
| branch | popcorn-port |
| changeset 562 | 643614f78c44 |
| parent 561 | a10e7b6fdb08 |
| child 563 | 4816e3425933 |
| permissions | -rw-r--r-- |
| 543 | 1 |
IriSP.createAnnotationWidget = function(Popcorn, config, Serializer) { |
2 |
IriSP.Widget.call(this, Popcorn, config, Serializer); |
|
3 |
this._hidden = true; |
|
| 547 | 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 | 6 |
this.ids = {}; /* a dictionnary linking buttons ids to keywords */ |
| 543 | 7 |
}; |
8 |
||
9 |
||
10 |
IriSP.createAnnotationWidget.prototype = new IriSP.Widget(); |
|
11 |
||
12 |
IriSP.createAnnotationWidget.prototype.clear = function() { |
|
13 |
this.selector.find(".Ldt-SaTitle").text(""); |
|
14 |
this.selector.find(".Ldt-SaDescription").text(""); |
|
15 |
this.selector.find(".Ldt-SaKeywordText").text(""); |
|
16 |
}; |
|
17 |
||
18 |
IriSP.createAnnotationWidget.prototype.draw = function() { |
|
19 |
var _this = this; |
|
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 | 27 |
this.selector.append(annotationMarkup); |
| 548 | 28 |
|
| 543 | 29 |
this.selector.hide(); |
| 548 | 30 |
for (var i = 0; i < this.keywords.length; i++) { |
| 549 | 31 |
var keyword = this.keywords[i]; |
32 |
var id = IriSP.guid("button_"); |
|
33 |
var templ = IriSP.templToHTML("<button id={{id}} class='Ldt-createAnnotation-absent-keyword'>{{keyword}}</button>", |
|
34 |
{keyword: keyword, id: id}); |
|
| 548 | 35 |
|
| 549 | 36 |
this.ids[keyword] = id; // save it for the function that handle textarea changes. |
37 |
|
|
| 548 | 38 |
this.selector.find(".Ldt-createAnnotation-keywords").append(templ); |
| 549 | 39 |
this.selector.find("#" + id).click(function(keyword) { return function() { |
40 |
var contents = _this.selector.find(".Ldt-createAnnotation-Description").val(); |
|
41 |
if (contents.indexOf(keyword) != -1) { |
|
42 |
var newVal = contents.replace(keyword, ""); |
|
43 |
} else { |
|
44 |
var newVal = contents + keyword; |
|
45 |
} |
|
46 |
|
|
47 |
_this.selector.find(".Ldt-createAnnotation-Description").val(newVal); |
|
48 |
// also call our update function. |
|
49 |
_this.handleTextChanges(); |
|
50 |
} |
|
51 |
}(keyword)); |
|
| 548 | 52 |
} |
53 |
|
|
| 549 | 54 |
this.selector.find(".Ldt-createAnnotation-Description") |
55 |
.bind("propertychange keyup input paste", IriSP.wrap(this, this.handleTextChanges)); |
|
| 543 | 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 | 58 |
this._Popcorn.listen("IriSP.PlayerWidget.AnnotateButton.clicked", |
| 547 | 59 |
IriSP.wrap(this, this.handleAnnotateSignal)); |
| 543 | 60 |
}; |
61 |
||
62 |
IriSP.createAnnotationWidget.prototype.handleAnnotateSignal = function() { |
|
63 |
if (this._hidden == false) { |
|
64 |
this.selector.hide(); |
|
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 | 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 | 85 |
this.selector.show(); |
86 |
this._hidden = false; |
|
87 |
} |
|
| 549 | 88 |
}; |
89 |
||
90 |
/** watch for changes in the textfield and change the buttons accordingly */ |
|
91 |
IriSP.createAnnotationWidget.prototype.handleTextChanges = function(event) { |
|
92 |
var contents = this.selector.find(".Ldt-createAnnotation-Description").val(); |
|
93 |
||
94 |
for(var keyword in this.ids) { |
|
95 |
|
|
96 |
var id = this.ids[keyword]; |
|
97 |
||
98 |
if (contents.indexOf(keyword) != -1) { |
|
99 |
/* the word is present in the textarea but the button is not toggled */ |
|
100 |
if (this.selector.find("#" + id).hasClass("Ldt-createAnnotation-absent-keyword")) |
|
101 |
this.selector.find("#" + id).removeClass("Ldt-createAnnotation-absent-keyword") |
|
102 |
.addClass("Ldt-createAnnotation-present-keyword"); |
|
103 |
} else { |
|
104 |
/* the word is absent from the textarea but the button is toggled */ |
|
105 |
if (this.selector.find("#" + id).hasClass("Ldt-createAnnotation-present-keyword")) { |
|
106 |
this.selector.find("#" + id).removeClass("Ldt-createAnnotation-present-keyword") |
|
107 |
.addClass("Ldt-createAnnotation-absent-keyword"); |
|
108 |
} |
|
109 |
} |
|
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) { |
|
561
a10e7b6fdb08
display an error message when the user forget to enter text.
hamidouk
parents:
553
diff
changeset
|
115 |
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
|
116 |
var contents = textfield.val(); |
|
a10e7b6fdb08
display an error message when the user forget to enter text.
hamidouk
parents:
553
diff
changeset
|
117 |
|
|
a10e7b6fdb08
display an error message when the user forget to enter text.
hamidouk
parents:
553
diff
changeset
|
118 |
if (contents === "") { |
|
a10e7b6fdb08
display an error message when the user forget to enter text.
hamidouk
parents:
553
diff
changeset
|
119 |
textfield.after(IriSP.templToHTML(IriSP.createAnnotation_errorMessage_template)); |
|
a10e7b6fdb08
display an error message when the user forget to enter text.
hamidouk
parents:
553
diff
changeset
|
120 |
textfield.css("background-color", "#d93c71"); |
| 562 | 121 |
|
122 |
// use namespaced events to be able to unbind them quickly and without unbinding |
|
123 |
// the other event handlers. |
|
|
561
a10e7b6fdb08
display an error message when the user forget to enter text.
hamidouk
parents:
553
diff
changeset
|
124 |
textfield.bind("propertychange.tmp keyup.tmp input.tmp paste.tmp", IriSP.wrap(this, function() { |
|
a10e7b6fdb08
display an error message when the user forget to enter text.
hamidouk
parents:
553
diff
changeset
|
125 |
var contents = textfield.val(); |
|
a10e7b6fdb08
display an error message when the user forget to enter text.
hamidouk
parents:
553
diff
changeset
|
126 |
console.log(contents); |
|
a10e7b6fdb08
display an error message when the user forget to enter text.
hamidouk
parents:
553
diff
changeset
|
127 |
if (contents !== "") { |
|
a10e7b6fdb08
display an error message when the user forget to enter text.
hamidouk
parents:
553
diff
changeset
|
128 |
this.selector.find(".Ldt-createAnnotation-errorMessage").hide(); |
|
a10e7b6fdb08
display an error message when the user forget to enter text.
hamidouk
parents:
553
diff
changeset
|
129 |
textfield.css("background-color", ""); |
|
a10e7b6fdb08
display an error message when the user forget to enter text.
hamidouk
parents:
553
diff
changeset
|
130 |
textfield.unbind(".tmp"); |
|
a10e7b6fdb08
display an error message when the user forget to enter text.
hamidouk
parents:
553
diff
changeset
|
131 |
} |
|
a10e7b6fdb08
display an error message when the user forget to enter text.
hamidouk
parents:
553
diff
changeset
|
132 |
})); |
|
a10e7b6fdb08
display an error message when the user forget to enter text.
hamidouk
parents:
553
diff
changeset
|
133 |
} else { |
|
a10e7b6fdb08
display an error message when the user forget to enter text.
hamidouk
parents:
553
diff
changeset
|
134 |
this.selector.find(".Ldt-createAnnotation-DoubleBorder").children().hide(); |
|
a10e7b6fdb08
display an error message when the user forget to enter text.
hamidouk
parents:
553
diff
changeset
|
135 |
this.selector.find(".Ldt-createAnnotation-endScreen").show(); |
|
a10e7b6fdb08
display an error message when the user forget to enter text.
hamidouk
parents:
553
diff
changeset
|
136 |
} |
| 543 | 137 |
}; |