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