2013-09-03 09:59:30 +00:00
/ * *
2014-01-22 10:12:51 +00:00
* @ name Album Module
* @ description Takes care of every action an album can handle and execute .
* @ author Tobias Reich
* @ copyright 2014 by Tobias Reich
2013-09-03 09:59:30 +00:00
* /
album = {
json : null ,
getID : function ( ) {
var id ;
if ( photo . json ) id = photo . json . album ;
else if ( album . json ) id = album . json . id ;
else id = $ ( ".album:hover, .album.active" ) . attr ( "data-id" ) ;
// Search
if ( ! id ) id = $ ( ".photo:hover, .photo.active" ) . attr ( "data-album-id" ) ;
if ( id ) return id ;
else return false ;
} ,
load : function ( albumID , refresh ) {
var startTime ,
params ,
durationTime ,
2014-01-22 10:12:51 +00:00
waitTime ;
2013-09-03 09:59:30 +00:00
password . get ( albumID , function ( ) {
if ( ! refresh ) {
loadingBar . show ( ) ;
lychee . animate ( ".album, .photo" , "contentZoomOut" ) ;
lychee . animate ( ".divider" , "fadeOut" ) ;
}
startTime = new Date ( ) . getTime ( ) ;
params = "getAlbum&albumID=" + albumID + "&password=" + password . value ;
2014-01-22 10:12:51 +00:00
lychee . api ( params , function ( data ) {
2013-09-03 09:59:30 +00:00
2014-01-22 10:12:51 +00:00
if ( data === "Warning: Album private!" ) {
2013-09-03 09:59:30 +00:00
lychee . setMode ( "view" ) ;
return false ;
}
2014-01-22 10:12:51 +00:00
if ( data === "Warning: Wrong password!" ) {
2013-09-03 09:59:30 +00:00
album . load ( albumID , refresh ) ;
return false ;
}
album . json = data ;
durationTime = ( new Date ( ) . getTime ( ) - startTime ) ;
if ( durationTime > 300 ) waitTime = 0 ; else if ( refresh ) waitTime = 0 ; else waitTime = 300 - durationTime ;
if ( ! visible . albums ( ) && ! visible . photo ( ) && ! visible . album ( ) ) waitTime = 0 ;
2013-09-08 17:50:31 +00:00
setTimeout ( function ( ) {
2014-01-22 10:12:51 +00:00
2013-09-03 09:59:30 +00:00
view . album . init ( ) ;
2014-01-22 10:12:51 +00:00
2013-09-03 09:59:30 +00:00
if ( ! refresh ) {
lychee . animate ( ".album, .photo" , "contentZoomIn" ) ;
view . header . mode ( "album" ) ;
}
2014-01-22 10:12:51 +00:00
2013-09-08 17:50:31 +00:00
} , waitTime ) ;
2013-09-03 09:59:30 +00:00
} ) ;
} ) ;
} ,
parse : function ( photo ) {
if ( photo && photo . thumbUrl ) photo . thumbUrl = lychee . upload _path _thumb + photo . thumbUrl ;
else if ( ! album . json . title ) album . json . title = "Untitled" ;
} ,
add : function ( ) {
2014-01-22 10:12:51 +00:00
var title ,
params ,
buttons ;
2013-09-03 09:59:30 +00:00
2014-01-22 10:12:51 +00:00
buttons = [
[ "Create Album" , function ( ) {
2013-09-03 09:59:30 +00:00
2014-01-22 10:12:51 +00:00
title = $ ( ".message input.text" ) . val ( ) ;
2013-09-03 09:59:30 +00:00
2014-01-22 10:12:51 +00:00
if ( title === "" ) title = "Untitled" ;
2013-09-03 09:59:30 +00:00
2014-01-22 10:12:51 +00:00
if ( title . length > 0 && title . length < 31 ) {
2013-09-03 09:59:30 +00:00
2014-01-22 10:12:51 +00:00
modal . close ( ) ;
2013-09-03 09:59:30 +00:00
2014-01-22 10:12:51 +00:00
params = "addAlbum&title=" + escape ( encodeURI ( title ) ) ;
lychee . api ( params , function ( data ) {
2014-01-27 22:58:51 +00:00
if ( data !== false ) {
if ( data === true ) data = 1 ; // Avoid first album to be true
lychee . goto ( data ) ;
} else lychee . error ( null , params , data ) ;
2014-01-22 10:12:51 +00:00
} ) ;
} else loadingBar . show ( "error" , "Title too short or too long. Please try again!" ) ;
} ] ,
[ "Cancel" , function ( ) { } ]
] ;
modal . show ( "New Album" , "Please enter a title for this album: <input class='text' type='text' placeholder='Title' value='Untitled'>" , buttons ) ;
2013-09-03 09:59:30 +00:00
} ,
delete : function ( albumID ) {
var params ,
buttons ,
albumTitle ;
buttons = [
[ "Delete Album and Photos" , function ( ) {
2014-01-24 12:49:01 +00:00
params = "deleteAlbum&albumID=" + albumID ;
2014-01-22 10:12:51 +00:00
lychee . api ( params , function ( data ) {
2013-09-03 09:59:30 +00:00
2014-01-22 10:12:51 +00:00
if ( visible . albums ( ) ) {
albums . json . num -- ;
view . albums . content . delete ( albumID ) ;
} else lychee . goto ( "" ) ;
2013-09-03 09:59:30 +00:00
2014-01-22 10:12:51 +00:00
if ( data !== true ) lychee . error ( null , params , data ) ;
2013-09-03 09:59:30 +00:00
} ) ;
} ] ,
[ "Keep Album" , function ( ) { } ]
] ;
2014-01-22 10:12:51 +00:00
if ( albumID === "0" ) {
2013-09-03 09:59:30 +00:00
buttons [ 0 ] [ 0 ] = "Clear Unsorted" ;
modal . show ( "Clear Unsorted" , "Are you sure you want to delete all photos from 'Unsorted'?<br>This action can't be undone!" , buttons )
} else {
if ( album . json ) albumTitle = album . json . title ;
else if ( albums . json ) albumTitle = albums . json . content [ albumID ] . title ;
modal . show ( "Delete Album" , "Are you sure you want to delete the album '" + albumTitle + "' and all of the photos it contains? This action can't be undone!" , buttons ) ;
}
} ,
setTitle : function ( albumID ) {
var oldTitle = "" ,
newTitle ,
2014-01-22 10:12:51 +00:00
params ,
buttons ;
2013-09-03 09:59:30 +00:00
2014-01-22 10:12:51 +00:00
if ( ! albumID ) return false ;
2013-09-03 09:59:30 +00:00
if ( album . json ) oldTitle = album . json . title ;
else if ( albums . json ) oldTitle = albums . json . content [ albumID ] . title ;
2014-01-22 10:12:51 +00:00
buttons = [
[ "Set Title" , function ( ) {
2013-09-03 09:59:30 +00:00
2014-01-22 10:12:51 +00:00
newTitle = $ ( ".message input.text" ) . val ( ) ;
2013-09-03 09:59:30 +00:00
2014-01-22 10:12:51 +00:00
if ( newTitle === "" ) newTitle = "Untitled" ;
2013-09-03 09:59:30 +00:00
2014-01-22 10:12:51 +00:00
if ( albumID !== "" && albumID != null && albumID && newTitle . length < 31 ) {
2013-09-03 09:59:30 +00:00
2014-01-22 10:12:51 +00:00
if ( visible . album ( ) ) {
2013-09-03 09:59:30 +00:00
2014-01-22 10:12:51 +00:00
album . json . title = newTitle ;
view . album . title ( oldTitle ) ;
2013-09-03 09:59:30 +00:00
2014-01-22 10:12:51 +00:00
} else if ( visible . albums ( ) ) {
2013-09-03 09:59:30 +00:00
2014-01-22 10:12:51 +00:00
albums . json . content [ albumID ] . title = newTitle ;
view . albums . content . title ( albumID ) ;
2013-09-03 09:59:30 +00:00
2014-01-22 10:12:51 +00:00
}
2013-09-03 09:59:30 +00:00
2014-01-22 10:12:51 +00:00
params = "setAlbumTitle&albumID=" + albumID + "&title=" + escape ( encodeURI ( newTitle ) ) ;
lychee . api ( params , function ( data ) {
if ( data !== true ) lychee . error ( null , params , data ) ;
} ) ;
} else if ( newTitle . length > 0 ) loadingBar . show ( "error" , "New title too short or too long. Please try again!" ) ;
} ] ,
[ "Cancel" , function ( ) { } ]
] ;
modal . show ( "Set Title" , "Please enter a new title for this album: <input class='text' type='text' placeholder='Title' value='" + oldTitle + "'>" , buttons ) ;
} ,
setDescription : function ( photoID ) {
var oldDescription = album . json . description ,
description ,
params ,
buttons ;
buttons = [
[ "Set Description" , function ( ) {
description = $ ( ".message input.text" ) . val ( ) ;
if ( description . length < 800 ) {
if ( visible . album ( ) ) {
album . json . description = description ;
view . album . description ( ) ;
}
params = "setAlbumDescription&albumID=" + photoID + "&description=" + escape ( description ) ;
lychee . api ( params , function ( data ) {
if ( data !== true ) lychee . error ( null , params , data ) ;
2013-09-03 09:59:30 +00:00
2014-01-22 10:12:51 +00:00
} ) ;
} else loadingBar . show ( "error" , "Description too long. Please try again!" ) ;
} ] ,
[ "Cancel" , function ( ) { } ]
] ;
modal . show ( "Set Description" , "Please enter a description for this album: <input class='text' type='text' placeholder='Description' value='" + oldDescription + "'>" , buttons ) ;
2013-09-03 09:59:30 +00:00
} ,
setPublic : function ( albumID , e ) {
var params ;
2014-01-22 10:12:51 +00:00
if ( $ ( ".message input.text" ) . length > 0 && $ ( ".message input.text" ) . val ( ) . length > 0 ) {
params = "setAlbumPublic&albumID=" + albumID + "&password=" + hex _md5 ( $ ( ".message input.text" ) . val ( ) ) ;
2013-09-08 17:50:31 +00:00
album . json . password = true ;
2014-01-22 10:12:51 +00:00
2013-09-08 17:50:31 +00:00
} else {
2014-01-22 10:12:51 +00:00
2013-09-08 17:50:31 +00:00
params = "setAlbumPublic&albumID=" + albumID ;
album . json . password = false ;
2014-01-22 10:12:51 +00:00
2013-09-08 17:50:31 +00:00
}
2013-09-03 09:59:30 +00:00
if ( visible . album ( ) ) {
album . json . public = ( album . json . public == 0 ) ? 1 : 0 ;
view . album . public ( ) ;
2014-01-22 10:12:51 +00:00
view . album . password ( ) ;
2013-09-03 09:59:30 +00:00
if ( album . json . public == 1 ) contextMenu . shareAlbum ( albumID , e ) ;
}
2014-01-22 10:12:51 +00:00
lychee . api ( params , function ( data ) {
if ( data !== true ) lychee . error ( null , params , data ) ;
2013-09-03 09:59:30 +00:00
} ) ;
} ,
share : function ( service ) {
var link = "" ,
url = location . href ;
switch ( service ) {
case 0 :
link = "https://twitter.com/share?url=" + encodeURI ( url ) ;
break ;
case 1 :
link = "http://www.facebook.com/sharer.php?u=" + encodeURI ( url ) + "&t=" + encodeURI ( album . json . title ) ;
break ;
case 2 :
link = "mailto:?subject=" + encodeURI ( album . json . title ) + "&body=" + encodeURI ( "Hi! Check this out: " + url ) ;
break ;
default :
link = "" ;
break ;
}
if ( link . length > 5 ) location . href = link ;
} ,
getArchive : function ( albumID ) {
var link ;
if ( location . href . indexOf ( "index.html" ) > 0 ) link = location . href . replace ( location . hash , "" ) . replace ( "index.html" , "php/api.php?function=getAlbumArchive&albumID=" + albumID ) ;
else link = location . href . replace ( location . hash , "" ) + "php/api.php?function=getAlbumArchive&albumID=" + albumID ;
2014-01-22 10:12:51 +00:00
if ( lychee . publicMode ) link += "&password=" + password . value ;
2013-09-03 09:59:30 +00:00
location . href = link ;
}
}