summaryrefslogtreecommitdiff
path: root/ishtar_common/templates/ishtar/blocks/window_tables/dynamic_documents.html
blob: ff92b8af96650b1e9ee37e726bb01230b6af10db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
{% load i18n %}

<h3>{{caption}}</h3>

<div class="modal fade table-modal-lg" tabindex="-1" role="dialog"
     aria-hidden="true" id="modal_grid_{{name}}">
    <div class="modal-dialog full modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <div class="current-sheets"></div>
                <div class="current-grid"></div>
            </div>
        </div>
    </div>
</div>

<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 class="btn btn-secondary" data-toggle="modal"
                    data-target=".table-modal-lg">
                {% 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 %}
            <a class="btn btn-secondary" href='{{simple_source}}csv{{ source_attrs|safe }}' target='_blank' title="{% trans 'Export as CSV' %}">{% trans "CSV" %}</a>
            <a class="btn btn-secondary" href='{{source_full}}csv{{ source_attrs|safe }}' target='_blank' title="{% trans 'Export as CSV - full' %}">{% trans "CSV full" %}</a>
            {% else %}
            <a class="btn btn-secondary" href="{{simple_source}}csv{{ source_attrs|safe }}" target="_blank" title="{% trans 'Export as CSV' %}">CSV</a>
            {% endif %}
        </div>
    </div>
</div>

<div class="row toolbar justify-content-center">
</div>

<script type="text/javascript" language='javascript'>

setTimeout(
    function(){
      datatable_options = {
        "ajax": {
            "url": "{{source}}",
            "dataSrc": "rows"
        },
        "columns": [
            { "data": "id", "visible": false },
            { "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 %}
        ]
      };
      $.extend(datatable_options, datatables_default);
      if (datatables_i18n) datatable_options['language'] = datatables_i18n;

      datatable_{{sname}} = jQuery("#grid_{{name}}").DataTable(datatable_options);

        $('#modal_grid_{{name}}').on('show.bs.modal', function (e) {
            $('#grid_{{name}}_wrapper').appendTo(
                '#modal_grid_{{name}} .modal-body .current-grid');
            $('#grid_{{name}}').DataTable().clear().draw();
            setTimeout(function(){
                $('#modal_grid_{{name}} .modal-body').resize();
            }, 500);  // fix table header refresh for datatable

        });

        $('#modal_grid_{{name}}').on('hide.bs.modal', function (e) {
            $('#grid_{{name}}_wrapper').appendTo(
                '#grid_{{name}}_meta_wrapper');
            $('#grid_{{name}}').DataTable().clear().draw()
        });

      {% comment %}
      {
        url:'{{source|safe}}',
        datatype: "json",
        mtype: 'GET',
        colNames:['id', '', {{col_names|safe}}],
        colModel:[
          {name:'id', index:'id', hidden:true},
          {name:'link', index:'link', width:30},
          {{extra_cols|safe}}
        ],
        sortname: '__default__',
        viewrecords: true,
        sortorder: "asc",
        emptyrecords: "{{no_result}}",
        loadtext: "{{loading}}",
        pager: '#pager_{{name}}',
        width: null,
        shrinkToFit: false,
        rowNum:20,
        jsonReader : {repeatitems: false},
        loadError: function (jqXHR, textStatus, errorThrown) {
            alert("{% trans "An error as occured during search. Check your query fields." %}");
        }
      });
      {% if large %}jQuery("#grid_{{name}}").jqGrid('setGridHeight', 272);{% endif %}
    {% endcomment %}
}, 200);

</script>