nextcloud/apps/gallery/js/album_cover.js

139 lines
4.9 KiB
JavaScript
Raw Normal View History

2011-09-26 00:32:08 +04:00
var actual_cover;
var paths = [];
2012-03-04 21:28:41 +04:00
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.pop();
}
2012-03-11 19:49:21 +04:00
var p='';
for (var i in paths) p += paths[i]+'/';
$('#g-album-loading').show();
$.getJSON(OC.filePath('gallery','ajax','galleryOp.php'), {operation: 'get_gallery', path: p }, albumClickHandler);
2012-03-04 21:28:41 +04:00
}
2012-03-11 19:49:21 +04:00
function albumClick(title) {
paths.push(title);
crumbCount++;
2012-03-11 19:49:21 +04:00
var p = '';
for (var i in paths) p += paths[i]+'/';
$('#g-album-loading').show();
$.getJSON(OC.filePath('gallery','ajax','galleryOp.php'), {operation: 'get_gallery', path: p }, function(r) {
albumClickHandler(r);
if ($('#g-album-navigation :last-child'))
$('#g-album-navigation :last-child').removeClass('last');
2012-03-11 19:49:21 +04:00
$('#g-album-navigation').append('<div class="crumb last real" style="background-image:url(\''+OC.imagePath('core','breadcrumb')+'\')"><a href=\"javascript:returnToElement('+crumbCount+');\">'+decodeURIComponent(escape(title))+'</a></div>');
});
2012-03-04 21:28:41 +04:00
}
function constructSharingPath() {
2012-05-07 18:46:35 +04:00
return document.location.protocol + '//' + document.location.host + OC.linkTo('', 'public.php') + '?service=gallery&token=' + Albums.token;
}
2012-03-24 21:35:16 +04:00
function shareGallery() {
var existing_token = '';
if (Albums.token)
existing_token = constructSharingPath();
2012-03-24 21:35:16 +04:00
var form_fields = [{text: 'Share', name: 'share', type: 'checkbox', value: Albums.shared},
{text: 'Share recursive', name: 'recursive', type: 'checkbox', value: Albums.recursive},
{text: 'Shared gallery address', name: 'address', type: 'text', value: existing_token}];
OC.dialogs.form(form_fields, t('gallery', 'Share gallery'), function(values){
var p = '';
2012-03-30 23:14:01 +04:00
for (var i in paths) p += paths[i]+'/';
2012-03-24 21:35:16 +04:00
if (p == '') p = '/';
2012-03-30 23:14:01 +04:00
alert(p);
2012-03-24 21:35:16 +04:00
$.getJSON(OC.filePath('gallery', 'ajax', 'galleryOp.php'), {operation: 'share', path: p, share: values[0].value, recursive: values[1].value}, function(r) {
if (r.status == 'success') {
Albums.shared = r.sharing;
if (Albums.shared) {
Albums.token = r.token;
Albums.recursive = r.recursive;
} else {
Albums.token = '';
Albums.recursive = false;
}
var actual_addr = '';
if (Albums.token)
actual_addr = constructSharingPath();
2012-03-24 21:35:16 +04:00
$('input[name="address"]').val(actual_addr);
} else {
OC.dialogs.alert(t('gallery', 'Error: ') + r.cause, t('gallery', 'Internal error'));
}
});
});
}
2012-03-04 21:28:41 +04:00
function albumClickHandler(r) {
Albums.photos = [];
Albums.albums = [];
if (r.status == 'success') {
for (var i in r.albums) {
var a = r.albums[i];
2012-03-24 21:35:16 +04:00
Albums.add(a.name, a.numOfItems, a.path, a.shared, a.recursive, a.token);
}
for (var i in r.photos) {
2012-03-24 21:35:16 +04:00
Albums.photos.push(r.photos[i]);
}
2012-03-24 21:35:16 +04:00
Albums.shared = r.shared;
if (Albums.shared) {
Albums.recursive = r.recursive;
Albums.token = r.token;
} else {
Albums.recursive = false;
Albums.token = '';
}
$(document).ready(function(){
var targetDiv = $('#gallery_list');
targetDiv.html('');
Albums.display(targetDiv);
//$('#gallery_list').sortable({revert:true});
$('.album').each(function(i, el) {
2012-03-11 19:49:21 +04:00
$(el).click(albumClick.bind(null,$(el).attr('title')));
//$(el).draggable({connectToSortable: '#gallery_list', handle: '.dummy'});
});
});
} else {
2012-03-24 21:35:16 +04:00
OC.dialogs.alert(t('gallery', 'Error: ') + r.cause, t('gallery', 'Internal error'));
}
2012-03-11 19:49:21 +04:00
$('#g-album-loading').hide();
2011-09-26 00:32:08 +04:00
}
var albumCounter = 0;
var totalAlbums = 0;
function scanForAlbums(cleanup) {
2012-03-11 19:49:21 +04:00
Scanner.scanAlbums();
return;
2011-12-22 00:55:52 +04:00
}
function settings() {
OC.dialogs.form([{text: t('gallery', 'Scanning root'), name: 'root', type:'text', value:gallery_scanning_root},
{text: t('gallery', 'Default order'), name: 'order', type:'select', value:gallery_default_order, options:[
{text:t('gallery', 'Ascending'), value:'ASC'}, {text: t('gallery', 'Descending'), value:'DESC'} ]}],
t('gallery', 'Settings'),
function(values) {
var scanning_root = values[0].value;
var disp_order = values[1].value;
if (scanning_root == '') {
OC.dialogs.alert(t('gallery', 'Scanning root cannot be empty'), t('gallery', 'Error'));
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') {
Albums.clear(document.getElementById('gallery_list'));
scanForAlbums(true);
}
gallery_scanning_root = scanning_root;
} else {
OC.dialogs.alert(t('gallery', 'Error: ') + r.cause, t('gallery', 'Error'));
return;
}
});
});
}