-
Notifications
You must be signed in to change notification settings - Fork 0
/
javascript.html
437 lines (377 loc) · 15.3 KB
/
javascript.html
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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
<script>
function start(){
console.log('start')
createTableFiles()
createTableDiffide()
}
$(document).ready(function() {
//controlla il click su tableFiles
$("#tableFiles").on('click', function(){
//gestisce il change di checkedAll
$("#checkedAll").change(function(){
if(this.checked){
$(".checkSingle").each(function(){
this.checked=true;
})
}else{
$(".checkSingle").each(function(){
this.checked=false;
})
}
});
//gestisce il change di checkedSingle
$(".checkSingle").change(function () {
if ($(this).is(":checked")){
var isAllChecked = 0;
$(".checkSingle").each(function(){
if(!this.checked)
isAllChecked = 1;
})
if(isAllChecked == 0){
$("#checkedAll").prop("checked", true);
}
}
else {
$("#checkedAll").prop("checked", false);
};
});
})
//aggiorna la tableFiles (deve stare fuori dal .on della table
$("#refreshTableFiles").click(function(){
console.log('aggiorna la tabella')
var $icon = $( this ).find( ".glyphicon.glyphicon-refresh" ),
animateClass = "glyphicon-refresh-animate";
$icon.addClass( animateClass );
// setTimeout is to indicate some async operation
window.setTimeout( function() {
$icon.removeClass( animateClass );
}, 2000 );
$("#tableFiles tbody").remove();
console.log('launch createTableFiles')
createTableFiles()
})
//monitorizza il click di tableDiffide
$("#tableDiffide").on('click', function(){
var numdiffide = 0
//gestisce il change di checkedAllDiffide
$("#checkedAllDiffide").change(function(){
if(this.checked){
$(".checkSingleDiffide").each(function(){
this.checked=true;
})
}else{
$(".checkSingleDiffide").each(function(){
this.checked=false;
})
}
});
//gestisce il change di checkedSingleDiffide
$(".checkSingleDiffide").click(function (numdiffide) {
console.log('numdiffide ' + numdiffide)
if ($(this).is(":checked")){
numdiffide++
var isAllChecked = 0;
$(".checkSingleDiffide").each(function(){
if(!this.checked)
isAllChecked = 1;
})
if(isAllChecked == 0){
$("#checkedAllDiffide").prop("checked", true);
}
}
else {
numdiffide--
$("#checkedAllDiffide").prop("checked", false);
return numdiffide
}
});
});
}); // chiude il document ready
// validazione tableFiles
$('#myFormFiles').validator().on('submit', function (e) {
if (e.isDefaultPrevented()) {
console.log('form prevented')
}
else
{
// le checkbox non contengono l'attributo require, quindi il controllo viene fatto qui !
var min = 1 //minumum number of boxes to be checked for this form-group
if($(".checkSingle:checkbox:checked").length<min){
console.log('devi selezionare almeno ' + min + ' file/s')
return false
// è necessario selezionare almeno un file
}
$('#importOutput').html('')
// importa i dati dai file di affido selezionati
// gestisce l'animazione dell'icona del button importa
console.log('click icon')
var $icon = $( this ).find( ".glyphicon.glyphicon-import" );
if($icon.hasClass('glyphicon-import')) {
$icon.removeClass('glyphicon-import')
$icon.addClass('glyphicon-refresh')
$icon.addClass('glyphicon-refresh-animate')
// setTimeout is to indicate some async operation
window.setTimeout( function() {
$icon.removeClass('glyphicon-refresh')
$icon.removeClass('glyphicon-refresh-animate')
$icon.addClass('glyphicon-import')
}, 2000 );
}
//compone l'array dei files selezionati
var files = []
var checkboxes = $("input:checkbox:checked");
$(checkboxes).each(function(){
arr = $(this).closest('tr').find('td').eq(2);
$(arr).each(function(){
files.push(this.innerHTML)
});
});
//legge i dati dai files di affido selezionati
console.log(files)
google.script.run
.withSuccessHandler(onReadDiffide)
.withFailureHandler(onError2)
.readDiffideDaInviareFromFiles(files)
return false
}
function onReadDiffide(objDiffideDaInviare){
console.log('dati scritti su sheet')
// ricrea la tabella dei files aggiornata
createTableFiles()
// crea la tabella diffide
createTableDiffide(objDiffideDaInviare)
}
function onError2(err){
console.log(err)
$('#importOutput').html('Non è stato possibile importare il file selezionato')
}
})
//**********
// button Filter
$('.filterable .btn-filter').click(function(){
var $panel = $(this).parents('.filterable'),
$filters = $panel.find('.filters input'),
$tbody = $panel.find('.table tbody');
if ($filters.prop('disabled') === true) {
$filters.prop('disabled', false);
$("#range").attr("placeholder", "(es. 3-28)");
$("#range").attr('size', ($("#range").attr('placeholder').length))
$filters.first().focus();
} else {
$filters.val('').prop('disabled', true);
$tbody.find('.no-result').remove();
$tbody.find('tr').show();
}
});
$('#range').blur(function(e){
/* Ignore tab key */
var code = e.keyCode || e.which;
if (code == '9') return;
/* if esc is pressed we want to clear the value of search bo */
if (code == 27 || $(this).val() == '') {
$(this).val('');
}
/* Useful DOM data and selectors */
var $input = $(this),
rangeArray = $input.val().toLowerCase().split("-"),
$panel = $input.parents('.filterable'),
column = $panel.find('.filters th').index($input.parents('th')),
$table = $panel.find('.table'),
$rows = $table.find('tbody tr')
/* filter function ;) */
var $filteredRows = $rows.filter(function(){
var $t = $(this);
for (var i = rangeArray[0]; i < rangeArray[0]; ++i) {
if ($t.is(":contains('" +i+ "')")) {
return true;
}
}
return false;
})
console.log(JSON.stringify("righe filtrate " + $filteredRows))
/* Clean previous no-result if exist */
$table.find('tbody .no-result').remove();
/* Show all rows, hide filtered ones (never do that outside of a demo ! xD) */
$rows.show();
$filteredRows.hide();
/* Prepend no-result row if all rows are filtered */
if ($filteredRows.length === $rows.length) {
$table.find('tbody').prepend($('<tr class="no-result text-center"><td colspan="'+ $table.find('.filters th').length +'">No result found</td></tr>'));
}
});
$('.filterable .filters input').not('#range').keyup(function(e){
/* Ignore tab key */
var code = e.keyCode || e.which;
if (code == '9') return;
//if esc is pressed we want to clear the value of search box
if (code == 27 || $(this).val() == '') {
$(this).val('');
}
/* Useful DOM data and selectors */
var $input = $(this),
inputContent = $input.val().toLowerCase(),
$panel = $input.parents('.filterable'),
column = $panel.find('.filters th').index($input.parents('th')),
$table = $panel.find('.table'),
$rows = $table.find('tbody tr');
console.log(inputContent)
/* Dirtiest filter function ever ;) */
var $filteredRows = $rows.filter(function(){
var value = $(this).find('td').eq(column).text().toLowerCase();
return value.indexOf(inputContent) === -1;
});
/* Clean previous no-result if exist */
$table.find('tbody .no-result').remove();
/* Show all rows, hide filtered ones (never do that outside of a demo ! xD) */
$rows.show();
$filteredRows.hide();
/* Prepend no-result row if all rows are filtered */
if ($filteredRows.length === $rows.length) {
$table.find('tbody').prepend($('<tr class="no-result text-center"><td colspan="'+ $table.find('.filters th').length +'">No result found</td></tr>'));
}
});
// form validator di Diffide
$('#myFormDiffide').validator().on('submit', function (e) {
var min = 1 //minumum number of boxes to be checked for this form-group
if (e.isDefaultPrevented()) {
console.log('form prevented')
}
else
{
// le checkbox non contengono l'attributo require, quindi il controllo viene fatto qui !
// console.log ($(".checkSingleDiffide :checkbox").length)
// è necessario selezionare almeno un file
// if($(".checkSingleDiffide :checkbox:checked").length<min){
// console.log('devi selezionare almeno ' + min + ' diffida/e')
printDiffide()
return false
}
})
function printDiffide(){
var invioData = $('#modalPrint').modal('show')
return false;
/*
// gestisce l'animazione dell'icona del button importa
console.log('click icon')
var $icon = $( this ).find( ".glyphicon.glyphicon-print" );
if($icon.hasClass('glyphicon-print')) {
$icon.removeClass('glyphicon-print')
$icon.addClass('glyphicon-refresh')
$icon.addClass('glyphicon-refresh-animate')
// setTimeout is to indicate some async operation
window.setTimeout( function() {
$icon.removeClass('glyphicon-refresh')
$icon.removeClass('glyphicon-refresh-animate')
$icon.addClass('glyphicon-print')
}, 2000 );
}
//compone l'array dei files selezionati
var checkboxes = $("input:checkbox:checked");
$(checkboxes).each(function(){
arr = $(this).closest('tr').find('td').eq(2);
$(arr).each(function(){
diffide.push(this.innerHTML)
});
});
//legge i dati dai files di affido selezionati
console.log(diffide)
google.script.run
.withSuccessHandler(onPrintDiffide)
.withFailureHandler(onError3)
.printDiffide(diffide)
return false
*/
}
function onPrintDiffide(){
}
function onError3(err){
console.log(err)
$('#printOutput').html('Non è stato possibile stampare le diffide selezionate')
}
$('#modal').click(function (){
$('#modal').modal('open');
});
$('#range').blur(function(e){
var range = $('#range').val()
console.log(range)
});
function createTableFiles(){
console.log('createTableFiles')
//legge i files affidi da importare presenti su folder
google.script.run
.withSuccessHandler(onImported)
.withFailureHandler(onFailure)
.readFilesAffidiFromFolder()
}
function onFailure(error) {
var div = document.getElementById('output');
div.innerHTML = "ERROR: " + error.message;
}
function onImported(objFilesAffidi){
var files = JSON.parse(objFilesAffidi)
console.log("data")
console.log(files)
console.log("numero files= " + files.length)
var myCheckbox = ''
var assegnati = 0
var wroteOnTable = 0
$('#tableFiles tbody').empty()
if (files.length == 0) {
$('#tableFiles thead').append('<th><td style="text-align: center" colspan="6">No result found</td></th>');
}
else
{
for (var i=0; i<files.length; i++){
if (files[i]['Stato affido'] == 'Assegnato'){
assegnati++
myCheckbox = '<label><input id="checkbox'+(i+1)+'" class="checkSingle" type="checkbox"></label>'
tr = $('<tr>');
tr.append("<td>" + myCheckbox + "</td>");
tr.append("<td>" + files[i]['Nome del file'] + "</td>");
tr.append("<td style='display: none'>" + files[i]['URL'] + "</td>");
tr.append("<td>" + files[i]['Stato affido'] + "</td>");
tr.append("<td>" + files[i]['Data assegnazione'] + "</td>");
tr.append("<td>" + files[i]['Data importazione'] + "</td>");
tr.append("<td>" + files[i].Badge + "</td>");
$('#tableFiles').append(tr);
wroteOnTable++
}
}
}
console.log('scritti in tabella ' + wroteOnTable)
console.log('files assegnati ' + assegnati)
}
// Crea la TableDiffide
function createTableDiffide(){
//legge dati affidi e crea tabella diffide
console.log('createTableDiffide')
google.script.run
.withSuccessHandler(onReadDiffideDaInviare)
.withFailureHandler(onFailure)
.readDiffideDaInviareFromSheet()
}
// withSuccessHandler di readDiffideDaInviare
function onReadDiffideDaInviare(objAllDiffideDaInviare){
var diffide = JSON.parse(objAllDiffideDaInviare)
console.log('DiffideDaInviare ')
console.log(diffide)
$('#tableDiffide tbody').remove()
var tr
if (diffide.length > 0){
for (i=0; i<diffide.length; i++){
var myCheckbox = '<div vcenter> <label> <input id="checkbox'+(i+1)+'" class="checkSingleDiffide" type="checkbox"> </label> </div>'
tr = $('<tr>');
tr.append("<td >" + myCheckbox + "</td>");
tr.append("<td>" + diffide[i]['Riferimento pratica'] + "</td>");
tr.append("<td>" + diffide[i]['Codice cliente'] + "</td>");
tr.append("<td>" + diffide[i]['Dato fiscale'] + "</td>");
tr.append("<td>" + diffide[i]['Ragione sociale'] + "</td>");
$('#tableDiffide').append(tr);
}
}
else
{
$('#tableDiffide tbody').prepend($('<tr class="no-result text-center"><td colspan="">No result found</td></tr>'));
}
}
</script>