diff options
-rw-r--r-- | archaeological_finds/forms.py | 2 | ||||
-rw-r--r-- | ishtar_common/static/js/ishtar.js | 12 | ||||
-rw-r--r-- | ishtar_common/templates/base.html | 1 | ||||
-rw-r--r-- | ishtar_common/templates/blocks/DataTables.html | 16 | ||||
-rw-r--r-- | ishtar_common/widgets.py | 1 |
5 files changed, 26 insertions, 6 deletions
diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py index 5ca8618d5..663ab3663 100644 --- a/archaeological_finds/forms.py +++ b/archaeological_finds/forms.py @@ -725,7 +725,7 @@ class FindFormSelection(CustomFormSearch): label="", required=False, widget=widgets.DataTable( reverse_lazy('get-find'), - FindSelect, models.Find, + FindSelect, models.Find, source_full=reverse_lazy('get-find-full')), validators=[valid_id(models.Find)]) diff --git a/ishtar_common/static/js/ishtar.js b/ishtar_common/static/js/ishtar.js index ff8e43b54..e4e80d681 100644 --- a/ishtar_common/static/js/ishtar.js +++ b/ishtar_common/static/js/ishtar.js @@ -70,6 +70,7 @@ var datatables_static_default = { var activate_all_search_msg = "Searches in the shortcut menu deals with all items."; var activate_own_search_msg = "Searches in the shortcut menu deals with only your items."; var added_message = " items added."; +var select_only_one_msg = "Select only one item."; var search_pinned_msg = ""; var advanced_menu = false; @@ -956,3 +957,14 @@ var qa_action_register = function(url) { ); }); }; + +var dt_single_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/base.html b/ishtar_common/templates/base.html index 652df14b3..add4f1d6c 100644 --- a/ishtar_common/templates/base.html +++ b/ishtar_common/templates/base.html @@ -44,6 +44,7 @@ var activate_own_search_msg = "{% trans 'Searches in the shortcut menu deal with only your items.' %}"; var search_pinned_msg = "{% trans 'Search pinned' %}"; var added_message = "{% trans " items added." %}"; + var select_only_one_msg = {% trans "Select only one item." %}; var YES = "{% trans 'yes' %}"; var NO = "{% trans 'no' %}"; var autorefresh_message_start = "{% trans 'Autorefresh start. The form is disabled.' %}"; diff --git a/ishtar_common/templates/blocks/DataTables.html b/ishtar_common/templates/blocks/DataTables.html index b5f669963..e1966787b 100644 --- a/ishtar_common/templates/blocks/DataTables.html +++ b/ishtar_common/templates/blocks/DataTables.html @@ -152,7 +152,7 @@ jQuery(document).ready(function(){ } }, "select": { - "style": {% if multiple_select %}'multi'{% else %}'single'{% endif %} + "style": {% if multiple_select or quick_actions %}'multi'{% else %}'single'{% endif %} }, {% if multiple_select or quick_actions %}"buttons": [ {% for url, title, icon, target in quick_actions %} @@ -170,7 +170,7 @@ jQuery(document).ready(function(){ } }, {% if not forloop.last %},{% endif %} - {% endfor %}{% if multiple_select %}{% if quick_actions%},{% endif %} + {% endfor %}{% if quick_actions%},{% endif %} { extend: 'selectAll', text: '<i class="fa fa-check-circle-o"></i>', @@ -181,7 +181,6 @@ jQuery(document).ready(function(){ text: '<i class="fa fa-times"></i>', titleAttr: "{% trans 'Deselect' %}" } - {% endif %} ], "dom": 'lBtip', {% else %} @@ -192,7 +191,11 @@ jQuery(document).ready(function(){ { "data": "link", "orderable": false },{% for col in extra_cols %} { "data": "{{col}}", "defaultContent": "-", "render": $.fn.dataTable.render.ellipsis( 70, true ) }{% if not forloop.last %},{% endif %}{% endfor %} - ] + ], + "initComplete": function(settings, json) { + var api = new $.fn.dataTable.Api(settings); + dt_single_enable_disable_submit_button(null, api); + } }; if (!debug) $.fn.dataTable.ext.errMode = 'none'; @@ -201,6 +204,11 @@ jQuery(document).ready(function(){ if (datatables_i18n) datatable_options['language'] = datatables_i18n; datatable_{{sname}} = jQuery("#grid_{{name}}").DataTable(datatable_options); + {% if not multiple_select %} + datatable_{{sname}}.on('select', dt_single_enable_disable_submit_button); + datatable_{{sname}}.on('deselect', dt_single_enable_disable_submit_button); + {% endif %} + {% if multiple %} jQuery("#add_button_{{name}}").click(function (){ var mygrid = jQuery("#grid_{{name}}"); diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py index 7d9e06926..3fd48fa0d 100644 --- a/ishtar_common/widgets.py +++ b/ishtar_common/widgets.py @@ -1055,7 +1055,6 @@ class DataTable(Select2Media, forms.RadioSelect): if hasattr(self.associated_model, "QUICK_ACTIONS"): dct['quick_actions'] = \ self.associated_model.get_quick_actions(user=self.user) - self.multiple_select = True source = unicode(self.source) dct.update({'name': name, 'col_names': col_names, |