aboutsummaryrefslogtreecommitdiffstats
path: root/server/templates/server/doc_list_table.html
blob: eb9c9465b43ad3b86ed4285632b3cba568a767be (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
{% extends 'registration/base_admin.html' %}

{% block title %}Admin - Lista Utenti{% endblock %}

{% block breadcrumb %}
  <a href="{% url 'server'%}" class="breadcrumb hide-on-med-and-down">Admin</a>
  <a href="{% url 'doctype'%}" class="breadcrumb hide-on-med-and-down">Tipi</a>
  <a class="breadcrumb hide-on-med-and-down">Documenti</a>
{% endblock %}
{% block toolbar %}
  <div class="nav-wrapper {{color}}">
    <ul>
      <li><a href="#modal1" data-target="modal1" class="modal-trigger tooltipped" data-position="top" data-tooltip="Seleziona colonne"><i class="material-icons">view_column</i></a></li>
      <li><a class="tooltipped" data-position="top" data-tooltip="Scarica tabella come Excel" Onclick='table.download("xlsx", "{{type_name}} - tabella.xlsx")'><i class="material-icons">table_view</i></a></li>
      <li><a class="tooltipped" data-position="top" data-tooltip="Scarica tabella come PDF" Onclick='table.downloadToTab("pdf")'><i class="material-icons">picture_as_pdf</i></a></li>
    </ul>
    <ul class="right">
      <li><a class="tooltipped" data-position="top" data-tooltip="Pulisci filtri" Onclick="send('clear')"><i class="material-icons">clear</i></a></li>
      <li><a href="#modal2" data-target="modal2" class="modal-trigger tooltipped" data-position="top" data-tooltip="Filtri"><i class="material-icons">filter_list</i></a></li>
    </ul>
  </div>
{% endblock %}

{% block script_import %}
<script src=" https://cdn.jsdelivr.net/npm/luxon@3.4.1/build/global/luxon.min.js "></script>
<script src="https://unpkg.com/jspdf@latest/dist/jspdf.umd.min.js"></script>
<script src="https://unpkg.com/jspdf-autotable@latest/dist/jspdf.plugin.autotable.js"></script>
<script src="https://cdn.sheetjs.com/xlsx-0.20.1/package/dist/xlsx.full.min.js"></script>

{% endblock %}

{% block content %}
{% load app_filter %}
<form id="selection" action="{% url 'doclist-table' type_id=type_id %}" method="post">
{% csrf_token %}
<div id="modal2" class="modal modal-fixed-footer">
  <div class="modal-content">
    <h5>Filtri</h5>
    <div class="row">
      <div class="input-field col l3 s12">
        <label>
          <input name="filter_hidden" type="checkbox" class="filled-in" {{hidden_check}}/>
          <span style="color:black"><i class="material-icons left">archive</i>Archiviati</span>
        </label>
      </div>
      <div class="input-field col l3 s12">
        <label>
          <input name="filter_wait" type="checkbox" class="filled-in" {{wait_check}}/>
          <span style="color:black"><i class="material-icons left">timelapse</i>In Attesa</span>
        </label>
      </div>
      <div class="input-field col l3 s12">
        <label>
          <input name="filter_selfsign" type="checkbox" class="filled-in" {{selfsign_check}}/>
          <span style="color:black"><i class="material-icons left">assignment_turned_in</i>No firma</span>
        </label>
      </div>
      <div class="input-field col l3 s12">
        <label>
          <input name="filter_ok" type="checkbox" class="filled-in" {{ok_check}}/>
          <span style="color:black"><i class="material-icons left">check</i>Approvati</span>
        </label>
      </div>
    </div>
    <br>
    <br>
    <div class = "row">
      <div class="input-field col l6 s12">
        <label for="newer">Pi&ugrave; recenti di</label>
        <input value="{{newer}}" name="newer" id="newer" type="text" class="datepicker">
      </div>
      <div class="input-field col l6 s12">
        <label for="older">Pi&ugrave; vecchi di</label>
        <input value="{{older}}" name="older" id="older" type="text" class="datepicker">
      </div>
    </div>
    <div class = "row">
      <div class="col s12" {% if type_id != 0 %} hidden {% endif %}>
        <div id="chips_type" class="chips chips-placeholder chips-autocomplete"></div>
      </div>
      <div class="col s12">
        <div id="chips_owner" class="chips chips-placeholder chips-autocomplete "></div>
      </div>
      <div class="col s12">
        <div id="chips_groups" class="chips chips-placeholder chips-autocomplete "></div>
      </div>
    </div>
    <div class="row">
      <div class="input-field col s12">
        <label>
          <input name="filter_signdoc" type="checkbox" class="filled-in" {{signdoc_check}}/>
          <span style="color:black"><i class="material-icons left">check_circle</i>Visualizza solo approvati con firma allegata</span>
        </label>
      </div>
    </div>
  </div>
  <div class="modal-footer">
    <a href="#!" onclick="send('filter')" class="modal-close waves-effect waves-green btn-flat">Applica</a>
  </div>
</div>
<input type="hidden" name="action" id="action">
<input type="hidden" name="owner" id="owner">
<input type="hidden" name="type" id="type">
<input type="hidden" name="groups" id="groups">
<div id="modal1" class="modal modal-fixed-footer">
  <div class="modal-content">
    <h5>Colonne</h5>
    <div class="row" id="column-select">
    </div>
  </div>
  <div class="modal-footer">
    <a href="#!" onclick="update_cols()" class="modal-close waves-effect waves-green btn-flat">Applica</a>
  </div>
</div>
</form>

<div id="example-table"></div>
{% endblock %}

{% block script %}
  $(document).ready(function(){
      $('#modal1').modal();
      $('#modal2').modal();
      $(".tabulator-col-resize-handle").css("margin-left", "-3px");
  });

  var iconFormatter = function(cell) {
    return '<i class="material-icons">' + cell.getValue() + '</i>';
  }

  var tabledata = [
      {% for doc in docs %}
        {
          {% if doc.status == "wait" %}
            status: 'timelapse',
          {% elif doc.status == "ok" %}
            {% if doc.signed_doc %}
            status: 'check_circle',
            {% else %}
            status: 'check',
            {% endif %}
          {% elif doc.status == "archive" %}
            status: 'archive',
          {% elif doc.status == "autosign" %}
            status: 'assignment_turned_in',
          {% endif %}
          type: "{{doc.document_type.name}}",
          code: {% if doc.status == "ok" or doc.status == "archive" %} "{{doc.code}}" {% else %} "???" {% endif %},
          compilation_date: "{{doc.compilation_date|date:"d/m/Y"}}",
          capo: {% if "capi" in doc.usercode.user|user_groups %}true{% else %}false{% endif %},
          name: "{{doc.usercode.first_name}}",
          last_name: "{{doc.usercode.last_name}}",
          email: "{{doc.personal_data.email}}",
          birth_date: "{{doc.personal_data.born_date|date:"d/m/Y"}}",
          branca: "{{ doc.usercode.branca }}",
          parent_name: "{{doc.personal_data.parent_name}}",
          avs_number: "{{doc.personal_data.avs_number}}",
          via: "{{doc.personal_data.via}}",
          cap: "{{doc.personal_data.cap}}",
          country: "{{doc.personal_data.country}}",
          nationality: "{{doc.personal_data.nationality}}",
          phone: "{{doc.personal_data.phone}}",
          home_phone: "{{doc.personal_data.home_phone}}",
          school: "{{doc.personal_data.school}}",
          year: "{{doc.personal_data.year}}",
          emer_name: "{{doc.medical_data.emer_name}}",
          emer_relative: "{{doc.medical_data.emer_relative}}",
          cell_phone: "{{doc.medical_data.cell_phone}}",
          emer_phone: "{{doc.medical_data.emer_phone}}",
          emer_address: "{{doc.medical_data.address}}",
          health_care: "{{doc.medical_data.health_care}}",
          injuries: "{{doc.medical_data.injuries}}",
          rc: "{{doc.medical_data.rc}}",
          rega: "{{doc.medical_data.rega}}",
          medic_name: "{{doc.medical_data.medic_name}}",
          medic_phone: "{{doc.medical_data.medic_phone}}",
          medic_address: "{{doc.medical_data.medic_address}}",
          sickness: "{{doc.medical_data.sickness}}",
          vaccine: "{{doc.medical_data.vaccine}}",
          tetanus_date: "{{doc.medical_data.tetanus_date}}",
          allergy: "{{doc.medical_data.allergy}}",
          drugs: "{{doc.medical_data.drugs}}",
          misc: "{{doc.medical_data.misc}}",
          {% for key in doc|doc_key %}
            custom_key_{{forloop.counter0}}: "{{key.value}}",
          {% endfor %}
        },
      {% endfor %}
  ];

  var columns = [];

  var col_categories = [
    {field: "base", name: "Informazioni base", cols: 
      [
        {title: "Nome", field: "name", frozen: true},
        {title: "Cognome", field: "last_name", frozen: true},
        {title: "Stato", field: "status", formatter: iconFormatter},
        {title: "Tipo", field: "type"},
        {title: "Codice", field: "code"},
        {title: "Capo", field: "capo", formatter:"tickCross"},
        {title: "Data compilazione", field: "compilation_date", sorter:"date"},
        {title: "Branca", field: "branca"},
        {title: "Email", field: "email", visible: false},
        {title: "Data di nascita", field: "birth_date", visible: false, sorter:"date"},
      ]
    },
    {field: "personal", name: "Informazioni personali", cols: 
      [
        {title: "Nome genitore", field: "parent_name", visible: false},
        {title: "Numero AVS", field: "avs_number", visible: false},
        {title: "Via", field: "via", visible: false},
        {title: "CAP", field: "cap", visible: false},
        {title: "Paese", field: "country", visible: false},
        {title: "Nazionalita", field: "nationality", visible: false},
        {title: "Telefono", field: "phone", visible: false},
        {title: "Telefono casa", field: "home_phone", visible: false},
        {title: "Scuola", field: "school", visible: false},
        {title: "Anno", field: "year", visible: false},
      ]
    },
    {field: "medical", name: "Informazioni mediche", cols: 
      [
        {title: "Nome emergenza", field: "emer_name", visible: false},
        {title: "Parentela emergenza", field: "emer_relative", visible: false},
        {title: "Cellulare emergenza", field: "cell_phone", visible: false},
        {title: "Telefono emergenza", field: "emer_phone", visible: false},
        {title: "Indirizzo emergenza", field: "emer_address", visible: false},
        {title: "Assicurazione sanitaria", field: "health_care", visible: false},
        {title: "Infortuni", field: "injuries", visible: false},
        {title: "RC", field: "rc", visible: false},
        {title: "REGA", field: "rega", visible: false},
        {title: "Nome medico", field: "medic_name", visible: false},
        {title: "Telefono medico", field: "medic_phone", visible: false},
        {title: "Indirizzo medico", field: "medic_address", visible: false},
        {title: "Malattie avute", field: "sickness", visible: false},
        {title: "Vaccinazioni", field: "vaccine", visible: false},
        {title: "Data vaccino tetano", field: "tetanus_date", visible: false},
        {title: "Allergie", field: "allergy", visible: false},
        {title: "Farmaci da assumere", field: "drugs", visible: false},
        {title: "Info particolari", field: "misc", visible: false},
      ]
    },
    {% if custom_keys|length > 0 %}
    {field: "custom", name: "Parametri personalizzati", cols: 
      [
        {% for key in custom_keys %}
          {title: "{{key.1}}", field: "custom_key_{{key.0}}", visible: true, width: "7%"},
        {% endfor %}
      ]
    },
    {% endif %}
  ]

  var docTypes = {};
  for (var i=0; i < tabledata.length; i++) {
    if (!(tabledata[i].type in docTypes)) {
      docTypes[tabledata[i].type] = true;
    }
  }

  var col_select = document.getElementById("column-select");
  for (var j = 0; j < col_categories.length; j++) {
    col_select.innerHTML += '<div class="input-field col s12"><label><input onclick="check_all(\''+col_categories[j].field+'\')" id="category_'+col_categories[j].field+'" type="checkbox" class="filled-in"/><span style="color:black"><b>'+col_categories[j].name+'</b></span></label></div>';
    var all_visible = true;
    for (var i = 0; i < col_categories[j].cols.length; i++) {
      columns.push(col_categories[j].cols[i]);
      if (columns[columns.length-1].visible == false) {
        col_select.innerHTML += '<div class="input-field col s12"><label>&emsp;<input onclick="verify_check(\''+col_categories[j].field+'\')" id="filter_'+col_categories[j].cols[i].field+'" type="checkbox" class="filled-in ctr_'+col_categories[j].field+'"/><span style="color:black">'+col_categories[j].cols[i].title+'</span></label></div>';
        all_visible = false;
      } else {
        col_select.innerHTML += '<div class="input-field col s12"><label>&emsp;<input onclick="verify_check(\''+col_categories[j].field+'\')" id="filter_'+col_categories[j].cols[i].field+'" type="checkbox" class="filled-in ctr_'+col_categories[j].field+'" checked="checked"/><span style="color:black">'+col_categories[j].cols[i].title+'</span></label></div>';
      }
    }
  }

  for (var i = 0; i < col_categories.length; i++) {
    verify_check(col_categories[i].field);
  }

  var hasGroupSummary = {};

  //initialize table
  var table = new Tabulator("#example-table", {
      movableColumns: true,
      layout:"fitDataFill",
      {% if type_id == 0 %}
      groupBy: "type",
      {% endif %}
      data:tabledata,
      columns:columns,
      groupHeader:function(value, count, data, group){
        return value + "<span style='color:#d00; margin-left:10px;'>(" + count + ")</span>";
      },
  });

  function update_cols() {
    for (var i = 0; i < columns.length; i++) {
      if (document.getElementById("filter_"+columns[i].field).checked) {
        table.showColumn(columns[i].field);
      } else {
        table.hideColumn(columns[i].field);
      }
    }
  }

  function check_all(cat) {
    var ctr_elem = document.getElementById("category_"+cat);
    if (ctr_elem.checked) {
      $('.ctr_'+cat).prop('checked', 'checked');
    } else {
      $('.ctr_'+cat).prop('checked', false);
    }
  }

  function verify_check(cat) {
    var ctr_elem = document.getElementById("category_"+cat);
    var all_checked = true;
    $('.ctr_'+cat).each(function() {
      if (!this.checked) {
        all_checked = false;
      }
    });
    if (all_checked) {
      ctr_elem.checked = true;
    } else {
      ctr_elem.checked = false;
    }
  }

$('.chips').chips();
$('#chips_type').chips({
  placeholder: 'Tipo',
  secondaryPlaceholder: '+Altro tipo',
  autocompleteOptions: {
    data: {
      {% for t in types %}
        '{{t.name}}': null,
      {% endfor %}
    },
    limit: Infinity,
    minLength: 0
  },
  data: [
    {% for d in chips_type %}
      {tag: '{{d}}'},
    {% endfor %}
  ]
});
$('#chips_owner').chips({
  placeholder: 'Utente',
  secondaryPlaceholder: '+Altro utente',
  autocompleteOptions: {
    data: {
      {% for user in users %}
        '{{user.user__username}} ({{user.user__first_name}} {{user.user__last_name}})': null,
      {% endfor %}
    },
    limit: Infinity,
    minLength: 0
  },
  data: [
    {% for d in chips_owner %}
      {tag: '{{d}}'},
    {% endfor %}
  ]
});
$('#chips_groups').chips({
  placeholder: 'Gruppo',
  secondaryPlaceholder: '+Altro gruppo',
  autocompleteOptions: {
    data: {
      {% for g in groups %}
        '{{g}}': null,
      {% endfor %}
    },
    limit: Infinity,
    minLength: 0
  },
  data: [
    {% for g in chips_groups %}
      {tag: '{{g}}'},
    {% endfor %}
  ]
});

function send(id) {
  var form = document.getElementById('selection')
  var action = document.getElementById('action')
  var owner = document.getElementById('owner')
  var type = document.getElementById('type')
  var groups = document.getElementById('groups')
  var chips_owner = M.Chips.getInstance(document.getElementById('chips_owner'));
  var chips_type = M.Chips.getInstance(document.getElementById('chips_type'));
  var chips_groups = M.Chips.getInstance(document.getElementById('chips_groups'));
  var type_array = []
  var owner_array = []
  var groups_array = []

  for (i=0; i < chips_owner.chipsData.length; i++) {
    owner_array.push(chips_owner.chipsData[i].tag)
  }

  for (i=0; i < chips_type.chipsData.length; i++) {
    type_array.push(chips_type.chipsData[i].tag)
  }

  for (i=0; i < chips_groups.chipsData.length; i++) {
    groups_array.push(chips_groups.chipsData[i].tag)
  }

  action.setAttribute('value', id);
  owner.setAttribute('value', owner_array.join("^|"))
  type.setAttribute('value', type_array.join("^|"))
  groups.setAttribute('value', groups_array.join("^|"))
  form.submit()
}

{% endblock %}