2016-01-05 08:34:07 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
oml.ui.editDialog = function() {
|
|
|
|
|
2016-01-12 04:44:33 +00:00
|
|
|
var ui = oml.user.ui,
|
|
|
|
arrayKeys = [
|
2016-01-05 14:43:57 +00:00
|
|
|
'author', 'place', 'publisher', 'language'
|
|
|
|
],
|
2016-01-12 04:44:33 +00:00
|
|
|
hasChanged = false,
|
|
|
|
ids = ui.listSelection,
|
2016-01-05 08:34:07 +00:00
|
|
|
keys = [
|
2016-01-12 04:44:33 +00:00
|
|
|
'title', 'author',
|
|
|
|
'publisher', 'place', 'date',
|
|
|
|
'series', 'edition', 'language', 'pages',
|
|
|
|
'categories', 'isbn', 'description', 'tableofcontents'
|
2016-01-05 08:34:07 +00:00
|
|
|
],
|
|
|
|
mixed = ' ',
|
|
|
|
separator = '; ',
|
|
|
|
tooltip = Ox._('Doubleclick to edit'),
|
|
|
|
|
|
|
|
$info = Ox.Element()
|
|
|
|
.addClass('OxSelectable')
|
|
|
|
.css({padding: '16px'});
|
|
|
|
|
|
|
|
var that = Ox.Dialog({
|
|
|
|
buttons: [
|
|
|
|
Ox.Button({
|
2016-01-12 04:44:33 +00:00
|
|
|
style: 'squared',
|
2016-01-05 08:34:07 +00:00
|
|
|
title: Ox._('Done')
|
|
|
|
})
|
|
|
|
.bindEvent({
|
|
|
|
click: function() {
|
2016-01-12 04:44:33 +00:00
|
|
|
if (!ui.updateResults && hasChanged) {
|
2016-01-12 04:49:27 +00:00
|
|
|
Ox.Request.clearCache();
|
2016-01-12 04:44:33 +00:00
|
|
|
oml.$ui.info.updateElement();
|
2016-01-12 08:52:20 +00:00
|
|
|
oml.reloadLists();
|
2016-01-12 04:44:33 +00:00
|
|
|
}
|
2016-01-05 08:34:07 +00:00
|
|
|
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-12 04:44:33 +00:00
|
|
|
}),
|
|
|
|
|
|
|
|
$updateCheckbox = Ox.Checkbox({
|
|
|
|
style: 'squared',
|
|
|
|
title: Ox._('Update Results in the Background'),
|
|
|
|
value: ui.updateResults
|
|
|
|
})
|
|
|
|
.css({
|
|
|
|
float: 'left',
|
|
|
|
margin: '4px'
|
|
|
|
})
|
|
|
|
.bindEvent({
|
|
|
|
change: function(data) {
|
|
|
|
oml.UI.set({updateResults: data.value});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$($updateCheckbox.find('.OxButton')[0]).css({margin: 0});
|
|
|
|
$(that.find('.OxBar')[1]).append($updateCheckbox);
|
2016-01-05 08:34:07 +00:00
|
|
|
|
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({
|
2016-01-12 04:44:33 +00:00
|
|
|
content: oml.ui.infoView(data, isMixed).bindEvent({
|
|
|
|
change: function() {
|
|
|
|
hasChanged = true;
|
|
|
|
}
|
|
|
|
})
|
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
|
|
|
};
|