summaryrefslogtreecommitdiffstats
path: root/coffee/controllers/settingscontroller.coffee
blob: 4da81c316e08661791407dba7edbea0bd5916b0a (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
55
56
57
58
59
60
###
# 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, @feedModel) ->
			
			@$scope.feeds = @feedModel.getItems()

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

			@$scope.$on 'hidesettings', =>
				@$scope.showSettings = false

			@$scope.export = =>
				@export()


		export: ->
			# FIXME: this should only work when the routes are loaded
			# and be put into a directive
			url = OC.Router.generate('news_export_opml')
			window.open url, '_blank'


		# 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
]