Add ability to set album thumbnails
This commit is contained in:
parent
e3372afa30
commit
3ba6dc6eb3
|
@ -18,6 +18,7 @@ if ( $_SESSION['currentalbum'] != 0 ) {
|
||||||
$data["albumscale"] = $album->getScale();
|
$data["albumscale"] = $album->getScale();
|
||||||
$data["albummanufacturer"] = $album->getManufacturer();
|
$data["albummanufacturer"] = $album->getManufacturer();
|
||||||
$data["albumdescription"] = $album->getDescription();
|
$data["albumdescription"] = $album->getDescription();
|
||||||
|
$data["thumbnailid"] = $album->getThumbnailID();
|
||||||
$data["images"] = $griditems;
|
$data["images"] = $griditems;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,9 +26,13 @@ if ( $_SESSION['currentalbum'] == 0 ) {
|
||||||
$griditems = Album::getList();
|
$griditems = Album::getList();
|
||||||
}
|
}
|
||||||
foreach ( $griditems as $griditem ) {
|
foreach ( $griditems as $griditem ) {
|
||||||
$data["albumcontents"] .= "<div class=\"thumbnail_grid\">";
|
$data["albumcontents"] .= "<div class=\"thumbnail_grid\" id=\"griditem_{$griditem->getID()}\">";
|
||||||
$data["albumcontents"] .= "<img class=\"thumbnail_grid_image albumthumbnail\" id=\"griditem_{$griditem->getID()}\" src=\"{$griditem->getThumbnail(URLSAFE)}\" />";
|
$data["albumcontents"] .= "<img class=\"thumbnail_grid_image albumthumbnail\" id=\"griditem_img_{$griditem->getID()}\" src=\"{$griditem->getThumbnail(URLSAFE)}\" />";
|
||||||
$data["albumcontents"] .= "<div class=\"thumbnail_grid_title textlink griditem_title\" id=\"title_{$griditem->getID()}\">{$griditem->getTitle(HTMLSAFE)}</div>";
|
$data["albumcontents"] .= "<div class=\"thumbnail_grid_title\"><span class='textlink griditem_title' id=\"title_{$griditem->getID()}\">{$griditem->getTitle(HTMLSAFE)}</span>";
|
||||||
|
if ( $currentuser->isLoggedIn() && ($_SESSION['currentalbum'] != 0) ) {
|
||||||
|
$data["albumcontents"] .= " <span class=\"textlink btn_setthumbnail\" id=\"setthumbnail_" . $griditem->getID() . "\">(SetThumb)</span>";
|
||||||
|
}
|
||||||
|
$data["albumcontents"] .= "</div>";
|
||||||
$data["albumcontents"] .= "</div>\n";
|
$data["albumcontents"] .= "</div>\n";
|
||||||
}
|
}
|
||||||
$data["currentalbum"] = $_SESSION['currentalbum'];
|
$data["currentalbum"] = $_SESSION['currentalbum'];
|
||||||
|
|
35
ajax/setthumbnail.php
Normal file
35
ajax/setthumbnail.php
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require '../header.php';
|
||||||
|
|
||||||
|
requireLogin();
|
||||||
|
|
||||||
|
$data = array();
|
||||||
|
$data["success"] = false;
|
||||||
|
|
||||||
|
if ( !isset($_REQUEST['imageid']) ) {
|
||||||
|
sendResponse($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
$image = new Image($_REQUEST['imageid']);
|
||||||
|
if ( $image->getID() == 0 ) {
|
||||||
|
sendResponse($data);
|
||||||
|
}
|
||||||
|
$album = new Album($image->getAlbumID());
|
||||||
|
$album->setThumbnail($image->getFileName());
|
||||||
|
$album->save();
|
||||||
|
|
||||||
|
$data["success"] = true;
|
||||||
|
$data["album"] = $album;
|
||||||
|
|
||||||
|
sendResponse($data);
|
||||||
|
|
||||||
|
function sendResponse($data) {
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
echo json_encode($data);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
exit();
|
||||||
|
|
||||||
|
// vim: set ts=4:sw=4
|
|
@ -5,6 +5,7 @@ class Album implements JsonSerializable {
|
||||||
private $foldername = "";
|
private $foldername = "";
|
||||||
private $title = "";
|
private $title = "";
|
||||||
private $thumbnail = "";
|
private $thumbnail = "";
|
||||||
|
private $thumbnailid = 0;
|
||||||
private $description = "";
|
private $description = "";
|
||||||
private $manufacturer = "";
|
private $manufacturer = "";
|
||||||
private $scale = "";
|
private $scale = "";
|
||||||
|
@ -72,6 +73,10 @@ class Album implements JsonSerializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getThumbnailID() {
|
||||||
|
return intval($this->thumbnailid);
|
||||||
|
}
|
||||||
|
|
||||||
public function getDescription($flag = 0) {
|
public function getDescription($flag = 0) {
|
||||||
switch ($flag) {
|
switch ($flag) {
|
||||||
case HTMLSAFE:
|
case HTMLSAFE:
|
||||||
|
@ -324,8 +329,8 @@ class Album implements JsonSerializable {
|
||||||
global $globaldbh;
|
global $globaldbh;
|
||||||
|
|
||||||
$reqid = intval($reqid);
|
$reqid = intval($reqid);
|
||||||
$query = "SELECT id, foldername, title, thumbnail, description, manufacturer, scale, createtime " .
|
$query = "SELECT a.id, a.foldername, a.title, a.thumbnail, a.description, a.manufacturer, a.scale, a.createtime, i.id AS thumbnailid " .
|
||||||
"FROM " . AppDB::TABLE_ALBUMS . " WHERE id=:id";
|
"FROM " . AppDB::TABLE_ALBUMS . " AS a LEFT JOIN " . AppDB::TABLE_IMAGES . " AS i ON i.filename=a.thumbnail WHERE a.id=:id";
|
||||||
$sth = $globaldbh->prepare($query);
|
$sth = $globaldbh->prepare($query);
|
||||||
$sth->bindValue(":id", $reqid, PDO::PARAM_INT);
|
$sth->bindValue(":id", $reqid, PDO::PARAM_INT);
|
||||||
$sth->execute();
|
$sth->execute();
|
||||||
|
@ -334,6 +339,7 @@ class Album implements JsonSerializable {
|
||||||
$this->setFolderName($row['foldername']);
|
$this->setFolderName($row['foldername']);
|
||||||
$this->setTitle($row['title']);
|
$this->setTitle($row['title']);
|
||||||
$this->setThumbnail($row['thumbnail']);
|
$this->setThumbnail($row['thumbnail']);
|
||||||
|
$this->thumbnailid = $row['thumbnailid'];
|
||||||
$this->setDescription($row['description']);
|
$this->setDescription($row['description']);
|
||||||
$this->setManufacturer($row['manufacturer']);
|
$this->setManufacturer($row['manufacturer']);
|
||||||
$this->setScale($row['scale']);
|
$this->setScale($row['scale']);
|
||||||
|
|
|
@ -53,6 +53,7 @@ $(document).ready(function() {
|
||||||
$("#btn_refresh").click(function() { refreshAlbums() });
|
$("#btn_refresh").click(function() { refreshAlbums() });
|
||||||
$("#btn_album_0").click(function() { showAlbum($(this)) });
|
$("#btn_album_0").click(function() { showAlbum($(this)) });
|
||||||
$(".albuminfo_label").click(function() { editAlbum(currentAlbum); });
|
$(".albuminfo_label").click(function() { editAlbum(currentAlbum); });
|
||||||
|
$(".btn_setthumbnail").click(function() { setAlbumThumbnail($(this)) });
|
||||||
getAlbumInfo();
|
getAlbumInfo();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -104,6 +105,10 @@ function getAlbumInfo() {
|
||||||
$("#albumscale").text(data.albumscale);
|
$("#albumscale").text(data.albumscale);
|
||||||
$("#albumdescription").text(data.albumdescription);
|
$("#albumdescription").text(data.albumdescription);
|
||||||
$("#albumcontents").html(data.albumcontents);
|
$("#albumcontents").html(data.albumcontents);
|
||||||
|
if ( data.currentalbum != 0 ) {
|
||||||
|
$("#griditem_"+data.thumbnailid).addClass("activethumbnail");
|
||||||
|
$(".btn_setthumbnail").click(function() { setAlbumThumbnail($(this)) });
|
||||||
|
}
|
||||||
$(".albumthumbnail").click(function() {
|
$(".albumthumbnail").click(function() {
|
||||||
if ( data.currentalbum == 0 ) {
|
if ( data.currentalbum == 0 ) {
|
||||||
showAlbum($(this));
|
showAlbum($(this));
|
||||||
|
@ -126,6 +131,25 @@ function getAlbumInfo() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setAlbumThumbnail(clickedElement) {
|
||||||
|
var imageid = clickedElement.attr("id").substring(clickedElement.attr("id").lastIndexOf("_") + 1);
|
||||||
|
$.ajax({
|
||||||
|
type: 'GET',
|
||||||
|
url: 'ajax/setthumbnail.php',
|
||||||
|
dataType: 'json',
|
||||||
|
data: {
|
||||||
|
imageid: imageid
|
||||||
|
},
|
||||||
|
success: function(data, stat, jqo) {
|
||||||
|
$(".thumbnail_grid").removeClass("activethumbnail");
|
||||||
|
$("#griditem_"+imageid).addClass("activethumbnail");
|
||||||
|
},
|
||||||
|
error: function(jqp, status, error) {
|
||||||
|
toastr.error("Error setting thumbnail!\n" + error, "Server Error");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function showImage(clickedElement) {
|
function showImage(clickedElement) {
|
||||||
var imageid = clickedElement.attr("id").substring(clickedElement.attr("id").lastIndexOf("_") + 1);
|
var imageid = clickedElement.attr("id").substring(clickedElement.attr("id").lastIndexOf("_") + 1);
|
||||||
var startIndex = 0;
|
var startIndex = 0;
|
||||||
|
|
|
@ -281,3 +281,6 @@ table tr td
|
||||||
.spacebelow_small {
|
.spacebelow_small {
|
||||||
margin-bottom: 1em;
|
margin-bottom: 1em;
|
||||||
}
|
}
|
||||||
|
.activethumbnail {
|
||||||
|
border: 2px solid orange;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user