284 |
284 |
285 /* Get the displayable types |
285 /* Get the displayable types |
286 We've got to jump through a few hoops because the json sometimes defines |
286 We've got to jump through a few hoops because the json sometimes defines |
287 fields with underscores and sometimes with dashes |
287 fields with underscores and sometimes with dashes |
288 */ |
288 */ |
289 var annotation_types = this._data.views[0]["annotation_types"]; |
289 var annotation_types = IriSP.get_aliased(this._data.views[0], ["annotation_types", "annotation-types"]); |
290 if (IriSP.null_or_undefined(annotation_types)) { |
290 if (annotation_types === null) { |
291 annotation_types = this._data.views[0]["annotation-types"]; |
|
292 if (IriSP.null_or_undefined(annotation_types)) { |
|
293 console.log("neither view.annotation_types nor view.annotation-types are defined"); |
291 console.log("neither view.annotation_types nor view.annotation-types are defined"); |
294 return; |
292 return; |
295 } |
293 } |
296 } |
294 |
297 |
295 var available_types = IriSP.get_aliased(this._data, ["annotation_types", "annotation-types"]); |
298 var available_types = this._data["annotation_types"]; |
296 if (available_types === null) { |
299 if (IriSP.null_or_undefined(available_types)) { |
297 console.log("neither view.annotation_types nor view.annotation-types are defined"); |
300 available_types = this._data["annotation-types"]; |
|
301 if (IriSP.null_or_undefined(available_types)) { |
|
302 console.log("neither annotation_types nor annotation-types are defined"); |
|
303 return; |
298 return; |
304 } |
|
305 } |
299 } |
306 |
300 |
307 var potential_types = []; |
301 var potential_types = []; |
308 |
302 |
309 // Get the list of types which contain "Tw" in their content |
303 // Get the list of types which contain "Tw" in their content |
310 for (var i = 0; i < available_types.length; i++) { |
304 for (var i = 0; i < available_types.length; i++) { |
311 if (/Tw/i.test(available_types[i]["dc:title"])) { |
305 if (/Tw/i.test(IriSP.get_aliased(available_types[i], ['dc:title', 'title']))) { |
312 potential_types.push(available_types[i].id); |
306 potential_types.push(available_types[i].id); |
313 } |
307 } |
314 } |
308 } |
315 |
309 |
316 // Get the intersection of both. |
310 // Get the intersection of both. |
327 |
321 |
328 /* Get the displayable types |
322 /* Get the displayable types |
329 We've got to jump through a few hoops because the json sometimes defines |
323 We've got to jump through a few hoops because the json sometimes defines |
330 fields with underscores and sometimes with dashes |
324 fields with underscores and sometimes with dashes |
331 */ |
325 */ |
332 var annotation_types = this._data.views[0]["annotation_types"]; |
326 var annotation_types = IriSP.get_aliased(this._data.views[0], ["annotation_types", "annotation-types"]); |
333 if (IriSP.null_or_undefined(annotation_types)) { |
327 if (annotation_types === null) { |
334 annotation_types = this._data.views[0]["annotation-types"]; |
|
335 if (IriSP.null_or_undefined(annotation_types)) { |
|
336 console.log("neither view.annotation_types nor view.annotation-types are defined"); |
328 console.log("neither view.annotation_types nor view.annotation-types are defined"); |
337 return; |
329 return; |
338 } |
330 } |
339 } |
331 |
340 |
332 var available_types = IriSP.get_aliased(this._data, ["annotation_types", "annotation-types"]); |
341 var available_types = this._data["annotation_types"]; |
333 if (available_types === null) { |
342 if (IriSP.null_or_undefined(available_types)) { |
334 console.log("neither view.annotation_types nor view.annotation-types are defined"); |
343 available_types = this._data["annotation-types"]; |
|
344 if (IriSP.null_or_undefined(available_types)) { |
|
345 console.log("neither annotation_types nor annotation-types are defined"); |
|
346 return; |
335 return; |
347 } |
|
348 } |
336 } |
349 |
337 |
350 var potential_types = []; |
338 var potential_types = []; |
351 |
339 |
352 // Get the list of types which do not contain "Tw" in their content |
340 // Get the list of types which do not contain "Tw" in their content |
353 for (var i = 0; i < available_types.length; i++) { |
341 for (var i = 0; i < available_types.length; i++) { |
354 if (!(/Tw/i.test(available_types[i]["dc:title"]))) { |
342 if (!(/Tw/i.test(IriSP.get_aliased(available_types[i], ['dc:title', 'title'])))) { |
355 potential_types.push(available_types[i].id); |
343 potential_types.push(available_types[i].id); |
356 } |
344 } |
357 } |
345 } |
358 |
346 |
359 // Get the intersection of both. |
347 // Get the intersection of both. |
365 |
353 |
366 /** return the id of the ligne de temps which contains name |
354 /** return the id of the ligne de temps which contains name |
367 @param name of the ligne de temps |
355 @param name of the ligne de temps |
368 */ |
356 */ |
369 IriSP.JSONSerializer.prototype.getId = function(name) { |
357 IriSP.JSONSerializer.prototype.getId = function(name) { |
370 if (IriSP.null_or_undefined(this._data["annotation-types"])) |
358 var available_types = IriSP.get_aliased(this._data, ["annotation_types", "annotation-types"]); |
|
359 |
|
360 if (available_types == null) |
371 return; |
361 return; |
372 |
362 |
373 name = name.toUpperCase(); |
363 name = name.toUpperCase(); |
374 var e; |
364 var e; |
375 e = IriSP.underscore.find(this._data["annotation-types"], |
365 e = IriSP.underscore.find(available_types, |
376 function(entry) { |
366 function(entry) { |
377 if (IriSP.null_or_undefined(entry["dc:title"])) |
367 if (IriSP.get_aliased(entry, ['dc:title', 'title']) === null) |
378 return false; |
368 return false; |
379 |
369 return (entry["dc:title"].toUpperCase().indexOf(name) !== -1); |
380 return (entry["dc:title"].toUpperCase().indexOf(name) !== -1) }); |
370 }); |
381 |
371 |
382 if (typeof(e) === "undefined") |
372 if (typeof(e) === "undefined") |
383 return; |
373 return; |
384 |
374 |
385 var id = e.id; |
375 var id = e.id; |
389 |
379 |
390 /** return the list of id's of the ligne de temps which contains name |
380 /** return the list of id's of the ligne de temps which contains name |
391 @param name of the ligne de temps |
381 @param name of the ligne de temps |
392 */ |
382 */ |
393 IriSP.JSONSerializer.prototype.getIds = function(name) { |
383 IriSP.JSONSerializer.prototype.getIds = function(name) { |
394 if (IriSP.null_or_undefined(this._data["annotation-types"])) |
384 var available_types = IriSP.get_aliased(this._data, ["annotation_types", "annotation-types"]); |
|
385 |
|
386 if (available_types == null) |
395 return; |
387 return; |
396 |
388 |
397 name = name.toUpperCase(); |
389 name = name.toUpperCase(); |
398 var e = []; |
390 var e = []; |
399 e = IriSP.underscore.filter(this._data["annotation-types"], |
391 e = IriSP.underscore.filter(available_types, |
400 function(entry) { return (entry["dc:title"].toUpperCase().indexOf(name) !== -1) }); |
392 function(entry) { return (IriSP.get_aliased(entry, ['dc:title', 'title']).toUpperCase().indexOf(name) !== -1) }); |
401 return IriSP.underscore.pluck(e, "id"); |
393 return IriSP.underscore.pluck(e, "id"); |
402 }; |
394 }; |
403 |
395 |
404 /** return the id of the ligne de temps named "Chapitrage" */ |
396 /** return the id of the ligne de temps named "Chapitrage" */ |
405 IriSP.JSONSerializer.prototype.getChapitrage = function() { |
397 IriSP.JSONSerializer.prototype.getChapitrage = function() { |