2011-09-26 00:32:08 +04:00
|
|
|
var actual_cover;
|
2012-03-07 21:58:10 +04:00
|
|
|
var paths = [];
|
2012-03-04 21:28:41 +04:00
|
|
|
var crumbCount = 0;
|
|
|
|
$(document).ready(returnToElement(0));
|
|
|
|
|
|
|
|
function returnToElement(num) {
|
2012-03-07 21:58:10 +04:00
|
|
|
while (crumbCount != num) {
|
|
|
|
$('#g-album-navigation .last').remove();
|
|
|
|
$('#g-album-navigation .crumb :last').parent().addClass('last');
|
|
|
|
crumbCount--;
|
|
|
|
paths.pop();
|
|
|
|
}
|
|
|
|
path=paths[paths.length-1];
|
|
|
|
$.getJSON(OC.filePath('gallery','ajax','galleryOp.php'), {operation: 'get_gallery', path: path }, albumClickHandler);
|
2012-03-04 21:28:41 +04:00
|
|
|
}
|
|
|
|
|
2012-03-07 21:58:10 +04:00
|
|
|
function albumClick(title,path) {
|
|
|
|
paths.push(path);
|
|
|
|
crumbCount++;
|
|
|
|
$.getJSON(OC.filePath('gallery','ajax','galleryOp.php'), {operation: 'get_gallery', path: path }, 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.imagePath('core','breadcrumb')+'\')"><a href=\"javascript:returnToElement('+crumbCount+');\">'+title+'</a></div>');
|
2012-03-04 21:28:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function albumClickHandler(r) {
|
2012-03-07 21:58:10 +04:00
|
|
|
Albums.photos = [];
|
|
|
|
Albums.albums = [];
|
|
|
|
if (r.status == 'success') {
|
|
|
|
for (var i in r.albums) {
|
|
|
|
var a = r.albums[i];
|
|
|
|
Albums.add(a.name, a.numOfItems,a.path);
|
|
|
|
}
|
|
|
|
for (var i in r.photos) {
|
|
|
|
Albums.photos.push(r.photos[i]);
|
|
|
|
}
|
|
|
|
var targetDiv = document.getElementById('gallery_list');
|
|
|
|
if (targetDiv) {
|
|
|
|
$(targetDiv).html('');
|
|
|
|
Albums.display(targetDiv);
|
|
|
|
//$('#gallery_list').sortable({revert:true});
|
|
|
|
$('.album').each(function(i, el) {
|
|
|
|
$(el).click(albumClick.bind(null,$(el).attr('title'),$(el).data('path')));
|
|
|
|
//$(el).draggable({connectToSortable: '#gallery_list', handle: '.dummy'});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
OC.dialogs.alert(t('gallery', 'Error: no such layer `gallery_list`'), t('gallery', 'Internal error'));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
OC.dialogs.alert(t('gallery', 'Error: ') + r.message, t('gallery', 'Internal error'));
|
|
|
|
}
|
2012-03-04 21:28:41 +04:00
|
|
|
}
|
2011-09-26 00:32:08 +04:00
|
|
|
|
|
|
|
function createNewAlbum() {
|
2012-03-07 21:58:10 +04:00
|
|
|
var name = prompt("album name", "");
|
|
|
|
if (name != null && name != "") {
|
|
|
|
$.getJSON(OC.filePath('gallery','ajax','createAlbum.php'), {album_name: name}, function(r) {
|
|
|
|
if (r.status == "success") {
|
|
|
|
var v = '<div class="gallery_box"><a href="?view='+r.name+'"><img class="gallery_album_cover"/></a><h1>'+r.name+'</h1></div>';
|
|
|
|
$('div#gallery_list').append(v);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2011-09-26 00:32:08 +04:00
|
|
|
}
|
|
|
|
|
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) {
|
2012-03-07 21:58:10 +04:00
|
|
|
cleanup = cleanup?true:false;
|
|
|
|
var albumCounter = 0;
|
|
|
|
var totalAlbums = 0;
|
|
|
|
$('#g-scan-button').attr('disabled', 'true');
|
|
|
|
$.getJSON(OC.filePath('gallery','ajax','galleryOp.php'), {cleanup: cleanup,operation:'filescan'}, function(r) {
|
2012-01-15 18:31:17 +04:00
|
|
|
|
2012-03-07 21:58:10 +04:00
|
|
|
if (r.status == 'success') {
|
|
|
|
totalAlbums = r.paths.length;
|
|
|
|
if (totalAlbums == 0) {
|
|
|
|
$('#notification').text(t('gallery', "No photos found")).fadeIn().slideDown().delay(3000).fadeOut().slideUp();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$('#scanprogressbar').progressbar({ value: (albumCounter/totalAlbums)*100 }).fadeIn();
|
|
|
|
for(var a in r.paths) {
|
|
|
|
$.getJSON(OC.filePath('gallery','ajax','galleryOp.php'),{operation:'partial_create','path':r.paths[a]}, function(r) {
|
2012-01-15 18:31:17 +04:00
|
|
|
|
2012-03-07 21:58:10 +04:00
|
|
|
albumCounter++;
|
|
|
|
$('#scanprogressbar').progressbar({ value: (albumCounter/totalAlbums)*100 });
|
|
|
|
if (albumCounter == totalAlbums) {
|
|
|
|
$('#scanprogressbar').fadeOut();
|
|
|
|
var targetDiv = document.getElementById('gallery_list');
|
|
|
|
if (targetDiv) {
|
|
|
|
targetDiv.innerHTML = '';
|
|
|
|
Albums.photos = [];
|
|
|
|
Albums.albums = [];
|
|
|
|
returnToElement(0);
|
|
|
|
} else {
|
|
|
|
alert('Error occured: no such layer `gallery_list`');
|
|
|
|
}
|
|
|
|
$('#g-scan-button').attr('disabled', null);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
alert('Error occured: ' + r.message);
|
|
|
|
}
|
|
|
|
});
|
2011-09-26 00:32:08 +04:00
|
|
|
}
|
2011-12-22 00:55:52 +04:00
|
|
|
|
|
|
|
function galleryRemove(albumName) {
|
2012-03-07 21:58:10 +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(OC.filePath('gallery','ajax','galleryOp.php'), {operation: "remove", name: decodeURIComponent(escape(albumName))}, function(r) {
|
|
|
|
if (r.status == "success") {
|
|
|
|
$(".gallery_box").filterAttr('data-album',albumName).remove();
|
|
|
|
Albums.remove(albumName);
|
|
|
|
} else {
|
|
|
|
OC.dialogs.alert(r.cause, "Error");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2011-12-22 00:55:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function galleryRename(name) {
|
2012-03-07 21:58:10 +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(OC.filePath('gallery','ajax','galleryOp.php'), {operation: 'rename', oldname: name, newname: newname}, function(r) {
|
|
|
|
if (r.status == 'success') {
|
|
|
|
Albums.rename($(".gallery_box").filterAttr('data-album',name), newname);
|
|
|
|
} else {
|
|
|
|
OC.dialogs.alert('Error: ' + r.cause, 'Error');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
2011-12-22 00:55:52 +04:00
|
|
|
}
|
|
|
|
|
2012-02-04 00:38:44 +04:00
|
|
|
function settings() {
|
2012-03-07 21:58:10 +04:00
|
|
|
$( '#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(OC.filePath('gallery','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');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
});
|
2012-02-04 00:38:44 +04:00
|
|
|
}
|