fix bugs in id dialog

This commit is contained in:
rolux 2013-03-02 15:31:50 +05:30
parent 06ac4b9c6e
commit b0c80a5f47

View file

@ -90,112 +90,111 @@ pandora.ui.idDialog = function(data) {
}); });
pandora.api.getIds(get, function(result) { pandora.api.getIds(get, function(result) {
var checkboxes = []; var checkboxes = [];
if (!data.imdbId) {
checkboxes.push(
{
id: 'none',
title: getTitle({
id: data.imdbId,
title: data.title,
director: data.director,
year: data.year
})
}
);
}
$content = Ox.Element() $content = Ox.Element()
.css({padding: '13px', overflowY: 'auto'}); .css({padding: '13px', overflowY: 'auto'});
if (result.data.items.length) { ['title', 'director', 'year'].forEach(function(key) {
['title', 'director', 'year'].forEach(function(key) { $input.push(
$input.push( Ox.Input({
Ox.Input({ label: Ox.toTitleCase(key),
label: Ox.toTitleCase(key), labelWidth: 128,
labelWidth: 128, value: key == 'director' && data[key]
value: key == 'director' && data[key] ? data[key].join(', ')
? data[key].join(', ') : data[key],
: data[key], width: formWidth
width: formWidth })
}) .css({display: 'inline-block', margin: '3px'})
.css({display: 'inline-block', margin: '3px'}) .bindEvent({
.bindEvent({ change: function(data_) {
change: function(data_) { data[key] = key == 'director'
data[key] = key == 'director' ? data_.value.split(', ')
? data_.value.split(', ') : data_.value;
: data_.value; that.options({content: $loading});
that.options({content: $loading}); getIds();
getIds(); }
} })
}) .appendTo($content)
.appendTo($content) );
); });
}); $('<div>')
$('<div>') .css({width: '1px', height: '8px'})
.css({width: '1px', height: '8px'}) .appendTo($content);
.appendTo($content); (
if (!data.imdbId) { data.imdbId
&& Ox.getIndexById(result.data.items, data.imdbId) == -1
? pandora.api.findId
: Ox.noop
)({id: data.imdbId}, function(result_) {
if (result_ && result_.data.items.length) {
checkboxes.push( checkboxes.push(
{ {
id: 'none', id: data.imdbId,
title: getTitle({ title: getTitle(result_.data.items[0])
id: data.imdbId,
title: data.title,
director: data.director,
year: data.year
})
} }
); )
} }
( checkboxes = checkboxes.concat(
data.imdbId result.data.items.map(function(item) {
&& Ox.getIndexById(result.data.items, data.imdbId) == -1 return {
? pandora.api.findId id: item.id,
: Ox.noop title: getTitle(item)
)({id: data.imdbId}, function(result_) { };
if (result_ && result_.data.items.length) { })
checkboxes.push( );
{ $checkboxGroup = Ox.CheckboxGroup({
id: data.imdbId, checkboxes: checkboxes,
title: getTitle(result_.data.items[0]) type: 'list',
} width: formWidth,
) value: !data.imdbId ? 'none' : data.imdbId
})
.css({display: 'inline-block', margin: '3px'})
.bindEvent({
change: updateButton
})
.appendTo($content);
var elements = $checkboxGroup.find('.OxCheckbox:not(.OxButton)');
checkboxes.forEach(function(checkbox, index) {
if (checkbox.id != 'none') {
Ox.Button({
title: 'arrowRight',
tooltip: 'View on IMDb',
type: 'image'
})
.css({
float: 'right',
marginTop: '-18px'
})
.bindEvent({
click: function() {
window.open('/url=' + encodeURIComponent(
'http://imdb.com/title/tt'
+ checkbox.id + '/combined'
), '_blank');
}
})
.appendTo(elements[index]);
} }
checkboxes = checkboxes.concat(
result.data.items.map(function(item) {
return {
id: item.id,
title: getTitle(item)
};
})
);
$checkboxGroup = Ox.CheckboxGroup({
checkboxes: checkboxes,
type: 'list',
width: formWidth,
value: !data.imdbId ? 'none' : data.imdbId
})
.css({display: 'inline-block', margin: '3px'})
.bindEvent({
change: updateButton
})
.appendTo($content);
var elements = $checkboxGroup.find('.OxCheckbox:not(.OxButton)');
checkboxes.forEach(function(checkbox, index) {
if (checkbox.id != 'none') {
Ox.Button({
title: 'arrowRight',
tooltip: 'View on IMDb',
type: 'image'
})
.css({
float: 'right',
marginTop: '-18px'
})
.bindEvent({
click: function() {
window.open('/url=' + encodeURIComponent(
'http://imdb.com/title/tt'
+ checkbox.id + '/combined'
), '_blank');
}
})
.appendTo(elements[index])
}
});
that.options({content: $content});
updateButton();
}); });
} that.options({content: $content});
updateButton();
});
}); });
} }
function getTitle(item) { function getTitle(item) {
item = Ox.clone(item, true);
if (item.id && item.id == data.imdbId) { if (item.id && item.id == data.imdbId) {
item.id = highlightTitle(item.id); item.id = highlightTitle(item.id);
} }