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
|
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('fromCloud', jsondata.data.tmp);
}
else{
OC.dialogs.alert(jsondata.data.message, t('news', 'Error'));
}
});
$('#appsettings_popup').remove();
},
browseFile:function(filelist){
if(!filelist) {
OC.dialogs.alert(t('news','No files selected.'), t('news', 'Error'));
return;
}
var file = filelist[0];
//check file format/size/...
var formData = new FormData();
formData.append('file', file);
News.Settings.importOpml('fromFile', formData);
$('#appsettings_popup').remove();
},
importOpml:function(type, data){
$('#notification').fadeIn();
$('#notification').html(t('news', 'Importing OPML file...'));
if (type == 'fromCloud') {
ajaxData = { path: data };
settings = {};
}
else if (type == 'fromFile') {
ajaxData = data;
settings = { cache: false, contentType: false, processData: false };
}
else {
throw t('news', 'Not a valid type');
}
param = {
url: OC.filePath('news', 'ajax', 'uploadopml.php'),
data: ajaxData,
type: 'POST',
success: function(jsondata){
if (jsondata.status == 'success') {
var eventSource=new OC.EventSource(OC.filePath('news','ajax','importopml.php'),{source:jsondata.data.source, path:jsondata.data.path});
eventSource.listen('progress',function(progress){
$('#notification').html('bingo');
//News.Objects.Menu.addNode(folderid, jsonData.data.listfeed);
//News.Objects.Menu.load(News.MenuNodeType.Feed, jsonData.data.feedid);
});
eventSource.listen('success',function(data){
$('#notification').html('done');
});
eventSource.listen('error',function(error){
$('#notification').fadeOut('400');
OC.dialogs.alert(error, t('news', 'Error'));
});
}
else {
OC.dialogs.alert(jsondata.data.message, t('news', 'Error'));
}
$('#notification').delay('2500').fadeOut('400');
}
};
$.ajax($.extend(param, settings));
},
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);
});
$('#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);
});
|