add placeholders for empty folders, fixes #250

This commit is contained in:
rolux 2014-02-03 08:58:23 +00:00
parent 3c1d3bbcb2
commit f8890ed015
6 changed files with 61 additions and 17 deletions

View file

@ -1,18 +1,31 @@
// vim: et:ts=4:sw=4:sts=4:ft=javascript // vim: et:ts=4:sw=4:sts=4:ft=javascript
'use strict'; 'use strict';
pandora.ui.folderBrowser = function(id, section) { pandora.ui.folderBrowser = function(id, section) {
var that = Ox.SplitPanel({ var that = Ox.Element();
elements: [ pandora.$ui.folderList[id] = pandora.ui.folderBrowserList(id, section)
{ .bindEvent({
element: pandora.ui.folderBrowserBar(id, section), init: function(data) {
size: 24 if (data.items) {
}, that.setElement(
{ Ox.SplitPanel({
element: pandora.$ui.folderList[id] = pandora.ui.folderBrowserList(id, section) elements: [
{
element: pandora.ui.folderBrowserBar(id, section),
size: 24
},
{
element: pandora.$ui.folderList[id]
}
],
orientation: 'vertical'
})
);
} else {
// if there are no items, then the placeholder is already there
pandora.$ui.folderPlaceholder[id].updateText('public');
}
} }
], });
orientation: 'vertical'
});
return that; return that;
}; };

View file

@ -191,11 +191,12 @@ pandora.ui.folderBrowserList = function(id, section) {
init: function(data) { init: function(data) {
pandora.site.sectionFolders[section][i].items = data.items; pandora.site.sectionFolders[section][i].items = data.items;
pandora.$ui.folder[i].$content.css({ pandora.$ui.folder[i].$content.css({
height: 40 + data.items * 16 + 'px' height: (data.items ? 40 + data.items * 16 : 16) + 'px'
}); });
pandora.$ui.folderList[id].css({ pandora.$ui.folderList[id].css({
height: 16 + data.items * 16 + 'px' height: 16 + data.items * 16 + 'px'
}); });
pandora.$ui.folderPlaceholder[id][data.items ? 'hide' : 'show']();
pandora.resizeFolders(); pandora.resizeFolders();
}, },
paste: function(data) { paste: function(data) {

View file

@ -8,6 +8,7 @@ pandora.ui.folderList = function(id, section) {
folderItems = section == 'items' ? 'Lists' : Ox.toTitleCase(section), folderItems = section == 'items' ? 'Lists' : Ox.toTitleCase(section),
folderItem = folderItems.slice(0, -1), folderItem = folderItems.slice(0, -1),
canEditFeatured = pandora.site.capabilities['canEditFeatured' + folderItems][pandora.user.level], canEditFeatured = pandora.site.capabilities['canEditFeatured' + folderItems][pandora.user.level],
$placeholder,
that; that;
var columns, items; var columns, items;
if (id != 'volumes') { if (id != 'volumes') {
@ -267,8 +268,11 @@ pandora.ui.folderList = function(id, section) {
max: 1, max: 1,
min: 0, min: 0,
pageLength: 1000, pageLength: 1000,
// won't work, getListData looks up data in $folderList // works when switching back from browser, but won't work on load, since
//selected: pandora.getListData().folder == id ? [ui._list] : [], // getListData relies on $folderList, so selectList is called in init handler
selected: pandora.getListData().folder == id
? [ui[ui.section == 'items' ? '_list' : ui.section.slice(0, -1)]]
: [],
sort: [{key: 'position', operator: '+'}], sort: [{key: 'position', operator: '+'}],
sortable: id != 'featured' || canEditFeatured, sortable: id != 'featured' || canEditFeatured,
unique: id != 'volumes' ? 'id' : 'name' unique: id != 'volumes' ? 'id' : 'name'
@ -377,11 +381,12 @@ pandora.ui.folderList = function(id, section) {
if (pandora.site.sectionFolders[section][i]) { if (pandora.site.sectionFolders[section][i]) {
pandora.site.sectionFolders[section][i].items = data.items; pandora.site.sectionFolders[section][i].items = data.items;
pandora.$ui.folder[i].$content.css({ pandora.$ui.folder[i].$content.css({
height: data.items * 16 + 'px' height: (data.items || 1) * 16 + 'px'
}); });
pandora.$ui.folderList[id].css({ pandora.$ui.folderList[id].css({
height: data.items * 16 + 'px' height: data.items * 16 + 'px'
}); })[data.items ? 'show' : 'hide']();
pandora.$ui.folderPlaceholder[id].updateText(id)[data.items ? 'hide' : 'show']();
} }
pandora.resizeFolders(); pandora.resizeFolders();
}, },

View file

@ -0,0 +1,21 @@
// vim: et:ts=4:sw=4:sts=4:ft=javascript
'use strict';
pandora.ui.folderPlaceholder = function(id, section) {
var that = Ox.Element()
.addClass('OxLight')
.css({
height: '14px',
padding: '1px 4px',
});
that.updateText = function(string) {
return that.html(
Ox._(
string != 'volumes'
? 'No ' + string + ' ' + (section == 'items' ? 'lists' : section)
: 'No local volumes'
)
);
};
return that.updateText(id);
};

View file

@ -17,6 +17,7 @@ pandora.ui.folders = function(section) {
pandora.$ui.folder = []; pandora.$ui.folder = [];
pandora.$ui.folderBrowser = {}; pandora.$ui.folderBrowser = {};
pandora.$ui.folderList = {}; pandora.$ui.folderList = {};
pandora.$ui.folderPlaceholder = {};
pandora.$ui.findListElement = {}; pandora.$ui.findListElement = {};
pandora.$ui.findListSelect = {}; pandora.$ui.findListSelect = {};
pandora.$ui.findListInput = {}; pandora.$ui.findListInput = {};
@ -338,6 +339,9 @@ pandora.ui.folders = function(section) {
} }
}) })
.appendTo(pandora.$ui.folder[i].$content); .appendTo(pandora.$ui.folder[i].$content);
pandora.$ui.folderPlaceholder[folder.id] = pandora.ui.folderPlaceholder(folder.id, section)
.hide()
.appendTo(pandora.$ui.folder[i].$content);
}); });
function infoButton(title, text) { function infoButton(title, text) {
return Ox.Button({ return Ox.Button({

View file

@ -991,7 +991,7 @@ pandora.getFoldersHeight = function(section) {
var height = 0; var height = 0;
pandora.site.sectionFolders[section].forEach(function(folder, i) { pandora.site.sectionFolders[section].forEach(function(folder, i) {
height += 16 + pandora.user.ui.showFolder[section][folder.id] * ( height += 16 + pandora.user.ui.showFolder[section][folder.id] * (
!!folder.showBrowser * 40 + folder.items * 16 !!(folder.showBrowser && folder.items) * 40 + (folder.items || 1) * 16
); );
}); });
return height; return height;