2011-09-26 00:32:08 +04:00
|
|
|
var actual_cover;
|
2012-03-04 21:28:41 +04:00
|
|
|
var paths = '';
|
|
|
|
var crumbCount = 0;
|
|
|
|
$(document).ready(returnToElement(0));
|
|
|
|
|
|
|
|
function returnToElement(num) {
|
|
|
|
while (crumbCount != num) {
|
|
|
|
$('#g-album-navigation .last').remove();
|
|
|
|
$('#g-album-navigation .crumb :last').parent().addClass('last');
|
|
|
|
crumbCount--;
|
|
|
|
paths = paths.substring(0, paths.lastIndexOf('\/'));
|
|
|
|
}
|
|
|
|
$.getJSON('ajax/galleryOp.php', {operation: 'get_gallery', path: paths }, albumClickHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
function albumClick(e) {
|
|
|
|
var title = decodeURIComponent(escape(e.data.title));
|
|
|
|
paths += '/' + title;
|
|
|
|
crumbCount++;
|
|
|
|
$.getJSON('ajax/galleryOp.php', {operation: 'get_gallery', path: paths }, albumClickHandler);
|
|
|
|
if ($('#g-album-navigation :last-child'))
|
|
|
|
$('#g-album-navigation :last-child').removeClass('last');
|
|
|
|
$('#g-album-navigation').append('<div class="crumb last real" style="background-image:url(\''+OC.webroot+'/core/img/breadcrumb.png\')"><a href=\"javascript:returnToElement('+crumbCount+');\">'+title+'</a></div>');
|
|
|
|
}
|
|
|
|
|
|
|
|
function albumClickHandler(r) {
|
|
|
|
Albums.photos = [];
|
|
|
|
Albums.albums = [];
|
2011-10-01 13:26:47 +04:00
|
|
|
if (r.status == 'success') {
|
|
|
|
for (var i in r.albums) {
|
|
|
|
var a = r.albums[i];
|
2012-01-15 18:31:17 +04:00
|
|
|
Albums.add(a.name, a.numOfItems);
|
2011-09-26 00:32:08 +04:00
|
|
|
}
|
2012-03-04 21:28:41 +04:00
|
|
|
for (var i in r.photos) {
|
|
|
|
Albums.photos.push(r.photos[i]);
|
|
|
|
}
|
2011-10-01 13:26:47 +04:00
|
|
|
var targetDiv = document.getElementById('gallery_list');
|
|
|
|
if (targetDiv) {
|
2012-01-15 18:31:17 +04:00
|
|
|
$(targetDiv).html('');
|
2011-10-01 13:26:47 +04:00
|
|
|
Albums.display(targetDiv);
|
2012-03-04 21:28:41 +04:00
|
|
|
//$('#gallery_list').sortable({revert:true});
|
|
|
|
$('.album').each(function(i, el) {
|
|
|
|
$(el).click({title:$(el).attr('title')}, albumClick);
|
|
|
|
//$(el).draggable({connectToSortable: '#gallery_list', handle: '.dummy'});
|
2012-01-30 22:36:33 +04:00
|
|
|
});
|
2011-10-01 13:26:47 +04:00
|
|
|
} else {
|
2012-03-04 21:28:41 +04:00
|
|
|
OC.dialogs.alert(t('gallery', 'Error: no such layer `gallery_list`'), t('gallery', 'Internal error'));
|
2011-10-01 13:26:47 +04:00
|
|
|
}
|
|
|
|
} else {
|
2012-03-04 21:28:41 +04:00
|
|
|
OC.dialogs.alert(t('gallery', 'Error: ') + r.message, t('gallery', 'Internal error'));
|
2011-10-01 13:26:47 +04:00
|
|
|
}
|
2012-03-04 21:28:41 +04:00
|
|
|
}
|
2011-09-26 00:32:08 +04:00
|
|
|
|
|
|
|
function createNewAlbum() {
|
|
|
|
var name = prompt("album name", "");
|
|
|
|
if (name != null && name != "") {
|
|
|
|
$.getJSON("ajax/createAlbum.php", {album_name: name}, function(r) {
|
|
|
|
if (r.status == "success") {
|
2012-03-04 21:28:41 +04:00
|
|
|
var v = '<div class="gallery_box"><a href="?view='+r.name+'"><img class="gallery_album_cover"/></a><h1>'+r.name+'</h1></div>';
|
2011-09-26 00:32:08 +04:00
|
|
|
$('div#gallery_list').append(v);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-15 18:31:17 +04:00
|
|
|
var albumCounter = 0;
|
|
|
|
var totalAlbums = 0;
|
|
|
|
|
2012-02-04 00:38:44 +04:00
|
|
|
function scanForAlbums(cleanup) {
|
|
|
|
cleanup = cleanup?true:false;
|
2012-01-15 18:31:17 +04:00
|
|
|
var albumCounter = 0;
|
|
|
|
var totalAlbums = 0;
|
2012-02-04 00:38:44 +04:00
|
|
|
$('#g-scan-button').attr('disabled', 'true');
|
|
|
|
$.getJSON('ajax/galleryOp.php?operation=filescan', {cleanup: cleanup}, function(r) {
|
2012-01-15 18:31:17 +04:00
|
|
|
|
2011-09-26 00:32:08 +04:00
|
|
|
if (r.status == 'success') {
|
2012-01-15 18:31:17 +04:00
|
|
|
totalAlbums = r.paths.length;
|
2012-01-24 02:25:36 +04:00
|
|
|
if (totalAlbums == 0) {
|
|
|
|
$('#notification').text(t('gallery', "No photos found")).fadeIn().slideDown().delay(3000).fadeOut().slideUp();
|
|
|
|
return;
|
|
|
|
}
|
2012-01-30 22:36:33 +04:00
|
|
|
$('#scanprogressbar').progressbar({ value: (albumCounter/totalAlbums)*100 }).fadeIn();
|
2012-01-15 18:31:17 +04:00
|
|
|
for(var a in r.paths) {
|
2012-03-04 21:28:41 +04:00
|
|
|
$.getJSON('ajax/galleryOp.php',{operation:'partial_create','path':r.paths[a]}, function(r) {
|
2012-01-15 18:31:17 +04:00
|
|
|
|
|
|
|
albumCounter++;
|
2012-01-30 22:36:33 +04:00
|
|
|
$('#scanprogressbar').progressbar({ value: (albumCounter/totalAlbums)*100 });
|
2012-01-15 18:31:17 +04:00
|
|
|
if (albumCounter == totalAlbums) {
|
2012-01-30 22:36:33 +04:00
|
|
|
$('#scanprogressbar').fadeOut();
|
2012-01-15 18:31:17 +04:00
|
|
|
var targetDiv = document.getElementById('gallery_list');
|
|
|
|
if (targetDiv) {
|
|
|
|
targetDiv.innerHTML = '';
|
2012-03-04 21:28:41 +04:00
|
|
|
Albums.photos = [];
|
|
|
|
Albums.albums = [];
|
|
|
|
returnToElement(0);
|
2012-01-15 18:31:17 +04:00
|
|
|
} else {
|
|
|
|
alert('Error occured: no such layer `gallery_list`');
|
|
|
|
}
|
2012-02-04 00:38:44 +04:00
|
|
|
$('#g-scan-button').attr('disabled', null);
|
2012-01-15 18:31:17 +04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2011-09-26 00:32:08 +04:00
|
|
|
} else {
|
|
|
|
alert('Error occured: ' + r.message);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2011-12-22 00:55:52 +04:00
|
|
|
|
|
|
|
function galleryRemove(albumName) {
|
2012-03-04 03:35:37 +04:00
|
|
|
OC.dialogs.confirm(t('gallery', 'Do you want to remove album ') + decodeURIComponent(escape(albumName)),
|
|
|
|
t('gallery', 'Remove confirmation'),
|
|
|
|
function(decision) {
|
|
|
|
if (decision) {
|
|
|
|
$.getJSON("ajax/galleryOp.php", {operation: "remove", name: decodeURIComponent(escape(albumName))}, function(r) {
|
|
|
|
if (r.status == "success") {
|
2012-03-04 21:28:41 +04:00
|
|
|
$(".gallery_box").filterAttr('data-album',albumName).remove();
|
2012-03-04 03:35:37 +04:00
|
|
|
Albums.remove(albumName);
|
|
|
|
} else {
|
|
|
|
OC.dialogs.alert(r.cause, "Error");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2012-01-30 22:36:33 +04:00
|
|
|
});
|
2011-12-22 00:55:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function galleryRename(name) {
|
2012-03-04 03:35:37 +04:00
|
|
|
OC.dialogs.prompt(t('gallery', 'New album name'),
|
|
|
|
t('gallery', 'Change name'),
|
|
|
|
name,
|
|
|
|
function(newname) {
|
|
|
|
if (newname == name || newname == '') return;
|
|
|
|
if (Albums.find(newname)) {
|
|
|
|
OC.dialogs.alert('Album ' + newname + ' exists', 'Alert');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$.getJSON('ajax/galleryOp.php', {operation: 'rename', oldname: name, newname: newname}, function(r) {
|
|
|
|
if (r.status == 'success') {
|
2012-03-04 21:28:41 +04:00
|
|
|
Albums.rename($(".gallery_box").filterAttr('data-album',name), newname);
|
2012-03-04 03:35:37 +04:00
|
|
|
} else {
|
|
|
|
OC.dialogs.alert('Error: ' + r.cause, 'Error');
|
|
|
|
}
|
|
|
|
});
|
2012-01-30 22:36:33 +04:00
|
|
|
});
|
2011-12-22 00:55:52 +04:00
|
|
|
}
|
|
|
|
|
2012-02-04 00:38:44 +04:00
|
|
|
function settings() {
|
|
|
|
$( '#g-dialog-settings' ).dialog({
|
|
|
|
height: 180,
|
|
|
|
width: 350,
|
|
|
|
modal: false,
|
|
|
|
buttons: [{
|
|
|
|
text: t('gallery', 'Apply'),
|
|
|
|
click: function() {
|
|
|
|
var scanning_root = $('#g-scanning-root').val();
|
|
|
|
var disp_order = $('#g-display-order option:selected').val();
|
|
|
|
if (scanning_root == '') {
|
|
|
|
alert('Scanning root cannot be empty');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$.getJSON('ajax/galleryOp.php', {operation: 'store_settings', root: scanning_root, order: disp_order}, function(r) {
|
|
|
|
if (r.status == 'success') {
|
|
|
|
if (r.rescan == 'yes') {
|
|
|
|
$('#g-dialog-settings').dialog('close');
|
|
|
|
Albums.clear(document.getElementById('gallery_list'));
|
|
|
|
scanForAlbums(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
alert('Error: ' + r.cause);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$('#g-dialog-settings').dialog('close');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: t('gallery', 'Cancel'),
|
|
|
|
click: function() {
|
|
|
|
$(this).dialog('close');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
});
|
|
|
|
}
|