Generate less HTML to show the channel grid.

This commit is contained in:
Pēteris Caune 2018-06-11 12:40:20 +03:00
parent 639249a395
commit b6d47eb3b5
No known key found for this signature in database
GPG Key ID: E28D7679E9A9EDE2
2 changed files with 27 additions and 7 deletions

View File

@ -175,11 +175,27 @@ $(function () {
return false; return false;
}); });
$(".integrations").tooltip({
container: "body",
selector: "img",
title: function() {
var idx = $(this).index();
return $("#ch-" + idx).data("title");
}
});
$(".integrations").on("click", "img", function() { $(".integrations").on("click", "img", function() {
var isOff = $(this).toggleClass("off").hasClass("off"); var isOff = $(this).toggleClass("off").hasClass("off");
var token = $('input[name=csrfmiddlewaretoken]').val(); var token = $('input[name=csrfmiddlewaretoken]').val();
var idx = $(this).index();
var checkCode = $(this).closest("tr").data("code");
var channelCode = $("#ch-" + idx).data("code");
var url = "/checks/" + checkCode + "/channels/" + channelCode + "/enabled";
$.ajax({ $.ajax({
url: this.dataset.url, url: url,
type: "post", type: "post",
headers: {"X-CSRFToken": token}, headers: {"X-CSRFToken": token},
data: {"state": isOff ? "off" : "on"} data: {"state": isOff ? "off" : "on"}

View File

@ -80,12 +80,8 @@
<div class="integrations"> <div class="integrations">
{% spaceless %} {% spaceless %}
{% for channel in channels %} {% for channel in channels %}
<img <img src="{{ channel.icon_url }}"
data-toggle="tooltip" {% if channel in check.channel_set.all %}{% else %}class="off"{% endif %} />
data-url="{% url 'hc-switch-channel' check.code channel.code %}"
title="{{ channel }}"
src="{{ channel.icon_url }}"
{% if channel in check.channel_set.all %}{% else %}class="off"{% endif %} />
{% endfor %} {% endfor %}
{% endspaceless %} {% endspaceless %}
</div> </div>
@ -155,3 +151,11 @@
{% endfor %} {% endfor %}
</table> </table>
{% for channel in channels %}
<div
id="ch-{{ forloop.counter0}}"
data-code="{{ channel.code }}"
data-title="{{ channel }}">
</div>
{% endfor %}