2010-06-08 11:19:41 -04:00
NEWSBLUR . AssetModel = function ( ) {
var _Reader = null ;
2010-06-11 20:55:38 -04:00
var _Prefs = null ;
2010-06-08 11:19:41 -04:00
return {
reader : function ( ) {
if ( ! _Reader ) {
_Reader = new NEWSBLUR . AssetModel . Reader ( ) ;
_Reader . init ( ) ;
} else {
_Reader . init ( ) ;
}
return _Reader ;
2010-06-11 20:55:38 -04:00
}
2010-06-08 11:19:41 -04:00
} ;
} ( ) ;
NEWSBLUR . AssetModel . Reader = function ( ) {
2011-02-27 19:42:22 -05:00
this . defaults = {
classifiers : {
titles : { } ,
tags : { } ,
authors : { } ,
feeds : { }
}
} ;
2010-06-08 11:19:41 -04:00
this . feeds = { } ;
2011-04-05 19:24:12 -04:00
this . favicons = { } ;
2010-06-08 11:19:41 -04:00
this . folders = [ ] ;
this . stories = { } ;
2010-12-15 16:10:54 -05:00
this . story _keys = { } ;
this . queued _read _stories = { } ;
2011-02-27 19:42:22 -05:00
this . classifiers = _ . extend ( { } , this . defaults [ 'classifiers' ] ) ;
2010-11-30 10:30:18 -05:00
this . starred _stories = [ ] ;
2010-12-01 14:11:42 -05:00
this . starred _count = 0 ;
2010-12-15 16:10:54 -05:00
this . read _stories _river _count = 0 ;
2011-01-30 21:40:00 -05:00
this . flags = {
'favicons_fetching' : false
} ;
2010-06-08 11:19:41 -04:00
} ;
NEWSBLUR . AssetModel . Reader . prototype = {
init : function ( ) {
this . ajax = { } ;
2010-10-06 20:26:42 -04:00
this . ajax [ 'queue' ] = $ . manageAjax . create ( 'queue' , { queue : false } ) ;
this . ajax [ 'queue_clear' ] = $ . manageAjax . create ( 'queue_clear' , { queue : 'clear' } ) ;
this . ajax [ 'feed' ] = $ . manageAjax . create ( 'feed' , { queue : 'clear' , abortOld : true , domCompleteTrigger : true } ) ;
this . ajax [ 'feed_page' ] = $ . manageAjax . create ( 'feed_page' , { queue : false , abortOld : true , abortIsNoSuccess : false , domCompleteTrigger : true } ) ;
2010-12-10 15:26:50 -05:00
this . ajax [ 'statistics' ] = $ . manageAjax . create ( 'statistics' , { queue : 'clear' , abortOld : true } ) ;
2010-10-06 20:58:29 -04:00
$ . ajaxSettings . traditional = true ;
2010-06-08 11:19:41 -04:00
return ;
} ,
make _request : function ( url , data , callback , error _callback , options ) {
var self = this ;
var options = $ . extend ( {
'ajax_group' : 'queue' ,
'traditional' : true ,
2010-10-06 20:26:42 -04:00
'domSuccessTrigger' : true ,
2011-02-28 19:29:19 -05:00
'preventDoubleRequests' : false
2010-06-08 11:19:41 -04:00
} , options ) ;
2011-04-20 09:35:59 -04:00
var request _type = options . request _type || 'POST' ;
2010-07-25 23:13:27 -04:00
var clear _queue = false ;
2010-06-08 11:19:41 -04:00
if ( options [ 'ajax_group' ] == 'feed' ) {
2010-07-25 23:13:27 -04:00
clear _queue = true ;
}
if ( options [ 'ajax_group' ] == 'statistics' ) {
clear _queue = true ;
request _type = 'GET' ;
}
if ( clear _queue ) {
2010-06-08 11:19:41 -04:00
this . ajax [ options [ 'ajax_group' ] ] . clear ( true ) ;
}
this . ajax [ options [ 'ajax_group' ] ] . add ( {
url : url ,
data : data ,
2010-07-25 23:13:27 -04:00
type : request _type ,
2010-06-08 11:19:41 -04:00
beforeSend : function ( ) {
// NEWSBLUR.log(['beforeSend', options]);
$ . isFunction ( options [ 'beforeSend' ] ) && options [ 'beforeSend' ] ( ) ;
return true ;
} ,
success : function ( o ) {
// NEWSBLUR.log(['make_request 1', o]);
if ( $ . isFunction ( callback ) ) {
callback ( o ) ;
}
} ,
2011-02-02 13:07:12 -05:00
error : function ( e , textStatus , errorThrown ) {
NEWSBLUR . log ( [ 'AJAX Error' , textStatus , errorThrown ] ) ;
2010-06-08 11:19:41 -04:00
if ( $ . isFunction ( error _callback ) ) {
error _callback ( ) ;
2010-07-24 15:54:25 -04:00
} else if ( $ . isFunction ( callback ) ) {
2011-02-24 18:51:30 -05:00
var message = "Please create an account. Not much to do without an account." ;
if ( NEWSBLUR . Globals . is _authenticated ) {
message = "Sorry, there was an unhandled error." ;
}
callback ( { 'message' : message } ) ;
2010-06-08 11:19:41 -04:00
}
}
} ) ;
} ,
mark _story _as _read : function ( story _id , feed _id , callback ) {
var self = this ;
var read = false ;
2011-02-23 19:41:05 -05:00
var story = this . get _story ( story _id ) ;
read = story . read _status ;
2011-03-16 11:54:20 -04:00
story . read _status = 1 ;
2010-12-15 16:10:54 -05:00
2010-06-08 11:19:41 -04:00
if ( ! read && NEWSBLUR . Globals . is _authenticated ) {
2010-12-15 16:10:54 -05:00
if ( ! ( feed _id in this . queued _read _stories ) ) { this . queued _read _stories [ feed _id ] = [ ] ; }
this . queued _read _stories [ feed _id ] . push ( story _id ) ;
// NEWSBLUR.log(['Marking Read', this.queued_read_stories, story_id]);
2010-06-08 11:19:41 -04:00
this . make _request ( '/reader/mark_story_as_read' , {
2010-12-15 16:10:54 -05:00
story _id : this . queued _read _stories [ feed _id ] ,
2010-06-08 11:19:41 -04:00
feed _id : feed _id
2010-12-15 16:10:54 -05:00
} , null , null , {
2010-06-08 11:19:41 -04:00
'ajax_group' : 'queue_clear' ,
'traditional' : true ,
'beforeSend' : function ( ) {
2010-12-15 16:10:54 -05:00
self . queued _read _stories [ feed _id ] = [ ] ;
2010-06-08 11:19:41 -04:00
}
} ) ;
}
2010-12-15 16:10:54 -05:00
this . read _stories _river _count += 1 ;
2010-09-05 18:08:08 -07:00
$ . isFunction ( callback ) && callback ( read ) ;
2010-06-08 11:19:41 -04:00
} ,
2010-12-30 19:24:52 -05:00
mark _story _as _unread : function ( story _id , feed _id , callback ) {
var self = this ;
var read = true ;
for ( s in this . stories ) {
if ( this . stories [ s ] . id == story _id ) {
2011-03-16 11:54:20 -04:00
this . stories [ s ] . read _status = 0 ;
2010-12-30 19:24:52 -05:00
break ;
}
}
if ( NEWSBLUR . Globals . is _authenticated ) {
this . make _request ( '/reader/mark_story_as_unread' , {
story _id : story _id ,
feed _id : feed _id
} , null , null , { } ) ;
}
$ . isFunction ( callback ) && callback ( ) ;
} ,
2010-11-30 10:30:18 -05:00
mark _story _as _starred : function ( story _id , feed _id , callback ) {
var self = this ;
2010-12-02 11:09:09 -05:00
this . starred _count += 1 ;
2010-12-30 18:37:29 -05:00
var story = this . get _story ( story _id ) ;
story . starred = true ;
2010-11-30 10:30:18 -05:00
this . make _request ( '/reader/mark_story_as_starred' , {
story _id : story _id ,
feed _id : feed _id
} , callback ) ;
} ,
2010-12-02 20:18:33 -05:00
mark _story _as _unstarred : function ( story _id , callback ) {
2010-12-01 09:30:56 -05:00
var self = this ;
2010-12-02 11:09:09 -05:00
this . starred _count -= 1 ;
2010-12-30 18:37:29 -05:00
var story = this . get _story ( story _id ) ;
story . starred = false ;
2010-12-01 09:30:56 -05:00
this . make _request ( '/reader/mark_story_as_unstarred' , {
2010-12-02 20:18:33 -05:00
story _id : story _id
2010-12-01 09:30:56 -05:00
} , callback ) ;
} ,
2010-06-08 11:19:41 -04:00
mark _feed _as _read : function ( feed _id , callback ) {
var self = this ;
2010-11-05 20:34:17 -04:00
var feed _ids = _ . isArray ( feed _id )
? _ . select ( feed _id , function ( f ) { return f ; } )
: [ feed _id ] ;
2010-06-08 11:19:41 -04:00
2010-11-30 10:30:18 -05:00
this . make _request ( '/reader/mark_feed_as_read' , {
feed _id : feed _ids
} , callback ) ;
2010-06-08 11:19:41 -04:00
} ,
2010-10-25 20:20:59 -04:00
load _feeds : function ( callback , error _callback ) {
2010-06-08 11:19:41 -04:00
var self = this ;
var pre _callback = function ( subscriptions ) {
2011-02-04 00:22:58 -05:00
// NEWSBLUR.log(['subscriptions', subscriptions]);
2010-10-16 20:07:47 -04:00
var flat _feeds = function ( feeds ) {
var flattened = _ . flatten ( _ . map ( feeds , _ . values ) ) ;
return _ . flatten ( _ . map ( flattened , function ( feed ) {
2010-11-01 23:00:20 -04:00
if ( ! _ . isNumber ( feed ) && feed ) return flat _feeds ( feed ) ;
2010-10-16 20:07:47 -04:00
else return feed ;
} ) ) ;
} ;
2010-10-23 12:13:27 -04:00
var valid _feeds = flat _feeds ( { 'root' : subscriptions . folders } ) ;
2010-10-16 20:07:47 -04:00
_ . each ( subscriptions . feeds , function ( feed , feed _id ) {
if ( _ . contains ( valid _feeds , parseInt ( feed _id , 10 ) ) ) {
self . feeds [ feed _id ] = feed ;
2011-01-30 21:40:00 -05:00
if ( feed . favicon _fetching ) self . flags [ 'favicons_fetching' ] = true ;
2010-10-16 20:07:47 -04:00
}
} ) ;
2010-06-08 11:19:41 -04:00
self . folders = subscriptions . folders ;
2010-12-01 14:11:42 -05:00
self . starred _count = subscriptions . starred _count ;
2011-04-05 19:24:12 -04:00
if ( ! _ . isEqual ( self . favicons , { } ) ) {
_ . each ( self . feeds , function ( feed ) {
2011-05-01 18:57:19 -04:00
if ( self . favicons [ feed . id ] ) {
feed . favicon = self . favicons [ feed . id ] ;
}
2011-04-05 19:24:12 -04:00
} ) ;
}
2010-06-08 11:19:41 -04:00
callback ( ) ;
} ;
2011-05-01 18:57:19 -04:00
var data = { } ;
if ( NEWSBLUR . Flags [ 'start_import_from_google_reader' ] ) {
data [ 'include_favicons' ] = true ;
}
this . make _request ( '/reader/feeds' , data , pre _callback , error _callback , { request _type : 'GET' } ) ;
2010-06-08 11:19:41 -04:00
} ,
2011-04-05 19:24:12 -04:00
load _feed _favicons : function ( callback , loaded _once , load _all ) {
var pre _callback = _ . bind ( function ( favicons ) {
this . favicons = favicons ;
if ( ! _ . isEqual ( this . feeds , { } ) ) {
_ . each ( this . feeds , _ . bind ( function ( feed ) {
2011-05-01 18:57:19 -04:00
if ( favicons [ feed . id ] ) {
feed . favicon = favicons [ feed . id ] ;
}
2011-04-05 19:24:12 -04:00
} , this ) ) ;
}
callback ( ) ;
} , this ) ;
var data = {
load _all : load _all
} ;
if ( loaded _once ) {
data [ 'feed_ids' ] = _ . compact ( _ . map ( this . feeds , function ( feed ) {
return ! feed . favicon && feed . id ;
} ) ) ;
}
2011-04-20 09:35:59 -04:00
this . make _request ( '/reader/favicons' , data , pre _callback , pre _callback , { request _type : 'GET' } ) ;
2011-04-05 19:24:12 -04:00
} ,
2010-06-08 11:19:41 -04:00
load _feed : function ( feed _id , page , first _load , callback ) {
var self = this ;
var pre _callback = function ( data ) {
return self . load _feed _precallback ( data , feed _id , callback , first _load ) ;
} ;
2011-02-04 09:56:15 -05:00
this . feed _id = feed _id ;
2010-10-25 20:20:59 -04:00
// NEWSBLUR.log(['load_feed', feed_id, page, first_load, callback, pre_callback, this.feeds[feed_id].feed_address]);
2010-06-08 11:19:41 -04:00
if ( feed _id ) {
2011-04-21 10:44:50 -04:00
this . make _request ( '/reader/feed/' + feed _id ,
2010-06-08 11:19:41 -04:00
{
2010-10-25 20:20:59 -04:00
page : page ,
feed _address : this . feeds [ feed _id ] . feed _address
2010-06-08 11:19:41 -04:00
} , pre _callback ,
2011-02-04 09:56:15 -05:00
$ . noop ,
2010-06-08 11:19:41 -04:00
{
2011-04-21 10:44:50 -04:00
'ajax_group' : ( page > 1 ? 'feed_page' : 'feed' ) ,
2011-04-20 09:35:59 -04:00
'request_type' : 'GET'
2010-06-08 11:19:41 -04:00
}
) ;
}
} ,
load _feed _precallback : function ( data , feed _id , callback , first _load ) {
2010-12-15 16:10:54 -05:00
var self = this ;
2011-02-04 09:56:15 -05:00
// NEWSBLUR.log(['load_feed_precallback', feed_id, this.feed_id, this.feed_id == feed_id, first_load]);
2011-01-14 00:59:51 -05:00
if ( data . dupe _feed _id && this . feed _id == data . dupe _feed _id ) {
feed _id = data . dupe _feed _id ;
}
2011-02-04 09:56:15 -05:00
if ( feed _id == this . feed _id ) {
if ( data && first _load ) {
this . stories = data . stories ;
2011-02-27 19:42:22 -05:00
this . feed _tags = data . feed _tags || { } ;
this . feed _authors = data . feed _authors || { } ;
2011-02-04 09:56:15 -05:00
this . feed _id = feed _id ;
2011-02-27 19:42:22 -05:00
this . classifiers = data . classifiers || this . defaults [ 'classifiers' ] ;
2011-02-04 09:56:15 -05:00
this . starred _stories = data . starred _stories ;
this . story _keys = { } ;
for ( var s in data . stories ) {
this . story _keys [ data . stories [ s ] . id ] = true ;
2010-06-08 11:19:41 -04:00
}
2011-03-16 11:54:20 -04:00
if ( data . feed _address ) {
this . feeds [ feed _id ] . feed _address = data . feed _address ;
}
2011-02-04 09:56:15 -05:00
} else if ( data ) {
data . stories = _ . select ( data . stories , function ( story ) {
if ( ! self . story _keys [ story . id ] ) {
self . stories . push ( story ) ;
self . story _keys [ story . id ] = true ;
return true ;
}
} ) ;
}
$ . isFunction ( callback ) && callback ( data , first _load ) ;
2010-06-08 11:19:41 -04:00
}
} ,
2010-12-02 11:09:09 -05:00
2011-03-04 12:27:31 -05:00
load _canonical _feed : function ( feed _id , callback ) {
var pre _callback = _ . bind ( function ( data ) {
this . feeds [ data . id ] = data ;
this . feed _tags = data . feed _tags || { } ;
this . feed _authors = data . feed _authors || { } ;
this . feed _id = feed _id ;
this . classifiers = data . classifiers || this . defaults [ 'classifiers' ] ;
callback && callback ( ) ;
} , this ) ;
2011-04-24 20:42:42 -04:00
this . make _request ( '/rss_feeds/feed/' + feed _id , { } , pre _callback , $ . noop , { request _type : 'GET' } ) ;
2011-03-04 12:27:31 -05:00
} ,
2010-12-02 20:18:33 -05:00
fetch _starred _stories : function ( page , callback , first _load ) {
var self = this ;
var pre _callback = function ( data ) {
2010-12-10 15:26:50 -05:00
return self . load _feed _precallback ( data , 'starred' , callback , first _load ) ;
2010-12-02 20:18:33 -05:00
} ;
2011-02-04 09:56:15 -05:00
this . feed _id = 'starred' ;
2010-12-02 20:18:33 -05:00
2011-04-20 09:35:59 -04:00
this . make _request ( '/reader/starred_stories' , {
2010-12-02 11:09:09 -05:00
page : page
2011-02-04 09:56:15 -05:00
} , pre _callback , $ . noop , {
2011-04-20 09:35:59 -04:00
'ajax_group' : ( page ? 'feed_page' : 'feed' ) ,
'request_type' : 'GET'
2010-12-10 15:26:50 -05:00
} ) ;
} ,
2011-02-04 09:56:15 -05:00
fetch _river _stories : function ( feed _id , feeds , page , callback , first _load ) {
2010-12-10 15:26:50 -05:00
var self = this ;
2010-12-15 16:10:54 -05:00
if ( first _load || ! page ) this . read _stories _river _count = 0 ;
2010-12-10 15:26:50 -05:00
var pre _callback = function ( data ) {
2011-02-04 09:56:15 -05:00
return self . load _feed _precallback ( data , feed _id , callback , first _load ) ;
2010-12-10 15:26:50 -05:00
} ;
2010-12-15 16:10:54 -05:00
2011-02-04 09:56:15 -05:00
this . feed _id = feed _id ;
2011-04-20 09:35:59 -04:00
this . make _request ( '/reader/river_stories' , {
2010-12-10 15:26:50 -05:00
feeds : feeds ,
2010-12-15 16:10:54 -05:00
page : page ,
2010-12-16 12:59:49 -05:00
read _stories _count : this . read _stories _river _count
2011-02-04 09:56:15 -05:00
} , pre _callback , $ . noop , {
2011-04-20 09:35:59 -04:00
'ajax_group' : ( page ? 'feed_page' : 'feed' ) ,
'request_type' : 'GET'
2010-12-02 11:09:09 -05:00
} ) ;
} ,
2010-09-17 12:40:42 -04:00
get _feeds _trainer : function ( feed _id , callback ) {
2010-08-01 19:12:42 -04:00
var self = this ;
2010-09-21 19:07:36 -04:00
var params = { } ;
if ( feed _id ) {
params [ 'feed_id' ] = feed _id ;
}
2010-08-01 19:12:42 -04:00
2011-04-24 21:27:31 -04:00
this . make _request ( '/reader/feeds_trainer' , params , callback , null , { 'ajax_group' : 'feed' , 'request_type' : 'GET' } ) ;
2010-08-01 19:12:42 -04:00
} ,
2010-10-29 11:34:33 -04:00
retrain _all _sites : function ( callback ) {
var self = this ;
var params = { } ;
if ( NEWSBLUR . Globals . is _authenticated ) {
this . make _request ( '/reader/retrain_all_sites' , params , callback , null ) ;
} else {
if ( $ . isFunction ( callback ) ) callback ( ) ;
}
} ,
2011-03-09 09:48:24 -05:00
refresh _feeds : function ( callback , has _unfetched _feeds , feed _id ) {
2010-06-08 11:19:41 -04:00
var self = this ;
2010-08-11 22:02:47 -04:00
var pre _callback = function ( data ) {
2011-02-06 15:04:21 -05:00
self . post _refresh _feeds ( data , callback ) ;
2010-06-08 11:19:41 -04:00
} ;
2010-08-11 22:02:47 -04:00
var data = { } ;
if ( has _unfetched _feeds ) {
data [ 'check_fetch_status' ] = has _unfetched _feeds ;
}
2011-01-30 21:40:00 -05:00
if ( this . flags [ 'favicons_fetching' ] ) {
2011-05-01 18:57:19 -04:00
var favicons _fetching = _ . compact ( _ . map ( this . feeds , function ( feed , k ) {
2011-01-30 21:40:00 -05:00
if ( feed . favicon _fetching && feed . active ) return k ;
} ) ) ;
if ( favicons _fetching . length ) {
data [ 'favicons_fetching' ] = favicons _fetching ;
}
}
2011-03-09 09:48:24 -05:00
if ( feed _id ) {
data [ 'feed_id' ] = feed _id ;
}
2010-08-11 22:02:47 -04:00
2011-04-23 18:22:52 -04:00
if ( NEWSBLUR . Globals . is _authenticated || feed _id ) {
2010-08-11 22:02:47 -04:00
this . make _request ( '/reader/refresh_feeds' , data , pre _callback ) ;
2010-06-08 11:19:41 -04:00
}
} ,
2011-02-06 15:04:21 -05:00
post _refresh _feeds : function ( data , callback ) {
var updated _feeds = [ ] ;
for ( var f in data . feeds ) {
if ( ! this . feeds [ f ] ) continue ;
var updated = false ;
f = parseInt ( f , 10 ) ;
var feed = data . feeds [ f ] ;
if ( feed . id && f != feed . id ) {
NEWSBLUR . log ( [ 'Dupe feed being refreshed' , f , feed . id , this . feeds [ f ] ] ) ;
this . feeds [ feed . id ] = this . feeds [ f ] ;
}
for ( var k in feed ) {
if ( this . feeds [ f ] [ k ] != feed [ k ] ) {
// NEWSBLUR.log(['New Feed', this.feeds[f][k], feed[k], f, k]);
this . feeds [ f ] [ k ] = feed [ k ] ;
NEWSBLUR . log ( [ 'Different' , k , this . feeds [ f ] , feed ] ) ;
updated = true ;
}
}
if ( ( feed [ 'has_exception' ] && ! this . feeds [ f ] [ 'has_exception' ] ) ||
( this . feeds [ f ] [ 'has_exception' ] && ! feed [ 'has_exception' ] ) ) {
updated = true ;
this . feeds [ f ] [ 'has_exception' ] = ! ! feed [ 'has_exception' ] ;
}
if ( feed [ 'favicon' ] ) {
this . feeds [ f ] [ 'favicon' ] = feed [ 'favicon' ] ;
this . feeds [ f ] [ 'favicon_color' ] = feed [ 'favicon_color' ] ;
this . feeds [ f ] [ 'favicon_fetching' ] = false ;
updated = true ;
}
if ( updated && ! ( f in updated _feeds ) ) {
updated _feeds . push ( f ) ;
}
}
callback ( updated _feeds ) ;
} ,
2011-04-21 10:44:50 -04:00
refresh _feed : function ( feed _id , callback ) {
2010-06-08 11:19:41 -04:00
var self = this ;
var pre _callback = function ( data ) {
// NEWSBLUR.log(['refresh_feed pre_callback', data]);
self . load _feed _precallback ( data , feed _id , callback ) ;
} ;
// NEWSBLUR.log(['refresh_feed', feed_id, page, first_load, callback, pre_callback]);
if ( feed _id ) {
2011-04-21 10:44:50 -04:00
this . make _request ( '/reader/feed/' + feed _id ,
2010-06-08 11:19:41 -04:00
{
page : 0 ,
2010-10-25 20:20:59 -04:00
feed _address : this . feeds [ feed _id ] . feed _address
2010-06-08 11:19:41 -04:00
} , pre _callback ,
null ,
{
2011-04-20 09:35:59 -04:00
'ajax_group' : 'feed_page' ,
'request_type' : 'GET'
2010-06-08 11:19:41 -04:00
}
) ;
}
} ,
2010-08-11 22:02:47 -04:00
count _unfetched _feeds : function ( ) {
var counts = {
'unfetched_feeds' : 0 ,
'fetched_feeds' : 0
} ;
for ( var f in this . feeds ) {
var feed = this . feeds [ f ] ;
2010-10-02 17:05:55 -04:00
if ( feed . active ) {
if ( feed [ 'not_yet_fetched' ] ) {
counts [ 'unfetched_feeds' ] += 1 ;
} else {
counts [ 'fetched_feeds' ] += 1 ;
}
2010-08-11 22:02:47 -04:00
}
}
return counts ;
} ,
2011-03-15 23:42:27 -04:00
set _feed : function ( feed _id , feed ) {
var self = this ;
return this . feeds [ feed _id ] = feed ;
} ,
2010-06-08 11:19:41 -04:00
get _feed : function ( feed _id ) {
var self = this ;
return this . feeds [ feed _id ] ;
} ,
get _feeds : function ( ) {
var self = this ;
return this . feeds ;
} ,
get _folders : function ( ) {
var self = this ;
return this . folders ;
} ,
get _feed _tags : function ( ) {
return this . feed _tags ;
} ,
get _feed _authors : function ( ) {
return this . feed _authors ;
} ,
get _story : function ( story _id , callback ) {
var self = this ;
for ( s in this . stories ) {
if ( this . stories [ s ] . id == story _id ) {
return this . stories [ s ] ;
}
}
return null ;
} ,
2011-04-24 01:52:44 -04:00
save _classifier : function ( data , callback ) {
2010-08-11 23:02:17 -04:00
if ( NEWSBLUR . Globals . is _authenticated ) {
2011-04-24 01:52:44 -04:00
this . make _request ( '/classifier/save' , data , callback ) ;
2010-08-11 23:02:17 -04:00
} else {
if ( $ . isFunction ( callback ) ) callback ( ) ;
}
2010-06-08 11:19:41 -04:00
} ,
get _feed _classifier : function ( feed _id , callback ) {
2011-04-24 01:52:44 -04:00
this . make _request ( '/classifier/' + feed _id , { } , callback , null , {
2011-04-20 09:35:59 -04:00
'ajax_group' : 'feed' ,
'request_type' : 'GET'
2010-06-08 11:19:41 -04:00
} ) ;
} ,
2011-01-23 14:08:49 -05:00
delete _feed : function ( feed _id , in _folder , callback , duplicate _feed ) {
if ( ! duplicate _feed ) delete this . feeds [ feed _id ] ;
2010-08-11 23:02:17 -04:00
if ( NEWSBLUR . Globals . is _authenticated ) {
2010-09-14 20:49:28 -04:00
this . make _request ( '/reader/delete_feed' , {
'feed_id' : feed _id ,
'in_folder' : in _folder
} , callback , null ) ;
} else {
if ( $ . isFunction ( callback ) ) callback ( ) ;
}
} ,
2010-09-22 10:12:38 -04:00
delete _folder : function ( folder _name , in _folder , feeds , callback ) {
2010-09-14 20:49:28 -04:00
if ( NEWSBLUR . Globals . is _authenticated ) {
2010-09-16 10:35:36 -04:00
this . make _request ( '/reader/delete_folder' , {
'folder_name' : folder _name ,
2010-09-22 10:12:38 -04:00
'in_folder' : in _folder ,
'feed_id' : feeds
2010-09-16 10:35:36 -04:00
} , callback , null ) ;
2010-08-11 23:02:17 -04:00
} else {
if ( $ . isFunction ( callback ) ) callback ( ) ;
}
2010-12-11 14:02:37 -05:00
} ,
2010-12-11 15:26:45 -05:00
rename _feed : function ( feed _id , feed _title , callback ) {
2010-12-11 14:02:37 -05:00
this . feeds [ feed _id ] . feed _title = feed _title ;
if ( NEWSBLUR . Globals . is _authenticated ) {
this . make _request ( '/reader/rename_feed' , {
'feed_id' : feed _id ,
2010-12-11 15:26:45 -05:00
'feed_title' : feed _title
2010-12-11 14:02:37 -05:00
} , callback , null ) ;
} else {
if ( $ . isFunction ( callback ) ) callback ( ) ;
}
} ,
rename _folder : function ( folder _name , new _folder _name , in _folder , callback ) {
if ( NEWSBLUR . Globals . is _authenticated ) {
this . make _request ( '/reader/rename_folder' , {
'folder_name' : folder _name ,
'new_folder_name' : new _folder _name ,
'in_folder' : in _folder
} , callback , null ) ;
} else {
if ( $ . isFunction ( callback ) ) callback ( ) ;
}
2010-06-08 11:19:41 -04:00
} ,
save _add _url : function ( url , folder , callback ) {
this . make _request ( '/reader/add_url/' , {
'url' : url ,
'folder' : folder
2011-02-24 18:51:30 -05:00
} , callback , function ( ) {
callback ( { 'message' : NEWSBLUR . Globals . is _anonymous ? 'Please create an account. Not much to do without an account.' : 'There was a problem trying to add this site. Please try a different URL.' } ) ;
} ) ;
2010-06-08 11:19:41 -04:00
} ,
save _add _folder : function ( folder , parent _folder , callback ) {
this . make _request ( '/reader/add_folder/' , {
'folder' : folder ,
'parent_folder' : parent _folder
2011-02-24 18:51:30 -05:00
} , callback , function ( ) {
callback ( { 'message' : NEWSBLUR . Globals . is _anonymous ? 'Please create an account. Not much to do without an account.' : 'There was a problem trying to add this folder. Please try a different URL.' } ) ;
} ) ;
2010-06-08 11:19:41 -04:00
} ,
2010-06-11 20:55:38 -04:00
preference : function ( preference , value , callback ) {
if ( typeof value == 'undefined' ) {
2010-12-08 20:53:45 -05:00
var pref = NEWSBLUR . Preferences [ preference ] ;
if ( ( /\d+/ ) . test ( pref ) ) return parseInt ( pref , 10 ) ;
return pref ;
2010-06-11 20:55:38 -04:00
}
2010-08-18 20:35:45 -04:00
if ( NEWSBLUR . Preferences [ preference ] == value ) {
return $ . isFunction ( callback ) && callback ( ) ;
}
2010-07-06 14:57:32 -04:00
NEWSBLUR . Preferences [ preference ] = value ;
2010-11-05 10:35:52 -04:00
var preferences = { } ;
preferences [ preference ] = value ;
this . make _request ( '/profile/set_preference' , preferences , callback , null ) ;
2010-10-30 00:27:52 -04:00
} ,
save _preferences : function ( preferences , callback ) {
_ . each ( preferences , function ( value , preference ) {
NEWSBLUR . Preferences [ preference ] = value ;
} ) ;
2010-11-05 10:35:52 -04:00
this . make _request ( '/profile/set_preference' , preferences , callback , null ) ;
2010-06-14 01:01:21 -04:00
} ,
2010-07-06 14:57:32 -04:00
view _setting : function ( feed _id , feed _view _setting , callback ) {
if ( typeof feed _view _setting == 'undefined' ) {
2011-03-15 23:42:27 -04:00
return NEWSBLUR . Preferences . view _settings [ feed _id + '' ] || NEWSBLUR . Preferences . default _view ;
2010-07-06 14:57:32 -04:00
}
NEWSBLUR . Preferences . view _settings [ feed _id + '' ] = feed _view _setting ;
2010-11-05 10:35:52 -04:00
this . make _request ( '/profile/set_view_setting' , {
'feed_id' : feed _id + '' ,
'feed_view_setting' : feed _view _setting
} , callback , null ) ;
2010-07-06 14:57:32 -04:00
} ,
2010-09-05 18:08:08 -07:00
collapsed _folders : function ( folder _title , is _collapsed , callback ) {
var folders = NEWSBLUR . Preferences . collapsed _folders ;
var changed = false ;
2010-10-30 00:27:52 -04:00
if ( is _collapsed && ! _ . contains ( NEWSBLUR . Preferences . collapsed _folders , folder _title ) ) {
2010-09-05 18:08:08 -07:00
NEWSBLUR . Preferences . collapsed _folders . push ( folder _title ) ;
changed = true ;
2010-10-21 13:48:08 -04:00
} else if ( ! is _collapsed && _ . contains ( NEWSBLUR . Preferences . collapsed _folders , folder _title ) ) {
2010-09-05 18:08:08 -07:00
NEWSBLUR . Preferences . collapsed _folders = _ . without ( folders , folder _title ) ;
changed = true ;
}
2011-03-30 09:30:45 -04:00
if ( changed ) {
this . make _request ( '/profile/set_collapsed_folders' , {
'collapsed_folders' : $ . toJSON ( NEWSBLUR . Preferences . collapsed _folders )
} , callback , null ) ;
}
2010-09-05 18:08:08 -07:00
} ,
2010-06-14 01:01:21 -04:00
save _mark _read : function ( days , callback ) {
2010-11-05 10:35:52 -04:00
this . make _request ( '/reader/mark_all_as_read' , { 'days' : days } , callback ) ;
2010-06-30 12:17:22 -04:00
} ,
get _features _page : function ( page , callback ) {
2011-04-20 09:35:59 -04:00
this . make _request ( '/reader/features' , { 'page' : page } , callback , callback , { request _type : 'GET' } ) ;
2010-07-11 11:10:45 -04:00
} ,
2011-04-09 13:07:12 -04:00
load _recommended _feed : function ( page , refresh , callback , error _callback ) {
2011-04-09 11:13:02 -04:00
this . make _request ( '/recommendations/load_recommended_feed' , {
'page' : page ,
'refresh' : refresh
2011-04-20 09:35:59 -04:00
} , callback , error _callback , { request _type : 'GET' } ) ;
2011-03-13 16:24:49 -04:00
} ,
2011-04-24 22:47:20 -04:00
load _dashboard _graphs : function ( callback , error _callback ) {
this . make _request ( '/statistics/dashboard_graphs' , { } , callback , error _callback , { request _type : 'GET' } ) ;
} ,
2010-07-11 11:10:45 -04:00
save _feed _order : function ( folders , callback ) {
2010-11-05 10:35:52 -04:00
this . make _request ( '/reader/save_feed_order' , { 'folders' : $ . toJSON ( folders ) } , callback ) ;
2010-07-25 23:13:27 -04:00
} ,
get _feed _statistics : function ( feed _id , callback ) {
2011-04-24 00:05:39 -04:00
this . make _request ( '/rss_feeds/statistics/' + feed _id , { } , callback , callback , {
2011-04-20 09:35:59 -04:00
'ajax_group' : 'statistics' ,
'requesst_type' : 'GET'
2010-07-25 23:13:27 -04:00
} ) ;
2010-08-17 23:40:03 -04:00
} ,
2011-04-07 10:30:05 -04:00
get _feed _recommendation _info : function ( feed _id , callback ) {
2011-04-24 00:05:39 -04:00
this . make _request ( '/recommendations/load_feed_info/' + feed _id , { } , callback , callback , {
2011-04-20 09:35:59 -04:00
'ajax_group' : 'statistics' ,
'request_type' : 'GET'
2011-04-07 10:30:05 -04:00
} ) ;
} ,
2010-08-17 23:40:03 -04:00
start _import _from _google _reader : function ( callback ) {
this . make _request ( '/import/import_from_google_reader/' , { } , callback ) ;
2010-08-25 10:18:08 -04:00
} ,
2011-04-07 10:30:05 -04:00
save _recommended _site : function ( data , callback ) {
if ( NEWSBLUR . Globals . is _authenticated ) {
this . make _request ( '/recommendations/save_recommended_feed' , data , callback ) ;
} else {
if ( $ . isFunction ( callback ) ) callback ( ) ;
}
} ,
2010-08-25 10:18:08 -04:00
save _exception _retry : function ( feed _id , callback ) {
var self = this ;
2011-02-06 15:04:21 -05:00
var pre _callback = function ( data ) {
// NEWSBLUR.log(['refresh_feed pre_callback', data]);
self . post _refresh _feeds ( data , callback ) ;
} ;
2011-04-23 18:22:52 -04:00
this . make _request ( '/rss_feeds/exception_retry' , {
'feed_id' : feed _id ,
'reset_fetch' : ! ! ( this . feeds [ feed _id ] . has _feed _exception || this . feeds [ feed _id ] . has _page _exception )
} , pre _callback ) ;
2010-08-25 20:43:35 -04:00
} ,
save _exception _change _feed _link : function ( feed _id , feed _link , callback ) {
var self = this ;
2011-02-06 15:04:21 -05:00
var pre _callback = function ( data ) {
2011-04-23 18:22:52 -04:00
// NEWSBLUR.log(['save_exception_change_feed_link pre_callback', feed_id, feed_link, data]);
2011-02-06 15:04:21 -05:00
self . post _refresh _feeds ( data , callback ) ;
NEWSBLUR . reader . force _feed _refresh ( feed _id ) ;
} ;
2010-08-25 20:43:35 -04:00
if ( NEWSBLUR . Globals . is _authenticated ) {
this . make _request ( '/rss_feeds/exception_change_feed_link' , {
'feed_id' : feed _id ,
'feed_link' : feed _link
2011-02-06 15:04:21 -05:00
} , pre _callback ) ;
2010-08-25 20:43:35 -04:00
} else {
if ( $ . isFunction ( callback ) ) callback ( ) ;
}
} ,
save _exception _change _feed _address : function ( feed _id , feed _address , callback ) {
var self = this ;
2011-02-06 15:04:21 -05:00
var pre _callback = function ( data ) {
2011-04-23 18:22:52 -04:00
// NEWSBLUR.log(['save_exception_change_feed_address pre_callback', feed_id, feed_address, data]);
2011-02-06 15:04:21 -05:00
self . post _refresh _feeds ( data , callback ) ;
NEWSBLUR . reader . force _feed _refresh ( feed _id ) ;
} ;
2010-08-25 20:43:35 -04:00
if ( NEWSBLUR . Globals . is _authenticated ) {
this . make _request ( '/rss_feeds/exception_change_feed_address' , {
'feed_id' : feed _id ,
'feed_address' : feed _address
2011-02-06 15:04:21 -05:00
} , pre _callback ) ;
2010-08-25 10:18:08 -04:00
} else {
if ( $ . isFunction ( callback ) ) callback ( ) ;
}
2010-09-28 18:53:57 -04:00
} ,
save _feed _chooser : function ( approved _feeds , callback ) {
if ( NEWSBLUR . Globals . is _authenticated ) {
this . make _request ( '/reader/save_feed_chooser' , {
2010-11-05 20:34:17 -04:00
'approved_feeds' : _ . select ( approved _feeds , function ( f ) { return f ; } )
2010-09-28 18:53:57 -04:00
} , callback ) ;
} else {
if ( $ . isFunction ( callback ) ) callback ( ) ;
}
2011-02-27 16:13:22 -05:00
} ,
2011-05-06 10:06:13 -04:00
send _story _email : function ( data , callback , error _callback ) {
if ( NEWSBLUR . Globals . is _authenticated ) {
this . make _request ( '/reader/send_story_email' , data , callback , error _callback ) ;
} else {
error _callback ( 'You must be logged in to send a story over email. Just log in or create an account.' ) ;
}
} ,
2011-02-27 19:42:22 -05:00
recalculate _story _scores : function ( feed _id ) {
2011-02-27 16:13:22 -05:00
_ . each ( this . stories , _ . bind ( function ( story , i ) {
2011-02-27 19:42:22 -05:00
if ( story . story _feed _id != feed _id ) return ;
2011-02-27 16:13:22 -05:00
this . stories [ i ] . intelligence . title = 0 ;
_ . each ( this . classifiers . titles , _ . bind ( function ( classifier _score , classifier _title ) {
if ( this . stories [ i ] . intelligence . title <= 0 &&
story . story _title && story . story _title . indexOf ( classifier _title ) != - 1 ) {
this . stories [ i ] . intelligence . title = classifier _score ;
}
} , this ) ) ;
this . stories [ i ] . intelligence . author = 0 ;
_ . each ( this . classifiers . authors , _ . bind ( function ( classifier _score , classifier _author ) {
if ( this . stories [ i ] . intelligence . author <= 0 &&
story . story _authors && story . story _authors . indexOf ( classifier _author ) != - 1 ) {
this . stories [ i ] . intelligence . author = classifier _score ;
}
} , this ) ) ;
this . stories [ i ] . intelligence . tags = 0 ;
_ . each ( this . classifiers . tags , _ . bind ( function ( classifier _score , classifier _tag ) {
if ( this . stories [ i ] . intelligence . tags <= 0 &&
story . story _tags && _ . contains ( story . story _tags , classifier _tag ) ) {
this . stories [ i ] . intelligence . tags = classifier _score ;
}
} , this ) ) ;
this . stories [ i ] . intelligence . feed = 0 ;
_ . each ( this . classifiers . feeds , _ . bind ( function ( classifier _score , classifier _feed _id ) {
if ( this . stories [ i ] . intelligence . feed <= 0 &&
story . story _feed _id == classifier _feed _id ) {
this . stories [ i ] . intelligence . feed = classifier _score ;
}
} , this ) ) ;
} , this ) ) ;
2010-06-08 11:19:41 -04:00
}
2010-08-25 10:18:08 -04:00
2010-06-08 11:19:41 -04:00
} ;
2010-06-11 20:55:38 -04:00