documentDialog: remove settings, pass area, return position

This commit is contained in:
rolux 2015-02-05 07:26:31 +00:00
parent ae1160b6c4
commit 5eced4f160

View file

@ -62,7 +62,6 @@ pandora.ui.documentDialog = function(options) {
isItemView = !pandora.$ui.documentsDialog, isItemView = !pandora.$ui.documentsDialog,
items = options.items, items = options.items,
item = items[options.index], item = items[options.index],
settings = getSettings(),
$content = Ox.Element(), $content = Ox.Element(),
@ -96,7 +95,6 @@ pandora.ui.documentDialog = function(options) {
if (data.value) { if (data.value) {
if (Ox.getObjectById(items, data.value)) { if (Ox.getObjectById(items, data.value)) {
item = Ox.getObjectById(items, data.value); item = Ox.getObjectById(items, data.value);
settings = getSettings();
setTitle(); setTitle();
setContent(); setContent();
} else { } else {
@ -142,58 +140,54 @@ pandora.ui.documentDialog = function(options) {
setTitle(); setTitle();
setContent(); setContent();
function getSettings() {
return Ox.extend(item.extension == 'pdf' ? {
position: 1,
zoom: 'fit'
} : {
center: 'auto',
zoom: 'fit'
}, pandora.user.ui.documents[item.id] || {});
}
function setContent() { function setContent() {
$content.replaceWith( $content.replaceWith(
$content = ( $content = (
item.extension == 'pdf' item.extension == 'pdf'
? Ox.PDFViewer({ ? Ox.PDFViewer({
height: dialogHeight, height: dialogHeight,
page: settings.position, page: pandora.user.ui.documents[item.id]
? pandora.user.ui.documents[item.id].position
: 1,
url: '/documents/' + item.id + '/' url: '/documents/' + item.id + '/'
+ item.name + '.' + item.extension, + item.name + '.' + item.extension,
width: dialogWidth, width: dialogWidth,
zoom: settings.zoom zoom: 'fit'
}) })
: Ox.ImageViewer({ : Ox.ImageViewer({
center: settings.center, area: pandora.user.ui.documents[item.id]
? pandora.user.ui.documents[item.id].position
: [],
height: dialogHeight, height: dialogHeight,
imageHeight: item.dimensions[1], imageHeight: item.dimensions[1],
imagePreviewURL: pandora.getMediaURL('/documents/' + item.id + '/256p.jpg'), imagePreviewURL: pandora.getMediaURL('/documents/' + item.id + '/256p.jpg'),
imageURL: pandora.getMediaURL('/documents/' + item.id + '/' imageURL: pandora.getMediaURL('/documents/' + item.id + '/'
+ item.name + '.' + item.extension), + item.name + '.' + item.extension),
imageWidth: item.dimensions[0], imageWidth: item.dimensions[0],
width: dialogWidth, width: dialogWidth
zoom: settings.zoom
}) })
) )
.bindEvent({ .bindEvent({
center: function(data) { center: function(data) {
pandora.UI.set('documents.' + item.id, Ox.extend(settings, { pandora.UI.set(
center: data.center 'documents.' + item.id + '.position',
})); $content.getArea()
);
}, },
key_escape: function() { key_escape: function() {
pandora.$ui.documentDialog.close(); pandora.$ui.documentDialog.close();
}, },
page: function(data) { page: function(data) {
pandora.UI.set('documents.' + item.id, Ox.extend(settings, { pandora.UI.set(
position: data.page 'documents.' + item.id + '.position',
})); data.page
);
}, },
zoom: function(data) { zoom: function(data) {
pandora.UI.set('documents.' + item.id, Ox.extend(settings, { pandora.UI.set(
zoom: data.zoom 'documents.' + item.id + '.position',
})); $content.getArea()
);
} }
}) })
); );