New sharing dialog

Choose if album should be listed public or not #177
This commit is contained in:
Tobias Reich 2014-07-21 22:16:30 +02:00
parent abc7c9233d
commit cf9ad486f0
6 changed files with 30 additions and 20 deletions

View File

@ -179,7 +179,8 @@
/* Radio Buttons ------------------------------------------------*/ /* Radio Buttons ------------------------------------------------*/
.message .choice { .message .choice {
float: left; float: left;
padding: 12px 5% 15px; margin: 12px 5%;
width: 90%;
color: #fff; color: #fff;
} }

View File

@ -285,15 +285,17 @@ album = {
setPublic: function(albumID, e) { setPublic: function(albumID, e) {
var params; var params,
password = "",
listed = false;
if (!visible.message()&&album.json.public==0) { if (!visible.message()&&album.json.public==0) {
modal.show("Share Album", "This album will be shared with one of the following properties:</p><form><div class='choice'><input type='radio' value='public' name='choice' checked><h2>Public</h2><p>Visible and accessible for everyone.</p></div><div class='choice'><input type='radio' value='password' name='choice'><h2>Password protected</h2><p>Not visible to visitors and only accessible with a valid password.<input class='text' type='password' placeholder='password' value='' style='display: none;'></p></div></form><p style='display: none;'>", [["Share Album", function() { album.setPublic(album.getID(), e) }], ["Cancel", function() {}]], -160); modal.show("Share Album", "This album will be shared with one of the following properties:</p><form><div class='choice'><input type='checkbox' name='listed' value='listed' checked><h2>Visible</h2><p>Listed to visitors of your Lychee.</p></div><div class='choice'><input type='checkbox' name='password' value='password'><h2>Password protected</h2><p>Only accessible with a valid password.<input class='text' type='password' placeholder='password' value='' style='display: none;'></p></div></form><p style='display: none;'>", [["Share Album", function() { album.setPublic(album.getID(), e) }], ["Cancel", function() {}]], -160);
$(".message .choice input:radio").on("change", function() { $(".message .choice input[name='password']").on("change", function() {
if ($(this).val()==="password") $(".message .choice input.text").show(); if ($(this).prop('checked')===true) $(".message .choice input.text").show();
else $(".message .choice input.text").hide(); else $(".message .choice input.text").hide();
}); });
@ -302,18 +304,22 @@ album = {
} }
if (visible.message()&&$(".message .choice input:checked").val()==="password") { if (visible.message()) {
params = "setAlbumPublic&albumID=" + albumID + "&password=" + md5($(".message input.text").val()); if ($(".message .choice input[name='password']:checked").val()==="password") {
album.json.password = true; password = md5($(".message input.text").val());
album.json.password = true;
} else {
password = "";
album.json.password = false;
}
} else { if ($(".message .choice input[name='listed']:checked").val()==="listed") listed = true;
params = "setAlbumPublic&albumID=" + albumID + "&password=";
album.json.password = false;
} }
params = "setAlbumPublic&albumID=" + albumID + "&password=" + password + "&visible=" + listed;
if (visible.album()) { if (visible.album()) {
album.json.public = (album.json.public==0) ? 1 : 0; album.json.public = (album.json.public==0) ? 1 : 0;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -110,9 +110,9 @@ class Admin extends Access {
private function setAlbumPublic() { private function setAlbumPublic() {
Module::dependencies(isset($_POST['albumID'], $_POST['password'])); Module::dependencies(isset($_POST['albumID'], $_POST['password'], $_POST['visible']));
$album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumID']); $album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumID']);
echo $album->setPublic($_POST['password']); echo $album->setPublic($_POST['password'], $_POST['visible']);
} }

View File

@ -441,7 +441,7 @@ class Album extends Module {
} }
public function setPublic($password) { public function setPublic($password, $visible) {
# Check dependencies # Check dependencies
self::dependencies(isset($this->database, $this->albumIDs)); self::dependencies(isset($this->database, $this->albumIDs));
@ -457,8 +457,11 @@ class Album extends Module {
# Invert public # Invert public
$public = ($album->public=='0' ? 1 : 0); $public = ($album->public=='0' ? 1 : 0);
# Convert visible
$visible = ($visible==='true' ? 1 : 0);
# Set public # Set public
$result = $this->database->query("UPDATE lychee_albums SET public = '$public', visible = 1, password = NULL WHERE id = '$album->id';"); $result = $this->database->query("UPDATE lychee_albums SET public = '$public', visible = '$visible', password = NULL WHERE id = '$album->id';");
if (!$result) { if (!$result) {
Log::error($this->database, __METHOD__, __LINE__, $this->database->error); Log::error($this->database, __METHOD__, __LINE__, $this->database->error);
return false; return false;
@ -499,12 +502,12 @@ class Album extends Module {
$password = get_hashed_password($password); $password = get_hashed_password($password);
# Set hashed password # Set hashed password
$result = $this->database->query("UPDATE lychee_albums SET visible = 0, password = '$password' WHERE id IN ('$this->albumIDs');"); $result = $this->database->query("UPDATE lychee_albums SET password = '$password' WHERE id IN ('$this->albumIDs');");
} else { } else {
# Unset password # Unset password
$result = $this->database->query("UPDATE lychee_albums SET visible = 1, password = NULL WHERE id IN ('$this->albumIDs');"); $result = $this->database->query("UPDATE lychee_albums SET password = NULL WHERE id IN ('$this->albumIDs');");
} }