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