1 |
efrain |
1 |
require(['core/first', 'jquery', 'jqueryui', 'core/ajax', 'pnotify'], function(core, $, bootstrap, ajax, pnotify) {
|
|
|
2 |
$(document).ready(function() {
|
|
|
3 |
|
|
|
4 |
$.fn.reloadFiles = function() {
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
$('.ccn_preloader_load').show();
|
|
|
8 |
|
|
|
9 |
|
|
|
10 |
$('#local-cesa-reportes-all-files').empty();
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
ajax.call([{
|
|
|
14 |
methodname: 'local_cesa_reportes_report_all_files',
|
|
|
15 |
args: {
|
|
|
16 |
'fakeparam': 0,
|
|
|
17 |
},
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
}])[0].done(function(response) {
|
|
|
21 |
$('.ccn_preloader_load').hide();
|
|
|
22 |
|
|
|
23 |
var json = JSON.parse(response);
|
|
|
24 |
|
|
|
25 |
if(json.success) {
|
|
|
26 |
$('#local-cesa-reportes-all-files').html(json.data);
|
|
|
27 |
}
|
|
|
28 |
return;
|
|
|
29 |
}).fail(function(err) {
|
|
|
30 |
$('.ccn_preloader_load').hide();
|
|
|
31 |
|
|
|
32 |
return;
|
|
|
33 |
});
|
|
|
34 |
};
|
|
|
35 |
|
|
|
36 |
$('body').on('click', 'button.btn-download-file', function(e) {
|
|
|
37 |
e.preventDefault();
|
|
|
38 |
|
|
|
39 |
$('#btn-download-file').prop('disabled', true);
|
|
|
40 |
$('.ccn_preloader_load').show();
|
|
|
41 |
|
|
|
42 |
ajax.call([{
|
|
|
43 |
methodname: 'local_cesa_reportes_report_download_file',
|
|
|
44 |
args: {
|
|
|
45 |
'id': $(this).data('id'),
|
|
|
46 |
},
|
|
|
47 |
}])[0].done(function(response) {
|
|
|
48 |
$('.ccn_preloader_load').hide();
|
|
|
49 |
$('#btn-download-file').prop('disabled', false);
|
|
|
50 |
|
|
|
51 |
var json = JSON.parse(response);
|
|
|
52 |
if(json.success) {
|
|
|
53 |
var anchor = window.document.createElement("a");
|
|
|
54 |
anchor.href = 'data:application/octet-stream;charset=utf-8;base64,' + json.data.content ;
|
|
|
55 |
anchor.download = json.data.basename;
|
|
|
56 |
document.body.appendChild(anchor);
|
|
|
57 |
anchor.click(); // IE: "Access is denied"; see: https://connect.microsoft.com/IE/feedback/details/797361/ie-10-treats-blob-url-as-cross-origin-and-denies-access
|
|
|
58 |
document.body.removeChild(anchor);
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
}).fail(function(err) {
|
|
|
62 |
$('.ccn_preloader_load').hide();
|
|
|
63 |
$('#btn-delete-file').prop('disabled', false);
|
|
|
64 |
|
|
|
65 |
return;
|
|
|
66 |
});
|
|
|
67 |
});
|
|
|
68 |
|
|
|
69 |
|
|
|
70 |
$('body').on('click', 'button.btn-delete-file', function(e) {
|
|
|
71 |
e.preventDefault();
|
|
|
72 |
|
|
|
73 |
$('.ccn_preloader_load').show();
|
|
|
74 |
$('#btn-delete-file').prop('disabled', true);
|
|
|
75 |
|
|
|
76 |
ajax.call([{
|
|
|
77 |
methodname: 'local_cesa_reportes_report_delete_file',
|
|
|
78 |
args: {
|
|
|
79 |
'id': $(this).data('id'),
|
|
|
80 |
},
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
}])[0].done(function(response) {
|
|
|
84 |
|
|
|
85 |
$('.ccn_preloader_load').hide();
|
|
|
86 |
$('#btn-delete-file').prop('disabled', false);
|
|
|
87 |
|
|
|
88 |
|
|
|
89 |
var json = JSON.parse(response);
|
|
|
90 |
|
|
|
91 |
if(json.success) {
|
|
|
92 |
$('#local-cesa-reportes-all-files').html(json.data);
|
|
|
93 |
}
|
|
|
94 |
return;
|
|
|
95 |
|
|
|
96 |
|
|
|
97 |
}).fail(function(err) {
|
|
|
98 |
$('.ccn_preloader_load').hide();
|
|
|
99 |
$('#btn-delete-file').prop('disabled', false);
|
|
|
100 |
|
|
|
101 |
return;
|
|
|
102 |
});
|
|
|
103 |
});
|
|
|
104 |
|
|
|
105 |
$.fn.reloadFiles();
|
|
|
106 |
|
|
|
107 |
});
|
|
|
108 |
});
|