pandora/static/js/entity.js

28 lines
959 B
JavaScript
Raw Normal View History

2014-11-19 16:04:45 +00:00
// vim: et:ts=4:sw=4:sts=4:ft=javascript
'use strict';
pandora.ui.entity = function(options, callback) {
2014-11-20 16:12:52 +00:00
// options: {id, view}, view: 'annotation' or 'entity'
2014-11-20 12:24:28 +00:00
pandora.api.getEntity({
id: options.id
2014-11-20 13:19:46 +00:00
}, function(response) {
2014-11-20 12:24:28 +00:00
Ox.get(
2014-11-20 13:19:46 +00:00
'/static/html/entities.' + response.data.type + '.' + options.view + '.html',
2014-11-20 12:24:28 +00:00
function(html) {
2014-11-19 16:04:45 +00:00
html = html.replace(/\{(.+?)\}/g, function() {
var parts = arguments[1].split('|'),
2014-11-20 13:19:46 +00:00
value = response.data[parts[0]];
2014-11-19 16:04:45 +00:00
return Ox.isEmpty(value)
|| Ox.isNull(value)
|| Ox.isUndefined(value)
2014-11-20 16:12:52 +00:00
? Ox._(parts[1] || '<span class="OxLight">unknown</a>')
2014-11-19 16:04:45 +00:00
: Ox.isArray(value) ? value.join('; ')
: value;
});
callback(html);
2014-11-20 12:24:28 +00:00
}
);
});
2014-11-20 13:19:46 +00:00
};