2016-01-05 08:34:07 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
oml.ui.editDialog = function() {
|
|
|
|
|
2016-01-05 14:43:57 +00:00
|
|
|
var arrayKeys = [
|
|
|
|
'author', 'place', 'publisher', 'language'
|
|
|
|
],
|
|
|
|
ids = oml.user.ui.listSelection,
|
2016-01-05 08:34:07 +00:00
|
|
|
keys = [
|
|
|
|
'title', 'author', 'place', 'publisher', 'date',
|
|
|
|
'edition', 'language', 'pages', 'description'
|
|
|
|
],
|
|
|
|
mixed = ' ',
|
|
|
|
separator = '; ',
|
|
|
|
tooltip = Ox._('Doubleclick to edit'),
|
|
|
|
|
|
|
|
$info = Ox.Element()
|
|
|
|
.addClass('OxSelectable')
|
|
|
|
.css({padding: '16px'});
|
|
|
|
|
|
|
|
var that = Ox.Dialog({
|
|
|
|
buttons: [
|
|
|
|
Ox.Button({
|
|
|
|
title: Ox._('Done')
|
|
|
|
})
|
|
|
|
.bindEvent({
|
|
|
|
click: function() {
|
|
|
|
that.close();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
],
|
|
|
|
closeButton: true,
|
|
|
|
content: Ox.LoadingScreen().start(),
|
2016-01-05 14:43:57 +00:00
|
|
|
height: 256,
|
2016-01-05 08:34:07 +00:00
|
|
|
removeOnClose: true,
|
|
|
|
title: Ox._('Edit Metadata for {0}', [
|
|
|
|
Ox.formatNumber(ids.length) + ' ' + (
|
|
|
|
ids.length == 1 ? 'Book' : 'Books'
|
|
|
|
)
|
|
|
|
]),
|
|
|
|
width: 512
|
|
|
|
});
|
|
|
|
|
2016-01-11 13:33:29 +00:00
|
|
|
getMetadata();
|
2016-01-05 08:34:07 +00:00
|
|
|
|
|
|
|
function getMetadata(callback) {
|
|
|
|
oml.api.find({
|
|
|
|
keys: keys,
|
|
|
|
query: {
|
|
|
|
conditions: ids.map(function(id) {
|
|
|
|
return {
|
|
|
|
key: 'id',
|
|
|
|
operator: '==',
|
|
|
|
value: id
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
operator: '|'
|
|
|
|
}
|
|
|
|
}, function(result) {
|
|
|
|
var data = {},
|
2016-01-11 13:33:29 +00:00
|
|
|
isMixed = {},
|
2016-01-05 08:34:07 +00:00
|
|
|
items = result.data.items;
|
|
|
|
keys.forEach(function(key) {
|
2016-01-05 18:06:57 +00:00
|
|
|
var isArray = Ox.contains(arrayKeys, key),
|
|
|
|
values = items.map(function(item) {
|
|
|
|
return item[key];
|
|
|
|
});
|
2016-01-05 08:34:07 +00:00
|
|
|
if (isArray) {
|
|
|
|
values = values.map(function(value) {
|
2016-01-05 18:13:35 +00:00
|
|
|
return (value || []).join(separator);
|
2016-01-05 08:34:07 +00:00
|
|
|
});
|
|
|
|
}
|
2016-01-11 13:33:29 +00:00
|
|
|
if (Ox.unique(values).length > 1) {
|
|
|
|
isMixed[key] = true;
|
|
|
|
}
|
|
|
|
data[key] = isMixed[key] ? null
|
|
|
|
: isArray ? values[0].split(separator)
|
|
|
|
: values[0];
|
|
|
|
});
|
|
|
|
that.options({
|
|
|
|
content: oml.ui.infoView(data, isMixed)
|
2016-01-05 08:34:07 +00:00
|
|
|
});
|
2016-01-09 07:04:51 +00:00
|
|
|
});
|
2016-01-08 10:11:24 +00:00
|
|
|
}
|
|
|
|
|
2016-01-05 08:34:07 +00:00
|
|
|
return that;
|
|
|
|
|
2016-01-05 10:28:18 +00:00
|
|
|
};
|