Implemented button based multi item actions
This commit is contained in:
@@ -86,15 +86,26 @@
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% if multi_select %}
|
||||
{% with "true" as form_hide_required_text %}
|
||||
{% get_multi_item_links_form %}
|
||||
{% endwith %}
|
||||
<div class="group navform wat-cf">
|
||||
<button class="button" type="submit" name="{{ form.prefix }}-submit">
|
||||
<img src="{{ MEDIA_URL }}web_theme_media/images/icons/tick.png" alt="{% if object %}{% trans 'Save' %}{% else %}{% trans 'Submit' %}{% endif %}" /> {% if object %}{% trans "Save" %}{% else %}{% trans "Submit" %}{% endif %}
|
||||
</button>
|
||||
</div>
|
||||
{% if multi_select or multi_select_as_buttons %}
|
||||
{% if multi_select_as_buttons %}
|
||||
{% get_multi_item_links as multi_item_links %}
|
||||
<div class="group navform wat-cf">
|
||||
{% for link in multi_item_links %}
|
||||
<button class="button" type="submit" name="action" value="{{ link.url }}">
|
||||
{% if link.famfam %}<span class="famfam active famfam-{{ link.famfam|default:'link' }}"></span>{% endif %}{{ link.text|capfirst }}
|
||||
</button>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
{% with "true" as form_hide_required_text %}
|
||||
{% get_multi_item_links_form %}
|
||||
{% endwith %}
|
||||
<div class="group navform wat-cf">
|
||||
<button class="button" type="submit" name="{{ form.prefix }}-submit">
|
||||
<img src="{{ MEDIA_URL }}web_theme_media/images/icons/tick.png" alt="{% if object %}{% trans 'Save' %}{% else %}{% trans 'Submit' %}{% endif %}" /> {% if object %}{% trans "Save" %}{% else %}{% trans "Submit" %}{% endif %}
|
||||
</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</form>
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import types
|
||||
import copy
|
||||
import re
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.urlresolvers import reverse, NoReverseMatch
|
||||
@@ -215,21 +216,27 @@ def resolve_template_variable(context, name):
|
||||
|
||||
|
||||
class GetNavigationLinks(Node):
|
||||
def __init__(self, *args):
|
||||
self.menu_name = None
|
||||
if args:
|
||||
self.menu_name = args[0]
|
||||
def __init__(self, menu_name=None, links_dict=object_navigation, var_name='object_navigation_links'):
|
||||
self.menu_name = menu_name
|
||||
self.links_dict = links_dict
|
||||
self.var_name = var_name
|
||||
|
||||
def render(self, context):
|
||||
menu_name = resolve_template_variable(context, self.menu_name)
|
||||
context['object_navigation_links'] = _get_object_navigation_links(context, menu_name)
|
||||
context[self.var_name] = _get_object_navigation_links(context, menu_name, links_dict=self.links_dict)
|
||||
return ''
|
||||
|
||||
|
||||
@register.tag
|
||||
def get_object_navigation_links(parser, token):
|
||||
args = token.split_contents()
|
||||
return GetNavigationLinks(*args[1:])
|
||||
tag_name, arg = token.contents.split(None, 1)
|
||||
|
||||
m = re.search(r'("?\w+"?)?.?as (\w+)', arg)
|
||||
if not m:
|
||||
raise TemplateSyntaxError("%r tag had invalid arguments" % tag_name)
|
||||
|
||||
menu_name, var_name = m.groups()
|
||||
return GetNavigationLinks(menu_name=menu_name, var_name=var_name)
|
||||
|
||||
|
||||
@register.inclusion_tag('generic_navigation.html', takes_context=True)
|
||||
@@ -242,6 +249,17 @@ def object_navigation_template(context):
|
||||
return new_context
|
||||
|
||||
|
||||
@register.tag
|
||||
def get_multi_item_links(parser, token):
|
||||
tag_name, arg = token.contents.split(None, 1)
|
||||
m = re.search(r'("?\w+"?)?.?as (\w+)', arg)
|
||||
if not m:
|
||||
raise TemplateSyntaxError("%r tag had invalid arguments" % tag_name)
|
||||
|
||||
menu_name, var_name = m.groups()
|
||||
return GetNavigationLinks(menu_name=menu_name, links_dict=multi_object_navigation, var_name=var_name)
|
||||
|
||||
|
||||
@register.inclusion_tag('generic_form_instance.html', takes_context=True)
|
||||
def get_multi_item_links_form(context):
|
||||
new_context = copy.copy(context)
|
||||
|
||||
@@ -74,7 +74,7 @@ def document_list(request):
|
||||
template_name='generic_list.html',
|
||||
extra_context={
|
||||
'title':_(u'documents'),
|
||||
'multi_select':True,
|
||||
'multi_select_as_buttons':True,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
|
||||
{% get_object_navigation_links %}
|
||||
{% get_object_navigation_links as object_navigation_links %}
|
||||
{% if object_navigation_links %}
|
||||
<div class="block">
|
||||
{% if object %}
|
||||
@@ -150,7 +150,7 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% get_object_navigation_links "sidebar" %}
|
||||
{% get_object_navigation_links "sidebar" as object_navigation_links %}
|
||||
{% if object_navigation_links %}
|
||||
<div class="block">
|
||||
<h3>{% trans "Other available actions" %}</h3>
|
||||
|
||||
Reference in New Issue
Block a user