2014-01-07 08:24:00 +00:00
|
|
|
// vim: et:ts=4:sw=4:sts=4:ft=javascript
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2014-02-04 05:53:04 +00:00
|
|
|
// fixme: this is a very uncommon pattern
|
2014-01-17 13:49:11 +00:00
|
|
|
|
2014-02-04 05:53:04 +00:00
|
|
|
pandora.openDocumentDialog = function(options) {
|
2014-02-03 06:12:55 +00:00
|
|
|
if (
|
|
|
|
pandora.$ui.documentDialog && options.ids && options.ids.length == 1
|
|
|
|
&& Ox.getObjectById(pandora.$ui.documentDialog.getItems(), options.ids[0])
|
|
|
|
) {
|
2017-01-25 21:01:40 +00:00
|
|
|
pandora.UI.set({'part.document': options.ids[0]});
|
2014-02-03 06:12:55 +00:00
|
|
|
} else if (options.ids) {
|
2014-01-20 11:13:07 +00:00
|
|
|
pandora.api.findDocuments({
|
|
|
|
query: {
|
|
|
|
conditions: options.ids.map(function(id) {
|
|
|
|
return {key: 'id', value: id, operator: '=='}
|
|
|
|
}),
|
|
|
|
operator: '|'
|
|
|
|
},
|
|
|
|
range: [0, options.ids.length],
|
2016-10-04 22:00:03 +00:00
|
|
|
keys: ['description', 'dimensions', 'extension', 'id', 'title', 'modified']
|
2014-01-20 11:13:07 +00:00
|
|
|
}, function(result) {
|
2014-02-03 06:12:55 +00:00
|
|
|
var i = 0,
|
|
|
|
documents = Ox.sort(result.data.items, function(item) {
|
|
|
|
return options.ids.indexOf(item.id);
|
|
|
|
}).map(function(document) {
|
|
|
|
return Ox.extend({index: i++}, document);
|
|
|
|
});
|
2014-01-20 11:13:07 +00:00
|
|
|
pandora.openDocumentDialog({documents: documents});
|
2014-01-17 13:49:11 +00:00
|
|
|
});
|
2014-01-20 11:13:07 +00:00
|
|
|
} else {
|
2014-01-17 13:49:11 +00:00
|
|
|
if (!pandora.$ui.documentDialog) {
|
|
|
|
pandora.$ui.documentDialog = pandora.ui.documentDialog({
|
|
|
|
index: 0,
|
2014-01-20 11:13:07 +00:00
|
|
|
items: options.documents,
|
2014-01-17 13:49:11 +00:00
|
|
|
})
|
|
|
|
.bindEvent({
|
|
|
|
close: function() {
|
2017-01-25 21:01:40 +00:00
|
|
|
pandora.user.ui.page == 'document' && pandora.UI.set({page: ''});
|
2014-01-17 13:49:11 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.open();
|
|
|
|
} else {
|
|
|
|
pandora.$ui.documentDialog.update({
|
|
|
|
index: 0,
|
2014-01-20 11:13:07 +00:00
|
|
|
items: options.documents
|
2014-01-17 13:49:11 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
pandora.UI.set({
|
2017-01-25 21:01:40 +00:00
|
|
|
page: 'document',
|
|
|
|
'part.document': options.documents[0].id
|
2014-01-17 13:49:11 +00:00
|
|
|
});
|
2014-01-20 11:13:07 +00:00
|
|
|
return pandora.$ui.documentDialog;
|
|
|
|
}
|
2014-01-17 13:49:11 +00:00
|
|
|
};
|
|
|
|
|
2014-01-07 11:38:19 +00:00
|
|
|
pandora.ui.documentDialog = function(options) {
|
|
|
|
|
2014-12-17 16:52:21 +00:00
|
|
|
var dialogHeight = Math.round((window.innerHeight - 48) * 0.9) - 24,
|
|
|
|
dialogWidth = Math.round(window.innerWidth * 0.9) - 48,
|
2014-02-13 12:07:28 +00:00
|
|
|
isItemView = !pandora.$ui.documentsDialog,
|
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() {
|
2015-02-05 10:27:37 +00:00
|
|
|
pandora.UI.set({'part.documents': ''});
|
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
|
|
|
});
|
2015-02-05 08:18:40 +00:00
|
|
|
$content.getArea && pandora.UI.set(
|
|
|
|
'documents.' + item.id,
|
|
|
|
{position: $content.getArea().map(Math.round)}
|
|
|
|
);
|
2014-01-07 08:24:00 +00:00
|
|
|
},
|
2015-02-05 10:27:37 +00:00
|
|
|
'pandora_part.documents': 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)) {
|
2014-01-20 11:13:07 +00:00
|
|
|
item = Ox.getObjectById(items, data.value);
|
|
|
|
setTitle();
|
|
|
|
setContent();
|
2014-01-07 12:40:33 +00:00
|
|
|
} else {
|
2014-01-20 12:23:25 +00:00
|
|
|
// ...
|
2014-01-07 12:40:33 +00:00
|
|
|
}
|
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) {
|
2015-02-05 10:27:37 +00:00
|
|
|
pandora.UI.set({'part.documents': ''});
|
2014-01-07 08:24:00 +00:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
2015-02-05 08:14:56 +00:00
|
|
|
$embedButton = Ox.Button({
|
|
|
|
title: 'embed',
|
|
|
|
tooltip: Ox._('Embed'),
|
|
|
|
type: 'image'
|
|
|
|
})
|
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
|
|
|
right: '4px',
|
|
|
|
top: '4px'
|
|
|
|
})
|
|
|
|
.bindEvent({
|
|
|
|
click: function(data) {
|
|
|
|
var id = options.items[options.index].id;
|
|
|
|
pandora.$ui.embedDocumentDialog = pandora.ui.embedDocumentDialog(
|
|
|
|
id,
|
|
|
|
pandora.user.ui.documents[id]
|
|
|
|
? pandora.user.ui.documents[id].position
|
|
|
|
: null
|
|
|
|
).open();
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
2014-01-07 08:24:00 +00:00
|
|
|
$selectButton = Ox.ButtonGroup({
|
|
|
|
buttons: [
|
2014-02-13 13:57:36 +00:00
|
|
|
{id: 'previous', title: 'left', tooltip: Ox._('Previous')},
|
|
|
|
{id: 'next', title: 'right', tooltip: Ox._('Next')}
|
2014-01-07 08:24:00 +00:00
|
|
|
],
|
|
|
|
type: 'image'
|
|
|
|
})
|
2014-01-07 11:38:19 +00:00
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
2015-03-02 10:35:22 +00:00
|
|
|
right: '24px',
|
2014-01-07 11:38:19 +00:00
|
|
|
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-02-13 12:07:28 +00:00
|
|
|
pandora.$ui[
|
|
|
|
isItemView ? 'documents' : 'documentsDialogPanel'
|
2015-02-05 10:27:37 +00:00
|
|
|
].selectSelected(data.id == 'previous' ? -1 : 1);
|
2014-01-07 08:24:00 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-02-05 08:14:56 +00:00
|
|
|
$(that.find('.OxBar')[0]).append($embedButton).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,
|
2015-02-05 07:26:31 +00:00
|
|
|
page: pandora.user.ui.documents[item.id]
|
|
|
|
? pandora.user.ui.documents[item.id].position
|
|
|
|
: 1,
|
2015-01-24 10:20:46 +00:00
|
|
|
url: '/documents/' + item.id + '/'
|
2016-10-04 22:00:03 +00:00
|
|
|
+ item.title + '.' + item.extension,
|
2014-01-16 04:50:27 +00:00
|
|
|
width: dialogWidth,
|
2015-02-05 07:26:31 +00:00
|
|
|
zoom: 'fit'
|
2014-01-07 14:29:12 +00:00
|
|
|
})
|
2014-01-07 08:24:00 +00:00
|
|
|
: Ox.ImageViewer({
|
2015-02-05 07:26:31 +00:00
|
|
|
area: pandora.user.ui.documents[item.id]
|
|
|
|
? pandora.user.ui.documents[item.id].position
|
|
|
|
: [],
|
2014-01-07 11:38:19 +00:00
|
|
|
height: dialogHeight,
|
2014-01-07 08:24:00 +00:00
|
|
|
imageHeight: item.dimensions[1],
|
2015-10-26 15:10:12 +00:00
|
|
|
imagePreviewURL: pandora.getMediaURL('/documents/' + item.id + '/256p.jpg?' + item.modified),
|
2014-11-18 13:38:37 +00:00
|
|
|
imageURL: pandora.getMediaURL('/documents/' + item.id + '/'
|
2016-10-04 22:00:03 +00:00
|
|
|
+ item.title + '.' + item.extension + '?' + item.modified),
|
2014-01-07 08:24:00 +00:00
|
|
|
imageWidth: item.dimensions[0],
|
2015-02-05 07:26:31 +00:00
|
|
|
width: dialogWidth
|
2014-01-07 08:24:00 +00:00
|
|
|
})
|
|
|
|
)
|
|
|
|
.bindEvent({
|
2014-01-07 12:40:33 +00:00
|
|
|
center: function(data) {
|
2015-02-05 07:26:31 +00:00
|
|
|
pandora.UI.set(
|
2015-02-05 07:29:08 +00:00
|
|
|
'documents.' + item.id,
|
2015-02-05 07:41:25 +00:00
|
|
|
{position: $content.getArea().map(Math.round)}
|
2015-02-05 07:26:31 +00:00
|
|
|
);
|
2014-01-07 08:24:00 +00:00
|
|
|
},
|
2014-01-07 12:40:33 +00:00
|
|
|
key_escape: function() {
|
|
|
|
pandora.$ui.documentDialog.close();
|
|
|
|
},
|
|
|
|
page: function(data) {
|
2015-02-05 07:26:31 +00:00
|
|
|
pandora.UI.set(
|
2015-02-05 07:29:08 +00:00
|
|
|
'documents.' + item.id,
|
2015-02-05 07:30:56 +00:00
|
|
|
{position: data.page}
|
2015-02-05 07:26:31 +00:00
|
|
|
);
|
2014-01-07 08:24:00 +00:00
|
|
|
},
|
|
|
|
zoom: function(data) {
|
2015-02-05 07:26:31 +00:00
|
|
|
pandora.UI.set(
|
2015-02-05 07:29:08 +00:00
|
|
|
'documents.' + item.id,
|
2015-02-05 07:41:25 +00:00
|
|
|
{position: $content.getArea().map(Math.round)}
|
2015-02-05 07:26:31 +00:00
|
|
|
);
|
2014-01-07 08:24:00 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-01-07 12:40:33 +00:00
|
|
|
function setTitle() {
|
2016-10-04 22:00:03 +00:00
|
|
|
that.options({title: item.title + '.' + item.extension});
|
2014-01-07 12:40:33 +00:00
|
|
|
}
|
|
|
|
|
2014-01-20 11:13:07 +00:00
|
|
|
that.getItems = function() {
|
|
|
|
return items;
|
|
|
|
};
|
2014-02-03 06:12:55 +00:00
|
|
|
|
2014-01-07 12:40:33 +00:00
|
|
|
that.update = function(options) {
|
|
|
|
items = options.items;
|
|
|
|
item = items[options.index];
|
|
|
|
setTitle();
|
2014-02-14 05:52:56 +00:00
|
|
|
$selectButton[items.length > 1 ? 'show' : 'hide']();
|
2014-01-07 12:40:33 +00:00
|
|
|
setContent();
|
|
|
|
};
|
|
|
|
|
2014-01-07 08:24:00 +00:00
|
|
|
return that;
|
|
|
|
|
|
|
|
};
|