2013-04-24 14:01:48 -07:00
( function ( $ , document , window ) {
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
function populateHistory ( packageInfo , page ) {
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
var html = '' ;
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
for ( var i = 0 , length = Math . min ( packageInfo . versions . length , 10 ) ; i < length ; i ++ ) {
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
var version = packageInfo . versions [ i ] ;
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
html += '<h2 style="margin:.5em 0;">' + version . versionStr + ' (' + version . classification + ')</h2>' ;
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
html += '<div style="margin-bottom:1.5em;">' + version . description + '</div>' ;
}
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
$ ( '#revisionHistory' , page ) . html ( html ) ;
}
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
function populateVersions ( packageInfo , page , installedPlugin ) {
var html = '' ;
for ( var i = 0 , length = packageInfo . versions . length ; i < length ; i ++ ) {
var version = packageInfo . versions [ i ] ;
html += '<option value="' + version . versionStr + '|' + version . classification + '">' + version . versionStr + ' (' + version . classification + ')</option>' ;
}
var selectmenu = $ ( '#selectVersion' , page ) . html ( html ) ;
var packageVersion ;
if ( installedPlugin ) {
// Select the first available package with the same update class as the installed version
packageVersion = packageInfo . versions . filter ( function ( current ) {
return current . classification == installedPlugin . UpdateClass ;
} ) [ 0 ] ;
} else {
$ ( '#pCurrentVersion' , page ) . hide ( ) . html ( "" ) ;
}
// If we don't have a package version to select, pick the first release build
if ( ! packageVersion ) {
// Select the first available package with the same update class as the installed version
packageVersion = packageInfo . versions . filter ( function ( current ) {
return current . classification == "Release" ;
} ) [ 0 ] ;
}
// If we still don't have a package version to select, pick the first Beta build
if ( ! packageVersion ) {
// Select the first available package with the same update class as the installed version
packageVersion = packageInfo . versions . filter ( function ( current ) {
return current . classification == "Beta" ;
} ) [ 0 ] ;
}
if ( packageVersion ) {
var val = packageVersion . versionStr + '|' + packageVersion . classification ;
$ ( '#selectVersion' , page ) . val ( val ) ;
}
selectmenu . selectmenu ( 'refresh' ) ;
}
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
function renderPackage ( pkg , installedPlugins , pluginSecurityInfo , page ) {
2013-02-20 18:33:05 -07:00
var installedPlugin = installedPlugins . filter ( function ( ip ) {
return ip . Name == pkg . name ;
} ) [ 0 ] ;
2013-04-24 14:01:48 -07:00
populateVersions ( pkg , page , installedPlugin ) ;
populateHistory ( pkg , page ) ;
2013-02-20 18:33:05 -07:00
Dashboard . setPageTitle ( pkg . name ) ;
2013-04-24 14:01:48 -07:00
if ( pkg . targetSystem == 'Server' ) {
$ ( "#btnInstallDiv" , page ) . show ( ) ;
$ ( "#nonServerMsg" , page ) . hide ( ) ;
$ ( "#pSelectVersion" , page ) . show ( ) ;
} else {
$ ( "#btnInstallDiv" , page ) . hide ( ) ;
$ ( "#pSelectVersion" , page ) . hide ( ) ;
$ ( "#nonServerMsg" , page ) . html ( "This plugin must be installed from " + pkg . targetSystem ) . show ( ) ;
}
2013-04-03 19:25:14 -07:00
2013-02-20 18:33:05 -07:00
if ( pkg . shortDescription ) {
$ ( '#tagline' , page ) . show ( ) . html ( pkg . shortDescription ) ;
} else {
$ ( '#tagline' , page ) . hide ( ) ;
}
$ ( '#overview' , page ) . html ( pkg . overview || "" ) ;
$ ( '#developer' , page ) . html ( pkg . owner ) ;
if ( pkg . isPremium ) {
$ ( '.premiumPackage' , page ) . show ( ) ;
// Fill in registration info
var regStatus = "<strong>" ;
if ( pkg . isRegistered ) {
regStatus += "You are currently registered for this feature" ;
} else {
if ( new Date ( pkg . expDate ) . getTime ( ) < new Date ( 1970 , 1 , 1 ) . getTime ( ) ) {
2013-03-07 12:03:23 -07:00
regStatus += "This feature has no registration information" ;
2013-02-20 18:33:05 -07:00
} else {
2013-03-14 11:14:12 -07:00
if ( new Date ( pkg . expDate ) . getTime ( ) <= new Date ( ) . getTime ( ) ) {
regStatus += "The trial period for this feature has expired" ;
2013-02-20 18:33:05 -07:00
} else {
regStatus += "The trial period for this feature will expire in " + Math . round ( ( new Date ( pkg . expDate ) . getTime ( ) - new Date ( ) . getTime ( ) ) / ( 86400000 ) ) + " day(s)" ;
}
}
}
regStatus += "</strong>" ;
$ ( '#regStatus' , page ) . html ( regStatus ) ;
if ( pluginSecurityInfo . IsMBSupporter ) {
$ ( '#regInfo' , page ) . html ( pkg . regInfo || "" ) ;
2013-03-07 12:03:23 -07:00
if ( pkg . price > 0 ) {
// Fill in PayPal info
2013-04-23 07:38:36 -07:00
$ ( '.premiumHasPrice' , page ) . show ( ) ;
2013-03-07 12:03:23 -07:00
$ ( '#featureId' , page ) . val ( pkg . featureId ) ;
$ ( '#featureName' , page ) . val ( pkg . name ) ;
$ ( '#amount' , page ) . val ( pkg . price ) ;
$ ( '#regPrice' , page ) . html ( "<h2>Price: $" + pkg . price . toFixed ( 2 ) + " (USD)</h2>" ) ;
var url = "http://mb3admin.com/admin/service/user/getPayPalEmail?id=" + pkg . owner ;
2013-04-24 14:01:48 -07:00
$ . getJSON ( url ) . done ( function ( dev ) {
2013-03-07 12:03:23 -07:00
if ( dev . payPalEmail ) {
$ ( '#payPalEmail' , page ) . val ( dev . payPalEmail ) ;
} else {
$ ( '#ppButton' , page ) . hide ( ) ;
$ ( '#noEmail' , page ) . show ( ) ;
}
} ) ;
} else {
// Supporter-only feature
2013-04-23 07:38:36 -07:00
$ ( '.premiumHasPrice' , page ) . hide ( ) ;
2013-03-07 12:03:23 -07:00
}
2013-02-20 18:33:05 -07:00
} else {
2013-03-26 20:00:50 -07:00
$ ( '#regInfo' , page ) . html ( "You must be a <a href='supporter.html'>Media Browser Supporter</a> in order to gain access to this feature." ) . trigger ( 'create' ) ;
2013-02-20 18:33:05 -07:00
$ ( '#ppButton' , page ) . hide ( ) ;
}
} else {
$ ( '.premiumPackage' , page ) . hide ( ) ;
}
if ( pkg . richDescUrl ) {
$ ( '#pViewWebsite' , page ) . show ( ) ;
$ ( '#pViewWebsite a' , page ) [ 0 ] . href = pkg . richDescUrl ;
} else {
$ ( '#pViewWebsite' , page ) . hide ( ) ;
}
2013-05-11 23:05:51 -07:00
if ( pkg . previewImage || pkg . thumbImage ) {
2013-02-20 18:33:05 -07:00
var color = pkg . tileColor || "#2572EB" ;
var img = pkg . previewImage ? pkg . previewImage : pkg . thumbImage ;
$ ( '#pPreviewImage' , page ) . show ( ) . html ( "<img src='" + img + "' style='max-width: 100%;border-radius:10px;-moz-box-shadow: 0 0 20px 3px " + color + ";-webkit-box-shadow: 0 0 20px 3px " + color + ";box-shadow: 0 0 20px 3px " + color + ";' />" ) ;
} else {
$ ( '#pPreviewImage' , page ) . hide ( ) . html ( "" ) ;
}
if ( installedPlugin ) {
$ ( '#pCurrentVersion' , page ) . show ( ) . html ( "You currently have version <strong>" + installedPlugin . Version + "</strong> installed." ) ;
} else {
$ ( '#pCurrentVersion' , page ) . hide ( ) . html ( "" ) ;
}
Dashboard . hideLoadingMsg ( ) ;
2013-04-24 14:01:48 -07:00
}
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
$ ( document ) . on ( 'pageshow' , "#addPluginPage" , function ( ) {
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
var page = this ;
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
Dashboard . showLoadingMsg ( ) ;
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
var name = getParameterByName ( 'name' ) ;
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
var promise1 = ApiClient . getPackageInfo ( name ) ;
var promise2 = ApiClient . getInstalledPlugins ( ) ;
var promise3 = ApiClient . getPluginSecurityInfo ( ) ;
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
$ . when ( promise1 , promise2 , promise3 ) . done ( function ( response1 , response2 , response3 ) {
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
renderPackage ( response1 [ 0 ] , response2 [ 0 ] , response3 [ 0 ] , page ) ;
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
} ) ;
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
} ) ;
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
function performInstallation ( packageName , updateClass , version ) {
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
ApiClient . installPlugin ( packageName , updateClass , version ) . done ( function ( ) {
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
Dashboard . hideLoadingMsg ( ) ;
} ) ;
}
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
function addPluginpage ( ) {
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
var self = this ;
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
self . onSubmit = function ( ) {
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
Dashboard . showLoadingMsg ( ) ;
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
var page = $ ( this ) . parents ( '#addPluginPage' ) ;
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
$ ( '#btnInstall' , page ) . button ( 'disable' ) ;
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
var name = getParameterByName ( 'name' ) ;
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
ApiClient . getInstalledPlugins ( ) . done ( function ( plugins ) {
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
var installedPlugin = plugins . filter ( function ( ip ) {
return ip . Name == name ;
} ) [ 0 ] ;
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
var vals = $ ( '#selectVersion' , page ) . val ( ) . split ( '|' ) ;
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
var version = vals [ 0 ] ;
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
if ( installedPlugin && installedPlugin . Version == version ) {
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
Dashboard . hideLoadingMsg ( ) ;
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
Dashboard . confirm ( "Are you sure you wish to reinstall the same version you already have? In most cases this will not have any effect." , "Plugin Reinstallation" , function ( confirmResult ) {
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
if ( confirmResult ) {
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
Dashboard . showLoadingMsg ( ) ;
performInstallation ( name , vals [ 1 ] , version ) ;
} else {
$ ( '#btnInstall' , page ) . button ( 'enable' ) ;
}
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
} ) ;
} else {
performInstallation ( name , vals [ 1 ] , version ) ;
}
} ) ;
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
return false ;
} ;
2013-02-20 18:33:05 -07:00
}
2013-04-24 14:01:48 -07:00
window . AddPluginPage = new addPluginpage ( ) ;
} ) ( jQuery , document , window ) ;