Skip to content

Commit 540ef74

Browse files
committed
Fix community list track/untrack on document page, also fix the
attached Javascript which had a split personality regarding how to deal with a repeated click - Legacy-Id: 10714
1 parent b7232d0 commit 540ef74

5 files changed

Lines changed: 16 additions & 36 deletions

File tree

ietf/doc/views_doc.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
from django.shortcuts import render, render_to_response, get_object_or_404, redirect
3737
from django.template import RequestContext
3838
from django.template.loader import render_to_string
39-
from django.core.exceptions import ObjectDoesNotExist
4039
from django.core.urlresolvers import reverse as urlreverse
4140
from django.conf import settings
4241
from django import forms
@@ -50,7 +49,7 @@
5049
can_adopt_draft, get_chartering_type, get_document_content, get_tags_for_stream_id,
5150
needed_ballot_positions, nice_consensus, prettify_std_name, update_telechat, has_same_ballot,
5251
get_initial_notify, make_notify_changed_event, crawl_history)
53-
from ietf.community.models import CommunityList
52+
from ietf.community.utils import augment_docs_with_tracking_info
5453
from ietf.group.models import Role
5554
from ietf.group.utils import can_manage_group_type, can_manage_materials
5655
from ietf.ietfauth.utils import has_role, is_authorized_in_doc_stream, user_is_person, role_required
@@ -341,15 +340,7 @@ def document_main(request, name, rev=None):
341340
elif can_edit_stream_info and (not iesg_state or iesg_state.slug == 'watching'):
342341
actions.append(("Submit to IESG for Publication", urlreverse('doc_to_iesg', kwargs=dict(name=doc.name))))
343342

344-
tracking_document = False
345-
if request.user.is_authenticated():
346-
try:
347-
clist = CommunityList.objects.get(user=request.user)
348-
clist.update()
349-
if clist.get_documents().filter(name=doc.name).count() > 0:
350-
tracking_document = True
351-
except ObjectDoesNotExist:
352-
pass
343+
augment_docs_with_tracking_info([doc], request.user)
353344

354345
replaces = [d.name for d in doc.related_that_doc("replaces")]
355346
replaced_by = [d.name for d in doc.related_that("replaces")]
@@ -416,7 +407,6 @@ def document_main(request, name, rev=None):
416407
shepherd_writeup=shepherd_writeup,
417408
search_archive=search_archive,
418409
actions=actions,
419-
tracking_document=tracking_document,
420410
),
421411
context_instance=RequestContext(request))
422412

ietf/group/tests_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def test_group_documents(self):
197197
self.client.login(username="secretary", password="secretary+password")
198198
r = self.client.get(url)
199199
q = PyQuery(r.content)
200-
self.assertTrue(any([draft2.name in x.attrib['href'] for x in q('table td a.community-list-add-remove-doc')]))
200+
self.assertTrue(any([draft2.name in x.attrib['href'] for x in q('table td a.track-untrack-doc')]))
201201

202202
# test the txt version too while we're at it
203203
url = urlreverse('ietf.group.info.group_documents_txt', kwargs=dict(group_type=group.type_id, acronym=group.acronym))

ietf/static/ietf/js/ietf.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,23 +100,19 @@ $(document).ready(function () {
100100
}
101101

102102
// search results
103-
$('.community-list-add-remove-doc').click(function(e) {
103+
$('.track-untrack-doc').click(function(e) {
104104
e.preventDefault();
105-
var trigger = $(this);
106-
$.ajax({
105+
var trigger = $(this);
106+
$.ajax({
107107
url: trigger.attr('href'),
108108
type: 'POST',
109109
cache: false,
110110
dataType: 'json',
111111
success: function(response){
112112
if (response.success) {
113113
trigger.parent().find(".tooltip").remove();
114-
trigger.find("span.fa").toggleClass("fa-bookmark fa-bookmark-o");
115-
if (trigger.hasClass('btn')) {
116-
trigger.attr('disabled', true).blur();
117-
} else {
118-
trigger.contents().unwrap().blur();
119-
}
114+
trigger.addClass("hide");
115+
trigger.parent().find(".track-untrack-doc").not(trigger).removeClass("hide");
120116
}
121117
}
122118
});

ietf/templates/doc/document_draft.html

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -434,11 +434,8 @@
434434
</ul>
435435
</div>
436436
{% if user.is_authenticated %}
437-
{% if tracking_document %}
438-
<a class="btn btn-default btn-xs community-list-add-remove-doc" href="{% url "community_personal_untrack_document" doc.name %}" title="Remove from your personal ID list"><span class="fa fa-bookmark-o"></span> Untrack</a>
439-
{% else %}
440-
<a class="btn btn-default btn-xs community-list-add-remove-doc" href="{% url "community_personal_track_document" doc.name %}" title="Add to your personal ID list"><span class="fa fa-bookmark"></span> Track</a>
441-
{% endif %}
437+
<a class="btn btn-default btn-xs track-untrack-doc {% if not doc.tracked_in_personal_community_list %}hide{% endif %}" href="{% url "community_personal_untrack_document" doc.name %}" title="Remove from your personal ID list"><span class="fa fa-bookmark"></span> Untrack</a>
438+
<a class="btn btn-default btn-xs track-untrack-doc {% if doc.tracked_in_personal_community_list %}hide{% endif %}" href="{% url "community_personal_track_document" doc.name %}" title="Add to your personal ID list"><span class="fa fa-bookmark-o"></span> Track</a>
442439
{% endif %}
443440

444441
{% if can_edit and iesg_state %}

ietf/templates/doc/search/search_result_row.html

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,12 @@
1313

1414
<td>
1515
{% if user.is_authenticated %}
16-
{% if doc.tracked_in_personal_community_list %}
17-
<a href="{% url "community_personal_untrack_document" doc.name %}" class="community-list-add-remove-doc" title="Remove from your personal ID list">
18-
<span class="fa fa-bookmark"></span>
19-
</a>
20-
{% else %}
21-
<a href="{% url "community_personal_track_document" doc.name %}" class="community-list-add-remove-doc" title="Add to your personal ID list">
22-
<span class="fa fa-bookmark-o"></span>
23-
</a>
24-
{% endif %}
16+
<a href="{% url "community_personal_untrack_document" doc.name %}" class="track-untrack-doc {% if not doc.tracked_in_personal_community_list %}hide{% endif %}" title="Remove from your personal ID list">
17+
<span class="fa fa-bookmark"></span>
18+
</a>
19+
<a href="{% url "community_personal_track_document" doc.name %}" class="track-untrack-doc {% if doc.tracked_in_personal_community_list %}hide{% endif %}" title="Add to your personal ID list">
20+
<span class="fa fa-bookmark-o"></span>
21+
</a>
2522
{% endif %}
2623
</td>
2724

0 commit comments

Comments
 (0)