Webserver:

- Create/edit/delete playlists in the app
- Fixed projektconfiguration (some project builds were disabled)
- hide menue lines if the user has no right
This commit is contained in:
lukeIam committed 2013-12-13 18:01:43 +01:00
1 parent 959a11a4a2
commit 35657f8698
19 files changed
+572 -113

No files matched your search

+25 -11
View File
@@ -84,14 +84,14 @@ namespace ServerLib
private static GetAllSongsDelegate _GetAllSongs;
public static GetAllSongsDelegate GetAllSongs
{
get { return CServer._GetAllSongs; }
internal get { return CServer._GetAllSongs; }
set { CServer._GetAllSongs = value; }
}
private static GetCurrentSongIdDelegate _GetCurrentSongId;
public static GetCurrentSongIdDelegate GetCurrentSongId
{
get { return CServer._GetCurrentSongId; }
internal get { return CServer._GetCurrentSongId; }
set { CServer._GetCurrentSongId = value; }
}
@@ -103,7 +103,7 @@ namespace ServerLib
private static GetPlaylistsDelegate _GetPlaylists;
public static GetPlaylistsDelegate GetPlaylists
{
get { return _GetPlaylists; }
internal get { return _GetPlaylists; }
set { _GetPlaylists = value; }
}
@@ -111,45 +111,59 @@ namespace ServerLib
private static GetPlaylistDelegate _GetPlaylist;
public static GetPlaylistDelegate GetPlaylist
{
get { return _GetPlaylist; }
internal get { return _GetPlaylist; }
set { _GetPlaylist = value; }
}
private static AddSongToPlaylistDelegate _AddSongToPlaylist;
public static AddSongToPlaylistDelegate AddSongToPlaylist
{
get { return _AddSongToPlaylist; }
internal get { return _AddSongToPlaylist; }
set { _AddSongToPlaylist = value; }
}
private static RemoveSongFromPlaylistDelegate _RemoveSongFromPlaylist;
public static RemoveSongFromPlaylistDelegate RemoveSongFromPlaylist
{
get { return _RemoveSongFromPlaylist; }
internal get { return _RemoveSongFromPlaylist; }
set { _RemoveSongFromPlaylist = value; }
}
private static MoveSongInPlaylistDelegate _MoveSongInPlaylist;
public static MoveSongInPlaylistDelegate MoveSongInPlaylist
{
get { return _MoveSongInPlaylist; }
internal get { return _MoveSongInPlaylist; }
set { _MoveSongInPlaylist = value; }
}
private static PlaylistContainsSongDelegate _PlaylistContainsSong;
public static PlaylistContainsSongDelegate PlaylistContainsSong
{
get { return _PlaylistContainsSong; }
internal get { return _PlaylistContainsSong; }
set { _PlaylistContainsSong = value; }
}
private static GetPlaylistSongsDelegate _GetPlaylistSongs;
public static GetPlaylistSongsDelegate GetPlaylistSongs
{
get { return _GetPlaylistSongs; }
internal get { return _GetPlaylistSongs; }
set { _GetPlaylistSongs = value; }
}
private static RemovePlaylistDelegate _RemovePlaylist;
public static RemovePlaylistDelegate RemovePlaylist
{
internal get { return _RemovePlaylist; }
set { _RemovePlaylist = value; }
}
private static AddPlaylistDelegate _AddPlaylist;
public static AddPlaylistDelegate AddPlaylist
{
internal get { return _AddPlaylist; }
set { _AddPlaylist = value; }
}
#endregion
#region user management
@@ -188,9 +202,9 @@ namespace ServerLib
internal get { return CServer._GetUserIdFromUsername; }
set { CServer._GetUserIdFromUsername = value; }
}
#endregion
public CServer(int port, bool encrypted)
{
_Init(port, encrypted);
+25 -7
View File
@@ -301,7 +301,7 @@ namespace ServerLib
public void AddSongToPlaylist(int songId, int playlistId, bool allowDuplicates)
{
if (_CheckRight(EUserRights.AddSongToPlaylist) || _CheckRight(EUserRights.EditPlaylists))
if (_CheckRight(EUserRights.AddSongToPlaylist))
{
CServer.AddSongToPlaylist(songId, playlistId, allowDuplicates);
}
@@ -309,17 +309,17 @@ namespace ServerLib
public void RemoveSongFromPlaylist(int position, int playlistId, int songId)
{
if (_CheckRight(EUserRights.EditPlaylists))
if (_CheckRight(EUserRights.RemoveSongsFromPlaylists))
{
CServer.RemoveSongFromPlaylist(position, playlistId, songId);
}
}
public void MoveSongInPlaylist(int oldPosition, int newPosition, int playlistId, int songId)
public void MoveSongInPlaylist(int newPosition, int playlistId, int songId)
{
if (_CheckRight(EUserRights.EditPlaylists))
if (_CheckRight(EUserRights.ReorderPlaylists))
{
CServer.MoveSongInPlaylist(oldPosition, newPosition, playlistId, songId);
CServer.MoveSongInPlaylist(newPosition, playlistId, songId);
}
}
@@ -333,9 +333,21 @@ namespace ServerLib
return CServer.GetPlaylistSongs(playlistId);
}
public bool IsPlaylistEditable(int playlistId)
public void RemovePlaylist(int playlistId)
{
return _CheckRight(EUserRights.EditPlaylists);
if (_CheckRight(EUserRights.DeletePlaylists))
{
CServer.RemovePlaylist(playlistId);
}
}
public int AddPlaylist(string playlistName)
{
if (_CheckRight(EUserRights.CreatePlaylists))
{
return CServer.AddPlaylist(playlistName);
}
return -1;
}
#endregion
@@ -354,6 +366,11 @@ namespace ServerLib
CServer.SetUserRole(profileId, userRole);
}
}
public bool HasUserRight(int right)
{
return _CheckRight((EUserRights)right);
}
private static bool _CheckRight(EUserRights requestedRight)
{
@@ -382,5 +399,6 @@ namespace ServerLib
}
#endregion
}
}
+25 -15
View File
@@ -108,20 +108,7 @@ namespace ServerLib
public delegate SSongInfo[] GetAllSongsDelegate();
public delegate int GetCurrentSongIdDelegate();
public delegate SPlaylistInfo[] GetPlaylistsDelegate();
public delegate SPlaylistInfo GetPlaylistDelegate(int playlistId);
public delegate void AddSongToPlaylistDelegate(int songId, int playlistId, bool allowDuplicates);
public delegate void RemoveSongFromPlaylistDelegate(int position, int playlistId, int songId);
public delegate void MoveSongInPlaylistDelegate(int oldPosition, int newPosition, int playlistId, int songId);
public delegate bool PlaylistContainsSongDelegate(int songId, int playlistId);
public delegate SPlaylistSongInfo[] GetPlaylistSongsDelegate(int playlistId);
[DataContract]
public struct SSongInfo
@@ -144,6 +131,28 @@ namespace ServerLib
public int SongId { get; set; }
}
#endregion
#region playlists
public delegate SPlaylistInfo[] GetPlaylistsDelegate();
public delegate SPlaylistInfo GetPlaylistDelegate(int playlistId);
public delegate void AddSongToPlaylistDelegate(int songId, int playlistId, bool allowDuplicates);
public delegate void RemoveSongFromPlaylistDelegate(int position, int playlistId, int songId);
public delegate void MoveSongInPlaylistDelegate(int newPosition, int playlistId, int songId);
public delegate bool PlaylistContainsSongDelegate(int songId, int playlistId);
public delegate SPlaylistSongInfo[] GetPlaylistSongsDelegate(int playlistId);
public delegate void RemovePlaylistDelegate(int playlistId);
public delegate int AddPlaylistDelegate(string playlistName);
[DataContract]
public struct SPlaylistSongInfo
{
[DataMember]
@@ -155,7 +164,8 @@ namespace ServerLib
[DataMember]
public int GameMode;
}
[DataContract]
public struct SPlaylistInfo
{
[DataMember]
@@ -150,8 +150,8 @@ namespace ServerLib
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/moveSongInPlaylist?oldPosition={oldPosition}&newPosition={newPosition}&playlistId={playlistId}&songId={songId}")]
void MoveSongInPlaylist(int oldPosition, int newPosition, int playlistId, int songId);
UriTemplate = "/moveSongInPlaylist?newPosition={newPosition}&playlistId={playlistId}&songId={songId}")]
void MoveSongInPlaylist(int newPosition, int playlistId, int songId);
[OperationContract]
[WebInvoke(Method = "GET",
@@ -166,9 +166,14 @@ namespace ServerLib
SPlaylistSongInfo[] GetPlaylistSongs(int playlistId);
[OperationContract, WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/isPlaylistEditable?playlistId={playlistId}")]
bool IsPlaylistEditable(int playlistId);
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/removePlaylist?playlistId={playlistId}")]
void RemovePlaylist(int playlistId);
[OperationContract, WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/addPlaylist?playlistName={playlistName}")]
int AddPlaylist(string playlistName);
#endregion
@@ -186,6 +191,12 @@ namespace ServerLib
UriTemplate = "/setUserRole?profileId={profileId}&userRole={userRole}")]
void SetUserRole(int profileId, int userRole);
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/hasUserRight?right={right}")]
bool HasUserRight(int right);
#endregion
}
}
@@ -10,7 +10,10 @@ namespace ServerLib
UploadPhotos = 0x02,
ViewOtherProfiles = 0x04,
UseKeyboard = 0x08,
EditPlaylists = 0x16,
AddSongToPlaylist = 0x32
ReorderPlaylists = 0x16,
AddSongToPlaylist = 0x32,
CreatePlaylists = 0x64,
DeletePlaylists = 0x128,
RemoveSongsFromPlaylists = 0x256
}
}
@@ -9,8 +9,13 @@ namespace ServerLib
{EUserRoles.Administrator,
(EUserRights.EditAllProfiles|
EUserRights.UploadPhotos|
EUserRights.ViewOtherProfiles)|
EUserRights.UseKeyboard},
EUserRights.ViewOtherProfiles|
EUserRights.UseKeyboard|
EUserRights.AddSongToPlaylist|
EUserRights.ReorderPlaylists|
EUserRights.CreatePlaylists|
EUserRights.DeletePlaylists|
EUserRights.RemoveSongsFromPlaylists)},
{EUserRoles.AuthenticatedUser,
(EUserRights.UploadPhotos|
EUserRights.ViewOtherProfiles|
+6
View File
@@ -189,24 +189,28 @@ Global
{EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.DebugLinux|Mixed Platforms.ActiveCfg = Debug|Any CPU
{EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.DebugLinux|Mixed Platforms.Build.0 = Debug|Any CPU
{EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.DebugLinux|x64.ActiveCfg = Debug|Any CPU
{EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.DebugLinux|x64.Build.0 = Debug|Any CPU
{EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.DebugLinux|x86.ActiveCfg = Debug|Any CPU
{EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.DebugWin|Any CPU.ActiveCfg = Debug|Any CPU
{EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.DebugWin|Any CPU.Build.0 = Debug|Any CPU
{EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.DebugWin|Mixed Platforms.ActiveCfg = Debug|Any CPU
{EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.DebugWin|Mixed Platforms.Build.0 = Debug|Any CPU
{EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.DebugWin|x64.ActiveCfg = Debug|Any CPU
{EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.DebugWin|x64.Build.0 = Debug|Any CPU
{EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.DebugWin|x86.ActiveCfg = Debug|Any CPU
{EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.ReleaseLinux|Any CPU.ActiveCfg = Release|Any CPU
{EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.ReleaseLinux|Any CPU.Build.0 = Release|Any CPU
{EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.ReleaseLinux|Mixed Platforms.ActiveCfg = Release|Any CPU
{EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.ReleaseLinux|Mixed Platforms.Build.0 = Release|Any CPU
{EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.ReleaseLinux|x64.ActiveCfg = Release|Any CPU
{EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.ReleaseLinux|x64.Build.0 = Release|Any CPU
{EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.ReleaseLinux|x86.ActiveCfg = Release|Any CPU
{EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.ReleaseWin|Any CPU.ActiveCfg = Release|Any CPU
{EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.ReleaseWin|Any CPU.Build.0 = Release|Any CPU
{EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.ReleaseWin|Mixed Platforms.ActiveCfg = Release|Any CPU
{EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.ReleaseWin|Mixed Platforms.Build.0 = Release|Any CPU
{EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.ReleaseWin|x64.ActiveCfg = Release|Any CPU
{EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.ReleaseWin|x64.Build.0 = Release|Any CPU
{EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.ReleaseWin|x86.ActiveCfg = Release|Any CPU
{55F89808-4E79-4FFE-BC13-48258913F5C9}.DebugLinux|Any CPU.ActiveCfg = Debug|Any CPU
{55F89808-4E79-4FFE-BC13-48258913F5C9}.DebugLinux|Any CPU.Build.0 = Debug|Any CPU
@@ -218,6 +222,7 @@ Global
{55F89808-4E79-4FFE-BC13-48258913F5C9}.DebugWin|Mixed Platforms.ActiveCfg = Debug|Any CPU
{55F89808-4E79-4FFE-BC13-48258913F5C9}.DebugWin|Mixed Platforms.Build.0 = Debug|Any CPU
{55F89808-4E79-4FFE-BC13-48258913F5C9}.DebugWin|x64.ActiveCfg = Debug|Any CPU
{55F89808-4E79-4FFE-BC13-48258913F5C9}.DebugWin|x64.Build.0 = Debug|Any CPU
{55F89808-4E79-4FFE-BC13-48258913F5C9}.DebugWin|x86.ActiveCfg = Debug|Any CPU
{55F89808-4E79-4FFE-BC13-48258913F5C9}.ReleaseLinux|Any CPU.ActiveCfg = Release|Any CPU
{55F89808-4E79-4FFE-BC13-48258913F5C9}.ReleaseLinux|Any CPU.Build.0 = Release|Any CPU
@@ -229,6 +234,7 @@ Global
{55F89808-4E79-4FFE-BC13-48258913F5C9}.ReleaseWin|Mixed Platforms.ActiveCfg = Release|Any CPU
{55F89808-4E79-4FFE-BC13-48258913F5C9}.ReleaseWin|Mixed Platforms.Build.0 = Release|Any CPU
{55F89808-4E79-4FFE-BC13-48258913F5C9}.ReleaseWin|x64.ActiveCfg = Release|Any CPU
{55F89808-4E79-4FFE-BC13-48258913F5C9}.ReleaseWin|x64.Build.0 = Release|Any CPU
{55F89808-4E79-4FFE-BC13-48258913F5C9}.ReleaseWin|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
+4 -4
View File
@@ -124,7 +124,7 @@ namespace Vocaluxe.Base
public static EOffOn ServerActive = EOffOn.TR_CONFIG_OFF;
public static EOffOn ServerEncryption = EOffOn.TR_CONFIG_OFF;
public static int ServerPort = 3000;
public static string ServerPassword = "vocaluxe";
//public static string ServerPassword = "vocaluxe";
//Lists to save parameters and values
private static readonly List<string> _Params = new List<string>();
@@ -299,7 +299,7 @@ namespace Vocaluxe.Base
if (ServerPort < 1 || ServerPort > 65535)
ServerPort = 3000;
xmlReader.GetValue("//root/Server/ServerPassword", out ServerPassword, ServerPassword);
//xmlReader.GetValue("//root/Server/ServerPassword", out ServerPassword, ServerPassword);
#endregion Server
}
@@ -573,8 +573,8 @@ namespace Vocaluxe.Base
writer.WriteComment("Server Port (default: 3000) [1..65535]");
writer.WriteElementString("ServerPort", ServerPort.ToString());
writer.WriteComment("Server Password (default: vocaluxe)");
writer.WriteElementString("ServerPassword", ServerPassword);
//writer.WriteComment("Server Password (default: vocaluxe)");
//writer.WriteElementString("ServerPassword", ServerPassword);
writer.WriteEndElement();
#endregion Server
+14 -14
View File
@@ -1,18 +1,18 @@
#region license
// This file is part of Vocaluxe.
#region license
// This file is part of Vocaluxe.
//
// Vocaluxe is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Vocaluxe is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Vocaluxe is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Vocaluxe is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
// You should have received a copy of the GNU General Public License
// along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
#endregion
using System;
@@ -77,7 +77,7 @@ namespace Vocaluxe.Base
foreach (string file in files)
{
var playlist = new CPlaylistFile(file);
CPlaylistFile playlist = new CPlaylistFile(file, files.IndexOf(file));
_Playlists.Add(playlist);
}
}
@@ -125,7 +125,7 @@ namespace Vocaluxe.Base
public static int NewPlaylist()
{
var pl = new CPlaylistFile {PlaylistName = "New Playlist"};
CPlaylistFile pl = new CPlaylistFile { PlaylistName = "New Playlist", Id = _Playlists.Count };
_Playlists.Add(pl);
return _Playlists.Count - 1;
}
+54 -26
View File
@@ -47,7 +47,6 @@ namespace Vocaluxe.Base.Server
_Clients = new Dictionary<int, CClientHandler>();
_Server = new CServer(CConfig.ServerPort, CConfig.ServerEncryption == EOffOn.TR_CONFIG_ON);
//TODO: remove CConfig.ServerPassword
CServer.SendKeyEvent = _SendKeyEvent;
CServer.GetProfileData = _GetProfileData;
@@ -64,6 +63,15 @@ namespace Vocaluxe.Base.Server
CServer.SetUserRole = _SetUserRole;
CServer.GetUserIdFromUsername = _GetUserIdFromUsername;
CServer.GetDelayedImage = _GetDelayedImage;
CServer.GetPlaylists = _GetPlaylists;
CServer.GetPlaylist = _GetPlaylist;
CServer.AddSongToPlaylist = _AddSongToPlaylist;
CServer.RemoveSongFromPlaylist = _RemoveSongFromPlaylist;
CServer.MoveSongInPlaylist = _MoveSongInPlaylist;
CServer.PlaylistContainsSong = _PlaylistContainsSong;
CServer.GetPlaylistSongs = _GetPlaylistSongs;
CServer.RemovePlaylist = _RemovePlaylist;
CServer.AddPlaylist = _AddPlaylist;
_Discover = new CDiscover(CConfig.ServerPort, CCommands.BroadcastKeyword);
Controller.Init();
@@ -432,31 +440,32 @@ namespace Vocaluxe.Base.Server
#region playlist
public static SPlaylistInfo[] GetPlaylists()
private static SPlaylistInfo[] _GetPlaylists()
{
return (from p in CPlaylists.Playlists
select _GetPlaylistInfo(p)).ToArray();
}
public static SPlaylistInfo GetPlaylist(int playlistId)
private static SPlaylistInfo _GetPlaylist(int playlistId)
{
if (CPlaylists.Playlists.Length <= playlistId)
if (CPlaylists.Playlists.Length <= playlistId || playlistId < 0)
{
throw new ArgumentException("invalid playlistId");
}
return _GetPlaylistInfo(CPlaylists.Playlists[playlistId]);
}
public static void AddSongToPlaylist(int songId, int playlistId, bool allowDuplicates)
private static void _AddSongToPlaylist(int songId, int playlistId, bool allowDuplicates)
{
if (CPlaylists.Playlists.Length <= playlistId)
if (CPlaylists.Playlists.Length <= playlistId || playlistId < 0)
{
throw new ArgumentException("invalid playlistId");
}
if (allowDuplicates || PlaylistContainsSong(songId, playlistId))
if (allowDuplicates || !_PlaylistContainsSong(songId, playlistId))
{
CPlaylists.AddPlaylistSong(playlistId, songId);
CPlaylists.SavePlaylist(playlistId);
}
else
{
@@ -464,57 +473,58 @@ namespace Vocaluxe.Base.Server
}
}
public static void RemoveSongFromPlaylist(int position, int playlistId, int songId)
private static void _RemoveSongFromPlaylist(int position, int playlistId, int songId)
{
if (CPlaylists.Playlists.Length <= playlistId)
if (CPlaylists.Playlists.Length <= playlistId || playlistId < 0)
{
throw new ArgumentException("invalid playlistId");
}
if (!PlaylistContainsSong(songId, playlistId))
if (!_PlaylistContainsSong(songId, playlistId))
{
throw new ArgumentException("invalid songId");
}
if (CPlaylists.Playlists[playlistId].Songs.Count <= position || CPlaylists.Playlists[playlistId].Songs[position].SongID != songId)
if (position < 0 || CPlaylists.Playlists[playlistId].Songs.Count <= position
|| CPlaylists.Playlists[playlistId].Songs[position].SongID != songId)
{
throw new ArgumentException("invalid position");
}
CPlaylists.Playlists[playlistId].DeleteSong(position);
CPlaylists.SavePlaylist(playlistId);
}
public static void MoveSongInPlaylist(int oldPosition, int newPosition, int playlistId, int songId)
private static void _MoveSongInPlaylist(int newPosition, int playlistId, int songId)
{
if (CPlaylists.Playlists.Length <= playlistId)
if (CPlaylists.Playlists.Length <= playlistId || playlistId < 0)
{
throw new ArgumentException("invalid playlistId");
}
if (!PlaylistContainsSong(songId, playlistId))
if (!_PlaylistContainsSong(songId, playlistId))
{
throw new ArgumentException("invalid songId");
}
if (CPlaylists.Playlists[playlistId].Songs.Count <= oldPosition || CPlaylists.Playlists[playlistId].Songs[oldPosition].SongID != songId)
{
throw new ArgumentException("invalid oldPosition");
}
if (CPlaylists.Playlists[playlistId].Songs.Count < newPosition )
if (CPlaylists.Playlists[playlistId].Songs.Count < newPosition)
{
throw new ArgumentException("invalid newPosition");
}
CPlaylists.MovePlaylistSong(playlistId,oldPosition, newPosition);
int oldPosition = CPlaylists.Playlists[playlistId].Songs.FindIndex(s => s.SongID == songId);
CPlaylists.MovePlaylistSong(playlistId, oldPosition, newPosition);
CPlaylists.SavePlaylist(playlistId);
}
public static bool PlaylistContainsSong(int songId, int playlistId)
private static bool _PlaylistContainsSong(int songId, int playlistId)
{
if (CPlaylists.Playlists.Length <= playlistId)
if (CPlaylists.Playlists.Length <= playlistId || playlistId < 0)
{
throw new ArgumentException("invalid playlistId");
}
return CPlaylists.Playlists[playlistId].Songs.Any(s => s.SongID == songId);
}
public static SPlaylistSongInfo[] GetPlaylistSongs(int playlistId)
private static SPlaylistSongInfo[] _GetPlaylistSongs(int playlistId)
{
if (CPlaylists.Playlists.Length <= playlistId)
if (CPlaylists.Playlists.Length <= playlistId || playlistId < 0)
{
throw new ArgumentException("invalid playlistId");
}
@@ -540,7 +550,7 @@ namespace Vocaluxe.Base.Server
SPlaylistSongInfo[] result = new SPlaylistSongInfo[playlist.Songs.Count];
for (int i = 0; i < playlist.Songs.Count; i++)
{
result[i] = _GetPlaylistSongInfo(playlist.Songs[i], 1 /*TODO:PlaylistID???*/, i);
result[i] = _GetPlaylistSongInfo(playlist.Songs[i], playlist.Id, i);
}
return result;
}
@@ -549,13 +559,31 @@ namespace Vocaluxe.Base.Server
{
return new SPlaylistInfo
{
PlaylistId = 1, /*TODO: PlaylistId*/
PlaylistId = playlist.Id,
PlaylistName = playlist.PlaylistName,
SongCount = playlist.Songs.Count,
LastChanged = DateTime.Now.ToLongDateString()
};
}
private static void _RemovePlaylist(int playlistId)
{
if (CPlaylists.Playlists.Length <= playlistId || playlistId < 0)
{
throw new ArgumentException("invalid playlistId");
}
CPlaylists.DeletePlaylist(playlistId);
}
private static int _AddPlaylist(string playlistName)
{
int newPlaylistId = CPlaylists.NewPlaylist();
CPlaylists.Playlists[newPlaylistId].PlaylistName = playlistName;
CPlaylists.SavePlaylist(newPlaylistId);
return newPlaylistId;
}
#endregion
#region user management
+16 -14
View File
@@ -1,18 +1,18 @@
#region license
// This file is part of Vocaluxe.
#region license
// This file is part of Vocaluxe.
//
// Vocaluxe is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Vocaluxe is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Vocaluxe is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Vocaluxe is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
// You should have received a copy of the GNU General Public License
// along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
#endregion
using System;
@@ -31,6 +31,7 @@ namespace Vocaluxe.Lib.Playlist
{
public string PlaylistName;
public string PlaylistFile;
public int Id = -1;
public List<CPlaylistSong> Songs = new List<CPlaylistSong>();
public CPlaylistFile()
@@ -39,8 +40,9 @@ namespace Vocaluxe.Lib.Playlist
PlaylistFile = string.Empty;
}
public CPlaylistFile(string file)
public CPlaylistFile(string file, int id)
{
Id = id;
PlaylistFile = file;
_LoadPlaylist();
}
@@ -217,7 +219,7 @@ namespace Vocaluxe.Lib.Playlist
if (destNr < 0 || destNr > Songs.Count - 1)
return;
var ps = new CPlaylistSong(songID, gm);
CPlaylistSong ps = new CPlaylistSong(songID, gm);
Songs.Insert(destNr, ps);
}
}
+12
View File
@@ -343,6 +343,9 @@
<CustomToolNamespace>css</CustomToolNamespace>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Website\img\addPlaylist.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Website\img\logout.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
@@ -355,6 +358,9 @@
<Content Include="Website\img\playlist.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Website\img\playlists.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Website\img\spotify.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
@@ -391,10 +397,16 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CustomToolNamespace>js</CustomToolNamespace>
</Content>
<Content Include="Website\js\jquery-ui-1.10.3.custom.min.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Website\js\jquery.mobile-1.3.2.min.js">
<CustomToolNamespace>js</CustomToolNamespace>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Website\js\jquery.ui.touch-punch.min.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Website\js\main.js">
<CustomToolNamespace>js</CustomToolNamespace>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+9 -4
View File
@@ -50,10 +50,10 @@
text-align: center;
}
#displaySongContent span {
font-size: 18px;
font-weight: bold;
}
#displaySongContent span {
font-size: 18px;
font-weight: bold;
}
.imageLoaderImg {
height: 100%;
@@ -80,3 +80,8 @@
-webkit-border-radius: 0px !important;
border-radius: 0px !important;
}
.cursorStyleClickable {
cursor: pointer;
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

+47 -7
View File
@@ -7,6 +7,8 @@
<link rel="stylesheet" href="css/style.css" />
<script src="js/jquery-1.9.1.min.js"></script>
<script src="js/jquery.mobile-1.3.2.min.js"></script>
<script src="js/jquery-ui-1.10.3.custom.min.js"></script>
<script src="js/jquery.ui.touch-punch.min.js"></script>
<script src="js/main.js"></script>
</head>
<body>
@@ -58,11 +60,18 @@
<a href="#selectSong" data-transition="slidefade">
<img src="img/playlist.png">
<h2>All songs</h2>
<p>List all available songs</p>
<p>Lists all available songs</p>
</a>
</li>
<li>
<a href="#selectProfile" data-transition="slidefade">
<a href="#selectPlaylist" data-transition="slidefade">
<img src="img/playlists.png">
<h2>All playlists</h2>
<p>Lists all playlists</p>
</a>
</li>
<li>
<a id="mainPageSelectProfile" href="#selectProfile" data-transition="slidefade">
<img src="img/profiles.png">
<h2>Profiles</h2>
<p>Shows all profiles</p>
@@ -76,7 +85,7 @@
</a>
</li>
<li>
<a href="#keyboard" data-transition="slidefade">
<a id="mainPageKeyboard" href="#keyboard" data-transition="slidefade">
<img src="img/keyboard.png">
<h2>Keyboard</h2>
<p>Send keys</p>
@@ -176,15 +185,18 @@
<br />
<br />
<div id="displaySongLinks">
<img id="displaySongLinkYoutube" src="img/youtube.png" />
<img id="displaySongLinkSpotify" src="img/spotify.png" />
<img id="displaySongLinkWikipedia" src="img/wikipedia.png" />
<img class="cursorStyleClickable" id="displaySongAddPlaylist" src="img/addPlaylist.png" />
<br />
<br />
<img class="cursorStyleClickable" id="displaySongLinkYoutube" src="img/youtube.png" />
<img class="cursorStyleClickable" id="displaySongLinkSpotify" src="img/spotify.png" />
<img class="cursorStyleClickable" id="displaySongLinkWikipedia" src="img/wikipedia.png" />
</div>
</div>
<!-- /content -->
<div data-role="popup" id="popupVideo" data-overlay-theme="a" data-theme="a" data-corners="false" data-tolerance="15,15">
<a href="#" data-role="button" data-theme="a" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Close</a>
<a href="#" data-role="button" data-theme="a" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Close</a>
<iframe width="480" height="320" seamless></iframe>
</div>
<!-- /popup -->
@@ -284,6 +296,34 @@
</div>
<!-- /page -->
<div id="selectPlaylist" data-content-theme="a" data-role="page" data-add-back-btn="true">
<div data-role="header">
<h1>Select a playlist</h1>
<a id="selectPlaylistAddPlaylistButton" href="#" class="ui-btn-right" data-icon="add">Add</a>
</div>
<!-- /header -->
<div id="selectPlaylistContent" data-role="content">
<ul data-split-theme="a" id="selectPlaylistContentList" data-role="listview" data-filter="true"></ul>
</div>
<!-- /content -->
</div>
<!-- /page -->
<div id="displayPlaylist" data-content-theme="a" data-role="page" data-add-back-btn="true">
<div id="displayPlaylistHeader" data-role="header">
<h1>Playlist</h1>
<a id="displayPlaylistSaveButton" class="ui-btn-right" href="#" data-icon="add">Save</a>
</div>
<!-- /header -->
<div id="displayPlaylistContent" data-role="content">
<ol data-split-theme="a" id="displayPlaylistContentList" data-role="listview" data-filter="true"></ol>
</div>
<!-- /content -->
</div>
<!-- /page -->
<div class="ui-loader-background"></div>
</body>
</html>
+6
View File
@@ -0,0 +1,6 @@
/*! jQuery UI - v1.10.3 - 2013-11-03
* http://jqueryui.com
* Includes: jquery.ui.core.js, jquery.ui.widget.js, jquery.ui.mouse.js, jquery.ui.sortable.js
* Copyright 2013 jQuery Foundation and other contributors; Licensed MIT */
(function(e,t){function i(t,i){var s,n,r,o=t.nodeName.toLowerCase();return"area"===o?(s=t.parentNode,n=s.name,t.href&&n&&"map"===s.nodeName.toLowerCase()?(r=e("img[usemap=#"+n+"]")[0],!!r&&a(r)):!1):(/input|select|textarea|button|object/.test(o)?!t.disabled:"a"===o?t.href||i:i)&&a(t)}function a(t){return e.expr.filters.visible(t)&&!e(t).parents().addBack().filter(function(){return"hidden"===e.css(this,"visibility")}).length}var s=0,n=/^ui-id-\d+$/;e.ui=e.ui||{},e.extend(e.ui,{version:"1.10.3",keyCode:{BACKSPACE:8,COMMA:188,DELETE:46,DOWN:40,END:35,ENTER:13,ESCAPE:27,HOME:36,LEFT:37,NUMPAD_ADD:107,NUMPAD_DECIMAL:110,NUMPAD_DIVIDE:111,NUMPAD_ENTER:108,NUMPAD_MULTIPLY:106,NUMPAD_SUBTRACT:109,PAGE_DOWN:34,PAGE_UP:33,PERIOD:190,RIGHT:39,SPACE:32,TAB:9,UP:38}}),e.fn.extend({focus:function(t){return function(i,a){return"number"==typeof i?this.each(function(){var t=this;setTimeout(function(){e(t).focus(),a&&a.call(t)},i)}):t.apply(this,arguments)}}(e.fn.focus),scrollParent:function(){var t;return t=e.ui.ie&&/(static|relative)/.test(this.css("position"))||/absolute/.test(this.css("position"))?this.parents().filter(function(){return/(relative|absolute|fixed)/.test(e.css(this,"position"))&&/(auto|scroll)/.test(e.css(this,"overflow")+e.css(this,"overflow-y")+e.css(this,"overflow-x"))}).eq(0):this.parents().filter(function(){return/(auto|scroll)/.test(e.css(this,"overflow")+e.css(this,"overflow-y")+e.css(this,"overflow-x"))}).eq(0),/fixed/.test(this.css("position"))||!t.length?e(document):t},zIndex:function(i){if(i!==t)return this.css("zIndex",i);if(this.length)for(var a,s,n=e(this[0]);n.length&&n[0]!==document;){if(a=n.css("position"),("absolute"===a||"relative"===a||"fixed"===a)&&(s=parseInt(n.css("zIndex"),10),!isNaN(s)&&0!==s))return s;n=n.parent()}return 0},uniqueId:function(){return this.each(function(){this.id||(this.id="ui-id-"+ ++s)})},removeUniqueId:function(){return this.each(function(){n.test(this.id)&&e(this).removeAttr("id")})}}),e.extend(e.expr[":"],{data:e.expr.createPseudo?e.expr.createPseudo(function(t){return function(i){return!!e.data(i,t)}}):function(t,i,a){return!!e.data(t,a[3])},focusable:function(t){return i(t,!isNaN(e.attr(t,"tabindex")))},tabbable:function(t){var a=e.attr(t,"tabindex"),s=isNaN(a);return(s||a>=0)&&i(t,!s)}}),e("<a>").outerWidth(1).jquery||e.each(["Width","Height"],function(i,a){function s(t,i,a,s){return e.each(n,function(){i-=parseFloat(e.css(t,"padding"+this))||0,a&&(i-=parseFloat(e.css(t,"border"+this+"Width"))||0),s&&(i-=parseFloat(e.css(t,"margin"+this))||0)}),i}var n="Width"===a?["Left","Right"]:["Top","Bottom"],r=a.toLowerCase(),o={innerWidth:e.fn.innerWidth,innerHeight:e.fn.innerHeight,outerWidth:e.fn.outerWidth,outerHeight:e.fn.outerHeight};e.fn["inner"+a]=function(i){return i===t?o["inner"+a].call(this):this.each(function(){e(this).css(r,s(this,i)+"px")})},e.fn["outer"+a]=function(t,i){return"number"!=typeof t?o["outer"+a].call(this,t):this.each(function(){e(this).css(r,s(this,t,!0,i)+"px")})}}),e.fn.addBack||(e.fn.addBack=function(e){return this.add(null==e?this.prevObject:this.prevObject.filter(e))}),e("<a>").data("a-b","a").removeData("a-b").data("a-b")&&(e.fn.removeData=function(t){return function(i){return arguments.length?t.call(this,e.camelCase(i)):t.call(this)}}(e.fn.removeData)),e.ui.ie=!!/msie [\w.]+/.exec(navigator.userAgent.toLowerCase()),e.support.selectstart="onselectstart"in document.createElement("div"),e.fn.extend({disableSelection:function(){return this.bind((e.support.selectstart?"selectstart":"mousedown")+".ui-disableSelection",function(e){e.preventDefault()})},enableSelection:function(){return this.unbind(".ui-disableSelection")}}),e.extend(e.ui,{plugin:{add:function(t,i,a){var s,n=e.ui[t].prototype;for(s in a)n.plugins[s]=n.plugins[s]||[],n.plugins[s].push([i,a[s]])},call:function(e,t,i){var a,s=e.plugins[t];if(s&&e.element[0].parentNode&&11!==e.element[0].parentNode.nodeType)for(a=0;s.length>a;a++)e.options[s[a][0]]&&s[a][1].apply(e.element,i)}},hasScroll:function(t,i){if("hidden"===e(t).css("overflow"))return!1;var a=i&&"left"===i?"scrollLeft":"scrollTop",s=!1;return t[a]>0?!0:(t[a]=1,s=t[a]>0,t[a]=0,s)}})})(jQuery);(function(e,t){var i=0,s=Array.prototype.slice,a=e.cleanData;e.cleanData=function(t){for(var i,s=0;null!=(i=t[s]);s++)try{e(i).triggerHandler("remove")}catch(n){}a(t)},e.widget=function(i,s,a){var n,r,o,h,l={},u=i.split(".")[0];i=i.split(".")[1],n=u+"-"+i,a||(a=s,s=e.Widget),e.expr[":"][n.toLowerCase()]=function(t){return!!e.data(t,n)},e[u]=e[u]||{},r=e[u][i],o=e[u][i]=function(e,i){return this._createWidget?(arguments.length&&this._createWidget(e,i),t):new o(e,i)},e.extend(o,r,{version:a.version,_proto:e.extend({},a),_childConstructors:[]}),h=new s,h.options=e.widget.extend({},h.options),e.each(a,function(i,a){return e.isFunction(a)?(l[i]=function(){var e=function(){return s.prototype[i].apply(this,arguments)},t=function(e){return s.prototype[i].apply(this,e)};return function(){var i,s=this._super,n=this._superApply;return this._suLine truncated
+11
View File
@@ -0,0 +1,11 @@
/*
* jQuery UI Touch Punch 0.2.2
*
* Copyright 2011, Dave Furfero
* Dual licensed under the MIT or GPL Version 2 licenses.
*
* Depends:
* jquery.ui.widget.js
* jquery.ui.mouse.js
*/
(function(b){b.support.touch="ontouchend" in document;if(!b.support.touch){return;}var c=b.ui.mouse.prototype,e=c._mouseInit,a;function d(g,h){if(g.originalEvent.touches.length>1){return;}g.preventDefault();var i=g.originalEvent.changedTouches[0],f=document.createEvent("MouseEvents");f.initMouseEvent(h,true,true,window,1,i.screenX,i.screenY,i.clientX,i.clientY,false,false,false,false,0,null);g.target.dispatchEvent(f);}c._touchStart=function(g){var f=this;if(a||!f._mouseCapture(g.originalEvent.changedTouches[0])){return;}a=true;f._touchMoved=false;d(g,"mouseover");d(g,"mousemove");d(g,"mousedown");};c._touchMove=function(f){if(!a){return;}this._touchMoved=true;d(f,"mousemove");};c._touchEnd=function(f){if(!a){return;}d(f,"mouseup");d(f,"mouseout");if(!this._touchMoved){d(f,"click");}a=false;};c._mouseInit=function(){var f=this;f.element.bind("touchstart",b.proxy(f,"_touchStart")).bind("touchmove",b.proxy(f,"_touchMove")).bind("touchend",b.proxy(f,"_touchEnd"));e.call(f);};})(jQuery);
+290 -2
View File
@@ -2,6 +2,9 @@ var ownProfileId = -1;
var profileIdRequest = -1;
var songIdRequest = -1;
var allSongsCache = null;
var playlistIdRequest = -1;
var playlistRequestName = "";
var customSelectPlaylistSongCallback = null;
var sessionId = "";
$(document).ready(function () {
@@ -197,6 +200,8 @@ function initPageLoadHandler() {
url: "getSong?songId=" + songIdRequest,
headers: { "session": sessionId }
}).done(function (result) {
$('#displaySongAddPlaylist').hide();
if (result.Title != null) {
$('#displaySongTitle').text(result.Title);
}
@@ -239,6 +244,14 @@ function initPageLoadHandler() {
if (result.Title != null || result.Artist != null) {
$('#displaySongLinks').show();
$('#displaySongAddPlaylist').unbind('click').click(function () {
customSelectPlaylistSongCallback = function (playlistId) {
request({ url: "addSongToPlaylist?songId=" + result.SongId + "&playlistId=" + playlistId + "&duplicates=false" }, "Add to playlist...");
history.back();
};
$.mobile.changePage("#selectPlaylist", { transition: "slidefade" });
});
$('#displaySongLinkYoutube').unbind('click').click(function () {
showYoutube(result.Artist, result.Title);
});
@@ -253,6 +266,16 @@ function initPageLoadHandler() {
} else {
$('#displaySongLinks').hide();
}
request({
url: "hasUserRight?right=" + 0x32
}).done(function (result2) {
if (result2) {
$('#displaySongAddPlaylist').show();
} else {
$('#displaySongAddPlaylist').hide();
}
});
});
// Save promise on page so the transition handler can find it.
@@ -280,8 +303,7 @@ function initPageLoadHandler() {
if (allSongsCache == null) {
var promise = request({
url: "getAllSongs",
headers: { "session": sessionId }
url: "getAllSongs"
}).done(function (data) {
allSongsCache = data;
handleGetAllSongs();
@@ -350,6 +372,272 @@ function initPageLoadHandler() {
//pageLoadHandler for login
$(document).on('pagebeforeshow', '#login', pagebeforeshowLogin);
//pageLoadHandler for main
$(document).on('pagebeforeshow', '#main', function () {
request({
url: "hasUserRight?right=" + 0x02
}).done(function (result) {
if (result) {
$('#mainPageTakePhotoLink').parent().parent().parent().show();
} else {
$('#mainPageTakePhotoLink').parent().parent().parent().hide();
}
});
request({
url: "hasUserRight?right=" + 0x08
}).done(function (result) {
if (result) {
$('#mainPageKeyboard').parent().parent().parent().show();
} else {
$('#mainPageKeyboard').parent().parent().parent().hide();
}
});
request({
url: "hasUserRight?right=" + 0x04
}).done(function (result) {
if (result) {
$('#mainPageSelectProfile').parent().parent().parent().show();
} else {
$('#mainPageSelectProfile').parent().parent().parent().hide();
}
});
});
//pageLoadHandler for selectPlaylist
$(document).on('pagebeforeshow', '#selectPlaylist', function () {
function handleGetAllPlaylists(data) {
$('#selectPlaylistContentList').children().remove();
$('#selectPlaylistAddPlaylistButton').hide();
function handleSelectSongLineClick(e) {
playlistIdRequest = parseInt(e.currentTarget.parentElement.parentElement.parentElement.id.replace("selectPlaylistLine_", ""));
playlistRequestName = $(e.currentTarget.parentElement.parentElement.parentElement).find('h2').text();
if (customSelectPlaylistSongCallback != null) {
customSelectPlaylistSongCallback(playlistIdRequest, playlistRequestName);
customSelectPlaylistSongCallback = null;
} else {
$.mobile.changePage("#displayPlaylist", { transition: "slidefade" });
}
}
function handleSelectSongLineDeleteClick(e) {
var playlistToDeleteId = parseInt(e.currentTarget.parentElement.id.replace("selectPlaylistLine_", ""));
var playlistToDeleteName = $(e.currentTarget.parentElement).find('h2').text();
if (window.confirm("Do you really want to delete this playlist:\n" + playlistToDeleteName)) {
request({ url: "removePlaylist?playlistId=" + playlistToDeleteId }, "Loading...").done(function () {
request({
url: "getPlaylists"
}).done(function (data2) {
handleGetAllPlaylists(data2);
});
});
}
}
for (var id in data) {
var line = $('<li id="selectPlaylistLine_'
+ data[id].PlaylistId
+ '"> <a href="#"> '/*+'<img src="' + ((data[profile].Avatar && data[profile].Avatar.base64Data) ? data[id].Avatar.base64Data : "img/profile.png") + '"> '*/
+ ' <h2>' + data[id].PlaylistName + '</h2> <p>'
+ data[id].SongCount
+ ' songs</p> </a> <a href="#" class="delete" data-icon="delete">Delete</a> </li>')
.appendTo('#selectPlaylistContentList');
line.find('a:not(.delete)').click(handleSelectSongLineClick);
line.find('a.delete').click(handleSelectSongLineDeleteClick);
}
$('#selectPlaylistContentList').listview('refresh');
request({
url: "hasUserRight?right=" + 0x128
}).done(function (result) {
if (result) {
$('#selectPlaylistContentList').find('.delete').show();
$('#selectPlaylistContentList').listview('refresh');
} else {
$('#selectPlaylistContentList').find('.delete').hide();
$('#selectPlaylistContentList').listview('refresh');
}
});
$('#selectPlaylistAddPlaylistButton').unbind('click').hide().click(function () {
var name = prompt("Name of the new playlist:", "NewPlaylistName");
if (name != null
&& name.replace(" ", "") != ""
&& $('h2').filter(function () { return this.textContent == name; }).length == 0) {
request({ url: "addPlaylist?playlistName=" + name }, "Creating...").done(function () {
request({
url: "getPlaylists"
}).done(function (data2) {
handleGetAllPlaylists(data2);
});
});
} else {
alert("This is not a name.");
}
});
request({
url: "hasUserRight?right=" + 0x64
}).done(function (result) {
if (result) {
$('#selectPlaylistAddPlaylistButton').show();
} else {
$('#selectPlaylistAddPlaylistButton').hide();
}
});
}
var promise = request({
url: "getPlaylists"
}).done(function (data) {
handleGetAllPlaylists(data);
});
// Save promise on page so the transition handler can find it.
$(this).data('promise', promise);
});
//pageLoadHandler for displayPlaylist
$(document).on('pagebeforeshow', '#displayPlaylist', function () {
function handleGetAllPlaylistSongs(data) {
$('#displayPlaylistHeader').find('h1').text(playlistRequestName);
$('#displayPlaylistSaveButton').hide().unbind('click').click(function () {
var promises = [];
$('#displayPlaylistContentList').find('li').each(function (indx, elem) {
var newPos = $(elem).index();
var oldPos = $(elem).data("oldPos");
if (newPos != oldPos) {
var movedId = elem.id.replace("selectSongLine_", "");
promises.push(request({
url: "moveSongInPlaylist?&newPosition=" + newPos + "&playlistId=" + playlistIdRequest + "&songId=" + movedId
}, "Resorting..."));
}
});
$.when.apply(promises).done(function () {
//reload data
request({
url: "getPlaylistSongs?playlistId=" + playlistIdRequest
}).done(function (data2) {
handleGetAllPlaylistSongs(data2);
});
});
});
$('#displayPlaylistContentList').children().remove();
function handleSelectPlaylistSongLineClick(e) {
songIdRequest = parseInt(e.currentTarget.parentElement.parentElement.parentElement.id.replace("selectSongLine_", ""));
$.mobile.changePage("#displaySong", { transition: "slidefade" });
}
function handleSelectPlaylistSongLineDeleteClick(e) {
var songToDeleteId = parseInt(e.currentTarget.parentElement.id.replace("selectSongLine_", ""));
var songToDeleteName = $(e.currentTarget.parentElement).find('h2').text();
if (window.confirm("Do you really want to delete this song from playlist:\n" + songToDeleteName)) {
request({
url: "/removeSongFromPlaylist?position=" + $('#selectSongLine_' + songToDeleteId).index()
+ "&playlistId=" + playlistIdRequest
+ "&songId=" + songToDeleteId
}, "Loading...").done(function () {
//reload data
request({
url: "getPlaylistSongs?playlistId=" + playlistIdRequest
}).done(function (data2) {
handleGetAllPlaylistSongs(data2);
});
});
}
}
var sortedData = [];
for (var id1 in data) {
sortedData[data[id1].PlaylistPosition] = data[id1].Song;
}
var i = 0;
for (var id in sortedData) {
var line = $('<li id="selectSongLine_'
+ sortedData[id].SongId
+ '"> <a href="#"> <img> <h2>'
+ sortedData[id].Artist
+ '</h2> <p>'
+ sortedData[id].Title
+ '</p> </a> <a href="#" class="delete" data-icon="delete">Delete</a> </li>')
.appendTo('#displayPlaylistContentList').data("oldPos", i++);
line.find('a:not(.delete)').click(handleSelectPlaylistSongLineClick);
line.find('a.delete').click(handleSelectPlaylistSongLineDeleteClick);
var img = line.find("img")[0];
addImage(img, sortedData[id].Cover, "img/noCover.png");
}
$('#displayPlaylistContentList').listview('refresh');
request({
url: "hasUserRight?right=" + 0x256
}).done(function (result) {
if (result) {
$('#displayPlaylistContentList').find('.delete').show();
$('#displayPlaylistContentList').listview('refresh');
} else {
$('#displayPlaylistContentList').find('.delete').hide();
$('#displayPlaylistContentList').listview('refresh');
}
});
request({
url: "hasUserRight?right=" + 0x16
}).done(function (result) {
if (result) {
$('#displayPlaylistContentList').sortable({
axis: 'y',
sort: function () {
$('#displayPlaylistSaveButton').show();
var $lis = $(this).children('li');
$lis.each(function () {
var $li = $(this);
var hindex = $lis.filter('.ui-sortable-helper').index();
if (!$li.is('.ui-sortable-helper')) {
var index = $li.index();
index = index < hindex ? index + 1 : index;
$li.val(index);
if ($li.is('.ui-sortable-placeholder')) {
$lis.filter('.ui-sortable-helper').val(index);
}
}
});
}
});
}
});
}
var promise = request({
url: "getPlaylistSongs?playlistId=" + playlistIdRequest
}).done(function (data) {
handleGetAllPlaylistSongs(data);
});
// Save promise on page so the transition handler can find it.
$(this).data('promise', promise);
});
}
function pagebeforeshowLogin() {