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