From b377956a13e330a98edf3db982b33ff7c614adb9 Mon Sep 17 00:00:00 2001 From: j Date: Thu, 26 Nov 2020 20:22:59 +0100 Subject: [PATCH] add option to add/remove values to listkeys in batchedit dialog --- static/js/addRemoveKeyDialog.js | 124 ++++++++++++++++++++++++++++++++ static/js/documentInfoView.js | 7 ++ static/js/infoView.js | 7 ++ 3 files changed, 138 insertions(+) create mode 100644 static/js/addRemoveKeyDialog.js diff --git a/static/js/addRemoveKeyDialog.js b/static/js/addRemoveKeyDialog.js new file mode 100644 index 000000000..107d55bce --- /dev/null +++ b/static/js/addRemoveKeyDialog.js @@ -0,0 +1,124 @@ + +pandora.ui.addRemoveKeyDialog = function(options) { + var item = Ox.getObjectById(pandora.site.documentKeys, options.key), + itemTitle = Ox._(item ? item.title : options.key), + dialogTitle = Ox._('Add/Remove {0}', [itemTitle]); + + return Ox.Element('') + .addClass('OxLight') + .html(' [+]') + .css({ + cursor: 'pointer', + }) + .options({ + tooltip: dialogTitle + }) + .on('click', function(event) { + var add, remove, + dialog = Ox.Dialog({ + buttons: [ + Ox.Button({ + title: Ox._('Cancel') + }) + .css({margin: '4px 4px 4px 0'}) + .bindEvent({ + click: function() { + dialog.close() + } + }), + Ox.Button({ + title: Ox._('Update'), + width: 52 + }).bindEvent({ + click: function() { + var addValue = add.value() + var removeValue = remove.value() + if (!addValue.length && !removeValue.length) { + dialog.close() + return + } + var $loading = Ox.LoadingScreen({ + width: 256, + height: 64 + }) + dialog.options({ + content: $loading.start() + }) + var ids = options.ids; + pandora.api[{ + 'items': 'find', + 'documents': 'findDocuments', + }[options.section]]({ + query: { + conditions: [{key: 'id', operator: '&', value: ids}] + }, + range: [0, ids.length], + keys: ['id', options.key] + + }, function(result) { + Ox.serialForEach(result.data.items, + function(item, index, items, callback) { + var changed = false + var value = item[options.key] || [] + if (addValue.length && !Ox.contains(value, addValue)) { + value.push(addValue) + changed = true + } + if (removeValue.length && Ox.contains(value, removeValue)) { + value = value.filter(function(v) { return v != removeValue; } ) + changed = true + } + if (changed) { + var edit = {id: item.id} + edit[options.key] = value + pandora.api[{ + 'items': 'edit', + 'documents': 'editDocument', + }[options.section]](edit, function(response) { + callback() + }) + } else { + callback() + } + }, + function() { + $loading.stop() + dialog.close() + } + ) + }) + } + }) + ], + closeButton: true, + content: Ox.Element() + .css({ + padding: '8px' + }) + .append( + add = Ox.Input({ + width: 240, + type: 'input', + label: 'Add' + }) + ) + .append( + Ox.Element().html('').css({ + height: '8px' + }) + ) + .append( + remove = Ox.Input({ + width: 240, + type: 'input', + label: 'Remove' + }) + ), + height: 64, + removeOnClose: true, + title: dialogTitle, + width: 256 + }).open(); + }) + +} diff --git a/static/js/documentInfoView.js b/static/js/documentInfoView.js index 1ba47cf59..7dc7e86d0 100644 --- a/static/js/documentInfoView.js +++ b/static/js/documentInfoView.js @@ -572,6 +572,13 @@ pandora.ui.documentInfoView = function(data, isMixed) { } }) .appendTo($element); + if (isMixed[key] && Ox.contains(listKeys, key)) { + pandora.ui.addRemoveKeyDialog({ + ids: ui.collectionSelection, + key: key, + section: ui.section + }).appendTo($element) + } } }); $element.appendTo($text); diff --git a/static/js/infoView.js b/static/js/infoView.js index 5bd588ed5..17d886455 100644 --- a/static/js/infoView.js +++ b/static/js/infoView.js @@ -529,6 +529,13 @@ pandora.ui.infoView = function(data, isMixed) { } }) .appendTo($element); + if (isMixed[key] && Ox.contains(listKeys, key)) { + pandora.ui.addRemoveKeyDialog({ + ids: ui.listSelection, + key: key, + section: ui.section + }).appendTo($element) + } } }); $element.appendTo($text);