2013-03-22 21:04:36 -07:00
$ . ajaxSetup ( {
crossDomain : true ,
2013-04-12 11:22:40 -07:00
error : function ( event ) {
2013-03-22 21:04:36 -07:00
Dashboard . hideLoadingMsg ( ) ;
if ( ! Dashboard . suppressAjaxErrors ) {
setTimeout ( function ( ) {
var msg = event . getResponseHeader ( "X-Application-Error-Code" ) || Dashboard . defaultErrorMessage ;
Dashboard . showError ( msg ) ;
} , 500 ) ;
}
}
} ) ;
2013-04-23 12:36:36 -07:00
if ( $ . browser . msie ) {
2013-05-10 05:18:07 -07:00
2013-04-23 12:36:36 -07:00
// This is unfortuantely required due to IE's over-aggressive caching.
// https://github.com/MediaBrowser/MediaBrowser/issues/179
$ . ajaxSetup ( {
cache : false
} ) ;
}
2013-03-22 21:04:36 -07:00
$ . support . cors = true ;
$ ( document ) . one ( 'click' , WebNotifications . requestPermission ) ;
var Dashboard = {
jQueryMobileInit : function ( ) {
// Page
//$.mobile.page.prototype.options.theme = "a";
//$.mobile.page.prototype.options.headerTheme = "a";
//$.mobile.page.prototype.options.contentTheme = "a";
//$.mobile.page.prototype.options.footerTheme = "a";
//$.mobile.button.prototype.options.theme = "c";
2013-12-24 11:37:29 -07:00
//$.mobile.listview.prototype.options.dividerTheme = "b";
2013-03-22 21:04:36 -07:00
2013-12-24 11:37:29 -07:00
//$.mobile.popup.prototype.options.theme = "c";
//$.mobile.popup.prototype.options.transition = "none";
2014-02-22 22:52:30 -07:00
$ . mobile . defaultPageTransition = "none" ;
2013-03-22 21:04:36 -07:00
//$.mobile.collapsible.prototype.options.contentTheme = "a";
} ,
getCurrentUser : function ( ) {
if ( ! Dashboard . getUserPromise ) {
2013-07-16 09:03:28 -07:00
var userId = Dashboard . getCurrentUserId ( ) ;
Dashboard . getUserPromise = ApiClient . getUser ( userId ) . fail ( Dashboard . logout ) ;
2013-03-22 21:04:36 -07:00
}
return Dashboard . getUserPromise ;
} ,
2013-04-04 08:22:39 -07:00
validateCurrentUser : function ( page ) {
2013-07-16 09:03:28 -07:00
2013-03-22 21:04:36 -07:00
Dashboard . getUserPromise = null ;
if ( Dashboard . getCurrentUserId ( ) ) {
Dashboard . getCurrentUser ( ) ;
}
2013-04-15 18:46:17 -07:00
page = page || $ . mobile . activePage ;
2013-04-04 08:22:39 -07:00
var header = $ ( '.header' , page ) ;
2013-03-26 15:40:01 -07:00
2013-03-22 21:04:36 -07:00
if ( header . length ) {
// Re-render the header
header . remove ( ) ;
2013-08-27 21:31:34 -07:00
2013-07-16 09:03:28 -07:00
if ( Dashboard . getUserPromise ) {
2013-08-27 21:31:34 -07:00
Dashboard . getUserPromise . done ( function ( user ) {
2013-07-16 09:03:28 -07:00
Dashboard . ensureHeader ( page , user ) ;
} ) ;
} else {
Dashboard . ensureHeader ( page ) ;
}
2013-03-22 21:04:36 -07:00
}
} ,
getCurrentUserId : function ( ) {
2014-01-03 19:35:41 -07:00
if ( ! window . localStorage ) {
return null ;
}
2013-03-22 21:04:36 -07:00
2014-02-08 13:02:35 -07:00
var autoLoginUserId = getParameterByName ( 'u' ) ;
2014-02-08 13:22:40 -07:00
var storedUserId = localStorage . getItem ( "userId" ) ;
2014-02-08 13:02:35 -07:00
var userId ;
2014-02-08 13:22:40 -07:00
if ( autoLoginUserId && autoLoginUserId != storedUserId ) {
2014-03-15 13:08:06 -07:00
2014-02-08 13:22:40 -07:00
localStorage . setItem ( "userId" , autoLoginUserId ) ;
ApiClient . currentUserId ( autoLoginUserId ) ;
2013-03-22 21:04:36 -07:00
}
2014-02-08 13:22:40 -07:00
return autoLoginUserId || storedUserId ;
2013-03-22 21:04:36 -07:00
} ,
setCurrentUser : function ( userId ) {
2014-01-03 19:35:41 -07:00
if ( window . localStorage ) {
localStorage . setItem ( "userId" , userId ) ;
}
2014-02-08 13:02:35 -07:00
2013-03-22 21:04:36 -07:00
ApiClient . currentUserId ( userId ) ;
Dashboard . getUserPromise = null ;
} ,
logout : function ( ) {
2014-01-03 19:35:41 -07:00
if ( window . localStorage ) {
localStorage . removeItem ( "userId" ) ;
}
2014-02-08 13:02:35 -07:00
2013-03-22 21:04:36 -07:00
Dashboard . getUserPromise = null ;
ApiClient . currentUserId ( null ) ;
window . location = "login.html" ;
} ,
showError : function ( message ) {
$ . mobile . loading ( 'show' , {
text : message ,
textonly : true ,
textVisible : true
} ) ;
setTimeout ( function ( ) {
$ . mobile . loading ( 'hide' ) ;
2014-01-01 11:26:31 -07:00
} , 3000 ) ;
2013-03-22 21:04:36 -07:00
} ,
2013-12-26 19:23:57 -07:00
alert : function ( options ) {
2013-03-22 21:04:36 -07:00
2013-12-26 19:23:57 -07:00
if ( typeof options == "string" ) {
2013-03-22 21:04:36 -07:00
2013-12-26 19:23:57 -07:00
var message = options ;
$ . mobile . loading ( 'show' , {
text : message ,
textonly : true ,
textVisible : true
} ) ;
setTimeout ( function ( ) {
$ . mobile . loading ( 'hide' ) ;
2014-01-01 11:26:31 -07:00
} , 3000 ) ;
2013-12-26 19:23:57 -07:00
return ;
}
Dashboard . confirmInternal ( options . message , options . title || 'Alert' , false , options . callback ) ;
2013-03-22 21:04:36 -07:00
} ,
updateSystemInfo : function ( info ) {
Dashboard . lastSystemInfo = info ;
Dashboard . ensureWebSocket ( info ) ;
if ( ! Dashboard . initialServerVersion ) {
Dashboard . initialServerVersion = info . Version ;
}
if ( info . HasPendingRestart ) {
Dashboard . hideDashboardVersionWarning ( ) ;
2013-06-27 08:04:10 -07:00
Dashboard . getCurrentUser ( ) . done ( function ( currentUser ) {
if ( currentUser . Configuration . IsAdministrator ) {
2013-10-07 07:38:31 -07:00
Dashboard . showServerRestartWarning ( info ) ;
2013-06-27 08:04:10 -07:00
}
} ) ;
2013-03-22 21:04:36 -07:00
} else {
Dashboard . hideServerRestartWarning ( ) ;
if ( Dashboard . initialServerVersion != info . Version ) {
Dashboard . showDashboardVersionWarning ( ) ;
}
}
Dashboard . showInProgressInstallations ( info . InProgressInstallations ) ;
} ,
showInProgressInstallations : function ( installations ) {
installations = installations || [ ] ;
for ( var i = 0 , length = installations . length ; i < length ; i ++ ) {
var installation = installations [ i ] ;
var percent = installation . PercentComplete || 0 ;
if ( percent < 100 ) {
Dashboard . showPackageInstallNotification ( installation , "progress" ) ;
}
}
if ( installations . length ) {
Dashboard . ensureInstallRefreshInterval ( ) ;
} else {
Dashboard . stopInstallRefreshInterval ( ) ;
}
} ,
ensureInstallRefreshInterval : function ( ) {
if ( ! Dashboard . installRefreshInterval ) {
if ( ApiClient . isWebSocketOpen ( ) ) {
ApiClient . sendWebSocketMessage ( "SystemInfoStart" , "0,350" ) ;
}
Dashboard . installRefreshInterval = 1 ;
}
} ,
stopInstallRefreshInterval : function ( ) {
if ( Dashboard . installRefreshInterval ) {
if ( ApiClient . isWebSocketOpen ( ) ) {
ApiClient . sendWebSocketMessage ( "SystemInfoStop" ) ;
}
Dashboard . installRefreshInterval = null ;
}
} ,
cancelInstallation : function ( id ) {
ApiClient . cancelPackageInstallation ( id ) . always ( Dashboard . refreshSystemInfoFromServer ) ;
} ,
2013-10-07 07:38:31 -07:00
showServerRestartWarning : function ( systemInfo ) {
2013-03-22 21:04:36 -07:00
2013-12-27 09:18:42 -07:00
var html = '<span style="margin-right: 1em;">Please restart to finish updating.</span>' ;
2013-11-28 11:27:29 -07:00
2013-10-07 07:38:31 -07:00
if ( systemInfo . CanSelfRestart ) {
2013-12-24 11:37:29 -07:00
html += '<button type="button" data-icon="refresh" onclick="$(this).buttonEnabled(false);Dashboard.restartServer();" data-theme="b" data-inline="true" data-mini="true">Restart Server</button>' ;
2013-10-07 07:38:31 -07:00
}
2013-03-22 21:04:36 -07:00
Dashboard . showFooterNotification ( { id : "serverRestartWarning" , html : html , forceShow : true , allowHide : false } ) ;
} ,
hideServerRestartWarning : function ( ) {
$ ( '#serverRestartWarning' ) . remove ( ) ;
} ,
showDashboardVersionWarning : function ( ) {
var html = '<span style="margin-right: 1em;">Please refresh this page to receive new updates from the server.</span>' ;
2014-04-13 10:27:13 -07:00
html += '<button type="button" data-icon="refresh" onclick="$(this).buttonEnabled(false);Dashboard.reloadPage();" data-theme="b" data-inline="true" data-mini="true">Refresh</button>' ;
2013-03-22 21:04:36 -07:00
Dashboard . showFooterNotification ( { id : "dashboardVersionWarning" , html : html , forceShow : true , allowHide : false } ) ;
} ,
reloadPage : function ( ) {
2013-11-05 12:43:21 -07:00
var currentUrl = window . location . toString ( ) . toLowerCase ( ) ;
2013-11-28 11:27:29 -07:00
2013-11-05 12:43:21 -07:00
// If they're on a plugin config page just go back to the dashboard
// The plugin may not have been loaded yet, or could have been uninstalled
if ( currentUrl . indexOf ( 'configurationpage' ) != - 1 ) {
window . location . href = "dashboard.html" ;
} else {
window . location . href = window . location . href ;
}
2013-03-22 21:04:36 -07:00
} ,
hideDashboardVersionWarning : function ( ) {
$ ( '#dashboardVersionWarning' ) . remove ( ) ;
} ,
showFooterNotification : function ( options ) {
var removeOnHide = ! options . id ;
options . id = options . id || "notification" + new Date ( ) . getTime ( ) + parseInt ( Math . random ( ) ) ;
2014-03-17 20:41:42 -07:00
var footer = $ ( "#footer" ) . css ( "top" , "initial" ) . show ( ) ;
2014-03-17 15:37:05 -07:00
var parentElem = $ ( '#footerNotifications' , footer ) ;
2013-03-22 21:04:36 -07:00
var elem = $ ( '#' + options . id , parentElem ) ;
if ( ! elem . length ) {
elem = $ ( '<p id="' + options . id + '" class="footerNotification"></p>' ) . appendTo ( parentElem ) ;
}
2014-03-17 15:37:05 -07:00
var onclick = removeOnHide ? "$(\"#" + options . id + "\").trigger(\"notification.remove\").remove();" : "$(\"#" + options . id + "\").trigger(\"notification.hide\").hide();" ;
2013-03-22 21:04:36 -07:00
if ( options . allowHide !== false ) {
2013-12-29 19:41:22 -07:00
options . html += "<span style='margin-left: 1em;'><button type='button' onclick='" + onclick + "' data-icon='delete' data-iconpos='notext' data-mini='true' data-inline='true' data-theme='b'>Hide</button></span>" ;
2013-03-22 21:04:36 -07:00
}
if ( options . forceShow ) {
2014-03-17 16:59:25 -07:00
elem . slideDown ( 400 ) ;
}
2014-03-17 15:37:05 -07:00
elem . html ( options . html ) . trigger ( "create" ) ;
2013-03-22 21:04:36 -07:00
if ( options . timeout ) {
setTimeout ( function ( ) {
if ( removeOnHide ) {
2014-03-17 15:37:05 -07:00
elem . trigger ( "notification.remove" ) . remove ( ) ;
2013-03-22 21:04:36 -07:00
} else {
2014-03-17 15:37:05 -07:00
elem . trigger ( "notification.hide" ) . hide ( ) ;
2013-03-22 21:04:36 -07:00
}
} , options . timeout ) ;
}
2014-03-17 15:37:05 -07:00
footer . on ( "notification.remove notification.hide" , function ( e ) {
2014-03-17 20:41:42 -07:00
2014-03-17 15:37:05 -07:00
setTimeout ( function ( ) { // give the DOM time to catch up
2014-03-17 20:41:42 -07:00
if ( ! parentElem . html ( ) ) {
footer . slideUp ( ) ;
2014-03-17 15:37:05 -07:00
}
2014-03-17 20:41:42 -07:00
2014-03-17 15:37:05 -07:00
} , 50 ) ;
2014-03-17 20:41:42 -07:00
2014-03-17 15:37:05 -07:00
} ) ;
2013-03-22 21:04:36 -07:00
} ,
getConfigurationPageUrl : function ( name ) {
return "ConfigurationPage?name=" + encodeURIComponent ( name ) ;
} ,
navigate : function ( url , preserveQueryString ) {
2014-04-08 19:12:17 -07:00
var queryString = getWindowLocationSearch ( ) ;
2013-03-22 21:04:36 -07:00
if ( preserveQueryString && queryString ) {
url += queryString ;
}
$ . mobile . changePage ( url ) ;
} ,
showLoadingMsg : function ( ) {
2013-03-31 18:52:07 -07:00
$ . mobile . loading ( "show" ) ;
2013-03-22 21:04:36 -07:00
} ,
hideLoadingMsg : function ( ) {
2013-03-31 18:52:07 -07:00
$ . mobile . loading ( "hide" ) ;
2013-03-22 21:04:36 -07:00
} ,
processPluginConfigurationUpdateResult : function ( ) {
Dashboard . hideLoadingMsg ( ) ;
Dashboard . alert ( "Settings saved." ) ;
} ,
defaultErrorMessage : "There was an error processing the request." ,
processServerConfigurationUpdateResult : function ( result ) {
Dashboard . hideLoadingMsg ( ) ;
Dashboard . alert ( "Settings saved." ) ;
} ,
2013-12-26 19:23:57 -07:00
confirmInternal : function ( message , title , showCancel , callback ) {
2013-03-22 21:04:36 -07:00
2014-01-22 10:05:06 -07:00
$ ( '.confirmFlyout' ) . popup ( "close" ) . remove ( ) ;
2013-03-22 21:04:36 -07:00
2014-01-22 10:05:06 -07:00
var html = '<div data-role="popup" data-transition="slidefade" class="confirmFlyout" style="max-width:500px;" data-theme="a">' ;
2013-03-22 21:04:36 -07:00
2013-12-24 11:37:29 -07:00
html += '<div class="ui-bar-a" style="text-align:center;">' ;
2013-03-22 21:04:36 -07:00
html += '<h3>' + title + '</h3>' ;
html += '</div>' ;
2013-12-24 11:37:29 -07:00
html += '<div style="padding: 1em;">' ;
2013-03-22 21:04:36 -07:00
html += '<div style="padding: 1em .25em;margin: 0;">' ;
html += message ;
html += '</div>' ;
2014-01-22 10:05:06 -07:00
html += '<p><button type="button" data-icon="check" onclick="$(\'.confirmFlyout\')[0].confirm=true;$(\'.confirmFlyout\').popup(\'close\');" data-theme="b">Ok</button></p>' ;
2013-12-26 19:23:57 -07:00
if ( showCancel ) {
2014-01-22 10:05:06 -07:00
html += '<p><button type="button" data-icon="delete" onclick="$(\'.confirmFlyout\').popup(\'close\');" data-theme="a">Cancel</button></p>' ;
2013-12-26 19:23:57 -07:00
}
2013-03-22 21:04:36 -07:00
html += '</div>' ;
html += '</div>' ;
$ ( document . body ) . append ( html ) ;
2014-01-22 10:05:06 -07:00
$ ( '.confirmFlyout' ) . popup ( { history : false } ) . trigger ( 'create' ) . popup ( "open" ) . on ( "popupafterclose" , function ( ) {
2013-03-22 21:04:36 -07:00
if ( callback ) {
callback ( this . confirm == true ) ;
}
$ ( this ) . off ( "popupafterclose" ) . remove ( ) ;
} ) ;
} ,
2013-12-26 19:23:57 -07:00
confirm : function ( message , title , callback ) {
Dashboard . confirmInternal ( message , title , true , callback ) ;
} ,
2013-03-22 21:04:36 -07:00
refreshSystemInfoFromServer : function ( ) {
ApiClient . getSystemInfo ( ) . done ( function ( info ) {
Dashboard . updateSystemInfo ( info ) ;
} ) ;
} ,
restartServer : function ( ) {
Dashboard . suppressAjaxErrors = true ;
Dashboard . showLoadingMsg ( ) ;
2013-07-16 10:18:32 -07:00
ApiClient . restartServer ( ) . done ( function ( ) {
2013-03-22 21:04:36 -07:00
setTimeout ( function ( ) {
Dashboard . reloadPageWhenServerAvailable ( ) ;
} , 250 ) ;
} ) . fail ( function ( ) {
Dashboard . suppressAjaxErrors = false ;
} ) ;
} ,
reloadPageWhenServerAvailable : function ( retryCount ) {
2013-07-26 08:57:51 -07:00
// Don't use apiclient method because we don't want it reporting authentication under the old version
$ . getJSON ( ApiClient . getUrl ( "System/Info" ) ) . done ( function ( info ) {
2013-03-26 15:40:01 -07:00
2013-03-22 21:04:36 -07:00
// If this is back to false, the restart completed
if ( ! info . HasPendingRestart ) {
Dashboard . reloadPage ( ) ;
} else {
Dashboard . retryReload ( retryCount ) ;
}
2013-03-26 15:40:01 -07:00
} ) . fail ( function ( ) {
2013-03-22 21:04:36 -07:00
Dashboard . retryReload ( retryCount ) ;
} ) ;
} ,
2013-03-26 15:40:01 -07:00
2013-03-22 21:04:36 -07:00
retryReload : function ( retryCount ) {
setTimeout ( function ( ) {
retryCount = retryCount || 0 ;
retryCount ++ ;
if ( retryCount < 10 ) {
Dashboard . reloadPageWhenServerAvailable ( retryCount ) ;
} else {
Dashboard . suppressAjaxErrors = false ;
}
} , 500 ) ;
} ,
2013-05-13 22:36:36 -07:00
showUserFlyout : function ( context ) {
2013-03-22 21:04:36 -07:00
Dashboard . getCurrentUser ( ) . done ( function ( user ) {
2014-04-14 20:54:52 -07:00
var html = '<div data-role="panel" data-position="right" data-display="overlay" id="userFlyout" data-position-fixed="true" data-theme="b">' ;
2013-03-22 21:04:36 -07:00
2014-03-16 22:23:13 -07:00
html += '<h3>' ;
2013-03-22 21:04:36 -07:00
2014-03-16 22:23:13 -07:00
if ( user . PrimaryImageTag ) {
var imageUrl = ApiClient . getUserImageUrl ( user . Id , {
2013-03-22 21:04:36 -07:00
2014-04-11 08:36:25 -07:00
width : 28 ,
2014-03-16 22:23:13 -07:00
tag : user . PrimaryImageTag ,
type : "Primary"
2013-03-22 21:04:36 -07:00
2014-03-16 22:23:13 -07:00
} ) ;
2013-03-22 21:04:36 -07:00
2014-03-16 22:23:13 -07:00
html += '<img style="max-width:28px;vertical-align:middle;margin-right:5px;" src="' + imageUrl + '" />' ;
}
html += user . Name ;
html += '</h3>' ;
2013-03-22 21:04:36 -07:00
2014-04-14 20:54:52 -07:00
html += '<form>' ;
html += '<p><label for="chkEnableThemeSongs">Play theme songs</label><input onchange="ThemeSongManager.enabled(this.checked);" type="checkbox" id="chkEnableThemeSongs" data-mini="true" /></a>' ;
2014-04-19 22:21:08 -07:00
html += '<p><a data-mini="true" data-role="button" href="usersettings.html?userId=' + user . Id + '" data-icon="user">Preferences</button></a>' ;
2013-12-25 20:44:26 -07:00
html += '<p><button data-mini="true" type="button" onclick="Dashboard.logout();" data-icon="lock">Sign Out</button></p>' ;
2013-03-22 21:04:36 -07:00
2014-04-14 20:54:52 -07:00
html += '</form>' ;
2013-03-22 21:04:36 -07:00
html += '</div>' ;
$ ( document . body ) . append ( html ) ;
2014-04-14 20:54:52 -07:00
var elem = $ ( '#userFlyout' ) . panel ( { } ) . trigger ( 'create' ) . panel ( "open" ) . on ( "panelafterclose" , function ( ) {
2013-03-22 21:04:36 -07:00
2014-03-16 22:23:13 -07:00
$ ( this ) . off ( "panelafterclose" ) . remove ( ) ;
2013-03-22 21:04:36 -07:00
} ) ;
2014-04-14 20:54:52 -07:00
2014-04-14 21:23:08 -07:00
$ ( '#chkEnableThemeSongs' , elem ) . checked ( window . ThemeSongManager . enabled ( ) ) . checkboxradio ( 'refresh' ) ;
2013-03-22 21:04:36 -07:00
} ) ;
} ,
getPluginSecurityInfo : function ( ) {
if ( ! Dashboard . getPluginSecurityInfoPromise ) {
var deferred = $ . Deferred ( ) ;
// Don't let this blow up the dashboard when it fails
$ . ajax ( {
type : "GET" ,
url : ApiClient . getUrl ( "Plugins/SecurityInfo" ) ,
dataType : 'json' ,
error : function ( ) {
// Don't show normal dashboard errors
}
} ) . done ( function ( result ) {
2013-06-04 09:59:03 -07:00
deferred . resolveWith ( null , [ result ] ) ;
2013-03-22 21:04:36 -07:00
} ) ;
Dashboard . getPluginSecurityInfoPromise = deferred ;
}
return Dashboard . getPluginSecurityInfoPromise ;
} ,
resetPluginSecurityInfo : function ( ) {
Dashboard . getPluginSecurityInfoPromise = null ;
2013-09-14 14:19:32 -07:00
Dashboard . validateCurrentUser ( ) ;
2013-03-22 21:04:36 -07:00
} ,
2013-07-16 09:03:28 -07:00
ensureHeader : function ( page , user ) {
2013-03-22 21:04:36 -07:00
2013-05-13 22:36:36 -07:00
if ( ! page . hasClass ( 'libraryPage' ) && ! $ ( '.headerButtons' , page ) . length ) {
2013-03-22 21:04:36 -07:00
2013-07-16 09:03:28 -07:00
Dashboard . renderHeader ( page , user ) ;
2013-03-22 21:04:36 -07:00
}
} ,
renderHeader : function ( page , user ) {
var headerHtml = '' ;
2013-04-22 07:44:11 -07:00
var header = $ ( '.header' , page ) ;
2013-04-23 12:17:21 -07:00
2013-04-22 07:44:11 -07:00
if ( ! header . length ) {
headerHtml += '<div class="header">' ;
2013-03-22 21:04:36 -07:00
2013-05-13 22:36:36 -07:00
headerHtml += '<a class="logo" href="index.html">' ;
2013-03-22 21:04:36 -07:00
2013-05-13 22:36:36 -07:00
if ( page . hasClass ( 'standalonePage' ) ) {
2013-03-22 21:04:36 -07:00
2013-05-13 22:36:36 -07:00
headerHtml += '<img class="imgLogoIcon" src="css/images/mblogoicon.png" /><img class="imgLogoText" src="css/images/mblogotextblack.png" />' ;
2013-03-31 22:08:29 -07:00
}
2013-05-13 22:36:36 -07:00
headerHtml += '</a>' ;
2013-12-26 22:08:37 -07:00
if ( page . hasClass ( 'type-interior' ) ) {
headerHtml += '<div>' ;
headerHtml += '<button type="button" data-icon="bars" data-inline="true" data-iconpos="notext" class="ui-alt-icon" onclick="Dashboard.showDashboardMenu();">Menu</button>' ;
headerHtml += '</div>' ;
}
2013-04-22 07:44:11 -07:00
headerHtml += '</div>' ;
page . prepend ( headerHtml ) ;
2013-12-26 22:08:37 -07:00
header = $ ( '.header' , page ) . trigger ( 'create' ) ;
2013-03-22 21:04:36 -07:00
}
2013-05-13 22:36:36 -07:00
var imageColor = "black" ;
2013-03-22 21:04:36 -07:00
2013-04-22 07:44:11 -07:00
headerHtml = '' ;
headerHtml += '<div class="headerButtons">' ;
2013-03-22 21:04:36 -07:00
if ( user && ! page . hasClass ( 'wizardPage' ) ) {
2013-04-25 20:31:10 -07:00
2013-12-24 11:37:29 -07:00
headerHtml += '<a class="imageLink btnCurrentUser" href="#" onclick="Dashboard.showUserFlyout(this);"><span class="currentUsername" style="font-weight:normal;">' + user . Name + '</span>' ;
2013-03-22 21:04:36 -07:00
if ( user . PrimaryImageTag ) {
var url = ApiClient . getUserImageUrl ( user . Id , {
2014-04-11 08:36:25 -07:00
width : 28 ,
2013-03-22 21:04:36 -07:00
tag : user . PrimaryImageTag ,
type : "Primary"
} ) ;
headerHtml += '<img src="' + url + '" />' ;
} else {
2013-03-27 15:17:46 -07:00
headerHtml += '<img src="css/images/currentuserdefault' + imageColor + '.png" />' ;
2013-03-22 21:04:36 -07:00
}
headerHtml += '</a>' ;
if ( user . Configuration . IsAdministrator ) {
2013-12-26 22:13:19 -07:00
var href = window . location . toString ( ) . toLowerCase ( ) . indexOf ( 'dashboard.html' ) == - 1 ? 'dashboard.html' : '#' ;
headerHtml += '<a class="imageLink btnTools" href="' + href + '" data-role="button" data-icon="gear" data-inline="true" data-iconpos="notext">Tools</a>' ;
2013-03-22 21:04:36 -07:00
}
}
headerHtml += '</div>' ;
2013-04-22 07:44:11 -07:00
2013-12-26 22:08:37 -07:00
header . append ( headerHtml ) . trigger ( 'create' ) ;
2013-03-22 21:04:36 -07:00
2013-05-19 19:45:04 -07:00
if ( ! $ ( '.supporterIcon' , header ) . length ) {
2013-05-23 13:09:01 -07:00
2013-06-04 09:59:03 -07:00
Dashboard . getPluginSecurityInfo ( ) . done ( function ( pluginSecurityInfo ) {
2013-04-25 20:31:10 -07:00
2013-05-19 19:45:04 -07:00
if ( pluginSecurityInfo . IsMBSupporter ) {
2013-05-19 22:36:22 -07:00
$ ( '<a class="imageLink supporterIcon" href="supporter.html" title="Thank you for supporting Media Browser."><img src="css/images/supporter/supporterbadge.png" /></a>' ) . insertBefore ( $ ( '.btnTools' , header ) ) ;
2013-05-19 19:45:04 -07:00
} else {
2013-05-20 21:04:38 -07:00
$ ( '<a class="imageLink supporterIcon" href="supporter.html" title="Become a Media Browser supporter!"><img src="css/images/supporter/nonsupporterbadge.png" /></a>' ) . insertBefore ( $ ( '.btnTools' , header ) ) ;
2013-05-19 19:45:04 -07:00
}
} ) ;
}
2013-07-06 14:23:32 -07:00
$ ( Dashboard ) . trigger ( 'interiorheaderrendered' , [ header , user ] ) ;
2013-03-22 21:04:36 -07:00
} ,
2013-05-10 05:18:07 -07:00
2014-04-24 10:30:59 -07:00
ensureToolsMenu : function ( page , user ) {
2013-03-22 21:04:36 -07:00
if ( ! page . hasClass ( 'type-interior' ) ) {
return ;
}
var sidebar = $ ( '.toolsSidebar' , page ) ;
if ( ! sidebar . length ) {
var html = '<div class="content-secondary ui-bar-a toolsSidebar">' ;
2014-02-06 15:22:03 -07:00
html += '<p class="libraryPanelHeader" style="margin: 30px 0 20px 25px;"><a href="index.html" class="imageLink"><img src="css/images/mblogoicon.png" style="height:28px;" /><span>MEDIA</span><span class="mediaBrowserAccent">BROWSER</span></a></p>' ;
2013-12-27 14:10:06 -07:00
2014-04-24 10:30:59 -07:00
if ( user . Configuration . IsAdministrator ) {
html += '<div style="position:absolute;top:20px;right:20px;"><a data-role="button" data-theme="b" data-icon="edit" data-iconpos="notext" href="edititemmetadata.html" title="Metadata Manager">Metadata Manager</a></div>' ;
}
2013-03-22 21:04:36 -07:00
html += '<div class="sidebarLinks">' ;
var links = Dashboard . getToolsMenuLinks ( page ) ;
2013-12-26 22:08:37 -07:00
var i , length , link ;
for ( i = 0 , length = links . length ; i < length ; i ++ ) {
2013-03-22 21:04:36 -07:00
2013-12-26 22:08:37 -07:00
link = links [ i ] ;
2013-12-26 19:23:57 -07:00
2014-04-24 10:30:59 -07:00
if ( ! user . Configuration . IsAdministrator ) {
break ;
}
2013-12-25 20:44:26 -07:00
if ( link . divider ) {
html += "<div class='sidebarDivider'></div>" ;
}
2013-03-22 21:04:36 -07:00
if ( link . href ) {
if ( link . selected ) {
html += '<a class="selectedSidebarLink" href="' + link . href + '">' + link . name + '</a>' ;
} else {
html += '<a href="' + link . href + '">' + link . name + '</a>' ;
}
}
}
// collapsible
html += '</div>' ;
// content-secondary
html += '</div>' ;
2013-12-26 22:08:37 -07:00
html += '<div data-role="panel" id="dashboardPanel" class="dashboardPanel" data-position="left" data-display="overlay" data-position-fixed="true" data-theme="b">' ;
2013-12-27 14:10:06 -07:00
html += '<p class="libraryPanelHeader" style="margin: 20px 0 20px 15px;"><a href="index.html" class="imageLink"><img src="css/images/mblogoicon.png" /><span>MEDIA</span><span class="mediaBrowserAccent">BROWSER</span></a></p>' ;
2013-12-26 22:08:37 -07:00
for ( i = 0 , length = links . length ; i < length ; i ++ ) {
link = links [ i ] ;
2014-04-24 10:30:59 -07:00
if ( ! user . Configuration . IsAdministrator ) {
break ;
}
2013-12-26 22:08:37 -07:00
if ( link . divider ) {
html += "<div class='dashboardPanelDivider'></div>" ;
}
if ( link . href ) {
if ( link . selected ) {
html += '<a class="selectedDashboardPanelLink dashboardPanelLink" href="' + link . href + '">' + link . name + '</a>' ;
} else {
html += '<a class="dashboardPanelLink" href="' + link . href + '">' + link . name + '</a>' ;
}
}
}
html += '</div>' ;
$ ( page ) . append ( html ) . trigger ( 'create' ) ;
2013-03-22 21:04:36 -07:00
}
} ,
2013-12-26 22:08:37 -07:00
showDashboardMenu : function ( ) {
var page = $ . mobile . activePage ;
$ ( "#dashboardPanel" , page ) . panel ( "open" ) ;
} ,
2013-03-22 21:04:36 -07:00
getToolsMenuLinks : function ( page ) {
var pageElem = page [ 0 ] ;
return [ {
name : "Dashboard" ,
href : "dashboard.html" ,
2014-02-26 14:31:47 -07:00
selected : page . hasClass ( "dashboardHomePage" )
2013-03-22 21:04:36 -07:00
} , {
2014-03-03 21:53:48 -07:00
name : "Library" ,
2013-12-25 20:44:26 -07:00
divider : true ,
2013-03-22 21:04:36 -07:00
href : "library.html" ,
2013-12-26 11:46:38 -07:00
selected : page . hasClass ( "mediaLibraryPage" )
2013-03-22 21:04:36 -07:00
} , {
name : "Metadata" ,
href : "metadata.html" ,
selected : pageElem . id == "metadataConfigurationPage" || pageElem . id == "advancedMetadataConfigurationPage" || pageElem . id == "metadataImagesConfigurationPage"
2014-01-22 16:52:01 -07:00
} , {
name : "Auto-Organize" ,
href : "autoorganizelog.html" ,
selected : page . hasClass ( "organizePage" )
2013-03-22 21:04:36 -07:00
} , {
2014-03-10 10:38:53 -07:00
name : "DLNA" ,
2014-04-24 19:00:19 -07:00
divider : true ,
2014-03-10 10:38:53 -07:00
href : "dlnasettings.html" ,
selected : page . hasClass ( "dlnaPage" )
2014-01-12 09:55:38 -07:00
} , {
name : "Live TV" ,
2014-01-22 13:46:01 -07:00
href : "livetvstatus.html" ,
2014-01-12 09:55:38 -07:00
selected : page . hasClass ( "liveTvSettingsPage" )
2014-03-25 14:13:55 -07:00
} , {
name : "Plugins" ,
href : "plugins.html" ,
selected : page . hasClass ( "pluginConfigurationPage" )
2013-03-22 21:04:36 -07:00
} , {
2013-12-25 20:44:26 -07:00
name : "Users" ,
divider : true ,
2013-03-28 22:45:21 -07:00
href : "userprofiles.html" ,
2013-04-02 20:04:08 -07:00
selected : page . hasClass ( "userProfilesConfigurationPage" ) || ( pageElem . id == "mediaLibraryPage" && getParameterByName ( 'userId' ) )
2013-03-22 21:04:36 -07:00
} , {
2013-12-25 20:44:26 -07:00
name : "App Settings" ,
href : "appsplayback.html" ,
selected : page . hasClass ( "appsPage" )
2013-03-22 21:04:36 -07:00
} , {
name : "Advanced" ,
2013-12-25 20:44:26 -07:00
divider : true ,
2013-03-22 21:04:36 -07:00
href : "advanced.html" ,
2014-01-07 11:39:35 -07:00
selected : page . hasClass ( "advancedConfigurationPage" )
2013-03-22 21:04:36 -07:00
} , {
name : "Scheduled Tasks" ,
2013-03-28 22:45:21 -07:00
href : "scheduledtasks.html" ,
2013-03-22 21:04:36 -07:00
selected : pageElem . id == "scheduledTasksPage" || pageElem . id == "scheduledTaskPage"
} , {
name : "Help" ,
2013-12-25 20:44:26 -07:00
divider : true ,
2013-03-22 21:04:36 -07:00
href : "support.html" ,
selected : pageElem . id == "supportPage" || pageElem . id == "logPage" || pageElem . id == "supporterPage" || pageElem . id == "supporterKeyPage" || pageElem . id == "aboutPage"
} ] ;
} ,
ensureWebSocket : function ( systemInfo ) {
if ( ! ( "WebSocket" in window ) ) {
// Not supported by the browser
return ;
}
if ( ApiClient . isWebSocketOpenOrConnecting ( ) ) {
return ;
}
systemInfo = systemInfo || Dashboard . lastSystemInfo ;
2014-01-18 12:25:20 -07:00
var location = window . location ;
var webSocketUrl = "ws://" + location . hostname ;
2014-02-08 13:02:35 -07:00
2014-01-22 15:38:55 -07:00
if ( systemInfo . HttpServerPortNumber == systemInfo . WebSocketPortNumber ) {
2014-01-18 12:25:20 -07:00
if ( location . port ) {
webSocketUrl += ':' + location . port ;
}
} else {
webSocketUrl += ':' + systemInfo . WebSocketPortNumber ;
}
ApiClient . openWebSocket ( webSocketUrl ) ;
2013-03-22 21:04:36 -07:00
} ,
2013-03-26 15:40:01 -07:00
2014-04-13 10:27:13 -07:00
onWebSocketOpened : function ( ) {
ApiClient . reportCapabilities ( {
PlayableMediaTypes : "Audio,Video" ,
SupportedCommands : Dashboard . getSupportedRemoteCommands ( ) . join ( ',' )
} ) ;
} ,
2014-04-27 18:57:29 -07:00
processGeneralCommand : function ( cmd ) {
// Full list
// https://github.com/MediaBrowser/MediaBrowser/blob/master/MediaBrowser.Model/Session/GeneralCommand.cs#L23
2014-05-06 19:28:19 -07:00
2014-04-30 20:24:55 -07:00
switch ( cmd . Name ) {
2014-05-06 19:28:19 -07:00
2014-04-30 20:24:55 -07:00
case 'GoHome' :
Dashboard . navigate ( 'index.html' ) ;
break ;
case 'GoToSettings' :
Dashboard . navigate ( 'dashboard.html' ) ;
break ;
case 'DisplayContent' :
Dashboard . onBrowseCommand ( cmd . Arguments ) ;
break ;
case 'GoToSearch' :
Search . showSearchPanel ( $ . mobile . activePage ) ;
break ;
case 'VolumeUp' :
case 'VolumeDown' :
case 'Mute' :
case 'Unmute' :
case 'ToggleMute' :
case 'SetVolume' :
case 'SetAudioStreamIndex' :
case 'SetSubtitleStreamIndex' :
case 'ToggleFullscreen' :
break ;
default :
console . log ( 'Unrecognized command: ' + cmd . Name ) ;
break ;
2014-04-27 18:57:29 -07:00
}
} ,
2013-03-27 22:19:58 -07:00
onWebSocketMessageReceived : function ( e , data ) {
2013-03-26 15:40:01 -07:00
2013-03-27 22:19:58 -07:00
var msg = data ;
2013-03-31 18:52:07 -07:00
2013-03-22 21:04:36 -07:00
if ( msg . MessageType === "LibraryChanged" ) {
Dashboard . processLibraryUpdateNotification ( msg . Data ) ;
}
2013-09-05 10:26:03 -07:00
else if ( msg . MessageType === "ServerShuttingDown" ) {
Dashboard . hideServerRestartWarning ( ) ;
}
else if ( msg . MessageType === "ServerRestarting" ) {
Dashboard . hideServerRestartWarning ( ) ;
}
2013-03-22 21:04:36 -07:00
else if ( msg . MessageType === "UserDeleted" ) {
Dashboard . validateCurrentUser ( ) ;
}
else if ( msg . MessageType === "SystemInfo" ) {
Dashboard . updateSystemInfo ( msg . Data ) ;
}
2013-03-27 22:19:58 -07:00
else if ( msg . MessageType === "RestartRequired" ) {
2013-03-22 21:04:36 -07:00
Dashboard . updateSystemInfo ( msg . Data ) ;
}
else if ( msg . MessageType === "UserUpdated" ) {
Dashboard . validateCurrentUser ( ) ;
var user = msg . Data ;
if ( user . Id == Dashboard . getCurrentUserId ( ) ) {
$ ( '.currentUsername' ) . html ( user . Name ) ;
}
}
else if ( msg . MessageType === "PackageInstallationCompleted" ) {
2013-06-27 08:04:10 -07:00
Dashboard . getCurrentUser ( ) . done ( function ( currentUser ) {
if ( currentUser . Configuration . IsAdministrator ) {
Dashboard . showPackageInstallNotification ( msg . Data , "completed" ) ;
Dashboard . refreshSystemInfoFromServer ( ) ;
}
} ) ;
2013-03-22 21:04:36 -07:00
}
else if ( msg . MessageType === "PackageInstallationFailed" ) {
2013-06-27 08:04:10 -07:00
Dashboard . getCurrentUser ( ) . done ( function ( currentUser ) {
if ( currentUser . Configuration . IsAdministrator ) {
Dashboard . showPackageInstallNotification ( msg . Data , "failed" ) ;
Dashboard . refreshSystemInfoFromServer ( ) ;
}
} ) ;
2013-03-22 21:04:36 -07:00
}
else if ( msg . MessageType === "PackageInstallationCancelled" ) {
2013-06-27 08:04:10 -07:00
Dashboard . getCurrentUser ( ) . done ( function ( currentUser ) {
if ( currentUser . Configuration . IsAdministrator ) {
Dashboard . showPackageInstallNotification ( msg . Data , "cancelled" ) ;
Dashboard . refreshSystemInfoFromServer ( ) ;
}
} ) ;
2013-03-22 21:04:36 -07:00
}
else if ( msg . MessageType === "PackageInstalling" ) {
2013-06-27 08:04:10 -07:00
Dashboard . getCurrentUser ( ) . done ( function ( currentUser ) {
if ( currentUser . Configuration . IsAdministrator ) {
Dashboard . showPackageInstallNotification ( msg . Data , "progress" ) ;
Dashboard . refreshSystemInfoFromServer ( ) ;
}
} ) ;
2013-03-22 21:04:36 -07:00
}
2013-03-27 22:19:58 -07:00
else if ( msg . MessageType === "ScheduledTaskEnded" ) {
2013-03-22 21:04:36 -07:00
2013-06-27 08:04:10 -07:00
Dashboard . getCurrentUser ( ) . done ( function ( currentUser ) {
2013-07-16 09:03:28 -07:00
2013-06-27 08:04:10 -07:00
if ( currentUser . Configuration . IsAdministrator ) {
Dashboard . showTaskCompletionNotification ( msg . Data ) ;
}
} ) ;
2013-03-22 21:04:36 -07:00
}
2014-03-31 14:04:22 -07:00
else if ( msg . MessageType === "GeneralCommand" ) {
2013-08-27 21:31:34 -07:00
2014-03-31 14:04:22 -07:00
var cmd = msg . Data ;
2014-04-27 18:57:29 -07:00
Dashboard . processGeneralCommand ( cmd ) ;
2013-08-27 21:31:34 -07:00
}
else if ( msg . MessageType === "MessageCommand" ) {
var cmd = msg . Data ;
2013-08-27 22:17:26 -07:00
if ( cmd . TimeoutMs && WebNotifications . supported ( ) ) {
2013-08-27 21:31:34 -07:00
var notification = {
title : cmd . Header ,
body : cmd . Text ,
timeout : cmd . TimeoutMs
} ;
WebNotifications . show ( notification ) ;
2013-08-27 22:44:43 -07:00
}
else {
2013-08-27 21:31:34 -07:00
Dashboard . showFooterNotification ( { html : "<b>" + cmd . Header + ": </b>" + cmd . Text , timeout : cmd . TimeoutMs } ) ;
}
}
2013-05-10 05:18:07 -07:00
} ,
onBrowseCommand : function ( cmd ) {
var url ;
2013-05-25 17:53:51 -07:00
var type = ( cmd . ItemType || "" ) . toLowerCase ( ) ;
2013-05-10 05:18:07 -07:00
if ( type == "genre" ) {
2014-05-06 19:28:19 -07:00
url = "itembynamedetails.html?genre=" + ApiClient . encodeName ( cmd . ItemName ) ;
2013-05-10 05:18:07 -07:00
}
2013-06-10 20:31:00 -07:00
else if ( type == "musicgenre" ) {
2014-05-06 19:28:19 -07:00
url = "itembynamedetails.html?musicgenre=" + ApiClient . encodeName ( cmd . ItemName ) ;
2013-06-10 20:31:00 -07:00
}
2013-07-01 10:17:33 -07:00
else if ( type == "gamegenre" ) {
2014-05-06 19:28:19 -07:00
url = "itembynamedetails.html?gamegenre=" + ApiClient . encodeName ( cmd . ItemName ) ;
2013-07-01 10:17:33 -07:00
}
2013-05-10 05:18:07 -07:00
else if ( type == "studio" ) {
2014-05-06 19:28:19 -07:00
url = "itembynamedetails.html?studio=" + ApiClient . encodeName ( cmd . ItemName ) ;
2013-05-10 05:18:07 -07:00
}
else if ( type == "person" ) {
2014-05-06 19:28:19 -07:00
url = "itembynamedetails.html?person=" + ApiClient . encodeName ( cmd . ItemName ) ;
2013-05-10 05:18:07 -07:00
}
2013-11-21 13:48:26 -07:00
else if ( type == "musicartist" ) {
2014-05-06 19:28:19 -07:00
url = "itembynamedetails.html?musicartist=" + ApiClient . encodeName ( cmd . ItemName ) ;
2013-05-10 05:18:07 -07:00
}
2013-05-13 08:00:03 -07:00
2013-05-10 05:18:07 -07:00
if ( url ) {
Dashboard . navigate ( url ) ;
return ;
}
2013-05-25 17:53:51 -07:00
ApiClient . getItem ( Dashboard . getCurrentUserId ( ) , cmd . ItemId ) . done ( function ( item ) {
2013-05-10 05:18:07 -07:00
2014-05-06 19:28:19 -07:00
Dashboard . navigate ( LibraryBrowser . getHref ( item ) ) ;
2013-05-10 05:18:07 -07:00
} ) ;
2013-03-22 21:04:36 -07:00
} ,
showTaskCompletionNotification : function ( result ) {
var html = '' ;
if ( result . Status == "Completed" ) {
html += '<img src="css/images/notifications/done.png" class="notificationIcon" />' ;
return ;
}
else if ( result . Status == "Cancelled" ) {
html += '<img src="css/images/notifications/info.png" class="notificationIcon" />' ;
return ;
}
else {
html += '<img src="css/images/notifications/error.png" class="notificationIcon" />' ;
}
html += '<span>' ;
html += result . Name + " " + result . Status ;
html += '</span>' ;
var timeout = 0 ;
if ( result . Status == 'Cancelled' ) {
timeout = 2000 ;
}
Dashboard . showFooterNotification ( { html : html , id : result . Id , forceShow : true , timeout : timeout } ) ;
} ,
showPackageInstallNotification : function ( installation , status ) {
var html = '' ;
if ( status == 'completed' ) {
html += '<img src="css/images/notifications/done.png" class="notificationIcon" />' ;
}
else if ( status == 'cancelled' ) {
html += '<img src="css/images/notifications/info.png" class="notificationIcon" />' ;
}
else if ( status == 'failed' ) {
html += '<img src="css/images/notifications/error.png" class="notificationIcon" />' ;
}
else if ( status == 'progress' ) {
html += '<img src="css/images/notifications/download.png" class="notificationIcon" />' ;
}
html += '<span style="margin-right: 1em;">' ;
if ( status == 'completed' ) {
html += installation . Name + ' ' + installation . Version + ' installation completed' ;
}
else if ( status == 'cancelled' ) {
html += installation . Name + ' ' + installation . Version + ' installation was cancelled' ;
}
else if ( status == 'failed' ) {
html += installation . Name + ' ' + installation . Version + ' installation failed' ;
}
else if ( status == 'progress' ) {
html += 'Installing ' + installation . Name + ' ' + installation . Version ;
}
html += '</span>' ;
if ( status == 'progress' ) {
var percentComplete = Math . round ( installation . PercentComplete || 0 ) ;
html += '<progress style="margin-right: 1em;" max="100" value="' + percentComplete + '" title="' + percentComplete + '%">' ;
html += '' + percentComplete + '%' ;
html += '</progress>' ;
if ( percentComplete < 100 ) {
var btnId = "btnCancel" + installation . Id ;
2013-12-24 11:37:29 -07:00
html += '<button id="' + btnId + '" type="button" data-icon="delete" onclick="$(\'' + btnId + '\').buttonEnabled(false);Dashboard.cancelInstallation(\'' + installation . Id + '\');" data-theme="b" data-inline="true" data-mini="true">Cancel</button>' ;
2013-03-22 21:04:36 -07:00
}
}
var timeout = 0 ;
if ( status == 'cancelled' ) {
timeout = 2000 ;
}
var forceShow = status != "progress" ;
var allowHide = status != "progress" && status != 'cancelled' ;
Dashboard . showFooterNotification ( { html : html , id : installation . Id , timeout : timeout , forceShow : forceShow , allowHide : allowHide } ) ;
} ,
processLibraryUpdateNotification : function ( data ) {
2013-05-02 21:10:11 -07:00
var newItems = data . ItemsAdded ;
2013-05-10 05:18:07 -07:00
2013-05-02 21:10:11 -07:00
if ( ! newItems . length ) {
return ;
}
2013-03-22 21:04:36 -07:00
2013-04-15 11:45:58 -07:00
ApiClient . getItems ( Dashboard . getCurrentUserId ( ) , {
2013-04-19 15:09:21 -07:00
2013-04-15 11:45:58 -07:00
Recursive : true ,
2013-05-18 14:47:50 -07:00
Limit : 3 ,
2013-04-15 16:45:09 -07:00
Filters : "IsNotFolder" ,
2013-04-15 11:45:58 -07:00
SortBy : "DateCreated" ,
SortOrder : "Descending" ,
2013-05-02 21:10:11 -07:00
ImageTypes : "Primary" ,
Ids : newItems . join ( ',' )
2013-04-19 15:09:21 -07:00
2013-04-15 11:45:58 -07:00
} ) . done ( function ( result ) {
var items = result . Items ;
for ( var i = 0 , length = Math . min ( items . length , 2 ) ; i < length ; i ++ ) {
var item = items [ i ] ;
2013-05-02 21:10:11 -07:00
var notification = {
2013-04-15 11:45:58 -07:00
title : "New " + item . Type ,
body : item . Name ,
timeout : 5000
} ;
var imageTags = item . ImageTags || { } ;
2013-04-19 15:09:21 -07:00
2013-04-15 11:45:58 -07:00
if ( imageTags . Primary ) {
2013-05-02 21:10:11 -07:00
notification . icon = ApiClient . getImageUrl ( item . Id , {
2013-04-15 11:45:58 -07:00
width : 100 ,
tag : imageTags . Primary ,
type : "Primary"
} ) ;
}
2013-03-22 21:04:36 -07:00
2013-05-02 21:10:11 -07:00
WebNotifications . show ( notification ) ;
2013-03-22 21:04:36 -07:00
}
} ) ;
} ,
ensurePageTitle : function ( page ) {
if ( ! page . hasClass ( 'type-interior' ) ) {
return ;
}
2014-03-07 08:53:23 -07:00
if ( $ ( '.pageTitle' , page ) . length ) {
2013-03-22 21:04:36 -07:00
return ;
}
var parent = $ ( '.content-primary' , page ) ;
if ( ! parent . length ) {
parent = $ ( '.ui-content' , page ) [ 0 ] ;
}
$ ( parent ) . prepend ( "<h2 class='pageTitle'>" + ( document . title || " " ) + "</h2>" ) ;
} ,
setPageTitle : function ( title ) {
$ ( '.pageTitle' , $ . mobile . activePage ) . html ( title ) ;
if ( title ) {
document . title = title ;
}
2013-06-07 10:29:33 -07:00
} ,
getDisplayTime : function ( ticks ) {
var ticksPerHour = 36000000000 ;
var parts = [ ] ;
var hours = ticks / ticksPerHour ;
2013-12-05 20:39:44 -07:00
hours = Math . floor ( hours ) ;
2013-06-07 10:29:33 -07:00
if ( hours ) {
parts . push ( hours ) ;
}
ticks -= ( hours * ticksPerHour ) ;
var ticksPerMinute = 600000000 ;
var minutes = ticks / ticksPerMinute ;
2013-12-05 20:39:44 -07:00
minutes = Math . floor ( minutes ) ;
2013-06-07 10:29:33 -07:00
ticks -= ( minutes * ticksPerMinute ) ;
if ( minutes < 10 && hours ) {
minutes = '0' + minutes ;
}
parts . push ( minutes ) ;
var ticksPerSecond = 10000000 ;
var seconds = ticks / ticksPerSecond ;
2013-12-05 20:39:44 -07:00
seconds = Math . round ( seconds ) ;
2013-06-07 10:29:33 -07:00
if ( seconds < 10 ) {
seconds = '0' + seconds ;
}
parts . push ( seconds ) ;
return parts . join ( ':' ) ;
2013-11-07 10:27:05 -07:00
} ,
2013-11-28 11:27:29 -07:00
ratePackage : function ( link ) {
2013-11-07 10:27:05 -07:00
var id = link . getAttribute ( 'data-id' ) ;
var name = link . getAttribute ( 'data-name' ) ;
var rating = link . getAttribute ( 'data-rating' ) ;
var dialog = new RatingDialog ( $ . mobile . activePage ) ;
2013-11-08 08:37:22 -07:00
dialog . show ( {
header : "Rate and review " + name ,
id : id ,
rating : rating ,
2013-11-28 11:27:29 -07:00
callback : function ( review ) {
2013-11-08 08:37:22 -07:00
console . log ( review ) ;
dialog . close ( ) ;
2013-11-28 11:27:29 -07:00
ApiClient . createPackageReview ( review ) . done ( function ( ) {
2013-12-26 19:23:57 -07:00
Dashboard . alert ( {
message : "Thank you for your review" ,
title : "Thank You"
} ) ;
2013-11-08 08:37:22 -07:00
} ) ;
}
} ) ;
} ,
2013-11-28 11:27:29 -07:00
getStoreRatingHtml : function ( rating , id , name , noLinks ) {
2013-11-07 10:27:05 -07:00
2013-12-28 22:32:03 -07:00
var html = "<div style='margin-left: 5px; margin-right: 5px; display: inline-block; vertical-align:middle;'>" ;
2013-11-08 08:37:22 -07:00
if ( ! rating ) rating = 0 ;
2013-11-07 10:27:05 -07:00
2013-11-08 08:37:22 -07:00
for ( var i = 1 ; i <= 5 ; i ++ ) {
2013-11-08 13:53:09 -07:00
var title = noLinks ? rating + " stars" : "Rate " + i + ( i > 1 ? " stars" : " star" ) ;
2013-11-28 11:27:29 -07:00
2013-12-28 22:32:03 -07:00
html += noLinks ? "" : "<span data-id=" + id + " data-name='" + name + "' data-rating=" + i + " onclick='Dashboard.ratePackage(this);return false;' >" ;
2013-11-09 11:36:45 -07:00
if ( rating <= i - 1 ) {
2013-11-08 13:53:09 -07:00
html += "<div class='storeStarRating emptyStarRating' title='" + title + "'></div>" ;
2013-11-08 08:37:22 -07:00
} else if ( rating < i ) {
2013-11-08 13:53:09 -07:00
html += "<div class='storeStarRating halfStarRating' title='" + title + "'></div>" ;
2013-11-08 08:37:22 -07:00
} else {
2013-11-08 13:53:09 -07:00
html += "<div class='storeStarRating' title='" + title + "'></div>" ;
2013-11-08 08:37:22 -07:00
}
2013-12-28 22:32:03 -07:00
html += noLinks ? "" : "</span>" ;
2013-11-08 08:37:22 -07:00
}
html += "</div>" ;
return html ;
2013-12-28 09:58:13 -07:00
} ,
2014-02-08 13:02:35 -07:00
populateLanguages : function ( select , languages ) {
2013-12-28 09:58:13 -07:00
var html = "" ;
html += "<option value=''></option>" ;
for ( var i = 0 , length = languages . length ; i < length ; i ++ ) {
var culture = languages [ i ] ;
html += "<option value='" + culture . TwoLetterISOLanguageName + "'>" + culture . DisplayName + "</option>" ;
}
$ ( select ) . html ( html ) . selectmenu ( "refresh" ) ;
} ,
populateCountries : function ( select , allCountries ) {
var html = "" ;
html += "<option value=''></option>" ;
for ( var i = 0 , length = allCountries . length ; i < length ; i ++ ) {
var culture = allCountries [ i ] ;
html += "<option value='" + culture . TwoLetterISORegionName + "'>" + culture . DisplayName + "</option>" ;
}
$ ( select ) . html ( html ) . selectmenu ( "refresh" ) ;
2014-04-13 10:27:13 -07:00
} ,
getSupportedRemoteCommands : function ( ) {
// Full list
// https://github.com/MediaBrowser/MediaBrowser/blob/master/MediaBrowser.Model/Session/GeneralCommand.cs
return [
"GoHome" ,
"GoToSettings" ,
"VolumeUp" ,
"VolumeDown" ,
"Mute" ,
"Unmute" ,
"ToggleMute" ,
"SetVolume" ,
"SetAudioStreamIndex" ,
"SetSubtitleStreamIndex" ,
2014-04-27 18:57:29 -07:00
"DisplayContent" ,
"GoToSearch"
2014-04-13 10:27:13 -07:00
] ;
2013-11-08 08:37:22 -07:00
}
2013-10-18 12:47:57 -07:00
} ;
2013-04-01 22:14:37 -07:00
2013-10-18 12:47:57 -07:00
if ( ! window . WebSocket ) {
2014-01-03 19:35:41 -07:00
alert ( "This browser does not support web sockets. For a better experience, try a newer browser such as Chrome, Firefox, IE10+, Safari (iOS) or Opera." ) ;
2013-10-18 12:47:57 -07:00
}
2014-01-03 19:35:41 -07:00
else if ( ! IsStorageEnabled ( ) ) {
alert ( "This browser does not support local storage or is running in private mode. For a better experience, try a newer browser such as Chrome, Firefox, IE10+, Safari (iOS) or Opera." ) ;
2013-10-18 12:47:57 -07:00
}
2013-04-19 15:09:21 -07:00
2013-03-22 21:04:36 -07:00
2013-07-09 09:11:16 -07:00
var ApiClient = MediaBrowser . ApiClient . create ( "Dashboard" , window . dashboardVersion ) ;
2013-03-22 21:04:36 -07:00
2014-04-13 10:27:13 -07:00
$ ( ApiClient ) . on ( "websocketopen" , Dashboard . onWebSocketOpened ) . on ( "websocketmessage" , Dashboard . onWebSocketMessageReceived ) ;
2013-09-05 10:26:03 -07:00
2013-03-22 21:04:36 -07:00
$ ( function ( ) {
2014-03-20 01:34:54 -07:00
var videoPlayerHtml = '<div id="mediaPlayer" data-theme="b" class="ui-bar-b" style="display: none;">' ;
2014-03-17 15:37:05 -07:00
2014-03-20 01:34:54 -07:00
videoPlayerHtml += '<div id="videoBackdrop">' ;
videoPlayerHtml += '<div id="videoPlayer">' ;
videoPlayerHtml += '<div id="videoElement">' ;
2014-03-17 15:37:05 -07:00
2014-03-20 01:34:54 -07:00
videoPlayerHtml += '<div id="play" class="status"></div>' ;
videoPlayerHtml += '<div id="pause" class="status"></div>' ;
2014-03-17 15:37:05 -07:00
2014-03-20 01:34:54 -07:00
videoPlayerHtml += '</div>' ;
// Create controls
videoPlayerHtml += '<div id="videoControls" class="videoControls">' ;
videoPlayerHtml += '<div class="positionSliderContainer sliderContainer">' ;
videoPlayerHtml += '<input type="range" class="mediaSlider positionSlider slider" step=".001" min="0" max="100" value="0" style="display:none;" data-mini="true" data-theme="a" data-highlight="true" />' ;
videoPlayerHtml += '</div>' ;
2014-03-31 14:39:12 -07:00
videoPlayerHtml += '<div id="video-basic-controls">' ;
2014-03-20 01:34:54 -07:00
videoPlayerHtml += '<button id="video-previousTrackButton" class="mediaButton previousTrackButton" title="Previous Track" type="button" onclick="MediaPlayer.previousTrack();" data-icon="previous-track" data-iconpos="notext" data-inline="true">Previous Track</button>' ;
videoPlayerHtml += '<button id="video-playButton" class="mediaButton" title="Play" type="button" onclick="MediaPlayer.unpause();" data-icon="play" data-iconpos="notext" data-inline="true">Play</button>' ;
videoPlayerHtml += '<button id="video-pauseButton" class="mediaButton" title="Pause" type="button" onclick="MediaPlayer.pause();" data-icon="pause" data-iconpos="notext" data-inline="true">Pause</button>' ;
videoPlayerHtml += '<button id="video-stopButton" class="mediaButton" title="Stop" type="button" onclick="MediaPlayer.stop();" data-icon="stop" data-iconpos="notext" data-inline="true">Stop</button>' ;
videoPlayerHtml += '<button id="video-nextTrackButton" class="mediaButton nextTrackButton" title="Next Track" type="button" onclick="MediaPlayer.nextTrack();" data-icon="next-track" data-iconpos="notext" data-inline="true">Next Track</button>' ;
videoPlayerHtml += '<div class="currentTime"></div>' ;
2014-04-11 08:36:25 -07:00
videoPlayerHtml += '<div class="nowPlayingImage"></div>' ;
videoPlayerHtml += '<div class="nowPlayingText"></div>' ;
2014-03-20 01:34:54 -07:00
videoPlayerHtml += '<button id="video-muteButton" class="mediaButton muteButton" title="Mute" type="button" onclick="MediaPlayer.mute();" data-icon="audio" data-iconpos="notext" data-inline="true">Mute</button>' ;
2014-04-05 10:01:04 -07:00
videoPlayerHtml += '<button id="video-unmuteButton" class="mediaButton unmuteButton" title="Unmute" type="button" onclick="MediaPlayer.unMute();" data-icon="volume-off" data-iconpos="notext" data-inline="true">Unmute</button>' ;
2014-03-20 01:34:54 -07:00
videoPlayerHtml += '<div class="volumeSliderContainer sliderContainer">' ;
videoPlayerHtml += '<input type="range" class="mediaSlider volumeSlider slider" step=".05" min="0" max="1" value="0" style="display:none;" data-mini="true" data-theme="a" data-highlight="true" />' ;
videoPlayerHtml += '</div>' ;
2014-03-31 14:39:12 -07:00
videoPlayerHtml += '</div>' ; // video-basic-controls
videoPlayerHtml += '<div id="video-advanced-controls">' ;
2014-03-20 01:34:54 -07:00
videoPlayerHtml += '<button onclick="MediaPlayer.showQualityFlyout();" id="video-qualityButton" class="mediaButton qualityButton" title="Quality" type="button" data-icon="gear" data-iconpos="notext" data-inline="true">Quality</button>' ;
videoPlayerHtml += '<div class="mediaFlyoutContainer"><div id="video-qualityFlyout" style="display:none;" class="mediaPlayerFlyout"></div></div>' ;
videoPlayerHtml += '<button onclick="MediaPlayer.showAudioTracksFlyout();" id="video-audioTracksButton" class="imageButton mediaButton audioTracksButton" title="Audio tracks" type="button" data-icon="audiocd" data-iconpos="notext" data-inline="true">Audio Tracks</button>' ;
videoPlayerHtml += '<div class="mediaFlyoutContainer"><div id="video-audioTracksFlyout" style="display:none;" class="mediaPlayerFlyout audioTracksFlyout"></div></div>' ;
videoPlayerHtml += '<button onclick="MediaPlayer.showSubtitleMenu();" id="video-subtitleButton" class="imageButton mediaButton subtitleButton" title="Subtitles" type="button" data-icon="subtitles" data-iconpos="notext" data-inline="true">Subtitles</button>' ;
videoPlayerHtml += '<div class="mediaFlyoutContainer"><div id="video-subtitleFlyout" style="display:none;" class="mediaPlayerFlyout subtitleFlyout"></div></div>' ;
videoPlayerHtml += '<button onclick="MediaPlayer.showChaptersFlyout();" id="video-chaptersButton" class="mediaButton chaptersButton" title="Scenes" type="button" data-icon="video" data-iconpos="notext" data-inline="true">Scenes</button>' ;
videoPlayerHtml += '<div class="mediaFlyoutContainer"><div id="video-chaptersFlyout" style="display:none;" class="mediaPlayerFlyout chaptersFlyout"></div></div>' ;
2014-03-08 01:09:45 -07:00
2014-04-11 20:48:57 -07:00
videoPlayerHtml += '<button onclick="MediaPlayer.toggleFullscreen();" id="video-fullscreenButton" class="mediaButton fullscreenButton" title="Fullscreen" type="button" data-icon="expand" data-iconpos="notext" data-inline="true">Fullscreen</button>' ;
2014-03-31 14:39:12 -07:00
videoPlayerHtml += '</div>' ; // video-advanced-controls
2014-03-25 12:48:54 -07:00
2014-03-20 01:34:54 -07:00
videoPlayerHtml += '</div>' ; // videoControls
2014-03-17 15:37:05 -07:00
2014-03-20 01:34:54 -07:00
videoPlayerHtml += '</div>' ; // videoPlayer
videoPlayerHtml += '</div>' ; // videoBackdrop
videoPlayerHtml += '</div>' ; // mediaPlayer
$ ( document . body ) . append ( videoPlayerHtml ) ;
var mediaPlayerElem = $ ( '#mediaPlayer' , document . body ) ;
mediaPlayerElem . trigger ( 'create' ) ;
var footerHtml = '<div id="footer" data-theme="b" class="ui-bar-b">' ;
2014-04-13 10:27:13 -07:00
2014-03-17 15:37:05 -07:00
footerHtml += '<div id="footerNotifications"></div>' ;
2013-03-22 21:04:36 -07:00
footerHtml += '</div>' ;
$ ( document . body ) . append ( footerHtml ) ;
2013-09-19 17:53:18 -07:00
2013-12-27 21:42:40 -07:00
var footerElem = $ ( '#footer' , document . body ) ;
footerElem . trigger ( 'create' ) ;
2014-04-13 10:27:13 -07:00
2014-03-31 21:16:35 -07:00
$ ( window ) . on ( "beforeunload" , function ( ) {
2013-09-09 11:23:55 -07:00
// Close the connection gracefully when possible
if ( ApiClient . isWebSocketOpen ( ) && ! MediaPlayer . isPlaying ( ) ) {
2013-12-26 11:46:38 -07:00
console . log ( 'Sending close web socket command' ) ;
2013-09-09 11:23:55 -07:00
ApiClient . closeWebSocket ( ) ;
}
} ) ;
2013-03-22 21:04:36 -07:00
} ) ;
Dashboard . jQueryMobileInit ( ) ;
2013-07-16 09:03:28 -07:00
$ ( document ) . on ( 'pagebeforeshow' , ".page" , function ( ) {
2013-03-22 21:04:36 -07:00
var page = $ ( this ) ;
2013-03-26 15:40:01 -07:00
2013-03-22 21:04:36 -07:00
var userId = Dashboard . getCurrentUserId ( ) ;
ApiClient . currentUserId ( userId ) ;
2014-04-24 10:30:59 -07:00
if ( userId ) {
2013-03-22 21:04:36 -07:00
Dashboard . getCurrentUser ( ) . done ( function ( user ) {
2014-04-24 10:30:59 -07:00
if ( ! user . Configuration . IsAdministrator && page . hasClass ( 'type-interior' ) && ! page . hasClass ( 'publicUserPage' ) ) {
2013-08-20 07:42:07 -07:00
window . location . replace ( "index.html" ) ;
2013-03-22 21:04:36 -07:00
}
2013-05-10 05:18:07 -07:00
2014-04-24 10:30:59 -07:00
Dashboard . ensureToolsMenu ( page , user ) ;
2013-07-16 09:03:28 -07:00
Dashboard . ensureHeader ( page , user ) ;
Dashboard . ensurePageTitle ( page ) ;
} ) ;
2013-09-19 17:53:18 -07:00
}
2013-04-25 20:31:10 -07:00
2014-04-24 10:30:59 -07:00
else {
if ( this . id !== "loginPage" && ! page . hasClass ( 'wizardPage' ) ) {
Dashboard . logout ( ) ;
return ;
}
Dashboard . ensureHeader ( page ) ;
Dashboard . ensurePageTitle ( page ) ;
}
2013-09-19 17:53:18 -07:00
if ( ! ApiClient . isWebSocketOpen ( ) ) {
2013-07-16 09:03:28 -07:00
Dashboard . refreshSystemInfoFromServer ( ) ;
}
2014-04-09 20:47:57 -07:00
} ) ;