update identify dialog

This commit is contained in:
rlx 2016-01-12 09:33:27 +05:30
parent 8ad452378d
commit a8b154f3f5

View file

@ -6,7 +6,7 @@ oml.ui.identifyDialog = function(data) {
$form = Ox.Element(), $form = Ox.Element(),
$select = Ox.Select({ $findSelect = Ox.Select({
items: [ items: [
{id: 'title', title: Ox._('Title, Author etc.')}, {id: 'title', title: Ox._('Title, Author etc.')},
{id: 'isbn', title: Ox._('ISBN')}, {id: 'isbn', title: Ox._('ISBN')},
@ -21,15 +21,15 @@ oml.ui.identifyDialog = function(data) {
}) })
.bindEvent({ .bindEvent({
change: function(data) { change: function(data) {
$input.options({ $findInput.options({
value: getValue(data.value) value: getValue(data.value)
}).focusInput(true); }).focusInput(true);
} }
}), }),
$input = Ox.Input({ $findInput = Ox.Input({
style: 'squared', style: 'squared',
value: getValue($select.value()), value: getValue($findSelect.value()),
width: 480 width: 480
}) })
.bindEvent({ .bindEvent({
@ -39,7 +39,7 @@ oml.ui.identifyDialog = function(data) {
submit: findMetadata submit: findMetadata
}), }),
$button = Ox.Button({ $findButton = Ox.Button({
overlap: 'left', overlap: 'left',
style: 'squared', style: 'squared',
title: Ox._('Find'), title: Ox._('Find'),
@ -53,12 +53,12 @@ oml.ui.identifyDialog = function(data) {
elements: [ elements: [
Ox.FormElementGroup({ Ox.FormElementGroup({
elements: [ elements: [
$select, $findSelect,
$input $findInput
], ],
float: 'left' float: 'left'
}), }),
$button $findButton
], ],
float: 'right' float: 'right'
}) })
@ -67,6 +67,8 @@ oml.ui.identifyDialog = function(data) {
$list, $list,
$innerPanel,
$outerPanel = Ox.SplitPanel({ $outerPanel = Ox.SplitPanel({
elements: [ elements: [
{element: $form, size: 48}, {element: $form, size: 48},
@ -75,6 +77,25 @@ oml.ui.identifyDialog = function(data) {
orientation: 'vertical' orientation: 'vertical'
}), }),
$updateSelect = Ox.Select({
items: [
{id: 'replace', title: Ox._('Replace Metadata')},
{id: 'merge', title: Ox._('Merge Metadata')}
],
max: 1,
min: 1,
style: 'squared',
value: ui.updateMetadata,
width: 192
})
.css({margin: '4px'})
.bindEvent({
change: function(data) {
oml.UI.set({updateMetadata: data.value});
$list && $innerPanel.replaceElement(1, renderResult());
}
}),
$dontUpdateButton = Ox.Button({ $dontUpdateButton = Ox.Button({
id: 'dontupdate', id: 'dontupdate',
style: 'squared', style: 'squared',
@ -94,29 +115,17 @@ oml.ui.identifyDialog = function(data) {
}) })
.bindEvent({ .bindEvent({
click: function() { click: function() {
// FIXME: Wrong if user messes with lookup elements before clicking update button
var primaryId;
if (selected == 'lookup') {
primaryId = [
$lookupSelect.value(),
$lookupInput.value()
];
} else {
primaryId = $list.value(
$list.options('selected')[0],
'primaryid'
);
}
that.options({content: Ox.LoadingScreen().start()}); that.options({content: Ox.LoadingScreen().start()});
that.disableButtons(); that.disableButtons();
oml.api.edit({ oml.api.edit(Ox.extend({
id: data.id, id: data.id
primaryid: primaryId }, Ox.filter(
}, function(result) { $list.value($list.options('selected')[0]),
( function(value, key) {
$metadataSelect.value() == 'original' return Ox.contains($list.options('keys'), key)
? oml.api.resetMetadata : Ox.noop && value != data[key]
)({id: ui.item}, function(result) { }
)), function(result) {
Ox.Request.clearCache('find'); Ox.Request.clearCache('find');
oml.$ui.info.updateElement(); oml.$ui.info.updateElement();
oml.$ui.browser.reloadList(true); oml.$ui.browser.reloadList(true);
@ -125,7 +134,6 @@ oml.ui.identifyDialog = function(data) {
oml.$ui.infoView.updateElement(data.id); oml.$ui.infoView.updateElement(data.id);
that.close(); that.close();
}); });
});
} }
}), }),
@ -143,21 +151,30 @@ oml.ui.identifyDialog = function(data) {
width: 768 width: 768
}); });
$($updateSelect.find('.OxButton')[0]).css({margin: 0});
$updateSelect.appendTo($(that.find('.OxBar')[1]));
function disableButtons() { function disableButtons() {
$select.options('items').forEach(function(item) { $findSelect.options('items').forEach(function(item) {
$select.disableItem(item.id); $findSelect.disableItem(item.id);
});
$findInput.options({disabled: true});
$findButton.options({disabled: true});
$updateSelect.options('items').forEach(function(item) {
$updateSelect.disableItem(item.id);
}); });
$input.options({disabled: true});
$button.options({disabled: true});
$updateButton.options({disabled: true}); $updateButton.options({disabled: true});
} }
function enableButtons() { function enableButtons() {
$select.options('items').forEach(function(item) { $findSelect.options('items').forEach(function(item) {
$select.enableItem(item.id); $findSelect.enableItem(item.id);
});
$findInput.options({disabled: false});
$findButton.options({disabled: false});
$updateSelect.options('items').forEach(function(item) {
$updateSelect.enableItem(item.id);
}); });
$input.options({disabled: false});
$button.options({disabled: false});
$updateButton.options({disabled: false}); $updateButton.options({disabled: false});
} }
@ -165,8 +182,8 @@ oml.ui.identifyDialog = function(data) {
disableButtons(); disableButtons();
$outerPanel.replaceElement(1, Ox.LoadingScreen().start()); $outerPanel.replaceElement(1, Ox.LoadingScreen().start());
oml.api.findMetadata({ oml.api.findMetadata({
key: $select.value(), key: $findSelect.value(),
value: $input.value() value: $findInput.value()
}, function(result) { }, function(result) {
var items = result.data.items.map(function(item, index) { var items = result.data.items.map(function(item, index) {
return Ox.extend({index: index.toString()}, item); return Ox.extend({index: index.toString()}, item);
@ -185,8 +202,18 @@ oml.ui.identifyDialog = function(data) {
: data.id : data.id
} }
function renderResult() {
var index = $list.options('selected')[0];
return oml.ui.infoView(
$updateSelect.value() == 'replace'
? $list.value(index)
: Ox.map($list.value(index), function(value, key) {
return value || data[key];
})
);
}
function renderResults(items) { function renderResults(items) {
var $innerPanel;
if (items.length) { if (items.length) {
$list = Ox.TableList({ $list = Ox.TableList({
columns: [{ columns: [{
@ -213,10 +240,9 @@ oml.ui.identifyDialog = function(data) {
}) })
.bindEvent({ .bindEvent({
select: function(data) { select: function(data) {
var index = data.ids[0]; $innerPanel.replaceElement(1, renderResult());
$innerPanel.replaceElement(1, oml.ui.infoView($list.value(index)));
} }
}), });
$innerPanel = Ox.SplitPanel({ $innerPanel = Ox.SplitPanel({
elements: [ elements: [
{element: $list || Ox.Element(), size: 192}, {element: $list || Ox.Element(), size: 192},