openmedialibrary/static/js/infoView.js

843 lines
33 KiB
JavaScript
Raw Normal View History

2014-05-04 19:26:43 +02:00
'use strict';
2016-01-11 19:03:15 +05:30
oml.ui.infoView = function(externalData, isMixed) {
isMixed = isMixed || {};
2014-05-04 19:26:43 +02:00
var ui = oml.user.ui,
2016-01-11 16:16:57 +05:30
arrayKeys = ['author', 'place', 'publisher', 'language', 'categories'],
2014-05-19 22:58:00 +02:00
2016-01-11 19:03:15 +05:30
iconSize = externalData ? 256 : ui.iconSize,
2016-01-06 00:08:33 +05:30
2016-01-11 20:40:39 +05:30
isMultiple = arguments.length == 2,
2014-05-25 14:16:04 +02:00
2016-01-11 16:16:57 +05:30
separator = '; ',
2016-01-11 19:03:15 +05:30
css = getCSS(iconSize, oml.config.iconRatio),
2014-05-04 19:26:43 +02:00
that = Ox.Element()
.addClass('OxTextPage')
.css({overflowY: 'auto'})
.bindEvent({
2014-05-21 02:02:39 +02:00
oml_icons: function() {
that.updateElement(ui.item, [$icon])
},
2014-05-04 19:26:43 +02:00
oml_item: function() {
if (ui.item) {
2014-05-17 13:45:57 +02:00
that.updateElement(ui.item);
2014-05-04 19:26:43 +02:00
}
},
oml_listselection: function(data) {
2016-01-17 17:59:34 +05:30
if (
data.value
&& data.value.length
&& data.value[0] != ui.item
) {
2014-05-17 13:45:57 +02:00
that.updateElement(data.value[0]);
2014-05-04 19:26:43 +02:00
}
}
}),
2014-05-21 02:02:39 +02:00
$icon = Ox.Element()
2014-05-04 19:26:43 +02:00
.css({
position: 'absolute',
left: '16px',
top: '16px',
2014-05-21 02:02:39 +02:00
width: css.icon.width
2014-05-04 19:26:43 +02:00
})
.appendTo(that),
$info = Ox.Element()
.addClass('OxSelectable')
.css({
position: 'absolute',
2016-01-11 19:03:15 +05:30
left: !isMultiple ? css.info.left : '16px',
right: !externalData && !isMultiple
? '176px' : 16 + Ox.UI.SCROLLBAR_SIZE + 'px',
2014-05-04 19:26:43 +02:00
top: '16px'
})
2014-05-21 02:02:39 +02:00
[iconSize == 512 ? 'hide' : 'show']()
2014-05-04 19:26:43 +02:00
.appendTo(that),
2014-05-15 01:28:49 +02:00
$data,
$image, $reflection, $reflectionImage;
2014-05-14 20:46:31 +02:00
2016-01-11 19:03:15 +05:30
if (!externalData) {
2014-05-04 19:26:43 +02:00
$data = Ox.Element()
.addClass('OxSelectable')
.css({
position: 'absolute',
right: '16px',
top: '16px',
width: '128px'
})
.appendTo(that);
2014-05-14 20:46:31 +02:00
}
2014-05-04 19:26:43 +02:00
2016-01-11 16:16:57 +05:30
function formatLight(string) {
return '<span class="OxLight">' + string + '</span>';
}
function formatKey(key) {
return '<span style="font-weight: bold">'
+ Ox._(Ox.getObjectById(oml.config.itemKeys, key).title)
+ ':</span>&nbsp;';
}
function formatValue(value, key) {
var isEditor = key == 'author' && (value || []).some(function(value) {
return Ox.endsWith(value, ' (Ed.)');
});
return value ? (Ox.isArray(value) ? value : [value]).map(function(value) {
if (key == 'date' && value) {
value = value.slice(0, 4);
}
2016-01-11 19:03:15 +05:30
return (
key && !externalData ? '<a href="/' + key + '==' + value + '">' : ''
) + (
key == 'author' ? value.replace(/ \(Ed\.\)$/, '') : value
) + (
key && !externalData ? '</a>' : ''
);
2016-01-11 16:16:57 +05:30
}).join(separator) + (isEditor ? ' (Ed.)' : '') : '';
}
2014-05-19 17:00:33 +02:00
function getCSS(size, ratio) {
var width = Math.round(ratio >= 1 ? size : size * ratio),
height = Math.round(ratio <= 1 ? size : size / ratio),
left = size == 256 ? Math.floor((size - width) / 2) : 0;
return {
2014-05-21 02:02:39 +02:00
icon: {
2014-05-19 17:00:33 +02:00
width: size + 'px'
},
info: {
left: (size == 256 ? size + 32 : width + 48) + 'px'
},
image: {
left: left + 'px',
width: width + 'px',
height: height + 'px'
},
reflection: {
top: height + 'px'
}
};
}
2014-05-21 02:02:39 +02:00
function renderIdentifyButton(data) {
2016-01-11 19:03:15 +05:30
return Ox.Button({
disabled: data.mediastate != 'available',
2016-01-11 16:16:57 +05:30
style: 'squared',
2016-01-11 19:03:15 +05:30
title: Ox._('Identify Book...'),
2015-11-30 17:50:03 +01:00
width: 128
})
2016-01-11 16:16:57 +05:30
.css({marginTop: '8px'})
2015-11-30 17:50:03 +01:00
.bindEvent({
click: function() {
2016-01-12 09:33:02 +05:30
oml.$ui.identifyDialog = oml.ui.identifyDialog(data).open();
2015-11-30 17:50:03 +01:00
}
2016-01-11 19:03:15 +05:30
});
2015-11-30 17:50:03 +01:00
}
2014-05-04 19:26:43 +02:00
function renderMediaButton(data) {
2014-05-15 01:28:49 +02:00
2014-05-14 11:57:11 +02:00
function getListItems() {
var items = [];
if (ui._lists) {
items = ui._lists.filter(function(list) {
2016-01-17 13:27:49 +05:30
return list.user === ''
2014-05-14 11:57:11 +02:00
&& list.type != 'smart';
}).map(function(list) {
return {
id: list.id,
2016-01-17 13:27:49 +05:30
title: Ox._('Download to {0}', [
Ox.encodeHTMLEntities(list.name)
])
2014-05-14 11:57:11 +02:00
};
});
items.splice(1, 0, [{}]);
}
return items;
}
2014-05-15 01:28:49 +02:00
2014-05-14 11:57:11 +02:00
function setListItems() {
if ($element && ui._lists) {
$element.options({
disabled: false
}).options('elements')[1].options({
items: getListItems()
});
} else {
setTimeout(setListItems, 100);
}
}
if (data.mediastate == 'unavailable' && !ui._lists) {
setListItems();
}
2016-01-17 13:27:49 +05:30
2015-04-20 09:53:20 +02:00
var $element = (data.mediastate == 'unavailable' || Ox.isUndefined(data.mediastate))
2014-05-12 14:57:47 +02:00
? Ox.FormElementGroup({
elements: [
Ox.Button({
2016-01-11 16:16:57 +05:30
style: 'squared',
2014-05-12 14:57:47 +02:00
title: Ox._('Download Book'),
width: 112
})
.bindEvent({
click: function() {
var _this = this;
this.options({disabled: true});
oml.api.addListItems({
items: [ui.item],
list: ':'
}, function(result) {
_this.options({disabled: false});
data.mediastate = 'transferring';
that.updateElement(data, $data);
2014-05-12 14:57:47 +02:00
});
}
}),
Ox.MenuButton({
2014-05-14 11:57:11 +02:00
disabled: !ui._lists,
items: getListItems(),
2014-05-12 14:57:47 +02:00
overlap: 'left',
2016-01-11 16:16:57 +05:30
style: 'squared',
2014-05-21 02:02:39 +02:00
title: 'select',
2014-05-12 14:57:47 +02:00
tooltip: Ox._('Download Book to a List'),
type: 'image'
})
.bindEvent({
2016-01-17 16:54:53 +05:30
click: function(data_) {
2014-05-14 11:57:11 +02:00
data.mediastate = 'transferring';
2014-05-17 13:45:57 +02:00
that.updateElement(data, $data);
2016-01-17 16:59:33 +05:30
oml.api.addListItems({
items: [ui.item],
list: data_.id
}, function(result) {
2014-05-14 11:57:11 +02:00
// ...
});
2014-05-12 14:57:47 +02:00
}
})
],
float: 'right'
})
: data.mediastate == 'transferring'
2014-05-04 19:26:43 +02:00
? Ox.FormElementGroup({
elements: [
Ox.Button({
2016-01-11 16:16:57 +05:30
style: 'squared',
2014-05-04 19:26:43 +02:00
title: Ox._('Transferring...'),
width: 112
})
.bindEvent({
click: function() {
oml.UI.set({page: 'transfers'});
}
}),
Ox.Button({
overlap: 'left',
2016-01-11 16:16:57 +05:30
style: 'squared',
2014-05-04 19:26:43 +02:00
title: 'close',
tooltip: Ox._('Cancel Transfer'),
type: 'image'
})
.bindEvent({
click: function() {
data.mediastate = 'unavailable';
2014-05-17 13:45:57 +02:00
that.updateElement(data, $data);
2014-05-25 16:05:26 +02:00
oml.api.cancelDownloads({ids: [ui.item]}, function() {
2014-05-17 13:45:57 +02:00
that.updateElement(ui.item, $data);
2014-05-04 19:26:43 +02:00
});
}
})
],
float: 'right'
})
2016-01-18 16:21:07 +05:30
: Ox.FormElementGroup({
elements: [
Ox.Button({
style: 'squared',
title: Ox._('Read Book'),
width: 112
})
.bindEvent({
click: function() {
oml.UI.set({itemView: 'book'});
}
}),
Ox.MenuButton({
items: [
{id: 'read', title: Ox._('Read in Open Media Libary')},
{id: 'open', title: Ox._('Open in External Reader')},
{},
{id: 'show', title: Ox._('Show File')}
],
overlap: 'left',
style: 'squared',
title: 'select',
tooltip: Ox._('Download Book to a List'),
type: 'image'
})
.bindEvent({
click: function(data_) {
if (data_.id == 'read') {
oml.UI.set({itemView: 'book'});
} else if (data_.id == 'open') {
2016-01-19 10:51:43 +05:30
oml.api.openFile({id: oml.user.ui.item});
2016-01-18 16:21:07 +05:30
} else {
oml.api.openFolder({id: oml.user.ui.item});
}
}
})
],
float: 'right'
2014-05-04 19:26:43 +02:00
});
2014-05-14 11:57:11 +02:00
return $element;
2014-05-04 19:26:43 +02:00
}
2016-01-19 15:35:16 +05:30
function renderShareButton(data) {
2016-01-18 16:21:07 +05:30
return Ox.Checkbox({
2016-01-11 19:03:15 +05:30
style: 'squared',
2016-01-18 16:21:07 +05:30
title: Ox._('Share Metadata'),
2016-01-19 15:35:16 +05:30
value: data.sharemetadata,
2016-01-18 16:21:07 +05:30
width: 128,
2016-01-11 19:03:15 +05:30
})
.css({marginTop: '8px'})
.bindEvent({
2016-01-19 15:35:16 +05:30
change: function(changeData) {
oml.api.edit({
id: data.id,
sharemetadata: changeData.value
}, function(result) {
if (!changeData.value) {
that.updateElement(result.data, [$icon, $info, $data]);
}
});
2016-01-11 19:03:15 +05:30
}
});
}
2016-01-11 16:16:57 +05:30
function splitValue(value, key) {
var isEditor = key == 'author'
&& Ox.decodeHTMLEntities(value).split(separator).some(function(value) {
return Ox.endsWith(value, ' (Ed.)');
});
2016-01-14 15:55:29 +05:30
return value ? Ox.unique(
Ox.decodeHTMLEntities(value).split(separator).map(function(value) {
value = Ox.encodeHTMLEntities(value);
return isEditor
? value.replace(/ \(Ed\.\)$/, '') + ' (Ed.)'
: value;
})
2016-01-14 15:55:29 +05:30
) : [];
2016-01-08 15:41:24 +05:30
}
2014-05-19 17:00:33 +02:00
function toggleCoverSize(ratio) {
2014-05-19 22:58:00 +02:00
var css;
2014-05-21 02:02:39 +02:00
iconSize = iconSize == 256 ? 512 : 256,
css = getCSS(iconSize, ratio);
//$icon.animate(css.icon, 250);
2014-05-19 17:00:33 +02:00
$info.animate(css.info, 250);
$image.animate(css.image, 250);
$reflectionImage.animate(css.image, 250);
$reflection.animate(css.reflection, 250);
2014-05-21 02:02:39 +02:00
oml.UI.set({iconSize: iconSize});
2014-05-19 17:00:33 +02:00
}
function updateCover(ratio) {
2014-05-21 02:02:39 +02:00
var css = getCSS(iconSize, ratio);
2014-05-19 17:00:33 +02:00
$image.css(css.image).show();
$reflectionImage.css(css.image);
$reflection.css(css.reflection).show();
2014-05-15 01:28:49 +02:00
}
2016-01-16 10:44:22 +05:30
that.updateCover = function(url) {
Ox.Request.clearCache('get');
that.updateElement(ui.item, $icon);
};
2014-05-17 13:45:57 +02:00
that.updateElement = function(idOrData, $elements) {
2014-05-04 19:26:43 +02:00
var data = Ox.isObject(idOrData) ? idOrData : null,
2014-05-14 11:57:11 +02:00
id = data ? null : idOrData,
2014-05-04 19:26:43 +02:00
$elements = $elements
? Ox.makeArray($elements)
2014-05-21 02:02:39 +02:00
: [$icon, $info, $data];
2014-05-04 19:26:43 +02:00
(data ? Ox.noop : oml.api.get)({
id: id,
keys: []
}, function(result) {
2016-01-11 19:03:15 +05:30
if (!externalData && id && id != ui.item) {
2014-05-17 10:17:34 +02:00
return;
}
2014-05-04 19:26:43 +02:00
if (result) {
data = result.data;
}
2014-05-20 02:44:13 +02:00
Ox.print('BOOK DATA', data)
2014-05-21 02:02:39 +02:00
var $div,
2016-01-11 19:03:15 +05:30
isEditable = isMultiple || (
data.mediastate == 'available' && !externalData
),
src = !externalData
2014-05-21 02:02:39 +02:00
? '/' + data.id + '/' + ui.icons + '512.jpg?' + data.modified
2014-05-14 20:46:31 +02:00
: data.cover,
2014-05-21 02:02:39 +02:00
ratio = (
2016-01-11 19:03:15 +05:30
ui.icons == 'cover' || externalData
2014-05-21 02:02:39 +02:00
? data.coverRatio : data.previewRatio
) || oml.config.iconRatio,
size = iconSize,
2014-05-04 19:26:43 +02:00
reflectionSize = Math.round(size / 2);
$elements.forEach(function($element) {
$element.empty();
2014-05-21 02:02:39 +02:00
if ($element == $icon) {
2014-05-04 19:26:43 +02:00
2014-05-19 17:00:33 +02:00
$image = Ox.Element({
element: '<img>',
2016-01-16 10:44:22 +05:30
tooltip: !externalData
? Ox._('Doubleclick to edit')
: ''
2014-05-19 17:00:33 +02:00
})
2014-05-15 01:28:49 +02:00
.on({
2014-05-19 20:12:02 +02:00
error: function() {
if (size == 512) {
$info.show();
}
},
2014-05-15 01:28:49 +02:00
load: function() {
2014-05-19 17:00:33 +02:00
ratio = $image[0].width / $image[0].height;
updateCover(ratio);
2014-05-19 20:12:02 +02:00
if (size == 512) {
$info.css({
left: getCSS(512, ratio).info.left
}).show();
}
2014-05-15 01:28:49 +02:00
}
})
2014-05-04 19:26:43 +02:00
.attr({src: src})
.css({
2014-05-15 01:28:49 +02:00
position: 'absolute'
2014-05-04 19:26:43 +02:00
})
2014-05-15 01:28:49 +02:00
.hide()
2014-05-19 17:00:33 +02:00
.bindEvent({
2014-05-21 02:02:39 +02:00
doubleclick: function() {
2016-01-22 12:34:39 +05:30
if (isEditable) {
2016-01-16 10:44:22 +05:30
oml.$ui.coverDialog = oml.ui.coverDialog(
id, data.cover
).open();
2014-05-21 02:02:39 +02:00
}
},
2014-05-19 17:00:33 +02:00
singleclick: function() {
2016-01-11 19:03:15 +05:30
if (!externalData) {
2014-05-19 22:58:00 +02:00
toggleCoverSize(ratio);
}
2014-05-19 17:00:33 +02:00
}
})
2014-05-21 02:02:39 +02:00
.appendTo($icon);
2014-05-04 19:26:43 +02:00
$reflection = $('<div>')
.addClass('OxReflection')
.css({
position: 'absolute',
width: size + 'px',
height: reflectionSize + 'px',
overflow: 'hidden'
})
2014-05-15 01:28:49 +02:00
.hide()
2014-05-21 02:02:39 +02:00
.appendTo($icon);
2014-05-04 19:26:43 +02:00
2014-05-15 01:28:49 +02:00
$reflectionImage = $('<img>')
2014-05-04 19:26:43 +02:00
.attr({src: src})
.css({
2014-05-15 01:28:49 +02:00
position: 'absolute'
2014-05-04 19:26:43 +02:00
})
.appendTo($reflection);
$('<div>')
.css({
position: 'absolute',
width: size + 'px',
height: reflectionSize + 'px'
})
.appendTo($reflection);
} else if ($element == $info) {
2016-01-11 16:16:57 +05:30
// -------- Title --------
2014-05-21 02:02:39 +02:00
2014-05-04 19:26:43 +02:00
$('<div>')
2014-05-19 22:58:00 +02:00
.css({
2014-05-21 02:02:39 +02:00
marginTop: '-2px'
2014-05-19 22:58:00 +02:00
})
2014-05-21 02:02:39 +02:00
.append(
Ox.EditableContent({
clickLink: oml.clickLink,
editable: isEditable,
2016-01-11 19:03:15 +05:30
placeholder: formatLight(Ox._(
isMixed.title ? 'Mixed Title' : 'Unknown Title'
)),
2014-05-21 02:02:39 +02:00
tooltip: isEditable ? oml.getEditTooltip() : '',
2016-01-11 19:03:15 +05:30
value: Ox.encodeHTMLEntities(data.title || '')
2014-05-21 02:02:39 +02:00
})
.css({
fontWeight: 'bold',
fontSize: '13px'
})
.bindEvent({
submit: function(event) {
2016-01-08 15:29:02 +05:30
editMetadata('title', Ox.decodeHTMLEntities(event.value));
2014-05-21 02:02:39 +02:00
}
})
2014-05-14 11:57:11 +02:00
)
2014-05-04 19:26:43 +02:00
.appendTo($info);
2016-01-11 16:16:57 +05:30
// -------- Author --------
2014-05-14 11:57:11 +02:00
2014-05-21 02:02:39 +02:00
$('<div>')
.css({
marginTop: '2px'
})
.append(
Ox.EditableContent({
clickLink: oml.clickLink,
editable: isEditable,
format: function(value) {
2016-01-11 16:16:57 +05:30
return formatValue(splitValue(value, 'author'), 'author');
2014-05-21 02:02:39 +02:00
},
2016-01-11 19:03:15 +05:30
placeholder: formatLight(Ox._(
isMixed.author ? 'Mixed Author' : 'Unknown Author'
)),
2014-05-21 02:02:39 +02:00
tooltip: isEditable ? oml.getEditTooltip() : '',
2016-01-11 19:03:15 +05:30
value: Ox.encodeHTMLEntities(
(data.author || []).map(function(value, index) {
return index < data.author.length - 1
? value.replace(/ \(Ed\.\)$/, '')
: value;
}).join(separator)
2016-01-11 19:03:15 +05:30
)
2014-05-21 02:02:39 +02:00
})
.css({
marginBottom: '-3px',
fontWeight: 'bold',
fontSize: '13px'
})
.bindEvent({
submit: function(event) {
2016-01-08 15:29:02 +05:30
editMetadata('author', Ox.decodeHTMLEntities(event.value));
2014-05-21 02:02:39 +02:00
}
})
)
.appendTo($info);
2016-01-11 16:16:57 +05:30
// -------- Publisher, Place, Date --------
2014-05-21 02:02:39 +02:00
$div = $('<div>')
.css({
marginTop: '4px',
})
.appendTo($info);
2016-01-11 16:16:57 +05:30
['publisher', 'place', 'date'].forEach(function(key, index) {
2014-05-21 02:02:39 +02:00
if (index) {
$('<span>').html(', ').appendTo($div);
}
$('<span>')
.html(formatKey(key))
.appendTo($div);
Ox.EditableContent({
clickLink: oml.clickLink,
editable: isEditable,
format: function(value) {
2016-01-05 22:49:34 +05:30
return formatValue(
Ox.contains(arrayKeys, key)
2016-01-08 15:41:24 +05:30
? splitValue(value) : value,
2016-01-05 22:49:34 +05:30
key
);
2014-05-21 02:02:39 +02:00
},
2016-01-11 19:03:15 +05:30
placeholder: formatLight(Ox._(
isMixed[key] ? 'mixed' : 'unknown'
)),
2014-05-21 02:02:39 +02:00
tooltip: isEditable ? oml.getEditTooltip() : '',
2016-01-11 16:16:57 +05:30
value: Ox.encodeHTMLEntities(
2016-01-05 20:13:37 +05:30
Ox.contains(arrayKeys, key)
2016-01-11 16:16:57 +05:30
? (data[key] || []).join(separator)
: (data[key] || '')
)
2014-05-16 10:06:11 +02:00
})
2014-05-21 02:02:39 +02:00
.bindEvent({
submit: function(event) {
2016-01-08 15:29:02 +05:30
editMetadata(key, Ox.decodeHTMLEntities(event.value));
2014-05-21 02:02:39 +02:00
}
})
.appendTo($div);
});
2014-05-19 22:58:00 +02:00
2016-01-11 16:16:57 +05:30
// -------- Series, Edition, Language, Pages --------
2014-05-21 02:02:39 +02:00
$div = $('<div>')
.css({
marginTop: '4px',
})
.appendTo($info);
2016-01-11 16:16:57 +05:30
['series', 'edition', 'language', 'pages'].forEach(function(key, index) {
2014-05-21 02:02:39 +02:00
if (index) {
$('<span>').html(', ').appendTo($div);
}
$('<span>')
.html(formatKey(key))
.appendTo($div);
Ox.EditableContent({
clickLink: oml.clickLink,
editable: isEditable,
format: function(value) {
2016-01-12 09:33:02 +05:30
return (
Ox.contains(['series', 'language'], key)
? formatValue : Ox.identity
)(
2016-01-11 16:16:57 +05:30
Ox.contains(arrayKeys, key)
? splitValue(value) : value,
key
);
2014-05-21 02:02:39 +02:00
},
2016-01-11 19:03:15 +05:30
placeholder: formatLight(Ox._(
isMixed[key] ? 'mixed' : 'unknown'
)),
2014-05-21 02:02:39 +02:00
tooltip: isEditable ? oml.getEditTooltip() : '',
2016-01-11 16:16:57 +05:30
value: Ox.encodeHTMLEntities(
2016-01-05 20:13:37 +05:30
Ox.contains(arrayKeys, key)
2016-01-11 16:16:57 +05:30
? (data[key] || []).join(separator)
: (data[key] || '')
)
2014-05-19 22:58:00 +02:00
})
2014-05-21 02:02:39 +02:00
.bindEvent({
submit: function(event) {
2016-01-08 15:29:02 +05:30
editMetadata(key, Ox.decodeHTMLEntities(event.value));
2014-05-21 02:02:39 +02:00
}
})
.appendTo($div);
});
2016-01-11 16:16:57 +05:30
// -------- Categories --------
2014-05-21 13:07:41 +02:00
2016-01-11 16:16:57 +05:30
if (data.categories || isEditable) {
$div = $('<div>')
2014-05-21 13:07:41 +02:00
.css({
marginTop: '4px',
})
.appendTo($info);
2016-01-11 16:16:57 +05:30
$('<span>')
.html(formatKey('categories'))
.appendTo($div);
Ox.EditableContent({
clickLink: oml.clickLink,
editable: isEditable,
format: function(value) {
return formatValue(splitValue(value), 'categories');
},
2016-01-11 19:03:15 +05:30
placeholder: formatLight(Ox._(
isMixed.categories ? 'mixed' : 'unknown'
)),
2016-01-11 16:16:57 +05:30
tooltip: isEditable ? oml.getEditTooltip() : '',
value: Ox.encodeHTMLEntities((data.categories || []).join(separator))
})
.bindEvent({
submit: function(event) {
editMetadata('categories', Ox.decodeHTMLEntities(event.value));
}
})
.appendTo($div);
2014-05-21 13:07:41 +02:00
}
2016-01-11 16:16:57 +05:30
// -------- ISBN --------
2014-05-04 19:26:43 +02:00
2016-01-11 16:16:57 +05:30
if (data.isbn || isEditable) {
$div = $('<div>')
2014-05-16 10:06:11 +02:00
.css({
2016-01-11 16:16:57 +05:30
marginTop: '4px',
2014-05-16 10:06:11 +02:00
})
.appendTo($info);
2016-01-11 16:16:57 +05:30
$('<span>')
.html(formatKey('isbn'))
.appendTo($div);
Ox.EditableContent({
editable: isEditable,
format: function(value) {
return (value ? [
2016-01-16 20:35:17 +05:30
Ox.formatISBN(value, 13, true),
Ox.formatISBN(value, 10, true)
2016-01-11 16:16:57 +05:30
] : []).join(separator);
},
2016-01-11 19:03:15 +05:30
placeholder: formatLight(Ox._(
isMixed.isbn ? 'mixed' : 'unknown'
)),
2016-01-11 16:16:57 +05:30
tooltip: isEditable ? oml.getEditTooltip() : '',
2016-01-16 20:48:14 +05:30
value: Ox.formatISBN(data.isbn || '', 13, true)
2016-01-11 16:16:57 +05:30
})
.bindEvent({
submit: function(event) {
2016-01-16 20:48:14 +05:30
this.options({
value: Ox.formatISBN(event.value, 13, true)
});
editMetadata(
'isbn', Ox.formatISBN(event.value, 13)
);
2016-01-11 16:16:57 +05:30
}
})
.appendTo($div);
2014-05-16 10:06:11 +02:00
}
2014-05-04 19:26:43 +02:00
2016-01-11 16:16:57 +05:30
// -------- Description, Table of Contents --------
2014-05-21 02:02:39 +02:00
2016-01-11 16:16:57 +05:30
['description', 'tableofcontents'].forEach(function(key) {
if (data[key] || isEditable) {
$('<div>')
.css({
marginTop: '8px',
textAlign: 'justify'
})
.append(
Ox.EditableContent({
clickLink: oml.clickLink,
editable: isEditable,
format: function(value) {
return value.replace(/\n/g, '<br>');
},
2016-01-11 19:03:15 +05:30
placeholder: formatLight(Ox._(
isMixed[key] ? 'Mixed {0}' : 'No {0}', [
2016-01-11 16:16:57 +05:30
Ox.getObjectById(oml.config.itemKeys, key).title
])),
tooltip: isEditable ? oml.getEditTooltip() : '',
type: 'textarea',
value: Ox.encodeHTMLEntities(data[key] || '')
})
.bindEvent({
submit: function(event) {
editMetadata(
key,
Ox.decodeHTMLEntities(event.value).replace(/<br>/g, '\n')
);
}
})
)
.appendTo($info);
}
});
2014-05-14 11:57:11 +02:00
2014-05-14 20:46:31 +02:00
$('<div>').css({height: '16px'}).appendTo($info);
2014-05-04 19:26:43 +02:00
2014-05-21 02:02:39 +02:00
oml.createLinks($info);
2014-05-04 19:26:43 +02:00
} else if ($element == $data) {
2014-05-21 02:02:39 +02:00
renderMediaButton(data).appendTo($data);
2014-05-12 14:57:47 +02:00
$('<div>')
.addClass('OxSelectable')
.css({
2014-05-14 11:57:11 +02:00
marginTop: '10px',
2014-05-12 14:57:47 +02:00
})
.text(
[
2014-05-21 02:02:39 +02:00
data.extension.toUpperCase(),
2014-05-12 14:57:47 +02:00
Ox.formatValue(data.size, 'B')
].join(', ')
)
.appendTo($data);
2016-01-11 16:16:57 +05:30
renderIdentifyButton(data).appendTo($data);
2014-05-12 14:57:47 +02:00
['accessed', 'modified', 'added', 'created'].forEach(function(id) {
var title;
if (data[id]) {
title = Ox.getObjectById(oml.config.itemKeys, id).title;
$('<div>')
.css({
marginTop: '8px',
fontWeight: 'bold'
})
.text(title)
.appendTo($data);
2014-05-14 11:57:11 +02:00
$('<div>')
2016-01-11 19:55:49 +05:30
.text(Ox.formatDate(data[id], '%B %e, %Y'))
2014-05-12 14:57:47 +02:00
.appendTo($data);
}
});
2016-01-11 19:03:15 +05:30
if (data.mediastate == 'available') {
2016-01-19 15:35:16 +05:30
renderShareButton(data).appendTo($data);
2016-01-11 19:03:15 +05:30
}
2015-11-30 17:50:03 +01:00
2014-05-04 19:26:43 +02:00
$('<div>').css({height: '16px'}).appendTo($data);
}
});
function editMetadata(key, value) {
var edit = Ox.extend(
{id: !isMultiple ? data.id : ui.listSelection},
key,
Ox.contains(arrayKeys, key)
? splitValue(value, key).map(Ox.decodeHTMLEntities)
: value
);
if (!Ox.isEqual(edit[key], data[key])) {
data[key] = edit[key];
2014-05-04 19:26:43 +02:00
oml.api.edit(edit, function(result) {
2016-01-12 10:16:07 +05:30
if (!isMultiple || ui.updateResults) {
Ox.Request.clearCache();
if (Ox.contains(['title', 'author', 'description'], key)) {
oml.$ui.info.updateElement();
}
2016-01-16 14:27:38 +05:30
if (ui.showFilters) {
oml.$ui.filters.forEach(function($filter) {
$filter.reloadList(true);
});
}
2016-01-12 10:16:07 +05:30
oml.$ui.list.value(
result.data.id, key, result.data[key]
);
oml.$ui.browser.value(
result.data.id, key, result.data[key]
);
2016-01-05 23:10:39 +05:30
}
2016-01-16 13:53:42 +05:30
that.updateElement(result.data, [$data]);
2016-01-12 10:16:07 +05:30
that.triggerEvent('change', Ox.extend({}, key, value));
2014-05-04 19:26:43 +02:00
});
}
}
});
};
2016-01-11 19:03:15 +05:30
if (!externalData) {
2014-05-17 13:45:57 +02:00
ui.item && that.updateElement(ui.item);
2016-01-11 19:03:15 +05:30
} else if (!isMultiple) {
that.updateElement(externalData, [$icon, $info]);
2014-05-14 20:46:31 +02:00
} else {
2016-01-11 19:03:15 +05:30
that.updateElement(externalData, [$info]);
2014-05-14 20:46:31 +02:00
}
2014-05-04 19:26:43 +02:00
that.bindEvent({
mousedown: function() {
2015-03-07 18:09:59 +05:30
setTimeout(function() {
!Ox.Focus.focusedElementIsInput() && that.gainFocus();
});
}
})
2014-05-04 19:26:43 +02:00
return that;
};