diff options
| -rw-r--r-- | archaeological_context_records/forms.py | 1 | ||||
| -rw-r--r-- | archaeological_finds/forms.py | 7 | ||||
| -rw-r--r-- | archaeological_finds/forms_treatments.py | 4 | ||||
| -rw-r--r-- | archaeological_operations/forms.py | 2 | ||||
| -rw-r--r-- | ishtar_common/templates/blocks/DataTables-content.html | 45 | ||||
| -rw-r--r-- | ishtar_common/templates/blocks/DataTables-gallery.html | 33 | ||||
| -rw-r--r-- | ishtar_common/templates/blocks/DataTables.html | 82 | ||||
| -rw-r--r-- | ishtar_common/widgets.py | 5 | 
8 files changed, 104 insertions, 75 deletions
diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py index 8bd3db9f5..54ae74202 100644 --- a/archaeological_context_records/forms.py +++ b/archaeological_context_records/forms.py @@ -122,6 +122,7 @@ class RecordFormSelection(CustomFormSearch):          widget=widgets.DataTable(              reverse_lazy('get-contextrecord'),              RecordSelect, models.ContextRecord, +            gallery=True,              source_full=reverse_lazy('get-contextrecord-full')),          validators=[valid_id(models.ContextRecord)]) diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py index ae592d013..3073c5c23 100644 --- a/archaeological_finds/forms.py +++ b/archaeological_finds/forms.py @@ -992,6 +992,7 @@ class FindFormSelection(CustomFormSearch):          widget=widgets.DataTable(              reverse_lazy('get-find'),              FindSelect, models.Find, +            gallery=True,              source_full=reverse_lazy('get-find-full')),          validators=[valid_id(models.Find)]) @@ -1002,6 +1003,7 @@ class FindFormSelectionWarehouseModule(FindFormSelection):          widget=widgets.DataTable(              reverse_lazy('get-find'),              FindSelectWarehouseModule, models.Find, +            gallery=True,              source_full=reverse_lazy('get-find-full')),          validators=[valid_id(models.Find)]) @@ -1015,6 +1017,7 @@ class MultipleFindFormSelection(forms.Form):          widget=widgets.DataTable(              reverse_lazy('get-find'),              FindSelect, models.Find, +            gallery=True,              multiple_select=True,              source_full=reverse_lazy('get-find-full')),          validators=[valid_id(models.Find)]) @@ -1026,6 +1029,7 @@ class MultipleFindFormSelectionWarehouseModule(MultipleFindFormSelection):          widget=widgets.DataTable(              reverse_lazy('get-find'),              FindSelectWarehouseModule, models.Find, +            gallery=True,              multiple_select=True,              source_full=reverse_lazy('get-find-full')),          validators=[valid_id(models.Find)]) @@ -1041,6 +1045,7 @@ class FindMultipleFormSelection(forms.Form):          label="", required=False,          widget=widgets.DataTable(              reverse_lazy('get-find'), FindSelectWarehouseModule, models.Find, +            gallery=True,              multiple=True, multiple_cols=[2, 3, 4]),          validators=[valid_ids(models.Find)]) @@ -1186,6 +1191,7 @@ class UpstreamFindFormSelection(PkWizardSearch, FindFormSelection):          widget=widgets.DataTable(              reverse_lazy('get-find'),              FindSelect, current_model, +            gallery=True,              multiple_select=True,              source_full=reverse_lazy('get-find-full')),          validators=[valid_ids(current_model)]) @@ -1203,6 +1209,7 @@ class SingleUpstreamFindFormSelection(UpstreamFindFormSelection):          widget=widgets.DataTable(              reverse_lazy('get-find'),              FindSelect, current_model, +            gallery=True,              source_full=reverse_lazy('get-find-full')),          validators=[valid_ids(current_model)]) diff --git a/archaeological_finds/forms_treatments.py b/archaeological_finds/forms_treatments.py index 10c4527ef..18c0697fc 100644 --- a/archaeological_finds/forms_treatments.py +++ b/archaeological_finds/forms_treatments.py @@ -74,7 +74,9 @@ class TreatmentFormSelection(forms.Form):          label="", required=False,          widget=widgets.DataTable(              reverse_lazy('get-treatment'), -            TreatmentSelect, models.Treatment), +            TreatmentSelect, models.Treatment, +            gallery=True, +        ),          validators=[valid_id(models.Treatment)]) diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py index 3103990c9..abb5de8a9 100644 --- a/archaeological_operations/forms.py +++ b/archaeological_operations/forms.py @@ -603,6 +603,7 @@ class OperationFormSelection(IshtarForm):          label="", required=False,          widget=widgets.DataTable(              reverse_lazy('get-operation'), OperationSelect, models.Operation, +            gallery=True,              source_full=reverse_lazy('get-operation-full')),          validators=[valid_id(models.Operation)]) @@ -1313,6 +1314,7 @@ class SiteFormSelection(IshtarForm):          widget=widgets.DataTable(              reverse_lazy('get-site'), SiteSelect,              models.ArchaeologicalSite, +            gallery=True,              source_full=reverse_lazy('get-site-full')),          validators=[valid_id(models.ArchaeologicalSite)]) diff --git a/ishtar_common/templates/blocks/DataTables-content.html b/ishtar_common/templates/blocks/DataTables-content.html new file mode 100644 index 000000000..41513aade --- /dev/null +++ b/ishtar_common/templates/blocks/DataTables-content.html @@ -0,0 +1,45 @@ +{% load i18n %} +    <div id="grid_{{name}}_meta_wrapper"> +        <table id='grid_{{name}}' class="display" width="100%"> +            <thead> +            <tr> +                <th></th> +                <th></th>{% for col in col_names %} +                <th>{{col}}</th> +            {% endfor %}</tr> +            </thead> +        </table> +    </div> + +    <div id='foot_{{name}}' class="gridfooter row toolbar"> +        <div class='col-md-2'> +            <div class="btn-group btn-group-sm" role="group"> +                <button type='button' class="btn btn-secondary" data-toggle="modal" +                        data-target="#modal_grid_{{name}}"> +                    {% trans "Expand table" %} <i class="fa fa-expand" aria-hidden="true"></i> +                </button> +            </div> +        </div> +        <div class='col-md-2'> +            <div class="btn-group btn-group-sm" role="group" +                 aria-label="{% trans 'Export'%}"> +                {% if source_full or extra_sources %} +                <a class="btn btn-secondary" href='{{source}}csv' target='_blank' +                   title="{% trans 'Export as CSV - ' %}{% trans 'simple'%}">{% trans "Simple CSV" %}</a> +                {% if source_full %}<a class='btn btn-secondary' href='{{source_full}}csv' target='_blank' title="{% trans 'Export as CSV - full' %}">{% trans "CSV full" %}</a>{% endif %} +                {% for slug, name, extra_source in extra_sources %} +                <a class="btn btn-secondary" href='{{extra_source}}csv' target='_blank' title="{% trans 'Export as CSV - ' %}{{name}}">{{name}}</a> +                {% endfor %} +                {% else %} +                <a class="btn btn-secondary" href="{{source}}csv" target="_blank" title="{% trans 'Export as CSV' %}">{% trans "CSV" %}</a> +                {% endif %} +            </div> +        </div> +    </div> + +    {% if multiple %} +    <input type="button" id="add_button_{{name}}" value="{% trans 'Add' %}"/> +    <ul id="selectmulti_{{name}}" class="selectmulti"></ul> +    {% endif %} + +    <input type="hidden" id="hidden_{{name}}" name="{{name}}"/> diff --git a/ishtar_common/templates/blocks/DataTables-gallery.html b/ishtar_common/templates/blocks/DataTables-gallery.html new file mode 100644 index 000000000..5fa448d89 --- /dev/null +++ b/ishtar_common/templates/blocks/DataTables-gallery.html @@ -0,0 +1,33 @@ +{% load i18n %} + +<ul class="nav nav-tabs m-3"> +  <li class="nav-item"> +    <a class="nav-link active" id="tab-grid-{{name}}" data-toggle="tab" +       href="#tab-content-grid-{{name}}" role="tab" +       aria-controls="tab-content-grid-{{name}}" aria-selected="true"> +        {% trans "Table" %} +    </a> +  </li> +  <li class="nav-item"> +      <a class="nav-link" id="tab-gallery-{{name}}" data-toggle="tab" +         href="#tab-content-gallery-{{name}}" role="tab" +         aria-controls="tab-content-gallery-{{name}}" aria-selected="true"> +          {% trans "Gallery" %} +      </a> +  </li> +</ul> + + +<div class="tab-content"> +  <div class="tab-pane active" +       id="tab-content-grid-{{name}}" role="tabpanel" +       aria-labelledby="tab-grid-{{name}}"> +      {% include "blocks/DataTables-content.html" %} +  </div> +  <div class="tab-pane" +       id="tab-content-gallery-{{name}}" role="tabpanel" +       aria-labelledby="tab-gallery-{{name}}"> +  </div> +</div> + + diff --git a/ishtar_common/templates/blocks/DataTables.html b/ishtar_common/templates/blocks/DataTables.html index 07725353c..2e2897539 100644 --- a/ishtar_common/templates/blocks/DataTables.html +++ b/ishtar_common/templates/blocks/DataTables.html @@ -27,79 +27,11 @@    </div>  </div> -<ul class="nav nav-tabs m-3"> -  <li class="nav-item"> -    <a class="nav-link active" id="tab-grid-{{name}}" data-toggle="tab" -       href="#tab-content-grid-{{name}}" role="tab" -       aria-controls="tab-content-grid-{{name}}" aria-selected="true"> -        {% trans "Table" %} -    </a> -  </li> -  <li class="nav-item"> -      <a class="nav-link" id="tab-gallery-{{name}}" data-toggle="tab" -         href="#tab-content-gallery-{{name}}" role="tab" -         aria-controls="tab-content-gallery-{{name}}" aria-selected="true"> -          {% trans "Gallery" %} -      </a> -  </li> -</ul> - - -<div class="tab-content"> -  <div class="tab-pane active" -       id="tab-content-grid-{{name}}" role="tabpanel" -       aria-labelledby="tab-grid-{{name}}"> - -    <div id="grid_{{name}}_meta_wrapper"> -        <table id='grid_{{name}}' class="display" width="100%"> -            <thead> -            <tr> -                <th></th> -                <th></th>{% for col in col_names %} -                <th>{{col}}</th> -            {% endfor %}</tr> -            </thead> -        </table> -    </div> - -    <div id='foot_{{name}}' class="gridfooter row toolbar"> -        <div class='col-md-2'> -            <div class="btn-group btn-group-sm" role="group"> -                <button type='button' class="btn btn-secondary" data-toggle="modal" -                        data-target="#modal_grid_{{name}}"> -                    {% trans "Expand table" %} <i class="fa fa-expand" aria-hidden="true"></i> -                </button> -            </div> -        </div> -        <div class='col-md-2'> -            <div class="btn-group btn-group-sm" role="group" -                 aria-label="{% trans 'Export'%}"> -                {% if source_full or extra_sources %} -                <a class="btn btn-secondary" href='{{source}}csv' target='_blank' -                   title="{% trans 'Export as CSV - ' %}{% trans 'simple'%}">{% trans "Simple CSV" %}</a> -                {% if source_full %}<a class='btn btn-secondary' href='{{source_full}}csv' target='_blank' title="{% trans 'Export as CSV - full' %}">{% trans "CSV full" %}</a>{% endif %} -                {% for slug, name, extra_source in extra_sources %} -                <a class="btn btn-secondary" href='{{extra_source}}csv' target='_blank' title="{% trans 'Export as CSV - ' %}{{name}}">{{name}}</a> -                {% endfor %} -                {% else %} -                <a class="btn btn-secondary" href="{{source}}csv" target="_blank" title="{% trans 'Export as CSV' %}">{% trans "CSV" %}</a> -                {% endif %} -            </div> -        </div> -    </div> - -    {% if multiple %} -    <input type="button" id="add_button_{{name}}" value="{% trans 'Add' %}"/> -    <ul id="selectmulti_{{name}}" class="selectmulti"></ul> -    {% endif %} - -    <input type="hidden" id="hidden_{{name}}" name="{{name}}"/> -  </div> -  <div class="tab-pane active" -       id="tab-content-gallery-{{name}}" role="tabpanel" -       aria-labelledby="tab-gallery-{{name}}"> -  </div> -</div> +{% if gallery %} +{% include "blocks/DataTables-gallery.html" %} +{% else %} +{% include "blocks/DataTables-content.html" %} +{% endif %}  <script type="text/javascript" language='javascript'>  $('#modal_grid_{{name}}').on('show.bs.modal', function (e) { @@ -119,6 +51,7 @@ $('#modal_grid_{{name}}').on('hide.bs.modal', function (e) {      current_modal = null;  }); +{% if gallery %}  $("#tab-gallery-{{name}}").click(function(){      current_tab = "gallery";      gallery_submit_search(); @@ -128,11 +61,13 @@ $("#tab-grid-{{name}}").click(function(){      current_tab = "table";      datatable_submit_search();  }); +{% endif %}  var query_vars = new Array({{col_idx|safe}});  var selItems_{{sname}} = new Array(); +{% if gallery %}  gallery_submit_search = function(){      var data = search_get_query_data(query_vars, "{{name}}");      var nb_select = jQuery("#id_{{name}}-length_image").val(); @@ -151,6 +86,7 @@ gallery_submit_search = function(){      }      return false;  }; +{% endif %}  datatable_submit_search = function(){      var data = search_get_query_data(query_vars, "{{name}}"); diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py index 5853c9675..aee4eb95d 100644 --- a/ishtar_common/widgets.py +++ b/ishtar_common/widgets.py @@ -953,7 +953,7 @@ class DataTable(Select2Media, forms.RadioSelect):                   table_cols='TABLE_COLS', multiple=False, multiple_cols=[2],                   new=False, new_message="", source_full=None,                   multiple_select=False, sortname="__default__", -                 col_prefix=''): +                 col_prefix='', gallery=False):          """          DataTable widget init. @@ -970,6 +970,7 @@ class DataTable(Select2Media, forms.RadioSelect):          :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 +        :param gallery: display the gallery if True          """          super(DataTable, self).__init__(attrs=attrs)          self.source = source @@ -987,6 +988,7 @@ class DataTable(Select2Media, forms.RadioSelect):          self.sortname = sortname          self.col_prefix = col_prefix          self.user = None +        self.gallery = gallery          if self.col_prefix and not self.col_prefix.endswith('__'):              self.col_prefix += "__" @@ -1105,6 +1107,7 @@ class DataTable(Select2Media, forms.RadioSelect):                      'loading': unicode(_("Loading...")),                      'remove': unicode(_(u"Remove")),                      'sname': name.replace('-', ''), +                    'gallery': self.gallery,                      'multiple': self.multiple,                      'multiple_select': self.multiple_select,                      'multi_cols': ",".join((u'"%d"' % col  | 
