Changeset 10989
- Timestamp:
- Feb 25, 2012, 10:27:05 AM (12 years ago)
- Location:
- trunk/trac
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/trac/htdocs/js/threaded_comments.js
r10688 r10989 1 /* Threaded ticket comments 2 ======================== 3 4 See the #prefs form in ticket.html. 5 6 We have three mutually exclusive orders, 'newest' first, 'oldest' 7 first and 'threaded'. In addition, changes without comments can be 8 filtered out. 9 10 When switching to 'threaded', the changes without comments must be 11 shown again as they can also have a follow-up. After appending 12 eventual children, they must be hidden again and `:has(.comment)` 13 will now take into account the threaded comments in 14 children. Likewise, when switching away from 'threaded' to a linear 15 order, the changes without comments need to be hidden again. 16 */ 1 17 jQuery(document).ready(function($){ 2 18 var comments = null; 3 var toggle = $('#trac-threaded-toggle'); 4 toggle.click(function() { 5 $(this).toggleClass('checked'); 6 if ($(this).hasClass('checked')) { 19 var order = null; 20 var form = $("#prefs"); 21 22 var commentsOnly = $("#trac-comments-only-toggle"); 23 var applyCommentsOnly = function() { 24 if (commentsOnly.attr('checked')) { 25 $("ul.changes").hide(); 26 $("div.change:not(:has(.comment))").hide(); 27 } else { 28 $("ul.changes").show(); 29 $("div.change:not(:has(.comment))").show(); 30 } 31 }; 32 33 var applyOrder = function() { 34 var commentsOnlyChecked = commentsOnly.attr('checked'); 35 if (commentsOnlyChecked) { 36 commentsOnly.attr("checked", false); 37 applyCommentsOnly(); 38 } 39 order = $("input[name='trac-comments-order']:checked").val(); 40 if (order == 'newest') { 41 $("#changelog").append($("div.change").get().reverse()); 42 } else if (order == 'threaded') { 7 43 comments = $("div.change"); 8 44 comments.each(function() { … … 16 52 } 17 53 }); 18 } else { 54 } 55 if (commentsOnlyChecked) { 56 commentsOnly.attr("checked", true); 57 applyCommentsOnly(); 58 } 59 }; 60 var unapplyOrder = function() { 61 if (order == 'newest') { 62 $("#changelog").append($("div.change").get().reverse()); 63 } else if (order == 'threaded') { 19 64 if (comments) { 20 65 $("#changelog").append(comments); … … 22 67 } 23 68 } 69 }; 70 71 if ($("a.follow-up").length) 72 $('#trac-threaded-toggle').show(); 73 else if (comments_prefs.comments_order == 'threaded') 74 comments_prefs.comments_order = 'oldest' 75 76 $("input[name='trac-comments-order']") 77 .filter("[value=" + comments_prefs.comments_order + "]") 78 .attr('checked', 'checked'); 79 applyOrder(); 80 $("input[name='trac-comments-order']").change(function() { 81 unapplyOrder(); 82 applyOrder(); 83 $.ajax({ url: form.attr('action'), type: 'POST', data: { 84 save_prefs: true, 85 ticket_comments_order: order, 86 __FORM_TOKEN: form_token, 87 }, dataType: 'text' }); 24 88 }); 25 if ($("a.follow-up").length) 26 toggle.closest("form").show(); 89 90 commentsOnly.attr('checked', comments_prefs.comments_only != 'false'); 91 applyCommentsOnly(); 92 commentsOnly.click(function() { 93 applyCommentsOnly(); 94 $.ajax({ url: form.attr('action'), type: 'POST', data: { 95 save_prefs: true, 96 ticket_comments_only: commentsOnly.attr('checked'), 97 __FORM_TOKEN: form_token, 98 }, dataType: 'text' }); 99 }); 27 100 }); -
trunk/trac/prefs/web_ui.py
r10629 r10989 62 62 63 63 def process_request(self, req): 64 xhr = req.get_header('X-Requested-With') == 'XMLHttpRequest' 65 if xhr and req.method == 'POST' and 'save_prefs' in req.args: 66 self._do_save_xhr(req) 67 64 68 panel_id = req.args['panel_id'] 65 69 … … 127 131 # Internal methods 128 132 133 def _do_save_xhr(self, req): 134 for key in req.args: 135 if not key in ['save_prefs', 'panel_id']: 136 req.session[key] = req.args[key] 137 req.session.save() 138 req.send_no_content() 139 129 140 def _do_save(self, req): 130 141 for field in self._form_fields: -
trunk/trac/ticket/templates/ticket.html
r10984 r10989 34 34 actions.click(updateActionFields); 35 35 updateActionFields(); 36 36 37 37 var comment_focused = false; 38 38 $("#comment").focus(function() { comment_focused = true; }) … … 42 42 // Update ticket box 43 43 $("#ticket").replaceWith(items.filter('#ticket')); 44 // Unthread and update changelog 45 var threaded_toggle = $('#trac-threaded-toggle'); 46 if (threaded_toggle.checked()) 47 threaded_toggle.click(); 44 // Unthread, unrevert and update changelog 45 if (!$('#trac-comments-oldest').checked()) 46 $('#trac-comments-oldest').click().change(); 48 47 $("#changelog").replaceWith(items.filter("#changelog")); 49 48 // Show warning … … 125 124 <py:if test="ticket.exists"> 126 125 <xi:include href="ticket_box.html" py:with="preview_mode = change_preview.fields"/> 127 126 128 127 <!--! do not show attachments for old versions of this ticket or for new tickets --> 129 128 <py:if test="not version and version != 0 and ticket.exists"> … … 133 132 134 133 <div style="${'display: none' if not changes else None}"> 135 <form id="trac-threaded-form" method="get" action="" style="display: none"> 136 <div> 137 <input id="trac-threaded-toggle" type="checkbox" /> 138 <label for="trac-threaded-toggle">Threaded Comments</label> 139 </div> 140 </form> 134 <div style="position: relative"> 135 <form id="prefs" method="get" action="${href.prefs()}" style="position: absolute; right: 0"> 136 <div id="trac-comments-order"> 137 <input type="radio" id="trac-comments-oldest" name="trac-comments-order" value="oldest" checked="checked" /> 138 <label for="trac-comments-oldest">Oldest first</label> 139 <input type="radio" id="trac-comments-newest" name="trac-comments-order" value="newest" /> 140 <label for="trac-comments-newest">Newest first</label> 141 <span id="trac-threaded-toggle" style="display: none"> 142 <input type="radio" id="trac-comments-threaded" name="trac-comments-order" value="threaded" /> 143 <label for="trac-comments-threaded">Threaded</label> 144 </span> 145 </div> 146 <div> 147 <input id="trac-comments-only-toggle" type="checkbox" /> 148 <label for="trac-comments-only-toggle">Comments only</label> 149 </div> 150 </form> 151 </div> 141 152 142 153 <h2 class="foldable">Change History</h2> … … 369 380 370 381 <xi:include href="ticket_box.html" py:if="not ticket.exists" py:with="preview_mode = True"/> 371 382 372 383 <div id="help" i18n:msg=""> 373 384 <strong>Note:</strong> See -
trunk/trac/ticket/web_ui.py
r10690 r10989 45 45 from trac.util.translation import _, tag_, tagn_, N_, gettext, ngettext 46 46 from trac.versioncontrol.diff import get_diff_options, diff_blocks 47 from trac.web import arg_list_to_args, parse_arg_list, IRequestHandler 47 from trac.web import arg_list_to_args, parse_arg_list, IRequestHandler, \ 48 RequestDone 48 49 from trac.web.chrome import (Chrome, INavigationContributor, ITemplateProvider, 49 50 add_ctxtnav, add_link, add_notice, add_script, 50 add_s tylesheet, add_warning, auth_link,51 prevnext_nav, web_context)51 add_script_data, add_stylesheet, add_warning, 52 auth_link, prevnext_nav, web_context) 52 53 from trac.wiki.formatter import format_to, format_to_html, format_to_oneliner 53 54 … … 635 636 break 636 637 638 add_script_data(req, {'comments_prefs': self._get_prefs(req)}) 637 639 add_stylesheet(req, 'common/css/ticket.css') 638 640 add_script(req, 'common/js/folding.js') … … 654 656 655 657 return 'ticket.html', data, None 656 658 659 def _get_prefs(self, req): 660 return {'comments_order': req.session.get('ticket_comments_order', 661 'oldest'), 662 'comments_only': req.session.get('ticket_comments_only', 663 False)} 664 657 665 def _prepare_data(self, req, ticket, absurls=False): 658 666 return {'ticket': ticket, 'to_utimestamp': to_utimestamp, -
trunk/trac/web/api.py
r10966 r10989 522 522 raise RequestDone 523 523 524 def send_no_content(self): 525 self.send_response(204) 526 self.send_header('Content-Length', 0) 527 self.send_header('Content-Type', 'text/plain') 528 self.end_headers() 529 raise RequestDone 530 524 531 def send_file(self, path, mimetype=None): 525 532 """Send a local file to the browser.
Note:
See TracChangeset
for help on using the changeset viewer.