import media dialog
This commit is contained in:
parent
926d3f0f09
commit
5ef6062613
2 changed files with 43 additions and 10 deletions
|
@ -153,6 +153,19 @@ examples (config.SITENAME.jsonc) that are part of this pan.do/ra distribution.
|
||||||
{"id": "embeds", "title": "Embeds"}
|
{"id": "embeds", "title": "Embeds"}
|
||||||
],
|
],
|
||||||
/*
|
/*
|
||||||
|
"importMetadata" defines what fields (as defined in "itemKeys") will get
|
||||||
|
populated with imported metadata. There is metadata for "title",
|
||||||
|
"description", "uploader", "date", "tags", "id", "url", and the value must
|
||||||
|
be a format string (like "{title} ({id})"). The type of the itemKeys must
|
||||||
|
be "string", ["string"], "text", "date" or "year". The last two only work
|
||||||
|
with "{date}".
|
||||||
|
*/
|
||||||
|
"importMetadata": {
|
||||||
|
"keywords": "{tags}",
|
||||||
|
"summary": "{description}",
|
||||||
|
"title": "{title}"
|
||||||
|
},
|
||||||
|
/*
|
||||||
"itemKeys" defines the metadata associated with each item. Required keys
|
"itemKeys" defines the metadata associated with each item. Required keys
|
||||||
are "*", "id" and "title". Annotation layers can be referenced too, which
|
are "*", "id" and "title". Annotation layers can be referenced too, which
|
||||||
makes them available in the find element. Adding a key with "annotations"
|
makes them available in the find element. Adding a key with "annotations"
|
||||||
|
|
|
@ -88,15 +88,36 @@ pandora.ui.importMediaDialog = function(options) {
|
||||||
function addMedia(url, callback) {
|
function addMedia(url, callback) {
|
||||||
pandora.api.getMediaUrlInfo({url: url}, function(result) {
|
pandora.api.getMediaUrlInfo({url: url}, function(result) {
|
||||||
result.data.items.forEach(function(info) {
|
result.data.items.forEach(function(info) {
|
||||||
pandora.api.add({title: info.title}, function(result) {
|
var infoKeys = [
|
||||||
var edit = {
|
"date", "description", "id", "tags",
|
||||||
date: info.date,
|
"title", "uploader", "url"
|
||||||
director: info.uploader ? [info.uploader] : [],
|
];
|
||||||
id: result.data.id,
|
var values = Ox.map(pandora.site.importMetadata, function(value, key) {
|
||||||
notes: info.url,
|
var type = pandora.site.itemKeys[key].type;
|
||||||
summary: info.description,
|
infoKeys.forEach(function(infoKey) {
|
||||||
topic: info.tags
|
infoValue = info[infoKey];
|
||||||
};
|
if (key == 'year') {
|
||||||
|
infoValue = infoValue.substr(0, 4);
|
||||||
|
}
|
||||||
|
if (infoKey == 'tags' && Ox.isArray(type)) {
|
||||||
|
infoValue = infoValue.join(', ');
|
||||||
|
}
|
||||||
|
value = value.replace(
|
||||||
|
new RegExp('\{' + infoKey '\}', 'g'), infoValue
|
||||||
|
);
|
||||||
|
});
|
||||||
|
if (Ox.isArray(type)) {
|
||||||
|
value = [value];
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
});
|
||||||
|
pandora.api.add({title: values.title || info.title}, function(result) {
|
||||||
|
var edit = Ox.extend(
|
||||||
|
Ox.filter(values, function(value, key) {
|
||||||
|
return key != 'title'
|
||||||
|
}),
|
||||||
|
{'id': result.data.id}
|
||||||
|
);
|
||||||
pandora.api.edit(edit, function(result) {
|
pandora.api.edit(edit, function(result) {
|
||||||
pandora.api.addMediaUrl({
|
pandora.api.addMediaUrl({
|
||||||
url: info.url,
|
url: info.url,
|
||||||
|
@ -104,7 +125,6 @@ pandora.ui.importMediaDialog = function(options) {
|
||||||
}, function(result) {
|
}, function(result) {
|
||||||
if (result.data.taskId) {
|
if (result.data.taskId) {
|
||||||
pandora.wait(result.data.taskId, function(result) {
|
pandora.wait(result.data.taskId, function(result) {
|
||||||
Ox.print('status?', result);
|
|
||||||
callback(edit.id);
|
callback(edit.id);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue