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();
} else if (page == '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 {
pandora.UI.set({page: ''});
}

View file

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

View file

@ -7,6 +7,7 @@ pandora.ui.documentsPanel = function(options) {
var ui = pandora.user.ui,
hasItemView = false, // FIXME
isItemView = options.isItemView,
listLoaded = false,
columns = [
{
@ -301,7 +302,18 @@ pandora.ui.documentsPanel = function(options) {
.css({float: 'right', margin: '4px 2px'})
.bindEvent({
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),
@ -455,7 +467,15 @@ pandora.ui.documentsPanel = function(options) {
}
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() {
@ -714,6 +734,7 @@ pandora.ui.documentsPanel = function(options) {
})
.bindEventOnce({
load: function() {
listLoaded = true;
selectDocuments();
!ui.showBrowser && $list.gainFocus();
}
@ -759,6 +780,9 @@ pandora.ui.documentsPanel = function(options) {
}
function selectDocuments() {
if(!listLoaded) {
return;
}
var selected = ui.documentsSelection[isItemView ? ui.item : ''] || [],
string = selected.length < 2 ? 'Document' : ' Documents';
$list.options({selected: selected});

View file

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