list.html
4.94 KB
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
{% load static i18n pagination permissions_tags class_filter %}
{% load django_bootstrap_breadcrumbs %}
{% subject_permissions request.user topic.subject as has_subject_permissions %}
<div id="resource_{{ topic.slug }}_topic" class="list-group resource_list">
{% for resource in topic.resource_topic.all %}
{% resource_permissions request.user resource as has_resource_permissions %}
{% if has_resource_permissions %}
<div class="list-group-item {% if not resource.visible %}disabled{% endif %}">
<input type="hidden" class="id_inp_resource" name="id" value="{{ resource.id }}" />
<input type="hidden" class="order_inp_resource" name="order" value="{{ resource.order }}" />
<input type="hidden" class="url_order_resource" value="{% url 'topics:update_resource_order' %}" />
<h4 class="pull-left list-group-item-heading">
<a data-href="{{ resource.access_link }}" class="resource_link" {% if resource.show_window %}target="_blank"{% endif %}>
{{ resource.name }}
</a>
</h4>
{% if has_subject_permissions %}
<div class="pull-right category-card-items">
<a><i class="fa fa-arrows" aria-hidden="true"></i></a>
<span class="btn-group pull-right">
<button class="btn btn-sm btn_menu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fa fa-ellipsis-v" aria-hidden="true"></i>
</button>
<ul class="dropdown-menu pull-right" role="menu" aria-labelledby="moreResources">
<li><a href="{% url resource.update_link topic.slug resource.slug %}" class="edit"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li>
{% if resource|class_name == 'filelink' %}
<li><a href="{% url 'file_links:get_chart' resource.slug %}" class="edit"><i class="fa fa-line-chart fa-fw" aria-hidden="true"></i>{% trans 'Reports' %}</a></li>
{% endif %}
{% if resource|class_name == 'webpage' %}
<li><a href="{% url 'webpages:get_chart' resource.slug %}" class="edit"><i class="fa fa-line-chart fa-fw" aria-hidden="true"></i>{% trans 'Reports' %}</a></li>
{% endif %}
{% if resource|class_name == 'pdffile' %}
<li><a href="{% url 'pdf_files:get_chart' resource.slug %}" class="edit"><i class="fa fa-line-chart fa-fw" aria-hidden="true"></i>{% trans 'Reports' %}</a></li>
{% endif %}
{% if resource|class_name == 'goals' %}
<li><a href="{% url 'goals:reports' resource.slug %}" class="edit"><i class="fa fa-file-pdf-o fa-fw" aria-hidden="true"></i>{% trans 'Reports' %}</a></li>
{% endif %}
<li><a href="javascript:delete_resource('{% url resource.delete_link resource.slug %}')" class="delete"><i class="fa fa-trash fa-fw" aria-hidden="true"></i>{% trans 'Remove' %}</a></li>
</ul>
</span>
</div>
{% endif %}
<br clear="all" />
{% autoescape off %}
{{ resource.brief_description }}
{% endautoescape %}
</div>
{% endif %}
{% endfor %}
</div>
<script type="text/javascript">
function delete_resource(url) {
$('.modal').remove();
$.get(url, function (modal) {
$("#resource_{{ topic.slug }}_topic").parent().after(modal);
$('.modal').modal('show');
});
}
$(".list-group-item").unbind().on('click', function (e) {
var arrow = $(this).find('i.fa-arrows').is(e.target),
menu = $(this).find('i.fa-ellipsis-v').is(e.target),
btn = $(this).find('button.btn_menu').is(e.target),
del = $(this).find('a.delete').is(e.target),
upd = $(this).find('a.edit').is(e.target);
if (!arrow && !menu && !del && !upd && !btn) {
var link = $(this).find('.resource_link').data('href'),
target = $(this).find('.resource_link').attr('target');
if (typeof(target) != 'undefined') {
window.open(link, target);
} else {
window.location = link;
}
}
});
$("#resource_{{ topic.slug }}_topic").sortable({
delay: 100,
distance: 5,
handle: 'i.fa-arrows',
update: function( event, ui ) {
var cont = 1;
var data = [];
$("#resource_{{ topic.slug }}_topic").find('.order_inp_resource').each(function () {
$(this).val(cont++);
data.push({
'resource_id': $(this).parent().find('.id_inp_resource').val(),
'resource_order': $(this).val()
});
});
data = JSON.stringify(data);
sendUpdateResource(data);
},
});
function sendUpdateResource(data) {
$.ajax({
url: $('.url_order_resource').val(),
dataType: 'json',
data: {'data': data},
success: function(response) {
console.log(response);
},
error: function(response) {
console.log(response);
}
});
}
</script>