diff options
author | Bartek Przybylski <bart.p.pl@gmail.com> | 2012-01-15 15:31:17 +0100 |
---|---|---|
committer | Bartek Przybylski <bart.p.pl@gmail.com> | 2012-01-15 15:31:37 +0100 |
commit | 07cf709eeb0be12376a1e471aa37bfd2cd8a9caf (patch) | |
tree | 289d21573350ef7df72f42f7a3bdf6118421ba09 /apps/gallery/js | |
parent | 63d9c1a8179bdefa6c4b6f089af6ce91cd11a46a (diff) | |
download | nextcloud-server-07cf709eeb0be12376a1e471aa37bfd2cd8a9caf.tar.gz nextcloud-server-07cf709eeb0be12376a1e471aa37bfd2cd8a9caf.zip |
better scanning model for gallery, more feedback to user while scanning
Diffstat (limited to 'apps/gallery/js')
-rw-r--r-- | apps/gallery/js/album_cover.js | 43 | ||||
-rw-r--r-- | apps/gallery/js/albums.js | 24 |
2 files changed, 40 insertions, 27 deletions
diff --git a/apps/gallery/js/album_cover.js b/apps/gallery/js/album_cover.js index 0009eb04e4f..e50593c0087 100644 --- a/apps/gallery/js/album_cover.js +++ b/apps/gallery/js/album_cover.js @@ -4,10 +4,11 @@ $(document).ready(function() { if (r.status == 'success') { for (var i in r.albums) { var a = r.albums[i]; - Albums.add(a.name, a.numOfItems, a.bgPath); + Albums.add(a.name, a.numOfItems); } var targetDiv = document.getElementById('gallery_list'); if (targetDiv) { + $(targetDiv).html(''); Albums.display(targetDiv); } else { alert('Error occured: no such layer `gallery_list`'); @@ -30,14 +31,42 @@ function createNewAlbum() { } } +var albumCounter = 0; +var totalAlbums = 0; + function scanForAlbums() { + var albumCounter = 0; + var totalAlbums = 0; + $('#notification').text("Scanning directories"); $("#notification").fadeIn(); $("#notification").slideDown(); - $.getJSON('ajax/galleryOp.php?operation=scan', function(r) { - $("#notification").fadeOut(); - $("#notification").slideUp(); + $.getJSON('ajax/galleryOp.php?operation=filescan', function(r) { + if (r.status == 'success') { - window.location.reload(true); + totalAlbums = r.paths.length; + $('#notification').text("Creating thumbnails ... " + Math.floor((albumCounter/totalAlbums)*100) + "%"); + for(var a in r.paths) { + $.getJSON('ajax/galleryOp.php?operation=partial_create&path='+r.paths[a], function(r) { + + if (r.status == 'success') { + Albums.add(r.album_details.albumName, r.album_details.imagesCount); + } + + albumCounter++; + $('#notification').text("Creating thumbnails ... " + Math.floor((albumCounter/totalAlbums)*100) + "%"); + if (albumCounter == totalAlbums) { + $("#notification").fadeOut(); + $("#notification").slideUp(); + var targetDiv = document.getElementById('gallery_list'); + if (targetDiv) { + targetDiv.innerHTML = ''; + Albums.display(targetDiv); + } else { + alert('Error occured: no such layer `gallery_list`'); + } + } + }); + } } else { alert('Error occured: ' + r.message); } @@ -48,8 +77,8 @@ 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); + $("#gallery_album_box[title='"+albumName+"']").remove(); + Albums.remove(albumName); } else { alert("Error: " + r.cause); } diff --git a/apps/gallery/js/albums.js b/apps/gallery/js/albums.js index 2fb1ac89bab..546aadba49f 100644 --- a/apps/gallery/js/albums.js +++ b/apps/gallery/js/albums.js @@ -12,13 +12,9 @@ Albums={ // album with the same name wont be insered, // and false will be returned // true on success - add: function(album_name, num, bgPath) { - for (var a in Albums.albums) { - if (a.name == album_name) { - return false; - } - } - Albums.albums.push({name: album_name, numOfCovers: num, backgroundPath: bgPath}); + add: function(album_name, num) { + if (Albums.albums[album_name] != undefined) return false; + Albums.albums[album_name] = {name: album_name, numOfCovers: num}; return true; }, // remove element with given name @@ -40,19 +36,7 @@ Albums={ // return element which match given name // of undefined if such element do not exist find: function(name) { - var i = -1, tmp = 0; - for (var k in Albums.albums) { - var a = Albums.albums[k]; - if (a.name == name) { - i = tmp; - break; - } - tmp++; - } - if (i != -1) { - return Albums.albums[i]; - } - return undefined; + return Albums.albums[name]; }, // displays gallery in linear representation // on given element, and apply default styles for gallery |