Commit local changes

This commit is contained in:
Trevor Squillario 2014-02-22 18:56:13 -05:00
parent bb7d018de4
commit 310c79f63c
16 changed files with 2134 additions and 2520 deletions

View file

@ -100,7 +100,7 @@
<div class="albumtext" title="{{o.artist}}" ng-bind-html="o.artist"></div> <div class="albumtext" title="{{o.artist}}" ng-bind-html="o.artist"></div>
</li> </li>
</ul> </ul>
<div id="player" ng-click="hideQueue()"> <div id="player">
<div id="playercontainer"> <div id="playercontainer">
<div id="playerleft" class="floatleft"> <div id="playerleft" class="floatleft">
<div class="playeractions floatleft"> <div class="playeractions floatleft">

View file

@ -1,5 +1,6 @@
/* Declare app level module */
var JamStash = angular.module('JamStash', ['ngCookies', 'ngRoute', 'ngSanitize']); var JamStash = angular.module('JamStash', ['ngCookies', 'ngRoute', 'ngSanitize']);
//var JamStash = angular.module('JamStash', ['ngCookies', 'ngRoute']);
/* /*
JamStash.config(function ($sceDelegateProvider) { JamStash.config(function ($sceDelegateProvider) {
$sceDelegateProvider.resourceUrlWhitelist(['/^\s*(https?|file|ms-appx):/', 'self']); $sceDelegateProvider.resourceUrlWhitelist(['/^\s*(https?|file|ms-appx):/', 'self']);
@ -9,73 +10,36 @@ JamStash.config(function ($sceDelegateProvider) {
// URL: http://server.com/index.html#/Chapter/1/Section/2?search=moby // URL: http://server.com/index.html#/Chapter/1/Section/2?search=moby
// Route: /Chapter/:chapterId/Section/:sectionId // Route: /Chapter/:chapterId/Section/:sectionId
// //
// Then $routeParams ==> {chapterId:1, sectionId:2, search:'moby'} // Then
$routeParams ==> {chapterId:1, sectionId:2, search:'moby'}
*/ */
JamStash.config(function($routeProvider) { JamStash.config(function ($routeProvider) {
$routeProvider $routeProvider
.when('/index', { .when('/index', { redirectTo: '/library' })
redirectTo: '/library' .when('/settings', { templateUrl: 'js/partials/settings.html', controller: 'SettingsCtrl' })
}) .when('/queue', { templateUrl: 'js/partials/queue.html', controller: 'QueueCtrl' })
.when('/settings', { .when('/library', { templateUrl: 'js/partials/library.html', controller: 'SubsonicCtrl' })
templateUrl: 'js/partials/settings.html', .when('/library/:artistId', { templateUrl: 'js/partials/library.html', controller: 'SubsonicCtrl', reloadOnSearch: false })
controller: 'SettingsCtrl' .when('/library/:artistId/:albumId', { templateUrl: 'js/partials/library.html', controller: 'SubsonicCtrl', reloadOnSearch: false })
}) .when('/playlists', { templateUrl: 'js/partials/playlists.html', controller: 'PlaylistCtrl' })
.when('/queue', { .when('/podcasts', { templateUrl: 'js/partials/podcasts.html', controller: 'PodcastCtrl' })
templateUrl: 'js/partials/queue.html', .when('/archive', { templateUrl: 'js/partials/archive.html', controller: 'ArchiveCtrl' })
controller: 'QueueCtrl' .when('/archive/:artist', { templateUrl: 'js/partials/archive.html', controller: 'ArchiveCtrl' })
}) .when('/archive/:artist/:album', { templateUrl: 'js/partials/archive.html', controller: 'ArchiveCtrl' })
.when('/library', { .otherwise({ redirectTo: '/index' });
templateUrl: 'js/partials/library.html',
controller: 'SubsonicCtrl'
})
.when('/library/:artistId', {
templateUrl: 'js/partials/library.html',
controller: 'SubsonicCtrl',
reloadOnSearch: false
})
.when('/library/:artistId/:albumId', {
templateUrl: 'js/partials/library.html',
controller: 'SubsonicCtrl',
reloadOnSearch: false
})
.when('/playlists', {
templateUrl: 'js/partials/playlists.html',
controller: 'PlaylistCtrl'
})
.when('/podcasts', {
templateUrl: 'js/partials/podcasts.html',
controller: 'PodcastCtrl'
})
.when('/archive', {
templateUrl: 'js/partials/archive.html',
controller: 'ArchiveCtrl'
})
.when('/archive/:artist', {
templateUrl: 'js/partials/archive.html',
controller: 'ArchiveCtrl'
})
.when('/archive/:artist/:album', {
templateUrl: 'js/partials/archive.html',
controller: 'ArchiveCtrl'
})
.otherwise({
redirectTo: '/index'
});
}) })
.run(['$rootScope', '$location', 'globals', .run(['$rootScope', '$location', 'globals', function ($rootScope, $location, globals) {
function($rootScope, $location, globals) { $rootScope.$on("$locationChangeStart", function (event, next, current) {
$rootScope.$on("$locationChangeStart", function(event, next, current) {
$rootScope.loggedIn = false; $rootScope.loggedIn = false;
var path = $location.path().replace(/^\/([^\/]*).*$/, '$1'); var path = $location.path().replace(/^\/([^\/]*).*$/, '$1');
if (globals.settings.Username !== "" && globals.settings.Password !== "" && globals.settings.Server !== "" && path !== 'archive') { if (globals.settings.Username != "" && globals.settings.Password != "" && globals.settings.Server != "" && path != 'archive') {
$rootScope.loggedIn = true; $rootScope.loggedIn = true;
} }
if (!$rootScope.loggedIn && (path != 'settings' && path != 'archive')) { if (!$rootScope.loggedIn && (path != 'settings' && path != 'archive')) {
$location.path('/settings'); $location.path('/settings');
} }
}); });
} }]);
]);
/* /*
JamStash.config(function ($httpProvider, globals) { JamStash.config(function ($httpProvider, globals) {
$httpProvider.defaults.timeout = globals.settings.Timeout; $httpProvider.defaults.timeout = globals.settings.Timeout;

View file

@ -1,5 +1,5 @@
JamStash.controller('ArchiveCtrl', JamStash.controller('ArchiveCtrl',
function ArchiveCtrl($scope, $rootScope, $location, $routeParams, $http, utils, globals, model, notifications, player, json) { function ArchiveCtrl($scope, $rootScope, $location, $routeParams, $http, utils, globals, model, notifications, player, json) {
//$("#left-component").layout($scope.layoutThreeCol); //$("#left-component").layout($scope.layoutThreeCol);
$scope.settings = globals.settings; $scope.settings = globals.settings;
@ -8,57 +8,52 @@
$scope.Protocol = 'jsonp'; $scope.Protocol = 'jsonp';
$scope.artist = []; $scope.artist = [];
$scope.album = []; $scope.album = [];
$scope.selectedArtist = null; $scope.selectedArtist;
$scope.selectedAlbum = null; $scope.selectedAlbum;
$scope.selectedSongs = []; $scope.selectedSongs = [];
$scope.SavedCollections = globals.SavedCollections; $scope.SavedCollections = globals.SavedCollections;
$scope.AllCollections = []; $scope.AllCollections = [];
$scope.loadedCollection = false; $scope.loadedCollection = false;
json.getCollections(function (data) {
json.getCollections(function(data) {
$scope.AllCollections = data; $scope.AllCollections = data;
$scope.loadedCollection = true; $scope.loadedCollection = true;
}); });
$scope.writeSavedCollection = function () {
$scope.writeSavedCollection = function() {
utils.setValue('SavedCollections', $scope.SavedCollections.join(), false); utils.setValue('SavedCollections', $scope.SavedCollections.join(), false);
/*
$scope.$apply(function () {
});
*/
globals.SavedCollections = $scope.SavedCollections; globals.SavedCollections = $scope.SavedCollections;
}; }
$scope.addSavedCollection = function (newValue) {
$scope.addSavedCollection = function(newValue) {
if ($scope.SavedCollections.indexOf(newValue) == -1) { if ($scope.SavedCollections.indexOf(newValue) == -1) {
$scope.SavedCollections.push(newValue); $scope.SavedCollections.push(newValue);
$scope.writeSavedCollection(); $scope.writeSavedCollection();
} }
}; }
$scope.deleteSavedCollection = function (index) {
$scope.deleteSavedCollection = function(index) {
$scope.SavedCollections.splice(index, 1); $scope.SavedCollections.splice(index, 1);
$scope.writeSavedCollection(); $scope.writeSavedCollection();
}; }
$scope.selectedCollection;
$scope.selectedCollection = null; $scope.$watch("selectedCollection", function (newValue, oldValue) {
$scope.$watch("selectedCollection", function(newValue, oldValue) {
if (newValue !== oldValue) { if (newValue !== oldValue) {
$scope.addSavedCollection(newValue); $scope.addSavedCollection(newValue);
} }
}); });
$scope.setupDemoCollections = function () {
$scope.setupDemoCollections = function() {
var demo = ["YonderMountainStringBand", "GreenskyBluegrass"]; var demo = ["YonderMountainStringBand", "GreenskyBluegrass"];
angular.forEach(demo, function(item, key) { angular.forEach(demo, function (item, key) {
if ($scope.SavedCollections.indexOf(item) == -1) { if ($scope.SavedCollections.indexOf(item) == -1) {
$scope.SavedCollections.push(item); $scope.SavedCollections.push(item);
} }
}); });
}; }
$scope.archiveUrl = 'https://archive.org/'; $scope.archiveUrl = 'https://archive.org/';
/* Filter */ /* Filter */
$scope.selectedArchiveAlbumSort = "date desc"; $scope.selectedArchiveAlbumSort = "date desc";
$scope.ArchiveAlbumSort = [ $scope.ArchiveAlbumSort = [
'addeddate desc', 'addeddate desc',
'addeddate asc', 'addeddate asc',
@ -76,9 +71,8 @@
'publicdate asc', 'publicdate asc',
'stars desc', 'stars desc',
'stars asc' 'stars asc'
]; ],
$scope.$watch("selectedArchiveAlbumSort", function (newValue, oldValue) {
$scope.$watch("selectedArchiveAlbumSort", function(newValue, oldValue) {
if (utils.getValue('AlbumSort') != newValue) { if (utils.getValue('AlbumSort') != newValue) {
if (typeof newValue != 'undefined') { if (typeof newValue != 'undefined') {
utils.setValue('AlbumSort', newValue, true); utils.setValue('AlbumSort', newValue, true);
@ -89,37 +83,40 @@
$scope.getAlbums(''); $scope.getAlbums('');
} }
}); });
$scope.getYears = function (startYear) {
$scope.getYears = function(startYear) { var currentYear = new Date().getFullYear(), years = [];
var currentYear = new Date().getFullYear(),
years = [];
startYear = startYear || 1950; startYear = startYear || 1950;
while (startYear <= currentYear) { while (startYear <= currentYear) {
years.push(startYear++); years.push(startYear++);
} }
return years; return years;
}; }
$scope.Years = $scope.getYears(),
$scope.Years = $scope.getYears();
$scope.filter = { $scope.filter = {
Year: "", Year: "",
Source: "", Source: "",
Description: "" Description: ""
}; };
$scope.filterSave = function () {
$scope.filterSave = function() {
if ($scope.selectedArtist) { if ($scope.selectedArtist) {
$scope.getAlbums('', ''); $scope.getAlbums('', '');
} }
}; }
/* End Filter */ /* End Filter */
$scope.getAlbums = function(name, identifier) { /*
$scope.getArtists = function (data) {
var map = function (data) {
return new model.Artist('', data);
};
angular.forEach($scope.SavedCollections, function (item, key) {
$scope.artist.push(map(item));
});
};
*/
$scope.getAlbums = function (name, identifier) {
var url = $scope.archiveUrl + 'advancedsearch.php?q='; var url = $scope.archiveUrl + 'advancedsearch.php?q=';
if (name != '') {
if (name !== '') {
$scope.selectedArtist = name; $scope.selectedArtist = name;
url += 'collection:(' + name + ') AND format:(MP3)'; url += 'collection:(' + name + ') AND format:(MP3)';
} else if ($scope.selectedArtist) { } else if ($scope.selectedArtist) {
@ -127,18 +124,13 @@
} else { } else {
url += 'identifier:(' + identifier + ')'; url += 'identifier:(' + identifier + ')';
} }
var map = function (data) {
var map = function(data) {
var song = data; var song = data;
var coverartthumb, coverartfull, starred; var coverartthumb, coverartfull, starred;
var url = $scope.archiveUrl + 'details/' + song.identifier; var url = $scope.archiveUrl + 'details/' + song.identifier;
coverartthumb = 'images/albumdefault_50.jpg'; coverartthumb = 'images/albumdefault_50.jpg';
coverartfull = 'images/albumdefault_160.jpg'; coverartfull = 'images/albumdefault_160.jpg';
if (parseInt(song.avg_rating) == 5) { if (parseInt(song.avg_rating) == 5) { starred = true; } else { starred = false; }
starred = true;
} else {
starred = false;
}
//var description = '<b>Details</b><br />'; //var description = '<b>Details</b><br />';
var description = '<b>Source</b>: ' + song.source + '<br />'; var description = '<b>Source</b>: ' + song.source + '<br />';
description += '<b>Date</b>: ' + song.date + '<br />'; description += '<b>Date</b>: ' + song.date + '<br />';
@ -146,41 +138,36 @@
description += typeof song.avg_rating != 'undefined' ? '<b>Rating</b>: ' + song.avg_rating + '<br />' : ''; description += typeof song.avg_rating != 'undefined' ? '<b>Rating</b>: ' + song.avg_rating + '<br />' : '';
description += typeof song.downloads != 'undefined' ? '<b>Downloads</b>: ' + song.downloads + '<br />' : ''; description += typeof song.downloads != 'undefined' ? '<b>Downloads</b>: ' + song.downloads + '<br />' : '';
return new model.Album(song.identifier, null, song.title, song.collection[0], '', coverartthumb, coverartfull, $.format.date(new Date(song.publicdate), "yyyy-MM-dd h:mm a"), starred, description, url); return new model.Album(song.identifier, null, song.title, song.collection[0], '', coverartthumb, coverartfull, $.format.date(new Date(song.publicdate), "yyyy-MM-dd h:mm a"), starred, description, url);
}; }
if ($scope.filter.Source) { if ($scope.filter.Source) {
url += ' AND source:(' + $scope.filter.Source + ')'; url += ' AND source:(' + $scope.filter.Source + ')';
} }
if ($scope.filter.Year) { if ($scope.filter.Year) {
if (parseInt($scope.filter.Year)) { if (parseInt($scope.filter.Year)) {
url += ' AND year:(' + $scope.filter.Year + ')'; url += ' AND year:(' + $scope.filter.Year + ')';
} }
} }
if ($scope.filter.Description) { if ($scope.filter.Description) {
url += ' AND description:(' + $scope.filter.Description + ')'; url += ' AND description:(' + $scope.filter.Description + ')';
} }
if ($scope.selectedArchiveAlbumSort) { if ($scope.selectedArchiveAlbumSort) {
url += '&sort[]=' + $scope.selectedArchiveAlbumSort; url += '&sort[]=' + $scope.selectedArchiveAlbumSort;
} }
url += '&fl[]=avg_rating,collection,date,description,downloads,headerImage,identifier,publisher,publicdate,source,subject,title,year'; url += '&fl[]=avg_rating,collection,date,description,downloads,headerImage,identifier,publisher,publicdate,source,subject,title,year';
url += '&rows=50&page=1&output=json'; url += '&rows=50&page=1&output=json';
$.ajax({ $.ajax({
url: url, url: url,
method: 'GET', method: 'GET',
dataType: $scope.Protocol, dataType: $scope.Protocol,
timeout: globals.settings.Timeout, timeout: globals.settings.Timeout,
success: function(data) { success: function (data) {
var items = []; var items = [];
if (data.response.docs.length > 0) { if (data["response"].docs.length > 0) {
items = data.response.docs; items = data["response"].docs;
//alert(JSON.stringify(data["response"]));
$scope.album = []; $scope.album = [];
$rootScope.song = []; $rootScope.song = [];
angular.forEach(items, function(item, key) { angular.forEach(items, function (item, key) {
$scope.album.push(map(item)); $scope.album.push(map(item));
}); });
$scope.$apply(); $scope.$apply();
@ -189,42 +176,24 @@
notifications.updateMessage("Sorry :(", true); notifications.updateMessage("Sorry :(", true);
} }
}, },
error: function() { error: function () {
alert('Archive.org service down :('); alert('Archive.org service down :(');
} }
}); });
}; };
utils.mapSong = function (key, song, server, dir, identifier, coverart) {
utils.mapSong = function(key, song, server, dir, identifier, coverart) {
var url, time, track, title, rating, starred, contenttype, suffix; var url, time, track, title, rating, starred, contenttype, suffix;
var specs = ''; var specs = ''
if (song.format == 'VBR MP3') { if (song.format == 'VBR MP3') {
url = 'http://' + server + dir + key; url = 'http://' + server + dir + key;
if (typeof song.bitrate == 'undefined' || typeof song.format == 'undefined') { if (typeof song.bitrate == 'undefined' || typeof song.format == 'undefined') { specs = '&nbsp;'; } else { specs = song.bitrate + 'kbps, ' + song.format.toLowerCase(); }
specs = '&nbsp;'; if (typeof song.track == 'undefined') { track = '&nbsp;'; } else { track = song.track; }
} else { if (typeof song.title == 'undefined') { title = '&nbsp;'; } else { title = song.title; }
specs = song.bitrate + 'kbps, ' + song.format.toLowerCase(); if (typeof song.length == 'undefined') { time = '&nbsp;'; } else { time = utils.timeToSeconds(song.length); }
}
if (typeof song.track == 'undefined') {
track = '&nbsp;';
} else {
track = song.track;
}
if (typeof song.title == 'undefined') {
title = '&nbsp;';
} else {
title = song.title;
}
if (typeof song.length == 'undefined') {
time = '&nbsp;';
} else {
time = utils.timeToSeconds(song.length);
}
return new model.Song(song.md5, identifier, song.track, title, song.creator, '', song.album, '', coverart, coverart, time, '', '', 'mp3', specs, url, 0, ''); return new model.Song(song.md5, identifier, song.track, title, song.creator, '', song.album, '', coverart, coverart, time, '', '', 'mp3', specs, url, 0, '');
} }
}; };
$scope.getSongs = function (id, action) {
$scope.getSongs = function(id, action) {
$scope.selectedAlbum = id; $scope.selectedAlbum = id;
var url = $scope.archiveUrl + 'details/' + id + '?output=json'; var url = $scope.archiveUrl + 'details/' + id + '?output=json';
$.ajax({ $.ajax({
@ -232,7 +201,7 @@
method: 'GET', method: 'GET',
dataType: $scope.Protocol, dataType: $scope.Protocol,
timeout: globals.settings.Timeout, timeout: globals.settings.Timeout,
success: function(data) { success: function (data) {
var coverart = ''; var coverart = '';
var server = data.server; var server = data.server;
var dir = data.dir; var dir = data.dir;
@ -242,7 +211,7 @@
} }
var items = data.files; var items = data.files;
if (action == 'add') { if (action == 'add') {
angular.forEach(items, function(item, key) { angular.forEach(items, function (item, key) {
var song = utils.mapSong(key, item, server, dir, identifier, coverart); var song = utils.mapSong(key, item, server, dir, identifier, coverart);
if (song) { if (song) {
$rootScope.queue.push(song); $rootScope.queue.push(song);
@ -253,14 +222,14 @@
$scope.$apply(); $scope.$apply();
} else if (action == 'play') { } else if (action == 'play') {
$rootScope.queue = []; $rootScope.queue = [];
angular.forEach(items, function(item, key) { angular.forEach(items, function (item, key) {
var song = utils.mapSong(key, item, server, dir, identifier, coverart); var song = utils.mapSong(key, item, server, dir, identifier, coverart);
if (song) { if (song) {
$rootScope.queue.push(song); $rootScope.queue.push(song);
} }
}); });
var next = $rootScope.queue[0]; var next = $rootScope.queue[0];
$scope.$apply(function() { $scope.$apply(function () {
$rootScope.playSong(false, next); $rootScope.playSong(false, next);
}); });
$rootScope.showQueue(); $rootScope.showQueue();
@ -268,7 +237,7 @@
} else { } else {
$scope.album = []; $scope.album = [];
$rootScope.song = []; $rootScope.song = [];
angular.forEach(items, function(item, key) { angular.forEach(items, function (item, key) {
var song = utils.mapSong(key, item, server, dir, identifier, coverart); var song = utils.mapSong(key, item, server, dir, identifier, coverart);
if (song) { if (song) {
$rootScope.song.push(song); $rootScope.song.push(song);
@ -279,35 +248,31 @@
} }
}); });
}; };
$scope.addSongsToQueue = function () {
$scope.addSongsToQueue = function() {
if ($scope.selectedSongs.length > 0) { if ($scope.selectedSongs.length > 0) {
angular.forEach($scope.selectedSongs, function(item, key) { angular.forEach($scope.selectedSongs, function (item, key) {
$scope.queue.push(item); $scope.queue.push(item);
item.selected = false; item.selected = false;
}); });
$rootScope.showQueue(); $rootScope.showQueue();
notifications.updateMessage($scope.selectedSongs.length + ' Song(s) Added to Queue', true); notifications.updateMessage($scope.selectedSongs.length + ' Song(s) Added to Queue', true);
} }
}; }
$scope.scrollToTop = function () {
$scope.scrollToTop = function() {
$('#Artists').stop().scrollTo('#auto', 400); $('#Artists').stop().scrollTo('#auto', 400);
}; }
$scope.selectAll = function () {
$scope.selectAll = function() { angular.forEach($rootScope.song, function (item, key) {
angular.forEach($rootScope.song, function(item, key) {
$scope.selectedSongs.push(item); $scope.selectedSongs.push(item);
item.selected = true; item.selected = true;
}); });
}; }
$scope.selectNone = function () {
$scope.selectNone = function() { angular.forEach($rootScope.song, function (item, key) {
angular.forEach($rootScope.song, function(item, key) {
$scope.selectedSongs = []; $scope.selectedSongs = [];
item.selected = false; item.selected = false;
}); });
}; }
/* Launch on Startup */ /* Launch on Startup */
if ($routeParams.artist) { if ($routeParams.artist) {
@ -320,4 +285,4 @@
$scope.addSavedCollection($routeParams.artist); $scope.addSavedCollection($routeParams.artist);
} }
/* End Startup */ /* End Startup */
}); });

View file

@ -1,5 +1,6 @@
JamStash.controller('SubsonicCtrl', JamStash.controller('SubsonicCtrl',
function SubsonicCtrl($scope, $rootScope, $location, $window, $routeParams, utils, globals, model, notifications, player) { function SubsonicCtrl($scope, $rootScope, $location, $window, $routeParams, utils, globals, model, notifications, player) {
//$("#SubsonicAlbums").layout($scope.layoutThreeCol);
$rootScope.song = []; $rootScope.song = [];
//$scope.artistId = $routeParams.artistId; //$scope.artistId = $routeParams.artistId;
@ -11,79 +12,59 @@
$scope.album = []; $scope.album = [];
$scope.Server = globals.settings.Server; $scope.Server = globals.settings.Server;
$scope.playlistMenu = []; $scope.playlistMenu = [];
$scope.AutoAlbums = [{ $scope.AutoAlbums = [
id: "random", { id: "random", name: "Random" },
name: "Random" { id: "newest", name: "Recently Added" },
}, { { id: "starred", name: "Starred" },
id: "newest", { id: "highest", name: "Top Rated" },
name: "Recently Added" { id: "frequent", name: "Most Played" },
}, { { id: "recent", name: "Recently Played" }
id: "starred", ];
name: "Starred" $scope.selectedAutoAlbum;
}, { $scope.selectedArtist;
id: "highest", $scope.selectedAlbum;
name: "Top Rated"
}, {
id: "frequent",
name: "Most Played"
}, {
id: "recent",
name: "Recently Played"
}];
$scope.selectedAutoAlbum = null;
$scope.selectedArtist = null;
$scope.selectedAlbum = null;
$scope.SelectedAlbumSort = globals.settings.DefaultAlbumSort; $scope.SelectedAlbumSort = globals.settings.DefaultAlbumSort;
$scope.AlbumSort = globals.AlbumSorts; $scope.AlbumSort = globals.AlbumSorts;
$scope.BreadCrumbs = []; $scope.BreadCrumbs = [];
$scope.$watch("SelectedAlbumSort.id", function (newValue, oldValue) {
$scope.$watch("SelectedAlbumSort.id", function(newValue, oldValue) {
if (newValue !== oldValue) { if (newValue !== oldValue) {
if ($rootScope.song.length > 0) { if ($rootScope.song.length > 0) {
$scope.sortSubsonicSongs(newValue); $scope.sortSubsonicSongs(newValue);
} else if ($scope.album.length > 0) { } else if ($scope.album.length > 0) {
$scope.sortSubsonicAlbums(newValue); $scope.sortSubsonicAlbums(newValue);
indexes = $.map(globals.AlbumSorts, function (obj, index) {
indexes = $.map(globals.AlbumSorts, function(obj, index) {
if (obj.id == newValue) { if (obj.id == newValue) {
return index; return index;
} }
}); })
globals.settings.DefaultAlbumSort = globals.AlbumSorts[indexes]; globals.settings.DefaultAlbumSort = globals.AlbumSorts[indexes];
} }
} }
}); });
$rootScope.$watch("SelectedMusicFolder", function (newValue, oldValue) {
$rootScope.$watch("SelectedMusicFolder", function(newValue, oldValue) {
if (newValue !== oldValue) { if (newValue !== oldValue) {
utils.setValue('MusicFolders', angular.toJson(newValue), true); utils.setValue('MusicFolders', angular.toJson(newValue), true);
$scope.getArtists(newValue.id); $scope.getArtists(newValue.id);
} }
}); });
$scope.SearchType = globals.settings.DefaultSearchType; $scope.SearchType = globals.settings.DefaultSearchType;
$scope.SearchTypes = globals.SearchTypes; $scope.SearchTypes = globals.SearchTypes;
$scope.rescanLibrary = function (data, event) {
$scope.rescanLibrary = function(data, event) {
$.ajax({ $.ajax({
url: globals.BaseURL() + '/getUser.view?' + globals.BaseParams() + '&username=' + globals.settings.Username, url: globals.BaseURL() + '/getUser.view?' + globals.BaseParams() + '&username=' + globals.settings.Username,
method: 'GET', method: 'GET',
dataType: globals.settings.Protocol, dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout, timeout: globals.settings.Timeout,
success: function(data) { success: function (data) {
if (data["subsonic-response"].user.adminRole === true) { if (data["subsonic-response"].user.adminRole == true) {
$.get(globals.settings.Server + '/musicFolderSettings.view?scanNow'); $.get(globals.settings.Server + '/musicFolderSettings.view?scanNow');
} else { } else {
alert('You are not logged in as an admin user!'); alert('You are not logged in as an admin user!');
} }
} }
}); });
}; }
$scope.mapArtist = function (data) {
$scope.mapArtist = function(data) {
var name = ''; var name = '';
var artist = data.artist; var artist = data.artist;
var artists = []; var artists = [];
@ -92,34 +73,23 @@
} else { } else {
artists[0] = artist; artists[0] = artist;
} }
angular.forEach(artists, function(item, key) { angular.forEach(artists, function (item, key) {
if (typeof item.name !== 'undefined') { if (typeof item.name !== 'undefined') { item.name = item.name.toString(); }
item.name = item.name.toString();
}
}); });
if (typeof data.name !== 'undefined') { if (typeof data.name !== 'undefined') { name = data.name.toString(); }
name = data.name.toString();
}
return new model.Index(name, artists); return new model.Index(name, artists);
}; }
$scope.mapIndex = function (data) {
$scope.mapIndex = function(data) {
var name, id = ''; var name, id = '';
if (typeof data.id !== 'undefined') { if (typeof data.id !== 'undefined') { id = data.id; }
id = data.id; if (typeof data.name !== 'undefined') { name = data.name.toString(); }
}
if (typeof data.name !== 'undefined') {
name = data.name.toString();
}
return new model.Artist(id, name); return new model.Artist(id, name);
}; }
$scope.mapPlaylist = function (data) {
$scope.mapPlaylist = function(data) {
return new model.Artist(data.id, data.name); return new model.Artist(data.id, data.name);
}; }
$scope.getArtists = function (id) {
$scope.getArtists = function(id) { var url, id;
var url;
if (utils.getValue('MusicFolders')) { if (utils.getValue('MusicFolders')) {
var folder = angular.fromJson(utils.getValue('MusicFolders')); var folder = angular.fromJson(utils.getValue('MusicFolders'));
id = folder.id; id = folder.id;
@ -134,17 +104,9 @@
method: 'GET', method: 'GET',
dataType: globals.settings.Protocol, dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout, timeout: globals.settings.Timeout,
done: function() { done: function () { if (globals.settings.Debug) { console.log("DONE!"); } },
if (globals.settings.Debug) { error: function () { if (globals.settings.Debug) { console.log("ERROR!"); } },
console.log("DONE!"); success: function (data) {
}
},
error: function() {
if (globals.settings.Debug) {
console.log("ERROR!");
}
},
success: function(data) {
var indexes = []; var indexes = [];
if (typeof data["subsonic-response"].indexes.index != 'undefined') { if (typeof data["subsonic-response"].indexes.index != 'undefined') {
if (data["subsonic-response"].indexes.index.length > 0) { if (data["subsonic-response"].indexes.index.length > 0) {
@ -165,41 +127,32 @@
} else { } else {
items[0] = data["subsonic-response"].indexes.shortcut; items[0] = data["subsonic-response"].indexes.shortcut;
} }
angular.forEach(items, function(item, key) { angular.forEach(items, function (item, key) {
$scope.shortcut.push($scope.mapIndex(item)); $scope.shortcut.push($scope.mapIndex(item));
}); });
} }
$scope.index = []; $scope.index = [];
angular.forEach(indexes, function(item, key) { angular.forEach(indexes, function (item, key) {
$scope.index.push($scope.mapArtist(item)); $scope.index.push($scope.mapArtist(item));
}); });
$scope.$apply(); $scope.$apply();
} }
}); });
}; };
$scope.refreshArtists = function (id) {
$scope.refreshArtists = function(id) {
utils.setValue('MusicFolders', null, true); utils.setValue('MusicFolders', null, true);
$scope.getArtists(); $scope.getArtists();
}; };
$scope.mapAlbum = function(data) { $scope.mapAlbum = function (data) {
var album = data; var album = data;
var title, coverartthumb, coverartfull, starred; var title, coverartthumb, coverartfull, starred;
if (typeof album.coverArt != 'undefined') { if (typeof album.coverArt != 'undefined') {
coverartthumb = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&size=160&id=' + album.coverArt; coverartthumb = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&size=160&id=' + album.coverArt;
coverartfull = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&id=' + album.coverArt; coverartfull = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&id=' + album.coverArt;
} }
if (typeof album.starred !== 'undefined') { if (typeof album.starred !== 'undefined') { starred = true; } else { starred = false; }
starred = true; if (typeof album.title !== 'undefined') { title = album.title; } else { title = album.name; }
} else {
starred = false;
}
if (typeof album.title !== 'undefined') {
title = album.title;
} else {
title = album.name;
}
var type; var type;
if (album.isDir) { if (album.isDir) {
type = 'byfolder'; type = 'byfolder';
@ -207,24 +160,19 @@
type = 'bytag'; type = 'bytag';
} }
return new model.Album(album.id, album.parent, title, album.artist, album.artistId, coverartthumb, coverartfull, $.format.date(new Date(album.created), "yyyy-MM-dd h:mm a"), starred, '', '', type); return new model.Album(album.id, album.parent, title, album.artist, album.artistId, coverartthumb, coverartfull, $.format.date(new Date(album.created), "yyyy-MM-dd h:mm a"), starred, '', '', type);
}; }
$scope.getAlbums = function (id, name) {
$scope.getAlbums = function(id, name) {
$scope.selectedAutoAlbum = null; $scope.selectedAutoAlbum = null;
$scope.selectedArtist = id; $scope.selectedArtist = id;
$scope.BreadCrumbs = []; $scope.BreadCrumbs = [];
$scope.BreadCrumbs.push({ $scope.BreadCrumbs.push({ 'type': 'artist', 'id': id, 'name': name });
'type': 'artist',
'id': id,
'name': name
});
var url = globals.BaseURL() + '/getMusicDirectory.view?' + globals.BaseParams() + '&id=' + id; var url = globals.BaseURL() + '/getMusicDirectory.view?' + globals.BaseParams() + '&id=' + id;
$.ajax({ $.ajax({
url: url, url: url,
method: 'GET', method: 'GET',
dataType: globals.settings.Protocol, dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout, timeout: globals.settings.Timeout,
success: function(data) { success: function (data) {
var items = []; var items = [];
if (typeof data["subsonic-response"].directory.child != 'undefined') { if (typeof data["subsonic-response"].directory.child != 'undefined') {
if (data["subsonic-response"].directory.child.length > 0) { if (data["subsonic-response"].directory.child.length > 0) {
@ -235,7 +183,7 @@
$scope.album = []; $scope.album = [];
$rootScope.song = []; $rootScope.song = [];
angular.forEach(items, function(item, key) { angular.forEach(items, function (item, key) {
if (item.isDir) { if (item.isDir) {
$scope.album.push($scope.mapAlbum(item)); $scope.album.push($scope.mapAlbum(item));
} else { } else {
@ -252,8 +200,21 @@
} }
}); });
}; };
$scope.getArtistByTag = function (id) { // Gets Artist by ID3 tag
/*
var map = {
create: function (options) {
var album = options.data;
var coverart, starred;
if (typeof album.coverArt != 'undefined') {
coverart = self.settings.BaseURL() + '/getCoverArt.view?' + self.settings.BaseParams() + '&size=50&id=' + album.coverArt;
}
if (typeof album.starred !== 'undefined') { starred = true; } else { starred = false; }
return new model.Album(album.id, album.parent, album.name, album.artist, coverart, album.created, starred, '', '');
}
}
*/
$scope.getArtistByTag = function(id) { // Gets Artist by ID3 tag
$scope.selectedAutoAlbum = null; $scope.selectedAutoAlbum = null;
$scope.selectedArtist = id; $scope.selectedArtist = id;
var url = globals.BaseURL() + '/getArtist.view?' + globals.BaseParams() + '&id=' + id; var url = globals.BaseURL() + '/getArtist.view?' + globals.BaseParams() + '&id=' + id;
@ -262,7 +223,7 @@
method: 'GET', method: 'GET',
dataType: globals.settings.Protocol, dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout, timeout: globals.settings.Timeout,
success: function(data) { success: function (data) {
var items = []; var items = [];
if (typeof data["subsonic-response"].artist != 'undefined') { if (typeof data["subsonic-response"].artist != 'undefined') {
if (data["subsonic-response"].artist.album.length > 0) { if (data["subsonic-response"].artist.album.length > 0) {
@ -273,7 +234,7 @@
$scope.album = []; $scope.album = [];
$rootScope.song = []; $rootScope.song = [];
angular.forEach(items, function(item, key) { angular.forEach(items, function (item, key) {
$scope.album.push($scope.mapAlbum(item)); $scope.album.push($scope.mapAlbum(item));
}); });
$scope.$apply(); $scope.$apply();
@ -283,14 +244,13 @@
} }
}); });
}; };
$scope.getAlbumByTag = function (id) { // Gets Album by ID3 tag
$scope.getAlbumByTag = function(id) { // Gets Album by ID3 tag
$.ajax({ $.ajax({
url: globals.BaseURL() + '/getAlbum.view?' + globals.BaseParams() + '&id=' + id, url: globals.BaseURL() + '/getAlbum.view?' + globals.BaseParams() + '&id=' + id,
method: 'GET', method: 'GET',
dataType: globals.settings.Protocol, dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout, timeout: globals.settings.Timeout,
success: function(data) { success: function (data) {
if (typeof data["subsonic-response"].album != 'undefined') { if (typeof data["subsonic-response"].album != 'undefined') {
$scope.album = []; $scope.album = [];
$rootScope.song = []; $rootScope.song = [];
@ -303,7 +263,7 @@
} else { } else {
items[0] = data["subsonic-response"].album.song; items[0] = data["subsonic-response"].album.song;
} }
angular.forEach(items, function(item, key) { angular.forEach(items, function (item, key) {
$rootScope.song.push(utils.mapSong(item)); $rootScope.song.push(utils.mapSong(item));
}); });
$scope.$apply(); $scope.$apply();
@ -311,32 +271,28 @@
} }
}); });
}; };
$scope.offset = 0; $scope.offset = 0;
$scope.getAlbumListBy = function(id, offset) { $scope.getAlbumListBy = function (id, offset) {
var size, url; var size, url;
$scope.selectedArtist = null; $scope.selectedArtist = null;
$scope.selectedAutoAlbum = id; $scope.selectedAutoAlbum = id;
$scope.BreadCrumbs = []; $scope.BreadCrumbs = [];
if (offset == 'next') { if (offset == 'next') {
$scope.offset = $scope.offset + globals.settings.AutoAlbumSize; $scope.offset = $scope.offset + globals.settings.AutoAlbumSize;
} else if (offset == 'prev') { } else if (offset == 'prev') {
$scope.offset = $scope.offset - globals.settings.AutoAlbumSize; $scope.offset = $scope.offset - globals.settings.AutoAlbumSize;
} }
if ($scope.offset > 0) { if ($scope.offset > 0) {
url = globals.BaseURL() + '/getAlbumList.view?' + globals.BaseParams() + '&size=' + globals.settings.AutoAlbumSize.toString() + '&type=' + id + '&offset=' + $scope.offset; url = globals.BaseURL() + '/getAlbumList.view?' + globals.BaseParams() + '&size=' + globals.settings.AutoAlbumSize.toString() + '&type=' + id + '&offset=' + $scope.offset;
} else { } else {
url = globals.BaseURL() + '/getAlbumList.view?' + globals.BaseParams() + '&size=' + globals.settings.AutoAlbumSize.toString() + '&type=' + id; url = globals.BaseURL() + '/getAlbumList.view?' + globals.BaseParams() + '&size=' + globals.settings.AutoAlbumSize.toString() + '&type=' + id;
} }
$.ajax({ $.ajax({
url: url, url: url,
method: 'GET', method: 'GET',
dataType: globals.settings.Protocol, dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout, timeout: globals.settings.Timeout,
success: function(data) { success: function (data) {
var items = []; var items = [];
if (typeof data["subsonic-response"].albumList.album != 'undefined') { if (typeof data["subsonic-response"].albumList.album != 'undefined') {
if (data["subsonic-response"].albumList.album.length > 0) { if (data["subsonic-response"].albumList.album.length > 0) {
@ -346,7 +302,7 @@
} }
$scope.album = []; $scope.album = [];
$rootScope.song = []; $rootScope.song = [];
angular.forEach(items, function(item, key) { angular.forEach(items, function (item, key) {
if (item.isDir) { if (item.isDir) {
$scope.album.push($scope.mapAlbum(item)); $scope.album.push($scope.mapAlbum(item));
} else { } else {
@ -363,8 +319,7 @@
} }
}); });
}; };
$scope.getSongs = function (id, action) {
$scope.getSongs = function(id, action) {
$scope.selectedAlbum = id; $scope.selectedAlbum = id;
var url = globals.BaseURL() + '/getMusicDirectory.view?' + globals.BaseParams() + '&id=' + id; var url = globals.BaseURL() + '/getMusicDirectory.view?' + globals.BaseParams() + '&id=' + id;
$.ajax({ $.ajax({
@ -372,7 +327,7 @@
method: 'GET', method: 'GET',
dataType: globals.settings.Protocol, dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout, timeout: globals.settings.Timeout,
success: function(data) { success: function (data) {
var items = []; var items = [];
if (typeof data["subsonic-response"].directory.child != 'undefined') { if (typeof data["subsonic-response"].directory.child != 'undefined') {
if (data["subsonic-response"].directory.child.length > 0) { if (data["subsonic-response"].directory.child.length > 0) {
@ -381,7 +336,7 @@
items[0] = data["subsonic-response"].directory.child; items[0] = data["subsonic-response"].directory.child;
} }
if (action == 'add') { if (action == 'add') {
angular.forEach(items, function(item, key) { angular.forEach(items, function (item, key) {
$rootScope.queue.push(utils.mapSong(item)); $rootScope.queue.push(utils.mapSong(item));
}); });
$scope.$apply(); $scope.$apply();
@ -389,18 +344,18 @@
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true); notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else if (action == 'play') { } else if (action == 'play') {
$rootScope.queue = []; $rootScope.queue = [];
angular.forEach(items, function(item, key) { angular.forEach(items, function (item, key) {
$rootScope.queue.push(utils.mapSong(item)); $rootScope.queue.push(utils.mapSong(item));
}); });
var next = $rootScope.queue[0]; var next = $rootScope.queue[0];
$scope.$apply(function() { $scope.$apply(function () {
$rootScope.playSong(false, next); $rootScope.playSong(false, next);
}); });
$rootScope.showQueue(); $rootScope.showQueue();
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true); notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else if (action == 'preview') { } else if (action == 'preview') {
$scope.songpreview = []; $scope.songpreview = [];
angular.forEach(items, function(item, key) { angular.forEach(items, function (item, key) {
if (!item.isDir) { if (!item.isDir) {
$rootScope.songpreview.push(utils.mapSong(item)); $rootScope.songpreview.push(utils.mapSong(item));
} }
@ -410,21 +365,13 @@
if (typeof data["subsonic-response"].directory.id != 'undefined') { if (typeof data["subsonic-response"].directory.id != 'undefined') {
var albumId = data["subsonic-response"].directory.id; var albumId = data["subsonic-response"].directory.id;
var albumName = data["subsonic-response"].directory.name; var albumName = data["subsonic-response"].directory.name;
if ($scope.BreadCrumbs.length > 0) { $scope.BreadCrumbs.splice(1, ($scope.BreadCrumbs.length - 1)) };
if ($scope.BreadCrumbs.length > 0) { $scope.BreadCrumbs.push({ 'type': 'album', 'id': albumId, 'name': albumName });
$scope.BreadCrumbs.splice(1, ($scope.BreadCrumbs.length - 1));
}
$scope.BreadCrumbs.push({
'type': 'album',
'id': albumId,
'name': albumName
});
} }
$rootScope.song = []; $rootScope.song = [];
$scope.album = []; $scope.album = [];
var albums = []; var albums = [];
angular.forEach(items, function(item, key) { angular.forEach(items, function (item, key) {
if (item.isDir) { if (item.isDir) {
albums.push($scope.mapAlbum(item)); albums.push($scope.mapAlbum(item));
} else { } else {
@ -445,17 +392,16 @@
} }
}); });
}; };
$scope.search = function () {
$scope.search = function() {
var query = $('#Search').val(); var query = $('#Search').val();
if (query !== '') { if (query != '') {
var type = $('#SearchType').val(); var type = $('#SearchType').val();
$.ajax({ $.ajax({
url: globals.BaseURL() + '/search2.view?' + globals.BaseParams() + '&query=' + query, url: globals.BaseURL() + '/search2.view?' + globals.BaseParams() + '&query=' + query,
method: 'GET', method: 'GET',
dataType: globals.settings.Protocol, dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout, timeout: globals.settings.Timeout,
success: function(data) { success: function (data) {
if (data["subsonic-response"].searchResult2 !== "") { if (data["subsonic-response"].searchResult2 !== "") {
var header; var header;
var items = []; var items = [];
@ -467,7 +413,7 @@
items[0] = data["subsonic-response"].searchResult2.song; items[0] = data["subsonic-response"].searchResult2.song;
} }
$rootScope.song = []; $rootScope.song = [];
angular.forEach(items, function(item, key) { angular.forEach(items, function (item, key) {
$rootScope.song.push(utils.mapSong(item)); $rootScope.song.push(utils.mapSong(item));
}); });
$scope.$apply(); $scope.$apply();
@ -481,7 +427,7 @@
items[0] = data["subsonic-response"].searchResult2.album; items[0] = data["subsonic-response"].searchResult2.album;
} }
$scope.album = []; $scope.album = [];
angular.forEach(items, function(item, key) { angular.forEach(items, function (item, key) {
if (item.isDir) { if (item.isDir) {
$scope.album.push($scope.mapAlbum(item)); $scope.album.push($scope.mapAlbum(item));
} else { } else {
@ -498,7 +444,7 @@
} else { } else {
items[0] = data["subsonic-response"].searchResult2.artist; items[0] = data["subsonic-response"].searchResult2.artist;
} }
angular.forEach(items, function(item, key) { angular.forEach(items, function (item, key) {
$scope.shortcut.push(item); $scope.shortcut.push(item);
}); });
$scope.$apply(); $scope.$apply();
@ -507,20 +453,19 @@
} }
} }
}); });
//$('#Search').val("");
} }
}; }
$scope.toggleAZ = function (event) {
$scope.toggleAZ = function(event) {
$scope.toggleSubmenu('#submenu_AZIndex', '#AZIndex', 'right', 44); $scope.toggleSubmenu('#submenu_AZIndex', '#AZIndex', 'right', 44);
}; }
$scope.loadPlaylistsForMenu = function (data, event) {
$scope.loadPlaylistsForMenu = function(data, event) {
$.ajax({ $.ajax({
url: globals.BaseURL() + '/getPlaylists.view?' + globals.BaseParams(), url: globals.BaseURL() + '/getPlaylists.view?' + globals.BaseParams(),
method: 'GET', method: 'GET',
dataType: globals.settings.Protocol, dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout, timeout: globals.settings.Timeout,
success: function(data) { success: function (data) {
var playlists = []; var playlists = [];
$scope.playlistMenu = []; $scope.playlistMenu = [];
if (typeof data["subsonic-response"].playlists.playlist != 'undefined') { if (typeof data["subsonic-response"].playlists.playlist != 'undefined') {
@ -529,7 +474,7 @@
} else { } else {
playlists[0] = data["subsonic-response"].playlists.playlist; playlists[0] = data["subsonic-response"].playlists.playlist;
} }
angular.forEach(playlists, function(item, key) { angular.forEach(playlists, function (item, key) {
if (item.owner == globals.settings.Username) { if (item.owner == globals.settings.Username) {
$scope.playlistMenu.push($scope.mapPlaylist(item)); $scope.playlistMenu.push($scope.mapPlaylist(item));
} }
@ -549,12 +494,11 @@
*/ */
} }
}); });
}; }
$scope.addToPlaylist = function (id) {
$scope.addToPlaylist = function(id) {
var songs = []; var songs = [];
if ($scope.selectedSongs.length !== 0) { if ($scope.selectedSongs.length !== 0) {
angular.forEach($scope.selectedSongs, function(item, key) { angular.forEach($scope.selectedSongs, function (item, key) {
songs.push(item.id); songs.push(item.id);
}); });
var runningVersion = utils.parseVersionString(globals.settings.ApiVersion); var runningVersion = utils.parseVersionString(globals.settings.ApiVersion);
@ -565,11 +509,8 @@
url: globals.BaseURL() + '/updatePlaylist.view?' + globals.BaseParams(), url: globals.BaseURL() + '/updatePlaylist.view?' + globals.BaseParams(),
dataType: globals.settings.Protocol, dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout, timeout: globals.settings.Timeout,
data: { data: { playlistId: id, songIdToAdd: songs },
playlistId: id, success: function (data) {
songIdToAdd: songs
},
success: function(data) {
$scope.selectedSongs.length = 0; $scope.selectedSongs.length = 0;
notifications.updateMessage('Playlist Updated!', true); notifications.updateMessage('Playlist Updated!', true);
}, },
@ -577,25 +518,20 @@
}); });
} }
} }
}; }
$scope.sortDateFunction = function (a, b) {
$scope.sortDateFunction = function(a, b) {
return a.date < b.date ? 1 : -1; return a.date < b.date ? 1 : -1;
}; };
$scope.sortArtistFunction = function (a, b) {
$scope.sortArtistFunction = function(a, b) {
return a.artist.toLowerCase() < b.artist.toLowerCase() ? -1 : 1; return a.artist.toLowerCase() < b.artist.toLowerCase() ? -1 : 1;
}; };
$scope.sortAlbumFunction = function (a, b) {
$scope.sortAlbumFunction = function(a, b) {
return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1; return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1;
}; };
$scope.sortTrackFunction = function (a, b) {
$scope.sortTrackFunction = function(a, b) {
return parseInt(a.track) > parseInt(b.track) ? -1 : 1; return parseInt(a.track) > parseInt(b.track) ? -1 : 1;
}; };
$scope.sortSubsonicAlbums = function (newValue) {
$scope.sortSubsonicAlbums = function(newValue) {
if (typeof newValue != 'undefined') { if (typeof newValue != 'undefined') {
//alert(newValue); //alert(newValue);
switch (newValue) { switch (newValue) {
@ -611,8 +547,7 @@
} }
} }
}; };
$scope.sortSubsonicSongs = function (newValue) {
$scope.sortSubsonicSongs = function(newValue) {
if (typeof newValue != 'undefined') { if (typeof newValue != 'undefined') {
//alert(newValue); //alert(newValue);
switch (newValue) { switch (newValue) {
@ -640,4 +575,4 @@
$scope.getAlbums($routeParams.artistId); $scope.getAlbums($routeParams.artistId);
} }
/* End Startup */ /* End Startup */
}); });

View file

@ -1,60 +1,53 @@
JamStash.controller('AppCtrl', JamStash.controller('AppCtrl',
function AppCtrl($scope, $rootScope, $document, $location, $cookieStore, utils, globals, model, notifications, player) { function AppCtrl($scope, $rootScope, $document, $location, $cookieStore, utils, globals, model, notifications, player) {
$rootScope.settings = globals.settings; $rootScope.settings = globals.settings;
$rootScope.song = []; $rootScope.song = [];
$rootScope.queue = []; $rootScope.queue = [];
$rootScope.playingSong = null; $rootScope.playingSong;
$rootScope.MusicFolders = []; $rootScope.MusicFolders = [];
$rootScope.Genres = []; $rootScope.Genres = [];
$rootScope.selectedPlaylist = ""; $rootScope.selectedPlaylist = "";
$rootScope.selectedAutoPlaylist = ""; $rootScope.selectedAutoPlaylist = "";
$rootScope.SelectedMusicFolder = ""; $rootScope.SelectedMusicFolder = "";
$rootScope.unity = null; $rootScope.unity;
$rootScope.loggedIn = function () {
$rootScope.loggedIn = function() { if (globals.settings.Server != '' && globals.settings.Username != '' && globals.settings.Password != '') {
if (globals.settings.Server !== '' && globals.settings.Username !== '' && globals.settings.Password !== '') {
return true; return true;
} else { } else {
return false; return false;
} }
}; }
$rootScope.totalDisplayed = 50; $rootScope.totalDisplayed = 50;
$rootScope.loadMore = function () {
$rootScope.loadMore = function() {
$scope.totalDisplayed += 50; $scope.totalDisplayed += 50;
}; };
/*
$scope.playSong = function (loadonly, data) {
$scope.$apply(function () {
$rootScope.playSong(loadonly, data);
});
}
*/
// Reads cookies and sets globals.settings values // Reads cookies and sets globals.settings values
$scope.loadSettings = function() { $scope.loadSettings = function () {
// Temporary Code to Convert Cookies added 2/2/2014 // Temporary Code to Convert Cookies added 2/2/2014
if ($cookieStore.get('Settings')) { if ($cookieStore.get('Settings')) {
utils.setValue('Settings', $cookieStore.get('Settings'), false); utils.setValue('Settings', $cookieStore.get('Settings'), false);
$cookieStore.remove('Settings'); $cookieStore.remove('Settings');
} }
if (utils.getValue('Settings')) { if (utils.getValue('Settings')) {
$.each(utils.getValue('Settings'), function(k, v) { $.each(utils.getValue('Settings'), function (k, v) {
if (v == 'false') { if (v == 'false') { v = false; }
v = false; if (v == 'true') { v = true; }
}
if (v == 'true') {
v = true;
}
globals.settings[k] = v; globals.settings[k] = v;
}); });
} }
if (utils.getValue("SavedCollections")) { if (utils.getValue("SavedCollections")) { globals.SavedCollections = utils.getValue("SavedCollections").split(","); }
globals.SavedCollections = utils.getValue("SavedCollections").split(","); if (utils.getValue("SavedGenres")) { globals.SavedGenres = utils.getValue("SavedGenres").split(","); }
if (globals.settings.Debug) { console.log('Settings: ' + JSON.stringify(globals.settings, null, 2)); }
} }
if (utils.getValue("SavedGenres")) { $scope.toggleSetting = function (setting) {
globals.SavedGenres = utils.getValue("SavedGenres").split(",");
}
if (globals.settings.Debug) {
console.log('Settings: ' + JSON.stringify(globals.settings, null, 2));
}
};
$scope.toggleSetting = function(setting) {
var id = setting; var id = setting;
if (globals.settings[id]) { if (globals.settings[id]) {
globals.settings[id] = false; globals.settings[id] = false;
@ -62,23 +55,24 @@
globals.settings[id] = true; globals.settings[id] = true;
} }
notifications.updateMessage(setting + ' : ' + globals.settings[id], true); notifications.updateMessage(setting + ' : ' + globals.settings[id], true);
}; }
$.ajaxSetup({ $.ajaxSetup({
'beforeSend': function() { 'beforeSend': function () {
$("#loading").show(); $("#loading").show();
}, },
'complete': function() { 'complete': function () {
$("#loading").hide(); $("#loading").hide();
} }
}); });
$(".coverartfancy").on("click", "a", function() {
$(".coverartfancy").on("click", "a", function () {
$("a.coverartfancy").fancybox({ $("a.coverartfancy").fancybox({
beforeShow: function() { beforeShow: function () {
//this.title = $('#songdetails_artist').html(); //this.title = $('#songdetails_artist').html();
}, },
afterLoad: function() { afterLoad: function () {
//this.inner.prepend( '<h1>1. My custom title</h1>' ); //this.inner.prepend( '<h1>1. My custom title</h1>' );
//this.content = '<h1>2. My custom title</h1>'; //this.content = '<h1>2. My custom title</h1>';
}, },
@ -90,17 +84,15 @@
}); });
var submenu_active = false; var submenu_active = false;
$('div.submenu').mouseenter(function() { $('div.submenu').mouseenter(function () {
submenu_active = true; submenu_active = true;
}); });
$('div.submenu').mouseleave(function () {
$('div.submenu').mouseleave(function() {
submenu_active = false; submenu_active = false;
$('div.submenu').hide(); $('div.submenu').hide();
//setTimeout(function () { if (submenu_active == false) $('div.submenu').stop().fadeOut(); }, 400); //setTimeout(function () { if (submenu_active == false) $('div.submenu').stop().fadeOut(); }, 400);
}); });
$scope.toggleSubmenu = function (menu, pl, pos, margin) {
$scope.toggleSubmenu = function(menu, pl, pos, margin) {
var submenu = $(menu); var submenu = $(menu);
if (submenu.css('display') !== 'none') { if (submenu.css('display') !== 'none') {
submenu.fadeOut(); submenu.fadeOut();
@ -112,53 +104,39 @@
switch (pos) { switch (pos) {
case 'right': case 'right':
//show the menu to the right of placeholder //show the menu to the right of placeholder
submenu.css({ submenu.css({ "left": (off.left + margin) + "px", "top": (off.top) + "px" }).fadeIn(400);
"left": (off.left + margin) + "px",
"top": (off.top) + "px"
}).fadeIn(400);
break; break;
case 'left': case 'left':
//show the menu to the right of placeholder //show the menu to the right of placeholder
submenu.css({ submenu.css({ "left": (off.left - margin) + "px", "top": (off.top) + "px" }).fadeIn(400);
"left": (off.left - margin) + "px",
"top": (off.top) + "px"
}).fadeIn(400);
break; break;
} }
setTimeout(function() { setTimeout(function () { if (submenu_active == false) $('div.submenu').stop().fadeOut(); }, 10000);
if (submenu_active === false) $('div.submenu').stop().fadeOut();
}, 10000);
} }
}; }
$rootScope.showQueue = function () {
$rootScope.showQueue = function() {
var submenu = $('#QueuePreview'); var submenu = $('#QueuePreview');
submenu.fadeIn(400); submenu.fadeIn(400);
var timeout = globals.settings.Timeout; var timeout = globals.settings.Timeout;
setTimeout(function() { setTimeout(function () { submenu.fadeOut(); }, timeout);
submenu.fadeOut(); }
}, timeout); $rootScope.hideQueue = function () {
};
$rootScope.hideQueue = function() {
var submenu = $('#QueuePreview'); var submenu = $('#QueuePreview');
submenu.fadeOut(); submenu.fadeOut();
}; }
$scope.toggleQueue = function () {
$scope.toggleQueue = function() {
var submenu = $('#QueuePreview'); var submenu = $('#QueuePreview');
if (submenu.css('display') == 'none') { if (submenu.css('display') == 'none') {
$rootScope.showQueue(); $rootScope.showQueue();
} else { } else {
$rootScope.hideQueue(); $rootScope.hideQueue();
} }
}; }
$("a.coverartfancy").fancybox({ $("a.coverartfancy").fancybox({
beforeShow: function() { beforeShow: function () {
//this.title = $('#songdetails_artist').html(); //this.title = $('#songdetails_artist').html();
}, },
afterLoad: function() { afterLoad: function () {
//this.inner.prepend( '<h1>1. My custom title</h1>' ); //this.inner.prepend( '<h1>1. My custom title</h1>' );
//this.content = '<h1>2. My custom title</h1>'; //this.content = '<h1>2. My custom title</h1>';
}, },
@ -173,20 +151,14 @@
closeEffect: 'none' closeEffect: 'none'
}); });
$('#audiocontainer .scrubber').mouseover(function(e) { $('#audiocontainer .scrubber').mouseover(function (e) {
$('.audiojs .scrubber').stop().animate({ $('.audiojs .scrubber').stop().animate({ height: '8px' });
height: '8px'
});
});
$('#audiocontainer .scrubber').mouseout(function(e) {
$('.audiojs .scrubber').stop().animate({
height: '4px'
}); });
$('#audiocontainer .scrubber').mouseout(function (e) {
$('.audiojs .scrubber').stop().animate({ height: '4px' });
}); });
$('.message').on('click', function() { $('.message').on('click', function () { $(this).remove(); });
$(this).remove();
});
// Sway.fm Unity Plugin // Sway.fm Unity Plugin
$rootScope.unity = UnityMusicShim(); $rootScope.unity = UnityMusicShim();
@ -195,60 +167,68 @@
next: true, next: true,
previous: true previous: true
}); });
$rootScope.unity.setCallbackObject({ $rootScope.unity.setCallbackObject({
pause: function() { pause: function () {
if (globals.settings.Debug) { if (globals.settings.Debug) { console.log("Unity: Recieved playpause command"); }
console.log("Unity: Recieved playpause command");
}
player.playPauseSong(); player.playPauseSong();
}, },
next: function() { next: function () {
if (globals.settings.Debug) { if (globals.settings.Debug) { console.log("Unity: Recieved next command"); }
console.log("Unity: Recieved next command");
}
$rootScope.nextTrack(); $rootScope.nextTrack();
}, },
previous: function() { previous: function () {
if (globals.settings.Debug) { if (globals.settings.Debug) { console.log("Unity: Recieved previous command"); }
console.log("Unity: Recieved previous command");
}
$rootScope.previousTrack(); $rootScope.previousTrack();
} }
}); });
// JQuery UI Sortable - Drag and drop sorting
/*
var fixHelper = function (e, ui) {
ui.children().each(function () {
$(this).width($(this).width());
});
return ui;
};
$("#QueuePreview ul.songlist").sortable({
helper: fixHelper
});
*/
/* JQuery Layout Plugin - I don't think this is used anywhere
function resizePageLayout() {
var pageLayout = $("body").data("layout");
if (pageLayout) pageLayout.resizeAll();
};
*/
// Global Functions // Global Functions
window.onbeforeunload = function() { window.onbeforeunload = function () {
if (!globals.settings.Debug) { if (!globals.settings.Debug) {
if ($rootScope.queue.length > 0) { if ($rootScope.queue.length > 0) {
return "You're about to end your session, are you sure?"; return "You're about to end your session, are you sure?";
} }
} }
}; }
$scope.dragStart = function(e, ui) { $scope.dragStart = function (e, ui) {
ui.item.data('start', ui.item.index()); ui.item.data('start', ui.item.index());
}; }
$scope.dragEnd = function (e, ui) {
$scope.dragEnd = function(e, ui) {
var start = ui.item.data('start'), var start = ui.item.data('start'),
end = ui.item.index(); end = ui.item.index();
$rootScope.queue.splice(end, 0, $rootScope.queue.splice(end, 0,
$rootScope.queue.splice(start, 1)[0]); $rootScope.queue.splice(start, 1)[0]);
$scope.$apply(); $scope.$apply();
}; }
$document.keydown(function (e) {
$document.keydown(function(e) {
$scope.scrollToIndex(e); $scope.scrollToIndex(e);
}); });
$scope.scrollToIndex = function (e) {
$scope.scrollToIndex = function(e) {
var source = e.target.id; var source = e.target.id;
if (source != 'Search' && source != 'Source' && source != 'Description' && source != 'ChatMsg' && source != 'AutoPlaylists') { if (source != 'Search' && source != 'Source' && source != 'Description' && source != 'ChatMsg' && source != 'AutoPlaylists') {
var unicode = e.charCode ? e.charCode : e.keyCode; var unicode = e.charCode ? e.charCode : e.keyCode;
if (globals.settings.Debug) { if (globals.settings.Debug) { console.log('Keycode Triggered: ' + unicode); }
console.log('Keycode Triggered: ' + unicode);
}
/* /*
if (unicode == 49) { if (unicode == 49) {
utils.changeTab('tabQueue'); utils.changeTab('tabQueue');
@ -283,13 +263,10 @@
} else if (unicode == 36 && $('#tabLibrary').is(':visible')) { // home } else if (unicode == 36 && $('#tabLibrary').is(':visible')) { // home
$('#left-component').stop().scrollTo('#MusicFolders', 400); $('#left-component').stop().scrollTo('#MusicFolders', 400);
} }
var volume;
if (unicode == 189) { // dash - volume down if (unicode == 189) { // dash - volume down
volume = utils.getValue('Volume') ? parseFloat(utils.getValue('Volume')) : 1; var volume = utils.getValue('Volume') ? parseFloat(utils.getValue('Volume')) : 1;
if (volume <= 1 && volume > 0 && source === '') { if (volume <= 1 && volume > 0 && source == '') {
volume += -0.1; volume += -.1;
$(player1).jPlayer({ $(player1).jPlayer({
volume: volume volume: volume
}); });
@ -297,11 +274,10 @@
//updateMessage('Volume: ' + Math.round(volume * 100) + '%'); //updateMessage('Volume: ' + Math.round(volume * 100) + '%');
} }
} }
if (unicode == 187) { // equals - volume up if (unicode == 187) { // equals - volume up
volume = utils.getValue('Volume') ? parseFloat(utils.getValue('Volume')) : 1; var volume = utils.getValue('Volume') ? parseFloat(utils.getValue('Volume')) : 1;
if (volume < 1 && volume >= 0 && source === '') { if (volume < 1 && volume >= 0 && source == '') {
volume += 0.1; volume += .1;
$(player1).jPlayer({ $(player1).jPlayer({
volume: volume volume: volume
}); });
@ -312,43 +288,37 @@
} }
return true; return true;
}; };
$scope.scrollToIndexName = function (index) {
$scope.scrollToIndexName = function(index) {
var el = '#' + index; var el = '#' + index;
if ($(el).length > 0) { if ($(el).length > 0) {
$('#left-component').stop().scrollTo(el, 400); $('#left-component').stop().scrollTo(el, 400);
} }
}; };
$scope.scrollToTop = function () {
$scope.scrollToTop = function() {
$('#Artists').stop().scrollTo('#auto', 400); $('#Artists').stop().scrollTo('#auto', 400);
}; }
$scope.selectAll = function () {
$scope.selectAll = function() { angular.forEach($rootScope.song, function (item, key) {
angular.forEach($rootScope.song, function(item, key) {
$scope.selectedSongs.push(item); $scope.selectedSongs.push(item);
item.selected = true; item.selected = true;
}); });
}; }
$scope.playAll = function () {
$scope.playAll = function() {
$rootScope.queue = []; $rootScope.queue = [];
$scope.selectAll(); $scope.selectAll();
$scope.addSongsToQueue(); $scope.addSongsToQueue();
var next = $rootScope.queue[0]; var next = $rootScope.queue[0];
$rootScope.playSong(false, next); $rootScope.playSong(false, next);
}; }
$scope.selectNone = function () {
$scope.selectNone = function() { angular.forEach($rootScope.song, function (item, key) {
angular.forEach($rootScope.song, function(item, key) {
$scope.selectedSongs = []; $scope.selectedSongs = [];
item.selected = false; item.selected = false;
}); });
}; }
$scope.addSongsToQueue = function () {
$scope.addSongsToQueue = function() {
if ($scope.selectedSongs.length !== 0) { if ($scope.selectedSongs.length !== 0) {
angular.forEach($scope.selectedSongs, function(item, key) { angular.forEach($scope.selectedSongs, function (item, key) {
$scope.queue.push(item); $scope.queue.push(item);
item.selected = false; item.selected = false;
}); });
@ -356,19 +326,17 @@
notifications.updateMessage($scope.selectedSongs.length + ' Song(s) Added to Queue', true); notifications.updateMessage($scope.selectedSongs.length + ' Song(s) Added to Queue', true);
$scope.selectedSongs.length = 0; $scope.selectedSongs.length = 0;
} }
}; }
$scope.isActive = function (route) {
$scope.isActive = function(route) {
return route === $location.path(); return route === $location.path();
}; };
$scope.getMusicFolders = function () {
$scope.getMusicFolders = function() {
$.ajax({ $.ajax({
url: globals.BaseURL() + '/getMusicFolders.view?' + globals.BaseParams(), url: globals.BaseURL() + '/getMusicFolders.view?' + globals.BaseParams(),
method: 'GET', method: 'GET',
dataType: globals.settings.Protocol, dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout, timeout: globals.settings.Timeout,
success: function(data) { success: function (data) {
if (data["subsonic-response"].musicFolders.musicFolder !== undefined) { if (data["subsonic-response"].musicFolders.musicFolder !== undefined) {
var folders = []; var folders = [];
if (data["subsonic-response"].musicFolders.musicFolder.length > 0) { if (data["subsonic-response"].musicFolders.musicFolder.length > 0) {
@ -380,9 +348,8 @@
$rootScope.MusicFolders = folders; $rootScope.MusicFolders = folders;
if (utils.getValue('MusicFolders')) { if (utils.getValue('MusicFolders')) {
var folder = angular.fromJson(utils.getValue('MusicFolders')); var folder = angular.fromJson(utils.getValue('MusicFolders'));
var i = 0, var i = 0, index = "";
index = ""; angular.forEach($rootScope.MusicFolders, function (item, key) {
angular.forEach($rootScope.MusicFolders, function(item, key) {
if (item.id == folder.id) { if (item.id == folder.id) {
index = i; index = i;
} }
@ -394,25 +361,43 @@
} }
} }
}); });
}; }
$scope.getGenres = function () {
$scope.getGenres = function() {
var genres = 'Acid Rock,Acoustic,Alt Country,Alt/Indie,Alternative & Punk,Alternative Metal,Alternative,AlternRock,Awesome,Bluegrass,Blues,Blues-Rock,Classic Hard Rock,Classic Rock,Comedy,Country,Country-Rock,Dance,Dance-Rock,Deep Funk,Easy Listening,Electronic,Electronica,Electronica/Dance,Folk,Folk/Rock,Funk,Grunge,Hard Rock,Heavy Metal,Holiday,House,Improg,Indie Rock,Indie,International,Irish,Jam Band,Jam,Jazz Fusion,Jazz,Latin,Live Albums,Metal,Music,Oldies,Other,Pop,Pop/Rock,Post Rock,Progressive Rock,Psychedelic Rock,Psychedelic,Punk,R&B,Rap & Hip-Hop,Reggae,Rock & Roll,Rock,Rock/Pop,Roots,Ska,Soft Rock,Soul,Southern Rock,Thrash Metal,Unknown,Vocal,World'; var genres = 'Acid Rock,Acoustic,Alt Country,Alt/Indie,Alternative & Punk,Alternative Metal,Alternative,AlternRock,Awesome,Bluegrass,Blues,Blues-Rock,Classic Hard Rock,Classic Rock,Comedy,Country,Country-Rock,Dance,Dance-Rock,Deep Funk,Easy Listening,Electronic,Electronica,Electronica/Dance,Folk,Folk/Rock,Funk,Grunge,Hard Rock,Heavy Metal,Holiday,House,Improg,Indie Rock,Indie,International,Irish,Jam Band,Jam,Jazz Fusion,Jazz,Latin,Live Albums,Metal,Music,Oldies,Other,Pop,Pop/Rock,Post Rock,Progressive Rock,Psychedelic Rock,Psychedelic,Punk,R&B,Rap & Hip-Hop,Reggae,Rock & Roll,Rock,Rock/Pop,Roots,Ska,Soft Rock,Soul,Southern Rock,Thrash Metal,Unknown,Vocal,World';
$rootScope.Genres = genres.split(','); $rootScope.Genres = genres.split(',');
// TODO: fix this /* This is broken in version 4.8, unable to convert XML to JSON
}; $.ajax({
url: globals.BaseURL() + '/getGenres.view?' + globals.BaseParams(),
method: 'GET',
dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout,
success: function (data) {
if (typeof data["subsonic-response"].genres != 'undefined') {
var items = [];
if (data["subsonic-response"].genres.length > 0) {
items = data["subsonic-response"].genres;
} else {
items[0] = data["subsonic-response"].genres;
}
$scope.download = function(id) { $rootScope.Genres = items;
$scope.$apply();
}
}
});
*/
}
$scope.download = function (id) {
$.ajax({ $.ajax({
url: globals.BaseURL() + '/getUser.view?' + globals.BaseParams() + '&username=' + globals.settings.Username, url: globals.BaseURL() + '/getUser.view?' + globals.BaseParams() + '&username=' + globals.settings.Username,
method: 'GET', method: 'GET',
dataType: globals.settings.Protocol, dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout, timeout: globals.settings.Timeout,
success: function(data) { success: function (data) {
if (typeof data["subsonic-response"].error != 'undefined') { if (typeof data["subsonic-response"].error != 'undefined') {
notifications.updateMessage('Error: ' + data["subsonic-response"].error.message, true); notifications.updateMessage('Error: ' + data["subsonic-response"].error.message, true);
} else { } else {
if (data["subsonic-response"].user.downloadRole === true) { if (data["subsonic-response"].user.downloadRole == true) {
$window.location.href = globals.BaseURL() + '/download.view?' + globals.BaseParams() + '&id=' + id; $window.location.href = globals.BaseURL() + '/download.view?' + globals.BaseParams() + '&id=' + id;
} else { } else {
notifications.updateMessage('You do not have permission to Download', true); notifications.updateMessage('You do not have permission to Download', true);
@ -420,15 +405,14 @@
} }
} }
}); });
}; }
$scope.ping = function () {
$scope.ping = function() {
$.ajax({ $.ajax({
url: globals.BaseURL() + '/ping.view?' + globals.BaseParams(), url: globals.BaseURL() + '/ping.view?' + globals.BaseParams(),
method: 'GET', method: 'GET',
dataType: globals.settings.Protocol, dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout, timeout: globals.settings.Timeout,
success: function(data) { success: function (data) {
if (data["subsonic-response"].status == 'ok') { if (data["subsonic-response"].status == 'ok') {
globals.settings.ApiVersion = data["subsonic-response"].version; globals.settings.ApiVersion = data["subsonic-response"].version;
} else { } else {
@ -437,33 +421,29 @@
} }
} }
}, },
error: function() { error: function () {
notifications.updateMessage('Unable to connect to Subsonic server'); notifications.updateMessage('Unable to connect to Subsonic server');
} }
}); });
}; }
$scope.addSongToQueue = function (data) {
$scope.addSongToQueue = function(data) {
$rootScope.queue.push(data); $rootScope.queue.push(data);
}; }
$scope.queueRemoveSelected = function (data, event) {
$scope.queueRemoveSelected = function(data, event) { angular.forEach($scope.selectedSongs, function (item, key) {
angular.forEach($scope.selectedSongs, function(item, key) {
var index = $rootScope.queue.indexOf(item); var index = $rootScope.queue.indexOf(item);
if (index > -1) { if (index > -1) {
$rootScope.queue.splice(index, 1); $rootScope.queue.splice(index, 1);
} }
}); });
}; }
$scope.queueEmpty = function () {
$scope.queueEmpty = function() {
//self.selectedSongs([]); //self.selectedSongs([]);
$rootScope.queue = []; $rootScope.queue = [];
}; }
$scope.queueTotal = function () {
$scope.queueTotal = function() {
var total = 0; var total = 0;
ko.utils.arrayForEach(self.queue(), function(item) { ko.utils.arrayForEach(self.queue(), function (item) {
total += parseInt(item.duration()); total += parseInt(item.duration());
}); });
if (self.queue().length > 0) { if (self.queue().length > 0) {
@ -471,16 +451,12 @@
} else { } else {
return '0 song(s), 00:00:00 total time'; return '0 song(s), 00:00:00 total time';
} }
}; }
$scope.queueShuffle = function () {
$scope.queueShuffle = function() { $rootScope.queue.sort(function () { return 0.5 - Math.random() });
$rootScope.queue.sort(function() { }
return 0.5 - Math.random();
});
};
$scope.selectedSongs = []; $scope.selectedSongs = [];
$scope.selectSong = function(data) { $scope.selectSong = function (data) {
var i = $scope.selectedSongs.indexOf(data); var i = $scope.selectedSongs.indexOf(data);
if (i >= 0) { if (i >= 0) {
$scope.selectedSongs.splice(i, 1); $scope.selectedSongs.splice(i, 1);
@ -490,44 +466,36 @@
data.selected = true; data.selected = true;
} }
//$scope.$apply(); //$scope.$apply();
};
$rootScope.getRandomSongs = function(action, genre, folder) {
if (globals.settings.Debug) {
console.log('action:' + action + ', genre:' + genre + ', folder:' + folder);
} }
$rootScope.getRandomSongs = function (action, genre, folder) {
if (globals.settings.Debug) { console.log('action:' + action + ', genre:' + genre + ', folder:' + folder); }
var size = globals.settings.AutoPlaylistSize; var size = globals.settings.AutoPlaylistSize;
$rootScope.selectedPlaylist = null; $rootScope.selectedPlaylist = null;
if (typeof folder == 'number') { if (typeof folder == 'number') {
$rootScope.selectedAutoPlaylist = folder; $rootScope.selectedAutoPlaylist = folder;
} else if (genre !== '') { } else if (genre != '') {
$rootScope.selectedAutoPlaylist = genre; $rootScope.selectedAutoPlaylist = genre;
} else { } else {
$rootScope.selectedAutoPlaylist = 'random'; $rootScope.selectedAutoPlaylist = 'random';
} }
var genreParams = ''; var genreParams = '';
if (genre != '' && genre != 'Random') {
if (genre !== '' && genre != 'Random') {
genreParams = '&genre=' + genre; genreParams = '&genre=' + genre;
} }
folderParams = ''; folderParams = '';
if (typeof folder == 'number' && folder != '' && folder != 'all') {
if (typeof folder == 'number' && folder !== '' && folder != 'all') {
//alert(folder); //alert(folder);
folderParams = '&musicFolderId=' + folder; folderParams = '&musicFolderId=' + folder;
} else if (typeof $rootScope.SelectedMusicFolder.id != 'undefined') { } else if (typeof $rootScope.SelectedMusicFolder.id != 'undefined') {
//alert($rootScope.SelectedMusicFolder.id); //alert($rootScope.SelectedMusicFolder.id);
folderParams = '&musicFolderId=' + $rootScope.SelectedMusicFolder.id; folderParams = '&musicFolderId=' + $rootScope.SelectedMusicFolder.id;
} }
$.ajax({ $.ajax({
url: globals.BaseURL() + '/getRandomSongs.view?' + globals.BaseParams() + '&size=' + size + genreParams + folderParams, url: globals.BaseURL() + '/getRandomSongs.view?' + globals.BaseParams() + '&size=' + size + genreParams + folderParams,
method: 'GET', method: 'GET',
dataType: globals.settings.Protocol, dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout, timeout: globals.settings.Timeout,
success: function(data) { success: function (data) {
if (typeof data["subsonic-response"].randomSongs.song != 'undefined') { if (typeof data["subsonic-response"].randomSongs.song != 'undefined') {
var items = []; var items = [];
if (data["subsonic-response"].randomSongs.song.length > 0) { if (data["subsonic-response"].randomSongs.song.length > 0) {
@ -536,7 +504,7 @@
items[0] = data["subsonic-response"].randomSongs.song; items[0] = data["subsonic-response"].randomSongs.song;
} }
if (action == 'add') { if (action == 'add') {
angular.forEach(items, function(item, key) { angular.forEach(items, function (item, key) {
$rootScope.queue.push(utils.mapSong(item)); $rootScope.queue.push(utils.mapSong(item));
}); });
$scope.$apply(); $scope.$apply();
@ -544,18 +512,18 @@
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true); notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else if (action == 'play') { } else if (action == 'play') {
$rootScope.queue = []; $rootScope.queue = [];
angular.forEach(items, function(item, key) { angular.forEach(items, function (item, key) {
$rootScope.queue.push(utils.mapSong(item)); $rootScope.queue.push(utils.mapSong(item));
}); });
var next = $rootScope.queue[0]; var next = $rootScope.queue[0];
$scope.$apply(function() { $scope.$apply(function () {
$rootScope.playSong(false, next); $rootScope.playSong(false, next);
}); });
$rootScope.showQueue(); $rootScope.showQueue();
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true); notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else { } else {
$rootScope.song = []; $rootScope.song = [];
angular.forEach(items, function(item, key) { angular.forEach(items, function (item, key) {
$rootScope.song.push(utils.mapSong(item)); $rootScope.song.push(utils.mapSong(item));
}); });
$scope.$apply(); $scope.$apply();
@ -563,9 +531,8 @@
} }
} }
}); });
}; }
$scope.updateFavorite = function (item) {
$scope.updateFavorite = function(item) {
var id = item.id; var id = item.id;
var starred = item.starred; var starred = item.starred;
var url; var url;
@ -581,15 +548,14 @@
method: 'GET', method: 'GET',
dataType: globals.settings.Protocol, dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout, timeout: globals.settings.Timeout,
success: function() { success: function () {
notifications.updateMessage('Favorite Updated!', true); notifications.updateMessage('Favorite Updated!', true);
} }
}); });
}; }
$scope.toTrusted = function (html) {
$scope.toTrusted = function(html) {
return $sce.trustAsHtml(html); return $sce.trustAsHtml(html);
}; }
/* Launch on Startup */ /* Launch on Startup */
$scope.loadSettings(); $scope.loadSettings();
@ -603,4 +569,4 @@
} }
} }
/* End Startup */ /* End Startup */
}); });

View file

@ -1,31 +1,28 @@
JamStash.controller('PlaylistCtrl', JamStash.controller('PlaylistCtrl',
function PlaylistCtrl($scope, $rootScope, $location, utils, globals, model, notifications) { function PlaylistCtrl($scope, $rootScope, $location, utils, globals, model, notifications) {
//$("#left-component").layout($scope.layoutTwoCol);
$rootScope.song = []; $rootScope.song = [];
$scope.itemType = 'pl'; $scope.itemType = 'pl';
$scope.playlists = []; $scope.playlists = [];
$scope.playlistsPublic = []; $scope.playlistsPublic = [];
$scope.playlistsGenre = globals.SavedGenres; $scope.playlistsGenre = globals.SavedGenres;
$scope.selectedGenre = null; $scope.selectedGenre;
$scope.$watch("selectedGenre", function (newValue, oldValue) {
$scope.$watch("selectedGenre", function(newValue, oldValue) {
if (newValue !== oldValue) { if (newValue !== oldValue) {
globals.SavedGenres.push(newValue); globals.SavedGenres.push(newValue);
//$scope.playlistsGenre.push(); //$scope.playlistsGenre.push();
utils.setValue('SavedGenres', globals.SavedGenres.join(), false); utils.setValue('SavedGenres', globals.SavedGenres.join(), false);
} }
}); });
$scope.getPlaylists = function (refresh) {
$scope.getPlaylists = function(refresh) { if (globals.settings.Debug) { console.log("LOAD PLAYLISTS"); }
if (globals.settings.Debug) {
console.log("LOAD PLAYLISTS");
}
$.ajax({ $.ajax({
url: globals.BaseURL() + '/getPlaylists.view?' + globals.BaseParams(), url: globals.BaseURL() + '/getPlaylists.view?' + globals.BaseParams(),
method: 'GET', method: 'GET',
dataType: globals.settings.Protocol, dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout, timeout: globals.settings.Timeout,
success: function(data) { success: function (data) {
if (data["subsonic-response"].playlists.playlist !== undefined) { if (data["subsonic-response"].playlists.playlist !== undefined) {
var items = []; var items = [];
if (data["subsonic-response"].playlists.playlist.length > 0) { if (data["subsonic-response"].playlists.playlist.length > 0) {
@ -33,7 +30,7 @@
} else { } else {
items[0] = data["subsonic-response"].playlists.playlist; items[0] = data["subsonic-response"].playlists.playlist;
} }
angular.forEach(items, function(item, key) { angular.forEach(items, function (item, key) {
if (item.owner == globals.settings.Username) { if (item.owner == globals.settings.Username) {
$scope.playlists.push(item); $scope.playlists.push(item);
} else if (item.public) { } else if (item.public) {
@ -44,9 +41,8 @@
} }
} }
}); });
}; }
$scope.getPlaylist = function (id, action) {
$scope.getPlaylist = function(id, action) {
$rootScope.selectedAutoPlaylist = null; $rootScope.selectedAutoPlaylist = null;
$rootScope.selectedPlaylist = id; $rootScope.selectedPlaylist = id;
$.ajax({ $.ajax({
@ -54,7 +50,7 @@
method: 'GET', method: 'GET',
dataType: globals.settings.Protocol, dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout, timeout: globals.settings.Timeout,
success: function(data) { success: function (data) {
if (typeof data["subsonic-response"].playlist.entry != 'undefined') { if (typeof data["subsonic-response"].playlist.entry != 'undefined') {
var items = []; var items = [];
var playlist = data["subsonic-response"].playlist; var playlist = data["subsonic-response"].playlist;
@ -64,7 +60,7 @@
items[0] = playlist.entry; items[0] = playlist.entry;
} }
if (action == 'add') { if (action == 'add') {
angular.forEach(items, function(item, key) { angular.forEach(items, function (item, key) {
$rootScope.queue.push(utils.mapSong(item)); $rootScope.queue.push(utils.mapSong(item));
}); });
$scope.$apply(); $scope.$apply();
@ -72,11 +68,11 @@
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true); notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else if (action == 'play') { } else if (action == 'play') {
$rootScope.queue = []; $rootScope.queue = [];
angular.forEach(items, function(item, key) { angular.forEach(items, function (item, key) {
$rootScope.queue.push(utils.mapSong(item)); $rootScope.queue.push(utils.mapSong(item));
}); });
var next = $rootScope.queue[0]; var next = $rootScope.queue[0];
$scope.$apply(function() { $scope.$apply(function () {
$rootScope.playSong(false, next); $rootScope.playSong(false, next);
}); });
$rootScope.showQueue(); $rootScope.showQueue();
@ -84,7 +80,7 @@
} else { } else {
$scope.album = []; $scope.album = [];
$rootScope.song = []; $rootScope.song = [];
angular.forEach(items, function(item, key) { angular.forEach(items, function (item, key) {
$rootScope.song.push(utils.mapSong(item)); $rootScope.song.push(utils.mapSong(item));
}); });
$scope.$apply(); $scope.$apply();
@ -94,9 +90,8 @@
} }
} }
}); });
}; }
$scope.getStarred = function (action, type) {
$scope.getStarred = function(action, type) {
var size = globals.settings.AutoPlaylistSize; var size = globals.settings.AutoPlaylistSize;
$rootScope.selectedPlaylist = null; $rootScope.selectedPlaylist = null;
$rootScope.selectedAutoPlaylist = 'starred'; $rootScope.selectedAutoPlaylist = 'starred';
@ -105,7 +100,7 @@
method: 'GET', method: 'GET',
dataType: globals.settings.Protocol, dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout, timeout: globals.settings.Timeout,
success: function(data) { success: function (data) {
if (typeof data["subsonic-response"].starred !== 'undefined') { if (typeof data["subsonic-response"].starred !== 'undefined') {
var items = []; var items = [];
switch (type) { switch (type) {
@ -135,7 +130,7 @@
items[0] = data["subsonic-response"].starred.song; items[0] = data["subsonic-response"].starred.song;
} }
if (action == 'add') { if (action == 'add') {
angular.forEach(items, function(item, key) { angular.forEach(items, function (item, key) {
$rootScope.queue.push(utils.mapSong(item)); $rootScope.queue.push(utils.mapSong(item));
}); });
$scope.$apply(); $scope.$apply();
@ -143,18 +138,18 @@
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true); notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else if (action == 'play') { } else if (action == 'play') {
$rootScope.queue = []; $rootScope.queue = [];
angular.forEach(items, function(item, key) { angular.forEach(items, function (item, key) {
$rootScope.queue.push(utils.mapSong(item)); $rootScope.queue.push(utils.mapSong(item));
}); });
var next = $rootScope.queue[0]; var next = $rootScope.queue[0];
$scope.$apply(function() { $scope.$apply(function () {
$rootScope.playSong(false, next); $rootScope.playSong(false, next);
}); });
$rootScope.showQueue(); $rootScope.showQueue();
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true); notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else { } else {
$rootScope.song = []; $rootScope.song = [];
angular.forEach(items, function(item, key) { angular.forEach(items, function (item, key) {
$rootScope.song.push(utils.mapSong(item)); $rootScope.song.push(utils.mapSong(item));
}); });
$scope.$apply(); $scope.$apply();
@ -167,25 +162,23 @@
} }
} }
}); });
}; }
$scope.newPlaylist = function (data, event) {
$scope.newPlaylist = function(data, event) {
var reply = prompt("Choose a name for your new playlist.", ""); var reply = prompt("Choose a name for your new playlist.", "");
if (reply !== 'null' && reply !== null && reply !== '') { if (reply != 'null' && reply != null && reply != '') {
$.ajax({ $.ajax({
url: globals.BaseURL() + '/createPlaylist.view?' + globals.BaseParams() + '&name=' + reply, url: globals.BaseURL() + '/createPlaylist.view?' + globals.BaseParams() + '&name=' + reply,
method: 'GET', method: 'GET',
dataType: globals.settings.Protocol, dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout, timeout: globals.settings.Timeout,
success: function(data) { success: function (data) {
loadPlaylists(true); loadPlaylists(true);
} }
}); });
} }
}; }
$scope.deletePlaylist = function () {
$scope.deletePlaylist = function() { if ($rootScope.selectedPlaylist != null) {
if ($rootScope.selectedPlaylist !== null) {
var id = $rootScope.selectedPlaylist; var id = $rootScope.selectedPlaylist;
if (utils.confirmDelete('Are you sure you want to delete the selected playlist?')) { if (utils.confirmDelete('Are you sure you want to delete the selected playlist?')) {
$.ajax({ $.ajax({
@ -193,19 +186,18 @@
method: 'GET', method: 'GET',
dataType: globals.settings.Protocol, dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout, timeout: globals.settings.Timeout,
success: function(data) { success: function (data) {
$scope.getPlaylists(); $scope.getPlaylists();
} }
}); });
} }
} }
}; }
$scope.savePlaylist = function () {
$scope.savePlaylist = function() { if ($rootScope.selectedPlaylist() != null) {
if ($rootScope.selectedPlaylist() !== null) {
var id = $rootScope.selectedPlaylist().id(); var id = $rootScope.selectedPlaylist().id();
var songs = []; var songs = [];
ko.utils.arrayForEach($rootScope.song(), function(item) { ko.utils.arrayForEach($rootScope.song(), function (item) {
songs.push(item.id); songs.push(item.id);
}); });
if (songs.length > 0) { if (songs.length > 0) {
@ -214,11 +206,8 @@
url: globals.BaseURL() + '/createPlaylist.view?' + globals.BaseParams(), url: globals.BaseURL() + '/createPlaylist.view?' + globals.BaseParams(),
dataType: globals.settings.Protocol, dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout, timeout: globals.settings.Timeout,
data: { data: { playlistId: id, songId: songs },
playlistId: id, success: function () {
songId: songs
},
success: function() {
$scope.getPlaylist(id); $scope.getPlaylist(id);
notifications.updateMessage('Playlist Updated!', true); notifications.updateMessage('Playlist Updated!', true);
}, },
@ -226,14 +215,12 @@
}); });
} }
} }
}; }
$scope.removeSelectedSongs = function (data, event) {
$scope.removeSelectedSongs = function(data, event) { ko.utils.arrayForEach($scope.selectedSongs(), function (item) {
ko.utils.arrayForEach($scope.selectedSongs(), function(item) {
$rootScope.song.remove(item); $rootScope.song.remove(item);
}); });
}; }
/* End Playlists */ /* End Playlists */
/* Launch on Startup */ /* Launch on Startup */
@ -241,4 +228,4 @@
//$scope.getMusicFolders(); //$scope.getMusicFolders();
$scope.getGenres(); $scope.getGenres();
/* End Startup */ /* End Startup */
}); });

View file

@ -1,20 +1,18 @@
JamStash.controller('PodcastCtrl', JamStash.controller('PodcastCtrl',
function PodcastCtrl($scope, $rootScope, $location, utils, globals, model, notifications) { function PodcastCtrl($scope, $rootScope, $location, utils, globals, model, notifications) {
//$("#left-component").layout($scope.layoutTwoCol);
$rootScope.song = []; $rootScope.song = [];
$scope.podcasts = []; $scope.podcasts = [];
$scope.selectedPodcast = null; $scope.selectedPodcast;
$scope.getPodcasts = function (refresh) {
$scope.getPodcasts = function(refresh) { if (globals.settings.Debug) { console.log("LOAD PODCASTS"); }
if (globals.settings.Debug) {
console.log("LOAD PODCASTS");
}
$.ajax({ $.ajax({
url: globals.BaseURL() + '/getPodcasts.view?' + globals.BaseParams(), url: globals.BaseURL() + '/getPodcasts.view?' + globals.BaseParams(),
method: 'GET', method: 'GET',
dataType: globals.settings.Protocol, dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout, timeout: globals.settings.Timeout,
success: function(data) { success: function (data) {
if (data["subsonic-response"].podcasts.channel !== undefined) { if (data["subsonic-response"].podcasts.channel !== undefined) {
var items = []; var items = [];
if (data["subsonic-response"].podcasts.channel.length > 0) { if (data["subsonic-response"].podcasts.channel.length > 0) {
@ -27,62 +25,34 @@
} }
} }
}); });
}; }
$scope.getPodcast = function (id, action) {
$scope.getPodcast = function(id, action) {
$scope.selectedPodcast = id; $scope.selectedPodcast = id;
var map = function(data) { var map = function (data) {
var song = data; var song = data;
var url, track, rating, starred, contenttype, suffix, description; var url, track, rating, starred, contenttype, suffix, description;
var specs = '', var specs = '', coverartthumb = '', coverartfull = '';
coverartthumb = '',
coverartfull = '';
if (typeof song.coverArt != 'undefined') { if (typeof song.coverArt != 'undefined') {
coverartthumb = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&size=60&id=' + song.coverArt; coverartthumb = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&size=60&id=' + song.coverArt;
coverartfull = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&id=' + song.coverArt; coverartfull = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&id=' + song.coverArt;
} }
if (typeof song.description == 'undefined') { if (typeof song.description == 'undefined') { description = ''; } else { description = song.description; }
description = ''; if (typeof song.track == 'undefined') { track = '&nbsp;'; } else { track = song.track; }
} else { if (typeof song.starred !== 'undefined') { starred = true; } else { starred = false; }
description = song.description; if (song.bitRate !== undefined) { specs += song.bitRate + ' Kbps'; }
} if (song.transcodedSuffix !== undefined) { specs += ', transcoding:' + song.suffix + ' > ' + song.transcodedSuffix; } else { specs += ', ' + song.suffix; }
if (typeof song.track == 'undefined') { if (song.transcodedSuffix !== undefined) { suffix = song.transcodedSuffix; } else { suffix = song.suffix; }
track = '&nbsp;'; if (suffix == 'ogg') { suffix = 'oga'; }
} else {
track = song.track;
}
if (typeof song.starred !== 'undefined') {
starred = true;
} else {
starred = false;
}
if (song.bitRate !== undefined) {
specs += song.bitRate + ' Kbps';
}
if (song.transcodedSuffix !== undefined) {
specs += ', transcoding:' + song.suffix + ' > ' + song.transcodedSuffix;
} else {
specs += ', ' + song.suffix;
}
if (song.transcodedSuffix !== undefined) {
suffix = song.transcodedSuffix;
} else {
suffix = song.suffix;
}
if (suffix == 'ogg') {
suffix = 'oga';
}
var salt = Math.floor(Math.random() * 100000); var salt = Math.floor(Math.random() * 100000);
url = globals.BaseURL() + '/stream.view?' + globals.BaseParams() + '&id=' + song.streamId + '&salt=' + salt; url = globals.BaseURL() + '/stream.view?' + globals.BaseParams() + '&id=' + song.streamId + '&salt=' + salt;
return new model.Song(song.streamId, song.parent, track, song.title, song.artist, song.artistId, song.album, song.albumId, coverartthumb, coverartfull, song.duration, song.userRating, starred, suffix, specs, url, 0, description); return new model.Song(song.streamId, song.parent, track, song.title, song.artist, song.artistId, song.album, song.albumId, coverartthumb, coverartfull, song.duration, song.userRating, starred, suffix, specs, url, 0, description);
}; }
$.ajax({ $.ajax({
url: globals.BaseURL() + '/getPodcasts.view?' + globals.BaseParams(), url: globals.BaseURL() + '/getPodcasts.view?' + globals.BaseParams(),
method: 'GET', method: 'GET',
dataType: globals.settings.Protocol, dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout, timeout: globals.settings.Timeout,
success: function(data) { success: function (data) {
if (data["subsonic-response"].podcasts.channel !== undefined) { if (data["subsonic-response"].podcasts.channel !== undefined) {
var podcasts = []; var podcasts = [];
if (data["subsonic-response"].podcasts.channel.length > 0) { if (data["subsonic-response"].podcasts.channel.length > 0) {
@ -91,7 +61,7 @@
podcasts[0] = data["subsonic-response"].podcasts.channel; podcasts[0] = data["subsonic-response"].podcasts.channel;
} }
var items = []; var items = [];
$.each(podcasts, function(i, item) { $.each(podcasts, function (i, item) {
if (item.id == id) { if (item.id == id) {
items = item.episode; items = item.episode;
} }
@ -99,7 +69,7 @@
if (typeof items != 'undefined') { if (typeof items != 'undefined') {
if (action == 'add') { if (action == 'add') {
angular.forEach(items, function(item, key) { angular.forEach(items, function (item, key) {
if (item.status != "skipped") { if (item.status != "skipped") {
$rootScope.queue.push(map(item)); $rootScope.queue.push(map(item));
} }
@ -109,13 +79,13 @@
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true); notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else if (action == 'play') { } else if (action == 'play') {
$rootScope.queue = []; $rootScope.queue = [];
angular.forEach(items, function(item, key) { angular.forEach(items, function (item, key) {
if (item.status != "skipped") { if (item.status != "skipped") {
$rootScope.queue.push(map(item)); $rootScope.queue.push(map(item));
} }
}); });
var next = $rootScope.queue[0]; var next = $rootScope.queue[0];
$scope.$apply(function() { $scope.$apply(function () {
$rootScope.playSong(false, next); $rootScope.playSong(false, next);
}); });
$rootScope.showQueue(); $rootScope.showQueue();
@ -123,7 +93,7 @@
} else { } else {
$scope.album = []; $scope.album = [];
$rootScope.song = []; $rootScope.song = [];
angular.forEach(items, function(item, key) { angular.forEach(items, function (item, key) {
if (item.status != "skipped") { if (item.status != "skipped") {
$rootScope.song.push(map(item)); $rootScope.song.push(map(item));
} }
@ -134,9 +104,9 @@
} }
} }
}); });
}; }
/* Launch on Startup */ /* Launch on Startup */
$scope.getPodcasts(); $scope.getPodcasts();
/* End Startup */ /* End Startup */
}); });

View file

@ -1,8 +1,8 @@
JamStash.controller('QueueCtrl', JamStash.controller('QueueCtrl',
function QueueCtrl($scope, $rootScope, $routeParams, $location, utils, globals, json, notifications) { function QueueCtrl($scope, $rootScope, $routeParams, $location, utils, globals, json, notifications) {
$scope.settings = globals.settings; $scope.settings = globals.settings;
//$scope.song = $rootScope.queue; //$scope.song = $rootScope.queue;
//angular.copy($rootScope.queue, $scope.song); //angular.copy($rootScope.queue, $scope.song);
$scope.song = $rootScope.queue; $scope.song = $rootScope.queue;
}); });

View file

@ -1,94 +1,71 @@
JamStash.controller('SettingsCtrl', JamStash.controller('SettingsCtrl',
function SettingsCtrl($scope, $routeParams, $location, utils, globals, json, notifications) { function SettingsCtrl($scope, $routeParams, $location, utils, globals, json, notifications, player) {
$scope.settings = globals.settings; $scope.settings = globals.settings;
$scope.Timeouts = [
$scope.Timeouts = [{ { id: 10000, name: 10 },
id: 10000, { id: 20000, name: 20 },
name: 10 { id: 30000, name: 30 },
}, { { id: 40000, name: 40 },
id: 20000, { id: 50000, name: 50 },
name: 20 { id: 60000, name: 60 },
}, { { id: 90000, name: 90 },
id: 30000, { id: 120000, name: 120 }
name: 30 ];
}, {
id: 40000,
name: 40
}, {
id: 50000,
name: 50
}, {
id: 60000,
name: 60
}, {
id: 90000,
name: 90
}, {
id: 120000,
name: 120
}];
$scope.Protocols = ["json", "jsonp"]; $scope.Protocols = ["json", "jsonp"];
$scope.Themes = ["Default", "Dark"]; $scope.Themes = ["Default", "Dark"];
$scope.SearchTypes = globals.SearchTypes; $scope.SearchTypes = globals.SearchTypes;
$scope.Layouts = globals.Layouts; $scope.Layouts = globals.Layouts;
$scope.$watch('settings.HideAZ', function() { $scope.$watch('settings.HideAZ', function () {
if (globals.settings.HideAZ) { if (globals.settings.HideAZ) {
$('#AZIndex').hide(); $('#AZIndex').hide();
} else { } else {
$('#AZIndex').show(); $('#AZIndex').show();
} }
}); });
$scope.reset = function () {
$scope.reset = function() {
utils.setValue('Settings', null, true); utils.setValue('Settings', null, true);
$scope.loadSettings(); $scope.loadSettings();
};
$scope.save = function() {
if ($scope.settings.Password !== '' && globals.settings.Password.substring(0, 4) != 'enc:') {
$scope.settings.Password = 'enc:' + utils.HexEncode($scope.settings.Password);
} }
if (globals.settings.NotificationSong) { $scope.save = function () {
if ($scope.settings.Password != '' && globals.settings.Password.substring(0, 4) != 'enc:') { $scope.settings.Password = 'enc:' + utils.HexEncode($scope.settings.Password); }
if ($scope.settings.NotificationSong) {
notifications.requestPermissionIfRequired(); notifications.requestPermissionIfRequired();
if (!notifications.hasNotificationPermission()) { if (!notifications.hasNotificationPermission()) {
alert('HTML5 Notifications are not available for your current browser, Sorry :('); alert('HTML5 Notifications are not available for your current browser, Sorry :(');
} }
} }
if (globals.settings.NotificationNowPlaying) { if ($scope.settings.NotificationNowPlaying) {
notifications.requestPermissionIfRequired(); notifications.requestPermissionIfRequired();
if (!notifications.hasNotificationPermission()) { if (!notifications.hasNotificationPermission()) {
alert('HTML5 Notifications are not available for your current browser, Sorry :('); alert('HTML5 Notifications are not available for your current browser, Sorry :(');
} }
} }
if (globals.settings.SaveTrackPosition) { if ($scope.settings.SaveTrackPosition) {
//saveTrackPosition(); player.saveTrackPosition();
} else { } else {
//deleteCurrentPlaylist(); player.deleteCurrentQueue();
} }
if (globals.settings.Theme) { if ($scope.settings.Theme) {
utils.switchTheme(globals.settings.Theme); utils.switchTheme(globals.settings.Theme);
} }
utils.setValue('Settings', $scope.settings, true); utils.setValue('Settings', $scope.settings, true);
notifications.updateMessage('Settings Updated!', true); notifications.updateMessage('Settings Updated!', true);
$scope.loadSettings(); $scope.loadSettings();
if (globals.settings.Server !== '' && globals.settings.Username !== '' && globals.settings.Password !== '') { if (globals.settings.Server != '' && globals.settings.Username != '' && globals.settings.Password != '') {
$scope.ping(); $scope.ping();
} }
}; };
json.getChangeLog(function (data) {
json.getChangeLog(function(data) {
$scope.changeLog = data.slice(0, 10); $scope.changeLog = data.slice(0, 10);
//notifications.updateMessage('Latest Version: ' + $scope.changeLog[0].version, true);
}); });
$scope.changeLogShowMore = function () {
$scope.changeLogShowMore = function() { json.getChangeLog(function (data) {
json.getChangeLog(function(data) {
$scope.changeLog = data; $scope.changeLog = data;
}); });
}; }
$scope.setupDemo = function () {
$scope.setupDemo = function() {
var Username = "android-guest"; var Username = "android-guest";
var Password = "guest"; var Password = "guest";
var Server = "http://subsonic.org/demo"; var Server = "http://subsonic.org/demo";
@ -100,8 +77,8 @@
//$scope.save(); //$scope.save();
$location.url('/library'); $location.url('/library');
} }
}; }
/* Load on Startup */ /* Load on Startup */
/* End Startup */ /* End Startup */
}); });

View file

@ -2,6 +2,7 @@
{ {
"date": "2/7/2014", "version": "3.2.2", "date": "2/7/2014", "version": "3.2.2",
"changes": [ "changes": [
{ "text": "- Bug fixes!" },
{ "text": "- Legacy version of <a href=\"http://jamstash.com/mini\" target=\"_blank\">MiniSub</a>" } { "text": "- Legacy version of <a href=\"http://jamstash.com/mini\" target=\"_blank\">MiniSub</a>" }
] ]
}, },

View file

@ -1,5 +1,5 @@
<div id="queue" class="tabcontent"> <div id="queue" class="tabcontent">
<div class="section fullsection floatleft"> <div class="section fullsection floatleft">
<ul class="songlist simplelist" ng-include src="'js/partials/songs.html'"></ul> <ul class="songlist simplelist noselect" ng-include src="'js/partials/songs.html'" sortable></ul>
</div> </div>
</div> </div>

View file

@ -86,10 +86,6 @@
<div class="clear"></div> <div class="clear"></div>
<select id="Timeout" name="Timeout" class="" ng-model="settings.Timeout" ng-options="o.id as o.name for o in Timeouts" title="AJAX Request Timeout (Seconds)"></select> <select id="Timeout" name="Timeout" class="" ng-model="settings.Timeout" ng-options="o.id as o.name for o in Timeouts" title="AJAX Request Timeout (Seconds)"></select>
<div class="clear"></div> <div class="clear"></div>
<label for="NotificationTimeout">Notification Timeout</label>
<div class="clear"></div>
<select id="NotificationTimeout" name="NotificationTimeout" class="" ng-model="settings.NotificationTimeout" ng-options="o.id as o.name for o in Timeouts" title="Notification Timeout (Seconds)"></select>
<div class="clear"></div>
<label for="Protocol">Protocol</label><br /> <label for="Protocol">Protocol</label><br />
<select id="Protocol" name="Protocol" class="" ng-model="settings.Protocol" ng-options="o for o in Protocols" title="Enable Cross-Domain AJAX Requests (Use if hosted in a different domain than Subsonic)"></select> <select id="Protocol" name="Protocol" class="" ng-model="settings.Protocol" ng-options="o for o in Protocols" title="Enable Cross-Domain AJAX Requests (Use if hosted in a different domain than Subsonic)"></select>
<!-- <!--

View file

@ -1,36 +1,31 @@
JamStash.service('player', function($rootScope, $window, utils, globals, model, notifications) { JamStash.service('player', function ($rootScope, $window, utils, globals, model, notifications) {
var player1 = '#playdeck_1'; var player1 = '#playdeck_1';
var player2 = '#playdeck_2'; var player2 = '#playdeck_2';
var scrobbled = false; var scrobbled = false;
var timerid = 0; var timerid = 0;
$rootScope.defaultPlay = function(data, event) { $rootScope.defaultPlay = function (data, event) {
if (typeof $(player1).data("jPlayer") == 'undefined') { if (typeof $(player1).data("jPlayer") == 'undefined') {
$rootScope.nextTrack(); $rootScope.nextTrack();
} }
}; }
$rootScope.nextTrack = function () {
$rootScope.nextTrack = function() {
var next = getNextSong(); var next = getNextSong();
if (next) { if (next) {
$rootScope.playSong(false, next); $rootScope.playSong(false, next);
} }
//$(player1).jPlayer("stop"); //$(player1).jPlayer("stop");
//$(player2).jPlayer("play"); //$(player2).jPlayer("play");
}; }
$rootScope.previousTrack = function () {
$rootScope.previousTrack = function() {
var next = getNextSong(true); var next = getNextSong(true);
if (next) { if (next) {
$rootScope.playSong(false, next); $rootScope.playSong(false, next);
} }
};
getNextSong = function(previous) {
var song;
if (globals.settings.Debug) {
console.log('Getting Next Song > ' + 'Queue length: ' + $rootScope.queue.length);
} }
getNextSong = function (previous) {
var song;
if (globals.settings.Debug) { console.log('Getting Next Song > ' + 'Queue length: ' + $rootScope.queue.length); }
if ($rootScope.queue.length > 0) { if ($rootScope.queue.length > 0) {
angular.forEach($rootScope.queue, function(item, key) { angular.forEach($rootScope.queue, function(item, key) {
if (item.playing === true) { if (item.playing === true) {
@ -45,9 +40,7 @@
next = $rootScope.queue[index + 1]; next = $rootScope.queue[index + 1];
} }
if (typeof next != 'undefined') { if (typeof next != 'undefined') {
if (globals.settings.Debug) { if (globals.settings.Debug) { console.log('Next Song: ' + next.id); }
console.log('Next Song: ' + next.id);
}
return next; return next;
} else { } else {
return false; return false;
@ -55,26 +48,24 @@
} else { } else {
return false; return false;
} }
}; }
this.startSaveTrackPosition = function () {
this.startSaveTrackPosition = function() {
if (globals.settings.SaveTrackPosition) { if (globals.settings.SaveTrackPosition) {
if (timerid !== 0) { if (timerid != 0) {
clearInterval(timerid); clearInterval(timerid);
} }
timerid = $window.setInterval(function() { timerid = $window.setInterval(function () {
if (globals.settings.SaveTrackPosition) { if (globals.settings.SaveTrackPosition) {
saveTrackPosition(); this.saveTrackPosition();
} }
}, 30000); }, 30000);
} }
}; }
this.saveTrackPosition = function () {
saveTrackPosition = function() {
//var audio = typeof $(player1).data("jPlayer") != 'undefined' ? true : false; //var audio = typeof $(player1).data("jPlayer") != 'undefined' ? true : false;
var audio = $(player1).data("jPlayer"); var audio = $(player1).data("jPlayer");
if (typeof audio != 'undefined') { if (typeof audio != 'undefined') {
if (audio.status.currentTime > 0 && audio.status.paused === false) { if (audio.status.currentTime > 0 && audio.status.paused == false) {
var song; var song;
angular.forEach($rootScope.queue, function(item, key) { angular.forEach($rootScope.queue, function(item, key) {
if (item.playing === true) { if (item.playing === true) {
@ -83,7 +74,7 @@
}); });
if (song) { if (song) {
var position = audio.status.currentTime; var position = audio.status.currentTime;
if (position !== null) { if (position != null) {
$('#action_SaveProgress').fadeTo("slow", 0).delay(500).fadeTo("slow", 1).delay(500).fadeTo("slow", 0).delay(500).fadeTo("slow", 1); $('#action_SaveProgress').fadeTo("slow", 0).delay(500).fadeTo("slow", 1).delay(500).fadeTo("slow", 0).delay(500).fadeTo("slow", 1);
song.position = position; song.position = position;
// Save Queue // Save Queue
@ -91,17 +82,13 @@
try { try {
var songStr = angular.toJson(song); var songStr = angular.toJson(song);
localStorage.setItem('CurrentSong', songStr); localStorage.setItem('CurrentSong', songStr);
if (globals.settings.Debug) { if (globals.settings.Debug) { console.log('Saving Current Position: ' + songStr); }
console.log('Saving Current Position: ' + songStr);
}
var html = localStorage.getItem('CurrentQueue'); var html = localStorage.getItem('CurrentQueue');
if ($rootScope.queue.length > 0) { if ($rootScope.queue.length > 0) {
var current = $rootScope.queue; var current = $rootScope.queue;
if (current != html) { if (current != html) {
localStorage.setItem('CurrentQueue', angular.toJson(current)); localStorage.setItem('CurrentQueue', angular.toJson(current));
if (globals.settings.Debug) { if (globals.settings.Debug) { console.log('Saving Queue: ' + current.length + ' characters'); }
console.log('Saving Queue: ' + current.length + ' characters');
}
} }
} }
} catch (e) { } catch (e) {
@ -110,17 +97,16 @@
} }
} }
} else { } else {
if (globals.settings.Debug) { if (globals.settings.Debug) { console.log('HTML5::loadStorage not supported on your browser'); }
console.log('HTML5::loadStorage not supported on your browser');
} }
} }
} }
} }
} else {
if (globals.settings.Debug) { console.log('Saving Queue: No Audio Loaded'); }
} }
} }
}; this.loadTrackPosition = function () {
this.loadTrackPosition = function() {
if (utils.browserStorageCheck()) { if (utils.browserStorageCheck()) {
// Load Saved Song // Load Saved Song
var song = angular.fromJson(localStorage.getItem('CurrentSong')); var song = angular.fromJson(localStorage.getItem('CurrentSong'));
@ -134,36 +120,24 @@
if ($rootScope.queue.length > 0) { if ($rootScope.queue.length > 0) {
notifications.updateMessage($rootScope.queue.length + ' Saved Song(s)', true); notifications.updateMessage($rootScope.queue.length + ' Saved Song(s)', true);
} }
if (globals.settings.Debug) { if (globals.settings.Debug) { console.log('Play Queue Loaded From localStorage: ' + $rootScope.queue.length + ' song(s)'); }
console.log('Play Queue Loaded From localStorage: ' + $rootScope.queue.length + ' song(s)');
}
} }
} }
} else { } else {
if (globals.settings.Debug) { if (globals.settings.Debug) { console.log('HTML5::loadStorage not supported on your browser'); }
console.log('HTML5::loadStorage not supported on your browser');
} }
} }
}; this.deleteCurrentQueue = function (data) {
deleteCurrentQueue = function(data) {
if (utils.browserStorageCheck()) { if (utils.browserStorageCheck()) {
localStorage.removeItem('CurrentQueue'); localStorage.removeItem('CurrentQueue');
utils.setValue('CurrentSong', null, false); utils.setValue('CurrentSong', null, false);
if (globals.settings.Debug) { if (globals.settings.Debug) { console.log('Removing Play Queue'); }
console.log('Removing Play Queue');
}
} else { } else {
if (globals.settings.Debug) { if (globals.settings.Debug) { console.log('HTML5::loadStorage not supported on your browser, ' + html.length + ' characters'); }
console.log('HTML5::loadStorage not supported on your browser, ' + html.length + ' characters');
} }
} }
}; $rootScope.playSong = function (loadonly, data) {
if (globals.settings.Debug) { console.log('Play: ' + JSON.stringify(data, null, 2)); }
$rootScope.playSong = function(loadonly, data) {
if (globals.settings.Debug) {
console.log('Play: ' + JSON.stringify(data, null, 2));
}
angular.forEach($rootScope.queue, function(item, key) { angular.forEach($rootScope.queue, function(item, key) {
item.playing = false; item.playing = false;
}); });
@ -194,8 +168,7 @@
artist: artist, artist: artist,
favorite: false, favorite: false,
albumArt: coverartfull albumArt: coverartfull
}; }
if ($rootScope.unity) { if ($rootScope.unity) {
$rootScope.unity.sendState(playerState); $rootScope.unity.sendState(playerState);
} }
@ -206,13 +179,13 @@
$rootScope.showQueue(); $rootScope.showQueue();
} }
var spechtml = ''; var spechtml = '';
data = $(player1).data().jPlayer; var data = $(player1).data().jPlayer;
for (i = 0; i < data.solutions.length; i++) { for (i = 0; i < data.solutions.length; i++) {
var solution = data.solutions[i]; var solution = data.solutions[i];
if (data[solution].used) { if (data[solution].used) {
spechtml += "<strong class=\"codesyntax\">" + solution + "</strong> is"; spechtml += "<strong class=\"codesyntax\">" + solution + "</strong> is";
spechtml += " currently being used with<strong>"; spechtml += " currently being used with<strong>";
for (var format in data[solution].support) { for (format in data[solution].support) {
if (data[solution].support[format]) { if (data[solution].support[format]) {
spechtml += " <strong class=\"codesyntax\">" + format + "</strong>"; spechtml += " <strong class=\"codesyntax\">" + format + "</strong>";
} }
@ -227,18 +200,17 @@
notifications.showNotification(coverartthumb, utils.toHTML.un(title), utils.toHTML.un(artist + ' - ' + album), 'text', '#NextTrack'); notifications.showNotification(coverartthumb, utils.toHTML.un(title), utils.toHTML.un(artist + ' - ' + album), 'text', '#NextTrack');
} }
if (globals.settings.ScrollTitle) { if (globals.settings.ScrollTitle) {
title = utils.toHTML.un(artist) + ' - ' + utils.toHTML.un(title); var title = utils.toHTML.un(artist) + ' - ' + utils.toHTML.un(title);
utils.scrollTitle(title); utils.scrollTitle(title);
} else { } else {
utils.setTitle(utils.toHTML.un(artist) + ' - ' + utils.toHTML.un(title)); utils.setTitle(utils.toHTML.un(artist) + ' - ' + utils.toHTML.un(title));
} }
//utils.safeApply(); //utils.safeApply();
if (!$rootScope.$root.$$phase) { if(!$rootScope.$root.$$phase) {
$rootScope.$apply(); $rootScope.$apply();
} }
}; };
$rootScope.loadjPlayer = function (el, url, suffix, loadonly, position) {
$rootScope.loadjPlayer = function(el, url, suffix, loadonly, position) {
// jPlayer Setup // jPlayer Setup
var volume = 1; var volume = 1;
if (utils.getValue('Volume')) { if (utils.getValue('Volume')) {
@ -272,7 +244,7 @@
currentTime: "#played", currentTime: "#played",
duration: "#duration" duration: "#duration"
}, },
ready: function() { ready: function () {
console.log("File Suffix: " + suffix); console.log("File Suffix: " + suffix);
if (suffix == 'oga') { if (suffix == 'oga') {
$(this).jPlayer("setMedia", { $(this).jPlayer("setMedia", {
@ -304,9 +276,7 @@
// Scrobble song once percentage is reached // Scrobble song once percentage is reached
var p = event.jPlayer.status.currentPercentAbsolute; var p = event.jPlayer.status.currentPercentAbsolute;
if (!scrobbled && p > 30) { if (!scrobbled && p > 30) {
if (globals.settings.Debug) { if (globals.settings.Debug) { console.log('LAST.FM SCROBBLE - Percent Played: ' + p); }
console.log('LAST.FM SCROBBLE - Percent Played: ' + p);
}
scrobbleSong(true); scrobbleSong(true);
} }
}, },
@ -342,9 +312,8 @@
} }
}); });
return; return;
}; }
this.playPauseSong = function () {
this.playPauseSong = function() {
if (typeof $(player1).data("jPlayer") != 'undefined') { if (typeof $(player1).data("jPlayer") != 'undefined') {
if ($(player1).data("jPlayer").status.paused) { if ($(player1).data("jPlayer").status.paused) {
$(player1).jPlayer("play"); $(player1).jPlayer("play");
@ -352,24 +321,20 @@
$(player1).jPlayer("pause"); $(player1).jPlayer("pause");
} }
} }
}; }
playVideo = function (id, bitrate) {
playVideo = function(id, bitrate) {
var w, h; var w, h;
bitrate = parseInt(bitrate); bitrate = parseInt(bitrate);
if (bitrate <= 600) { if (bitrate <= 600) {
w = 320; w = 320; h = 240;
h = 240;
} else if (bitrate <= 1000) { } else if (bitrate <= 1000) {
w = 480; w = 480; h = 360;
h = 360;
} else { } else {
w = 640; w = 640; h = 480;
h = 480;
} }
//$("#jPlayerSelector").jPlayer("option", "fullScreen", true); //$("#jPlayerSelector").jPlayer("option", "fullScreen", true);
$("#videodeck").jPlayer({ $("#videodeck").jPlayer({
ready: function() { ready: function () {
/* /*
$.fancybox({ $.fancybox({
autoSize: false, autoSize: false,
@ -387,35 +352,32 @@
solution: "html, flash", solution: "html, flash",
supplied: "m4v" supplied: "m4v"
}); });
}; }
scrobbleSong = function(submission) { scrobbleSong = function (submission) {
if ($rootScope.loggedIn && submission) { if ($rootScope.loggedIn && submission) {
var id = $rootScope.playingSong.id; var id = $rootScope.playingSong.id;
if (globals.settings.Debug) { if (globals.settings.Debug) { console.log('Scrobble Song: ' + id); }
console.log('Scrobble Song: ' + id);
}
$.ajax({ $.ajax({
url: globals.BaseURL() + '/scrobble.view?' + globals.BaseParams() + '&id=' + id + "&submission=" + submission, url: globals.BaseURL() + '/scrobble.view?' + globals.BaseParams() + '&id=' + id + "&submission=" + submission,
method: 'GET', method: 'GET',
dataType: globals.settings.Protocol, dataType: globals.settings.Protocol,
timeout: 10000, timeout: 10000,
success: function() { success: function () {
scrobbled = true; scrobbled = true;
} }
}); });
} }
}; }
rateSong = function (songid, rating) {
rateSong = function(songid, rating) {
$.ajax({ $.ajax({
url: baseURL + '/setRating.view?' + baseParams + '&id=' + songid + "&rating=" + rating, url: baseURL + '/setRating.view?' + baseParams + '&id=' + songid + "&rating=" + rating,
method: 'GET', method: 'GET',
dataType: protocol, dataType: protocol,
timeout: 10000, timeout: 10000,
success: function() { success: function () {
updateMessage('Rating Updated!', true); updateMessage('Rating Updated!', true);
} }
}); });
}; }
}); });

View file

@ -1,6 +1,6 @@
JamStash.service('model', function() { JamStash.service('model', function () {
// Figure out how to move this, circular dependency with utils // Figure out how to move this, circular dependency with utils
secondsToTime = function(secs) { secondsToTime = function (secs) {
// secs = 4729 // secs = 4729
var times = new Array(3600, 60, 1); var times = new Array(3600, 60, 1);
var time = ''; var time = '';
@ -12,10 +12,12 @@
// 2: 49/1 = 49 // 2: 49/1 = 49
if (tmp < 1) { if (tmp < 1) {
tmp = '00'; tmp = '00';
} else if (tmp < 10) { }
else if (tmp < 10) {
tmp = '0' + tmp; tmp = '0' + tmp;
} }
if (i === 0 && tmp == '00') {} else { if (i == 0 && tmp == '00') {
} else {
time += tmp; time += tmp;
if (i < 2) { if (i < 2) {
time += ':'; time += ':';
@ -24,19 +26,16 @@
secs = secs % times[i]; secs = secs % times[i];
} }
return time; return time;
}; }
this.Index = function (name, artist) {
this.Index = function(name, artist) {
this.name = name; this.name = name;
this.artist = artist; this.artist = artist;
}; }
this.Artist = function (id, name) {
this.Artist = function(id, name) {
this.id = id; this.id = id;
this.name = name; this.name = name;
}; }
this.Album = function (id, parentid, name, artist, artistId, coverartthumb, coverartfull, date, starred, description, url, type) {
this.Album = function(id, parentid, name, artist, artistId, coverartthumb, coverartfull, date, starred, description, url, type) {
this.id = id; this.id = id;
this.parentid = parentid; this.parentid = parentid;
this.name = name; this.name = name;
@ -49,9 +48,8 @@
this.description = description; this.description = description;
this.url = url; this.url = url;
this.type = type; this.type = type;
}; }
this.Song = function (id, parentid, track, name, artist, artistId, album, albumId, coverartthumb, coverartfull, duration, rating, starred, suffix, specs, url, position, description) {
this.Song = function(id, parentid, track, name, artist, artistId, album, albumId, coverartthumb, coverartfull, duration, rating, starred, suffix, specs, url, position, description) {
this.id = id; this.id = id;
this.parentid = parentid; this.parentid = parentid;
this.track = track; this.track = track;
@ -63,7 +61,7 @@
this.coverartthumb = coverartthumb; this.coverartthumb = coverartthumb;
this.coverartfull = coverartfull; this.coverartfull = coverartfull;
this.duration = duration; this.duration = duration;
this.time = duration === '' ? '00:00' : secondsToTime(duration); this.time = duration == '' ? '00:00' : secondsToTime(duration);
this.rating = rating; this.rating = rating;
this.starred = starred; this.starred = starred;
this.suffix = suffix; this.suffix = suffix;
@ -74,56 +72,38 @@
this.playing = false; this.playing = false;
this.description = description; this.description = description;
this.displayName = this.name + " - " + this.album + " - " + this.artist; this.displayName = this.name + " - " + this.album + " - " + this.artist;
}; }
}); });
JamStash.service('globals', function() { JamStash.service('globals', function () {
this.SearchTypes = [
this.SearchTypes = [{ { id: "song", name: "Song" },
id: "song", { id: "album", name: "Album" },
name: "Song" { id: "artist", name: "Artist" },
}, { ];
id: "album", this.Layouts = [
name: "Album" { id: "grid", name: "Grid" },
}, { { id: "list", name: "List" }
id: "artist", ];
name: "Artist" this.AlbumSorts = [
}, ]; { id: "default", name: "Default Sort" },
{ id: "artist", name: "Artist" },
this.Layouts = [{ { id: "album", name: "Album" },
id: "grid", { id: "track", name: "Track" },
name: "Grid" { id: "createdate desc", name: "Date Added" },
}, { ];
id: "list",
name: "List"
}];
this.AlbumSorts = [{
id: "default",
name: "Default Sort"
}, {
id: "artist",
name: "Artist"
}, {
id: "album",
name: "Album"
}, {
id: "track",
name: "Track"
}, {
id: "createdate desc",
name: "Date Added"
}, ];
this.settings = { this.settings = {
// Subsonic // Subsonic
/* Demo Server
Username: "android-guest"),
Password: "guest"),
Server: "http://subsonic.org/demo"),
*/
Url: "http://Jamstash.com/beta/#/archive/", Url: "http://Jamstash.com/beta/#/archive/",
Username: "", Username: "",
Password: "", Password: "",
Server: "", Server: "",
Timeout: 10000, Timeout: 20000,
NotificationTimeout: 20000,
Protocol: "jsonp", Protocol: "jsonp",
ApplicationName: "Jamstash", ApplicationName: "Jamstash",
ApiVersion: "1.6.0", ApiVersion: "1.6.0",
@ -146,24 +126,17 @@ JamStash.service('globals', function() {
Repeat: false, Repeat: false,
Debug: false Debug: false
}; };
this.SavedCollections = []; this.SavedCollections = [];
this.SavedGenres = []; this.SavedGenres = [];
this.BaseURL = function() { this.BaseURL = function () { return this.settings.Server + '/rest'; };
return this.settings.Server + '/rest'; this.BaseParams = function () { return 'u=' + this.settings.Username + '&p=' + this.settings.Password + '&f=' + this.settings.Protocol + '&v=' + this.settings.ApiVersion + '&c=' + this.settings.ApplicationName; };
};
this.BaseParams = function() {
return 'u=' + this.settings.Username + '&p=' + this.settings.Password + '&f=' + this.settings.Protocol + '&v=' + this.settings.ApiVersion + '&c=' + this.settings.ApplicationName;
};
}); });
// Directives // Directives
JamStash.directive('layout', function() { JamStash.directive('layout', function () {
return { return {
link: function(scope, elm, attrs) { link: function (scope, elm, attrs) {
var pageLayoutOptions = { var pageLayoutOptions = {
name: 'pageLayout', // only for debugging name: 'pageLayout', // only for debugging
@ -183,16 +156,16 @@ JamStash.directive('layout', function() {
}; };
var layoutThreeCol = { var layoutThreeCol = {
east__size: 0.42, east__size: .42,
east__minSize: 400, east__minSize: 400,
east__maxSize: 0.5, // 50% of layout width east__maxSize: .5, // 50% of layout width
east__initClosed: false, east__initClosed: false,
east__initHidden: false, east__initHidden: false,
//center__size: 'auto', //center__size: 'auto',
center__minWidth: 0.38, center__minWidth: .38,
center__initClosed: false, center__initClosed: false,
center__initHidden: false, center__initHidden: false,
west__size: 0.2, west__size: .2,
west__minSize: 200, west__minSize: 200,
west__initClosed: false, west__initClosed: false,
west__initHidden: false, west__initHidden: false,
@ -202,12 +175,12 @@ JamStash.directive('layout', function() {
}; };
var layoutTwoCol = { var layoutTwoCol = {
center__size: 0.8, center__size: .8,
center__minSize: 400, center__minSize: 400,
center__maxSize: 0.5, // 50% of layout width center__maxSize: .5, // 50% of layout width
center__initClosed: false, center__initClosed: false,
center__initHidden: false, center__initHidden: false,
west__size: 0.2, west__size: .2,
west__minSize: 200, west__minSize: 200,
west__initClosed: false, west__initClosed: false,
west__initHidden: false, west__initHidden: false,
@ -216,20 +189,17 @@ JamStash.directive('layout', function() {
//applyDefaultStyles: true //applyDefaultStyles: true
}; };
scope.$watch(attrs.state, function(state) { scope.$watch(attrs.state, function (state) {
var layout;
if (state == 1) { if (state == 1) {
layout = elm.layout(pageLayoutOptions); var layout = elm.layout(pageLayoutOptions);
} }
if (state == 2) { if (state == 2) {
layout = elm.layout(layoutTwoCol); var layout = elm.layout(layoutTwoCol);
//scope.layout.sizePane('east', 120); //scope.layout.sizePane('east', 120);
//scope.layout.show('west'); //scope.layout.show('west');
//scope.layout.show('south'); //scope.layout.show('south');
} else if (state == 3) { } else if (state == 3) {
layout = elm.layout(layoutThreeCol); var layout = elm.layout(layoutThreeCol);
//scope.layout.sizePane('east', 60); //scope.layout.sizePane('east', 60);
//scope.layout.hide('west'); //scope.layout.hide('west');
//scope.layout.hide('south'); //scope.layout.hide('south');
@ -239,10 +209,9 @@ JamStash.directive('layout', function() {
} }
}; };
}); });
JamStash.directive('sortable', function () {
JamStash.directive('sortable', function() {
return { return {
link: function(scope, elm, attrs) { link: function (scope, elm, attrs) {
elm.sortable({ elm.sortable({
start: scope.dragStart, start: scope.dragStart,
update: scope.dragEnd update: scope.dragEnd
@ -251,17 +220,49 @@ JamStash.directive('sortable', function() {
} }
}; };
}); });
JamStash.directive('split', function () {
JamStash.directive('split', function() {
return { return {
link: function(scope, elm, attrs) { link: function (scope, elm, attrs) {
elm.splitPane(); elm.splitPane();
/*
//elm.first().resizable({
$('#SubsonicAlbums > div:first').resizable({
handles: 'e',
minWidth: '100',
maxWidth: '400',
resize: function () {
alert('foo');
var remainingSpace = $(this).parent().width() - $(this).outerWidth();
var divTwo = $(this).next();
var divTwoWidth = remainingSpace - (divTwo.outerWidth() - divTwo.width());
divTwo.css('width', divTwoWidth + 'px');
}
});
*/
/*
scope.$watch(attrs.state, function (state) {
if (state == 1) {
var layout = elm.layout(pageLayoutOptions);
}
if (state == 2) {
var layout = elm.layout(layoutTwoCol);
//scope.layout.sizePane('east', 120);
//scope.layout.show('west');
//scope.layout.show('south');
} else if (state == 3) {
var layout = elm.layout(layoutThreeCol);
//scope.layout.sizePane('east', 60);
//scope.layout.hide('west');
//scope.layout.hide('south');
}
scope.layout = layout;
});
*/
} }
}; };
}); });
JamStash.directive('fancybox', function ($compile) {
JamStash.directive('fancybox', function($compile) {
return { return {
restrict: 'A', restrict: 'A',
replace: false, replace: false,
@ -272,7 +273,7 @@ JamStash.directive('fancybox', function($compile) {
$.fancybox.open(el); $.fancybox.open(el);
compiled($scope); compiled($scope);
}; };
$scope.fancyboxOpenUrl = function() { $scope.fancyboxOpenUrl = function () {
var el = angular.element(element.html()), var el = angular.element(element.html()),
compiled = $compile(el); compiled = $compile(el);
$.fancybox.open(el); $.fancybox.open(el);
@ -281,8 +282,7 @@ JamStash.directive('fancybox', function($compile) {
} }
}; };
}); });
JamStash.directive('songpreview', function ($compile, subsonic) {
JamStash.directive('songpreview', function($compile, subsonic) {
return { return {
restrict: 'E', restrict: 'E',
templateUrl: 'js/partials/songs.html', templateUrl: 'js/partials/songs.html',
@ -291,8 +291,8 @@ JamStash.directive('songpreview', function($compile, subsonic) {
scope: { scope: {
song: '@' song: '@'
}, },
link: function(scope, element, attrs) { link: function (scope, element, attrs) {
subsonic.getSongTemplate(function(data) { subsonic.getSongTemplate(function (data) {
scope.song = data; scope.song = data;
//var el = angular.element(element.html()), //var el = angular.element(element.html()),
//var el = element.html(), //var el = element.html(),
@ -301,25 +301,23 @@ JamStash.directive('songpreview', function($compile, subsonic) {
//compiled($scope); //compiled($scope);
}); });
} }
}; }
}); })
JamStash.directive('stopEvent', function () {
JamStash.directive('stopEvent', function() {
return { return {
restrict: 'A', restrict: 'A',
link: function(scope, element, attr) { link: function (scope, element, attr) {
element.bind(attr.stopEvent, function(e) { element.bind(attr.stopEvent, function (e) {
e.stopPropagation(); e.stopPropagation();
}); });
} }
}; };
}); });
JamStash.directive('ngEnter', function () {
JamStash.directive('ngEnter', function() { return function (scope, element, attrs) {
return function(scope, element, attrs) { element.bind("keydown keypress", function (event) {
element.bind("keydown keypress", function(event) {
if (event.which === 13) { if (event.which === 13) {
scope.$apply(function() { scope.$apply(function () {
scope.$eval(attrs.ngEnter); scope.$eval(attrs.ngEnter);
}); });
@ -328,18 +326,13 @@ JamStash.directive('ngEnter', function() {
}); });
}; };
}); });
JamStash.directive('ngDownload', function ($compile) {
JamStash.directive('ngDownload', function($compile) {
return { return {
restrict: 'E', restrict: 'E',
scope: { scope: { data: '=' },
data: '=' link: function (scope, elm, attrs) {
},
link: function(scope, elm, attrs) {
function getUrl() { function getUrl() {
return URL.createObjectURL(new Blob([JSON.stringify(scope.data)], { return URL.createObjectURL(new Blob([JSON.stringify(scope.data)], { type: "application/json" }));
type: "application/json"
}));
} }
elm.append($compile( elm.append($compile(
@ -349,7 +342,7 @@ JamStash.directive('ngDownload', function($compile) {
'</a>' '</a>'
)(scope)); )(scope));
scope.$watch(scope.data, function() { scope.$watch(scope.data, function () {
elm.children()[0].href = getUrl(); elm.children()[0].href = getUrl();
}); });
} }
@ -357,45 +350,47 @@ JamStash.directive('ngDownload', function($compile) {
}); });
/* Factory */ /* Factory */
JamStash.factory('json', function($http) { // Deferred loading JamStash.factory('json', function ($http) { // Deferred loading
return { return {
getCollections: function(callback) { getCollections: function (callback) {
$http.get('js/json_collections.js').success(callback); $http.get('js/json_collections.js').success(callback);
}, },
getChangeLog: function(callback) { getChangeLog: function (callback) {
$http.get('js/json_changelog.js').success(callback); $http.get('js/json_changelog.js').success(callback);
} }
};
});
JamStash.factory('template', function($compile, $http, $templateCache) { // Deferred loading
return {
getCollections: function(callback) {
$http.get('js/json_collections.js', {
cache: $templateCache
}).success(callback);
},
getChangeLog: function(callback) {
$http.get('js/json_changelog.js', {
cache: $templateCache
}).success(callback);
},
getSongs: function(callback) {
templateUrl = 'js/partials/songs.html';
$http.get(templateUrl, {
cache: $templateCache
}).success(callback);
} }
};
}); });
JamStash.factory('template', function ($http, $compile, $http, $templateCache) { // Deferred loading
JamStash.factory('subsonic', function($http, globals, utils) {
return { return {
getSongTemplate: function(callback) { getCollections: function (callback) {
$http.get('js/json_collections.js', { cache: $templateCache }).success(callback);
},
getChangeLog: function (callback) {
$http.get('js/json_changelog.js', { cache: $templateCache }).success(callback);
},
getSongs: function (callback) {
templateUrl = 'js/partials/songs.html';
$http.get(templateUrl, { cache: $templateCache }).success(callback);
}
}
});
JamStash.factory('subsonic', function ($http, globals, utils) {
return {
getSongTemplate: function (callback) {
var id = '16608'; var id = '16608';
var url = globals.BaseURL() + '/getMusicDirectory.view?' + globals.BaseParams() + '&id=' + id; var url = globals.BaseURL() + '/getMusicDirectory.view?' + globals.BaseParams() + '&id=' + id;
/*
$.ajax({
url: url,
method: 'GET',
dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout,
success: function (data) {
$http.get(url).success(function(data) { }
});
*/
$http.get(url).success(function (data) {
var items = []; var items = [];
var song = []; var song = [];
if (typeof data["subsonic-response"].directory.child != 'undefined') { if (typeof data["subsonic-response"].directory.child != 'undefined') {
@ -404,7 +399,7 @@ JamStash.factory('subsonic', function($http, globals, utils) {
} else { } else {
items[0] = data["subsonic-response"].directory.child; items[0] = data["subsonic-response"].directory.child;
} }
angular.forEach(items, function(item, key) { angular.forEach(items, function (item, key) {
if (!item.isDir) { if (!item.isDir) {
song.push(utils.mapSong(item)); song.push(utils.mapSong(item));
} }
@ -413,54 +408,47 @@ JamStash.factory('subsonic', function($http, globals, utils) {
} }
}); });
} }
}; }
}); });
/* Filters */ /* Filters */
JamStash.filter('capitalize', function() { JamStash.filter('capitalize', function () {
return function(input, scope) { return function (input, scope) {
return input.substring(0, 1).toUpperCase() + input.substring(1); return input.substring(0, 1).toUpperCase() + input.substring(1);
}; }
}); });
JamStash.service('notifications', function($rootScope, globals) { JamStash.service('notifications', function ($rootScope, globals) {
var msgIndex = 1; var msgIndex = 1;
this.updateMessage = function(msg, autohide) { this.updateMessage = function (msg, autohide) {
if (msg !== '') { if (msg != '') {
var id = msgIndex; var id = msgIndex;
$('#messages').append('<span id=\"msg_' + id + '\" class="message">' + msg + '</span>'); $('#messages').append('<span id=\"msg_' + id + '\" class="message">' + msg + '</span>');
$('#messages').fadeIn(); $('#messages').fadeIn();
$("#messages").scrollTo('100%'); $("#messages").scrollTo('100%');
var el = '#msg_' + id; var el = '#msg_' + id;
if (autohide) { if (autohide) {
setTimeout(function() { setTimeout(function () {
$(el).fadeOut(function() { $(el).fadeOut(function () { $(this).remove(); });
$(this).remove(); }, globals.settings.Timeout);
});
}, globals.settings.NotificationTimeout);
} }
$(el).click(function() { $(el).click(function () {
$(el).fadeOut(function() { $(el).fadeOut(function () { $(this).remove(); });
$(this).remove();
});
return false; return false;
}); });
msgIndex++; msgIndex++;
} }
}; }
this.requestPermissionIfRequired = function () {
this.requestPermissionIfRequired = function() {
if (!this.hasNotificationPermission() && (window.webkitNotifications)) { if (!this.hasNotificationPermission() && (window.webkitNotifications)) {
window.webkitNotifications.requestPermission(); window.webkitNotifications.requestPermission();
} }
}; }
this.hasNotificationPermission = function () {
this.hasNotificationPermission = function() { return !!(window.webkitNotifications) && (window.webkitNotifications.checkPermission() == 0);
return !!(window.webkitNotifications) && (window.webkitNotifications.checkPermission() === 0); }
}; var notifications = new Array();
this.showNotification = function (pic, title, text, type, bind) {
var notifications = [];
this.showNotification = function(pic, title, text, type, bind) {
if (this.hasNotificationPermission()) { if (this.hasNotificationPermission()) {
//closeAllNotifications() //closeAllNotifications()
var popup; var popup;
@ -469,26 +457,25 @@ JamStash.service('notifications', function($rootScope, globals) {
} else if (type == 'html') { } else if (type == 'html') {
popup = window.webkitNotifications.createHTMLNotification(text); popup = window.webkitNotifications.createHTMLNotification(text);
} }
if (bind == '#NextTrack') { if (bind = '#NextTrack') {
popup.addEventListener('click', function(bind) { popup.addEventListener('click', function (bind) {
//$(bind).click(); //$(bind).click();
$rootScope.nextTrack(); $rootScope.nextTrack();
this.cancel(); this.cancel();
}); })
} }
notifications.push(popup); notifications.push(popup);
setTimeout(function(notWin) { setTimeout(function (notWin) {
notWin.cancel(); notWin.cancel();
}, globals.settings.NotificationTimeout, popup); }, globals.settings.Timeout, popup);
popup.show(); popup.show();
} else { } else {
console.log("showNotification: No Permission"); console.log("showNotification: No Permission");
} }
}; }
this.closeAllNotifications = function () {
this.closeAllNotifications = function() { for (notification in notifications) {
for (var notification in notifications) {
notifications[notification].cancel(); notifications[notification].cancel();
} }
}; }
}); });

View file

@ -1,17 +1,15 @@
JamStash.service('utils', function($cookieStore, globals, model) { JamStash.service('utils', function ($cookieStore, globals, model) {
this.safeApply = function (fn) {
this.safeApply = function(fn) {
var phase = this.$root.$$phase; var phase = this.$root.$$phase;
if (phase == '$apply' || phase == '$digest') { if (phase == '$apply' || phase == '$digest') {
if (fn && (typeof(fn) === 'function')) { if (fn && (typeof (fn) === 'function')) {
fn(); fn();
} }
} else { } else {
this.$apply(fn); this.$apply(fn);
} }
}; };
this.setValue = function (key, value, notify) {
this.setValue = function(key, value, notify) {
/* /*
if (value !== null) { if (value !== null) {
$cookieStore.put(key, value); $cookieStore.put(key, value);
@ -24,13 +22,10 @@ JamStash.service('utils', function($cookieStore, globals, model) {
try { try {
localStorage.setItem(key, JSON.stringify(value)); localStorage.setItem(key, JSON.stringify(value));
} catch (e) { } catch (e) {
if (globals.settings.Debug) { if (globals.settings.Debug) { console.log(e); }
console.log(e);
} }
} }
}; this.getValue = function (value) {
this.getValue = function(value) {
/* /*
if ($cookieStore.get(value)) { if ($cookieStore.get(value)) {
return $cookieStore.get(value); return $cookieStore.get(value);
@ -40,93 +35,60 @@ JamStash.service('utils', function($cookieStore, globals, model) {
*/ */
try { try {
var item = localStorage.getItem(value); var item = localStorage.getItem(value);
if (item !== '' && typeof item != 'undefined') { if (item != '' && typeof item != 'undefined') {
return JSON.parse(item); return JSON.parse(item);
} else { } else {
return false; return false;
} }
} catch (e) { } catch (e) {
if (globals.settings.Debug) { if (globals.settings.Debug) { console.log(e); }
console.log(e);
} }
} }
}; this.mapSong = function (data) {
this.mapSong = function(data) {
var song = data; var song = data;
var url, title, track, rating, starred, contenttype, suffix, description; var url, title, track, rating, starred, contenttype, suffix, description;
var specs = '', var specs = '', coverartthumb = '', coverartfull = '';
coverartthumb = '',
coverartfull = '';
if (typeof song.coverArt != 'undefined') { if (typeof song.coverArt != 'undefined') {
coverartthumb = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&size=60&id=' + song.coverArt; coverartthumb = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&size=60&id=' + song.coverArt;
coverartfull = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&id=' + song.coverArt; coverartfull = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&id=' + song.coverArt;
}
if (typeof song.description == 'undefined') {
description = '';
} else { } else {
description = song.description; coverartthumb = 'images/albumdefault_60.jpg';
} coverartfull = 'images/albumdefault_160.jpg';
if (typeof song.title == 'undefined') {
title = '&nbsp;';
} else {
title = song.title.toString();
}
if (typeof song.track == 'undefined') {
track = '&nbsp;';
} else {
track = song.track.toString();
}
if (typeof song.starred !== 'undefined') {
starred = true;
} else {
starred = false;
}
if (song.bitRate !== undefined) {
specs += song.bitRate + ' Kbps';
}
if (song.transcodedSuffix !== undefined) {
specs += ', transcoding:' + song.suffix + ' > ' + song.transcodedSuffix;
} else {
specs += ', ' + song.suffix;
}
if (song.transcodedSuffix !== undefined) {
suffix = song.transcodedSuffix;
} else {
suffix = song.suffix;
}
if (suffix == 'ogg') {
suffix = 'oga';
} }
if (typeof song.description == 'undefined') { description = ''; } else { description = song.description; }
if (typeof song.title == 'undefined') { title = '&nbsp;'; } else { title = song.title.toString(); }
if (typeof song.track == 'undefined') { track = '&nbsp;'; } else { track = song.track.toString(); }
if (typeof song.starred !== 'undefined') { starred = true; } else { starred = false; }
if (song.bitRate !== undefined) { specs += song.bitRate + ' Kbps'; }
if (song.transcodedSuffix !== undefined) { specs += ', transcoding:' + song.suffix + ' > ' + song.transcodedSuffix; } else { specs += ', ' + song.suffix; }
if (song.transcodedSuffix !== undefined) { suffix = song.transcodedSuffix; } else { suffix = song.suffix; }
if (suffix == 'ogg') { suffix = 'oga'; }
var salt = Math.floor(Math.random() * 100000); var salt = Math.floor(Math.random() * 100000);
url = globals.BaseURL() + '/stream.view?' + globals.BaseParams() + '&id=' + song.id + '&salt=' + salt; url = globals.BaseURL() + '/stream.view?' + globals.BaseParams() + '&id=' + song.id + '&salt=' + salt;
return new model.Song(song.id, song.parent, track, title, song.artist, song.artistId, song.album, song.albumId, coverartthumb, coverartfull, song.duration, song.userRating, starred, suffix, specs, url, 0, description); return new model.Song(song.id, song.parent, track, title, song.artist, song.artistId, song.album, song.albumId, coverartthumb, coverartfull, song.duration, song.userRating, starred, suffix, specs, url, 0, description);
}; }
this.confirmDelete = function (text) {
this.confirmDelete = function(text) {
var question = confirm(text); var question = confirm(text);
if (question) { if (question) {
return true; return true;
} else { }
else {
return false; return false;
} }
}; }
this.makeBaseAuth = function (user, password) {
this.makeBaseAuth = function(user, password) {
var tok = user + ':' + password; var tok = user + ':' + password;
var hash = $.base64Encode(tok); var hash = $.base64Encode(tok);
return "Basic " + hash; return "Basic " + hash;
}; }
this.HexEncode = function (n) {
this.HexEncode = function(n) {
for (var u = "0123456789abcdef", i = [], r = [], t = 0; t < 256; t++) for (var u = "0123456789abcdef", i = [], r = [], t = 0; t < 256; t++)
i[t] = u.charAt(t >> 4) + u.charAt(t & 15); i[t] = u.charAt(t >> 4) + u.charAt(t & 15);
for (t = 0; t < n.length; t++) for (t = 0; t < n.length; t++)
r[t] = i[n.charCodeAt(t)]; r[t] = i[n.charCodeAt(t)];
return r.join(""); return r.join("")
}; }
this.switchTheme = function (theme) {
this.switchTheme = function(theme) {
switch (theme.toLowerCase()) { switch (theme.toLowerCase()) {
case 'dark': case 'dark':
$('link[data-name=theme]').attr('href', 'style/Dark.css'); $('link[data-name=theme]').attr('href', 'style/Dark.css');
@ -137,18 +99,16 @@ JamStash.service('utils', function($cookieStore, globals, model) {
default: default:
break; break;
} }
}; }
// HTML5 // HTML5
this.browserStorageCheck = function() { this.browserStorageCheck = function () {
if (typeof(localStorage) == 'undefined') { if (typeof (localStorage) == 'undefined') {
return false; return false;
} else { } else {
return true; return true;
} }
}; }
this.timeToSeconds = function (time) {
this.timeToSeconds = function(time) {
var a = time.split(':'); // split it at the colons var a = time.split(':'); // split it at the colons
var seconds; var seconds;
switch (a.length) { switch (a.length) {
@ -165,9 +125,8 @@ JamStash.service('utils', function($cookieStore, globals, model) {
break; break;
} }
return seconds; return seconds;
}; }
this.secondsToTime = function (secs) {
this.secondsToTime = function(secs) {
// secs = 4729 // secs = 4729
var times = new Array(3600, 60, 1); var times = new Array(3600, 60, 1);
var time = ''; var time = '';
@ -179,10 +138,12 @@ JamStash.service('utils', function($cookieStore, globals, model) {
// 2: 49/1 = 49 // 2: 49/1 = 49
if (tmp < 1) { if (tmp < 1) {
tmp = '00'; tmp = '00';
} else if (tmp < 10) { }
else if (tmp < 10) {
tmp = '0' + tmp; tmp = '0' + tmp;
} }
if (i === 0 && tmp == '00') {} else { if (i == 0 && tmp == '00') {
} else {
time += tmp; time += tmp;
if (i < 2) { if (i < 2) {
time += ':'; time += ':';
@ -191,30 +152,27 @@ JamStash.service('utils', function($cookieStore, globals, model) {
secs = secs % times[i]; secs = secs % times[i];
} }
return time; return time;
}; }
this.arrayObjectIndexOf = function (myArray, searchTerm, property) {
this.arrayObjectIndexOf = function(myArray, searchTerm, property) {
for (var i = 0, len = myArray.length; i < len; i++) { for (var i = 0, len = myArray.length; i < len; i++) {
if (myArray[i][property] === searchTerm) return i; if (myArray[i][property] === searchTerm) return i;
} }
return -1; return -1;
}; }
this.logObjectProperties = function (obj) {
this.logObjectProperties = function(obj) { $.each(obj, function (key, value) {
$.each(obj, function(key, value) {
var parent = key; var parent = key;
if (typeof value === "object") { if (typeof value === "object") {
$.each(value, function(key, value) { $.each(value, function (key, value) {
console.log(parent + ' > ' + key + ' : ' + value); console.log(parent + ' > ' + key + ' : ' + value);
}); });
} else { } else {
console.log(key + ' : ' + value); console.log(key + ' : ' + value);
} }
}); });
}; }
this.clickButton = function (el) {
this.clickButton = function(el) { var el = $(el);
el = $(el);
if (el) { if (el) {
var classes = $(el).attr('class').split(" "); var classes = $(el).attr('class').split(" ");
for (var i = 0, l = classes.length; i < l; ++i) { for (var i = 0, l = classes.length; i < l; ++i) {
@ -231,143 +189,86 @@ JamStash.service('utils', function($cookieStore, globals, model) {
} }
} }
} }
}; }
this.findKeyForCode = function (code) {
this.findKeyForCode = function(code) { var map = { 'keymap': [
var map = { { 'key': 'a', 'code': 65 },
'keymap': [{ { 'key': 'b', 'code': 66 },
'key': 'a', { 'key': 'c', 'code': 67 },
'code': 65 { 'key': 'd', 'code': 68 },
}, { { 'key': 'e', 'code': 69 },
'key': 'b', { 'key': 'f', 'code': 70 },
'code': 66 { 'key': 'g', 'code': 71 },
}, { { 'key': 'h', 'code': 72 },
'key': 'c', { 'key': 'i', 'code': 73 },
'code': 67 { 'key': 'j', 'code': 74 },
}, { { 'key': 'k', 'code': 75 },
'key': 'd', { 'key': 'l', 'code': 76 },
'code': 68 { 'key': 'm', 'code': 77 },
}, { { 'key': 'n', 'code': 78 },
'key': 'e', { 'key': 'o', 'code': 79 },
'code': 69 { 'key': 'p', 'code': 80 },
}, { { 'key': 'q', 'code': 81 },
'key': 'f', { 'key': 'r', 'code': 82 },
'code': 70 { 'key': 's', 'code': 83 },
}, { { 'key': 't', 'code': 84 },
'key': 'g', { 'key': 'u', 'code': 85 },
'code': 71 { 'key': 'v', 'code': 86 },
}, { { 'key': 'w', 'code': 87 },
'key': 'h', { 'key': 'x', 'code': 88 },
'code': 72 { 'key': 'y', 'code': 89 },
}, { { 'key': 'z', 'code': 90 }
'key': 'i', ]
'code': 73
}, {
'key': 'j',
'code': 74
}, {
'key': 'k',
'code': 75
}, {
'key': 'l',
'code': 76
}, {
'key': 'm',
'code': 77
}, {
'key': 'n',
'code': 78
}, {
'key': 'o',
'code': 79
}, {
'key': 'p',
'code': 80
}, {
'key': 'q',
'code': 81
}, {
'key': 'r',
'code': 82
}, {
'key': 's',
'code': 83
}, {
'key': 't',
'code': 84
}, {
'key': 'u',
'code': 85
}, {
'key': 'v',
'code': 86
}, {
'key': 'w',
'code': 87
}, {
'key': 'x',
'code': 88
}, {
'key': 'y',
'code': 89
}, {
'key': 'z',
'code': 90
}]
}; };
var keyFound = 0; var keyFound = 0;
$.each(map.keymap, function(i, mapping) { $.each(map.keymap, function (i, mapping) {
if (mapping.code === code) { if (mapping.code === code) {
keyFound = mapping.key; keyFound = mapping.key;
} }
}); });
return keyFound; return keyFound;
}; }
this.toHTML = { this.toHTML = {
on: function(str) { on: function (str) {
var a = [], var a = [],
i = 0; i = 0;
for (; i < str.length;) a[i] = str.charCodeAt(i++); for (; i < str.length; ) a[i] = str.charCodeAt(i++);
return "&#" + a.join(";&#") + ";"; return "&#" + a.join(";&#") + ";"
}, },
un: function(str) { un: function (str) {
return str.replace(/&#(x)?([^;]{1,5});?/g, return str.replace(/&#(x)?([^;]{1,5});?/g,
function(a, b, c) { function (a, b, c) {
return String.fromCharCode(parseInt(c, b ? 16 : 10)); return String.fromCharCode(parseInt(c, b ? 16 : 10))
}); })
} }
}; };
this.getParameterByName = function(name) { this.getParameterByName = function (name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)"; var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS); var regex = new RegExp(regexS);
var results = regex.exec(window.location.search); var results = regex.exec(window.location.search);
if (results === null) if (results == null)
return ""; return "";
else else
return decodeURIComponent(results[1].replace(/\+/g, " ")); return decodeURIComponent(results[1].replace(/\+/g, " "));
}; }
this.getPathFromUrl = function (url) {
this.getPathFromUrl = function(url) {
var strurl = url.toString(); var strurl = url.toString();
var u = strurl.substring(0, strurl.indexOf('?')); var u = strurl.substring(0, strurl.indexOf('?'));
return u; return u
}; }
this.setTitle = function (text) {
this.setTitle = function(text) { if (text != "") {
if (text !== "") {
document.title = text; document.title = text;
} }
}; }
var timer = 0; var timer = 0;
this.scrollTitle = function(text) { this.scrollTitle = function (text) {
var shift = { var shift = {
"left": function(a) { "left": function (a) {
a.push(a.shift()); a.push(a.shift());
}, },
"right": function(a) { "right": function (a) {
a.unshift(a.pop()); a.unshift(a.pop());
} }
}; };
@ -383,19 +284,23 @@ JamStash.service('utils', function($cookieStore, globals, model) {
} }
t.push(" "); t.push(" ");
clearInterval(timer); clearInterval(timer);
timer = setInterval(function() { timer = setInterval(function () {
var f = shift[opts.dir]; var f = shift[opts.dir];
if (f) { if (f) {
f(t); f(t);
document.title = t.join(""); document.title = t.join("");
} }
}, opts.speed); }, opts.speed);
}; /*
$.marqueeTitle({
this.parseVersionString = function(str) { text: text,
if (typeof(str) != 'string') { dir: "left",
return false; speed: 1200
});
*/
} }
this.parseVersionString = function (str) {
if (typeof (str) != 'string') { return false; }
var x = str.split('.'); var x = str.split('.');
// parse from string or default to 0 if can't parse // parse from string or default to 0 if can't parse
var maj = parseInt(x[0]) || 0; var maj = parseInt(x[0]) || 0;
@ -405,10 +310,9 @@ JamStash.service('utils', function($cookieStore, globals, model) {
major: maj, major: maj,
minor: min, minor: min,
patch: pat patch: pat
}; }
}; }
this.checkVersion = function (runningVersion, minimumVersion) {
this.checkVersion = function(runningVersion, minimumVersion) {
if (runningVersion.major >= minimumVersion.major) { if (runningVersion.major >= minimumVersion.major) {
if (runningVersion.minor >= minimumVersion.minor) { if (runningVersion.minor >= minimumVersion.minor) {
if (runningVersion.patch >= minimumVersion.patch) { if (runningVersion.patch >= minimumVersion.patch) {
@ -422,9 +326,8 @@ JamStash.service('utils', function($cookieStore, globals, model) {
} else { } else {
return false; return false;
} }
}; }
this.checkVersionNewer = function (runningVersion, newVersion) {
this.checkVersionNewer = function(runningVersion, newVersion) {
if (runningVersion.major < newVersion.major) { if (runningVersion.major < newVersion.major) {
return true; return true;
} else { } else {
@ -438,14 +341,14 @@ JamStash.service('utils', function($cookieStore, globals, model) {
} }
} }
} }
}; }
this.parseDate = function (date) {
this.parseDate = function(date) {
// input: "2012-09-23 20:00:00.0" // input: "2012-09-23 20:00:00.0"
var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
var parts = date.split(" "); var parts = date.split(" ");
var dateParts = parts[0].split("-"); var dateParts = parts[0].split("-");
var month = parseInt(dateParts[1], 10) - 1; var month = parseInt(dateParts[1], 10) - 1;
return months[month] + " " + dateParts[2] + ", " + dateParts[0]; var date = months[month] + " " + dateParts[2] + ", " + dateParts[0];
}; return date;
}
}); });

View file

@ -527,6 +527,7 @@ ul.mainlist li.item a.add:hover
margin: 0 2px 0 6px; margin: 0 2px 0 6px;
text-decoration: none; text-decoration: none;
color: #829FC0; color: #829FC0;
font-size: 14px;
} }
#BreadCrumbs a:hover #BreadCrumbs a:hover
{ {