def format_element(bfo): """ Creates a navigation for comments. """ # get variables this_recid = bfo.control_field('001') try: this_content = bfo.fields('520__a')[0] except: return "" try: this_author = bfo.fields('100__a')[0] except: return "" this_limit_content = get_contextual_content(this_content, [], max_lines=2)[0] menu_recids = [] current_language = bfo.lang post_recid = get_parent_post(this_recid) menu_recids = get_comments(post_recid, newest_first=True) try: menu_out = '<h4>%s</h4>' % cfg_messages["in_issue"][current_language] except: menu_out = '<h4>%s</h4>' % cfg_messages["in_issue"]['en'] for recid in menu_recids: if str(this_recid) == str(recid): menu_out += '<div class="active"><div class="litem"><b>%s</b>: %s [...]</div></div>' % (this_author, this_limit_content) else: temp_rec = BibFormatObject(recid) content = temp_rec.fields('520__a')[0] limit_content = get_contextual_content(content, [], max_lines=1)[0] try: author = temp_rec.fields('100__a')[0] except: author = 'Anonymous' menu_out += '<div class="litem"><a href="%s/record/%s%s"><b>%s</b>: %s [...]</a></div>' % (CFG_SITE_URL, recid, (bfo.lang=="fr") and "?ln=fr" or "?ln=en", author, limit_content) return menu_out
def format_element(bfo): """ Displays comments on a post """ this_recid = bfo.control_field('001') current_language = bfo.lang post_comments_recids = get_comments(this_recid, newest_first=True) out = "" if post_comments_recids: # let's print just the 3 latest posts latest_post_comments_recids = post_comments_recids[:2] out += "<h4>%s</h4>" % cfg_messages["in_issue"][current_language] for comment_recid in latest_post_comments_recids: out += print_record(comment_recid, format='hb') out += "<br />" all_comments = "" all_post_comments_recids = post_comments_recids[2:] for comment_recid in all_post_comments_recids: all_comments += print_record(comment_recid, format='hb') all_comments += "<br />" out += """ <script type="text/javascript"> function displayAllComments(){ var all_comments = document.getElementById('all_comments'); var see_all_link = document.getElementById('see_all_link'); if (all_comments.style.display == 'none'){ all_comments.style.display = ''; see_all_link.innerHTML = "Show less comments" } else { all_comments.style.display = 'none'; see_all_link.innerHTML = "Show all comments" } } </script> """ out += '<span id="all_comments" style="">' + all_comments + '</span>' out += '<a class="moreinfo" id="see_all_link" \ href="javascript:void(0)" onclick="displayAllComments()""></a>' out += '<script type="text/javascript">displayAllComments()</script>' return out