summaryrefslogtreecommitdiffstats
path: root/js/app
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-04-11 19:34:24 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-04-11 19:34:24 +0200
commit9963975875836f768cc64f3a9dc00a1f33d9c07f (patch)
tree919ca3f3303ca159a56330caf87f54e5909b7da1 /js/app
parent959b8691fad5b109e17a2f358613813f209e1313 (diff)
added more code for adding feeds and folders
Diffstat (limited to 'js/app')
-rw-r--r--js/app/controllers/feedcontroller.coffee33
-rw-r--r--js/app/services/bl/feedbl.coffee36
2 files changed, 49 insertions, 20 deletions
diff --git a/js/app/controllers/feedcontroller.coffee b/js/app/controllers/feedcontroller.coffee
index 0860cabc5..742693253 100644
--- a/js/app/controllers/feedcontroller.coffee
+++ b/js/app/controllers/feedcontroller.coffee
@@ -49,28 +49,25 @@ angular.module('News').factory '_FeedController',
@_$scope.addFeed = (feedUrl, parentFolderId=0) =>
@_$scope.feedEmptyError = false
- @_$scope.feedError = false
+ @_$scope.feedExistsError = false
- if angular.isUndefined(feedUrl) or feedUrl.trim() == ''
- @_$scope.feedEmptyError = true
-
- if not @_$scope.feedEmptyError
+ try
@_isAddingFeed = true
-
- onError = =>
- @_$scope.feedError = true
+ @_feedBl.create feedUrl, parentFolderId
+ # on success
+ , =>
+ @_$scope.feedUrl = ''
+ @_isAddingFeed = false
+ # on error
+ , =>
@_isAddingFeed = false
-
- onSuccess = (data) =>
- if data.status == 'error'
- onError()
- else
- @_$scope.feedUrl = ''
- @_isAddingFeed = false
-
- @_persistence.createFeed(feedUrl.trim(), parentFolderId,
- onSuccess, onError)
+ catch error
+ if error instanceof _ExistsError
+ @_$scope.feedExistsError = true
+ else
+ @_$scope.feedEmptyError = true
+
@_$scope.addFolder = (folderName) =>
@_$scope.folderEmptyError = false
diff --git a/js/app/services/bl/feedbl.coffee b/js/app/services/bl/feedbl.coffee
index b0928cccb..68b288297 100644
--- a/js/app/services/bl/feedbl.coffee
+++ b/js/app/services/bl/feedbl.coffee
@@ -23,9 +23,9 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
angular.module('News').factory 'FeedBl',
['_Bl', 'ShowAll', 'Persistence', 'ActiveFeed', 'FeedType', 'ItemModel',
-'FeedModel', 'NewLoading',
+'FeedModel', 'NewLoading', '_ExistsError',
(_Bl, ShowAll, Persistence, ActiveFeed, FeedType, ItemModel, FeedModel,
-NewLoading) ->
+NewLoading, _ExistsError) ->
class FeedBl extends _Bl
@@ -125,6 +125,38 @@ NewLoading) ->
return feed.link
+ create: (url, parentId=0, onSuccess=null, onFailure=null) ->
+ onSuccess or= ->
+ onFailure or= ->
+
+ if angular.isUndefined(url) or url.trim() == ''
+ throw new Error()
+
+ url = url.trim()
+ urlHash = hex_md5(url)
+
+ if @_feedModel.getByUrlHash(urlHash)
+ throw new _ExistsError()
+
+ feed =
+ title: url.replace(
+ /^(?:https?:\/\/)?(?:www\.)?([a-z0-9_\-\.]+)(?:\/.*)?$/gi,
+ '$1')
+ url: url
+ urlHash: urlHash
+
+ @_feedModel.add(feed)
+
+ success = (response) =>
+ if response.status == 'error'
+ feed.error = response.msg
+ onFailure()
+ else
+ onSuccess()
+
+ @_persistence.createFeed url, parentId, success
+
+
return new FeedBl(ShowAll, FeedModel, Persistence, ActiveFeed, FeedType,
ItemModel, NewLoading)