summaryrefslogtreecommitdiffstats
path: root/coffee/controllers/settingscontroller.coffee
blob: 9afda54074e1c3508532dbe6ab7d8d83a6c8a641 (plain)
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
###
# ownCloud news app
#
# @author Alessandro Cosentino
# @author Bernhard Posselt
# Copyright (c) 2012 - Alessandro Cosentino <cosenal@gmail.com>
# Copyright (c) 2012 - Bernhard Posselt <nukeawhale@gmail.com>
#
# This file is licensed under the Affero General Public License version 3 or
# later.
#
# See the COPYING-README file
#
###

angular.module('News').factory '_SettingsController', ['Controller', 
(Controller) ->

	class SettingsController extends Controller

                constructor: (@$scope, @$rootScope, @persistence, @opmlParser) ->
			
			@add = false
			@settings = false
			@addingFeed = false
			@addingFolder = false

			@$scope.$on 'readFile', (scope, fileContent) =>
				structure = @opmlParser.parseXML(fileContent)
                                @parseOPMLStructure(structure)

			@$scope.$on 'hidesettings', =>
				@add = false
				@settings = false


		# recursively create folders
		parseOPMLStructure: (structure, folderId=0) ->
			for item in structure.getItems()
				if item.isFolder()
					onSuccess = (data) =>
						console.log data
						folderId = data.folders[0].id
						@parseOPMLStructure(item, folderId)
					@persistence.createFolder(item.getName(), onSuccess)
				else
					# FIXME: handle errors
					onSuccess = ->
					onError = ->
					@persistence.createFeed(item.getUrl(), folderId, onSuccess, onError)


	return SettingsController
]