diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-11-16 17:55:00 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-11-28 11:40:16 +0100 |
commit | cfcbb04a4c2eb4cd587f34826f2ce69ff6025312 (patch) | |
tree | e96f14eb96dd0c44aa0d5e5b8b4f9e8aa2cd110d /ishtar_common | |
parent | 948d624874bee030a03d63c114a5040113ef694c (diff) | |
download | Ishtar-cfcbb04a4c2eb4cd587f34826f2ce69ff6025312.tar.bz2 Ishtar-cfcbb04a4c2eb4cd587f34826f2ce69ff6025312.zip |
Wizard: display selected on final wizard panel
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/forms.py | 32 | ||||
-rw-r--r-- | ishtar_common/static/js/ishtar.js | 11 | ||||
-rw-r--r-- | ishtar_common/templates/blocks/DataTables.html | 6 | ||||
-rw-r--r-- | ishtar_common/widgets.py | 2 | ||||
-rw-r--r-- | ishtar_common/wizards.py | 2 |
5 files changed, 50 insertions, 3 deletions
diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index 20c65971e..63551ede2 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -341,6 +341,38 @@ class CustomForm(BSForm): return sorted(customs, key=lambda x: x[1]) +class PkWizardSearch(object): + current_model = None + pk_key = None + + @classmethod + def get_formated_datas(cls, cleaned_datas): + if not cls.current_model or not cls.pk_key: + return [] + items = [] + for data in cleaned_datas: + if not data or cls.pk_key not in data or not data[cls.pk_key]: + continue + pks = data[cls.pk_key] + for pk in unicode(pks).split(u','): + if not pk: + continue + try: + items.append( + unicode(cls.current_model.objects.get(pk=int(pk))) + ) + except (cls.current_model.DoesNotExist, ValueError): + continue + return [ + (u"", + mark_safe( + u"<ul class='compact'><li>" + u"</li><li>".join(items) + + u"</li></ul>" + )) + ] + + + class CustomFormSearch(forms.Form): need_user_for_initialization = True diff --git a/ishtar_common/static/js/ishtar.js b/ishtar_common/static/js/ishtar.js index e4e80d681..ea0ccc516 100644 --- a/ishtar_common/static/js/ishtar.js +++ b/ishtar_common/static/js/ishtar.js @@ -968,3 +968,14 @@ var dt_single_enable_disable_submit_button = function(e, dt, type, indexes){ $("#validation-bar #submit_form").prop('disabled', true); } }; + +var dt_multi_enable_disable_submit_button = function(e, dt, type, indexes){ + var rows = dt.rows( { selected: true } ).count(); + if (rows >= 1) { + $("#validation-bar #submit_form").prop('title', ""); + $("#validation-bar #submit_form").prop('disabled', false); + } else { + $("#validation-bar #submit_form").prop('title', select_only_one_msg); + $("#validation-bar #submit_form").prop('disabled', true); + } +}; diff --git a/ishtar_common/templates/blocks/DataTables.html b/ishtar_common/templates/blocks/DataTables.html index e1966787b..096650115 100644 --- a/ishtar_common/templates/blocks/DataTables.html +++ b/ishtar_common/templates/blocks/DataTables.html @@ -194,7 +194,8 @@ jQuery(document).ready(function(){ ], "initComplete": function(settings, json) { var api = new $.fn.dataTable.Api(settings); - dt_single_enable_disable_submit_button(null, api); + {% if not multiple_select %}dt_single_enable_disable_submit_button(null, api); + {% else %}dt_multi_enable_disable_submit_button(null, api);{% endif %} } }; @@ -207,6 +208,9 @@ jQuery(document).ready(function(){ {% if not multiple_select %} datatable_{{sname}}.on('select', dt_single_enable_disable_submit_button); datatable_{{sname}}.on('deselect', dt_single_enable_disable_submit_button); + {% else %} + datatable_{{sname}}.on('select', dt_multi_enable_disable_submit_button); + datatable_{{sname}}.on('deselect', dt_multi_enable_disable_submit_button); {% endif %} {% if multiple %} diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py index 3fd48fa0d..f668ee534 100644 --- a/ishtar_common/widgets.py +++ b/ishtar_common/widgets.py @@ -927,7 +927,7 @@ class DataTable(Select2Media, forms.RadioSelect): :param new: :param new_message: :param source_full: url to get full listing - :param multiple_select: + :param multiple_select: select multiple is available :param sortname: column name (model attribute) to use to sort :param col_prefix: prefix to remove to col_names """ diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index a439cc014..7fd19f721 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -1181,7 +1181,7 @@ class Wizard(IshtarWizard): return vals def get_current_object(self): - """Get the current object for an instancied wizard""" + """Get the current object for an instanced wizard""" current_obj = None for key in self.main_item_select_keys: main_form_key = key + self.url_name |