summaryrefslogtreecommitdiffstats
path: root/js/news.js
blob: 3675fb0dbb1d1578904d798d589f9be1e1135c0a (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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
News={
	UI:{
		overview:function(){
			if($('#addfeedfolder_dialog').dialog('isOpen') == true){
				$('#addfeedfolder_dialog').dialog('moveToTop');
			}else{
				$('#dialog_holder').load(OC.filePath('news', 'ajax', 'addfeedfolder.php'), function(jsondata){
					if(jsondata.status != 'error'){
						$('#addfeedfolder_dialog').dialog({
							minWidth: 600,
							close: function(event, ui) {
								$(this).dialog('destroy').remove();
							}
						}).css('overflow','visible');
					} else {
						alert(jsondata.data.message);
					}
				});
			}
			return false;
		}
	},	
	Folder: {
		submit:function(button){
				var displayname = $("#folder_add_name").val().trim();
				
				if(displayname.length == 0) {
					OC.dialogs.alert(t('news', 'Displayname cannot be empty.'), t('news', 'Error'));
					return false;
				}
				
				var url;
				url = OC.filePath('news', 'ajax', 'createfolder.php');
				
				$.post(url, { name: displayname },
					function(jsondata){
						if(jsondata.status == 'success'){
							//$(button).closest('tr').prev().html(jsondata.page).show().next().remove();
							OC.dialogs.alert(jsondata.data.message, t('news', 'Success!'));
						} else {
							OC.dialogs.alert(jsondata.data.message, t('news', 'Error'));
						}
				});
		}
	},
	Feed: {
		submit:function(button){
				var feedurl = $("#feed_add_url").val().trim();
				
				if(feedurl.length == 0) {
					OC.dialogs.alert(t('news', 'URL cannot be empty.'), t('news', 'Error'));
					return false;
				}
				
				var url;
				url = OC.filePath('news', 'ajax', 'newfeed.php');
				
				$.post(url, { feedurl: feedurl },
					function(jsondata){
						if(jsondata.status == 'success'){
							//$(button).closest('tr').prev().html(jsondata.page).show().next().remove();
							OC.dialogs.alert(jsondata.data.message, t('news', 'Success!'));
						} else {
							OC.dialogs.alert(jsondata.data.message, t('news', 'Error'));
						}
				});
		},
		doDelete:function() {
			$('#feeds_delete').tipsy('hide');
			OC.dialogs.confirm(t('news', 'Are you sure you want to delete this feed?'), t('news', 'Warning'), function(answer) {
				if(answer == true) {
					$.post(OC.filePath('contacts', 'ajax', 'deletefeed.php'),{'id':Contacts.UI.Card.id},function(jsondata){
						if(jsondata.status == 'success'){
							var newid = '';
							var curlistitem = $('#leftcontent [data-id="'+jsondata.data.id+'"]');
							var newlistitem = curlistitem.prev();
							if(newlistitem == undefined) {
								newlistitem = curlistitem.next();
							}
							curlistitem.remove();
							if(newlistitem != undefined) {
								newid = newlistitem.data('id');
							}
							$('#rightcontent').data('id',newid);
							this.id = this.fn = this.fullname = this.shortname = this.famname = this.givname = this.addname = this.honpre = this.honsuf = '';
							this.data = undefined;
							
							if($('#contacts li').length > 0) { // Load first in list.
								Contacts.UI.Card.update(newid);
							} else {
								// load intro page
								$.getJSON(OC.filePath('contacts', 'ajax', 'loadintro.php'),{},function(jsondata){
									if(jsondata.status == 'success'){
										id = '';
										$('#rightcontent').data('id','');
										$('#rightcontent').html(jsondata.data.page);
									}
									else{
										OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
									}
								});
							}
						}
						else{
							OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
						}
					});
				}
			});
			return false;
		}
	}
}

$(document).ready(function(){  
      
	$('#addfeedfolder').click(News.UI.overview);
	
	$('.collapsable').click(function(){ 
		$(this).parent().children().toggle();
		$(this).toggle();
	});
	
	$('.accordion .title').click(function() {
		$(this).next().toggle();
		return false;
	}).next().hide();
	
	$('#feeds_delete').click( function() { News.Feed.doDelete(); return false;} );

});