|
34
|
1 |
Rkns.Ldt = {} |
|
26
|
2 |
|
|
34
|
3 |
Rkns.Ldt.ProjectBin = Rkns.Utils.inherit(Rkns._BaseBin); |
|
|
4 |
|
|
|
5 |
Rkns.Ldt.ProjectBin.prototype.tagTemplate = Rkns._.template( |
|
58
|
6 |
'<li class="Rk-Bin-Item" data-image="<%-static_url%>img/ldt-tag.png" data-uri="<%=ldt_platform%>ldtplatform/ldt/front/search/?search=<%=encodedtitle%>&field=all" data-title="<%-title%>" data-description="Tag \'<%-title%>\'">' |
|
|
7 |
+ '<img class="Rk-Ldt-Tag-Icon" src="<%-static_url%>img/ldt-tag.png" /><h4><%=htitle%></h4><div class="Rk-Clear"></div></li>' |
|
26
|
8 |
); |
|
|
9 |
|
|
34
|
10 |
Rkns.Ldt.ProjectBin.prototype.annotationTemplate = Rkns._.template( |
|
37
|
11 |
'<li class="Rk-Bin-Item" data-image="<%=image%>" data-uri="<%=ldt_platform%>ldtplatform/ldt/front/player/<%=mediaid%>/#id=<%=annotationid%>" data-title="<%-title%>" data-description="<%-description%>">' |
|
44
|
12 |
+ '<img class="Rk-Ldt-Annotation-Icon" src="<%=image%>"/><h4><%=htitle%></h4><p><%=hdescription%></p><p>Start: <%=start%>, End: <%=end%>, Duration: <%=duration%></p><div class="Rk-Clear"></div></li>' |
|
26
|
13 |
); |
|
|
14 |
|
|
34
|
15 |
Rkns.Ldt.ProjectBin.prototype._init = function(_renkan, _opts) { |
|
61
|
16 |
this.renkan = _renkan; |
|
26
|
17 |
this.proj_id = _opts.project_id; |
|
28
|
18 |
this.ldt_platform = _opts.ldt_platform || "http://ldt.iri.centrepompidou.fr/"; |
|
26
|
19 |
this.title_$.html(_opts.title); |
|
64
|
20 |
this.title_icon_$.addClass('Rk-Ldt-Title-Icon'); |
|
42
|
21 |
this.refresh(); |
|
|
22 |
} |
|
|
23 |
|
|
44
|
24 |
Rkns.Ldt.ProjectBin.prototype.render = function(searchstr) { |
|
|
25 |
if (searchstr) { |
|
|
26 |
var rxbase = searchstr.replace(/(\W)/g,'\\$1'), |
|
|
27 |
_rgxp = new RegExp('('+rxbase+')','gi'), |
|
|
28 |
rxtest = new RegExp(rxbase,'i') |
|
|
29 |
} |
|
|
30 |
function highlight(_text) { |
|
|
31 |
return searchstr ? _text.replace(_rgxp, "<span class='searchmatch'>$1</span>") : _text; |
|
|
32 |
} |
|
26
|
33 |
function convertTC(_ms) { |
|
|
34 |
function pad(_n) { |
|
|
35 |
var _res = _n.toString(); |
|
|
36 |
while (_res.length < 2) { |
|
|
37 |
_res = '0' + _res; |
|
|
38 |
} |
|
|
39 |
return _res; |
|
|
40 |
} |
|
|
41 |
var _totalSeconds = Math.abs(Math.floor(_ms/1000)), |
|
|
42 |
_hours = Math.floor(_totalSeconds / 3600), |
|
|
43 |
_minutes = (Math.floor(_totalSeconds / 60) % 60), |
|
|
44 |
_seconds = _totalSeconds % 60, |
|
|
45 |
_res = ''; |
|
|
46 |
if (_hours) { |
|
|
47 |
_res += pad(_hours) + ':' |
|
|
48 |
} |
|
|
49 |
_res += pad(_minutes) + ':' + pad(_seconds); |
|
|
50 |
return _res; |
|
|
51 |
} |
|
44
|
52 |
|
|
|
53 |
var _html = '<li><h3>Tags</h3></li>', |
|
|
54 |
_projtitle = this.data.meta["dc:title"], |
|
|
55 |
_this = this, |
|
|
56 |
count = 0; |
|
|
57 |
_this.title_$.text('LDT Project: "' + _projtitle + '"'); |
|
|
58 |
Rkns._(_this.data.tags).map(function(_tag) { |
|
|
59 |
var _title = _tag.meta["dc:title"]; |
|
|
60 |
if (searchstr && !rxtest.test(_title)) { |
|
|
61 |
return; |
|
|
62 |
} |
|
|
63 |
count++; |
|
|
64 |
_html += _this.tagTemplate({ |
|
|
65 |
ldt_platform: _this.ldt_platform, |
|
|
66 |
title: _title, |
|
|
67 |
htitle: highlight(_title), |
|
58
|
68 |
encodedtitle : encodeURIComponent(_title), |
|
|
69 |
static_url: _this.renkan.static_url |
|
44
|
70 |
}) |
|
|
71 |
}); |
|
|
72 |
_html += '<li><h3>Annotations</h3></li>'; |
|
|
73 |
Rkns._(_this.data.annotations).map(function(_annotation) { |
|
|
74 |
var _description = _annotation.content.description, |
|
|
75 |
_title = _annotation.content.title.replace(_description,""); |
|
|
76 |
if (searchstr && !rxtest.test(_title) && !rxtest.test(_description)) { |
|
|
77 |
return; |
|
|
78 |
} |
|
|
79 |
count++; |
|
|
80 |
var _duration = _annotation.end - _annotation.begin, |
|
|
81 |
_img = ( |
|
|
82 |
(_annotation.content && _annotation.content.img && _annotation.content.img.src) |
|
|
83 |
? _annotation.content.img.src |
|
58
|
84 |
: ( _duration ? _this.renkan.static_url+"img/ldt-segment.png" : _this.renkan.static_url+"img/ldt-point.png" ) |
|
44
|
85 |
); |
|
|
86 |
_html += _this.annotationTemplate({ |
|
|
87 |
ldt_platform: _this.ldt_platform, |
|
|
88 |
title: _title, |
|
|
89 |
htitle: highlight(_title), |
|
|
90 |
description: _description, |
|
|
91 |
hdescription: highlight(_description), |
|
|
92 |
start: convertTC(_annotation.begin), |
|
|
93 |
end: convertTC(_annotation.end), |
|
|
94 |
duration: convertTC(_duration), |
|
|
95 |
mediaid: _annotation.media, |
|
|
96 |
annotationid: _annotation.id, |
|
58
|
97 |
image: _img, |
|
|
98 |
static_url: _this.renkan.static_url |
|
44
|
99 |
}); |
|
|
100 |
}); |
|
|
101 |
|
|
|
102 |
this.main_$.html(_html); |
|
|
103 |
if (searchstr && count) { |
|
|
104 |
this.count_$.text(count).show(); |
|
|
105 |
} else { |
|
|
106 |
this.count_$.hide(); |
|
|
107 |
} |
|
|
108 |
if (searchstr && !count) { |
|
|
109 |
this.$.hide(); |
|
|
110 |
} else { |
|
|
111 |
this.$.show(); |
|
|
112 |
} |
|
61
|
113 |
this.renkan.resizeBins(); |
|
44
|
114 |
} |
|
|
115 |
|
|
|
116 |
Rkns.Ldt.ProjectBin.prototype.refresh = function() { |
|
|
117 |
var _this = this; |
|
42
|
118 |
Rkns.$.ajax({ |
|
|
119 |
url: this.ldt_platform + 'ldtplatform/ldt/cljson/id/' + this.proj_id, |
|
|
120 |
dataType: "jsonp", |
|
|
121 |
success: function(_data) { |
|
44
|
122 |
_this.data = _data; |
|
|
123 |
_this.render(); |
|
26
|
124 |
} |
|
42
|
125 |
}); |
|
64
|
126 |
} |
|
|
127 |
|
|
|
128 |
Rkns.Ldt.Search = function(_renkan, _opts) { |
|
|
129 |
this.renkan = _renkan; |
|
|
130 |
this.lang = _opts.lang || "en"; |
|
|
131 |
} |
|
|
132 |
|
|
|
133 |
Rkns.Ldt.Search.prototype.getBgClass = function() { |
|
|
134 |
return "Rk-Ldt-Icon"; |
|
|
135 |
} |
|
|
136 |
|
|
|
137 |
Rkns.Ldt.Search.prototype.getSearchTitle = function() { |
|
66
|
138 |
return this.renkan.translate("Lignes de Temps"); |
|
64
|
139 |
} |
|
|
140 |
|
|
|
141 |
Rkns.Ldt.Search.prototype.search = function(_q) { |
|
|
142 |
this.renkan.tabs.push( |
|
|
143 |
new Rkns.Ldt.ResultsBin(this.renkan, { |
|
|
144 |
search: _q |
|
|
145 |
}) |
|
|
146 |
); |
|
|
147 |
} |
|
|
148 |
|
|
|
149 |
Rkns.Ldt.ResultsBin = Rkns.Utils.inherit(Rkns._BaseBin); |
|
|
150 |
|
|
|
151 |
Rkns.Ldt.ResultsBin.prototype.segmentTemplate = Rkns._.template( |
|
|
152 |
'<li class="Rk-Bin-Item" data-image="<%=image%>" data-uri="<%=ldt_platform%>ldtplatform/ldt/front/player/<%=mediaid%>/<%=projectid%>/<%=cuttingid%>/#id=<%=annotationid%>" data-title="<%-title%>" data-description="<%-description%>">' |
|
|
153 |
+ '<img class="Rk-Ldt-Annotation-Icon" src="<%=image%>"/><h4><%=htitle%></h4><p><%=hdescription%></p><p>Start: <%=start%>, End: <%=end%>, Duration: <%=duration%></p><div class="Rk-Clear"></div></li>' |
|
|
154 |
); |
|
|
155 |
|
|
|
156 |
Rkns.Ldt.ResultsBin.prototype._init = function(_renkan, _opts) { |
|
|
157 |
this.renkan = _renkan; |
|
|
158 |
this.ldt_platform = _opts.ldt_platform || "http://ldt.iri.centrepompidou.fr/"; |
|
|
159 |
this.max_results = _opts.max_results || 50; |
|
|
160 |
this.search = _opts.search; |
|
|
161 |
this.title_$.html('Lignes de Temps: "' + _opts.search + '"'); |
|
|
162 |
this.title_icon_$.addClass('Rk-Ldt-Title-Icon'); |
|
|
163 |
this.refresh(); |
|
|
164 |
} |
|
|
165 |
|
|
|
166 |
Rkns.Ldt.ResultsBin.prototype.render = function(searchstr) { |
|
|
167 |
if (searchstr) { |
|
|
168 |
var rxbase = searchstr.replace(/(\W)/g,'\\$1'), |
|
|
169 |
_rgxp = new RegExp('('+rxbase+')','gi'), |
|
|
170 |
rxtest = new RegExp(rxbase,'i') |
|
|
171 |
} |
|
|
172 |
function highlight(_text) { |
|
|
173 |
return searchstr ? _text.replace(_rgxp, "<span class='searchmatch'>$1</span>") : _text; |
|
|
174 |
} |
|
|
175 |
function convertTC(_ms) { |
|
|
176 |
function pad(_n) { |
|
|
177 |
var _res = _n.toString(); |
|
|
178 |
while (_res.length < 2) { |
|
|
179 |
_res = '0' + _res; |
|
|
180 |
} |
|
|
181 |
return _res; |
|
|
182 |
} |
|
|
183 |
var _totalSeconds = Math.abs(Math.floor(_ms/1000)), |
|
|
184 |
_hours = Math.floor(_totalSeconds / 3600), |
|
|
185 |
_minutes = (Math.floor(_totalSeconds / 60) % 60), |
|
|
186 |
_seconds = _totalSeconds % 60, |
|
|
187 |
_res = ''; |
|
|
188 |
if (_hours) { |
|
|
189 |
_res += pad(_hours) + ':' |
|
|
190 |
} |
|
|
191 |
_res += pad(_minutes) + ':' + pad(_seconds); |
|
|
192 |
return _res; |
|
|
193 |
} |
|
|
194 |
|
|
|
195 |
var _html = '', |
|
|
196 |
_this = this, |
|
|
197 |
count = 0; |
|
|
198 |
Rkns._(_this.data.objects).each(function(_segment) { |
|
|
199 |
var _description = _segment.abstract, |
|
|
200 |
_title = _segment.title; |
|
|
201 |
if (searchstr && !rxtest.test(_title) && !rxtest.test(_description)) { |
|
|
202 |
return; |
|
|
203 |
} |
|
|
204 |
count++; |
|
|
205 |
var _duration = _segment.duration, |
|
|
206 |
_begin = _segment.start_ts, |
|
|
207 |
_end = + _segment.duration + _begin |
|
|
208 |
_img = ( |
|
|
209 |
_duration |
|
|
210 |
? _this.renkan.static_url + "img/ldt-segment.png" |
|
|
211 |
: _this.renkan.static_url + "img/ldt-point.png" |
|
|
212 |
); |
|
|
213 |
_html += _this.segmentTemplate({ |
|
|
214 |
ldt_platform: _this.ldt_platform, |
|
|
215 |
title: _title, |
|
|
216 |
htitle: highlight(_title), |
|
|
217 |
description: _description, |
|
|
218 |
hdescription: highlight(_description), |
|
|
219 |
start: convertTC(_begin), |
|
|
220 |
end: convertTC(_end), |
|
|
221 |
duration: convertTC(_duration), |
|
|
222 |
mediaid: _segment.iri_id, |
|
|
223 |
projectid: _segment.project_id, |
|
|
224 |
cuttingid: _segment.cutting_id, |
|
|
225 |
annotationid: _segment.element_id, |
|
|
226 |
image: _img |
|
|
227 |
}); |
|
|
228 |
}); |
|
|
229 |
|
|
|
230 |
this.main_$.html(_html); |
|
|
231 |
if (searchstr && count) { |
|
|
232 |
this.count_$.text(count).show(); |
|
|
233 |
} else { |
|
|
234 |
this.count_$.hide(); |
|
|
235 |
} |
|
|
236 |
if (searchstr && !count) { |
|
|
237 |
this.$.hide(); |
|
|
238 |
} else { |
|
|
239 |
this.$.show(); |
|
|
240 |
} |
|
|
241 |
this.renkan.resizeBins(); |
|
|
242 |
} |
|
|
243 |
|
|
|
244 |
Rkns.Ldt.ResultsBin.prototype.refresh = function() { |
|
|
245 |
var _this = this; |
|
|
246 |
Rkns.$.ajax({ |
|
|
247 |
url: this.ldt_platform + 'ldtplatform/api/ldt/1.0/segments/search/', |
|
|
248 |
data: { |
|
|
249 |
format: "jsonp", |
|
|
250 |
q: this.search, |
|
|
251 |
limit: this.max_results |
|
|
252 |
}, |
|
|
253 |
dataType: "jsonp", |
|
|
254 |
success: function(_data) { |
|
|
255 |
_this.data = _data; |
|
|
256 |
_this.render(); |
|
|
257 |
} |
|
|
258 |
}); |
|
26
|
259 |
} |