Various Document fixes

This commit is contained in:
j 2014-01-20 11:13:07 +00:00
parent 1d4ecd80a2
commit b346be26d0
4 changed files with 76 additions and 30 deletions

View file

@ -73,7 +73,9 @@ pandora.ui.appPanel = function() {
pandora.$ui.home && pandora.$ui.tv.mute(); pandora.$ui.home && pandora.$ui.tv.mute();
} else if (page == 'documents') { } else if (page == 'documents') {
if (pandora.user.ui.part.documents) { if (pandora.user.ui.part.documents) {
pandora.openDocumentDialog([pandora.user.ui.part.documents.split('/')[0]]); pandora.openDocumentDialog({
ids: [pandora.user.ui.part.documents.split('/')[0]]
});
} else { } else {
pandora.UI.set({page: ''}); pandora.UI.set({page: ''});
} }

View file

@ -2,25 +2,34 @@
'use strict'; 'use strict';
pandora.openDocumentDialog = function(ids) { pandora.openDocumentDialog = function(options) {
pandora.api.findDocuments({ if (pandora.$ui.documentDialog && options.ids && options.ids.length == 1
query: { && Ox.getObjectById(pandora.$ui.documentDialog.getItems(), options.ids[0])){
conditions: ids.map(function(id) { pandora.UI.set({document: options.ids[0]});
return {key: 'id', value: id, operator: '=='} } else if(options.ids) {
}), pandora.api.findDocuments({
operator: '|' query: {
}, conditions: options.ids.map(function(id) {
keys: ['description', 'dimensions', 'extension', 'id', 'name'] return {key: 'id', value: id, operator: '=='}
}, function(result) { }),
var i = 0, documents = result.data.items.map(function(document) { operator: '|'
return Ox.extend({index: i++}, document); },
range: [0, options.ids.length],
keys: ['description', 'dimensions', 'extension', 'id', 'name']
}, function(result) {
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);
});
pandora.openDocumentDialog({documents: documents});
}); });
} else {
if (!pandora.$ui.documentDialog) { if (!pandora.$ui.documentDialog) {
pandora.$ui.documentDialog = pandora.ui.documentDialog({ pandora.$ui.documentDialog = pandora.ui.documentDialog({
index: 0, index: 0,
items: documents, items: options.documents,
}) })
.bindEvent({ .bindEvent({
close: function() { close: function() {
@ -31,14 +40,15 @@ pandora.openDocumentDialog = function(ids) {
} else { } else {
pandora.$ui.documentDialog.update({ pandora.$ui.documentDialog.update({
index: 0, index: 0,
items: documents, items: options.documents
}); });
} }
pandora.UI.set({ pandora.UI.set({
page: 'documents', page: 'documents',
'part.documents': documents[0].id 'part.documents': options.documents[0].id
}); });
}); return pandora.$ui.documentDialog;
}
}; };
pandora.ui.documentDialog = function(options) { pandora.ui.documentDialog = function(options) {
@ -47,13 +57,7 @@ pandora.ui.documentDialog = function(options) {
dialogWidth = Math.round(window.innerWidth * 0.9), dialogWidth = Math.round(window.innerWidth * 0.9),
items = options.items, items = options.items,
item = items[options.index], item = items[options.index],
settings = Ox.extend(item.extension == 'pdf' ? { settings = getSettings(),
page: 1,
zoom: 'fit'
} : {
center: 'auto',
zoom: 'fit'
}, pandora.user.ui.documents[item.id] || {}),
$content = Ox.Element(), $content = Ox.Element(),
@ -86,9 +90,12 @@ pandora.ui.documentDialog = function(options) {
pandora_document: function(data) { pandora_document: function(data) {
if (data.value) { if (data.value) {
if (Ox.getObjectById(items, data.value)) { if (Ox.getObjectById(items, data.value)) {
// ... item = Ox.getObjectById(items, data.value);
settings = getSettings();
setTitle();
setContent();
} else { } else {
// ... //
} }
} else { } else {
that.close(); that.close();
@ -129,6 +136,16 @@ pandora.ui.documentDialog = function(options) {
setTitle(); setTitle();
setContent(); setContent();
function getSettings() {
return Ox.extend(item.extension == 'pdf' ? {
page: 1,
zoom: 'fit'
} : {
center: 'auto',
zoom: 'fit'
}, pandora.user.ui.documents[item.id] || {});
}
function setContent() { function setContent() {
$content.replaceWith( $content.replaceWith(
$content = ( $content = (
@ -180,6 +197,9 @@ pandora.ui.documentDialog = function(options) {
that.options({title: item.name + '.' + item.extension}); that.options({title: item.name + '.' + item.extension});
} }
that.getItems = function() {
return items;
};
that.update = function(options) { that.update = function(options) {
items = options.items; items = options.items;
item = items[options.index]; item = items[options.index];

View file

@ -7,6 +7,7 @@ pandora.ui.documentsPanel = function(options) {
var ui = pandora.user.ui, var ui = pandora.user.ui,
hasItemView = false, // FIXME hasItemView = false, // FIXME
isItemView = options.isItemView, isItemView = options.isItemView,
listLoaded = false,
columns = [ columns = [
{ {
@ -301,7 +302,18 @@ pandora.ui.documentsPanel = function(options) {
.css({float: 'right', margin: '4px 2px'}) .css({float: 'right', margin: '4px 2px'})
.bindEvent({ .bindEvent({
click: function(data) { click: function(data) {
var selected = $list.options('selected');
if (data.id == 'next') {
selected.push(selected.shift());
} else {
selected.splice(0, 0, selected.pop());
}
$list.options('selected', selected);
$item.empty();
if (selected.length) {
$preview = renderPreview().appendTo($item);
$data = renderData().appendTo($item);
}
} }
}) })
.appendTo($itemBar), .appendTo($itemBar),
@ -455,7 +467,15 @@ pandora.ui.documentsPanel = function(options) {
} }
function openDocuments() { function openDocuments() {
pandora.openDocumentDialog($list.options('selected')); pandora.openDocumentDialog({
documents: $list.options('selected').map(function(id) {
return $list.value(id);
})
}).bindEvent({
close: function() {
$list.closePreview();
}
});
} }
function openDocumentsDialog() { function openDocumentsDialog() {
@ -714,6 +734,7 @@ pandora.ui.documentsPanel = function(options) {
}) })
.bindEventOnce({ .bindEventOnce({
load: function() { load: function() {
listLoaded = true;
selectDocuments(); selectDocuments();
!ui.showBrowser && $list.gainFocus(); !ui.showBrowser && $list.gainFocus();
} }
@ -759,6 +780,9 @@ pandora.ui.documentsPanel = function(options) {
} }
function selectDocuments() { function selectDocuments() {
if(!listLoaded) {
return;
}
var selected = ui.documentsSelection[isItemView ? ui.item : ''] || [], var selected = ui.documentsSelection[isItemView ? ui.item : ''] || [],
string = selected.length < 2 ? 'Document' : ' Documents'; string = selected.length < 2 ? 'Document' : ' Documents';
$list.options({selected: selected}); $list.options({selected: selected});

View file

@ -1409,7 +1409,7 @@ pandora.getPart = function(state, str, callback) {
} }
} else if (state.page == 'documents') { } else if (state.page == 'documents') {
var split = str.split('/')[0], var split = str.split('/')[0],
id = split[0]; id = split;
if (id) { if (id) {
pandora.api.findDocuments({ pandora.api.findDocuments({
query: { query: {