2014-08-24 08:48:06 -07:00
( function ( ) {
2014-08-31 15:20:38 -07:00
function addRecurringFields ( period , page ) {
2013-02-20 18:33:05 -07:00
2014-07-03 11:47:43 -07:00
// Add recurring fields to form
$ ( "<input type='hidden' name='a3' class='pprecurring' />" )
2014-08-24 08:48:06 -07:00
. attr ( 'value' , $ ( '#donateAmt' , page ) . val ( ) )
2014-08-31 15:20:38 -07:00
. appendTo ( "#payPalSupporterForm" , page ) ;
2014-08-24 08:48:06 -07:00
2014-08-16 22:38:13 -07:00
$ ( "<input type='hidden' name='p3' value='1' class='pprecurring' />" )
2014-08-31 15:20:38 -07:00
. appendTo ( "#payPalSupporterForm" , page ) ;
2014-08-24 08:48:06 -07:00
2014-08-31 15:20:38 -07:00
$ ( "<input type='hidden' name='t3' value='" + period + "' class='pprecurring' />" )
. appendTo ( "#payPalSupporterForm" , page ) ;
2014-08-24 08:48:06 -07:00
2014-07-03 11:47:43 -07:00
$ ( "<input type='hidden' name='src' value='1' class='pprecurring' />" )
2014-08-31 15:20:38 -07:00
. appendTo ( "#payPalSupporterForm" , page ) ;
2014-08-24 08:48:06 -07:00
2014-07-03 11:47:43 -07:00
$ ( "<input type='hidden' name='sra' value='1' class='pprecurring' />" )
2014-08-31 15:20:38 -07:00
. appendTo ( "#payPalSupporterForm" , page ) ;
2013-02-20 18:33:05 -07:00
2014-07-03 11:47:43 -07:00
//change command for subscriptions
2014-08-24 08:48:06 -07:00
$ ( '#ppCmd' , page ) . val ( '_xclick-subscriptions' ) ;
2014-08-31 15:20:38 -07:00
$ ( '#payPalSupporterForm' , page ) . trigger ( 'create' ) ;
console . log ( $ ( '#payPalSupporterForm' , page ) . html ( ) ) ;
2014-08-24 08:48:06 -07:00
}
function removeRecurringFields ( page ) {
2014-08-16 22:38:13 -07:00
$ ( '.pprecurring' , page ) . remove ( ) ;
2014-08-24 08:48:06 -07:00
2014-07-03 11:47:43 -07:00
//change command back
2014-08-16 22:38:13 -07:00
$ ( '#ppCmd' , page ) . val ( '_xclick' ) ;
2014-08-24 08:48:06 -07:00
}
2014-08-31 12:15:33 -07:00
2014-08-27 11:55:51 -07:00
function setItemNumber ( page , itemNumber ) {
$ ( '#ppItemNo' , page ) . val ( itemNumber ) ;
}
2014-08-24 08:48:06 -07:00
function getDonationType ( page ) {
return $ ( ".radioDonationType:checked" , page ) . val ( ) ;
}
var lifeTimeAmount = 30 ;
2014-09-03 18:44:40 -07:00
var dailyAmount = 1 ;
2014-08-24 08:48:06 -07:00
var monthlyAmount = 3 ;
var yearlyAmount = 20 ;
function getDonationAmount ( page ) {
var type = getDonationType ( page ) ;
if ( type == 'once' ) {
return $ ( "#selectOneTimeDonationAmount" , page ) . val ( ) ;
}
if ( type == 'yearly' ) {
return yearlyAmount ;
}
if ( type == 'monthly' ) {
return monthlyAmount ;
}
2014-09-03 18:44:40 -07:00
if ( type == 'daily' ) {
return dailyAmount ;
}
2014-08-24 08:48:06 -07:00
// lifetime
return lifeTimeAmount ;
}
function updateSavedDonationAmount ( page ) {
$ ( "#donateAmt" , page ) . val ( getDonationAmount ( page ) ) ;
}
2014-08-31 12:15:33 -07:00
function loadUserInfo ( page ) {
ApiClient . getJSON ( ApiClient . getUrl ( 'System/SupporterInfo' ) ) . done ( function ( info ) {
$ ( '.hfPlanType' , page ) . val ( info . PlanType || '' ) ;
$ ( '.hfIsActive' , page ) . val ( info . IsActiveSupporter . toString ( ) ) ;
$ ( '.radioDonationType' , page ) . checked ( false ) . checkboxradio ( 'refresh' ) ;
if ( info . PlanType == 'Lifetime' && info . IsActiveSupporter ) {
// If they have an active lifetime plan, select the one-time option
$ ( '#radioOneTimeDonation' , page ) . checked ( true ) . checkboxradio ( 'refresh' ) ;
} else {
// For all other statuses, select lifetime, to either acquire or upgrade
$ ( '#radioLifetimeSupporter' , page ) . checked ( true ) . checkboxradio ( 'refresh' ) ;
}
$ ( '.radioDonationType:checked' , page ) . trigger ( 'change' ) ;
if ( info . IsActiveSupporter || info . IsExpiredSupporter ) {
$ ( '.currentPlanInfo' , page ) . show ( ) ;
} else {
$ ( '.currentPlanInfo' , page ) . hide ( ) ;
}
if ( info . IsActiveSupporter && info . PlanType == 'Lifetime' ) {
$ ( '.planSummary' , page )
2014-09-04 20:48:53 -07:00
. html ( 'You have a lifetime supporter membership. You can provide additional donations on a one-time or recurring basis using the options below. Thank you for supporting Media Browser.' )
. css ( 'color' , 'blue' ) ;
2014-08-31 12:15:33 -07:00
}
else if ( info . IsActiveSupporter ) {
$ ( '.planSummary' , page )
. html ( 'You have an active ' + info . PlanType + ' membership. You can upgrade your plan using the options below.' )
2014-09-04 20:48:53 -07:00
. css ( 'color' , 'blue' ) ;
2014-08-31 12:15:33 -07:00
}
else if ( info . IsExpiredSupporter ) {
var expirationDate = info . ExpirationDate ? parseISO8601Date ( info . ExpirationDate , { toLocal : true } ) : new Date ( ) ;
expirationDate = expirationDate . toLocaleDateString ( ) ;
$ ( '.planSummary' , page )
. html ( 'Your ' + info . PlanType + ' membership expired on ' + expirationDate + '.' )
. css ( 'color' , 'red' ) ;
}
} ) ;
}
2014-08-24 08:48:06 -07:00
$ ( document ) . on ( 'pageinit' , "#supporterPage" , function ( ) {
2014-07-03 11:47:43 -07:00
2014-08-24 08:48:06 -07:00
var page = this ;
$ ( '.radioDonationType' , page ) . on ( 'change' , function ( ) {
var donationType = getDonationType ( page ) ;
updateSavedDonationAmount ( page ) ;
if ( donationType == 'once' ) {
$ ( '.fldOneTimeDonationAmount' , page ) . show ( ) ;
removeRecurringFields ( page ) ;
2014-08-27 11:55:51 -07:00
setItemNumber ( page , 'MBDonation' ) ;
$ ( '#oneTimeDescription' ) . show ( ) ;
2014-08-24 08:48:06 -07:00
}
else if ( donationType == 'yearly' ) {
$ ( '.fldOneTimeDonationAmount' , page ) . hide ( ) ;
2014-08-31 15:20:38 -07:00
addRecurringFields ( 'Y' , page ) ;
2014-08-27 11:55:51 -07:00
setItemNumber ( page , 'MBSClubYearly' ) ;
$ ( '#oneTimeDescription' ) . hide ( ) ;
2014-08-24 08:48:06 -07:00
}
else if ( donationType == 'monthly' ) {
$ ( '.fldOneTimeDonationAmount' , page ) . hide ( ) ;
2014-08-31 15:20:38 -07:00
addRecurringFields ( 'M' , page ) ;
2014-08-27 11:55:51 -07:00
setItemNumber ( page , 'MBSClubMonthly' ) ;
$ ( '#oneTimeDescription' ) . hide ( ) ;
2014-08-24 08:48:06 -07:00
}
2014-09-03 18:44:40 -07:00
else if ( donationType == 'daily' ) {
$ ( '.fldOneTimeDonationAmount' , page ) . hide ( ) ;
addRecurringFields ( 'D' , page ) ;
setItemNumber ( page , 'MBSClubDaily' ) ;
$ ( '#oneTimeDescription' ) . hide ( ) ;
}
2014-08-24 08:48:06 -07:00
else {
// Lifetime
$ ( '.fldOneTimeDonationAmount' , page ) . hide ( ) ;
removeRecurringFields ( page ) ;
2014-08-27 11:55:51 -07:00
setItemNumber ( page , 'MBSupporter' ) ;
2014-08-31 12:26:01 -07:00
$ ( '#oneTimeDescription' ) . hide ( ) ;
2014-08-24 08:48:06 -07:00
}
} ) ;
$ ( '#selectOneTimeDonationAmount' , page ) . on ( 'change' , function ( ) {
updateSavedDonationAmount ( page ) ;
} ) ;
} ) . on ( 'pageshow' , "#supporterPage" , function ( ) {
var page = this ;
$ ( '.lifetimeAmount' , page ) . html ( '$' + lifeTimeAmount ) ;
$ ( '.monthlyAmount' , page ) . html ( '$' + monthlyAmount ) ;
2014-09-03 18:44:40 -07:00
$ ( '.dailyAmount' , page ) . html ( '$' + dailyAmount ) ;
2014-08-24 08:48:06 -07:00
$ ( '.yearlyAmount' , page ) . html ( '$' + yearlyAmount ) ;
$ ( '#paypalReturnUrl' , page ) . val ( ApiClient . getUrl ( "supporterkey.html" ) ) ;
2014-07-03 11:47:43 -07:00
2014-08-24 08:48:06 -07:00
$ ( '.radioDonationType' , page ) . trigger ( 'change' ) ;
2013-02-20 18:33:05 -07:00
2014-08-31 12:15:33 -07:00
loadUserInfo ( page ) ;
2014-08-24 08:48:06 -07:00
} ) ;
2013-02-20 18:33:05 -07:00
2014-08-31 12:15:33 -07:00
window . SupporterPage = {
onSubmit : function ( ) {
var form = this ;
var page = $ ( form ) . parents ( '.page' ) ;
if ( $ ( '.hfIsActive' , page ) . val ( ) == 'true' ) {
var currentPlanType = $ ( '.hfPlanType' , page ) . val ( ) ;
if ( currentPlanType != 'Lifetime' ) {
// Use a regular alert to block the submission process until they hit ok
alert ( 'After completing this transaction you will need to cancel your previous recurring donation from within your PayPal account. Thank you for supporting Media Browser.' ) ;
}
}
}
} ;
2014-08-24 08:48:06 -07:00
} ) ( ) ;