131 lines
4.3 KiB
JavaScript
131 lines
4.3 KiB
JavaScript
(function(){
|
|
var loading = null,
|
|
site_url = null;
|
|
$("document").ready(function(){
|
|
loading = $("#loading");
|
|
bindHandlers();
|
|
})
|
|
|
|
var bindHandlers = function(){
|
|
$("#find-channels").on("click",function(){
|
|
site_url = $("#site-url-wrapper input[type=text]").val();
|
|
$("#site-url-wrapper").fadeOut();
|
|
getChannelList();
|
|
})
|
|
}
|
|
|
|
var getChannelList = function(){
|
|
displayLoading(true,"Fetching channels from " + site_url);
|
|
$.ajax({
|
|
url : "/admin/feeds/get_channel_list",
|
|
data : {"url" : site_url},
|
|
dataType : "json",
|
|
type : "get"
|
|
}).done(function(channels){
|
|
if (channels != null){
|
|
$.each(channels.channels,function(index,channel){
|
|
var ch = $("<div id='" + channel.key + "-channel' class='module cursor-pointer'><div class='lead muted'><i class='" + channel.app_icon + "'></i><br/><span style='font-size:14px;'>" + channel.title + "</span></div></div>");
|
|
ch.on("click",function(){
|
|
getFeedList(channel);
|
|
})
|
|
$("#channels").append(ch);
|
|
})
|
|
setTimeout(function(){
|
|
displayLoading(false);
|
|
setTimeout(function(){$("#channels").fadeIn();},500);
|
|
},1000);
|
|
}
|
|
else{
|
|
alert('Feed not found')
|
|
window.location.href = window.location.href
|
|
}
|
|
})
|
|
}
|
|
|
|
var getFeedList = function(channel){
|
|
$("#channels").fadeOut(function(){
|
|
$("#channels").html("");
|
|
displayLoading(true,"Fetching feed list for " + channel.title);
|
|
$.ajax({
|
|
url : "/admin/feeds/get_feed_list",
|
|
data : {"url" : site_url, "channel" : channel.key, "feed_list_url" : channel.url},
|
|
dataType : "json",
|
|
type : "get"
|
|
}).done(function(data){
|
|
$.each(data.feeds, function(index,feed){
|
|
var klass = (feed.subscribed ? "active" : "");
|
|
var f = $("<div class='module cursor-pointer " + klass + "'><div class='lead muted'><i class='icons-text-2'></i><br/><span style='font-size:14px;'>" + feed.title_translations[I18n.locale] + "</span></div></div>");
|
|
f.on("click",function(){
|
|
if($(this).hasClass("active")){
|
|
if(confirm("Are you sure, you want to unsubscribe from " + feed.title_translations[I18n.locale] + "?")){
|
|
unsubscribeFeed($(this),feed);
|
|
}
|
|
}else{
|
|
subscribeFeed($(this),feed,channel);
|
|
}
|
|
})
|
|
$("#channels").append(f);
|
|
})
|
|
setTimeout(function(){
|
|
displayLoading(false);
|
|
setTimeout(function(){$("#channels").fadeIn();},500);
|
|
},1000);
|
|
})
|
|
})
|
|
}
|
|
|
|
var unsubscribeFeed = function(dom,feed){
|
|
dom.removeClass("active");
|
|
$.ajax({
|
|
url : "/admin/feeds/unsubscribe",
|
|
data : {"feed_uid": feed.uid},
|
|
dataType : "json",
|
|
type : "post"
|
|
}).done(function(){
|
|
$("#selectCategoryModal").modal("hide");
|
|
})
|
|
}
|
|
|
|
var subscribeFeed = function(dom,feed,channel){
|
|
var subscribe_button = $("#subscribe-button"),
|
|
select = $("#local-category");
|
|
$("#selectCategoryModal").modal("show");
|
|
subscribe_button.attr("disabled","disabled");
|
|
$.ajax({
|
|
url : "/admin/feeds/get_category_list",
|
|
data : {"channel" : channel.key},
|
|
dataType : "json",
|
|
type : "get"
|
|
}).done(function(data){
|
|
select.html("");
|
|
$.each(data.categories,function(index,category){
|
|
select.append("<option value='" + category.id + "'>" + category.title + "</option>");
|
|
})
|
|
subscribe_button.removeAttr("disabled");
|
|
})
|
|
subscribe_button.unbind("click");
|
|
subscribe_button.on("click",function(){
|
|
dom.addClass("active");
|
|
$.ajax({
|
|
url : "/admin/feeds/subscribe",
|
|
data : {"url" : site_url, "feed" : feed, "channel" : channel.title, "channel_key" : channel.key, "category" : select.val()},
|
|
dataType : "json",
|
|
type : "post"
|
|
}).done(function(){
|
|
$("#selectCategoryModal").modal("hide");
|
|
})
|
|
})
|
|
|
|
}
|
|
|
|
var displayLoading = function(display, msg){
|
|
if(display){
|
|
loading.find(".progress_msg").text(msg);
|
|
loading.fadeIn();
|
|
}else{
|
|
loading.find(".progress_msg").text("");
|
|
loading.fadeOut();
|
|
}
|
|
}
|
|
})();
|