Files
bohung 5ae52c6e5f Auto merge http and https remote_site_url.
Update cache when updating channel_title or remote_site_url.
2022-06-21 18:10:50 +08:00

158 lines
5.8 KiB
ERB

<% content_for :page_specific_css do %>
<%= stylesheet_link_tag "index_channel" %>
<% end %>
<div>
<h3>Channel and feeds</h3>
</div>
<% in_use_locales = ([I18n.locale] + (I18n.available_locales - [I18n.locale])) %>
<div class="accordion channel-accordion" id="feedAccordion">
<% @school_urls.each_with_index do |url,index| %>
<div class="accordion-group channel-accordion-group">
<div class="accordion-heading channel-accordion-heading">
<% first_record = @site_feeds[url].first %>
<a class="accordion-toggle channel-accordion-toggle collapsed" data-toggle="collapse" data-parent="#feedAccordion" href="#channel_<%= index.to_s %>">
<span class="channel-url"><%= url %></span>
<span class="channel-source-name label <%= 'hide' if first_record.channel_title.blank? %>">
<%= first_record.channel_title %>
</span>
</a>
<div class="dropdown channel-dropdown">
<a class="channel-edit-form btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#">Edit</a>
<a class="channel-save-form btn btn-primary dropdown-toggle hide" data-toggle="dropdown" href="#">Save</a>
<ul class="dropdown-menu channel-dropdown-menu" role="menu" aria-labelledby="dLabel">
<form class="form-<%= first_record.id %> form-horizontal channel-form-horizontal" method="post" action="/admin/feeds/channel_title" data-remote="true">
<h5>Source name</h5>
<% channel_title_translations = first_record.channel_title_translations %>
<% in_use_locales.each do |l| %>
<div class="control-group channel-control-group">
<label class="control-label channel-label" for="<%= first_record.id %>-input<%=l%>"><%=t(l)%></label>
<div class="controls channel-controls">
<input type="text" id="<%= first_record.id %>-input<%=l%>" placeholder="Source" name="channel_title_translations[<%=l%>]" value="<%=channel_title_translations[l]%>">
</div>
</div>
<% end %>
<input type="hidden" name="url" value="<%= url %>">
</form>
</ul>
</div>
</div>
<div id="channel_<%= index.to_s %>" class="accordion-body collapse">
<div class="accordion-inner">
<% channels = @site_feeds[url].group_by(&:channel_name)
channel_names = channels.keys
channel_names.each do |name|
%>
<ul class="channel-list list-unstyled">
<li class="channel-item">
<span class="channel-name"><%= name %></span>
<ul class="channel-sublist">
<% channels[name].each do |channel| %>
<li class="channel-subitem" >
<span class="channel-feedname"><%= channel.feed_name %></span>
<span class="label label-info"><%= channel.category.title rescue "" %></span>
<span class="channel-actions">
<button class="btn <%= channel.disabled ? "btn-info" : "btn-warning" %> btn-small disable-feed-btn" data-feed-id="<%= channel.id.to_s %>"><%= channel.disabled ? t("feed.enable") : t("feed.disable") %></button>
<button class="btn btn-info btn-small force-refresh-btn" data-feed-uid="<%= channel.feed_uid %>" data-feed-name="<%= channel.feed_name %>"><%= t("feed.force_refresh") %></button>
<button class="btn btn-danger btn-small unsubscribe-btn" data-feed-uid="<%= channel.feed_uid %>" data-feed-name="<%= channel.feed_name %>"><%= t("feed.unsubscribe") %></button>
</span>
</li>
<% end %>
</ul>
</li>
</ul>
<% end %>
</div>
</div>
</div>
<% end %>
</div>
<script type="text/javascript">
$('.channel-form-horizontal').bind('ajax:success', function(evt, data, status, xhr){
var title = data['title'];
var el = $(this).parents('.accordion-heading').find('.channel-source-name');
if(title && title.length > 0){
el.text(data["title"]).removeClass('hide');
}else{
el.text(data["title"]).addClass('hide');
}
})
$(".disable-feed-btn").on("click",function(){
var disable = null,
el = $(this),
feed_id = $(this).data("feed-id");
if(el.hasClass("btn-warning")){
el.removeClass("btn-warning");
el.text("Disabling...");
disable = true;
}else{
el.removeClass("btn-info");
el.text("Enabling...");
disable = false;
}
$.ajax({
url : "/admin/feeds/disable",
data : {"feed_id" : feed_id, "disable" : disable},
dataType : "json",
type : "post"
}).done(function(){
if(disable){
setTimeout(function(){el.addClass("btn-info");el.text("Enable")},800);
}else{
setTimeout(function(){el.addClass("btn-warning");el.text("Disable")},800);
}
})
})
$(".channel-edit-form").on("click",function(){
var edit = $(this),
save = $(this).next();
edit.addClass("hide");
save.removeClass("hide");
$(document).one("click",function(){
edit.removeClass("hide");
save.addClass("hide");
})
})
$(".channel-save-form").on("click",function(){
var save = $(this),
edit = $(this).prev(),
form = $(this).parent().find("form");
edit.removeClass("hide");
save.addClass("hide");
form.submit();
})
$(".unsubscribe-btn").on("click",function(){
var el = $(this);
if(confirm("Are you sure, you want to unsubscribe from " + el.data("feed-name"))){
$.ajax({
url : "/admin/feeds/unsubscribe",
data : {"feed_uid": el.data("feed-uid")},
dataType : "json",
type : "post"
}).done(function(){
el.parents('.channel-subitem').remove();
})
}
});
$(".force-refresh-btn").on("click",function(){
var el = $(this);
$.ajax({
url : "/admin/feeds/force_refresh",
data : {"feed_uid": el.data("feed-uid")},
dataType : "json",
type : "post"
}).done(function(){
alert("<%= t("feed.successful") %>")
});
});
</script>