| author | hamidouk |
| Thu, 12 Jan 2012 13:15:34 +0100 | |
| branch | popcorn-port |
| changeset 614 | 116de1c38a7d |
| parent 611 | d931a7d12519 |
| child 616 | ff108c38a0c9 |
| 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 |
|
|
614
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
29 |
if (!this.cinecast_version) |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
30 |
this.selector.hide(); |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
31 |
|
| 548 | 32 |
for (var i = 0; i < this.keywords.length; i++) { |
| 549 | 33 |
var keyword = this.keywords[i]; |
34 |
var id = IriSP.guid("button_"); |
|
35 |
var templ = IriSP.templToHTML("<button id={{id}} class='Ldt-createAnnotation-absent-keyword'>{{keyword}}</button>", |
|
36 |
{keyword: keyword, id: id}); |
|
| 548 | 37 |
|
| 549 | 38 |
this.ids[keyword] = id; // save it for the function that handle textarea changes. |
39 |
|
|
| 548 | 40 |
this.selector.find(".Ldt-createAnnotation-keywords").append(templ); |
| 549 | 41 |
this.selector.find("#" + id).click(function(keyword) { return function() { |
42 |
var contents = _this.selector.find(".Ldt-createAnnotation-Description").val(); |
|
43 |
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
|
44 |
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
|
45 |
if (newVal == contents) |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
46 |
newVal = contents.replace(keyword, ""); |
| 549 | 47 |
} else { |
| 611 | 48 |
if (contents === "") |
49 |
var newVal = keyword; |
|
50 |
else |
|
51 |
var newVal = contents + " " + keyword; |
|
| 549 | 52 |
} |
53 |
|
|
54 |
_this.selector.find(".Ldt-createAnnotation-Description").val(newVal); |
|
| 570 | 55 |
// we use a custom event because there's no simple way to test for a js |
56 |
// change in a textfield. |
|
57 |
_this.selector.find(".Ldt-createAnnotation-Description").trigger("js_mod"); |
|
| 549 | 58 |
// also call our update function. |
59 |
_this.handleTextChanges(); |
|
60 |
} |
|
61 |
}(keyword)); |
|
| 548 | 62 |
} |
63 |
|
|
| 549 | 64 |
this.selector.find(".Ldt-createAnnotation-Description") |
65 |
.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
|
66 |
|
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
67 |
/* the cinecast version of the player is supposed to pause when the user clicks on the button */ |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
68 |
if (this.cinecast_version) |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
69 |
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
|
70 |
.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
|
71 |
function() { if (!_this._Popcorn.media.paused) _this._Popcorn.pause() }); |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
72 |
|
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
73 |
/* the cinecast version 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
|
74 |
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
|
75 |
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
|
76 |
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
|
77 |
*/ |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
78 |
if (this.cinecast_version) { |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
79 |
var legal_ids; |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
80 |
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
|
81 |
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
|
82 |
else |
|
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.getNonTweetIds()[0]; |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
84 |
|
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
85 |
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
|
86 |
var i; |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
87 |
|
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
88 |
for (i in annotations) { |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
89 |
var annotation = annotations[i]; |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
90 |
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
|
91 |
&& 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
|
92 |
continue; |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
93 |
} |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
94 |
|
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
95 |
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
|
96 |
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
|
97 |
console.log(annotation); |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
98 |
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
|
99 |
_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
|
100 |
|
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
101 |
_this._currentAnnotation = annotation; |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
102 |
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
|
103 |
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
|
104 |
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
|
105 |
_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
|
106 |
} }(annotation) |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
107 |
}; |
|
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 |
this._Popcorn.code(code); |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
110 |
} |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
111 |
} |
| 543 | 112 |
|
|
553
10d08f43c534
widget works now more or less like in samuel's crea.
hamidouk
parents:
549
diff
changeset
|
113 |
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
|
114 |
|
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
115 |
if (!this.cinecast_version) |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
116 |
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
|
117 |
IriSP.wrap(this, this.handleAnnotateSignal)); |
| 543 | 118 |
}; |
119 |
||
120 |
IriSP.createAnnotationWidget.prototype.handleAnnotateSignal = function() { |
|
|
614
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
121 |
// note : this signal is only handled by the non-cinecast version. |
| 543 | 122 |
if (this._hidden == false) { |
123 |
this.selector.hide(); |
|
124 |
this._hidden = true; |
|
| 570 | 125 |
|
126 |
// free the arrow. |
|
127 |
this._Popcorn.trigger("IriSP.ArrowWidget.releaseArrow"); |
|
| 543 | 128 |
} else { |
|
614
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
129 |
this.showStartScreen(); |
| 543 | 130 |
this.selector.show(); |
131 |
this._hidden = false; |
|
| 563 | 132 |
|
133 |
// block the arrow. |
|
134 |
this._Popcorn.trigger("IriSP.ArrowWidget.blockArrow"); |
|
| 543 | 135 |
} |
| 549 | 136 |
}; |
137 |
||
|
614
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
138 |
|
| 549 | 139 |
/** watch for changes in the textfield and change the buttons accordingly */ |
140 |
IriSP.createAnnotationWidget.prototype.handleTextChanges = function(event) { |
|
141 |
var contents = this.selector.find(".Ldt-createAnnotation-Description").val(); |
|
142 |
||
143 |
for(var keyword in this.ids) { |
|
144 |
|
|
145 |
var id = this.ids[keyword]; |
|
146 |
||
147 |
if (contents.indexOf(keyword) != -1) { |
|
148 |
/* the word is present in the textarea but the button is not toggled */ |
|
149 |
if (this.selector.find("#" + id).hasClass("Ldt-createAnnotation-absent-keyword")) |
|
150 |
this.selector.find("#" + id).removeClass("Ldt-createAnnotation-absent-keyword") |
|
151 |
.addClass("Ldt-createAnnotation-present-keyword"); |
|
152 |
} else { |
|
153 |
/* the word is absent from the textarea but the button is toggled */ |
|
154 |
if (this.selector.find("#" + id).hasClass("Ldt-createAnnotation-present-keyword")) { |
|
155 |
this.selector.find("#" + id).removeClass("Ldt-createAnnotation-present-keyword") |
|
156 |
.addClass("Ldt-createAnnotation-absent-keyword"); |
|
157 |
} |
|
158 |
} |
|
159 |
} |
|
|
553
10d08f43c534
widget works now more or less like in samuel's crea.
hamidouk
parents:
549
diff
changeset
|
160 |
}; |
|
10d08f43c534
widget works now more or less like in samuel's crea.
hamidouk
parents:
549
diff
changeset
|
161 |
|
|
614
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
162 |
IriSP.createAnnotationWidget.prototype.showStartScreen = function() { |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
163 |
this.selector.find(".Ldt-createAnnotation-DoubleBorder").children().show(); |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
164 |
this.selector.find("Ldt-createAnnotation-Description").val(""); |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
165 |
this.selector.find(".Ldt-createAnnotation-endScreen").hide(); |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
166 |
}; |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
167 |
|
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
168 |
IriSP.createAnnotationWidget.prototype.showEndScreen = function() { |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
169 |
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
|
170 |
|
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
171 |
if (this.cinecast_version) { |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
172 |
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
|
173 |
} |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
174 |
|
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
175 |
var twStatus = IriSP.mkTweetUrl(document.location.href); |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
176 |
var gpStatus = IriSP.mkGplusUrl(document.location.href); |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
177 |
var fbStatus = IriSP.mkFbUrl(document.location.href); |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
178 |
|
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
179 |
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
|
180 |
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
|
181 |
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
|
182 |
|
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
183 |
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
|
184 |
}; |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
185 |
|
|
553
10d08f43c534
widget works now more or less like in samuel's crea.
hamidouk
parents:
549
diff
changeset
|
186 |
/** handle clicks on "send annotation" button */ |
|
10d08f43c534
widget works now more or less like in samuel's crea.
hamidouk
parents:
549
diff
changeset
|
187 |
IriSP.createAnnotationWidget.prototype.handleButtonClick = function(event) { |
| 597 | 188 |
var _this = this; |
|
561
a10e7b6fdb08
display an error message when the user forget to enter text.
hamidouk
parents:
553
diff
changeset
|
189 |
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
|
190 |
var contents = textfield.val(); |
|
a10e7b6fdb08
display an error message when the user forget to enter text.
hamidouk
parents:
553
diff
changeset
|
191 |
|
|
614
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
192 |
if (contents === "") { |
| 570 | 193 |
if (this.selector.find(".Ldt-createAnnotation-errorMessage").length === 0) { |
194 |
this.selector.find(".Ldt-createAnnotation-Container") |
|
195 |
.after(IriSP.templToHTML(IriSP.createAnnotation_errorMessage_template)); |
|
| 571 | 196 |
textfield.css("background-color", "#d93c71"); |
197 |
} else { |
|
198 |
this.selector.find(".Ldt-createAnnotation-errorMessage").show(); |
|
199 |
} |
|
|
614
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 |
textfield.one("js_mod propertychange keyup input paste", IriSP.wrap(this, function() { |
| 570 | 202 |
var contents = textfield.val(); |
| 611 | 203 |
|
| 570 | 204 |
if (contents !== "") { |
205 |
this.selector.find(".Ldt-createAnnotation-errorMessage").hide(); |
|
206 |
textfield.css("background-color", ""); |
|
207 |
} |
|
208 |
})); |
|
|
561
a10e7b6fdb08
display an error message when the user forget to enter text.
hamidouk
parents:
553
diff
changeset
|
209 |
} else { |
|
614
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
210 |
this.showEndScreen(); |
|
594
96af41097260
WIP - adapting the widget to the new segments conventions.
hamidouk
parents:
575
diff
changeset
|
211 |
|
|
96af41097260
WIP - adapting the widget to the new segments conventions.
hamidouk
parents:
575
diff
changeset
|
212 |
if (typeof(this._currentAnnotation) === "undefined") { |
|
96af41097260
WIP - adapting the widget to the new segments conventions.
hamidouk
parents:
575
diff
changeset
|
213 |
console.log("this._currentAnnotation undefined"); |
|
96af41097260
WIP - adapting the widget to the new segments conventions.
hamidouk
parents:
575
diff
changeset
|
214 |
return; |
|
96af41097260
WIP - adapting the widget to the new segments conventions.
hamidouk
parents:
575
diff
changeset
|
215 |
} |
|
96af41097260
WIP - adapting the widget to the new segments conventions.
hamidouk
parents:
575
diff
changeset
|
216 |
|
|
614
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
217 |
this.sendLdtData(contents, function() { |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
218 |
if (_this.cinecast_version) { |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
219 |
if (_this._Popcorn.media.paused) |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
220 |
_this._Popcorn.play(); |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
221 |
|
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
222 |
window.setTimeout(IriSP.wrap(_this, function() { this.showStartScreen(); }), 5000); |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
223 |
} |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
224 |
}); |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
225 |
} |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
226 |
}; |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
227 |
|
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
228 |
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
|
229 |
var _this = this; |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
230 |
var apiJson = {annotations : [{}], meta: {}}; |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
231 |
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
|
232 |
|
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
233 |
annotation["media"] = this._serializer.currentMedia()["id"]; |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
234 |
annotation["begin"] = this._currentAnnotation.begin; |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
235 |
annotation["end"] = this._currentAnnotation.end; |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
236 |
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
|
237 |
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
|
238 |
annotation["type"] = ""; |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
239 |
|
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
240 |
annotation["type_title"] = "Contributions"; |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
241 |
annotation.content = {}; |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
242 |
annotation.content["data"] = contents; |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
243 |
|
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
244 |
var meta = apiJson["meta"]; |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
245 |
meta.creator = "An User"; |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
246 |
meta.created = Date().toString(); |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
247 |
|
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
248 |
annotation["tags"] = []; |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
249 |
|
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
250 |
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
|
251 |
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
|
252 |
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
|
253 |
annotation["tags"].push(keyword); |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
254 |
} |
|
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 |
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
|
257 |
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
|
258 |
|
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
259 |
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
|
260 |
{platf_url: IriSP.platform_url, id: project_id}); |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
261 |
|
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
262 |
IriSP.jQuery.ajax({ |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
263 |
url: url, |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
264 |
type: 'PUT', |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
265 |
contentType: 'application/json', |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
266 |
data: jsonString, |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
267 |
dataType: 'json', |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
268 |
success: function(json, textStatus, XMLHttpRequest) { |
| 597 | 269 |
/* add the annotation to the annotations and tell the world */ |
270 |
delete annotation.tags; |
|
271 |
annotation.content.description = annotation.content.data; |
|
272 |
delete annotation.content.data; |
|
273 |
annotation.id = json.annotations[0].id; |
|
274 |
annotation.title = _this._currentAnnotation.content.title; |
|
| 606 | 275 |
annotation.meta = meta; |
276 |
annotation.meta["id-ref"] = annotation["type"]; |
|
| 597 | 277 |
// everything is shared so there's no need to propagate the change |
278 |
_this._serializer._data.annotations.push(annotation); |
|
279 |
_this._Popcorn.trigger("IriSP.createAnnotationWidget.addedAnnotation"); |
|
|
614
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
280 |
callback(); |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
281 |
}, |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
282 |
error: |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
283 |
function() { |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
284 |
console.log("an error occured while contacting " |
|
116de1c38a7d
lots of refactoring for this widget, as well as changes to support the cinecast
hamidouk
parents:
611
diff
changeset
|
285 |
+ url + " and sending " + jsonString); } }); |
| 543 | 286 |
}; |