Commit 836fe36ed76daa5c74c19d3739dc7e7fa12f9b2f
1 parent
4002c470
Exists in
master
and in
3 other branches
Updating webpage links
Showing
6 changed files
with
132 additions
and
110 deletions
Show diff stats
amadeus/static/css/themes/green.css
topics/models.py
... | ... | @@ -77,3 +77,19 @@ class Resource(KnowsChild): |
77 | 77 | @always_as_child |
78 | 78 | def access_link(self): |
79 | 79 | pass |
80 | + | |
81 | + """ | |
82 | + Method to get the appropriated update link | |
83 | + Must override in the child models | |
84 | + """ | |
85 | + @always_as_child | |
86 | + def update_link(self): | |
87 | + pass | |
88 | + | |
89 | + """ | |
90 | + Method to get the appropriated delete link | |
91 | + Must override in the child models | |
92 | + """ | |
93 | + @always_as_child | |
94 | + def delete_link(self): | |
95 | + pass | |
80 | 96 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,108 @@ |
1 | +{% load static i18n pagination permissions_tags %} | |
2 | +{% load django_bootstrap_breadcrumbs %} | |
3 | + | |
4 | +{% subject_permissions request.user topic.subject as has_subject_permissions %} | |
5 | + | |
6 | +<div id="resource_{{ topic.slug }}" class="list-group resource_list"> | |
7 | + {% for resource in topic.resource_topic.all %} | |
8 | + {% if resource.visible or has_subject_permissions %} | |
9 | + <div class="list-group-item {% if not resource.visible %}disabled{% endif %}"> | |
10 | + <input type="hidden" class="id_inp" name="id" value="{{ resource.id }}" /> | |
11 | + <input type="hidden" class="order_inp" name="order" value="{{ resource.order }}" /> | |
12 | + <input type="hidden" class="url_order" value="{% url 'topics:update_resource_order' %}" /> | |
13 | + | |
14 | + <h4 class="pull-left list-group-item-heading"> | |
15 | + <a href="{% url resource.access_link resource.slug %}" class="resource_link" {% if resource.show_window %}target="_blank"{% endif %}> | |
16 | + {{ resource }} | |
17 | + </a> | |
18 | + </h4> | |
19 | + | |
20 | + {% if has_subject_permissions %} | |
21 | + <div class="pull-right category-card-items"> | |
22 | + <a><i class="fa fa-arrows" aria-hidden="true"></i></a> | |
23 | + <span class="btn-group pull-right"> | |
24 | + <button class="btn btn-sm btn_menu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | |
25 | + <i class="fa fa-ellipsis-v" aria-hidden="true"></i> | |
26 | + </button> | |
27 | + <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="moreResources"> | |
28 | + <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> | |
29 | + <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> | |
30 | + </ul> | |
31 | + </span> | |
32 | + </div> | |
33 | + {% endif %} | |
34 | + <br clear="all" /> | |
35 | + {% autoescape off %} | |
36 | + {{ resource.brief_description }} | |
37 | + {% endautoescape %} | |
38 | + </div> | |
39 | + {% endif %} | |
40 | + {% endfor %} | |
41 | +</div> | |
42 | +<script type="text/javascript"> | |
43 | + function delete_resource(url) { | |
44 | + $('.modal').remove(); | |
45 | + | |
46 | + $.get(url, function (modal) { | |
47 | + $("#resource_{{ topic.slug }}").parent().after(modal); | |
48 | + | |
49 | + $('.modal').modal('show'); | |
50 | + }); | |
51 | + } | |
52 | + | |
53 | + $(".list-group-item").unbind().on('click', function (e) { | |
54 | + var arrow = $(this).find('i.fa-arrows').is(e.target), | |
55 | + menu = $(this).find('i.fa-ellipsis-v').is(e.target), | |
56 | + btn = $(this).find('button.btn_menu').is(e.target), | |
57 | + del = $(this).find('a.delete').is(e.target), | |
58 | + upd = $(this).find('a.edit').is(e.target); | |
59 | + | |
60 | + if (!arrow && !menu && !del && !upd && !btn) { | |
61 | + var link = $(this).find('.resource_link').attr('href'), | |
62 | + target = $(this).find('.resource_link').attr('target'); | |
63 | + | |
64 | + if (typeof(target) != 'undefined') { | |
65 | + window.open(link, target); | |
66 | + } else { | |
67 | + window.location = link; | |
68 | + } | |
69 | + } | |
70 | + }); | |
71 | + | |
72 | + $("#resource_{{ topic.slug }}").sortable({ | |
73 | + delay: 100, | |
74 | + distance: 5, | |
75 | + handle: 'i.fa-arrows', | |
76 | + update: function( event, ui ) { | |
77 | + var cont = 1; | |
78 | + var data = []; | |
79 | + | |
80 | + $("#resource_{{ topic.slug }}").find('.order_inp').each(function () { | |
81 | + $(this).val(cont++); | |
82 | + | |
83 | + data.push({ | |
84 | + 'resource_id': $(this).parent().find('.id_inp').val(), | |
85 | + 'resource_order': $(this).val() | |
86 | + }); | |
87 | + }); | |
88 | + | |
89 | + data = JSON.stringify(data); | |
90 | + | |
91 | + sendUpdateResource(data); | |
92 | + }, | |
93 | + }); | |
94 | + | |
95 | + function sendUpdateResource(data) { | |
96 | + $.ajax({ | |
97 | + url: $("#resource_{{ topic.slug }}").find('.url_order').val(), | |
98 | + dataType: 'json', | |
99 | + data: {'data': data}, | |
100 | + success: function(response) { | |
101 | + console.log(response); | |
102 | + }, | |
103 | + error: function(response) { | |
104 | + console.log(response); | |
105 | + } | |
106 | + }); | |
107 | + } | |
108 | +</script> | |
0 | 109 | \ No newline at end of file | ... | ... |
topics/templates/topics/list.html
webpage/models.py
webpage/templates/webpages/list.html
... | ... | @@ -1,108 +0,0 @@ |
1 | -{% load static i18n pagination permissions_tags %} | |
2 | -{% load django_bootstrap_breadcrumbs %} | |
3 | - | |
4 | -{% subject_permissions request.user topic.subject as has_subject_permissions %} | |
5 | - | |
6 | -<div id="resource_{{ topic.slug }}" class="list-group resource_list"> | |
7 | - {% for resource in topic.resource_topic.all %} | |
8 | - {% if resource.visible or has_subject_permissions %} | |
9 | - <div class="list-group-item {% if not resource.visible %}disabled{% endif %}"> | |
10 | - <input type="hidden" class="id_inp" name="id" value="{{ resource.id }}" /> | |
11 | - <input type="hidden" class="order_inp" name="order" value="{{ resource.order }}" /> | |
12 | - <input type="hidden" class="url_order" value="{% url 'topics:update_resource_order' %}" /> | |
13 | - | |
14 | - <h4 class="pull-left list-group-item-heading"> | |
15 | - <a href="{% url resource.access_link resource.slug %}" class="resource_link" {% if resource.show_window %}target="_blank"{% endif %}> | |
16 | - {{ resource }} | |
17 | - </a> | |
18 | - </h4> | |
19 | - | |
20 | - {% if has_subject_permissions %} | |
21 | - <div class="pull-right category-card-items"> | |
22 | - <a><i class="fa fa-arrows" aria-hidden="true"></i></a> | |
23 | - <span class="btn-group pull-right"> | |
24 | - <button class="btn btn-sm btn_menu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | |
25 | - <i class="fa fa-ellipsis-v" aria-hidden="true"></i> | |
26 | - </button> | |
27 | - <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="moreResources"> | |
28 | - <li><a href="{% url 'webpages:update' topic.slug resource.slug %}" class="edit"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> | |
29 | - <li><a href="javascript:delete_resource('{% url 'webpages:delete' resource.slug %}')" class="delete"><i class="fa fa-trash fa-fw" aria-hidden="true"></i>{% trans 'Remove' %}</a></li> | |
30 | - </ul> | |
31 | - </span> | |
32 | - </div> | |
33 | - {% endif %} | |
34 | - <br clear="all" /> | |
35 | - {% autoescape off %} | |
36 | - {{ resource.brief_description }} | |
37 | - {% endautoescape %} | |
38 | - </div> | |
39 | - {% endif %} | |
40 | - {% endfor %} | |
41 | -</div> | |
42 | -<script type="text/javascript"> | |
43 | - function delete_resource(url) { | |
44 | - $('.modal').remove(); | |
45 | - | |
46 | - $.get(url, function (modal) { | |
47 | - $("#resource_{{ topic.slug }}").parent().after(modal); | |
48 | - | |
49 | - $('.modal').modal('show'); | |
50 | - }); | |
51 | - } | |
52 | - | |
53 | - $(".list-group-item").unbind().on('click', function (e) { | |
54 | - var arrow = $(this).find('i.fa-arrows').is(e.target), | |
55 | - menu = $(this).find('i.fa-ellipsis-v').is(e.target), | |
56 | - btn = $(this).find('button.btn_menu').is(e.target), | |
57 | - del = $(this).find('a.delete').is(e.target), | |
58 | - upd = $(this).find('a.edit').is(e.target); | |
59 | - | |
60 | - if (!arrow && !menu && !del && !upd && !btn) { | |
61 | - var link = $(this).find('.resource_link').attr('href'), | |
62 | - target = $(this).find('.resource_link').attr('target'); | |
63 | - | |
64 | - if (typeof(target) != 'undefined') { | |
65 | - window.open(link, target); | |
66 | - } else { | |
67 | - window.location = link; | |
68 | - } | |
69 | - } | |
70 | - }); | |
71 | - | |
72 | - $("#resource_{{ topic.slug }}").sortable({ | |
73 | - delay: 100, | |
74 | - distance: 5, | |
75 | - handle: 'i.fa-arrows', | |
76 | - update: function( event, ui ) { | |
77 | - var cont = 1; | |
78 | - var data = []; | |
79 | - | |
80 | - $("#resource_{{ topic.slug }}").find('.order_inp').each(function () { | |
81 | - $(this).val(cont++); | |
82 | - | |
83 | - data.push({ | |
84 | - 'resource_id': $(this).parent().find('.id_inp').val(), | |
85 | - 'resource_order': $(this).val() | |
86 | - }); | |
87 | - }); | |
88 | - | |
89 | - data = JSON.stringify(data); | |
90 | - | |
91 | - sendUpdateResource(data); | |
92 | - }, | |
93 | - }); | |
94 | - | |
95 | - function sendUpdateResource(data) { | |
96 | - $.ajax({ | |
97 | - url: $("#resource_{{ topic.slug }}").find('.url_order').val(), | |
98 | - dataType: 'json', | |
99 | - data: {'data': data}, | |
100 | - success: function(response) { | |
101 | - console.log(response); | |
102 | - }, | |
103 | - error: function(response) { | |
104 | - console.log(response); | |
105 | - } | |
106 | - }); | |
107 | - } | |
108 | -</script> | |
109 | 0 | \ No newline at end of file |