summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBartek Przybylski <bart.p.pl@gmail.com>2012-02-03 21:38:44 +0100
committerBartek Przybylski <bart.p.pl@gmail.com>2012-02-03 21:38:44 +0100
commit8df065065892ecfb1a3e6d31294d332fa8e4daf6 (patch)
tree83e824eb08d6e20f6bdbc117dcf67097332c4d30
parentee01d1a81d561fb41916bb3d231452956317b7bc (diff)
downloadnextcloud-server-8df065065892ecfb1a3e6d31294d332fa8e4daf6.tar.gz
nextcloud-server-8df065065892ecfb1a3e6d31294d332fa8e4daf6.zip
gallery settings, defining scan root and shor order
-rw-r--r--apps/gallery/ajax/galleryOp.php30
-rw-r--r--apps/gallery/css/styles.css3
-rw-r--r--apps/gallery/js/album_cover.js52
-rw-r--r--apps/gallery/js/albums.js6
-rw-r--r--apps/gallery/lib/album.php11
-rw-r--r--apps/gallery/templates/index.php28
6 files changed, 119 insertions, 11 deletions
diff --git a/apps/gallery/ajax/galleryOp.php b/apps/gallery/ajax/galleryOp.php
index 0c2674f8859..187cd8af292 100644
--- a/apps/gallery/ajax/galleryOp.php
+++ b/apps/gallery/ajax/galleryOp.php
@@ -54,9 +54,11 @@ function handleGalleryScanning() {
OC_JSON::success(array('albums' => OC_Gallery_Scanner::scan('/')));
}
-function handleFilescan() {
+function handleFilescan($cleanup) {
OC_JSON::checkLoggedIn();
- $pathlist = OC_Gallery_Scanner::find_paths('/');
+ if ($cleanup) OC_Gallery_Album::cleanup();
+ $root = OC_Appconfig::getValue('gallery', 'root', '').'/';
+ $pathlist = OC_Gallery_Scanner::find_paths($root);
sort($pathlist);
OC_JSON::success(array('paths' => $pathlist));
}
@@ -72,6 +74,25 @@ function handlePartialCreate($path) {
OC_JSON::success(array('album_details' => $albums));
}
+function handleStoreSettings($root, $order) {
+ OC_JSON::checkLoggedIn();
+ if (!OC_Filesystem::file_exists($root)) {
+ OC_JSON::error(array('cause' => 'No such file or directory'));
+ return;
+ }
+ if (!OC_Filesystem::is_dir($root)) {
+ OC_JSON::error(array('cause' => $root . ' is not a directory'));
+ return;
+ }
+
+ $current_root = OC_Appconfig::getValue('gallery', 'root', '/');
+ $root = trim(rtrim($root, '/'));
+ $rescan = $current_root==$root?'no':'yes';
+ OC_Appconfig::setValue('gallery', 'root', $root);
+ OC_Appconfig::setValue('gallery', 'order', $order);
+ OC_JSON::success(array('rescan' => $rescan));
+}
+
if ($_GET['operation']) {
switch($_GET['operation']) {
case 'rename':
@@ -89,11 +110,14 @@ if ($_GET['operation']) {
handleGalleryScanning();
break;
case 'filescan':
- handleFilescan();
+ handleFilescan($_GET['cleanup']);
break;
case 'partial_create':
handlePartialCreate($_GET['path']);
break;
+ case 'store_settings':
+ handleStoreSettings($_GET['root'], $_GET['order']);
+ break;
default:
OC_JSON::error(array('cause' => 'Unknown operation'));
}
diff --git a/apps/gallery/css/styles.css b/apps/gallery/css/styles.css
index 7872b6445ca..c039cd5ec02 100644
--- a/apps/gallery/css/styles.css
+++ b/apps/gallery/css/styles.css
@@ -12,3 +12,6 @@ div.gallery_control_overlay a { color:white; }
#gallery_images.rightcontent { padding:10px 5px; bottom: 0px; overflow: auto; right:0px}
#scan { position:absolute; right:13.5em; top:0em; }
#scan #scanprogressbar { position:relative; display:inline-block; width:10em; height:1.5em; top:.4em; }
+#g-settings {position: absolute; left 13.5em; top: 0;}
+input[type=button] { -webkit-transition: opacity 0.5s ease-in-out; -moz-transition: opacity 0.5s ease-in-out; -o-transition: opacity 0.5s ease-in-out; opacity: 1}
+input[type=button]:disabled { opacity: 0.5 }
diff --git a/apps/gallery/js/album_cover.js b/apps/gallery/js/album_cover.js
index e78db221cff..4ddac2f2111 100644
--- a/apps/gallery/js/album_cover.js
+++ b/apps/gallery/js/album_cover.js
@@ -38,10 +38,12 @@ function createNewAlbum() {
var albumCounter = 0;
var totalAlbums = 0;
-function scanForAlbums() {
+function scanForAlbums(cleanup) {
+ cleanup = cleanup?true:false;
var albumCounter = 0;
var totalAlbums = 0;
- $.getJSON('ajax/galleryOp.php?operation=filescan', function(r) {
+ $('#g-scan-button').attr('disabled', 'true');
+ $.getJSON('ajax/galleryOp.php?operation=filescan', {cleanup: cleanup}, function(r) {
if (r.status == 'success') {
totalAlbums = r.paths.length;
@@ -68,6 +70,7 @@ function scanForAlbums() {
} else {
alert('Error occured: no such layer `gallery_list`');
}
+ $('#g-scan-button').attr('disabled', null);
}
});
}
@@ -125,13 +128,13 @@ function galleryRename(name) {
$(this).dialog("close");
return;
}
- $.getJSON("ajax/galleryOp.php", {operation: "rename", oldname: name, newname: newname}, function(r) {
+ $.getJSON('ajax/galleryOp.php', {operation: 'rename', oldname: name, newname: newname}, function(r) {
if (r.status == "success") {
Albums.rename($(".gallery_album_box").filterAttr('data-album',name), newname);
} else {
alert("Error: " + r.cause);
}
- $('#dialog-form').dialog("close");
+ $('#dialog-form').dialog('close');
});
}
@@ -139,10 +142,49 @@ function galleryRename(name) {
{
text: t('gallery', 'Cancel'),
click: function() {
- $( this ).dialog( "close" );
+ $( this ).dialog('close');
}
}
],
});
}
+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');
+ }
+ }
+ ],
+ });
+}
diff --git a/apps/gallery/js/albums.js b/apps/gallery/js/albums.js
index d2b4d858b55..01e146a2f12 100644
--- a/apps/gallery/js/albums.js
+++ b/apps/gallery/js/albums.js
@@ -52,7 +52,7 @@ Albums={
});
$(".gallery_album_decoration a.remove", local).bind('click', {name: a.name},function(event){
event.preventDefault();
- galleryRemove(a.data.name);
+ galleryRemove(event.data.name);
});
$("a.view", local).attr('href','?view='+a.name);
$('h1',local).text(a.name);
@@ -80,6 +80,10 @@ Albums={
$("a.view", element).attr("href", "?view="+new_name);
$("h1", element).text(new_name);
}
+ },
+ clear: function(element) {
+ Albums.albums = new Array();
+ element.innerHTML = '';
}
}
diff --git a/apps/gallery/lib/album.php b/apps/gallery/lib/album.php
index 4eb12cc0b81..502237481a9 100644
--- a/apps/gallery/lib/album.php
+++ b/apps/gallery/lib/album.php
@@ -31,6 +31,14 @@ class OC_Gallery_Album {
$stmt = OC_DB::prepare('UPDATE *PREFIX*gallery_albums SET album_name=? WHERE uid_owner=? AND album_name=?');
$stmt->execute(array($newname, $owner, $oldname));
}
+
+ public static function cleanup() {
+ $albums = self::find(OC_User::getUser());
+ while ($r = $albums->fetchRow()) {
+ OC_Gallery_Photo::removeByAlbumId($r['album_id']);
+ self::remove(OC_User::getUser(), $r['album_name']);
+ }
+ }
public static function remove($owner, $name=null) {
$sql = 'DELETE FROM *PREFIX*gallery_albums WHERE uid_owner = ?';
@@ -69,7 +77,8 @@ class OC_Gallery_Album {
$sql .= ' AND album_path = ?';
$args[] = $path;
}
- $sql .= ' ORDER BY album_name ASC';
+ $order = OC_Appconfig::getValue('gallery', 'order', 'ASC');
+ $sql .= ' ORDER BY album_name ' . $order;
$stmt = OC_DB::prepare($sql);
return $stmt->execute($args);
diff --git a/apps/gallery/templates/index.php b/apps/gallery/templates/index.php
index 4c2fbcfe6c6..4e74be4c64e 100644
--- a/apps/gallery/templates/index.php
+++ b/apps/gallery/templates/index.php
@@ -9,7 +9,10 @@ $l = new OC_L10N('gallery');
<div id="controls">
<div id="scan">
<div id="scanprogressbar"></div>
- <input type="button" value="<?php echo $l->t('Rescan');?>" onclick="javascript:scanForAlbums();" />
+ <input type="button" id="g-scan-button" value="<?php echo $l->t('Rescan');?>" onclick="javascript:scanForAlbums();" />
+ </div>
+ <div id="g-settings">
+ <input type="button" id="g-settings-button" value="<?php echo $l->t('Settings');?>" onclick="javascript:settings();"/>
</div>
</div>
<div id="gallery_list">
@@ -28,3 +31,26 @@ $l = new OC_L10N('gallery');
</form>
</div>
+<div id="g-dialog-settings" title="<?php echo $l->t('Settings');?>" style="display:none">
+ <form>
+ <fieldset><?php $root = OC_Appconfig::getValue('gallery', 'root', '/'); $order = OC_Appconfig::getValue('gallery', 'order', 'ASC');?>
+ <label for="name"><?php echo $l->t('Scanning root');?></label>
+ <input type="text" name="g-scanning-root" id="g-scanning-root" class="text ui-widget-content ui-corner-all" value="<?php echo $root;?>" /><br/>
+
+ <label for="sort"><?php echo $l->t('Default sorting'); ?></label>
+ <select id="g-display-order">
+ <option value="ASC"<?php echo $order=='ASC'?'selected':'';?>><?php echo $l->t('Ascending'); ?></option>
+ <option value="DESC"<?php echo $order=='DESC'?'selected':'';?>><?php echo $l->t('Descending'); ?></option>
+ </select><br/>
+<!--
+ <label for="sort"><?php echo $l->t('Thumbnails size'); ?></label>
+ <select>
+ <option value="100">100px</option>
+ <option value="150">150px</option>
+ <option value="200">200px</option>
+ </select>
+ -->
+ </fieldset>
+ </form>
+</div>
+