Subversion Repositories oidplus

Rev

Rev 1036 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
635 daniel-mar 1
/*
2
 * OIDplus 2.0
3
 * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
 
18
var OIDplusPagePublicAttachments = {
19
 
20
        oid: "1.3.6.1.4.1.37476.2.5.2.4.1.95",
21
 
22
        downloadAttachment: function(webpath, id, file) {
23
 
24
                //OIDplus::webpath(__DIR__).'download.php?id='.urlencode($id).'&filename='.urlencode(basename($file)).'
25
 
26
                window.open(webpath + 'download.php?id='+encodeURI(id)+'&filename='+encodeURI(file), '_blank');
27
 
28
        },
29
 
30
        deleteAttachment: function(id, file) {
31
                if(!window.confirm(_L("Are you sure that you want to delete %1?",file))) return false;
32
 
33
                $.ajax({
34
                        url:"ajax.php",
35
                        method:"POST",
36
                        beforeSend: function(jqXHR, settings) {
37
                                $.xhrPool.abortAll();
38
                                $.xhrPool.add(jqXHR);
39
                        },
40
                        complete: function(jqXHR, text) {
41
                                $.xhrPool.remove(jqXHR);
42
                        },
43
                        data: {
44
                                csrf_token:csrf_token,
45
                                plugin:OIDplusPagePublicAttachments.oid,
46
                                action:"deleteAttachment",
47
                                id:id,
48
                                filename:file,
49
                        },
1036 daniel-mar 50
                        error: oidplus_ajax_error,
51
                        success: function (data) {
52
                                oidplus_ajax_success(data, function (data) {
833 daniel-mar 53
                                        alertSuccess(_L("OK"));
635 daniel-mar 54
                                        reloadContent();
1036 daniel-mar 55
                                });
635 daniel-mar 56
                        }
57
                });
58
        },
59
 
1400 daniel-mar 60
        uploadAttachment: function(idx, file) {
635 daniel-mar 61
                var file_data = $('#fileAttachment').prop('files')[0];
62
 
63
                var form_data = new FormData();
64
                form_data.append('csrf_token', csrf_token);
65
                form_data.append('userfile', file_data);
66
                form_data.append('plugin', OIDplusPagePublicAttachments.oid);
67
                form_data.append('action', "uploadAttachment");
1400 daniel-mar 68
                form_data.append('id', idx);
69
                alert("test " + idx);
635 daniel-mar 70
 
71
                $.ajax({
72
                        url:"ajax.php",
73
                        method:"POST",
74
                        processData:false,
75
                        contentType:false,
76
                        beforeSend: function(jqXHR, settings) {
77
                                $.xhrPool.abortAll();
78
                                $.xhrPool.add(jqXHR);
79
                        },
80
                        complete: function(jqXHR, text) {
81
                                $.xhrPool.remove(jqXHR);
82
                        },
83
                        data: form_data,
1036 daniel-mar 84
                        error: oidplus_ajax_error,
85
                        success: function (data) {
86
                                oidplus_ajax_success(data, function (data) {
833 daniel-mar 87
                                        alertSuccess(_L("OK"));
635 daniel-mar 88
                                        $('#fileAttachment').val('');
89
                                        reloadContent();
1036 daniel-mar 90
                                });
635 daniel-mar 91
                        }
92
                });
93
        },
94
 
95
        uploadAttachmentOnSubmit: function() {
96
                try {
1400 daniel-mar 97
                        OIDplusPagePublicAttachments.uploadAttachment($('input[name=id]').val(), $("#fileAttachment")[0].value);
635 daniel-mar 98
                } finally {
99
                        return false;
100
                }
101
        }
102
 
103
};