openmedialibrary/static/js/info.js

89 lines
2.7 KiB
JavaScript
Raw Normal View History

2014-05-04 19:26:43 +02:00
'use strict';
oml.ui.info = function() {
var ui = oml.user.ui,
that = Ox.Element()
.addClass('OxTextPage')
2014-05-17 13:45:57 +02:00
.css({
padding: '0 16px',
2014-05-04 19:26:43 +02:00
textAlign: 'center',
2014-05-17 13:45:57 +02:00
overflowY: 'auto'
})
.bindEvent({
2014-05-25 16:05:26 +02:00
toggle: function(data) {
oml.UI.set({showInfo: !data.collapsed});
},
2016-01-16 10:44:22 +05:30
oml_icons: function() {
that.updateElement();
},
2014-05-04 19:26:43 +02:00
oml_item: function() {
2014-05-17 13:45:57 +02:00
that.updateElement();
2014-05-04 19:26:43 +02:00
},
2014-05-17 13:45:57 +02:00
oml_listselection: function() {
that.updateElement();
}
});
2014-05-04 19:26:43 +02:00
2014-05-17 13:45:57 +02:00
that.updateElement = function() {
2014-05-04 19:26:43 +02:00
var id = ui.item || ui.listSelection[0];
2016-01-13 14:14:07 +05:30
Ox.Request.clearCache('get');
2014-05-04 19:26:43 +02:00
if (id) {
oml.api.get({
id: id,
keys: [
'author', 'coverRatio',
'description', 'modified', 'title'
2014-05-04 19:26:43 +02:00
]
}, function(result) {
var data = result.data;
that.empty();
$('<img>')
2016-01-13 14:14:07 +05:30
.attr({
src: '/' + id + '/' + ui.icons + '128.jpg?'
+ data.modified
})
2016-01-18 11:23:59 +05:30
.css({
margin: '16px 0 8px 0',
height: '128px'
})
.bind({
load: function() {
if (data.coverRatio > 1) {
$(this).css({
height: (128 / data.coverRatio) + 'px'
});
}
}
})
2014-05-04 19:26:43 +02:00
.appendTo(that);
$('<div>')
2016-01-09 12:37:17 +05:30
.addClass('OxSelectable')
.css({fontWeight: 'bold'})
2016-01-08 14:07:34 +05:30
.text(data.title || '')
2014-05-04 19:26:43 +02:00
.appendTo(that);
$('<div>')
2016-01-09 12:37:17 +05:30
.addClass('OxSelectable')
.css({fontWeight: 'bold'})
2016-01-14 14:55:14 +05:30
.text(oml.formatAuthor(data.author))
2014-05-04 19:26:43 +02:00
.appendTo(that);
$('<div>')
2016-01-09 12:37:17 +05:30
.addClass('OxSelectable')
2014-05-04 19:26:43 +02:00
.css({marginTop: '8px'})
2016-01-08 14:07:34 +05:30
.text(result.data.description || '')
2014-05-04 19:26:43 +02:00
.appendTo(that);
$('<div>')
.css({height: '16px'})
.appendTo(that);
});
} else {
that.empty();
}
return that;
};
2014-05-17 13:45:57 +02:00
return that.updateElement();
2014-05-04 19:26:43 +02:00
};