summaryrefslogtreecommitdiffstats
path: root/js/settings.js
blob: 24440d67dd8475e13c2e7d3faea72b1be3eb56c1 (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
News = News || {}

News.Settings={
	cloudFileSelected:function(path){
		$.getJSON(OC.filePath('news', 'ajax', 'selectfromcloud.php'),{'path':path},function(jsondata){
			if(jsondata.status == 'success'){
				News.Settings.importOpml(jsondata.data.tmp);
			}
			else{
				OC.dialogs.alert(jsondata.data.message, t('news', 'Error'));
			}
		});
	},
	browseFile:function(filelist){
		if(!filelist) {
			OC.dialogs.alert(t('news','No files selected.'), t('news', 'Error'));
			return;
		}
		var file = filelist[0];
	},
	importOpml:function(path){
		$.post(OC.filePath('news', 'ajax', 'importopml.php'), { path: path }, function(jsondata){
			if (jsondata.status == 'success') {
				var message = jsondata.data.countsuccess + t('news', ' out of ') + jsondata.data.count +
					t('news', ' feeds imported successfully from ') + jsondata.data.title;
				OC.dialogs.alert(message, t('news', 'Success'));
			} else {
				OC.dialogs.alert(jsondata.data.message, t('news', 'Error'));
			}
		});
	},
	exportOpml:function(button){
		document.location.href = OC.linkTo('news', 'opmlexporter.php');
		$('#appsettings_popup').remove();
	}
}


$('#cloudlink').click(function() {
	/*
	  * it needs to be filtered by MIME type, but there are too many MIME types corresponding to opml
	  * and filepicker doesn't support multiple MIME types filter.
	  */
	OC.dialogs.filepicker(t('news', 'Select file'), News.Settings.cloudFileSelected, false, '', true);
	$('#appsettings_popup').remove();
});

$('#browselink').click(function() {
	$('#file_upload_start').trigger('click');
});

$('#file_upload_start').change(function() {
	News.Settings.browseFile(this.files);
});

$('#exportbtn').click(function() {
	News.Settings.exportOpml(this);
});