removing and renaming albums
This commit is contained in:
parent
6a1a7fcd26
commit
1383cb51e7
|
@ -0,0 +1,29 @@
|
|||
<?
|
||||
require_once('../../../lib/base.php');
|
||||
require_once('../lib/album.php');
|
||||
OC_JSON::checkLoggedIn();
|
||||
OC_JSON::checkAppEnabled('gallery');
|
||||
|
||||
function handleRename($oldname, $newname) {
|
||||
OC_Gallery_Album::rename($oldname, $newname, OC_User::getUser());
|
||||
}
|
||||
|
||||
function handleRemove($name) {
|
||||
OC_Gallery_Album::remove(OC_User::getUser(), $name);
|
||||
}
|
||||
|
||||
if ($_GET['operation']) {
|
||||
switch($_GET['operation']) {
|
||||
case "rename":
|
||||
handleRename($_GET['oldname'], $_GET['newname']);
|
||||
OC_JSON::success(array('newname' => $_GET['newname']));
|
||||
break;
|
||||
case "remove":
|
||||
handleRemove($_GET['name']);
|
||||
OC_JSON::success();
|
||||
break;
|
||||
default:
|
||||
OC_JSON::error(array('cause' => "Unknown operation"));
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -16,6 +16,7 @@ div#gallery_album_box {
|
|||
vertical-align: top;
|
||||
padding: 10px;
|
||||
border: solid 1px black;
|
||||
position: relative;
|
||||
}
|
||||
.leftcontent div#gallery_album_box {
|
||||
margin: 5px;
|
||||
|
@ -23,20 +24,28 @@ div#gallery_album_box {
|
|||
|
||||
div#gallery_album_box h1 {
|
||||
font-size: 12pt;
|
||||
font-family: Arial;
|
||||
font-family: Verdana;
|
||||
}
|
||||
|
||||
div#gallery_album_cover {
|
||||
width: 199px;
|
||||
height: 199px;
|
||||
border: solid 1px #999;
|
||||
border: solid 1pt #999;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
div#gallery_control_overlay {
|
||||
width:199px;
|
||||
height:199px;
|
||||
position:relative;
|
||||
border: 0;
|
||||
position:absolute;
|
||||
right: 10pt;
|
||||
background-color: #333;
|
||||
opacity: 0.5;
|
||||
visibility:hidden;
|
||||
padding: 0 5pt;
|
||||
}
|
||||
|
||||
div#gallery_control_overlay a {
|
||||
color:white;
|
||||
}
|
||||
|
||||
#gallery_images {
|
||||
|
|
|
@ -39,3 +39,37 @@ function scanForAlbums() {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
function galleryRemove(albumName) {
|
||||
if (confirm("Do you wan't to remove album " + albumName + "?")) {
|
||||
$.getJSON("ajax/galleryOp.php", {operation: "remove", name: albumName}, function(r) {
|
||||
if (r.status == "success") {
|
||||
$("#gallery_album_box[title='"+albumName+"']").remove();
|
||||
Albums.remove(albumName);
|
||||
} else {
|
||||
alert("Error: " + r.cause);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function galleryRename(name) {
|
||||
var result = window.prompt("Input new gallery name", "");
|
||||
if (result) {
|
||||
if (Albums.find(result)) {
|
||||
alert("Album named '" + result + "' already exists");
|
||||
return;
|
||||
}
|
||||
$.getJSON("ajax/galleryOp.php", {operation: "rename", oldname: name, newname: result}, function(r) {
|
||||
if (r.status == "success") {
|
||||
Albums.rename($("#gallery_album_box[title='"+name+"']"), result);
|
||||
} else {
|
||||
alert("Error: " + r.cause);
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
alert("Album name can't be empty")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -57,13 +57,19 @@ Albums={
|
|||
// displays gallery in linear representation
|
||||
// on given element, and apply default styles for gallery
|
||||
display: function(element) {
|
||||
var displayTemplate = '<div id="gallery_album_box" title="*NAME*"><a href="#?view=*NAME*"><div id="#gallery_control_overlay"><div id="gallery_album_cover" title="*NAME*"></div></div></a><h1>*NAME*</h1></div></div>';
|
||||
var displayTemplate = '<div id="gallery_album_box" title="*NAME*"><div id="gallery_control_overlay"><a href="#" onclick="galleryRename(\'*NAME*\');return false;">rename</a> | <a href="#" onclick="galleryRemove(\'*NAME*\');">remove</a></div><a href="?view=*NAME*"><div id="gallery_album_cover" title="*NAME*"></div></a><h1>*NAME*</h1></div></div>';
|
||||
for (var i in Albums.albums) {
|
||||
var a = Albums.albums[i];
|
||||
var local = $(displayTemplate.replace(/\*NAME\*/g, a.name));
|
||||
$("#gallery_album_cover", local).css('background-repeat', 'no-repeat');
|
||||
$("#gallery_album_cover", local).css('background-position', '0');
|
||||
$("#gallery_album_cover", local).css('background-image','url("ajax/getCovers.php?album_name='+a.name+'")');
|
||||
local.mouseover(function(e) {
|
||||
$("#gallery_control_overlay", this).css('visibility','visible');
|
||||
});
|
||||
local.mouseout(function(e) {
|
||||
$("#gallery_control_overlay", this).css('visibility','hidden');
|
||||
});
|
||||
$("#gallery_album_cover", local).mousemove(function(e) {
|
||||
|
||||
var albumMetadata = Albums.find(this.title);
|
||||
|
@ -71,7 +77,7 @@ Albums={
|
|||
return;
|
||||
}
|
||||
var x = Math.min(Math.floor((e.layerX - this.offsetLeft)/(this.offsetWidth/albumMetadata.numOfCovers)), albumMetadata.numOfCovers-1);
|
||||
x *= this.offsetWidth;
|
||||
x *= this.offsetWidth-1;
|
||||
$(this).css('background-position', -x+'px 0');
|
||||
});
|
||||
$(element).append(local);
|
||||
|
|
|
@ -1,10 +1,27 @@
|
|||
<?php
|
||||
|
||||
class OC_Gallery_Album{
|
||||
class OC_Gallery_Album {
|
||||
public static function create($owner, $name){
|
||||
$stmt = OC_DB::prepare('INSERT INTO *PREFIX*gallery_albums (uid_owner, album_name) VALUES (?, ?)');
|
||||
$stmt->execute(array($owner, $name));
|
||||
}
|
||||
|
||||
public static function rename($oldname, $newname, $owner) {
|
||||
$stmt = OC_DB::prepare('UPDATE OR IGNORE *PREFIX*gallery_albums SET album_name=? WHERE uid_owner=? AND album_name=?');
|
||||
$stmt->execute(array($newname, $owner, $oldname));
|
||||
}
|
||||
|
||||
public static function remove($owner, $name=null) {
|
||||
$sql = 'DELETE FROM *PREFIX*gallery_albums WHERE uid_owner = ?';
|
||||
$args = array($owner);
|
||||
if (!is_null($name)){
|
||||
$sql .= ' AND album_name = ?';
|
||||
$args[] = $name;
|
||||
}
|
||||
$stmt = OC_DB::prepare($sql);
|
||||
return $stmt->execute($args);
|
||||
}
|
||||
|
||||
public static function find($owner, $name=null){
|
||||
$sql = 'SELECT * FROM *PREFIX*gallery_albums WHERE uid_owner = ?';
|
||||
$args = array($owner);
|
||||
|
|
Loading…
Reference in New Issue