Skip to content

Commit

Permalink
added filtering of related items on related item meta
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhuang committed Jun 2, 2013
1 parent 6ad9510 commit f0022e7
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 10 deletions.
9 changes: 6 additions & 3 deletions deme_django/cms/templatetags/item_tags.py
Expand Up @@ -990,7 +990,9 @@ def render(self, context):
relationship_set['name'] = name
relationship_set['field'] = field
viewable_items = manager.filter(active=True)
if viewable_items.count() == 0:
viewable_items_count = viewable_items.count()
relationship_set['count'] = viewable_items_count
if viewable_items_count == 0:
relationship_set['items'] = {}
relationship_sets.append(relationship_set)
continue
Expand Down Expand Up @@ -1024,10 +1026,11 @@ def render(self, context):
new_modal_query_string = '?modal=1&src=metadata&populate_' + field.field.name + '=' + str(item.pk)
new_modal_url = reverse('item_type_url', kwargs={'viewer': field.model.__name__.lower(), 'action': 'new'}) + new_modal_query_string

result.append('<div class="type type-related-item-add" data-new-modal-url="%(new_modal_url)s"><a href="%(list_url)s"><b>%(friendly_name)s</b></a></div>' % {
result.append('<div class="type type-related-item-add" data-new-modal-url="%(new_modal_url)s" data-count="%(count)s"><a href="%(list_url)s"><b>%(friendly_name)s</b></a></div>' % {
"list_url": list_url,
"friendly_name": friendly_name,
"new_modal_url": new_modal_url
"new_modal_url": new_modal_url,
"count": relationship_set['count']
})
for related_item in relationship_set['items']:
result.append('<div>%s</div>' % get_item_link_tag(context, related_item))
Expand Down
7 changes: 5 additions & 2 deletions deme_django/static/css/deme.css
Expand Up @@ -5133,6 +5133,9 @@ body.nonadmin #metabar {
#metabar .section > .collapse#metadata_content_item_details h3:first-child {
display: none;
}
#metadata_content_related_items .metadata_content_related_items_switcher_wrap {
margin-bottom: 10px;
}
#metadata_content_related_items .relationship {
margin-bottom: 15px;
}
Expand All @@ -5145,10 +5148,10 @@ body.nonadmin #metabar {
#metadata_content_related_items .relationship .type a {
vertical-align: middle;
}
#metadata_content_related_items .relationship .type .btn {
#metadata_content_related_items .relationship .type .newbtn {
margin-left: 10px;
position: absolute;
top: 2px;
top: 5px;
right: 5px;
}
.approvenpoll .propositions {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 25 additions & 2 deletions deme_django/static/javascripts/deme/metadata-related-item-add.js
@@ -1,12 +1,35 @@
$(function(){
$('#metadata_content_related_items').on('contentload', function(){
$(this).find('.type-related-item-add').each(function(){
// add toggle to top of section
content_section = $(this);
title = content_section.find('h3').first();
toggleButtons = $('<div class="btn-group btn-group-justified metadata_content_related_items_switcher_wrap" data-toggle="buttons-radio"><label class="btn btn-small btn-info active"><input type="radio" name="metadata_content_related_items_switcher" value="existing" checked="checked"> Existing</label><label class="btn btn-small btn-info"><input type="radio" name="metadata_content_related_items_switcher" value="all"> All</label></div>').insertAfter(title);

toggleButtons.find('input').change(function(e){
toggleButtonChange();
});

function toggleButtonChange() {
if ($("input[name='metadata_content_related_items_switcher']:checked").val() == 'all') {
content_section.find('.relationship').show();
} else {
content_section.find('.relationship').each(function(){
if ($(this).find('.type-related-item-add').first().attr('data-count') == 0) {
$(this).hide();
}
});
}
}
toggleButtonChange();

// append add buttons
content_section.find('.type-related-item-add').each(function(){
var type = $(this);
var detail_link = type.find('a');
var new_modal_url = type.attr('data-new-modal-url');

// add button
var newbtn = $('<a href="#" class="btn btn-default btn-small newbtn" title="New Item"><i class="glyphicon glyphicon-plus"></i></a>').insertAfter(detail_link);
var newbtn = $('<a href="#" class="newbtn" title="New Item"><i class="glyphicon glyphicon-plus"></i></a>').insertAfter(detail_link);
newbtn.click(function(e){
e.preventDefault();
var random_num = Math.floor((Math.random()*1000000)+1);
Expand Down
7 changes: 5 additions & 2 deletions deme_django/static/less/deme/metabar.less
Expand Up @@ -149,6 +149,9 @@
}

#metadata_content_related_items {
.metadata_content_related_items_switcher_wrap {
margin-bottom: 10px;
}
.relationship {
margin-bottom: 15px;
.type {
Expand All @@ -159,10 +162,10 @@
a {
vertical-align: middle;
}
.btn {
.newbtn {
margin-left: 10px;
position: absolute;
top: 2px;
top: 5px;
right: 5px;
}
}
Expand Down

0 comments on commit f0022e7

Please sign in to comment.