Commit 6f42052f66add1979bd2951c34998b1be29959c6
1 parent
b0e18756
Exists in
master
and in
5 other branches
Passing javascript to external static file [Issue: #73]
Showing
5 changed files
with
65 additions
and
71 deletions
Show diff stats
amadeus/settings.py
courses/templates/subject/form_view_teacher.html
1 | 1 | {% load static i18n %} |
2 | 2 | |
3 | 3 | {% block javascript %} |
4 | - <script type="text/javascript"> | |
5 | - var baseUrl = '{% url "forum:index" %}'; | |
6 | - var formUrl = '{% url "forum:create" %}'; | |
7 | - | |
8 | - function showForum(topic) { | |
9 | - $.ajax({ | |
10 | - url: baseUrl, | |
11 | - data: {'topic': topic}, | |
12 | - success: function(data) { | |
13 | - $(".forum_topics").html(data); | |
14 | - } | |
15 | - }); | |
16 | - | |
17 | - $('#forumModal').modal(); | |
18 | - } | |
19 | - | |
20 | - function getForm() { | |
21 | - $.ajax({ | |
22 | - url: formUrl, | |
23 | - success: function(data) { | |
24 | - $(".forum_form").html(data); | |
25 | - } | |
26 | - }); | |
27 | - | |
28 | - $(".forum_form").show(); | |
29 | - } | |
30 | - | |
31 | - var postsUrl = '{% url "forum:posts" %}'; | |
32 | - var formPostsUrl = ''; | |
33 | - | |
34 | - function showPosts(forum) { | |
35 | - if ($("#collapse" + forum).hasClass('in')) { | |
36 | - $("#collapse" + forum).collapse('hide'); | |
37 | - } else { | |
38 | - $.ajax({ | |
39 | - url: postsUrl, | |
40 | - data: {'forum': forum}, | |
41 | - success: function(data) { | |
42 | - $("#collapse" + forum).find(".well").html(data); | |
43 | - } | |
44 | - }); | |
45 | - | |
46 | - $("#collapse" + forum).collapse('show'); | |
47 | - } | |
48 | - } | |
49 | - | |
50 | - var postsAnswerUrl = '{% url "forum:post_answers" %}'; | |
51 | - var formPostsAnswersUrl = ''; | |
52 | - | |
53 | - function showPostsAnswers(post) { | |
54 | - if ($("#collapse" + post).hasClass('in')) { | |
55 | - $("#collapse" + post).collapse('hide'); | |
56 | - } else { | |
57 | - $.ajax({ | |
58 | - url: postsAnswerUrl, | |
59 | - data: {'post': post}, | |
60 | - success: function(data) { | |
61 | - $("#collapse" + post).find(".well").html(data); | |
62 | - } | |
63 | - }); | |
64 | - | |
65 | - $("#collapse" + post).collapse('show'); | |
66 | - } | |
67 | - } | |
68 | - </script> | |
4 | + <script type="text/javascript" src="{% static 'js/forum.js' %}"></script> | |
69 | 5 | {% endblock %} |
70 | 6 | |
71 | 7 | <div class="panel panel-default"> |
... | ... | @@ -73,7 +9,7 @@ |
73 | 9 | <div class="panel-heading"> |
74 | 10 | <div class="row"> |
75 | 11 | <div class="col-md-9 col-sm-9"> |
76 | - <h3>{{topic}}</h3> | |
12 | + <h3>{{ topic }}</h3> | |
77 | 13 | </div> |
78 | 14 | <div class="col-md-3 col-sm-3"> |
79 | 15 | <a href="{% url 'course:update_topic' topic.slug%}" class="btn">{% trans "edit" %}</a> |
... | ... | @@ -82,8 +18,8 @@ |
82 | 18 | </div> |
83 | 19 | </a> |
84 | 20 | <div class="panel-body"> |
85 | - <p>{{topic.description|linebreaks}}</p> | |
86 | - <a href="javascript:showForum('{{topic.slug}}')">Forum</a> | |
21 | + <p>{{ topic.description|linebreaks }}</p> | |
22 | + <a href="javascript:showForum('{% url 'forum:index' %}', '{{topic.slug}}')">Forum</a> | |
87 | 23 | </div> |
88 | 24 | </div> |
89 | 25 | |
... | ... | @@ -93,7 +29,7 @@ |
93 | 29 | <div class="modal-header"> |
94 | 30 | <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> |
95 | 31 | <h4 class="modal-title" id="myModalLabel"> |
96 | - <button type="button" class="btn btn-primary btn-sm" onclick="getForm();"><i class="fa fa-plus"></i> {% trans 'Create Forum' %}</button> | |
32 | + <button type="button" class="btn btn-primary btn-sm" onclick="getForm('{% url 'forum:create' %}');"><i class="fa fa-plus"></i> {% trans 'Create Forum' %}</button> | |
97 | 33 | </h4> |
98 | 34 | </div> |
99 | 35 | <div class="modal-body"> | ... | ... |
... | ... | @@ -0,0 +1,54 @@ |
1 | +function showForum(url, topic) { | |
2 | + $.ajax({ | |
3 | + url: url, | |
4 | + data: {'topic': topic}, | |
5 | + success: function(data) { | |
6 | + $(".forum_topics").html(data); | |
7 | + } | |
8 | + }); | |
9 | + | |
10 | + $('#forumModal').modal(); | |
11 | +} | |
12 | + | |
13 | +function getForm(url) { | |
14 | + $.ajax({ | |
15 | + url: url, | |
16 | + success: function(data) { | |
17 | + $(".forum_form").html(data); | |
18 | + } | |
19 | + }); | |
20 | + | |
21 | + $(".forum_form").show(); | |
22 | +} | |
23 | + | |
24 | +function showPosts(url, forum) { | |
25 | + if ($("#collapse" + forum).hasClass('in')) { | |
26 | + $("#collapse" + forum).collapse('hide'); | |
27 | + } else { | |
28 | + $.ajax({ | |
29 | + url: url, | |
30 | + data: {'forum': forum}, | |
31 | + success: function(data) { | |
32 | + $("#collapse" + forum).find(".well").html(data); | |
33 | + } | |
34 | + }); | |
35 | + | |
36 | + $("#collapse" + forum).collapse('show'); | |
37 | + } | |
38 | +} | |
39 | + | |
40 | +function showPostsAnswers(url, post) { | |
41 | + if ($("#collapse" + post).hasClass('in')) { | |
42 | + $("#collapse" + post).collapse('hide'); | |
43 | + } else { | |
44 | + $.ajax({ | |
45 | + url: url, | |
46 | + data: {'post': post}, | |
47 | + success: function(data) { | |
48 | + $("#collapse" + post).find(".well").html(data); | |
49 | + } | |
50 | + }); | |
51 | + | |
52 | + $("#collapse" + post).collapse('show'); | |
53 | + } | |
54 | +} | |
0 | 55 | \ No newline at end of file | ... | ... |
forum/templates/forum_list.html
... | ... | @@ -2,7 +2,7 @@ |
2 | 2 | |
3 | 3 | {% if foruns|length > 0 %} |
4 | 4 | {% for forum in foruns %} |
5 | - <a class="forum_collapse" role="button" href="javascript: showPosts('{{ forum.slug }}')" aria-expanded="false"> | |
5 | + <a class="forum_collapse" role="button" href="javascript: showPosts('{% url 'forum:posts' %}', '{{ forum.slug }}')" aria-expanded="false"> | |
6 | 6 | <div class="page-header"> |
7 | 7 | <h1 id="timeline">{{ forum }}</h1> |
8 | 8 | <b>{% trans 'Description' %}: </b>{{ forum.description }}<p> | ... | ... |
forum/templates/post_list.html
... | ... | @@ -4,7 +4,7 @@ |
4 | 4 | <ul class="timeline post"> |
5 | 5 | {% for post in posts %} |
6 | 6 | <li> |
7 | - <a class="post_collapse" role="button" href="javascript: showPostsAnswers('{{ post.id }}')" aria-expanded="false"> | |
7 | + <a class="post_collapse" role="button" href="javascript: showPostsAnswers('{% url 'forum:post_answers' %}', '{{ post.id }}')" aria-expanded="false"> | |
8 | 8 | <div class="timeline-panel"> |
9 | 9 | <div class="row"> |
10 | 10 | <div class="col-xs-2 col-sm-2 col-md-2"> | ... | ... |