New function to create the sidebar album structure

This commit is contained in:
Tobias Reich 2015-03-15 16:44:26 +01:00
parent 5c71fc3727
commit 7ed822be57
5 changed files with 94 additions and 100 deletions

BIN
dist/main.js vendored

Binary file not shown.

BIN
dist/view.js vendored

Binary file not shown.

View File

@ -266,102 +266,3 @@ build.tags = function(tags) {
return html; return html;
} }
build.sidebarAlbum = function(data, forView = false) {
var html = '',
visible = '',
password = '',
downloadable = '',
editTitleHTML = '',
editDescriptionHTML = '',
infos = [];
switch (data.public) {
case '0': visible = 'No';
break;
case '1': visible = 'Yes';
break;
default: visible = '-';
break;
}
switch (data.password) {
case '0': password = 'No';
break;
case '1': password = 'Yes';
break;
default: password = '-';
break;
}
switch (data.downloadable) {
case '0': downloadable = 'No';
break;
case '1': downloadable = 'Yes';
break;
default: downloadable = '-';
break;
}
if (forView===false&&lychee.publicMode===false) {
editTitleHTML = ' ' + build.editIcon('edit_title');
editDescriptionHTML = ' ' + build.editIcon('edit_description');
}
infos = [
['', 'Basics'],
['Title', data.title + editTitleHTML],
['Description', data.description + editDescriptionHTML],
['', 'Album'],
['Created', data.sysdate],
['Images', data.num],
['', 'Share'],
['Public', visible],
['Downloadable', downloadable],
['Password', password]
]
infos.forEach(function(info, i, items) {
// Set default for empty values
if (info[1]===''||info[1]===null||info[1]===undefined) info[1] = '-';
if (info[0]==='') {
// Divider
html += `
</table>
<div class='divider'>
<h1>${ info[1] }</h1>
</div>
<table id='infos'>
`
} else {
// Item
html += `
<tr>
<td>${ info[0] }</td>
<td class='attr_${ info[0].toLowerCase() }'>${ info[1] }</td>
</tr>
`
}
});
html += `
</table>
`
return html;
}

View File

@ -212,6 +212,94 @@ sidebar.createStructure.photo = function(data) {
} }
sidebar.createStructure.album = function(data) {
if (data===undefined||data===null||data==='') return false;
var editable = false,
structure = {},
visible = '',
password = '',
downloadable = '';
// Enable editable when user logged in
if (lychee.publicMode===false) editable = true;
// Set value for public
switch (data.public) {
case '0': visible = 'No';
break;
case '1': visible = 'Yes';
break;
default: visible = '-';
break;
}
// Set value for password
switch (data.password) {
case '0': password = 'No';
break;
case '1': password = 'Yes';
break;
default: password = '-';
break;
}
// Set value for downloadable
switch (data.downloadable) {
case '0': downloadable = 'No';
break;
case '1': downloadable = 'Yes';
break;
default: downloadable = '-';
break;
}
structure.basics = {
title: 'Basics',
type: sidebar.types.DEFAULT,
rows: [
{ title: 'Title', value: data.title, editable },
{ title: 'Description', value: data.description, editable }
]
}
structure.album = {
title: 'Album',
type: sidebar.types.DEFAULT,
rows: [
{ title: 'Created', value: data.sysdate },
{ title: 'Images', value: data.num }
]
}
structure.share = {
title: 'Share',
type: sidebar.types.DEFAULT,
rows: [
{ title: 'Public', value: visible },
{ title: 'Downloadable', value: downloadable },
{ title: 'Password', value: password }
]
}
// Construct all parts of the structure
structure = [
structure.basics,
structure.album,
structure.share
]
return structure;
}
sidebar.render = function(structure) { sidebar.render = function(structure) {
if (structure===undefined||structure===null||structure==='') return false; if (structure===undefined||structure===null||structure==='') return false;

View File

@ -266,8 +266,13 @@ view.album = {
sidebar: function() { sidebar: function() {
if ((visible.album()||!album.json.init)&&!visible.photo()) { if ((visible.album()||!album.json.init)&&!visible.photo()) {
sidebar.dom('.wrapper').html(build.sidebarAlbum(album.json));
let structure = sidebar.createStructure.album(album.json),
html = sidebar.render(structure);
sidebar.dom('.wrapper').html(html);
sidebar.bind(); sidebar.bind();
} }
} }