update identify dialog

This commit is contained in:
rlx 2016-01-12 09:33:27 +05:30
parent 8ad452378d
commit a8b154f3f5
1 changed files with 77 additions and 51 deletions

View File

@ -6,7 +6,7 @@ oml.ui.identifyDialog = function(data) {
$form = Ox.Element(),
$select = Ox.Select({
$findSelect = Ox.Select({
items: [
{id: 'title', title: Ox._('Title, Author etc.')},
{id: 'isbn', title: Ox._('ISBN')},
@ -21,15 +21,15 @@ oml.ui.identifyDialog = function(data) {
})
.bindEvent({
change: function(data) {
$input.options({
$findInput.options({
value: getValue(data.value)
}).focusInput(true);
}
}),
$input = Ox.Input({
$findInput = Ox.Input({
style: 'squared',
value: getValue($select.value()),
value: getValue($findSelect.value()),
width: 480
})
.bindEvent({
@ -39,7 +39,7 @@ oml.ui.identifyDialog = function(data) {
submit: findMetadata
}),
$button = Ox.Button({
$findButton = Ox.Button({
overlap: 'left',
style: 'squared',
title: Ox._('Find'),
@ -53,12 +53,12 @@ oml.ui.identifyDialog = function(data) {
elements: [
Ox.FormElementGroup({
elements: [
$select,
$input
$findSelect,
$findInput
],
float: 'left'
}),
$button
$findButton
],
float: 'right'
})
@ -67,6 +67,8 @@ oml.ui.identifyDialog = function(data) {
$list,
$innerPanel,
$outerPanel = Ox.SplitPanel({
elements: [
{element: $form, size: 48},
@ -75,6 +77,25 @@ oml.ui.identifyDialog = function(data) {
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({
id: 'dontupdate',
style: 'squared',
@ -94,37 +115,24 @@ oml.ui.identifyDialog = function(data) {
})
.bindEvent({
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.disableButtons();
oml.api.edit({
id: data.id,
primaryid: primaryId
}, function(result) {
(
$metadataSelect.value() == 'original'
? oml.api.resetMetadata : Ox.noop
)({id: ui.item}, function(result) {
Ox.Request.clearCache('find');
oml.$ui.info.updateElement();
oml.$ui.browser.reloadList(true);
oml.$ui.list.reloadList(true);
Ox.Request.clearCache(data.id);
oml.$ui.infoView.updateElement(data.id);
that.close();
});
oml.api.edit(Ox.extend({
id: data.id
}, Ox.filter(
$list.value($list.options('selected')[0]),
function(value, key) {
return Ox.contains($list.options('keys'), key)
&& value != data[key]
}
)), function(result) {
Ox.Request.clearCache('find');
oml.$ui.info.updateElement();
oml.$ui.browser.reloadList(true);
oml.$ui.list.reloadList(true);
Ox.Request.clearCache(data.id);
oml.$ui.infoView.updateElement(data.id);
that.close();
});
}
}),
@ -143,21 +151,30 @@ oml.ui.identifyDialog = function(data) {
width: 768
});
$($updateSelect.find('.OxButton')[0]).css({margin: 0});
$updateSelect.appendTo($(that.find('.OxBar')[1]));
function disableButtons() {
$select.options('items').forEach(function(item) {
$select.disableItem(item.id);
$findSelect.options('items').forEach(function(item) {
$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});
}
function enableButtons() {
$select.options('items').forEach(function(item) {
$select.enableItem(item.id);
$findSelect.options('items').forEach(function(item) {
$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});
}
@ -165,8 +182,8 @@ oml.ui.identifyDialog = function(data) {
disableButtons();
$outerPanel.replaceElement(1, Ox.LoadingScreen().start());
oml.api.findMetadata({
key: $select.value(),
value: $input.value()
key: $findSelect.value(),
value: $findInput.value()
}, function(result) {
var items = result.data.items.map(function(item, index) {
return Ox.extend({index: index.toString()}, item);
@ -185,8 +202,18 @@ oml.ui.identifyDialog = function(data) {
: 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) {
var $innerPanel;
if (items.length) {
$list = Ox.TableList({
columns: [{
@ -213,10 +240,9 @@ oml.ui.identifyDialog = function(data) {
})
.bindEvent({
select: function(data) {
var index = data.ids[0];
$innerPanel.replaceElement(1, oml.ui.infoView($list.value(index)));
$innerPanel.replaceElement(1, renderResult());
}
}),
});
$innerPanel = Ox.SplitPanel({
elements: [
{element: $list || Ox.Element(), size: 192},