pandora/static/js/documentDialog.js

139 lines
4.3 KiB
JavaScript
Raw Normal View History

2014-01-07 08:24:00 +00:00
// vim: et:ts=4:sw=4:sts=4:ft=javascript
'use strict';
2014-01-07 11:38:19 +00:00
pandora.ui.documentDialog = function(options) {
Ox.print('OPTIONS', options)
2014-01-07 08:24:00 +00:00
var dialogHeight = Math.round((window.innerHeight - 48) * 0.9),
dialogWidth = Math.round(window.innerWidth * 0.9),
2014-01-07 11:38:19 +00:00
items = options.items,
item = items[options.index],
2014-01-07 08:24:00 +00:00
$content = Ox.Element(),
that = Ox.Dialog({
closeButton: true,
content: $content,
2014-01-07 11:38:19 +00:00
focus: false,
2014-01-07 08:24:00 +00:00
height: dialogHeight,
maximizeButton: true,
minHeight: 256,
minWidth: 512,
padding: 0,
removeOnClose: true,
2014-01-07 12:40:33 +00:00
title: '',
2014-01-07 08:24:00 +00:00
width: dialogWidth
})
.bindEvent({
close: function() {
pandora.UI.set({document: ''});
2014-01-07 12:40:33 +00:00
delete pandora.$ui.documentDialog;
2014-01-07 08:24:00 +00:00
},
resize: function(data) {
2014-01-07 12:40:33 +00:00
dialogHeight = data.height;
dialogWidth = data.width;
2014-01-07 08:24:00 +00:00
$content.options({
2014-01-07 12:40:33 +00:00
height: dialogHeight,
width: dialogWidth
2014-01-07 08:24:00 +00:00
});
},
pandora_document: function(data) {
2014-01-07 14:29:12 +00:00
if (data.value) {
2014-01-07 12:40:33 +00:00
if (Ox.getObjectById(items, data.value)) {
} else {
}
2014-01-07 08:24:00 +00:00
} else {
2014-01-07 12:40:33 +00:00
that.close();
2014-01-07 08:24:00 +00:00
}
2014-01-07 12:40:33 +00:00
},
pandora_item: function(data) {
pandora.UI.set({document: ''});
2014-01-07 08:24:00 +00:00
}
}),
$selectButton = Ox.ButtonGroup({
buttons: [
{id: 'previous', title: 'left'},
{id: 'next', title: 'right'}
],
type: 'image'
})
2014-01-07 11:38:19 +00:00
.css({
position: 'absolute',
right: '4px',
top: '4px'
})
2014-01-07 14:29:12 +00:00
[items.length > 1 ? 'show' : 'hide']()
2014-01-07 08:24:00 +00:00
.bindEvent({
click: function(data) {
2014-01-07 11:38:19 +00:00
options.index = Ox.mod(
options.index + (data.id == 'previous' ? -1 : 1),
2014-01-07 08:24:00 +00:00
items.length
);
2014-01-07 11:38:19 +00:00
pandora.UI.set({document: items[options.index].id});
2014-01-07 08:24:00 +00:00
}
});
$(that.find('.OxBar')[0]).append($selectButton);
2014-01-07 11:38:19 +00:00
// fixme: why is this needed?
$(that.find('.OxContent')[0]).css({overflow: 'hidden'});
2014-01-07 08:24:00 +00:00
2014-01-07 12:40:33 +00:00
setTitle();
2014-01-07 08:24:00 +00:00
setContent();
function setContent() {
$content.replaceWith(
$content = (
item.extension == 'pdf'
2014-01-07 14:29:12 +00:00
? Ox.PDFViewer({
height: dialogHeight,
url: '/documents/' + item.id + '/'
+ item.name + '.' + item.extension,
width: dialogWidth
})
2014-01-07 08:24:00 +00:00
: Ox.ImageViewer({
2014-01-07 11:38:19 +00:00
height: dialogHeight,
2014-01-07 08:24:00 +00:00
imageHeight: item.dimensions[1],
imagePreviewURL: '/documents/' + item.id + '/256p.jpg',
imageURL: '/documents/' + item.id + '/'
+ item.name + '.' + item.extension,
imageWidth: item.dimensions[0],
2014-01-07 11:38:19 +00:00
width: dialogWidth
2014-01-07 08:24:00 +00:00
})
)
.bindEvent({
2014-01-07 12:40:33 +00:00
center: function(data) {
2014-01-07 08:24:00 +00:00
pandora.UI.set('document.' + item.id + '.center', data.center);
},
2014-01-07 12:40:33 +00:00
key_escape: function() {
pandora.$ui.documentDialog.close();
},
page: function(data) {
2014-01-07 08:24:00 +00:00
pandora.UI.set('document.' + item.id + '.page', data.page);
},
zoom: function(data) {
pandora.UI.set('document.' + item.id + '.zoom', data.zoom);
}
})
);
}
2014-01-07 12:40:33 +00:00
function setTitle() {
that.options({title: item.name + '.' + item.extension});
}
that.update = function(options) {
items = options.items;
item = items[options.index];
setTitle();
setContent();
};
2014-01-07 08:24:00 +00:00
return that;
};