'use strict'; oml.ui.editDialog = function() { var arrayKeys = [ 'author', 'place', 'publisher', 'language' ], ids = oml.user.ui.listSelection, 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(), height: 256, removeOnClose: true, title: Ox._('Edit Metadata for {0}', [ Ox.formatNumber(ids.length) + ' ' + ( ids.length == 1 ? 'Book' : 'Books' ) ]), width: 512 }); getMetadata(); 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 = {}, isMixed = {}, items = result.data.items; keys.forEach(function(key) { var isArray = Ox.contains(arrayKeys, key), values = items.map(function(item) { return item[key]; }); if (isArray) { values = values.map(function(value) { return (value || []).join(separator); }); } 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) }); }); } return that; };