1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
###
ownCloud - News
@author Bernhard Posselt
@copyright 2012 Bernhard Posselt nukeawhale@gmail.com
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
License as published by the Free Software Foundation; either
version 3 of the License, or any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU AFFERO GENERAL PUBLIC LICENSE for more details.
You should have received a copy of the GNU Affero General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
###
angular.module('News').factory 'FolderBl',
['_Bl', 'FolderModel', 'FeedBl', 'Persistence', 'FeedType', 'ActiveFeed',
'ItemModel', 'ShowAll', '_ExistsError', 'OPMLParser',
(_Bl, FolderModel, FeedBl, Persistence, FeedType, ActiveFeed,
ItemModel, ShowAll, _ExistsError, OPMLParser)->
class FolderBl extends _Bl
constructor: (@_folderModel, @_feedBl, @_showAll, activeFeed,
persistence, @_feedType, itemModel, @_opmlParser) ->
super(activeFeed, persistence, itemModel, @_feedType.Folder)
getById: (folderId) ->
return @_folderModel.getById(folderId)
delete: (folderId) ->
@_folderModel.removeById(folderId)
@_persistence.deleteFolder(folderId)
hasFeeds: (folderId) ->
return @_feedBl.getFeedsOfFolder(folderId).length
open: (folderId) ->
folder = @_folderModel.getById(folderId)
if angular.isDefined(folder)
if not folder.opened
folder.opened = true
@_persistence.openFolder(folder.id)
toggleFolder: (folderId) ->
folder = @_folderModel.getById(folderId)
if angular.isDefined(folder)
folder.opened = !folder.opened
if folder.opened
@_persistence.openFolder(folder.id)
else
@_persistence.collapseFolder(folder.id)
markFolderRead: (folderId) ->
for feed in @_feedBl.getFeedsOfFolder(folderId)
@_feedBl.markFeedRead(feed.id)
getUnreadCount: (folderId) ->
return @_feedBl.getFolderUnreadCount(folderId)
isVisible: (folderId) ->
if @_showAll.getShowAll()
return true
else
if @isActive(folderId) or
@_feedBl.getFolderUnreadCount(folderId) > 0
return true
if @_activeFeed.getType() == @_feedType.Feed
for feed in @_feedBl.getFeedsOfFolder(folderId)
if feed.id == @_activeFeed.getId()
return true
return false
getAll: ->
return @_folderModel.getAll()
create: (folderName, onSuccess=null, onFailure=null) ->
onSuccess or= ->
onFailure or= ->
if angular.isUndefined(folderName) or folderName.trim() == ''
throw new Error()
folderName = folderName.trim()
if @_folderModel.getByName(folderName)
throw new _ExistsError()
folder =
name: folderName
opened: true
@_folderModel.add(folder)
success = (response) =>
if response.status == 'error'
folder.error = response.msg
onFailure()
else
onSuccess(response.data)
@_persistence.createFolder folderName, 0, success
markErrorRead: (folderName) ->
@_folderModel.removeByName(folderName)
import: (xml) ->
opml = @_opmlParser.parseXML(xml)
@_importElement(opml, 0)
_importElement: (opml, parentFolderId) ->
for item in opml.getItems()
if item.isFolder()
try
@create item.getName(), (data) =>
@_importElement(item, data.folders[0].id)
catch error
if error instanceof _ExistsError
folder = @_folderModel.getByName(item.getName())
@open(folder.id)
@_importElement(item, folder.id)
else
try
@_feedBl.create(item.getUrl(), parentFolderId)
catch error
return new FolderBl(FolderModel, FeedBl, ShowAll, ActiveFeed, Persistence,
FeedType, ItemModel, OPMLParser)
]
|