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')) {
$location.path('/settings');
}
});
} }
]); if (!$rootScope.loggedIn && (path != 'settings' && path != 'archive')) {
$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,323 +1,288 @@
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;
$scope.itemType = 'archive'; $scope.itemType = 'archive';
$rootScope.song = []; $rootScope.song = [];
$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 () {
utils.setValue('SavedCollections', $scope.SavedCollections.join(), false);
/*
$scope.$apply(function () {
}); });
*/
$scope.writeSavedCollection = function() { globals.SavedCollections = $scope.SavedCollections;
utils.setValue('SavedCollections', $scope.SavedCollections.join(), false); }
globals.SavedCollections = $scope.SavedCollections; $scope.addSavedCollection = function (newValue) {
}; if ($scope.SavedCollections.indexOf(newValue) == -1) {
$scope.SavedCollections.push(newValue);
$scope.addSavedCollection = function(newValue) {
if ($scope.SavedCollections.indexOf(newValue) == -1) {
$scope.SavedCollections.push(newValue);
$scope.writeSavedCollection();
}
};
$scope.deleteSavedCollection = function(index) {
$scope.SavedCollections.splice(index, 1);
$scope.writeSavedCollection(); $scope.writeSavedCollection();
}; }
}
$scope.selectedCollection = null; $scope.deleteSavedCollection = function (index) {
$scope.SavedCollections.splice(index, 1);
$scope.$watch("selectedCollection", function(newValue, oldValue) { $scope.writeSavedCollection();
if (newValue !== oldValue) { }
$scope.addSavedCollection(newValue); $scope.selectedCollection;
$scope.$watch("selectedCollection", function (newValue, oldValue) {
if (newValue !== oldValue) {
$scope.addSavedCollection(newValue);
}
});
$scope.setupDemoCollections = function () {
var demo = ["YonderMountainStringBand", "GreenskyBluegrass"];
angular.forEach(demo, function (item, key) {
if ($scope.SavedCollections.indexOf(item) == -1) {
$scope.SavedCollections.push(item);
} }
}); });
}
$scope.archiveUrl = 'https://archive.org/';
$scope.setupDemoCollections = function() { /* Filter */
var demo = ["YonderMountainStringBand", "GreenskyBluegrass"]; $scope.selectedArchiveAlbumSort = "date desc";
angular.forEach(demo, function(item, key) { $scope.ArchiveAlbumSort = [
if ($scope.SavedCollections.indexOf(item) == -1) { 'addeddate desc',
$scope.SavedCollections.push(item); 'addeddate asc',
} 'avg_rating desc',
}); 'avg_rating asc',
}; 'createdate desc',
'createdate asc',
$scope.archiveUrl = 'https://archive.org/'; 'date desc',
'date asc',
/* Filter */ 'downloads desc',
$scope.selectedArchiveAlbumSort = "date desc"; 'downloads asc',
'num_reviews desc',
$scope.ArchiveAlbumSort = [ 'num_reviews asc',
'addeddate desc', 'publicdate desc',
'addeddate asc', 'publicdate asc',
'avg_rating desc', 'stars desc',
'avg_rating asc', 'stars asc'
'createdate desc', ],
'createdate asc', $scope.$watch("selectedArchiveAlbumSort", function (newValue, oldValue) {
'date desc', if (utils.getValue('AlbumSort') != newValue) {
'date asc', if (typeof newValue != 'undefined') {
'downloads desc', utils.setValue('AlbumSort', newValue, true);
'downloads asc',
'num_reviews desc',
'num_reviews asc',
'publicdate desc',
'publicdate asc',
'stars desc',
'stars asc'
];
$scope.$watch("selectedArchiveAlbumSort", function(newValue, oldValue) {
if (utils.getValue('AlbumSort') != newValue) {
if (typeof newValue != 'undefined') {
utils.setValue('AlbumSort', newValue, true);
} else {
utils.setValue('AlbumSort', null, true);
}
//alert(newValue);
$scope.getAlbums('');
}
});
$scope.getYears = function(startYear) {
var currentYear = new Date().getFullYear(),
years = [];
startYear = startYear || 1950;
while (startYear <= currentYear) {
years.push(startYear++);
}
return years;
};
$scope.Years = $scope.getYears();
$scope.filter = {
Year: "",
Source: "",
Description: ""
};
$scope.filterSave = function() {
if ($scope.selectedArtist) {
$scope.getAlbums('', '');
}
};
/* End Filter */
$scope.getAlbums = function(name, identifier) {
var url = $scope.archiveUrl + 'advancedsearch.php?q=';
if (name !== '') {
$scope.selectedArtist = name;
url += 'collection:(' + name + ') AND format:(MP3)';
} else if ($scope.selectedArtist) {
url += 'collection:(' + $scope.selectedArtist + ') AND format:(MP3)';
} else { } else {
url += 'identifier:(' + identifier + ')'; utils.setValue('AlbumSort', null, true);
} }
//alert(newValue);
$scope.getAlbums('');
}
});
$scope.getYears = function (startYear) {
var currentYear = new Date().getFullYear(), years = [];
startYear = startYear || 1950;
while (startYear <= currentYear) {
years.push(startYear++);
}
return years;
}
$scope.Years = $scope.getYears(),
$scope.filter = {
Year: "",
Source: "",
Description: ""
};
$scope.filterSave = function () {
if ($scope.selectedArtist) {
$scope.getAlbums('', '');
}
}
/* End Filter */
var map = function(data) { /*
var song = data; $scope.getArtists = function (data) {
var coverartthumb, coverartfull, starred; var map = function (data) {
var url = $scope.archiveUrl + 'details/' + song.identifier; return new model.Artist('', data);
coverartthumb = 'images/albumdefault_50.jpg'; };
coverartfull = 'images/albumdefault_160.jpg'; angular.forEach($scope.SavedCollections, function (item, key) {
if (parseInt(song.avg_rating) == 5) { $scope.artist.push(map(item));
starred = true; });
};
*/
$scope.getAlbums = function (name, identifier) {
var url = $scope.archiveUrl + 'advancedsearch.php?q=';
if (name != '') {
$scope.selectedArtist = name;
url += 'collection:(' + name + ') AND format:(MP3)';
} else if ($scope.selectedArtist) {
url += 'collection:(' + $scope.selectedArtist + ') AND format:(MP3)';
} else {
url += 'identifier:(' + identifier + ')';
}
var map = function (data) {
var song = data;
var coverartthumb, coverartfull, starred;
var url = $scope.archiveUrl + 'details/' + song.identifier;
coverartthumb = 'images/albumdefault_50.jpg';
coverartfull = 'images/albumdefault_160.jpg';
if (parseInt(song.avg_rating) == 5) { starred = true; } else { starred = false; }
//var description = '<b>Details</b><br />';
var description = '<b>Source</b>: ' + song.source + '<br />';
description += '<b>Date</b>: ' + song.date + '<br />';
description += typeof song.publisher != 'undefined' ? '<b>Transferer</b>: ' + song.publisher + '<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 />' : '';
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) {
url += ' AND source:(' + $scope.filter.Source + ')';
}
if ($scope.filter.Year) {
if (parseInt($scope.filter.Year)) {
url += ' AND year:(' + $scope.filter.Year + ')';
}
}
if ($scope.filter.Description) {
url += ' AND description:(' + $scope.filter.Description + ')';
}
if ($scope.selectedArchiveAlbumSort) {
url += '&sort[]=' + $scope.selectedArchiveAlbumSort;
}
url += '&fl[]=avg_rating,collection,date,description,downloads,headerImage,identifier,publisher,publicdate,source,subject,title,year';
url += '&rows=50&page=1&output=json';
$.ajax({
url: url,
method: 'GET',
dataType: $scope.Protocol,
timeout: globals.settings.Timeout,
success: function (data) {
var items = [];
if (data["response"].docs.length > 0) {
items = data["response"].docs;
//alert(JSON.stringify(data["response"]));
$scope.album = [];
$rootScope.song = [];
angular.forEach(items, function (item, key) {
$scope.album.push(map(item));
});
$scope.$apply();
notifications.updateMessage($scope.album.length, true);
} else { } else {
starred = false; notifications.updateMessage("Sorry :(", true);
} }
//var description = '<b>Details</b><br />'; },
var description = '<b>Source</b>: ' + song.source + '<br />'; error: function () {
description += '<b>Date</b>: ' + song.date + '<br />'; alert('Archive.org service down :(');
description += typeof song.publisher != 'undefined' ? '<b>Transferer</b>: ' + song.publisher + '<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 />' : '';
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) {
url += ' AND source:(' + $scope.filter.Source + ')';
} }
});
if ($scope.filter.Year) { };
if (parseInt($scope.filter.Year)) { utils.mapSong = function (key, song, server, dir, identifier, coverart) {
url += ' AND year:(' + $scope.filter.Year + ')'; var url, time, track, title, rating, starred, contenttype, suffix;
var specs = ''
if (song.format == 'VBR MP3') {
url = 'http://' + server + dir + key;
if (typeof song.bitrate == 'undefined' || typeof song.format == 'undefined') { specs = '&nbsp;'; } else { specs = song.bitrate + 'kbps, ' + song.format.toLowerCase(); }
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, '');
}
};
$scope.getSongs = function (id, action) {
$scope.selectedAlbum = id;
var url = $scope.archiveUrl + 'details/' + id + '?output=json';
$.ajax({
url: url,
method: 'GET',
dataType: $scope.Protocol,
timeout: globals.settings.Timeout,
success: function (data) {
var coverart = '';
var server = data.server;
var dir = data.dir;
var identifier = data.metadata.identifier[0];
if (typeof data.misc.image != 'undefined') {
coverart = data.misc.image;
} }
} var items = data.files;
if (action == 'add') {
if ($scope.filter.Description) { angular.forEach(items, function (item, key) {
url += ' AND description:(' + $scope.filter.Description + ')'; var song = utils.mapSong(key, item, server, dir, identifier, coverart);
} if (song) {
$rootScope.queue.push(song);
if ($scope.selectedArchiveAlbumSort) { }
url += '&sort[]=' + $scope.selectedArchiveAlbumSort; });
} $rootScope.showQueue();
notifications.updateMessage(Object.keys(items).length + ' Song(s) Added to Queue', true);
url += '&fl[]=avg_rating,collection,date,description,downloads,headerImage,identifier,publisher,publicdate,source,subject,title,year'; $scope.$apply();
url += '&rows=50&page=1&output=json'; } else if (action == 'play') {
$rootScope.queue = [];
$.ajax({ angular.forEach(items, function (item, key) {
url: url, var song = utils.mapSong(key, item, server, dir, identifier, coverart);
method: 'GET', if (song) {
dataType: $scope.Protocol, $rootScope.queue.push(song);
timeout: globals.settings.Timeout, }
success: function(data) { });
var items = []; var next = $rootScope.queue[0];
if (data.response.docs.length > 0) { $scope.$apply(function () {
items = data.response.docs; $rootScope.playSong(false, next);
$scope.album = []; });
$rootScope.song = []; $rootScope.showQueue();
angular.forEach(items, function(item, key) { notifications.updateMessage(Object.keys(items).length + ' Song(s) Added to Queue', true);
$scope.album.push(map(item));
});
$scope.$apply();
notifications.updateMessage($scope.album.length, true);
} else {
notifications.updateMessage("Sorry :(", true);
}
},
error: function() {
alert('Archive.org service down :(');
}
});
};
utils.mapSong = function(key, song, server, dir, identifier, coverart) {
var url, time, track, title, rating, starred, contenttype, suffix;
var specs = '';
if (song.format == 'VBR MP3') {
url = 'http://' + server + dir + key;
if (typeof song.bitrate == 'undefined' || typeof song.format == 'undefined') {
specs = '&nbsp;';
} else { } else {
specs = song.bitrate + 'kbps, ' + song.format.toLowerCase(); $scope.album = [];
$rootScope.song = [];
angular.forEach(items, function (item, key) {
var song = utils.mapSong(key, item, server, dir, identifier, coverart);
if (song) {
$rootScope.song.push(song);
}
});
$scope.$apply();
} }
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, '');
} }
}; });
};
$scope.getSongs = function(id, action) { $scope.addSongsToQueue = function () {
$scope.selectedAlbum = id; if ($scope.selectedSongs.length > 0) {
var url = $scope.archiveUrl + 'details/' + id + '?output=json'; angular.forEach($scope.selectedSongs, function (item, key) {
$.ajax({ $scope.queue.push(item);
url: url,
method: 'GET',
dataType: $scope.Protocol,
timeout: globals.settings.Timeout,
success: function(data) {
var coverart = '';
var server = data.server;
var dir = data.dir;
var identifier = data.metadata.identifier[0];
if (typeof data.misc.image != 'undefined') {
coverart = data.misc.image;
}
var items = data.files;
if (action == 'add') {
angular.forEach(items, function(item, key) {
var song = utils.mapSong(key, item, server, dir, identifier, coverart);
if (song) {
$rootScope.queue.push(song);
}
});
$rootScope.showQueue();
notifications.updateMessage(Object.keys(items).length + ' Song(s) Added to Queue', true);
$scope.$apply();
} else if (action == 'play') {
$rootScope.queue = [];
angular.forEach(items, function(item, key) {
var song = utils.mapSong(key, item, server, dir, identifier, coverart);
if (song) {
$rootScope.queue.push(song);
}
});
var next = $rootScope.queue[0];
$scope.$apply(function() {
$rootScope.playSong(false, next);
});
$rootScope.showQueue();
notifications.updateMessage(Object.keys(items).length + ' Song(s) Added to Queue', true);
} else {
$scope.album = [];
$rootScope.song = [];
angular.forEach(items, function(item, key) {
var song = utils.mapSong(key, item, server, dir, identifier, coverart);
if (song) {
$rootScope.song.push(song);
}
});
$scope.$apply();
}
}
});
};
$scope.addSongsToQueue = function() {
if ($scope.selectedSongs.length > 0) {
angular.forEach($scope.selectedSongs, function(item, key) {
$scope.queue.push(item);
item.selected = false;
});
$rootScope.showQueue();
notifications.updateMessage($scope.selectedSongs.length + ' Song(s) Added to Queue', true);
}
};
$scope.scrollToTop = function() {
$('#Artists').stop().scrollTo('#auto', 400);
};
$scope.selectAll = function() {
angular.forEach($rootScope.song, function(item, key) {
$scope.selectedSongs.push(item);
item.selected = true;
});
};
$scope.selectNone = function() {
angular.forEach($rootScope.song, function(item, key) {
$scope.selectedSongs = [];
item.selected = false; item.selected = false;
}); });
}; $rootScope.showQueue();
notifications.updateMessage($scope.selectedSongs.length + ' Song(s) Added to Queue', true);
/* Launch on Startup */
if ($routeParams.artist) {
if ($routeParams.album) {
//collection:(GreenskyBluegrass) AND format:(MP3) AND identifier:(gsbg2013-09-20.flac16)
$scope.getAlbums('', $routeParams.album);
} else {
$scope.getAlbums($routeParams.artist, '');
}
$scope.addSavedCollection($routeParams.artist);
} }
/* End Startup */ }
}); $scope.scrollToTop = function () {
$('#Artists').stop().scrollTo('#auto', 400);
}
$scope.selectAll = function () {
angular.forEach($rootScope.song, function (item, key) {
$scope.selectedSongs.push(item);
item.selected = true;
});
}
$scope.selectNone = function () {
angular.forEach($rootScope.song, function (item, key) {
$scope.selectedSongs = [];
item.selected = false;
});
}
/* Launch on Startup */
if ($routeParams.artist) {
if ($routeParams.album) {
//collection:(GreenskyBluegrass) AND format:(MP3) AND identifier:(gsbg2013-09-20.flac16)
$scope.getAlbums('', $routeParams.album);
} else {
$scope.getAlbums($routeParams.artist, '');
}
$scope.addSavedCollection($routeParams.artist);
}
/* End Startup */
});

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,244 +1,231 @@
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) {
if (globals.settings.Debug) { console.log("LOAD PLAYLISTS"); }
$.ajax({
url: globals.BaseURL() + '/getPlaylists.view?' + globals.BaseParams(),
method: 'GET',
dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout,
success: function (data) {
if (data["subsonic-response"].playlists.playlist !== undefined) {
var items = [];
if (data["subsonic-response"].playlists.playlist.length > 0) {
items = data["subsonic-response"].playlists.playlist;
} else {
items[0] = data["subsonic-response"].playlists.playlist;
}
angular.forEach(items, function (item, key) {
if (item.owner == globals.settings.Username) {
$scope.playlists.push(item);
} else if (item.public) {
$scope.playlistsPublic.push(item);
}
});
$scope.$apply();
}
} }
}); });
}
$scope.getPlaylists = function(refresh) { $scope.getPlaylist = function (id, action) {
if (globals.settings.Debug) { $rootScope.selectedAutoPlaylist = null;
console.log("LOAD PLAYLISTS"); $rootScope.selectedPlaylist = id;
} $.ajax({
$.ajax({ url: globals.BaseURL() + '/getPlaylist.view?' + globals.BaseParams() + '&id=' + id,
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 (typeof data["subsonic-response"].playlist.entry != 'undefined') {
if (data["subsonic-response"].playlists.playlist !== undefined) { var items = [];
var items = []; var playlist = data["subsonic-response"].playlist;
if (data["subsonic-response"].playlists.playlist.length > 0) { if (playlist.entry.length > 0) {
items = data["subsonic-response"].playlists.playlist; items = playlist.entry;
} else { } else {
items[0] = data["subsonic-response"].playlists.playlist; items[0] = playlist.entry;
} }
angular.forEach(items, function(item, key) { if (action == 'add') {
if (item.owner == globals.settings.Username) { angular.forEach(items, function (item, key) {
$scope.playlists.push(item); $rootScope.queue.push(utils.mapSong(item));
} else if (item.public) { });
$scope.playlistsPublic.push(item); $scope.$apply();
} $rootScope.showQueue();
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else if (action == 'play') {
$rootScope.queue = [];
angular.forEach(items, function (item, key) {
$rootScope.queue.push(utils.mapSong(item));
});
var next = $rootScope.queue[0];
$scope.$apply(function () {
$rootScope.playSong(false, next);
});
$rootScope.showQueue();
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else {
$scope.album = [];
$rootScope.song = [];
angular.forEach(items, function (item, key) {
$rootScope.song.push(utils.mapSong(item));
}); });
$scope.$apply(); $scope.$apply();
} }
} else {
$rootScope.song = [];
} }
}); }
}; });
}
$scope.getPlaylist = function(id, action) { $scope.getStarred = function (action, type) {
$rootScope.selectedAutoPlaylist = null; var size = globals.settings.AutoPlaylistSize;
$rootScope.selectedPlaylist = id; $rootScope.selectedPlaylist = null;
$rootScope.selectedAutoPlaylist = 'starred';
$.ajax({
url: globals.BaseURL() + '/getStarred.view?' + globals.BaseParams() + '&size=' + size,
method: 'GET',
dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout,
success: function (data) {
if (typeof data["subsonic-response"].starred !== 'undefined') {
var items = [];
switch (type) {
case 'artist':
if (typeof data["subsonic-response"].starred.artist !== 'undefined') {
if (data["subsonic-response"].starred.artist.length > 0) {
items = data["subsonic-response"].starred.artist;
} else {
items[0] = data["subsonic-response"].starred.artist;
}
}
break;
case 'album':
if (typeof data["subsonic-response"].starred.album !== 'undefined') {
if (data["subsonic-response"].starred.album.length > 0) {
items = data["subsonic-response"].starred.album;
} else {
items[0] = data["subsonic-response"].starred.album;
}
}
break;
case 'song':
if (typeof data["subsonic-response"].starred.song !== 'undefined') {
if (data["subsonic-response"].starred.song.length > 0) {
items = data["subsonic-response"].starred.song;
} else {
items[0] = data["subsonic-response"].starred.song;
}
if (action == 'add') {
angular.forEach(items, function (item, key) {
$rootScope.queue.push(utils.mapSong(item));
});
$scope.$apply();
$rootScope.showQueue();
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else if (action == 'play') {
$rootScope.queue = [];
angular.forEach(items, function (item, key) {
$rootScope.queue.push(utils.mapSong(item));
});
var next = $rootScope.queue[0];
$scope.$apply(function () {
$rootScope.playSong(false, next);
});
$rootScope.showQueue();
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else {
$rootScope.song = [];
angular.forEach(items, function (item, key) {
$rootScope.song.push(utils.mapSong(item));
});
$scope.$apply();
}
}
break;
default:
break;
}
}
}
});
}
$scope.newPlaylist = function (data, event) {
var reply = prompt("Choose a name for your new playlist.", "");
if (reply != 'null' && reply != null && reply != '') {
$.ajax({ $.ajax({
url: globals.BaseURL() + '/getPlaylist.view?' + globals.BaseParams() + '&id=' + id, 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) {
if (typeof data["subsonic-response"].playlist.entry != 'undefined') { loadPlaylists(true);
var items = [];
var playlist = data["subsonic-response"].playlist;
if (playlist.entry.length > 0) {
items = playlist.entry;
} else {
items[0] = playlist.entry;
}
if (action == 'add') {
angular.forEach(items, function(item, key) {
$rootScope.queue.push(utils.mapSong(item));
});
$scope.$apply();
$rootScope.showQueue();
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else if (action == 'play') {
$rootScope.queue = [];
angular.forEach(items, function(item, key) {
$rootScope.queue.push(utils.mapSong(item));
});
var next = $rootScope.queue[0];
$scope.$apply(function() {
$rootScope.playSong(false, next);
});
$rootScope.showQueue();
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else {
$scope.album = [];
$rootScope.song = [];
angular.forEach(items, function(item, key) {
$rootScope.song.push(utils.mapSong(item));
});
$scope.$apply();
}
} else {
$rootScope.song = [];
}
} }
}); });
}; }
}
$scope.getStarred = function(action, type) { $scope.deletePlaylist = function () {
var size = globals.settings.AutoPlaylistSize; if ($rootScope.selectedPlaylist != null) {
$rootScope.selectedPlaylist = null; var id = $rootScope.selectedPlaylist;
$rootScope.selectedAutoPlaylist = 'starred'; if (utils.confirmDelete('Are you sure you want to delete the selected playlist?')) {
$.ajax({
url: globals.BaseURL() + '/getStarred.view?' + globals.BaseParams() + '&size=' + size,
method: 'GET',
dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout,
success: function(data) {
if (typeof data["subsonic-response"].starred !== 'undefined') {
var items = [];
switch (type) {
case 'artist':
if (typeof data["subsonic-response"].starred.artist !== 'undefined') {
if (data["subsonic-response"].starred.artist.length > 0) {
items = data["subsonic-response"].starred.artist;
} else {
items[0] = data["subsonic-response"].starred.artist;
}
}
break;
case 'album':
if (typeof data["subsonic-response"].starred.album !== 'undefined') {
if (data["subsonic-response"].starred.album.length > 0) {
items = data["subsonic-response"].starred.album;
} else {
items[0] = data["subsonic-response"].starred.album;
}
}
break;
case 'song':
if (typeof data["subsonic-response"].starred.song !== 'undefined') {
if (data["subsonic-response"].starred.song.length > 0) {
items = data["subsonic-response"].starred.song;
} else {
items[0] = data["subsonic-response"].starred.song;
}
if (action == 'add') {
angular.forEach(items, function(item, key) {
$rootScope.queue.push(utils.mapSong(item));
});
$scope.$apply();
$rootScope.showQueue();
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else if (action == 'play') {
$rootScope.queue = [];
angular.forEach(items, function(item, key) {
$rootScope.queue.push(utils.mapSong(item));
});
var next = $rootScope.queue[0];
$scope.$apply(function() {
$rootScope.playSong(false, next);
});
$rootScope.showQueue();
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else {
$rootScope.song = [];
angular.forEach(items, function(item, key) {
$rootScope.song.push(utils.mapSong(item));
});
$scope.$apply();
}
}
break;
default:
break;
}
}
}
});
};
$scope.newPlaylist = function(data, event) {
var reply = prompt("Choose a name for your new playlist.", "");
if (reply !== 'null' && reply !== null && reply !== '') {
$.ajax({ $.ajax({
url: globals.BaseURL() + '/createPlaylist.view?' + globals.BaseParams() + '&name=' + reply, url: globals.BaseURL() + '/deletePlaylist.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) {
loadPlaylists(true); $scope.getPlaylists();
} }
}); });
} }
}; }
}
$scope.deletePlaylist = function() { $scope.savePlaylist = function () {
if ($rootScope.selectedPlaylist !== null) { if ($rootScope.selectedPlaylist() != null) {
var id = $rootScope.selectedPlaylist; var id = $rootScope.selectedPlaylist().id();
if (utils.confirmDelete('Are you sure you want to delete the selected playlist?')) { var songs = [];
$.ajax({ ko.utils.arrayForEach($rootScope.song(), function (item) {
url: globals.BaseURL() + '/deletePlaylist.view?' + globals.BaseParams() + '&id=' + id, songs.push(item.id);
method: 'GET',
dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout,
success: function(data) {
$scope.getPlaylists();
}
});
}
}
};
$scope.savePlaylist = function() {
if ($rootScope.selectedPlaylist() !== null) {
var id = $rootScope.selectedPlaylist().id();
var songs = [];
ko.utils.arrayForEach($rootScope.song(), function(item) {
songs.push(item.id);
});
if (songs.length > 0) {
$.ajax({
type: 'GET',
url: globals.BaseURL() + '/createPlaylist.view?' + globals.BaseParams(),
dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout,
data: {
playlistId: id,
songId: songs
},
success: function() {
$scope.getPlaylist(id);
notifications.updateMessage('Playlist Updated!', true);
},
traditional: true // Fixes POST with an array in JQuery 1.4
});
}
}
};
$scope.removeSelectedSongs = function(data, event) {
ko.utils.arrayForEach($scope.selectedSongs(), function(item) {
$rootScope.song.remove(item);
}); });
}; if (songs.length > 0) {
$.ajax({
type: 'GET',
url: globals.BaseURL() + '/createPlaylist.view?' + globals.BaseParams(),
dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout,
data: { playlistId: id, songId: songs },
success: function () {
$scope.getPlaylist(id);
notifications.updateMessage('Playlist Updated!', true);
},
traditional: true // Fixes POST with an array in JQuery 1.4
});
}
}
}
$scope.removeSelectedSongs = function (data, event) {
ko.utils.arrayForEach($scope.selectedSongs(), function (item) {
$rootScope.song.remove(item);
});
}
/* End Playlists */
/* End Playlists */ /* Launch on Startup */
$scope.getPlaylists();
/* Launch on Startup */ //$scope.getMusicFolders();
$scope.getPlaylists(); $scope.getGenres();
//$scope.getMusicFolders(); /* End Startup */
$scope.getGenres(); });
/* End Startup */
});

