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