diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2023-01-10 13:08:48 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2023-01-12 09:50:56 +0100 |
commit | a060b26ee54f8f2e95ad812faff3ef0511accf3e (patch) | |
tree | 79a9647f9e8563d44d08123dd4844a249001e63a /ishtar_common/templates | |
parent | 79aaca219772200a5456854ba5102a1c59a36aa1 (diff) | |
download | Ishtar-a060b26ee54f8f2e95ad812faff3ef0511accf3e.tar.bz2 Ishtar-a060b26ee54f8f2e95ad812faff3ef0511accf3e.zip |
Syndication - export external sources
Diffstat (limited to 'ishtar_common/templates')
5 files changed, 69 insertions, 44 deletions
diff --git a/ishtar_common/templates/blocks/DataTables-content.html b/ishtar_common/templates/blocks/DataTables-content.html index 029ebd84c..0665e7a4e 100644 --- a/ishtar_common/templates/blocks/DataTables-content.html +++ b/ishtar_common/templates/blocks/DataTables-content.html @@ -22,11 +22,11 @@ </div> <div class="col"> <div class="btn-group btn-group-sm" role="group"> - <button id="export-{{name}}" type="button" - class="btn btn-secondary dropdown-toggle table-export" data-toggle="dropdown" - aria-haspopup="true" aria-expanded="false"> + <button id="export-{{name}}" type="button" + class="btn btn-secondary dropdown-toggle table-export" data-toggle="dropdown" + aria-haspopup="true" aria-expanded="false"> {% trans 'Export'%} - </button> + </button> <div class="dropdown-menu" aria-labelledby="export-{{name}}"> {% if source_full or extra_sources %} <a class="dropdown-item {{sname}}-csv" href='{{source}}csv' target='_blank' @@ -40,7 +40,7 @@ {% endif %} </div> <div class="input-group-append"> - <div class="selected-lines input-group-text" id="btnGroupAddon"> + <div class="selected-lines input-group-text"> <span class="sl-whole">{% trans "whole table" %}</span> <span class="sl-selected"><span class="sl-number"></span> {% trans "selected item(s)" %}</span> </div> @@ -70,13 +70,13 @@ <input type="hidden" id="hidden_{{name}}" name="{{name}}"/> - {% for source_id, source_label, source_url in external_sources %} + {% for source_id, source_label, source_url, columns, column_labels, export_urls in external_sources %} <div id="grid_{{name}}_{{source_id}}_meta_wrapper" class="sources sources-{{source_id}}"> <table id='grid_{{name}}_{{source_id}}' class="display" width="100%"> <thead> <tr> <th></th> - <th></th>{% for col in col_names %} + <th></th>{% for col in column_labels %} <th>{{col}}</th> {% endfor %}</tr> </thead> @@ -92,6 +92,7 @@ </button> </div> </div> + {% if export_urls %} <div class="col"> <div class="btn-group btn-group-sm" role="group"> <button id="export-{{name}}-" type="button" @@ -100,16 +101,18 @@ {% trans 'Export'%} </button> <div class="dropdown-menu" aria-labelledby="export-{{name}}"> - <a class="dropdown-item {{sname}}-csv" href="{{source}}csv" target="_blank" title="{% trans 'Export as CSV' %}">{% trans "CSV" %}</a> + {% for lbl_export, export_url in export_urls %} + <a class="dropdown-item {{sname}}-csv-external" href="{{export_url}}" target="_blank" title="{% trans 'Export as CSV - ' %}{{lbl_export}}">{{lbl_export}}</a>{% endfor %} </div> <div class="input-group-append"> - <div class="selected-lines input-group-text" id="btnGroupAddon"> + <div class="selected-lines input-group-text"> <span class="sl-whole">{% trans "whole table" %}</span> <span class="sl-selected"><span class="sl-number"></span> {% trans "selected item(s)" %}</span> </div> </div> </div> </div> + {% endif %} </div> diff --git a/ishtar_common/templates/blocks/DataTables-external-sources.html b/ishtar_common/templates/blocks/DataTables-external-sources.html index c317e0c6f..af8774b82 100644 --- a/ishtar_common/templates/blocks/DataTables-external-sources.html +++ b/ishtar_common/templates/blocks/DataTables-external-sources.html @@ -6,7 +6,7 @@ <input type="radio" name="_sources" autocomplete="off" checked> {% trans "Local" %} <span class="badge badge-light" id="source_badge_default">-</span> </label> - {% for source_id, source_label, source_url in external_sources %} + {% for source_id, source_label, source_url, columns, column_labels, export_urls in external_sources %} <label id="source_button_{{source_id}}" class="btn btn-secondary"> <input type="radio" name="_sources" autocomplete="off"> {{source_label}} <span class="badge badge-light" id="source_badge_{{source_id}}">-</span> diff --git a/ishtar_common/templates/blocks/DataTables-stats.html b/ishtar_common/templates/blocks/DataTables-stats.html index d443a7721..8c6d387ac 100644 --- a/ishtar_common/templates/blocks/DataTables-stats.html +++ b/ishtar_common/templates/blocks/DataTables-stats.html @@ -48,7 +48,7 @@ {% with stats_name=name %}{% with extra="default" %} {% include "blocks/DataTables-stats-detail.html" %} {% endwith %}{% endwith %} - {% if external_sources %}{% for source_id, source_label, source_url in external_sources %} + {% if external_sources %}{% for source_id, source_label, source_url, columns, column_labels, export_urls in external_sources %} {% with stats_name=name %}{% with extra=source_id %} {% include "blocks/DataTables-stats-detail.html" %} {% endwith %}{% endwith %} diff --git a/ishtar_common/templates/blocks/DataTables-tabs.html b/ishtar_common/templates/blocks/DataTables-tabs.html index 8b6d4b807..2576f4df5 100644 --- a/ishtar_common/templates/blocks/DataTables-tabs.html +++ b/ishtar_common/templates/blocks/DataTables-tabs.html @@ -42,7 +42,7 @@ id="tab-content-gallery-{{name}}" role="tabpanel" aria-labelledby="tab-gallery-{{name}}"> <div id="content-gallery-{{name}}" class="sources sources-default"></div> - {% if external_sources %}{% for source_id, source_label, source_url in external_sources %} + {% if external_sources %}{% for source_id, source_label, source_url, columns, column_labels, export_urls in external_sources %} <div id="content-gallery-{{name}}-{{source_id}}" class="sources sources-{{source_id}}"></div> {% endfor %}{% endif %} </div>{% endif %} @@ -50,7 +50,7 @@ id="tab-content-map-{{name}}" role="tabpanel" aria-labelledby="tab-map-{{name}}"> <div id="map-{{name}}-default" class="sources sources-default"></div> - {% if external_sources %}{% for source_id, source_label, source_url in external_sources %} + {% if external_sources %}{% for source_id, source_label, source_url, columns, column_labels, export_urls in external_sources %} <div id="map-{{name}}-{{source_id}}" class="sources sources-{{source_id}}"></div>{% endfor %}{% endif %} </div>{% endif %} {% if current_model.STATISTIC_MODALITIES %} diff --git a/ishtar_common/templates/blocks/DataTables.html b/ishtar_common/templates/blocks/DataTables.html index 8ef1a5403..19ffd948e 100644 --- a/ishtar_common/templates/blocks/DataTables.html +++ b/ishtar_common/templates/blocks/DataTables.html @@ -25,7 +25,7 @@ </div> </div> -{% for source_id, source_label, source_url in external_sources %} +{% for source_id, source_label, source_url, columns, column_labels, export_urls in external_sources %} <div class="modal fade table-modal-lg" tabindex="-1" role="dialog" aria-hidden="true" id="modal_grid_{{name}}_{{source_id}}"> <div class="modal-dialog full modal-lg"> @@ -62,7 +62,7 @@ $('#modal_grid_{{name}}').on('hide.bs.modal', function (e) { bs_hide_table("{{name}}"); }); -{% for source_id, source_label, source_url in external_sources %} +{% for source_id, source_label, source_url, columns, column_labels, export_urls in external_sources %} $('#modal_grid_{{name}}_{{source_id}}').on('show.bs.modal', function (e) { bs_expand_table("{{name}}_{{source_id}}"); }); @@ -103,7 +103,7 @@ var selItems_{{sname}} = new Array(); {% if gallery %} gallery_submit_search = function(image_page){ - {% if external_sources %}{% for source_id, source_label, source_url in external_sources %} + {% if external_sources %}{% for source_id, source_label, source_url, columns, column_labels, export_urls in external_sources %} _gallery_submit_search(image_page, query_vars, "{{name}}", "{{source_url}}", "-{{source_id}}"); {% endfor %}{% endif %} return _gallery_submit_search(image_page, query_vars, "{{name}}", "{{source}}"); @@ -114,7 +114,7 @@ map_submit_search = function(){ if (current_source == "default"){ return _map_submit_search(query_vars, "{{name}}", "{{source}}"); } - {% if external_sources %}{% for source_id, source_label, source_url in external_sources %} + {% if external_sources %}{% for source_id, source_label, source_url, columns, column_labels, export_urls in external_sources %} else if (current_source == "{{source_id}}"){ return _map_submit_search(query_vars, "{{name}}", "{{source_url}}", "{{source_id}}"); } @@ -123,17 +123,17 @@ map_submit_search = function(){ {% endif %} extra_list = [ - "default"{% for source_id, source_label, source_url in external_sources %}, + "default"{% for source_id, source_label, source_url, columns, column_labels, export_urls in external_sources %}, "{{source_id}}"{% endfor %} ]; sources = [ - "{{source}}"{% for source_id, source_label, source_url in external_sources %}, + "{{source}}"{% for source_id, source_label, source_url, columns, column_labels, export_urls in external_sources %}, "{{source_url}}"{% endfor %} ]; stats_submit_search = function(){ - {% if external_sources %}{% for source_id, source_label, source_url in external_sources %} + {% if external_sources %}{% for source_id, source_label, source_url, columns, column_labels, export_urls in external_sources %} _stats_submit_search(query_vars, "{{name}}", "{{source_url}}", "{{source_id}}"); {% endfor %}{% endif %} return _stats_submit_search(query_vars, "{{name}}", "{{source}}"); @@ -151,7 +151,7 @@ datatable_submit_search = function(not_submited){ datatable_{{sname}}.ajax.url(url); datatable_{{sname}}.draw(); -{% if external_sources %}{% for source_id, source_label, source_url in external_sources %} +{% if external_sources %}{% for source_id, source_label, source_url, columns, column_labels, export_urls in external_sources %} if (!not_submited){ url = "{{source_url}}?submited=1&" + data; } else { @@ -170,16 +170,23 @@ datatable_submit_search = function(not_submited){ return false; }; -update_submit_args = function(){ - var data = search_get_query_data(query_vars, "{{name}}"); - var csv_url = "{{source}}csv?submited=1&" + data; - $(".{{sname}}-csv").attr("href", csv_url); - var csv_full_url = "{{source_full}}csv?submited=1&" + data; - $(".{{sname}}-csv-full").attr("href", csv_full_url); +update_submit_args = function(source_cls){ + if (!source_cls) source_cls = "sources-default"; + let data = search_get_query_data(query_vars, "{{name}}"); + let extra = "?submited=1&" + data; + let csv_url = "{{source}}csv" + extra; + $("." + source_cls + " .{{sname}}-csv").attr("href", csv_url); + let csv_full_url = "{{source_full}}csv?submited=1&" + data; + $("." + source_cls + " .{{sname}}-csv-full").attr("href", csv_full_url); {% for slug, name, extra_source in extra_sources %} - $(".{{slug}}-csv-full").attr("href", '{{extra_source}}csv?submited=1&' + data);{% endfor %} + $("." + source_cls + " .{{slug}}-csv-full").attr("href", '{{extra_source}}csv?submited=1&' + data);{% endfor %} {% for template in current_model.label_templates %} - $(".{{template.slug}}-labels").attr("href", '{{template.get_baselink_for_labels}}?submited=1&' + data);{% endfor %} + $("." + source_cls + " .{{template.slug}}-labels").attr("href", '{{template.get_baselink_for_labels}}?submited=1&' + data);{% endfor %} + + $("." + source_cls + " .{{sname}}-csv-external").each(function(){ + let url = $(this).attr("href").split('?')[0] + extra; + $(this).attr("href", url); + }); if ($('.modal-progress').length > 0){ $('.modal-progress').modal('hide'); @@ -187,24 +194,24 @@ update_submit_args = function(){ return false; }; -update_select_args = function(dt){ +update_select_args = function(dt, source_cls){ let nb_row = dt.rows( { selected: true } ).count(); - $(".sl-number").html(nb_row); + $("." + source_cls + " .sl-number").html(nb_row); if (nb_row == 0){ - $(".selected-lines .sl-whole").show(); - $(".selected-lines .sl-selected").hide(); - update_submit_args(); + $("." + source_cls + " .selected-lines .sl-whole").show(); + $("." + source_cls + " .selected-lines .sl-selected").hide(); + update_submit_args(source_cls); return; } - $(".selected-lines .sl-selected").show(); - $(".selected-lines .sl-whole").hide(); + $("." + source_cls + " .selected-lines .sl-selected").show(); + $("." + source_cls + " .selected-lines .sl-whole").hide(); let extra_sources = [{% for slug, name, extra_source in extra_sources %} ["{{slug}}", "{{name}}", "{{extra_source}}"]{% if not forloop.last %},{% endif %} {% endfor %}]; let extra_tpl = [{% for template in current_model.label_templates %} ["{{template.slug}}", "{{template.get_baselink_for_labels}}"]{% if not forloop.last %},{% endif %} {% endfor %}]; - update_export_urls(dt, "{{sname}}", "{{source}}", "{{source_full}}", extra_sources, extra_tpl); + update_export_urls(dt, source_cls, "{{sname}}", "{{source}}", "{{source_full}}", extra_sources, extra_tpl); } var current_source = "default"; @@ -227,7 +234,7 @@ jQuery(document).ready(function(){ return false; } ); - {% for source_id, source_label, source_url in external_sources %} + {% for source_id, source_label, source_url, columns, column_labels, export_urls in external_sources %} $("#source_button_{{source_id}}").click( function(){ current_source = "{{source_id}}"; @@ -327,14 +334,14 @@ jQuery(document).ready(function(){ datatable_{{sname}}.on( 'select', function(e, dt, type, indexes){ - update_select_args(dt); + update_select_args(dt, 'sources-default'); dt_single_enable_disable_submit_button(e, dt, type, indexes); } ); datatable_{{sname}}.on( 'deselect', function(e, dt, type, indexes){ - update_select_args(dt); + update_select_args(dt, 'sources-default'); dt_single_enable_disable_submit_button(e, dt, type, indexes); } ); @@ -342,20 +349,20 @@ jQuery(document).ready(function(){ datatable_{{sname}}.on( 'select', function(e, dt, type, indexes){ - update_select_args(dt); + update_select_args(dt, 'sources-default'); dt_multi_enable_disable_submit_button(e, dt, type, indexes); } ); datatable_{{sname}}.on( 'deselect', function(e, dt, type, indexes){ - update_select_args(dt); + update_select_args(dt, 'sources-default'); dt_multi_enable_disable_submit_button(e, dt, type, indexes); } ); {% endif %} -{% if external_sources %}{% for source_id, source_label, source_url in external_sources %} +{% if external_sources %}{% for source_id, source_label, source_url, columns, column_labels, export_urls in external_sources %} var base_external_source = "{{source_url}}"; if (default_search_vector){ @@ -375,10 +382,13 @@ jQuery(document).ready(function(){ } }, "deferLoading": 0, + "select": { + "style": 'multi' + }, "dom": 'litp', "columns": [ { "data": "id", "visible": false }, - { "data": "link", "orderable": false },{% for col in extra_cols %} + { "data": "link", "orderable": false },{% for col in columns %} { "data": "{{col}}", "defaultContent": "-", "render": $.fn.dataTable.render.ellipsis( 70, true ) }{% if not forloop.last %},{% endif %}{% endfor %} ] @@ -386,6 +396,18 @@ jQuery(document).ready(function(){ $.extend(datatable_options_{{source_id}}, datatables_default); if (datatables_i18n) datatable_options_{{source_id}}['language'] = datatables_i18n; datatable_{{sname}}_{{source_id}} = jQuery("#grid_{{name}}_{{source_id}}").DataTable(datatable_options_{{source_id}}); + datatable_{{sname}}_{{source_id}}.on( + 'select', + function(e, dt, type, indexes){ + update_select_args(dt, 'sources-{{source_id}}'); + } + ); + datatable_{{sname}}_{{source_id}}.on( + 'deselect', + function(e, dt, type, indexes){ + update_select_args(dt, 'sources-{{source_id}}'); + } + ); {% endfor %}{% endif %} |