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