View file

@ -1,142 +1,112 @@
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) { $.ajax({
console.log("LOAD PODCASTS"); url: globals.BaseURL() + '/getPodcasts.view?' + globals.BaseParams(),
method: 'GET',
dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout,
success: function (data) {
if (data["subsonic-response"].podcasts.channel !== undefined) {
var items = [];
if (data["subsonic-response"].podcasts.channel.length > 0) {
items = data["subsonic-response"].podcasts.channel;
} else {
items[0] = data["subsonic-response"].podcasts.channel;
}
$scope.podcasts = items;
$scope.$apply();
}
} }
$.ajax({ });
url: globals.BaseURL() + '/getPodcasts.view?' + globals.BaseParams(), }
method: 'GET', $scope.getPodcast = function (id, action) {
dataType: globals.settings.Protocol, $scope.selectedPodcast = id;
timeout: globals.settings.Timeout, var map = function (data) {
success: function(data) { var song = data;
if (data["subsonic-response"].podcasts.channel !== undefined) { var url, track, rating, starred, contenttype, suffix, description;
var items = []; var specs = '', coverartthumb = '', coverartfull = '';
if (data["subsonic-response"].podcasts.channel.length > 0) { if (typeof song.coverArt != 'undefined') {
items = data["subsonic-response"].podcasts.channel; coverartthumb = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&size=60&id=' + song.coverArt;
} else { coverartfull = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&id=' + song.coverArt;
items[0] = data["subsonic-response"].podcasts.channel; }
} if (typeof song.description == 'undefined') { description = ''; } else { description = song.description; }
$scope.podcasts = items; if (typeof song.track == 'undefined') { track = '&nbsp;'; } else { track = song.track; }
$scope.$apply(); 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);
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);
}
$.ajax({
url: globals.BaseURL() + '/getPodcasts.view?' + globals.BaseParams(),
method: 'GET',
dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout,
success: function (data) {
if (data["subsonic-response"].podcasts.channel !== undefined) {
var podcasts = [];
if (data["subsonic-response"].podcasts.channel.length > 0) {
podcasts = data["subsonic-response"].podcasts.channel;
} else {
podcasts[0] = data["subsonic-response"].podcasts.channel;
} }
} var items = [];
}); $.each(podcasts, function (i, item) {
}; if (item.id == id) {
items = item.episode;
$scope.getPodcast = function(id, action) {
$scope.selectedPodcast = id;
var map = function(data) {
var song = data;
var url, track, rating, starred, contenttype, suffix, description;
var specs = '',
coverartthumb = '',
coverartfull = '';
if (typeof song.coverArt != 'undefined') {
coverartthumb = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&size=60&id=' + song.coverArt;
coverartfull = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&id=' + song.coverArt;
}
if (typeof song.description == 'undefined') {
description = '';
} else {
description = song.description;
}
if (typeof song.track == 'undefined') {
track = '&nbsp;';
} 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);
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);
};
$.ajax({
url: globals.BaseURL() + '/getPodcasts.view?' + globals.BaseParams(),
method: 'GET',
dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout,
success: function(data) {
if (data["subsonic-response"].podcasts.channel !== undefined) {
var podcasts = [];
if (data["subsonic-response"].podcasts.channel.length > 0) {
podcasts = data["subsonic-response"].podcasts.channel;
} else {
podcasts[0] = data["subsonic-response"].podcasts.channel;
} }
var items = []; });
$.each(podcasts, function(i, item) {
if (item.id == id) {
items = item.episode;
}
});
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));
} }
}); });
$scope.$apply(); $scope.$apply();
$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 == '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();
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true); notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} 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));
} }
}); });
$scope.$apply(); $scope.$apply();
}
} }
} }
} }
}); }
}; });
}
/* 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,107 +1,84 @@
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 = [
{ id: 10000, name: 10 },
{ id: 20000, name: 20 },
{ id: 30000, 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.Themes = ["Default", "Dark"];
$scope.SearchTypes = globals.SearchTypes;
$scope.Layouts = globals.Layouts;
$scope.Timeouts = [{ $scope.$watch('settings.HideAZ', function () {
id: 10000, if (globals.settings.HideAZ) {
name: 10 $('#AZIndex').hide();
}, { } else {
id: 20000, $('#AZIndex').show();
name: 20 }
}, {
id: 30000,
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.Themes = ["Default", "Dark"];
$scope.SearchTypes = globals.SearchTypes;
$scope.Layouts = globals.Layouts;
$scope.$watch('settings.HideAZ', function() {
if (globals.settings.HideAZ) {
$('#AZIndex').hide();
} else {
$('#AZIndex').show();
}
});
$scope.reset = function() {
utils.setValue('Settings', null, true);
$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) {
notifications.requestPermissionIfRequired();
if (!notifications.hasNotificationPermission()) {
alert('HTML5 Notifications are not available for your current browser, Sorry :(');
}
}
if (globals.settings.NotificationNowPlaying) {
notifications.requestPermissionIfRequired();
if (!notifications.hasNotificationPermission()) {
alert('HTML5 Notifications are not available for your current browser, Sorry :(');
}
}
if (globals.settings.SaveTrackPosition) {
//saveTrackPosition();
} else {
//deleteCurrentPlaylist();
}
if (globals.settings.Theme) {
utils.switchTheme(globals.settings.Theme);
}
utils.setValue('Settings', $scope.settings, true);
notifications.updateMessage('Settings Updated!', true);
$scope.loadSettings();
if (globals.settings.Server !== '' && globals.settings.Username !== '' && globals.settings.Password !== '') {
$scope.ping();
}
};
json.getChangeLog(function(data) {
$scope.changeLog = data.slice(0, 10);
});
$scope.changeLogShowMore = function() {
json.getChangeLog(function(data) {
$scope.changeLog = data;
});
};
$scope.setupDemo = function() {
var Username = "android-guest";
var Password = "guest";
var Server = "http://subsonic.org/demo";
var Tab = "tabLibrary";
if (utils.confirmDelete("Do you want to connect to the Subsonic Demo server?")) {
globals.settings.Username = Username;
globals.settings.Password = Password;
globals.settings.Server = Server;
//$scope.save();
$location.url('/library');
}
};
/* Load on Startup */
/* End Startup */
}); });
$scope.reset = function () {
utils.setValue('Settings', null, true);
$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 ($scope.settings.NotificationSong) {
notifications.requestPermissionIfRequired();
if (!notifications.hasNotificationPermission()) {
alert('HTML5 Notifications are not available for your current browser, Sorry :(');
}
}
if ($scope.settings.NotificationNowPlaying) {
notifications.requestPermissionIfRequired();
if (!notifications.hasNotificationPermission()) {
alert('HTML5 Notifications are not available for your current browser, Sorry :(');
}
}
if ($scope.settings.SaveTrackPosition) {
player.saveTrackPosition();
} else {
player.deleteCurrentQueue();
}
if ($scope.settings.Theme) {
utils.switchTheme(globals.settings.Theme);
}
utils.setValue('Settings', $scope.settings, true);
notifications.updateMessage('Settings Updated!', true);
$scope.loadSettings();
if (globals.settings.Server != '' && globals.settings.Username != '' && globals.settings.Password != '') {
$scope.ping();
}
};
json.getChangeLog(function (data) {
$scope.changeLog = data.slice(0, 10);
//notifications.updateMessage('Latest Version: ' + $scope.changeLog[0].version, true);
});
$scope.changeLogShowMore = function () {
json.getChangeLog(function (data) {
$scope.changeLog = data;
});
}
$scope.setupDemo = function () {
var Username = "android-guest";
var Password = "guest";
var Server = "http://subsonic.org/demo";
var Tab = "tabLibrary";
if (utils.confirmDelete("Do you want to connect to the Subsonic Demo server?")) {
globals.settings.Username = Username;
globals.settings.Password = Password;
globals.settings.Server = Server;
//$scope.save();
$location.url('/library');
}
}
/* Load on 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) {
getNextSong = function(previous) {
var song; var song;
if (globals.settings.Debug) { if (globals.settings.Debug) { console.log('Getting Next Song > ' + 'Queue length: ' + $rootScope.queue.length); }
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", {
@ -299,14 +271,12 @@
console.log('[jPlayer Options Info]'); console.log('[jPlayer Options Info]');
utils.logObjectProperties($(el).data("jPlayer").options); utils.logObjectProperties($(el).data("jPlayer").options);
} }
}, },
timeupdate: function(event) { timeupdate: function(event) {
// 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,
@ -378,44 +343,41 @@
content: $('#videodeck') content: $('#videodeck')
}); });
*/ */
$(this).jPlayer("setMedia", { $(this).jPlayer("setMedia", {
m4v: 'https://&id=' + id + '&salt=83132' m4v: 'https://&id=' + id + '&salt=83132'
}).jPlayer("play"); }).jPlayer("play");
$('#videooverlay').show(); $('#videooverlay').show();
}, },
swfPath: "js/jplayer", swfPath: "js/jplayer",
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,28 +126,21 @@ 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
resizeWithWindowDelay: 250, // delay calling resizeAll when window is *still* resizing resizeWithWindowDelay: 250, // delay calling resizeAll when window is *still* resizing
//, resizeWithWindowMaxDelay: 2000 // force resize every XX ms while window is being resized //, resizeWithWindowMaxDelay: 2000 // force resize every XX ms while window is being resized
//center__children: {}, //center__children: {},
//north__paneSelector: "#container", //north__paneSelector: "#container",
@ -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,38 +220,69 @@ 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,
link: function($scope, element, attrs) { link: function($scope, element, attrs) {
$scope.fancyboxOpen = function() { $scope.fancyboxOpen = 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);
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);
compiled($scope); compiled($scope);
}; };
} }
}; };
}); });
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,28 +326,23 @@ 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(
'<a class="button" download="backup.json"' + '<a class="button" download="backup.json"' +
'href="' + getUrl() + '">' + 'href="' + getUrl() + '">' +
'Download' + 'Download' +
'</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,110 +350,105 @@ 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 ($http, $compile, $http, $templateCache) { // Deferred loading
JamStash.factory('template', function($compile, $http, $templateCache) { // Deferred loading
return { return {
getCollections: function(callback) { getCollections: function (callback) {
$http.get('js/json_collections.js', { $http.get('js/json_collections.js', { cache: $templateCache }).success(callback);
cache: $templateCache
}).success(callback);
}, },
getChangeLog: function(callback) { getChangeLog: function (callback) {
$http.get('js/json_changelog.js', { $http.get('js/json_changelog.js', { cache: $templateCache }).success(callback);
cache: $templateCache
}).success(callback);
}, },
getSongs: function(callback) { getSongs: function (callback) {
templateUrl = 'js/partials/songs.html'; templateUrl = 'js/partials/songs.html';
$http.get(templateUrl, { $http.get(templateUrl, { cache: $templateCache }).success(callback);
cache: $templateCache
}).success(callback);
} }
}; }
}); });
JamStash.factory('subsonic', function ($http, globals, utils) {
JamStash.factory('subsonic', function($http, globals, utils) {
return { return {
getSongTemplate: function(callback) { 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) {
var items = [];
var song = [];
if (typeof data["subsonic-response"].directory.child != 'undefined') {
if (data["subsonic-response"].directory.child.length > 0) {
items = data["subsonic-response"].directory.child;
} else {
items[0] = data["subsonic-response"].directory.child;
}
angular.forEach(items, function(item, key) {
if (!item.isDir) {
song.push(utils.mapSong(item));
}
});
callback(song);
} }
}); });
*/
$http.get(url).success(function (data) {
var items = [];
var song = [];
if (typeof data["subsonic-response"].directory.child != 'undefined') {
if (data["subsonic-response"].directory.child.length > 0) {
items = data["subsonic-response"].directory.child;
} else {
items[0] = data["subsonic-response"].directory.child;
}
angular.forEach(items, function (item, key) {
if (!item.isDir) {
song.push(utils.mapSong(item));
}
});
callback(song);
}
});
} }
}; }
}); });
/* 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
{ {