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 ) ;
2013-05-13 08:55:59 -07:00
if ( ! installedPlugin ) {
2013-04-24 14:01:48 -07:00
$ ( '#pCurrentVersion' , page ) . hide ( ) . html ( "" ) ;
}
2014-03-30 09:49:40 -07:00
var packageVersion = packageInfo . versions . filter ( function ( current ) {
2013-04-24 14:01:48 -07:00
2014-03-30 09:49:40 -07:00
return current . classification == "Release" ;
} ) [ 0 ] ;
2013-04-24 14:01:48 -07:00
// If we still don't have a package version to select, pick the first Beta build
if ( ! packageVersion ) {
packageVersion = packageInfo . versions . filter ( function ( current ) {
return current . classification == "Beta" ;
} ) [ 0 ] ;
}
2013-05-13 08:55:59 -07:00
selectmenu . selectmenu ( 'refresh' ) ;
2013-04-24 14:01:48 -07:00
if ( packageVersion ) {
var val = packageVersion . versionStr + '|' + packageVersion . classification ;
2013-05-13 08:55:59 -07:00
selectmenu . val ( val ) . selectmenu ( 'refresh' ) ;
2013-04-24 14:01:48 -07:00
}
}
2014-01-02 14:21:06 -07:00
2013-11-08 13:53:09 -07:00
function populateReviews ( id , page ) {
// Get the latest positive and negative reviews
var promise1 = ApiClient . getPackageReviews ( id , 4 , null , 3 , true ) ;
var promise2 = ApiClient . getPackageReviews ( id , null , 2 , 3 , true ) ;
$ . when ( promise1 , promise2 ) . done ( function ( response1 , response2 ) {
//positive
2013-12-24 11:37:29 -07:00
var html = '<div data-role="collapsible" data-collapsed="true" style="margin-top: 2em;" >' ;
2013-11-08 13:53:09 -07:00
html += '<h3>Latest Outstanding Reviews</h3>' ;
2014-01-02 14:21:06 -07:00
2013-11-08 13:53:09 -07:00
var positive = response1 [ 0 ] ;
var hasReviews = false ;
if ( positive && positive . length > 0 ) {
for ( var i = 0 ; i < positive . length ; i ++ ) {
var review = positive [ i ] ;
if ( review . title ) {
hasReviews = true ;
html += "<div>" ;
html += "<span class='storeItemReviewText'>" ;
html += new Date ( review . timestamp ) . toDateString ( ) ;
html += " " + Dashboard . getStoreRatingHtml ( review . rating , review . id , review . name , true ) ;
html += " " + review . title ;
html += "</span>" ;
if ( review . review ) {
html += "<p class='storeItemReviewText'>" ;
html += review . review ;
html += "</p>" ;
}
html += "</div>" ;
html += "<hr/>" ;
}
}
}
if ( ! hasReviews ) {
html += "<p>No Outstanding Reviews with additional information</p>" ;
}
html += "</div>" ;
//negative
2013-12-24 11:37:29 -07:00
html += '<div data-role="collapsible" data-collapsed="true" style="margin-top: 2em;" >' ;
2013-11-08 13:53:09 -07:00
html += '<h3>Latest Negative Reviews</h3>' ;
var negative = response2 [ 0 ] ;
hasReviews = false ;
if ( negative && negative . length > 0 ) {
for ( var i = 0 ; i < negative . length ; i ++ ) {
review = negative [ i ] ;
if ( review . title ) {
hasReviews = true ;
html += "<div>" ;
html += "<span class='storeItemReviewText'>" ;
html += new Date ( review . timestamp ) . toDateString ( ) ;
html += " " + Dashboard . getStoreRatingHtml ( review . rating , review . id , review . name , true ) ;
html += " " + review . title ;
html += "</span>" ;
if ( review . review ) {
html += "<p class='storeItemReviewText'>" ;
html += review . review ;
html += "</p>" ;
}
html += "</div>" ;
html += "<hr/>" ;
}
}
}
2014-01-02 14:21:06 -07:00
2013-11-08 13:53:09 -07:00
if ( ! hasReviews ) {
html += "<p>No Negative Reviews with additional information</p>" ;
}
html += "</div>" ;
$ ( '#latestReviews' , page ) . html ( html ) . trigger ( 'create' ) ;
} ) ;
}
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-11-08 13:53:09 -07:00
if ( pkg . totalRatings > 0 ) populateReviews ( pkg . id , page ) ;
2014-01-02 14:21:06 -07:00
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 ( ) ;
2014-02-18 06:19:32 -07:00
var msg = "This plug-in must be installed from " + pkg . targetSystem ;
2013-06-19 08:00:31 -07:00
$ ( "#nonServerMsg" , page ) . html ( msg ) . show ( ) ;
2013-04-24 14:01:48 -07:00
}
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 ( ) ) {
} 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 || "" ) ;
2014-01-02 14:21:06 -07:00
$ ( '.premiumDescription' , page ) . hide ( ) ;
$ ( '.supporterDescription' , page ) . hide ( ) ;
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-08-31 09:36:31 -07:00
2014-01-02 14:21:06 -07:00
if ( pkg . price ) {
$ ( '.premiumDescription' , page ) . show ( ) ;
$ ( '.supporterDescription' , page ) . hide ( ) ;
$ ( '#regInfo' , page ) . html ( "" ) ;
} else {
$ ( '.premiumDescription' , page ) . hide ( ) ;
$ ( '.supporterDescription' , page ) . show ( ) ;
$ ( '#regInfo' , page ) . html ( "" ) ;
}
2013-08-31 09:36:31 -07:00
2013-02-20 18:33:05 -07:00
$ ( '#ppButton' , page ) . hide ( ) ;
}
} else {
$ ( '.premiumPackage' , page ) . hide ( ) ;
}
2014-01-02 14:21:06 -07:00
2013-11-08 13:53:09 -07:00
//Ratings and Reviews
var ratingHtml = "<strong>Overall </strong>" + Dashboard . getStoreRatingHtml ( pkg . avgRating , pkg . id , pkg . name ) ;
ratingHtml += "<span class='storeReviewCount'>" ;
ratingHtml += " " + pkg . totalRatings + " Reviews" ;
ratingHtml += "</span>" ;
$ ( '#ratingLine' , page ) . html ( ratingHtml ) ;
2013-02-20 18:33:05 -07:00
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
2014-02-12 22:11:54 -07:00
var color = pkg . tileColor || "#38c" ;
2013-02-20 18:33:05 -07:00
var img = pkg . previewImage ? pkg . previewImage : pkg . thumbImage ;
2013-07-05 17:19:44 -07:00
$ ( '#pPreviewImage' , page ) . show ( ) . html ( "<img src='" + img + "' style='max-width: 100%;-moz-box-shadow: 0 0 20px 3px " + color + ";-webkit-box-shadow: 0 0 20px 3px " + color + ";box-shadow: 0 0 20px 3px " + color + ";' />" ) ;
2013-02-20 18:33:05 -07:00
} 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-11-04 11:16:47 -07:00
var guid = getParameterByName ( 'guid' ) ;
2013-02-20 18:33:05 -07:00
2013-11-04 11:16:47 -07:00
var promise1 = ApiClient . getPackageInfo ( name , guid ) ;
2013-04-24 14:01:48 -07:00
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-11-04 11:16:47 -07:00
function performInstallation ( packageName , guid , updateClass , version ) {
2013-02-20 18:33:05 -07:00
2013-11-04 11:16:47 -07:00
ApiClient . installPlugin ( packageName , guid , 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-12-24 11:37:29 -07:00
$ ( '#btnInstall' , page ) . buttonEnabled ( false ) ;
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
var name = getParameterByName ( 'name' ) ;
2013-11-04 11:16:47 -07:00
var guid = getParameterByName ( 'guid' ) ;
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 ( ) ;
2013-11-04 11:16:47 -07:00
performInstallation ( name , guid , vals [ 1 ] , version ) ;
2013-04-24 14:01:48 -07:00
} else {
2013-12-24 11:37:29 -07:00
$ ( '#btnInstall' , page ) . buttonEnabled ( true ) ;
2013-04-24 14:01:48 -07:00
}
2013-02-20 18:33:05 -07:00
2013-04-24 14:01:48 -07:00
} ) ;
} else {
2013-11-04 11:16:47 -07:00
performInstallation ( name , guid , vals [ 1 ] , version ) ;
2013-04-24 14:01:48 -07:00
}
} ) ;
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 ) ;