';
-
- returnHtml += '';
- return returnHtml;
- }
-
-
-
+ ////////////////////////////// Global Variables
+ // These vars track your position within the file explorer
+ var fileExplorerArray = [];
+ var fileExplorerScrollPosition = [];
+ // Stores an array of searchable ojects
+ var currentBrowsingList = [];
+ ////////////////////////////// Login Form
// Handle login form
$('#login-form').on('submit', function(e){
e.preventDefault();
$("#login-submit").attr("disabled","disabled");
- // MSTREAMAPI.login( $('#login-username').val(), $('#login-password').val(), function(response){
- // });
+ MSTREAMAPI.login($('#login-username').val(), $('#login-password').val(), function(response, error){
+ if(error !== false){
+ // Alert the user
+ $("#login-submit").attr("disabled",false);
+ $('#login-alert').removeClass('super-hide');
+ return;
+ }
-
- var request = $.ajax({
- url: "login",
- type: "POST",
- contentType: "application/json",
- dataType: "json",
- data: JSON.stringify(
- {
- username: $('#login-username').val(),
- password: $('#login-password').val()
- }
- )
- });
-
- request.done(function( msg ) {
- $('#login-alert').toggleClass('alert');
+ $('#login-alert').toggleClass('alert');
$('#login-alert').toggleClass('success');
$('#login-alert').text('Welcome To mStream!');
- // Get the key
- var parsedResponse = msg;
- var token = parsedResponse.token;
-
// Add the token to the cookies
- Cookies.set('token', token);
+ Cookies.set('token', response.token);
+
+ // Add the token the URL calls
+ updateCurrentServer($('#login-username').val(), response.token, response.vPath)
- // Add the token the URL calls
- MSTREAMAPI.currentServer.token = token;
- MSTREAMAPI.currentServer.vPath = parsedResponse.vPath;
loadFileExplorer();
// Remove the overlay
$('.login-overlay').fadeOut( "slow" );
$("#login-submit").attr("disabled",false);
- });
-
- request.fail(function( jqXHR, textStatus ) {
- // Alert the user
- $("#login-submit").attr("disabled",false);
- $('#login-alert').removeClass('super-hide');
- });
+ });
});
-
- $.ajaxPrefilter(function( options ) {
- options.beforeSend = function (xhr) {
- xhr.setRequestHeader('x-access-token', MSTREAMAPI.currentServer.token);
- }
- });
-
-
-
-
// Determine if the user needs to log in
function testIt(){
var token = Cookies.get('token');
-
if(token){
MSTREAMAPI.currentServer.token = token;
}
-
- var request = $.ajax({
- url: "ping",
- type: "GET"
- });
-
- request.done(function( msg ) {
- // Remove login screen
- // set vPath
- var decoded = msg;
- MSTREAMAPI.currentServer.vPath = decoded.vPath;
- });
-
- request.fail(function( jqXHR, textStatus ) {
- // alert( "Request failed: " + textStatus );
- $('.login-overlay').fadeIn( "slow" );
-
- });
-
+ MSTREAMAPI.ping( function(response, error){
+ if(error !== false){
+ $('.login-overlay').fadeIn( "slow" );
+ return;
+ }
+ // set vPath
+ MSTREAMAPI.currentServer.vPath = response.vPath;
+ // Setup the filebrowser
+ loadFileExplorer();
+ });
}
testIt();
-
-
-
-////////////////////////////// Initialization code
-
- // Supported file types
- var filetypes = '["mp3","ogg","wav","m4a","flac"]';
-
- // These vars track your position within the file explorer
- var fileExplorerArray = [];
- var fileExplorerScrollPosition = [];
-
- // Setup the filebrowser
- loadFileExplorer();
-
- // TODO: This will store an array of searchable ojects
- var currentBrowsingList = [];
-
-///////////////////////////// The Now Playing Column
-
-
-
-
-
-
-// clear the playlist
- $("#clear").click(function() {
- MSTREAM.clearPlaylist();
- });
-
-
-// when you click an mp3, add it to the now playling playlist
+ //////////////////////////////// Administrative stuff
+ // when you click an mp3, add it to the now playling playlist
$("#filelist").on('click', 'div.filez', function() {
MSTREAM.addSongWizard($(this).data("file_location"));
});
+ // Handle panel stuff
+ function resetPanel(panelName, className){
+ $('#filelist').empty();
+ $('.directoryTitle').hide();
+ $('#filelist').removeClass('scrollBoxHeight1');
+ $('#filelist').removeClass('scrollBoxHeight2');
+ $('#filelist').addClass(className);
+ $('.panel_one_name').html(panelName);
+ }
+ function boilerplateFailure(response, error){
+ $('#filelist').empty();
+ $('#filelist').html('
Call Failed
');
+ }
-// Adds file to the now playing playlist
-// There is no longer addfile1
- // function addFile2(file_location){
- // var raw_location = file_location;
- //
- // if(MSTREAMAPI.currentServer.vPath){
- // file_location = MSTREAMAPI.currentServer.vPath + '/' + file_location;
- // }
- //
- // if( MSTREAMAPI.currentServer.token){
- // file_location = file_location + '?token=' + MSTREAMAPI.currentServer.token;
- // }
- //
- // MSTREAM.addSong({
- // url: file_location,
- // filepath: raw_location
- // });
- // }
-
-
- // when you click 'add directory', add entire directory to the playlist
- $("#addall").on('click', function() {
- //make an array of all the mp3 files in the curent directory
- var elems = document.getElementsByClassName('filez');
- var arr = jQuery.makeArray(elems);
-
- //loop through array and add each file to the playlist
- $.each( arr, function() {
- MSTREAM.addSongWizard($(this).data("file_location"));
- });
- });
-
-
- // Remove item from Now Playling playlist
- $('body').on('click', 'a.closeit', function(e){
- $(this).parent().remove();
- });
-
-
-
-
-
-
-///////////////////////////////////////// File Explorer
+ // clear the playlist
+ $("#clear").on('click', function() {
+ MSTREAM.clearPlaylist();
+ });
+ /////////////////////////////////////// File Explorer
function loadFileExplorer(){
-
- $('.directoryTitle').hide();
- $('#directory_bar').show();
-
- $('.panel_one_name').html('File Explorer');
+ resetPanel('File Explorer', 'scrollBoxHeight1');
+ $('#directory_bar').show();
// Reset file explorer vars
fileExplorerArray = [];
fileExplorerScrollPosition = [];
- $('#filelist').removeClass('scrollBoxHeight1');
- $('#filelist').removeClass('scrollBoxHeight2');
- $('#filelist').addClass('scrollBoxHeight1');
-
//send this directory to be parsed and displayed
senddir(0);
-
}
-// Load up the file explorer
+ // Load up the file explorer
$('.get_file_explorer').on('click', loadFileExplorer);
-// when you click on a directory, go to that directory
+ // when you click on a directory, go to that directory
$("#filelist").on('click', 'div.dirz', function() {
//get the id of that class
var nextDir = $(this).attr("id");
fileExplorerArray.push(nextDir);
// Save the scroll position
- var scrollPosition = $('.testScroll').scrollTop();
+ var scrollPosition = $('#filelist').scrollTop();
fileExplorerScrollPosition.push(scrollPosition);
- //pass this value along
+ // pass this value along
senddir(0);
});
-// when you click the back directory
+ // when you click the back directory
$(".backButton").on('click', function() {
if(fileExplorerArray.length != 0){
// remove the last item in the array
@@ -308,10 +131,7 @@ $(document).ready(function(){
}
});
-
-
-
-// send a new directory to be parsed.
+ // send a new directory to be parsed.
function senddir(scrollPosition){
// Construct the directory string
var directoryString = "";
@@ -319,28 +139,25 @@ $(document).ready(function(){
directoryString += fileExplorerArray[i] + "/";
}
- MSTREAMAPI.dirparser(directoryString, false, function(response){
- // TODO: Check for failure
-
+ MSTREAMAPI.dirparser(directoryString, false, function(response, error){
+ if(error !== false){
+ boilerplateFailure(response, error);
+ }
// Set any directory views
$('.directoryName').html('/' + directoryString);
// hand this data off to be printed on the page
printdir(response);
// Set scroll postion
- $('.testScroll').scrollTop(scrollPosition);
+ $('#filelist').scrollTop(scrollPosition);
});
}
-
-// function that will recieve JSON array of a directory listing. It will then make a list of the directory and tack on classes for functionality
+ // function that will recieve JSON array of a directory listing. It will then make a list of the directory and tack on classes for functionality
function printdir(response){
- currentBrowsingList = [];
-
- var path = response.path;
currentBrowsingList = response.contents;
- //clear the list
+ // clear the list
$('#filelist').empty();
$('#search_folders').val('');
@@ -354,9 +171,9 @@ $(document).ready(function(){
filelist.push('