2011-07-27 09:33:47 -07:00
NEWSBLUR . ReaderAccount = function ( options ) {
2011-09-21 17:49:26 -07:00
var defaults = {
2013-01-08 14:11:59 -08:00
'width' : 700 ,
2011-09-21 17:49:26 -07:00
'animate_email' : false ,
2011-09-22 09:23:42 -07:00
'change_password' : false ,
2011-09-21 17:49:26 -07:00
'onOpen' : _ . bind ( function ( ) {
2011-09-22 09:23:42 -07:00
this . animate _fields ( ) ;
2013-09-23 13:34:16 -07:00
$ ( window ) . trigger ( 'resize.simplemodal' ) ;
2011-09-21 17:49:26 -07:00
} , this )
} ;
2011-07-27 09:33:47 -07:00
this . options = $ . extend ( { } , defaults , options ) ;
2012-05-17 18:40:46 -07:00
this . model = NEWSBLUR . assets ;
2011-07-27 09:33:47 -07:00
this . runner ( ) ;
} ;
NEWSBLUR . ReaderAccount . prototype = new NEWSBLUR . Modal ;
NEWSBLUR . ReaderAccount . prototype . constructor = NEWSBLUR . ReaderAccount ;
_ . extend ( NEWSBLUR . ReaderAccount . prototype , {
runner : function ( ) {
2013-11-13 10:07:21 -08:00
this . options . onOpen = _ . bind ( function ( ) {
// $(window).resize();
} , this ) ;
2011-07-27 09:33:47 -07:00
this . make _modal ( ) ;
this . open _modal ( ) ;
this . $modal . bind ( 'click' , $ . rescope ( this . handle _click , this ) ) ;
2011-07-27 22:17:34 -07:00
this . handle _change ( ) ;
2011-09-21 17:49:26 -07:00
this . select _preferences ( ) ;
2012-12-03 15:03:47 -08:00
2014-04-03 14:59:30 -07:00
this . fetch _payment _history ( ) ;
2014-09-29 13:09:46 -07:00
this . render _dates ( ) ;
2018-04-25 18:07:07 -07:00
if ( this . options . tab ) {
this . switch _tab ( this . options . tab ) ;
}
2011-07-27 09:33:47 -07:00
} ,
make _modal : function ( ) {
var self = this ;
this . $modal = $ . make ( 'div' , { className : 'NB-modal-preferences NB-modal-account NB-modal' } , [
2013-04-11 16:50:18 -07:00
$ . make ( 'div' , { className : 'NB-modal-tabs' } , [
$ . make ( 'div' , { className : 'NB-modal-loading' } ) ,
$ . make ( 'div' , { className : 'NB-modal-tab NB-active NB-modal-tab-account' } , 'Account' ) ,
$ . make ( 'div' , { className : 'NB-modal-tab NB-modal-tab-premium' } , 'Payments' ) ,
2017-05-18 16:59:35 -07:00
$ . make ( 'div' , { className : 'NB-modal-tab NB-modal-tab-emails' } , 'Emails' ) ,
$ . make ( 'div' , { className : 'NB-modal-tab NB-modal-tab-custom' } , 'Custom CSS/JavaScript' )
2013-04-11 16:50:18 -07:00
] ) ,
2013-04-05 11:26:25 -07:00
$ . make ( 'h2' , { className : 'NB-modal-title' } , [
$ . make ( 'div' , { className : 'NB-icon' } ) ,
2013-05-22 17:05:30 -07:00
'Account' ,
$ . make ( 'div' , { className : 'NB-icon-dropdown' } )
2013-04-05 11:26:25 -07:00
] ) ,
2011-07-27 09:33:47 -07:00
$ . make ( 'form' , { className : 'NB-preferences-form' } , [
2013-04-11 16:50:18 -07:00
$ . make ( 'div' , { className : 'NB-tab NB-tab-account NB-active' } , [
$ . make ( 'div' , { className : 'NB-preference NB-preference-username' } , [
$ . make ( 'div' , { className : 'NB-preference-options' } , [
$ . make ( 'div' , { className : 'NB-preference-option' } , [
$ . make ( 'input' , { id : 'NB-preference-username' , type : 'text' , name : 'username' , value : NEWSBLUR . Globals . username } )
] )
] ) ,
$ . make ( 'div' , { className : 'NB-preference-label' } , [
$ . make ( 'label' , { 'for' : 'NB-preference-username' } , 'Username' ) ,
$ . make ( 'div' , { className : 'NB-preference-error' } )
2011-07-27 09:33:47 -07:00
] )
] ) ,
2013-04-11 16:50:18 -07:00
$ . make ( 'div' , { className : 'NB-preference NB-preference-email' } , [
$ . make ( 'div' , { className : 'NB-preference-options' } , [
$ . make ( 'div' , { className : 'NB-preference-option' } , [
$ . make ( 'input' , { id : 'NB-preference-email' , type : 'text' , name : 'email' , value : NEWSBLUR . Globals . email } )
] )
] ) ,
$ . make ( 'div' , { className : 'NB-preference-label' } , [
$ . make ( 'label' , { 'for' : 'NB-preference-email' } , 'Email address' ) ,
2011-07-27 09:33:47 -07:00
2013-04-11 16:50:18 -07:00
$ . make ( 'div' , { className : 'NB-preference-error' } )
2011-07-27 09:33:47 -07:00
] )
] ) ,
2013-04-11 16:50:18 -07:00
$ . make ( 'div' , { className : 'NB-preference NB-preference-password' } , [
$ . make ( 'div' , { className : 'NB-preference-options' } , [
$ . make ( 'div' , { className : 'NB-preference-option' , style : ( this . options . change _password ? 'opacity: .2' : '' ) } , [
$ . make ( 'label' , { 'for' : 'NB-preference-password-old' } , 'Old password' ) ,
$ . make ( 'input' , { id : 'NB-preference-password-old' , type : 'password' , name : 'old_password' , value : '' } )
] ) ,
$ . make ( 'div' , { className : 'NB-preference-option' } , [
$ . make ( 'label' , { 'for' : 'NB-preference-password-new' } , 'New password' ) ,
$ . make ( 'input' , { id : 'NB-preference-password-new' , type : 'password' , name : 'new_password' , value : '' } )
] )
2011-07-27 09:33:47 -07:00
] ) ,
2013-04-11 16:50:18 -07:00
$ . make ( 'div' , { className : 'NB-preference-label' } , [
'Change password' ,
$ . make ( 'div' , { className : 'NB-preference-error' } )
2011-07-27 09:33:47 -07:00
] )
] ) ,
2013-04-11 16:50:18 -07:00
$ . make ( 'div' , { className : 'NB-preference NB-preference-opml' } , [
$ . make ( 'div' , { className : 'NB-preference-options' } , [
2014-04-03 14:59:30 -07:00
$ . make ( 'a' , { className : 'NB-modal-submit-button NB-modal-submit-green' , href : NEWSBLUR . URLs [ 'opml-export' ] } , 'Download OPML' )
2013-04-11 16:50:18 -07:00
] ) ,
$ . make ( 'div' , { className : 'NB-preference-label' } , [
'Backup your sites' ,
$ . make ( 'div' , { className : 'NB-preference-sublabel' } , 'Download this XML file as a backup' )
] )
2011-07-27 09:33:47 -07:00
] ) ,
2014-09-29 13:09:46 -07:00
$ . make ( 'div' , { className : 'NB-preference NB-preference-delete' } , [
$ . make ( 'div' , { className : 'NB-preference-options' } , [
$ . make ( 'div' , { className : 'NB-preference-saved-stories-date' } ) ,
$ . make ( 'div' , { className : 'NB-modal-submit-button NB-modal-submit-red NB-account-delete-saved-stories' } , 'Delete my saved stories' )
] ) ,
$ . make ( 'div' , { className : 'NB-preference-label' } , [
'Erase your saved stories'
] )
] ) ,
2013-04-11 16:50:18 -07:00
$ . make ( 'div' , { className : 'NB-preference NB-preference-delete' } , [
$ . make ( 'div' , { className : 'NB-preference-options' } , [
2014-04-03 14:59:30 -07:00
$ . make ( 'div' , { className : 'NB-modal-submit-button NB-modal-submit-red NB-account-delete-all-sites' } , 'Delete all of my sites' )
2013-04-11 16:50:18 -07:00
] ) ,
$ . make ( 'div' , { className : 'NB-preference-label' } , [
'Erase yourself' ,
2014-09-29 13:09:46 -07:00
$ . make ( 'div' , { className : 'NB-preference-sublabel' } , 'Friendly note: You will be emailed a backup of your sites' )
2013-05-23 18:14:21 -07:00
] )
] ) ,
$ . make ( 'div' , { className : 'NB-preference NB-preference-delete' } , [
$ . make ( 'div' , { className : 'NB-preference-options' } , [
2014-04-03 14:59:30 -07:00
$ . make ( 'a' , { className : 'NB-modal-submit-button NB-modal-submit-red' , href : NEWSBLUR . URLs [ 'delete-account' ] } , 'Delete my account' )
2013-05-23 18:14:21 -07:00
] ) ,
$ . make ( 'div' , { className : 'NB-preference-label' } , [
'Erase yourself permanently' ,
2013-04-11 16:50:18 -07:00
$ . make ( 'div' , { className : 'NB-preference-sublabel' } , 'Warning: This is actually permanent' )
] )
2011-07-27 09:33:47 -07:00
] )
] ) ,
2013-04-11 16:50:18 -07:00
$ . make ( 'div' , { className : 'NB-tab NB-tab-premium' } , [
$ . make ( 'div' , { className : 'NB-preference NB-preference-premium' } , [
$ . make ( 'div' , { className : 'NB-preference-options' } , [
2014-04-03 12:44:04 -07:00
( ! NEWSBLUR . Globals . is _premium && $ . make ( 'div' , [
2014-04-03 14:59:30 -07:00
$ . make ( 'div' , { style : 'margin-bottom: 12px;' } , [
'You have a ' ,
$ . make ( 'b' , 'free account' ) ,
'.'
] ) ,
2014-04-03 12:44:04 -07:00
$ . make ( 'a' , {
className : 'NB-modal-submit-button NB-modal-submit-green NB-account-premium-modal'
2014-04-03 14:59:30 -07:00
} , 'Upgrade to a Premium account' )
] ) ) ,
2013-04-11 16:50:18 -07:00
( NEWSBLUR . Globals . is _premium && $ . make ( 'div' , [
'Thank you! You have a ' ,
2022-01-26 10:53:56 -05:00
( NEWSBLUR . Globals . is _pro && $ . make ( 'b' , 'premium pro account' ) ) ,
( ! NEWSBLUR . Globals . is _pro && NEWSBLUR . Globals . is _archive && $ . make ( 'b' , 'premium archive account' ) ) ,
( ! NEWSBLUR . Globals . is _pro && ! NEWSBLUR . Globals . is _archive && NEWSBLUR . Globals . is _premium && $ . make ( 'b' , 'premium account' ) ) ,
2022-01-26 15:51:26 -05:00
'.' ,
( ! NEWSBLUR . Globals . is _archive && $ . make ( 'a' , {
className : 'NB-modal-submit-button NB-modal-submit-green NB-account-premium-modal NB-block'
} , 'Upgrade to a Premium Archive account' ) )
2013-04-11 16:50:18 -07:00
] ) )
] ) ,
$ . make ( 'div' , { className : 'NB-preference-label' } , [
2014-04-03 14:59:30 -07:00
'Premium status'
2012-12-03 15:03:47 -08:00
] )
] ) ,
2014-04-03 14:59:30 -07:00
( NEWSBLUR . Globals . is _premium && $ . make ( 'div' , { className : 'NB-preference NB-preference-premium-renew' } , [
$ . make ( 'div' , { className : 'NB-preference-options' } , [
2022-04-06 15:56:13 -04:00
$ . make ( 'div' , { className : "NB-premium-renewal-details-container" } , this . make _premium _renewal _details ( ) ) ,
$ . make ( 'div' , { className : 'NB-block NB-premium-expire-container' } , this . make _premium _expire ( ) ) ,
2014-04-03 14:59:30 -07:00
$ . make ( 'a' , { href : '#' , className : 'NB-block NB-account-premium-renew NB-modal-submit-button NB-modal-submit-green' } , 'Change your credit card' )
] ) ,
$ . make ( 'div' , { className : 'NB-preference-label' } , [
'Premium details'
] )
] ) ) ,
2013-04-11 16:50:18 -07:00
$ . make ( 'div' , { className : 'NB-preference NB-preference-premium-history' } , [
$ . make ( 'div' , { className : 'NB-preference-options' } , [
$ . make ( 'ul' , { className : 'NB-account-payments' } , [
$ . make ( 'li' , { className : 'NB-payments-loading' } , 'Loading...' )
2011-09-21 17:49:26 -07:00
] )
] ) ,
2013-04-11 16:50:18 -07:00
$ . make ( 'div' , { className : 'NB-preference-label' } , [
'Payment history'
2011-09-21 17:49:26 -07:00
] )
2014-04-03 14:59:30 -07:00
] ) ,
( NEWSBLUR . Globals . is _premium && $ . make ( 'div' , { className : 'NB-preference NB-preference-premium-cancel' } , [
2022-04-06 15:56:13 -04:00
$ . make ( 'div' , { className : 'NB-preference-options NB-premium-renewal-container' } , this . make _premium _renewal ( ) ) ,
2014-04-03 14:59:30 -07:00
$ . make ( 'div' , { className : 'NB-preference-label' } , [
'Premium renewal'
] )
] ) )
2011-09-21 17:49:26 -07:00
] ) ,
2013-04-11 16:50:18 -07:00
$ . make ( 'div' , { className : 'NB-tab NB-tab-emails' } , [
$ . make ( 'div' , { className : 'NB-preference NB-preference-emails' } , [
$ . make ( 'div' , { className : 'NB-preference-options' } , [
$ . make ( 'div' , [
$ . make ( 'input' , { id : 'NB-preference-emails-1' , type : 'radio' , name : 'send_emails' , value : 'true' } ) ,
$ . make ( 'label' , { 'for' : 'NB-preference-emails-1' } , [
'Email replies, re-shares, and new followers'
] )
] ) ,
$ . make ( 'div' , [
$ . make ( 'input' , { id : 'NB-preference-emails-2' , type : 'radio' , name : 'send_emails' , value : 'false' } ) ,
$ . make ( 'label' , { 'for' : 'NB-preference-emails-2' } , [
'Never ever send me an email'
] )
] )
] ) ,
$ . make ( 'div' , { className : 'NB-preference-label' } , [
'Emails'
] )
2013-01-03 10:33:22 -08:00
] )
] ) ,
2017-05-18 16:59:35 -07:00
$ . make ( 'div' , { className : 'NB-tab NB-tab-custom' } , [
$ . make ( 'fieldset' , [
$ . make ( 'legend' , 'Custom CSS' ) ,
$ . make ( 'div' , { className : 'NB-modal-section NB-profile-editor-blurblog-custom-css' } , [
$ . make ( 'textarea' , { 'className' : 'NB-account-custom-css' , name : 'custom_css' } , _ . string . trim ( $ ( "#NB-custom-css" ) . text ( ) ) )
] )
] ) ,
$ . make ( 'fieldset' , [
$ . make ( 'legend' , 'Custom JavaScript' ) ,
$ . make ( 'div' , { className : 'NB-modal-section NB-profile-editor-blurblog-custom-js' } , [
$ . make ( 'textarea' , { 'className' : 'NB-account-custom-javascript' , name : 'custom_js' } , _ . string . trim ( $ ( "#NB-custom-js" ) . text ( ) ) )
] )
] )
] ) ,
2011-07-27 09:33:47 -07:00
$ . make ( 'div' , { className : 'NB-modal-submit' } , [
2013-04-11 16:50:18 -07:00
$ . make ( 'input' , { type : 'submit' , disabled : 'true' , className : 'NB-modal-submit-button NB-modal-submit-green NB-disabled' , value : 'Change what you like above...' } )
2011-07-27 09:33:47 -07:00
] )
2011-07-27 22:17:34 -07:00
] ) . bind ( 'submit' , function ( e ) {
e . preventDefault ( ) ;
self . save _account _settings ( ) ;
return false ;
} )
2011-07-27 09:33:47 -07:00
] ) ;
} ,
2014-09-29 13:09:46 -07:00
render _dates : function ( ) {
var now = new Date ( ) ;
var this _year = now . getFullYear ( ) ;
var this _month = now . getMonth ( ) ;
var this _day = now . getDate ( ) ;
var $dates = $ ( ".NB-preference-saved-stories-date" , this . $modal ) ;
var $months = $ . make ( 'select' , { name : 'month' } ) ;
_ . each ( NEWSBLUR . utils . monthNames , function ( name , i ) {
var $option = $ . make ( 'option' , { value : i + "" } , name ) ;
2021-01-12 20:15:42 -05:00
if ( this _month == i ) $option . prop ( 'selected' , true ) ;
2014-09-29 13:09:46 -07:00
$months . append ( $option ) ;
} ) ;
var $days = $ . make ( 'select' , { name : 'day' } ) ;
_ . each ( _ . range ( 0 , 31 ) , function ( name , i ) {
var $option = $ . make ( 'option' , { value : i + 1 + "" } , i + 1 ) ;
2021-01-12 20:15:42 -05:00
if ( this _day == i + 1 ) $option . prop ( 'selected' , true ) ;
2014-09-29 13:09:46 -07:00
$days . append ( $option ) ;
} ) ;
var $years = $ . make ( 'select' , { name : 'year' } ) ;
_ . each ( _ . range ( 2009 , this _year + 1 ) , function ( name , i ) {
var $option = $ . make ( 'option' , { value : name + "" } , name ) ;
2021-01-12 20:15:42 -05:00
if ( this _year == name ) $option . prop ( 'selected' , true ) ;
2014-09-29 13:09:46 -07:00
$years . append ( $option ) ;
} ) ;
$dates . append ( $ . make ( 'span' , 'Older than: ' ) ) ;
$dates . append ( $months ) ;
$dates . append ( $days ) ;
$dates . append ( $years ) ;
} ,
2011-09-22 09:23:42 -07:00
animate _fields : function ( ) {
2011-09-21 17:49:26 -07:00
if ( this . options . animate _email ) {
2013-04-11 16:50:18 -07:00
this . switch _tab ( 'emails' ) ;
2011-09-21 17:49:26 -07:00
_ . delay ( _ . bind ( function ( ) {
var $emails = $ ( '.NB-preference-emails' , this . $modal ) ;
var bgcolor = $emails . css ( 'backgroundColor' ) ;
$emails . css ( 'backgroundColor' , bgcolor ) . animate ( {
'backgroundColor' : 'orange'
} , {
'queue' : false ,
'duration' : 1200 ,
'easing' : 'easeInQuad' ,
'complete' : function ( ) {
$emails . animate ( {
'backgroundColor' : bgcolor
} , {
'queue' : false ,
'duration' : 650 ,
'easing' : 'easeOutQuad'
} ) ;
}
} ) ;
} , this ) , 200 ) ;
2011-09-22 09:23:42 -07:00
} else if ( this . options . change _password ) {
_ . delay ( _ . bind ( function ( ) {
var $emails = $ ( '.NB-preference-password' , this . $modal ) ;
var bgcolor = $emails . css ( 'backgroundColor' ) ;
$emails . css ( 'backgroundColor' , bgcolor ) . animate ( {
'backgroundColor' : 'orange'
} , {
'queue' : false ,
'duration' : 1200 ,
'easing' : 'easeInQuad' ,
'complete' : function ( ) {
$emails . animate ( {
'backgroundColor' : bgcolor
} , {
'queue' : false ,
'duration' : 650 ,
'easing' : 'easeOutQuad'
} ) ;
}
} ) ;
} , this ) , 200 ) ;
2011-09-21 17:49:26 -07:00
}
2011-09-22 09:23:42 -07:00
2011-09-21 17:49:26 -07:00
} ,
2018-05-03 15:38:59 -07:00
close _and _load _premium : function ( options ) {
options = _ . extend ( { } , { 'premium_only' : true } , options ) ;
this . close ( function ( ) {
NEWSBLUR . reader . open _feedchooser _modal ( options ) ;
} ) ;
2011-07-27 09:33:47 -07:00
} ,
2013-03-13 15:46:51 -07:00
cancel _premium : function ( ) {
2014-04-03 15:14:33 -07:00
var $cancel = $ ( ".NB-account-premium-cancel" , this . $modal ) ;
$cancel . attr ( 'disabled' , 'disabled' ) ;
2022-01-26 15:51:26 -05:00
$cancel . removeClass ( 'NB-modal-submit-red' ) ;
$cancel . addClass ( 'NB-modal-submit-grey' ) ;
2014-04-03 15:14:33 -07:00
$cancel . text ( "Cancelling..." ) ;
var post _cancel = function ( message ) {
2022-01-26 15:51:26 -05:00
$cancel . remove ( ) ;
$ ( ".NB-account-payment.NB-scheduled" ) . addClass ( 'NB-canceled' ) ;
2014-04-03 14:59:30 -07:00
$ ( ".NB-preference-premium-cancel .NB-error" ) . remove ( ) ;
2020-10-19 15:07:14 -04:00
$ ( ".NB-preference-premium-cancel .NB-preference-options" ) . append ( $ . make ( "div" , {
className : "NB-error"
} , message ) . fadeIn ( 500 ) . css ( 'display' , 'block' ) ) ;
2014-04-03 15:14:33 -07:00
} ;
2013-03-13 15:46:51 -07:00
this . model . cancel _premium _subscription ( _ . bind ( function ( data ) {
2022-01-26 12:29:39 -05:00
NEWSBLUR . Globals . premium _renewal = false ;
2014-04-03 15:14:33 -07:00
post _cancel ( "Your subscription will no longer automatically renew." ) ;
2013-03-13 15:46:51 -07:00
} , this ) , _ . bind ( function ( data ) {
2022-01-26 12:29:39 -05:00
NEWSBLUR . Globals . premium _renewal = false ;
2014-04-03 15:14:33 -07:00
post _cancel ( data . message || "You have no active subscriptions." ) ;
2013-03-13 15:46:51 -07:00
} , this ) ) ;
} ,
2013-05-23 18:14:21 -07:00
delete _all _sites : function ( ) {
var $link = $ ( ".NB-account-delete-all-sites" , this . $modal ) ;
if ( window . confirm ( "Positive you want to delete everything?" ) ) {
NEWSBLUR . assets . delete _all _sites ( _ . bind ( function ( ) {
NEWSBLUR . assets . load _feeds ( ) ;
$link . replaceWith ( $ . make ( 'div' , 'Everything has been deleted.' ) ) ;
} , this ) , _ . bind ( function ( ) {
$link . replaceWith ( $ . make ( 'div' , { className : 'NB-error' } , 'There was a problem deleting your sites.' ) ) ;
} , this ) ) ;
}
} ,
2014-09-29 13:09:46 -07:00
delete _saved _stories : function ( ) {
var $link = $ ( ".NB-account-delete-saved-stories" , this . $modal ) ;
2014-09-29 13:13:29 -07:00
var $loading = $ ( '.NB-modal-loading' , this . $modal ) ;
2014-09-29 13:09:46 -07:00
var year = parseInt ( $ ( "select[name=year]" , this . $modal ) . val ( ) , 10 ) ;
var month = parseInt ( $ ( "select[name=month]" , this . $modal ) . val ( ) , 10 ) ;
var day = parseInt ( $ ( "select[name=day]" , this . $modal ) . val ( ) , 10 ) ;
var timestamp = ( new Date ( year , month , day ) ) . getTime ( ) / 1000 ;
if ( window . confirm ( "Positive you want to delete your saved stories?" ) ) {
2014-09-29 13:13:29 -07:00
$loading . addClass ( 'NB-active' ) ;
$link . attr ( 'disabled' , 'disabled' ) ;
$link . text ( "Deleting..." ) ;
2014-09-29 13:09:46 -07:00
NEWSBLUR . assets . delete _saved _stories ( timestamp , _ . bind ( function ( data ) {
2014-09-29 13:13:29 -07:00
$loading . removeClass ( 'NB-active' ) ;
2014-09-29 13:09:46 -07:00
NEWSBLUR . reader . update _starred _count ( ) ;
$link . replaceWith ( $ . make ( 'div' , Inflector . pluralize ( 'story' , data . stories _deleted , true ) + ' ' + Inflector . pluralize ( 'has' , data . stories _deleted ) +
' been deleted.' ) ) ;
} , this ) , _ . bind ( function ( ) {
2014-09-29 13:13:29 -07:00
$loading . removeClass ( 'NB-active' ) ;
2014-09-29 13:09:46 -07:00
NEWSBLUR . reader . update _starred _count ( ) ;
$link . replaceWith ( $ . make ( 'div' , { className : 'NB-error' } , 'There was a problem deleting your saved stories.' ) ) . show ( ) ;
} , this ) ) ;
}
} ,
2011-07-27 22:17:34 -07:00
handle _cancel : function ( ) {
var $cancel = $ ( '.NB-modal-cancel' , this . $modal ) ;
$cancel . click ( function ( e ) {
e . preventDefault ( ) ;
$ . modal . close ( ) ;
} ) ;
} ,
2011-09-21 17:49:26 -07:00
select _preferences : function ( ) {
var pref = this . model . preference ;
$ ( 'input[name=send_emails]' , this . $modal ) . each ( function ( ) {
if ( $ ( this ) . val ( ) == "" + pref ( 'send_emails' ) ) {
2021-01-12 20:15:42 -05:00
$ ( this ) . prop ( 'checked' , true ) ;
2011-09-21 17:49:26 -07:00
return false ;
}
} ) ;
} ,
2011-07-27 22:17:34 -07:00
serialize _preferences : function ( ) {
var preferences = { } ;
2017-05-18 16:59:35 -07:00
$ ( 'input[type=radio]:checked, select, textarea, input[type=text], input[type=password]' , this . $modal ) . each ( function ( ) {
2011-07-27 22:17:34 -07:00
var name = $ ( this ) . attr ( 'name' ) ;
var preference = preferences [ name ] = $ ( this ) . val ( ) ;
if ( preference == 'true' ) preferences [ name ] = true ;
else if ( preference == 'false' ) preferences [ name ] = false ;
} ) ;
$ ( 'input[type=checkbox]' , this . $modal ) . each ( function ( ) {
preferences [ $ ( this ) . attr ( 'name' ) ] = $ ( this ) . is ( ':checked' ) ;
} ) ;
return preferences ;
} ,
save _account _settings : function ( ) {
var self = this ;
var form = this . serialize _preferences ( ) ;
$ ( '.NB-preference-error' , this . $modal ) . text ( '' ) ;
$ ( 'input[type=submit]' , this . $modal ) . val ( 'Saving...' ) . attr ( 'disabled' , true ) . addClass ( 'NB-disabled' ) ;
2012-07-10 15:26:34 -07:00
NEWSBLUR . log ( [ "form['send_emails']" , form [ 'send_emails' ] ] ) ;
2011-09-21 17:49:26 -07:00
this . model . preference ( 'send_emails' , form [ 'send_emails' ] ) ;
2011-07-27 22:17:34 -07:00
this . model . save _account _settings ( form , function ( data ) {
if ( data . code == - 1 ) {
$ ( '.NB-preference-username .NB-preference-error' , this . $modal ) . text ( data . message ) ;
return self . disable _save ( ) ;
} else if ( data . code == - 2 ) {
$ ( '.NB-preference-email .NB-preference-error' , this . $modal ) . text ( data . message ) ;
return self . disable _save ( ) ;
} else if ( data . code == - 3 ) {
$ ( '.NB-preference-password .NB-preference-error' , this . $modal ) . text ( data . message ) ;
return self . disable _save ( ) ;
}
NEWSBLUR . Globals . username = data . payload . username ;
NEWSBLUR . Globals . email = data . payload . email ;
$ ( '.NB-module-account-username' ) . text ( NEWSBLUR . Globals . username ) ;
2013-05-06 15:21:17 -07:00
$ ( '.NB-feeds-header-user-name' ) . text ( NEWSBLUR . Globals . username ) ;
2011-07-27 22:17:34 -07:00
self . close ( ) ;
} ) ;
} ,
2022-04-06 15:56:13 -04:00
make _premium _expire : function ( ) {
return $ . make ( 'div' , [
$ . make ( 'span' , { className : 'NB-raquo' } , '»' ) ,
' ' ,
( NEWSBLUR . Globals . premium _expire && NEWSBLUR . utils . format _date ( NEWSBLUR . Globals . premium _expire ) ) ,
( ! NEWSBLUR . Globals . premium _expire && $ . make ( 'b' , "Never gonna expire. Congrats!" ) )
] ) ;
} ,
make _premium _renewal : function ( ) {
return $ . make ( 'div' , [
( NEWSBLUR . Globals . premium _renewal && $ . make ( 'a' , { href : '#' , className : 'NB-block NB-account-premium-cancel NB-modal-submit-button NB-modal-submit-red' } , 'Cancel subscription renewal' ) ) ,
( ! NEWSBLUR . Globals . premium _renewal && "Your subscription is no longer active." ) ,
( ! NEWSBLUR . Globals . premium _renewal && $ . make ( 'a' , { href : '#' , className : 'NB-block NB-account-premium-renew NB-modal-submit-button NB-modal-submit-green' } , 'Restart your subscription' ) )
] ) ;
} ,
make _premium _renewal _details : function ( ) {
return $ . make ( 'div' , [
( NEWSBLUR . Globals . premium _renewal && $ . make ( 'div' , { className : 'NB-block' } , 'Your premium account is paid until:' ) ) ,
( ! NEWSBLUR . Globals . premium _renewal && $ . make ( 'div' , { className : 'NB-block' } , 'Your premium account will downgrade on:' ) )
] ) ;
} ,
fetch _payment _history : function ( ) {
2013-05-10 12:05:24 -07:00
this . model . fetch _payment _history ( NEWSBLUR . Globals . user _id , _ . bind ( function ( data ) {
2012-12-03 15:03:47 -08:00
var $history = $ ( '.NB-account-payments' , this . $modal ) . empty ( ) ;
2022-04-06 15:56:13 -04:00
if ( NEWSBLUR . Globals . premium _renewal != data . premium _renewal ) {
NEWSBLUR . Globals . premium _renewal = data . premium _renewal ;
$ ( ".NB-premium-renewal-container" , this . $modal ) . html ( this . make _premium _renewal ( ) ) ;
$ ( ".NB-premium-renewal-details-container" , this . $modal ) . html ( this . make _premium _renewal _details ( ) ) ;
}
if ( NEWSBLUR . Globals . premium _expire != data . premium _expire ) {
if ( data . premium _expire ) {
NEWSBLUR . Globals . premium _expire = new Date ( data . premium _expire ) ;
$ ( ".NB-premium-expire-container" , this . $modal ) . html ( this . make _premium _expire ( ) ) ;
}
}
2014-04-03 14:59:30 -07:00
if ( ! data . payments || ! data . payments . length ) {
$history . append ( $ . make ( 'li' , { className : 'NB-account-payment' } , [
$ . make ( 'i' , 'No payments found.' )
2012-12-03 15:03:47 -08:00
] ) ) ;
2014-04-03 14:59:30 -07:00
} else {
2022-01-26 15:51:26 -05:00
if ( data . next _invoice ) {
data . payments . splice ( 0 , 0 , data . next _invoice ) ;
}
_ . each ( data . payments , function ( payment ) {
var date = new Date ( payment . payment _date ) ;
2022-04-08 15:27:40 -04:00
$history . append ( $ . make ( 'li' , { className : 'NB-account-payment ' + ( payment . scheduled ? ' NB-scheduled' : '' ) + ( payment . refunded ? ' NB-refunded' : '' ) } , [
2022-01-26 15:51:26 -05:00
$ . make ( 'div' , { className : 'NB-account-payment-date' } , date . format ( "F d, Y" ) ) ,
2014-04-03 14:59:30 -07:00
$ . make ( 'div' , { className : 'NB-account-payment-amount' } , "$" + payment . payment _amount ) ,
$ . make ( 'div' , { className : 'NB-account-payment-provider' } , payment . payment _provider )
] ) ) ;
} ) ;
}
2022-01-26 15:51:26 -05:00
2012-12-04 10:46:14 -08:00
$ ( window ) . resize ( ) ;
2012-12-03 15:03:47 -08:00
} , this ) ) ;
} ,
2011-07-27 09:33:47 -07:00
// ===========
// = Actions =
// ===========
handle _click : function ( elem , e ) {
var self = this ;
2013-04-11 16:50:18 -07:00
$ . targetIs ( e , { tagSelector : '.NB-modal-tab' } , function ( $t , $p ) {
e . preventDefault ( ) ;
var newtab ;
if ( $t . hasClass ( 'NB-modal-tab-account' ) ) {
newtab = 'account' ;
} else if ( $t . hasClass ( 'NB-modal-tab-premium' ) ) {
newtab = 'premium' ;
} else if ( $t . hasClass ( 'NB-modal-tab-emails' ) ) {
newtab = 'emails' ;
2017-05-18 16:59:35 -07:00
} else if ( $t . hasClass ( 'NB-modal-tab-custom' ) ) {
newtab = 'custom' ;
2013-04-11 16:50:18 -07:00
}
self . switch _tab ( newtab ) ;
} ) ;
2011-07-27 09:33:47 -07:00
$ . targetIs ( e , { tagSelector : '.NB-account-premium-modal' } , function ( $t , $p ) {
e . preventDefault ( ) ;
2013-03-04 11:12:10 -08:00
self . close _and _load _premium ( ) ;
} ) ;
$ . targetIs ( e , { tagSelector : '.NB-account-premium-renew' } , function ( $t , $p ) {
e . preventDefault ( ) ;
2018-05-03 15:38:59 -07:00
self . close _and _load _premium ( { 'renew' : true } ) ;
2011-07-27 09:33:47 -07:00
} ) ;
2013-03-13 15:46:51 -07:00
$ . targetIs ( e , { tagSelector : '.NB-account-premium-cancel' } , function ( $t , $p ) {
e . preventDefault ( ) ;
self . cancel _premium ( ) ;
2013-05-23 18:14:21 -07:00
} ) ;
$ . targetIs ( e , { tagSelector : '.NB-account-delete-all-sites' } , function ( $t , $p ) {
e . preventDefault ( ) ;
self . delete _all _sites ( ) ;
2013-03-13 15:46:51 -07:00
} ) ;
2014-09-29 13:09:46 -07:00
$ . targetIs ( e , { tagSelector : '.NB-account-delete-saved-stories' } , function ( $t , $p ) {
e . preventDefault ( ) ;
self . delete _saved _stories ( ) ;
} ) ;
2011-07-27 22:17:34 -07:00
$ . targetIs ( e , { tagSelector : '.NB-modal-cancel' } , function ( $t , $p ) {
e . preventDefault ( ) ;
self . close ( ) ;
} ) ;
} ,
handle _change : function ( ) {
$ ( 'input[type=radio],input[type=checkbox],select,input' , this . $modal ) . bind ( 'change' , _ . bind ( this . enable _save , this ) ) ;
$ ( 'input' , this . $modal ) . bind ( 'keydown' , _ . bind ( this . enable _save , this ) ) ;
2017-05-18 16:59:35 -07:00
$ ( '.NB-tab-custom' , this . $modal ) . delegate ( 'input[type=text],textarea' , 'keydown' , _ . bind ( this . enable _save , this ) ) ;
$ ( '.NB-tab-custom' , this . $modal ) . delegate ( 'input,textarea' , 'change' , _ . bind ( this . enable _save , this ) ) ;
2011-07-27 22:17:34 -07:00
} ,
enable _save : function ( ) {
$ ( 'input[type=submit]' , this . $modal ) . removeAttr ( 'disabled' ) . removeClass ( 'NB-disabled' ) . val ( 'Save My Account' ) ;
} ,
disable _save : function ( ) {
this . resize ( ) ;
$ ( 'input[type=submit]' , this . $modal ) . attr ( 'disabled' , true ) . addClass ( 'NB-disabled' ) . val ( 'Change what you like above...' ) ;
2011-07-27 09:33:47 -07:00
}
2020-10-19 15:07:14 -04:00
} ) ;